• Tag Archives compile
  • msp430- coding interrupts for mspgcc

    I am just an idiot, but thats my opinion. For those with MSPGCC compilers, we have a more difficult time finding code examples, and many of the code examples given either don’ explain very well (cryptic Coding, un-commented code) or they are for the CCS or IAR, and they dont use the same syntax as the MSPGCC compiler. So here is how to create an interrupt handler for non-PUC/POR interrupts.

    I will not go into interrupt vector masking, that is beyond me at this moment, but im not saying that i wont cover it later on, once i understand why you would want to mask it…..
    So lets start at what headers and other setup items you need before, creating the interrupt handler.
    First the signal.h has to be included into your code. #include<signal.h>
    this will give you access to the special function of
    interrupt(VECTOR ) service_routine (void) {/*interrupt code*/ }

    this is the same as #pragma vector=WDT_VECTOR
    __interrupt void watchdog_timer(void){ }

    These are the Defined vectors for interrupts right from the header files.(mspgcc headers)

    #define PORT1_VECTOR 4 /* 0xFFE4 Port 1 */
    #define PORT2_VECTOR 6 /* 0xFFE6 Port 2 */
    #define USI_VECTOR 8 /* 0xFFE8 USI */
    #define ADC10_VECTOR 10 /* 0xFFEA ADC10 */
    #define TIMERA1_VECTOR 16 /* 0xFFF0 Timer A CC1-2, TA */
    #define TIMERA0_VECTOR 18 /* 0xFFF2 Timer A CC0 */
    #define WDT_VECTOR 20 /* 0xFFF4 Watchdog Timer */
    #define NMI_VECTOR 28 /* 0xFFFC Non-maskable */

    all the interrupts should be self expainatory, vector = the source of the interrupt.

    since now we have all the basics we can now right a small program that uses interrupt, we will just create a small WDT interval timer.
    /*WDT interval timer- code based on msp430 examples*/
    //compiler=mspgcc
    #include<msp430x22x2.h>
    #include<signal.h> //interrupt service routine
    #include <io.h> //usually included on msp430 header, but for sfr register access.
    void main(void) {
    WDTCTL = WDT_MDLY_32; //~30mS intervals
    P1DIR |=BIT1;
    IE1 |= WDTIE; //enable interrupt
    _BIS_SR(LPM0_bits + GIE); //not low power mode and enable interrupts
    }//end of main
    //interrupt service routine
    interrupt(WDT_VECTOR) watchdog_timer(void)
    {
    P1OUT ^= BIT1;
    }//end of interrupt

    this should give you a good start on your Interrupts but there is still one thing that you may need. Changing the power modes when a interrupt is being serviced, the power mode will revert back to the power mode that it was in when the interrupt was called.
    There are 2 functions that we can use to clear or set power modes while in an interrupt.
    First one is to set the mode on exit of the routine, this is done by changing the copy of the status register that is saved to the stack. _BIS_SR_IRQ( ... )
    you would use this the same way you would use the _BIS_SR(…)

    The second one will clear the bits you select _BIC_SR_IRQ(...) same usage as the other, except it will just clear the bits not modify them.
    ***the use of _BIx_SR_IRQ() should only be used in an interrupt service request, the compiler will give you a warning but will produce the correct code if you use it anywhere else.***
    ****remember to enable Interrupts by using BIS_SR(GIE) or eint()****

    Edit 6-23-2011

    MSPGCC Uniarch branch of mspgcc has been released, It supports newer chips like the msp430G2453 (the newer 20pin DIPs) This is an initiative to unify the current branches of mspgcc. Interrupts for this version is slightly different. Once I test it or get confirmation from another user I will post the correct format for uniarch branch……but what would be better would be unify the branches so we don’t have so much confusion with these version discrepancies and nuances of the trees.

    As of right now uniarch is still being worked on and there and is not fully recommended unless you need support for the newer 20pin Dips (G2x53 G2x52).  Please don’t let my opinion dissuade your choice of compiler, mspgcc works great for me but uniarch may work better for you.

     

    Thank you Tissit for your Comment

    “In current gcc, you can (should) include msp430.c instead of the specific header and use the -m switches (in a Makefile) to tell the compiler which chip you’re using. It will find the right headers automatically. “

    If I forget something let me know and I will update


  • Easy Way for custom kernels

    Borrowed from hackaday,
    Borrowed from hackaday,

    I am a regular Browser of certain DIY and tech sites just because they always have something interesting, or some new idea or technology that may be useful. Today I found this post, http://hackaday.com/2009/08/25/kernelcheck-kernel-compiler/ and it interested me, a quick and easy way of Downloading patching and compiling the kernel…..I thought ‘WOW’ this is one of those packages that will vanish in a few weeks and it prolly buggy, no good support, and not a big user base with comments from ’01……..so i downloaded it and installed it, it has a few interesting dependencies like qt3 and a few other small libs…..now its installed, i go over the over simplified PDF….fairly easy to use so i go at it…..I was surprised how well it worked right out of the “package”,  I went ahead and updated the kernel info with a click of a button, i know which kernel is installed currently, i know what the current stable dev kernel is,  the current patch and a slew of other info that i really didn’t need… so next i decided i wanted a customized kernel, so i click 0n the custom, chose the current stable dev, with no patches (i didn’t try but you can go back to earlier versions of the Kernel) a few other options i chose as well as manual config, pack into a .deb package, there a bunch of other choices as well… so i did a basic config just to get it to compile my new kernel…..in less than 4 hours my new kernel was ready to be used, so  i loaded it up in the VMbox and took it for a spin, it loaded and worked just as if i had done this manually…..so I am pleased that some one has created a great tool like this to make life a little bit more easy for me….

    So is this going to Help those out there that want to customize there system? well a little, it will make the process a little faster and creating a custom kernels you will still need to know what you are doing when configuring it……My over all opinion of this software, I think its great and someone should have come up with this sooner. What i think is needed is some more advanced options for people building kernels for other systems, or cross-compile options, but other wise its a Great Tool with a nice intuitive GUI.

    As for support if you run into problems, well i haven’t had to deal with there mailing list but they do have one and it looks like this is an ongoing project for them. I am usually pretty critical of software becuase i have been let down so many times, but this one I really cant complain about, Its just a Great tool for your linux toolbox.

    Now just go to there site and check out the program for yourself http://kcheck.sourceforge.net/