??? 06/29/10 23:25 Read: times |
#176984 - Guidelines for periphrial drivers |
I'm developing a project that uses many of the peripherals on a Silabs C8051F340. Initially, I tried to create an implementation flexible module for each peripheral so that I could develop and test the code once and have a ready to use module for later projects. That started out great, but as I'm learning, many peripherals use common SFRs making such modules very difficult to achieve.
Here's my real world example. I am using Silabs SMBus which uses T0, T1, T2H, or T2L as it's clock source. I started with T1 since it was used in the Silabs SMBus example code. Things were fine until I added in my uart0 module which uses T1. No problem. I changed the SMBus code to use T0 and created #define variables to control whether the module uses T1 or T0 and calls the correct initialization code. Now I go to add in the TCP/IP stack and find out that it uses T0 somewhere in the pre-compiled library, and that it sets the T0 prescaler, which is shared by T0 and T1, to sysclk / 48. So now, not only do I have to move the SMBus code to T2H or T2L, which gives me more #defines and more unused code in the module, but I realize that my T0 and T1 initialization routines would not have worked anyway if my baudrate switcher routine for uart0 changed the prescaler. Given this experience, I'm left wondering how one best codes a peripheral module so that it's reusable but doesn't trample over shared resources. Thoughts? --David |
Topic | Author | Date |
Guidelines for periphrial drivers | 01/01/70 00:00 | |
My recommendation... | 01/01/70 00:00 | |
Advantage | 01/01/70 00:00 | |
So don't trample over shared resources, then! | 01/01/70 00:00 | |
Maybe someone have developed/modified | 01/01/70 00:00 | |
SMBus uses 2 timers on F34x series | 01/01/70 00:00 | |
well ...![]() | 01/01/70 00:00 |