Prao wrote:
How do I ensure that all these operations are done using a base 1ms timer.
Do I use both the PITs and divide the timer work between the two?
Or I use separate timers for each , like both PITs and the GPTs.
Don't use PIT-s directly. If you try to do any actual work inside interrupts, you are entering a world of pain.
I assume you have a simple main() function which contains a never-ending loop. Is that correct?
All processing MUST be done inside the main loop. It's very simple to implement.
You add some flags which are accessible for both interrupts and main loop. You need one flag for each period - 1ms, 30 ms and 300ms. They're just volatile integers in global scope. The interrupt handler only sets the flag (well, actually your do_tick_Xms() function does).
The main loop polls the flags. When main loop finds that a flag has been set, it does the processing for this period. It doesn't get any simpler than this 
----- begin main.c -----
volatile unsigned int g_tick1ms = 0;
volatile unsigned int g_tick30ms = 0;
volatile unsigned int g_tick300ms = 0;
int main(void) {
while (1) {
if (g_tick1ms) {
// Clear the flag
g_tick1ms = 0;
// Process the 1 ms tick
// ... your stuff here ...
}
if (g_tick30ms) {
// Clear the flag
g_tick30ms = 0;
// Process the 30 ms tick
// ... your stuff here ...
} if (g_tick300ms) {
// Clear the flag
g_tick300ms = 0;
// Process the 300 ms tick
// ... your stuff here ...
} }
}
----- end main.c -----
----- begin interrupts.c -----
extern volatile unsigned int g_tick1ms;
extern volatile unsigned int g_tick30ms;
extern volatile unsigned int g_tick300ms;
void do_tick_1ms() {
g_tick1ms = 1;
}
void do_tick_30ms() {
g_tick30ms = 1;
}
void do_tick_300ms() {
g_tick300ms = 1;
}
----- end interrupts.c -----
A word of warning: sharing any data between an interrupt handler and main loop is tricky. If you only exchange an integer (or any other atomic data) just declare it volatile and you'll be fine. Any non-atomic data (strings, arrays, structs, doubles etc) must be protected from simultaneous access. It's done by locking the data and this is where it gets complicated
Hopefully you don't need that, however.
Message Edited by DaStoned on 2009-05-08 03:01 PM