Monday, May 30, 2011
Which Linux for my system??
Over the past decade, we are seeing an accelerated adoption rate of Linux operating system for many hardware platforms. The hardware platforms are based out of either stand-alone processors or integrated processors or even systems on chip (SOC), 32-Bit or 64-Bit, single-core or multi-core, special cell processors or general purpose graphical processing units (GPU). About ten billion processors were manufactured in the year 2008. List of some of the processors can be found at http://en.wikipedia.org/wiki/List_of_microprocessors
The trend of number of transistors that can be put on an integrated circuit is doubling approximately every two years, almost following Moore's law. So, multiple new compact and efficient hardware platforms eventually hitting the market is inevitable.
The Linux market is growing rapidly because of secured networking protocols and ability to support variety of applications, its scalability, being royalty free and because of the number of active developers. Linux distributions may be specialized for different purposes including computer architecture support, embedded systems, stability, security, localization to a specific region or language, targeting of specific user groups and support for real-time applications. From general purpose use on Desktop, Servers, Mainframes , Supercomputers and Embedded Systems, Linux supports a vast variety of hardware platforms, probably more than any other operating system. Linux distributions have taken colossal of forms - from fully featured desktop, server, laptop, netbook, mobile phone, tablet operating systems to minimal environments as well. List of some of the Linux distributions can be found at http://en.wikipedia.org/wiki/List_of_Linux_distributions
(and also at http://distrowatch.com)
There are tools available to help select an appropriate distribution too. Yet, it’s not easy to pick up a Linux distribution for reasons like variety of choices, support for a particular feature or application on particular distribution, device drivers and processor architectures (as you see from the above, there are enormous hardware platforms, both custom and off the shelf). Also there are types as well, like live CD and flash drive installations. And for portable devices, there is already an intimidating list of hardware dependent distributions and versions of meego and android that are contemporary. It would be nice to have an easy method to pick up the right distribution and version as Linux seems to be eternal. Socrates said, “The unexamined life is not worth living”. So, let me elaborate some of the superficial points which may be useful in coming up with one:
1. Network booting is the process of booting a system from a network interface independently of data storage devices or installed operating systems. Most of the hardware platforms (esp. Intel based) provide an option to boot from the network in their firmware via the Preboot eXecution Environment (PXE). The PXE protocol is a combination of DHCP and TFTP protocols. DHCP is used to locate the appropriate boot server or servers and TFTP used to download the initial boot program and additional files. More on http://www.pix.net/software/pxeboot/archive/pxespec.pdf
2. Board Support Package (BSP) is implementation specific support code for a given hardware platform that conforms to a given operating system. It is commonly built with a boot loader that contains the minimal device support to load the operating system and device drivers for all the devices on the hardware platform. Linux Support Package or Linux BSP is commonly used term in the Linux world.
3. Linux kernel is maintained at http://www.kernel.org/ . Several other public source trees exist outside the kernel.org mainline, mostly for architecture specific development. For ease of use, a pre compiled Linux distribution can be download that supports particular hardware platform. It’s also very much possible to find the nearest open-source Linux kernel to the particular hardware platform and port it.
4. Once the operating system is installed, installing, upgrading, configuring, and removing software packages and their dependencies are cumbersome operations. Package Management System (PMS) is a collection of software tools to automate this process in a consistent manner. It typically maintains a database of software dependencies and version information to prevent software mismatches and missing prerequisites. Also allows upgrading software with latest versions, typically from a software repository. On my openSUSE desktop I use yast software management and zypper to install and maintain software packages. I also download and install rpm’s sometimes. Plenty of such divine tools are available on Linux distributions with comand line and graphical interfaces examples include yum, apt, dpkg, up2date, whohas, etc.
REVERIE
I stumbled upon an intriguing idea to automate the selection and install method as most of the necessary things are discretely available and can be made use of. Read through the synopsis below.
The Network Boot program which may be a ROM chip based or boot loader (like GRUB) based can additionally scan the system for listing down the architecture and devices on the hardware platform. The list could potentially include the comprehensive details not limiting to:
- CPU architecture, Register size, Clock speed and number of cores
- Size of memory (RAM)
- Display / Graphic adapters and Monitor / Display Devices (like LCD)
- IDE ATA / ATAPI / SCSI Controllers
- PCI Root Hubs and attached Devices
- PCMCIA adapters and attached Devices
- USB Root Hubs and attached Devices
- 1394 controllers and attached Devices
- Secure Digital host controllers
- Network interface adapters
- Bluetooth controllers
- Human Interface Devices
- Storage Devices / Disk Drives / DVD/CD-ROM drives
- Audio Controllers
This list could be sent to a remote Server over the intra or inter network by the Network Boot program. And of course, in order to the use intra or inter network by the Network Boot program, it should request an IP address (via DHCP) to a boot-server which is assumed to be local and separate (or even it could be the same) from the Server discussed below.
The Server can substantially have the following:
- Running network services like HTTP, FTP, TFTP, BOOTP, etc.
- Service to receive requests from Network Boot client program's
- Interpreter to parse the received list and to figure out suitable installable options of Linux kernel, Support Packages & Software Packages
- Provider program which can ftp the requested software components
- Archives of Readily available precompiled Linux Kernel images
- Archives of Support Packages and Drivers
- Software repository
- If kernel or driver or software package isn't available on the Server then it can maintain a link to the repository where it can be located
The PXE servers do run network services, does have a PXE Configuration file that contains the list of kernels which are available to boot and a copies of installer kernels. Also, Cobbler (https://fedorahosted.org/cobbler) is an installation server that assembles all the usual steps needed for a large network installation like TFTP, DNS, PXE, installation trees etc. and automates the process.
After receiving the list, the Server could parse the list and then generate suitable installable options of Linux kernel, Support Packages & Software Packages and then send it back to the System.
The Network Boot program could receive and then display the received list to the user with installable options (like GRUB presenting a graphical interface where the user can select which operating system to boot).
The user could pick the latest kernel versions, distributions, suitable drivers for the devices and the application software or development tools from the list and can select INSTALL. Most of the Linux distributions already have an interactive GUI installer.
The Network Boot program could pick items from the user selection and then request the Server for the software components and installables.
The Server can ftp the requested software. Starting from kernel installation to application software, this process would continue. If the server does not have the requested software component, it can maintain a list of repository locations and the fetch it from other servers and then ftp it back to the Network Boot program.
The method can be simplified by adding functions like auto install or recommended for an inscrutable layman, and for the experts, the as is custom install would suffice.
In a nutshell, it’s combining PXE, Boot loader, Linux distribution selector and a Package Management System in the conquest to pick up the right distribution and version of Linux. The only requirement or constraint is the network access to the Server. The hand held devices too could utilize the method as most of them have wifi NICs, and hand held devices without wifi are futile.
This method could also be used for finding the drivers for hotplug devices (like the windows "Install the software automatically" option) and to upgrade and manage softwares later in future.
I was smitten by an exquisite article on Clonezilla (http://www.clonezilla.org/) in the January/2011 issue of the Linux Journal (http://www.linuxjournal.com/) by Jeramiah Bowling. Clonezilla is open-source suite of cloning tools over the network and has significant resemblence to the method I was thoughtful about. It could be the starting point.
For a rendezvous, please leave a comment..
Thursday, May 7, 2009
You must set your goal
His words were echoing in my mind all the time .I was feeling like a looser, as I don’t have any goal or goals set. I seriously need a soul searching to find out my goal. Its not new, it always happens to me, when I have to take a decision on my own, this unset goal always bugs me. I always wait for couple of free days from work to sit idle and think about what should be my goal or goals. I get instant inspiration for becoming a leader by motivating speeches of our market tycoons, sometimes I think I should be an architect and I should solve all the problems across software industry or sometimes I think I should become a technocrat who knows each and everything about the technologies. Sometimes I want to be a part of a NGO and work for the society. But today’s newspaper ad reminded me that I wanted to become an entrepreneur at some point of time. Entrepreneurship, I like this word for too long but the best part of it from which I get inspired is “Be your own boss, let others work for you”. This is the only motivation for me to become an entrepreneur. Does this simply mean I am “non-cooperative” or I can’t follow others directing me? If every body gets same kind of motivation like me, I am afraid no business can survive on earth.
I am an amateur painter (I hate this word but I cant use the word “artist” as I don’t fit easily in it). When I start painting, there is a question always in my mind that whether it will look good or not, once I finish it. I keep on thinking on it and always feel a pressure about what if I failed, it will look ugly. People will say you are a big show off. Is an artist always supposed to make good paintings? You must be thinking that why this entire painting thing came in between the goals discussion .I just want to make an analogy between the two. In my painting scenario I set my goal and it doesn’t let me work high in my spirits .The performance issue keeps on bugging me.
I just want to make sure if there is something called goal exists or not. Had Alexandra the great always wanted to conquer the world, or it just happened by series of success he got. Had he set his goal? We said that he achieved his goal, what after achieving the goal, is it end of life that means we have no more goals.
Few days back somebody said, “By achieving your goals you will get what you always wanted”. Hell broke out on me, another thing I never thought of is what “I always wanted”. I think I never wanted a single thing, at the tender age I wanted a bicycle, then a scooter, then a bike and now a car and it will keep on changing.” Pleasure” must be the thing I always wanted but it seems its quiet radioactive, its keep on disintegrating with time and use.
Does “goal” mean “success” always? A funny thing about goal is if you don’t achieve it, it means you haven’t set your goal right. So it seems to me that people who achieve their goals are the only ones who had set their goals but the reverse is not true. Even if you set your goal there is no guarantee you will achieve it and people will say you haven’t set your goals correctly.
I know the above paragraph is quiet confusing and portrays “non sense”. But those are the real thoughts come in my mind when I think about setting my goal. You can see above that the problem and solution both are contradicting themselves.
One more term I recently heard was “short term goal and the Long term goal”. This is a smart invention, so if you feel like not achieving your prior set goal or your decision seems to be going in wrong direction, you should switch to short-term goal to change your final goal. But this term convinced me as bicycle was my short-term goal at the tender age but had I thought of car as a “long term goal” that time. So I can by the fact that we can have short-term goals but this long-term goal is still an open question to me.
I want to deep dived in my inner self and ask him what drives him to set a goal. Does goal mean a “desire”? When you see people adoring a leader or a businessman, you always want to become the same,” For what” I guess for same kind of adoring and appreciation you want. I want to become popular, people should follow my instincts, and they should talk about my good works and me all the time. So it feels like “desires” are directing us to set our goals. Money could be one of the factor but lot of people deny that they set their goals on the basis of money, it should be something related to self esteem.” Self esteem”, the word reminds me of the management lecture in my graduation that a man works for need first, then desire then self esteem. So we got three categories of goals then, what should fall under short term and long term and what lies beyond self-esteem is still a question.
Before my graduation “I always want to become an artist”. I entered college and got exposed to music, learned drum from a senior and practiced a lot then “I always want to become a drummer”. Eventually I started liking programming and it started fetching my interest so then “I always want to become a programmer”. You must be wondering why I am writing this “I always want to…” in quotes, because I want to show you that the answer of question “What is your goal” is based on the time when your are asking the question. If somebody had asked this question before my graduation I would have become an artist, but then what would happen to the drum and programming I enjoyed a lot as one of my passions. Does it simply mean that I have to live my life with a stupid decision of setting my goal as an artist and sacrifice other things, I could have enjoyed and make my goals too. This is the reason I always have doubt on the singularity of the word “goal”.
I think people who set their goals sacrifice a lot unknowingly other things they can do. I can be a programmer, drummer and an artist at the same time but my goals says I should be expert of any of them and showcase my dedication and expertise to the outside world. I have two options –I can enjoy all of them without setting a goal and end up like a normal person (Mr. Nobody) or master one of them and end up like a champ (Mr. Everybody). The later has a pain attached of leaving other two and million of things of my interest I would get to exposed in future.
Setting your goal is like practicing “Celibacy”. Why should I choose my life to be “virgin” on my own? What is pushing me to do that? I do not want to sacrifice all the things my destiny has planned for me .I got one life and don’t want to waste it with setting a stupid goal and chasing it all the time. I will keep on exposed to the material things and will use “short term goal” whenever I want. Today is a wonderful day, which prompted me to take lifetime decision (oops…not a goal) that I would never ever think of setting my goal or goals. Goals are for the losers who don’t want to see the better world they can actually see. Their paths are so narrow and gradually shrink with time .I want to see wide, wide open, all over the sky, experience everything I can do or I want to do. Doesn’t matter I would be a Mr. nobody, my inner self will be happy and appreciate me always. I am a “no goal” guy now and I am proud of me for not setting up a goal.
rajsingh.tarun@gmail.com
Friday, January 16, 2009
Querying of Patient Medical or Diagnostic data using Biometrics
For Finger Scan’s, an economical hardware is readily available and an algorithm to match with the saved finger print data making it a good tool for authentications.
Most of the Picture Archival / Patient Information servers carrying a patient database use name/numbers as key for searching patient info.
The method of Querying of Patient Medical / Diagnostic data using biometrics can be very efficiently used if the entire hospitals have a common network to query from.
By the time I was struck with the idea of using the biometric finger scan as an identifier for searching patient info it was too late as it is completely and comprehensively covered under U.S. Pat. No. 20060293925 by Dr. Leonard Flom in the year 2006.
The patent covers an idea of a System for storing medical records accessed using patient biometrics. The Abstract is as follows: A system for viewing and updating medical records using patient biometrics including at least one biometrics database including a plurality of biometric identifiers, at least one records database including a plurality of medical data records, at least one biometrics reader for receiving two or more biometric identifiers from a patient, a central records processor, software executing on the processor for querying the at least one biometrics database to verify the two or more biometric identifiers, and software executing on the processor for retrieving a medical data record corresponding to the two or more biometric identifiers from the at least one records database.
I am currently working on two of the ideas as a hobby project for open source and non-commercial use and definitely without violating the USPTOs United States patent law for U.S. Pat. No. 20060293925
- In Picture Archival / Patient Information servers resolving patient biometrics into DICOM identifier enabling querying using patient biometrics
- Adding patient biometrics tag in DICOM set
Keep watching..
Friday, January 9, 2009
Unique SOP Instance UID for every frame of a MultiFrame Image
The information object and the service class are the two fundamental components of DICOM. Information objects define the core contents of medical image, and service classes define what to do with those contents. The service classes and information objects are combined to form the elemental and functional units of DICOM. This combination is called a service-object pair, or SOP. Since DICOM is an object-oriented standard, the combination is actually called a service-object pair class, or a SOP class.
DICOM defines a series of storage SOP classes. When the attributes in the information object and the variables of the service class are populated by values representing a real patient, a particular imaging equipment, and a resulting image, the SOP class becomes a SOP instance (object of SOP class) and is assigned its own identifier.
DICOM standard suggests objects to be identified in such a way that each system that generates data can create an identifier for the data that is guaranteed to be unique. This is the unique identifier (UID). UIDs are made up of a sequence of numeric components separated by dots.
UIDs globally and uniquely identify an object which means that two different objects, even if they are not of the same type or do not appear in the same context, cannot have the same UID. With the aid of UIDs it is possible for related data objects to be sent by separate routes to an archive system and the linkages can be restored on arrival.
When there is a change and if the modified instance is sent to a PACS (Picture Archiving and Communication System) without creating a new instance, the PACS may reject it and keep the copy received before. Many servers do so and DICOM states explicitly there shall be no predictions what a Service Class Provider does when receiving an Instance already present in local storage.
One typical problem observed while transferring a single frame of a MultiFrame image to DICOM server (e.g. conquest) is that the single frame image overwrites the same MultiFrame image due to the usage of common SOP Instance UID. The problem can be depicted below:
Tuesday, December 30, 2008
Playing with I2C
Philips developed I²C (Inter-Integrated Circuit) bus, in the 1980s. I²C is a multi-master low bandwidth serial bus for short distance on board communications that is used to attach low-speed peripherals to a motherboard or an embedded system. All devices are connected through two bidirectional wires: Serial Data (SDA) and Serial Clock (SCL). Typical voltages used are +5 V or +3.3 V.
The I²C design has a 7-bit address space with 16 reserved addresses, so a maximum of 112 nodes can communicate on the same bus. The most common I²C bus modes are the 100 kbit/s standard mode and the 10 kbit/s low-speed mode. Recent revisions of I²C can host more nodes and run faster (400 kbit/s Fast mode, 1 Mbit/s Fast mode plus or Fm+, and 3.4 Mbit/s High Speed mode), and also support other extended features, such as 10-bit addressing.
I²C has a master/slave protocol. The master initiates the communication by issuing a start condition. This condition informs all the slave devices to listen on the serial data line for their respective address. Then the master sends the address of the target slave device and a read/write flag. The slave device with the matching address responds with an acknowledgment signal. Communication proceeds between the master and the slave on the data bus, when the communication is complete, the master issues a stop condition.
[References]
http://en.wikipedia.org/wiki/I2C
http://www.embedded.com/story/OEG20010718S0073
http://dmoz.org/Computers/Hardware/Buses/I2C/
http://www.esacademy.com/faq/i2c/
http://www.nxp.com/products/interface_control/i2c/index.html
http://www.nxp.com/acrobat_download/literature/9398/39340011.pdf
http://www.standardics.nxp.com/support/documents/i2c/pdf/i2c.bus.specification.pdf
The DDC (Display Data Channel) is a digital connection between a computer display and a graphics adapter that allows the display to communicate its specifications to the adapter. The standard was created by the VESA (Video Electronics Standards Association). The DDC link is carried on three pins – data, clock and ground – in a 15-pin VGA connector, a DVI connector or an HDMI connector. The current version of DDC, called DDC2B, is based on the I²C bus. DDC2B allows only one master – the graphics adapter. The monitor (e.g. a CRT or LCD) contains a read-only memory (ROM) chip programmed by the manufacturer with information about the graphics modes that the monitor can display.
[References]
http://en.wikipedia.org/wiki/Display_Data_Channel
http://www.vesa.org/summary/sumddcci.mht
http://ddccontrol.sourceforge.net/
Couple of years ago, I was assigned with a project to implement application specific APIs to communicate to a custom made LCD monitor (SE216). The application was running on a RTOS and was using a proprietary display adapter card. The custom made monitor was though DDC compliant but the protocol was not exactly DDC/CI or DDC2Bi. The communication of the display controller inside the LCD was based on RS232 and to offer the DDC communication option additional hardware was designed to translate the DDC communication into RS232 commands. Based on the Specification of the DDC-Protocol for the SE216 I implemented the following APIs for Reading:
Monitor Backlight Range
Monitor Backlight Level
Monitor Backlight Margin
Monitor Run Times
Monitor Temperature
Monitor Current Video Source
Active Video Sources avialable to MonitorMonitor Video Timings
Monitor Serial Number
Monitor Firmware Versions
Monitor Status
for setting:
Monitor Backlight Level
Backlight State(ON/OFF)
Monitor Video Source
After the implementation, It was time to test. I felt the best way to test is by analyzing the DDC communication so started looking for a I²C analyzer.
The monitor vendor suggested me to use the Traceii XL from Telos but it’s an expensive tool. I got demonstration done by a local guy for I2C BUS Monitor Plus from MCC but I found its not exactly meeting my requirement.
I searched over the internet and did come across some products for sniffer and master applications. Few of the sites and approximate prices are:
http://www.prodigytest.com - $1400
http://www.i2cchip.com - $69.95
http://www.saelig.com - $79.00 to $499.00
http://www.demoboard.com - $199.00 to $259.00
http://www.jupiteri.com - $299
http://www.totalphase.com - $300
http://www.teamfdi.com - $499.00
http://www.avitresearch.co.uk - £75.00 to £250.00
http://www.telos.info http://www.telos.de - Euro 1100
http://www.corelis.com - $3,950
Then while some more searching I came across a webpage by Nicolas Boichat, which had a reverse engineering method of analyzing I²C transfers by using a parallel port of the PC. Implemented it and started using it.
[Reference]
http://www.boichat.ch/nicolas/ddcci/method.html
Meanwhile I brought Beagle I2C/SPI/MDIO Protocol Analyzer from Total Phase, but I still loved to use the parallel port program (pportmon) to analyze.
The Parallel Port monitor method is as follows.
[1] Needed hardware
- A monitor supporting DDC and A computer running Windows 2000/XP, with a graphic card supporting DDC/CI or any other application capable of controlling the monitor (Basically two systems communicating over I²C).
- Another computer running Linux, with a parallel port, and a relatively fast processor.
- An old 15-pin VGA cable or DVI Cable.
- A straight-through parallel cable, with 25 pins at both side.
The I²C bus on which DDC/CI data is transferred uses 2 wires: SCL (clock), and SDA (data). On the VGA cable, these wires need to be connected on pins 15 (SCL) and 12 (SDA).Open the VGA cable by removing the plastic cover on a short length (3-4 cm), and find with an multimeter which wires are connected to pins 12 and 15 (no need to strip all the wires, just pierce them with a pin, without breaking them).
Connect wire 12 of the VGA cable to pin 13 of the parallel cable, and wire 15 to pin 12. In a DVI Cable pin 6 is DDC Clock and pin 7 is DDC Data. So connect 7 of the DVI cable to pin 13 (Select In – STATUS) of the parallel cable, and wire 6 to pin 12(Paper Out/Paper-End – STATUS). I also suggest binding of both the grounds (pins 18 to 25 on parallel port, pin 10 on VGA cable and pin 15 on DVI cable). With this tapped cable I²C transfer can be monitored using the parallel port.
[3] Analyze transfers
Connect the VGA cable between the computer running Windows and the monitor (communicating over I²C), and the other side of the parallel cable to the computer running Linux.On the Linux computer, download the source file pportmon.c from, and build it with:
# gcc -O2 pportmon.c -o pportmon
To run at root prompt simply type:
# ./pportmon
It will monitor I²C transfers for a few seconds.Change quickly a value (for example brightness), by one step (click only one time on the arrow on the scrollbar).
pportmon should print something like :
-->Start
-->Byte : 01101110 0x6e==>Address : 0x37 (W)
-->Byte : 01010001 0x51-->Byte : 10000100 0x84
-->Byte : 00000011 0x03
-->Byte : xxxxxxxx 0xXX [index]
-->Byte : 00000000 0x00
-->Byte : yyyyyyyy 0xYY [new value]
-->Byte : zzzzzzzz 0xZZ [checksum]
-->Stop (8, 1) [8 = byte count, 1 = bits left on the last byte (1 is ok)]
If you have something totally different, for example with another address, or with stops occurring while there are bits left, pportmon could probably not get enough CPU time to get all the data (this is not a real-time process, so sometimes the OS give CPU time to others process), so just retry. If it still doesn't work, try to stop CPU consuming processes, and increase the priority of the process by running it using nice (otherwise try to use a faster computer or slow the bus speed of I²C).
# nice -n -15 ./pportmon
Running on Windows
I modified the program pportmon.c to run on windows by using the inpout32 library. InpOut32 is a DLL file which can send a data to parallel port and which can return the data in the parallel port. This file with source code can be downloaded for free from
http://logix4u.net/Legacy_Ports/Parallel_Port/Inpout32.dll_for_Windows_98/2000/NT/XP.html
To run on windows the program pportmon.c needs the following modifications:
[1] Declaration
short _stdcall Inp32(short PortAddress);
void _stdcall Out32(short PortAddress, short data);
[2] Changing the read call
buf[i++] = inb(STATUS);
to
buf[i++] = (unsigned char)Inp32(STATUS);
[3] Addition of the following function
After the above modifications, I compiled it for both console and dialog based applications in Visual C++ to get a wonderful analysis of the DDC communications. The application will be bit slower compared to running on Linux. If it is slow for you too, try to stop CPU consuming processes, and increase the priority of the thread by using
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
(Otherwise try to use a faster computer).
I²C Send and Receive
There is a program available for I²C interfacing via PC parallel port on the webpage of Mika Iisakkila.
[Reference]
http://users.tkk.fi/iisakkil/stuff.html
The program implements I2C master-mode by bit-banging a couple of lines on the PC parallel port. Includes C source portable for both Borland and Microsoft compilers as well as a pdf schematic of the needed interface circuit. The method is complicated but is totally opto-isolated.
The source can be downloaded from http://users.tkk.fi/iisakkil/pc_i2c.zip and the schematic from http://users.tkk.fi/iisakkil/i2c_adap.pdf
Other References:
http://i2canalyzer.sourceforge.net/http://www.maxim-ic.com/appnotes.cfm/an_pk/3230
http://pdfserv.maxim-ic.com/en/an/AN3230.pdf
http://www.programmersheaven.com/download/19695/download.aspx
http://www.programmersheaven.com/download/6573/download.aspx
http://oap.sourceforge.net/oap/i2c_para_module/i2c_para_module.pdf
http://www.nxp.com/#/pip/pip=[pip=PCA9564_4]pp=[t=pip,i=PCA9564_4]
http://owfs.org/index.php?page=i2c-parallel-port-design
http://www.gsp.com/cgi-bin/man.cgi?section=4&topic=lpbb
http://www.jcoppens.com/globo/gl4pre/t_common/data/7405-i2c.pdf
Going ahead I found a microcontroller program of I²C implementation in C for devices that DO NOT have I²C hardware. The code did not use interrupts either, and was useful for Master application but not for Slave use.
[Reference]
http://www.mikrocontroller.net/topic/22461
I again modified the program pportmon.c to send and receive I²C data over the parallel port as well making use of the DATA0 and DATA1 line of the parallel port.
To take care of pull-up, open collector, bus conflicts, excessive current drains and voltage level mismatch an open collector IC 74HC07 can be used. Using a multimeter, measure the voltage across SDA to ground and SCL to ground of the I²C device. Use this voltage level to connect the Vcc of 74HC07 as shown below:
To send and receive I²C data the program pportmon.c needs the following modifications:
[1] Declaration
unsigned char _i2c_error; // bit array of error types
int usleep(long usec);
void I2CBitDly(void);
void I2CSCLHigh(void);
void I2CSendAddr(unsigned char addr);
void I2CSendByte(unsigned char bt);
void I2CSendStop(void);
unsigned char _I2CGetByte(unsigned char lastone);
#define I2CGetByte() _I2CGetByte(0)
#define I2CGetLastByte() _I2CGetByte(1)
[2] Setting DATA0 and DATA1 to HIGH
In the main function call Out32 (DATA, 0xFF);
[3] Implementing micro second sleep
On windows there is only Sleep with millisecond granularity. select system call can be used to create a microsecond sleep. The use of select forces to include the winsock library (and select won't allow to be called without any socket), which has to be initialized in main function
like:
WORD wVersionRequested = MAKEWORD(1,0);
WSADATA wsaData;
WSAStartup(wVersionRequested, &wsaData);
and the implementation
[4] Functions to send and receive data over I²C bus
I compiled the above functions in dialog based VC++ application and used it for communicating a slave device (which responds to bus speed of ~30kbps) successfully. The results are not 100% satisfactory though. The VC++ dialog based application has been built on MS VC++ 6.0 and tested on windows XP. It has following three parts:
[1] Tracing I²C data
- Click Start Trace to start a thread for analyzing the data available on SDA & SCL lines (same as pportmon). The analyzed data is displayed in Trace listbox.
- Click Stop Trace to kill the above thread and is only active when the trace thread is running.
- Click Clear Trace to clear the Trace listbox.
- Click Save Trace for exporting the contents of Trace listbox to a file for archiving the analysis and is only active when the trace thread is not running.
- Use the 1st row of Edit boxes and button for sending data over I²C bus.
- Enter the device Address (in HEX) in 1st Edit box.
- Enter the Command (in HEX) in 2nd Edit box.
- Enter the data bytes (in HEX) in subsequent Edit boxes. If the number of data bytes to send are less than the Edit boxes provided, Enter S or s. Data will be sent over I²C bus till an s or S is encountered and then a STOP byte is sent.
- Click Start Trace an then Click Transmit/Send.
- Observe for the sent data in Trace listbox and compare for accuracy.
- Use the 2nd row of Edit boxes and buttons for receiving data over I²C bus.
- Enter the device Address (in HEX) in 1st Edit box.
- Enter the command (in HEX) in 2nd Edit box. If there is no command to send then enter s or S.
- Enter the Address (in Hex) in 3rd Edit box. If there is no Address to send the enter s or S.
- Click Start Trace an then Click Transmit/Send.
- Observe for the sent data in Trace listbox and compare for accuracy.
- Enter the Number of Bytes to Read (in decimal – 0 to 255) in last Edit box.
- Click Receive.
- Observe for the received data in Trace listbox and compare for accuracy.
The installable and source code can be downloaded from the below link using SVN
https://i2c.svn.sourceforge.net/svnroot/i2c
and use the application at your own risk, I am not responsible if it destroys your computer, monitor or anything else.
If you like to comment/add/support then please mail me at irfan.net@gmail.com