This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Hi, have you an StarterWare "sleep" example ?

Other Parts Discussed in Thread: OMAPL138, OMAP-L138, SYSBIOS

 I have execute this intructions, but doesn't work, the OMAP doesn't go in sleep but go in normale execution :

"SysCfgRegistersUnlock();

asm ( "    teq    r1, #0\n\t");   

asm ( "    mcr p15, #0, r1, c7, c0, #4\n\t" );    

SysCfgRegistersLock();"

Can someone help me ?

  • Hi Sergio,

    Which StarterWare are you using?

    Regards

    Sandhya

  • Hi,

    My version is OMAPL138_StarterWare_1_10_03_03 , but i thing that the version is not important.

    I want to implement ARM Wait-For-Interrupt Sleep Mode function par. 10.6.1  document spruh77.pdf.

    Regards

    Sergio

  • Sysbios OMAP-L138

    I am working with "OMAPL138_StarterWare_1_10_03_03" application software without Linux or other OS.

    In this application there is "SWIHandler" assembler function :

    ;******************************************************************************
    ;*                  Function Definition of SWI Handler
    ;******************************************************************************    
    ;
    ; The SWI Handler switches to system mode if the SWI number is 458752. If the
    ; SWI number is different, no mode switching will be done. No other SWI are
    ; handled here
    ;
    SWIHandler:
            STMFD    r13!, {r0-r1, r14}       ; Save context in SVC stack
            LDR      r0, [r14, #-4]           ; R0 points to SWI instruction
            BIC      r0, r0, #MASK_SWI_NUM    ; Get the SWI number
            CMP      r0, #458752
            MRSEQ    r1, spsr                 ; Copy SPSR  
            ORREQ    r1, r1, #0x13            ; Change the mode to Supervisor
            MSREQ    spsr_cf, r1              ; Restore SPSR
            LDMFD    r13!, {r0-r1, pc}^       ; Restore registers from IRQ stack

    How can I modify this function to go in supervisor mode and activate "sleep" mode ?

    Sergio.

     

  • Hi Sergio,
    I will be moving this query to OMAPL13x forum for better response.

    Regards
    Sandhya
  • Hi Sergio,

    I have used your code to put the ARM in WFI mode and seems to be working.

    When the MCR command executed then ARM will be in WFI mode, it won't proceed to next line until it get any interrupt (ARM)

    I have debug the code and observed that behavior, so I conclude that it is working.

    I have attached the following code, the D5 LED from OMAPL138 LCDK board, it won't glow up until SD card insert/removal interrupt get generated.

    It started glowing when you insert/remove the SD card on LCDK board.

    Please test it and let me know if any.

    I hope this helps.

    If you looking for any power management, then you can implement DEEPSLEEP or gate clocking the peripheral modules etc.,

    Please note that you have to use ARM project with "system_config.lib", better to use "ARM gpio" project and just replace with this lines.

    gpioCardDetect.c
    /**
     * \file    gpioCardDetect.c
     *
     * \brief   This is a sample application file demonstrating the use of
     *          a GPIO pin to generate an interrupt whenever an MMC/SD card
     *          is inserted or ejected from the Evaluation Module(EVM).
     */
    
    /*
    * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
    *
    *  Redistribution and use in source and binary forms, with or without
    *  modification, are permitted provided that the following conditions
    *  are met:
    *
    *    Redistributions of source code must retain the above copyright
    *    notice, this list of conditions and the following disclaimer.
    *
    *    Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in the
    *    documentation and/or other materials provided with the
    *    distribution.
    *
    *    Neither the name of Texas Instruments Incorporated nor the names of
    *    its contributors may be used to endorse or promote products derived
    *    from this software without specific prior written permission.
    *
    *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    */
    
    #include <stdio.h>
    
    #include "interrupt.h"
    #include "uartStdio.h"
    #include "gpio.h"
    #include "psc.h"
    
    #include "soc_OMAPL138.h"
    #include "evmOMAPL138.h"
    
    /* System Defines */
    #include "lcdkOMAPL138.h"
    #include "soc_OMAPL138.h"
    #include "hw_syscfg0_OMAPL138.h"
    
    /****************************************************************************/
    /*              LOCAL FUNCTION PROTOTYPES                                   */
    /****************************************************************************/
    static void Delay(volatile unsigned int delay);
    static void ConfigureIntGPIO(void);
    static void CheckCardStatus(void);
    static void SetupInt(void);
    static void GPIOIsr(void);
    
    /****************************************************************************/
    /*              GLOBAL VARIABLES                                            */
    /****************************************************************************/
    volatile unsigned char flag = 0;
    
    /****************************************************************************/
    /*             LOCAL FUNCTION DEFINITIONS                                   */
    /****************************************************************************/
    
    /* LED Configuration */
    
    /* Titus : GP6[12], GP6[13], GP2[12] and GP0[9] is mapped to D4, D5, D6, D7 LEDs on OMAPL138/C6748 LCDK boards */
    
    /* Pin Multiplexing bit mask to select GP6[12] pin. */
    #define PINMUX13_GPIO6_12_ENABLE    (SYSCFG_PINMUX13_PINMUX13_15_12_GPIO6_12  << \
                                        SYSCFG_PINMUX13_PINMUX13_15_12_SHIFT)
    
    /* Pin Multiplexing bit mask to select GP6[13] pin. */
    #define PINMUX13_GPIO6_13_ENABLE    (SYSCFG_PINMUX13_PINMUX13_11_8_GPIO6_13  << \
                                        SYSCFG_PINMUX13_PINMUX13_11_8_SHIFT)
    
    /* Pin Multiplexing bit mask to select GP2[12] pin. */
    #define PINMUX5_GPIO2_12_ENABLE    (SYSCFG_PINMUX5_PINMUX5_15_12_GPIO2_12  << \
                                        SYSCFG_PINMUX5_PINMUX5_15_12_SHIFT)
    
    /* Pin Multiplexing bit mask to select GP0[9] pin. */
    #define PINMUX0_GPIO0_9_ENABLE    (SYSCFG_PINMUX0_PINMUX0_27_24_GPIO0_9  << \
                                        SYSCFG_PINMUX0_PINMUX0_27_24_SHIFT)
    
    /* PINMUX for S2 and S3 on OMAPL138 LCDK boards */
    
    /* Pin Multiplexing bit mask to select GP2[4] pin. */
    #define PINMUX6_GPIO2_4_ENABLE    (SYSCFG_PINMUX6_PINMUX6_15_12_GPIO2_4  << \
                                        SYSCFG_PINMUX6_PINMUX6_15_12_SHIFT)
    
    /* Pin Multiplexing bit mask to select GP2[5] pin. */
    #define PINMUX6_GPIO2_5_ENABLE    (SYSCFG_PINMUX6_PINMUX6_11_8_GPIO2_5  << \
                                        SYSCFG_PINMUX6_PINMUX6_11_8_SHIFT)
    
    void PinMuxSetup_leds(void)
    {
         unsigned int savePinmux = 0;
    
         /*
         ** Clearing the bit in context and retaining the other bit values
         ** in PINMUX13 register.
         */
         savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(13)) &
                      ~(SYSCFG_PINMUX13_PINMUX13_15_12));
    
         /* Setting the pins corresponding to GP6[12] in PINMUX13 register.*/
         HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(13)) =
              (PINMUX13_GPIO6_12_ENABLE | savePinmux);
    
    
         /*
         ** Clearing the bit in context and retaining the other bit values
         ** in PINMUX13 register.
         */
         savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(13)) &
                      ~(SYSCFG_PINMUX13_PINMUX13_11_8));
    
         /* Setting the pins corresponding to GP6[13] in PINMUX13 register.*/
         HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(13)) =
              (PINMUX13_GPIO6_13_ENABLE | savePinmux);
    
    
         /*
         ** Clearing the bit in context and retaining the other bit values
         ** in PINMUX5 register.
         */
         savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(5)) &
                      ~(SYSCFG_PINMUX5_PINMUX5_15_12));
    
         /* Setting the pins corresponding to GP2[12] in PINMUX5 register.*/
         HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(5)) =
              (PINMUX5_GPIO2_12_ENABLE | savePinmux);
    
    
         /*
         ** Clearing the bit in context and retaining the other bit values
         ** in PINMUX0 register.
         */
         savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(0)) &
                      ~(SYSCFG_PINMUX0_PINMUX0_27_24));
    
         /* Setting the pins corresponding to GP0[9] in PINMUX0 register.*/
         HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(0)) =
              (PINMUX0_GPIO0_9_ENABLE | savePinmux);
    
    }
    
    int main(void)
    {
    
        printf("OMAPL138 is in WFI mode. Insert/Remove the SD card to generate interrupt for wakeup.\n");
    
        /* The Local PSC number for GPIO is 3. GPIO belongs to PSC1 module.*/
        PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, PSC_POWERDOMAIN_ALWAYS_ON,
    		     PSC_MDCTL_NEXT_ENABLE);
    
        /* Pin Multiplexing of pins GP6[12], GP6[13], GP2[12], GP0[9], for LEDs in OMAPL138 LCDK board */
        PinMuxSetup_leds();
    
        /* LEDs SETUP */
    
            /* Sets the pin 109 (GP6[12]) as output.*/
            GPIODirModeSet(SOC_GPIO_0_REGS, 109, GPIO_DIR_OUTPUT);
    
            /* Sets the pin 110 (GP6[13]) as output.*/
            GPIODirModeSet(SOC_GPIO_0_REGS, 110, GPIO_DIR_OUTPUT);
    
            /* Sets the pin 45 (GP2[12]) as output.*/
            GPIODirModeSet(SOC_GPIO_0_REGS, 45, GPIO_DIR_OUTPUT);
    
            /* Sets the pin 10 (GP0[9]) as output.*/
            GPIODirModeSet(SOC_GPIO_0_REGS, 10, GPIO_DIR_OUTPUT);
    
    
        /* Initializes the UART instance.*/
        UARTStdioInit();
    
        /* Pin Multiplexing of pin 0 of GPIO Bank 4.*/
        GPIOBank4Pin0PinMuxSetup();
    
        /* Sets the pin 65(GP4[0]) as input.*/
        GPIODirModeSet(SOC_GPIO_0_REGS, 65, GPIO_DIR_INPUT);
    
        /*
        ** Configure rising edge and falling edge triggers on pin 65 to generate
        ** an interrupt
        */
        GPIOIntTypeSet(SOC_GPIO_0_REGS, 65, GPIO_INT_TYPE_BOTHEDGE);
    
        /* Enable interrupts for Bank 4.*/
        GPIOBankIntEnable(SOC_GPIO_0_REGS, 4);
    
        /* Configuring the AINTC to handle interrupts.*/
        SetupInt();
    
        /* Configure GPIO interrupts */
        ConfigureIntGPIO();
    
        //UARTPuts("StarterWare GPIO Demo Application.\r\n", -2);
        //UARTPuts("Insert an MMC/SD card.\r\n", -2);
    
        printf("StarterWare GPIO Demo Application\n");
        printf("Insert an MMC/SD card.\n");
    
        //Titus : ARM WFI code
        SysCfgRegistersUnlock();
    
        asm ( "    teq    r1, #0\n\t");
    
        asm ( "    mcr p15, #0, r1, c7, c0, #4\n\t" );
    
        //Here, code get stuck due to WFI and it resume when SD card interrupt raised.
    
        SysCfgRegistersLock();
    
        //LED D5 would glow when ARM comes out of WFI mode (i.e, when interrupt generated).
        GPIOPinWrite(SOC_GPIO_0_REGS, 109, GPIO_PIN_HIGH);
    
        printf("Comes out of WFI mode; Resume to normal operation.\n");
    
        while(1)
        {
            if(flag == 1)
            {
                CheckCardStatus();
            }
        }
    
    }
    
    
    
    /*
    ** \brief   This function invokes necessary functions to configure the ARM
    **          processor and ARM Interrupt Controller(AINTC) to receive and
    **          handle interrupts.
    */
    
    static void SetupInt(void)
    {
    	// Setup ARM or DSP interrupt controller
    
    #ifdef _TMS320C6X
    	// Initialize the DSP Interrupt Controller
    	IntDSPINTCInit();
    
    	// Enable DSP Interrupts Globally
    	IntGlobalEnable();
    #else
        /* Initialize the ARM Interrupt Controller.*/
        IntAINTCInit();
    
         /* Enable IRQ in CPSR.*/
        IntMasterIRQEnable();
    
        /* Enable the interrupts in GER of AINTC.*/
        IntGlobalEnable();
    
        /* Enable the interrupts in HIER of AINTC.*/
        IntIRQEnable();
    #endif
    }
    
    
    /*
    ** \brief  This function configures the AINTC to receive the GPIO interrupt.
    */
    
    static void ConfigureIntGPIO(void)
    {
    	// Configure GPIO interrupts for ARM or DSP
    
    #ifdef _TMS320C6X
    	// Register the ISR in the Interrupt Vector Table
    	IntRegister(C674X_MASK_INT4, GPIOIsr);
    
    	// Map the system interrupt to the DSP maskable interrupt
    	IntEventMap(C674X_MASK_INT4, SYS_INT_GPIO_B4INT);
    
    	// Enable DSP maskable interrupt
    	IntEnable(C674X_MASK_INT4);
    #else
        // Register the ISR in the Interrupt Vector Table.
        IntRegister(SYS_INT_GPIOB4, GPIOIsr);
    
        // Map the channnel number 2 of AINTC to GPIO BANK 4 system interrupt.
        IntChannelSet(SYS_INT_GPIOB4, 2);
    
        // Enable the System Interrupts for AINTC.
        IntSystemEnable(SYS_INT_GPIOB4);
    #endif
    }
    
    
    /*
    ** \brief   Interrupt Service Routine to be executed on GPIO interrupts.
    **          This disables the bank interrupts, clears the system interrupt
    **          status and pin interrupt status. This also sets flag as 1.
    */
    static void GPIOIsr(void)
    {
    
        /* Disable the interrupts for pins of bank 4 in GPIO.*/
        GPIOBankIntDisable(SOC_GPIO_0_REGS, 4);
    
    #ifdef _TMS320C6X
        // Clear the system interrupt status in the DSPINTC
        IntEventClear(SYS_INT_GPIO_B4INT);
    #else
        /* Clears the system interrupt status of GPIO in AINTC.*/
        IntSystemStatusClear(SYS_INT_GPIOB4);
    #endif
    
        /* Clears the Interrupt Status of GP4[0] in GPIO.*/
        GPIOPinIntClear(SOC_GPIO_0_REGS, 65);
    
        flag = 1;
    }
    
    /*
    ** \brief  This function checks the insertion status of the MMC/SD card
    **         in the device and prints related statements on the serial
    **         commuincation console of the external device.
    **
    */
    
    static void CheckCardStatus(void)
    {
        Delay(0x1FFF);
    
    #ifdef _TMS320C6X
        // Clear the system interrupt status in the DSPINTC
        IntEventClear(SYS_INT_GPIO_B4INT);
    #else
        /* Clears the system interrupt status of GPIO in AINTC.*/
        IntSystemStatusClear(SYS_INT_GPIOB4);
    #endif
    
        /* Clears the Interrupt Status of GP4[0] in GPIO.*/
        GPIOPinIntClear(SOC_GPIO_0_REGS, 65);
    
        /*
        ** 'GPIOPinRead' here returns the value on the GP4[0].
        ** If value returned is 1, it implies the card is removed.
        ** If value returned is 0, it implies the card is inserted.
        */
    
        if (GPIOPinRead(SOC_GPIO_0_REGS, 65))
        {
            //UARTPuts("MMC/SD card is removed.\n\r", -2);
            printf("MMC/SD card is removed.\n");
    
        }
        else
        {
            //UARTPuts("MMC/SD card inserted.\n\r", -2);
            printf("MMC/SD card inserted.\n");
    
        }
    
        flag = 0;
    
        /* Enable interrupts for pins of bank 4.*/
        GPIOBankIntEnable(SOC_GPIO_0_REGS, 4);
    }
    
    /*
    ** \brief   This function can be called to generate a delay.
    */
    
    static void Delay(volatile unsigned int delay)
    {
        while(delay--);
    }
    
    
    /*****************************END OF FILE************************************/
    

    /**
     * \file    gpioCardDetect.c
     *
     * \brief   This is a sample application file demonstrating the use of
     *          a GPIO pin to generate an interrupt whenever an MMC/SD card
     *          is inserted or ejected from the Evaluation Module(EVM).
     */
    
    /*
    * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
    *
    *  Redistribution and use in source and binary forms, with or without
    *  modification, are permitted provided that the following conditions
    *  are met:
    *
    *    Redistributions of source code must retain the above copyright
    *    notice, this list of conditions and the following disclaimer.
    *
    *    Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in the
    *    documentation and/or other materials provided with the
    *    distribution.
    *
    *    Neither the name of Texas Instruments Incorporated nor the names of
    *    its contributors may be used to endorse or promote products derived
    *    from this software without specific prior written permission.
    *
    *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    */
    
    #include <stdio.h>
    
    #include "interrupt.h"
    #include "uartStdio.h"
    #include "gpio.h"
    #include "psc.h"
    
    #include "soc_OMAPL138.h"
    #include "evmOMAPL138.h"
    
    /* System Defines */
    #include "lcdkOMAPL138.h"
    #include "soc_OMAPL138.h"
    #include "hw_syscfg0_OMAPL138.h"
    
    /****************************************************************************/
    /*              LOCAL FUNCTION PROTOTYPES                                   */
    /****************************************************************************/
    static void Delay(volatile unsigned int delay);
    static void ConfigureIntGPIO(void);
    static void CheckCardStatus(void);
    static void SetupInt(void);
    static void GPIOIsr(void);
    
    /****************************************************************************/
    /*              GLOBAL VARIABLES                                            */
    /****************************************************************************/
    volatile unsigned char flag = 0;
    
    /****************************************************************************/
    /*             LOCAL FUNCTION DEFINITIONS                                   */
    /****************************************************************************/
    
    /* LED Configuration */
    
    /* Titus : GP6[12], GP6[13], GP2[12] and GP0[9] is mapped to D4, D5, D6, D7 LEDs on OMAPL138/C6748 LCDK boards */
    
    /* Pin Multiplexing bit mask to select GP6[12] pin. */
    #define PINMUX13_GPIO6_12_ENABLE    (SYSCFG_PINMUX13_PINMUX13_15_12_GPIO6_12  << \
                                        SYSCFG_PINMUX13_PINMUX13_15_12_SHIFT)
    
    /* Pin Multiplexing bit mask to select GP6[13] pin. */
    #define PINMUX13_GPIO6_13_ENABLE    (SYSCFG_PINMUX13_PINMUX13_11_8_GPIO6_13  << \
                                        SYSCFG_PINMUX13_PINMUX13_11_8_SHIFT)
    
    /* Pin Multiplexing bit mask to select GP2[12] pin. */
    #define PINMUX5_GPIO2_12_ENABLE    (SYSCFG_PINMUX5_PINMUX5_15_12_GPIO2_12  << \
                                        SYSCFG_PINMUX5_PINMUX5_15_12_SHIFT)
    
    /* Pin Multiplexing bit mask to select GP0[9] pin. */
    #define PINMUX0_GPIO0_9_ENABLE    (SYSCFG_PINMUX0_PINMUX0_27_24_GPIO0_9  << \
                                        SYSCFG_PINMUX0_PINMUX0_27_24_SHIFT)
    
    /* PINMUX for S2 and S3 on OMAPL138 LCDK boards */
    
    /* Pin Multiplexing bit mask to select GP2[4] pin. */
    #define PINMUX6_GPIO2_4_ENABLE    (SYSCFG_PINMUX6_PINMUX6_15_12_GPIO2_4  << \
                                        SYSCFG_PINMUX6_PINMUX6_15_12_SHIFT)
    
    /* Pin Multiplexing bit mask to select GP2[5] pin. */
    #define PINMUX6_GPIO2_5_ENABLE    (SYSCFG_PINMUX6_PINMUX6_11_8_GPIO2_5  << \
                                        SYSCFG_PINMUX6_PINMUX6_11_8_SHIFT)
    
    void PinMuxSetup_leds(void)
    {
         unsigned int savePinmux = 0;
    
         /*
         ** Clearing the bit in context and retaining the other bit values
         ** in PINMUX13 register.
         */
         savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(13)) &
                      ~(SYSCFG_PINMUX13_PINMUX13_15_12));
    
         /* Setting the pins corresponding to GP6[12] in PINMUX13 register.*/
         HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(13)) =
              (PINMUX13_GPIO6_12_ENABLE | savePinmux);
    
    
         /*
         ** Clearing the bit in context and retaining the other bit values
         ** in PINMUX13 register.
         */
         savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(13)) &
                      ~(SYSCFG_PINMUX13_PINMUX13_11_8));
    
         /* Setting the pins corresponding to GP6[13] in PINMUX13 register.*/
         HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(13)) =
              (PINMUX13_GPIO6_13_ENABLE | savePinmux);
    
    
         /*
         ** Clearing the bit in context and retaining the other bit values
         ** in PINMUX5 register.
         */
         savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(5)) &
                      ~(SYSCFG_PINMUX5_PINMUX5_15_12));
    
         /* Setting the pins corresponding to GP2[12] in PINMUX5 register.*/
         HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(5)) =
              (PINMUX5_GPIO2_12_ENABLE | savePinmux);
    
    
         /*
         ** Clearing the bit in context and retaining the other bit values
         ** in PINMUX0 register.
         */
         savePinmux = (HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(0)) &
                      ~(SYSCFG_PINMUX0_PINMUX0_27_24));
    
         /* Setting the pins corresponding to GP0[9] in PINMUX0 register.*/
         HWREG(SOC_SYSCFG_0_REGS + SYSCFG0_PINMUX(0)) =
              (PINMUX0_GPIO0_9_ENABLE | savePinmux);
    
    }
    
    int main(void)
    {
    
        printf("OMAPL138 is in WFI mode. Insert/Remove the SD card to generate interrupt for wakeup.\n");
    
        /* The Local PSC number for GPIO is 3. GPIO belongs to PSC1 module.*/
        PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, PSC_POWERDOMAIN_ALWAYS_ON,
    		     PSC_MDCTL_NEXT_ENABLE);
    
        /* Pin Multiplexing of pins GP6[12], GP6[13], GP2[12], GP0[9], for LEDs in OMAPL138 LCDK board */
        PinMuxSetup_leds();
    
        /* LEDs SETUP */
    
            /* Sets the pin 109 (GP6[12]) as output.*/
            GPIODirModeSet(SOC_GPIO_0_REGS, 109, GPIO_DIR_OUTPUT);
    
            /* Sets the pin 110 (GP6[13]) as output.*/
            GPIODirModeSet(SOC_GPIO_0_REGS, 110, GPIO_DIR_OUTPUT);
    
            /* Sets the pin 45 (GP2[12]) as output.*/
            GPIODirModeSet(SOC_GPIO_0_REGS, 45, GPIO_DIR_OUTPUT);
    
            /* Sets the pin 10 (GP0[9]) as output.*/
            GPIODirModeSet(SOC_GPIO_0_REGS, 10, GPIO_DIR_OUTPUT);
    
    
        /* Initializes the UART instance.*/
        UARTStdioInit();
    
        /* Pin Multiplexing of pin 0 of GPIO Bank 4.*/
        GPIOBank4Pin0PinMuxSetup();
    
        /* Sets the pin 65(GP4[0]) as input.*/
        GPIODirModeSet(SOC_GPIO_0_REGS, 65, GPIO_DIR_INPUT);
    
        /*
        ** Configure rising edge and falling edge triggers on pin 65 to generate
        ** an interrupt
        */
        GPIOIntTypeSet(SOC_GPIO_0_REGS, 65, GPIO_INT_TYPE_BOTHEDGE);
    
        /* Enable interrupts for Bank 4.*/
        GPIOBankIntEnable(SOC_GPIO_0_REGS, 4);
    
        /* Configuring the AINTC to handle interrupts.*/
        SetupInt();
    
        /* Configure GPIO interrupts */
        ConfigureIntGPIO();
    
        //UARTPuts("StarterWare GPIO Demo Application.\r\n", -2);
        //UARTPuts("Insert an MMC/SD card.\r\n", -2);
    
        printf("StarterWare GPIO Demo Application\n");
        printf("Insert an MMC/SD card.\n");
    
        //Titus : ARM WFI code
        SysCfgRegistersUnlock();
    
        asm ( "    teq    r1, #0\n\t");
    
        asm ( "    mcr p15, #0, r1, c7, c0, #4\n\t" );
    
        //Here, code get stuck due to WFI and it resume when SD card interrupt raised.
    
        SysCfgRegistersLock();
    
        //LED D5 would glow when ARM comes out of WFI mode (i.e, when interrupt generated).
        GPIOPinWrite(SOC_GPIO_0_REGS, 109, GPIO_PIN_HIGH);
    
        printf("Comes out of WFI mode; Resume to normal operation.\n");
    
        while(1)
        {
            if(flag == 1)
            {
                CheckCardStatus();
            }
        }
    
    }
    
    
    
    /*
    ** \brief   This function invokes necessary functions to configure the ARM
    **          processor and ARM Interrupt Controller(AINTC) to receive and
    **          handle interrupts.
    */
    
    static void SetupInt(void)
    {
    	// Setup ARM or DSP interrupt controller
    
    #ifdef _TMS320C6X
    	// Initialize the DSP Interrupt Controller
    	IntDSPINTCInit();
    
    	// Enable DSP Interrupts Globally
    	IntGlobalEnable();
    #else
        /* Initialize the ARM Interrupt Controller.*/
        IntAINTCInit();
    
         /* Enable IRQ in CPSR.*/
        IntMasterIRQEnable();
    
        /* Enable the interrupts in GER of AINTC.*/
        IntGlobalEnable();
    
        /* Enable the interrupts in HIER of AINTC.*/
        IntIRQEnable();
    #endif
    }
    
    
    /*
    ** \brief  This function configures the AINTC to receive the GPIO interrupt.
    */
    
    static void ConfigureIntGPIO(void)
    {
    	// Configure GPIO interrupts for ARM or DSP
    
    #ifdef _TMS320C6X
    	// Register the ISR in the Interrupt Vector Table
    	IntRegister(C674X_MASK_INT4, GPIOIsr);
    
    	// Map the system interrupt to the DSP maskable interrupt
    	IntEventMap(C674X_MASK_INT4, SYS_INT_GPIO_B4INT);
    
    	// Enable DSP maskable interrupt
    	IntEnable(C674X_MASK_INT4);
    #else
        // Register the ISR in the Interrupt Vector Table.
        IntRegister(SYS_INT_GPIOB4, GPIOIsr);
    
        // Map the channnel number 2 of AINTC to GPIO BANK 4 system interrupt.
        IntChannelSet(SYS_INT_GPIOB4, 2);
    
        // Enable the System Interrupts for AINTC.
        IntSystemEnable(SYS_INT_GPIOB4);
    #endif
    }
    
    
    /*
    ** \brief   Interrupt Service Routine to be executed on GPIO interrupts.
    **          This disables the bank interrupts, clears the system interrupt
    **          status and pin interrupt status. This also sets flag as 1.
    */
    static void GPIOIsr(void)
    {
    
        /* Disable the interrupts for pins of bank 4 in GPIO.*/
        GPIOBankIntDisable(SOC_GPIO_0_REGS, 4);
    
    #ifdef _TMS320C6X
        // Clear the system interrupt status in the DSPINTC
        IntEventClear(SYS_INT_GPIO_B4INT);
    #else
        /* Clears the system interrupt status of GPIO in AINTC.*/
        IntSystemStatusClear(SYS_INT_GPIOB4);
    #endif
    
        /* Clears the Interrupt Status of GP4[0] in GPIO.*/
        GPIOPinIntClear(SOC_GPIO_0_REGS, 65);
    
        flag = 1;
    }
    
    /*
    ** \brief  This function checks the insertion status of the MMC/SD card
    **         in the device and prints related statements on the serial
    **         commuincation console of the external device.
    **
    */
    
    static void CheckCardStatus(void)
    {
        Delay(0x1FFF);
    
    #ifdef _TMS320C6X
        // Clear the system interrupt status in the DSPINTC
        IntEventClear(SYS_INT_GPIO_B4INT);
    #else
        /* Clears the system interrupt status of GPIO in AINTC.*/
        IntSystemStatusClear(SYS_INT_GPIOB4);
    #endif
    
        /* Clears the Interrupt Status of GP4[0] in GPIO.*/
        GPIOPinIntClear(SOC_GPIO_0_REGS, 65);
    
        /*
        ** 'GPIOPinRead' here returns the value on the GP4[0].
        ** If value returned is 1, it implies the card is removed.
        ** If value returned is 0, it implies the card is inserted.
        */
    
        if (GPIOPinRead(SOC_GPIO_0_REGS, 65))
        {
            //UARTPuts("MMC/SD card is removed.\n\r", -2);
            printf("MMC/SD card is removed.\n");
    
        }
        else
        {
            //UARTPuts("MMC/SD card inserted.\n\r", -2);
            printf("MMC/SD card inserted.\n");
    
        }
    
        flag = 0;
    
        /* Enable interrupts for pins of bank 4.*/
        GPIOBankIntEnable(SOC_GPIO_0_REGS, 4);
    }
    
    /*
    ** \brief   This function can be called to generate a delay.
    */
    
    static void Delay(volatile unsigned int delay)
    {
        while(delay--);
    }
    
    
    /*****************************END OF FILE************************************/