RobG 1,892 Posted January 14, 2011 Share Posted January 14, 2011 Here's a little code template I have created. Not sure what I am going to use it for, but someone might find it helpful. Handling of the interrupts is done in main rather than in interrupt routine itself. #include "msp430g2231.h" #define EV_TIMER BIT0 #define EV_PORT1 BIT1 #define EV_WDT BIT2 #define EV_USI BIT3 unsigned char events = 0; void main(void) { WDTCTL = WDTPW + WDTHOLD; // stop WDT // configure all here __bis_SR_register(LPM0_bits + GIE); // switch to LPM0 with interrupts while(1) { while(events) { if(events & EV_TIMER) { events &= EV_TIMER; // do your thing //clear TAIFG, etc. //enable interrupts, main, CCR0, CCR1, etc. } else if(events & EV_PORT1) { events &= ~EV_PORT1; // do your thing //P1IFG &= ~BITn; // clear IFG //P1IE |= BITn; // enable interrupt } else if(events & EV_WDT) { events &= ~EV_WDT; // do your thing IFG1 &= ~WDTIFG; //IE1 |= WDTIE; // enable WDT interrupt } else if(events & EV_USI) { events &= ~EV_USI; // do your thing USICTL1 &= ~USIIFG; //USICTL1 |= USIIE; // enable interrupts } } __bis_SR_register(LPM0_bits); // switch to LPM0 } } // WDT interrupt service routine #pragma vector=WDT_VECTOR __interrupt void Watchdog_Timer (void) { //IE1 &= ~WDTIE; // disable WDT interrupt events |= EV_WDT; __bic_SR_register_on_exit(LPM0_bits); // exit LPM0 } // Timer A interrupt service routine #pragma vector=TIMERA0_VECTOR __interrupt void Timer_A (void) { //disable interrupts, main, CCR0, CCR1, etc. events |= EV_TIMER; __bic_SR_register_on_exit(LPM0_bits); // exit LPM0 } // Port 1 interrupt service routine #pragma vector=PORT1_VECTOR __interrupt void Port_1(void) { //P1IE &= ~BITn; // disable interrupt events |= EV_PORT1; __bic_SR_register_on_exit(LPM0_bits); // exit LPM0 } // USI interrupt service routine #pragma vector = USI_VECTOR __interrupt void USI_TXRX (void) { //USICTL1 &= ~USIIE; // disable interrupts events |= EV_USI; __bic_SR_register_on_exit(LPM0_bits); // exit LPM0 } // TODO Add ADC routine NatureTM 1 Quote Link to post Share on other sites
NatureTM 100 Posted January 14, 2011 Share Posted January 14, 2011 Hey, that's interesting. I've been reading the uC/OS-III manual recently. This reminds me of how it deals with interrupts. It would be neat to implement priorities and communication between processes too. I guess you might now have much RAM or flash left over for your actual application if you did all that though. Quote Link to post Share on other sites
RobG 1,892 Posted January 14, 2011 Author Share Posted January 14, 2011 When it comes to priority, all you need to do is reorder if-else blocks. For example, we are inside EV_PORT1, EV_WDT and EV_TIMER interrupts occur, our current block finishes, if-else block is executed again, EV_TIMER block is executed, and so on. Quote Link to post Share on other sites
GeekDoc 226 Posted January 14, 2011 Share Posted January 14, 2011 I've been reading the uC/OS-III manual recently. How is that book? I haven't cracked mine yet; haven't even looked at the terms of the "$1000" license we won. Quote Link to post Share on other sites
NatureTM 100 Posted January 15, 2011 Share Posted January 15, 2011 I've been reading the uC/OS-III manual recently. How is that book? I haven't cracked mine yet; haven't even looked at the terms of the "$1000" license we won. Eh. Parts of it make me say, "that's really clever," or it shines some light on some other related topic about OS'es I was wondering about. The rest of the time it's like reading a technical document. Sometimes, the authors of books like this try to use some humor or analogies to make it an easier read. This guy didn't. There were several times I wanted to skip using the OS altogether. There's a fair amount of extra coding involved with using it. Now that I've read a little more, I think it's worth it. I've got some planning done on paper, and some parts arrived today, but I haven't actually written any code yet. Quote Link to post Share on other sites
GeekDoc 226 Posted January 15, 2011 Share Posted January 15, 2011 I've got some planning done on paper, and some parts arrived today, but I haven't actually written any code yet. You're way ahead of me. I just have the abstract I submitted. I don't think I'll get it done for the contest. :? Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.