Dear All, Its been almost a year working on Cortex-M3 (LPC1768, to be specific). Have developed an application code, with almost all peripherals. From the day 1st of development, i have been of the view to develop a generalized device driver file (actually library) which can be used directly by my colleagues and for future projects. with this view, i have tried to write whole code.
In the application developed by me, i have written different C source files for all peripherals, (Eg: uart.c, i2c.c, dac.c, qei.c, ...etc) with their respective header files (Eg: uart.h, i2c.h, dac.h, ...etc) . The declarations of global variables (as externs) and the global functions are done in the respective headers. The code looks nicely structured and organised. :)
The real problem starts when my colleagues use these (as i call them) generalized driver files to create their own projects. They are compelled to use the global variable names that i have used. Hence the driver files are not generalized in real sense. But then i also have limitation as cannot pass or return a buffer used in interrupt of peripheral (specially the communication buffers viz. uart-buffers, spi-buffers,...etc) Also they have to include many header files (and remove some) in all the source files depending upon peripherals used in their application.
The real question is, how can i make these files really generalized and hence have a library which can be included directly to the project irrespective of whether a peripheral is used or not?
Have googled. But could not find any documentation giving the detailed explaination about writing code that are generalized and can be used to create library.
I cant develop the code using any other language then C. Kindly guide.
Err, no - "global variables" does not fit particularly well with "nicely structured"!
Ooops. OK. Kindly provide some guidelines or detailed step for a nicely structured code.
They always want to be "guided" - not make an effort themselves !
Dear Andrew, Thank you for the links. Earlier, i was searching with keywords "how to write a generalised library code", "writing device drivers for lpc1768", "writing code for building library" and so on... But your keyword "api design" opened a new direction. Thanks for the valuable guidance. :)
Regards, Dhaval
Dear Tamir, A successful person never Gloats and one of the sign of a true hero is Humility.
i have mentioned, ... . with this view, i have tried to write whole code.
It may happen, that the person asking the question may have sometimes searched, but may not have found a good article. May be sometimes the keywords used for google search may not be in correct direction. May be that the person is having a tough day. :|
Nobody comes in this world learning everything from their Mother's womb. Everybody learns after their birth. If you cant guide, just ignore the post. Dont write comments that reflects your anger on the person for asking the question.
Keep Smiling and be Happy. :)
Learnt that...
1. A generalized and a good structured code must not have interrupt handlers in the library source files. 2. All the parameters are passed using pointers or structure & structure pointers. 3. No Global Variables.
Dear Experts, kindly contribute more points to the list. This may help in improving the beginner programmers' skills.
Regards, Dhaval :)