Ejemplo n.º 1
0
int UARTGetNum(void)  
{
     unsigned char rxByte;
     int sign = 1;
     int value = 0;

     rxByte = UARTGetc();

     /* Accounting for negative numbers.*/
     if('-' == rxByte)
     {
          UARTPutc('-');
          sign = -1;
     }
     else
     {
          UARTPutc(rxByte);
          value = value*10 + (rxByte - 0x30);
     } 
     
     do
     {
          rxByte = UARTGetc();

          /* Echoing the typed characters to the serial console.*/
          UARTPutc(rxByte);
          /*
          ** Checking if the entered character is a carriage return.
          ** Pressing the 'Enter' key on the keyboard executes a 
          ** carriage return on the serial console.
          */
          if('\r' == rxByte)
          {
               break;
          }
          /* 
          ** Subtracting 0x30 to convert the representation of the digit 
          ** from ASCII to hexadecimal.
          */
          value = value*10 + (rxByte - 0x30);

      }while(1);                 

      /* Accounting for the sign of the number.*/
      value = value * sign;

      return value;
}
Ejemplo n.º 2
0
/*
** Main Function.
*/
int main(void)
{
    unsigned char choice = 0;

    /* Enable the clocks for McSPI0 module.*/
    McSPI0ModuleClkConfig();

    /* Perform Pin-Muxing for SPI0 Instance.*/
    McSPIPinMuxSetup(0);

    /* Perform Pin-Muxing for CS0 of SPI0 Instance.*/
    McSPI0CSPinMuxSetup(MCSPI_CH_NUM);

    /* Initialize the UART utility functions.*/
    UARTStdioInit();

    /* Enable IRQ in CPSR.*/
    IntMasterIRQEnable();

    UARTPuts("Here the McSPI controller on the SOC communicates with ",-1);
    UARTPuts("the McSPI Flash.\r\n\r\n",-1);

    /* Initialize the EDMA3 instance.*/
    EDMA3Initialize();

    /* Request EDMA3CC for Tx and Rx channels for SPI0. */
    RequestEDMA3Channels();

    /* Set up the McSPI instance.*/
    McSPISetUp();

    /* Enable the SPI Flash for writing to it. */
    WriteEnable();

    UARTPuts("Do you want to erase a sector of the flash before writing to it ?.", -1);
    UARTPuts("\r\nInput y(Y)/n(N) to proceed.\r\n", -1);

    choice = UARTGetc();
    UARTPutc(choice);

    if(('y' == choice) || ('Y' == choice))
    {
        /* Erasing the specified sector of SPI Flash. */
        FlashSectorErase();
    }

    /* Enable the SPI Flash for writing to it. */
    WriteEnable();

    /* Write data of 1 page size into a page of Flash.*/
    FlashPageProgram();

    /* Read data of 1 page size from a page of flash.*/
    ReadFromFlash();

    /* Verify the data written to and read from Flash are same or not.*/
    VerifyData();

    while(1);
}
Ejemplo n.º 3
0
/**
 * \brief   This function builds an integer from teh data received
 *
 * \return  The value received
 *
 * \note   The numbers that this function can recieve should lie in the 
 *          following range:
 *          [-2^(31)] to [2^(31) - 1] i.e.
 *          0x80000000 to  0x7FFFFFFF  
 *
 *            This logic is meant only for Little Endian processors only.
 */
void UARTGetInt(int *val)
{
    char* pCh = (char*)(val);
    int size = 4;

    do
    {
        *pCh = (char)UARTGetc();
        pCh++;
    } while(--size);

    return;
}
Ejemplo n.º 4
0
int main(void)
{
    unsigned int triggerValue = 0;

    /* Setup the MMU and do necessary MMU configurations. */
    MMUConfigAndEnable();

    /* Enable all levels of CACHE. */
    CacheEnable(CACHE_ALL);

    /* Set up the UART2 peripheral */
    UARTStdioInit();

    /* Enable the WDT clocks */
    WatchdogTimer1ModuleClkConfig();

    /* Reset the Watchdog Timer */
    WatchdogTimerReset(SOC_WDT_1_REGS);

    /* Disable the Watchdog timer */
    WatchdogTimerDisable(SOC_WDT_1_REGS);
                                               
    /* Perform the initial settings for the Watchdog Timer */
    WatchdogTimerSetUp();

    /* Send the message to UART console */
    UARTPuts("Program Reset!", -1);
    UARTPuts("Input any key at least once in every 4 seconds to avoid a further reset.\n\r", -1);

    /* Enable the Watchdog Timer */
    WatchdogTimerEnable(SOC_WDT_1_REGS);

    while(1)
    {
        /* Wait for an input through UART. If no input is given, 
        ** the WDT will timeout and reset will occur.
        */
        if(UARTGetc())
        {

            triggerValue += 1;

            /* Write into the trigger register. This will load the value from the 
            ** load register into the counter register and hence timer will start 
            ** from the initial count.
            */
            WatchdogTimerTriggerSet(SOC_WDT_1_REGS, triggerValue);
        }
    }
}
Ejemplo n.º 5
0
unsigned int UARTGets(char *pRxBuffer, int numBytesToRead)
{     
     unsigned int count = 0;
     unsigned int flag = 0;

     if(numBytesToRead < 0)
     {
          flag = 1;
     }
     do
     {
          *pRxBuffer = UARTGetc();
          
          /*
          ** 0xD - ASCII value of Carriage Return.
          ** 0x1B - ASCII value of ESC character.
          */ 
          if(0xD == *pRxBuffer || 0x1B == *pRxBuffer)
          {
               *pRxBuffer = '\0';
               break;
          }

          /* Echoing the typed character back to the serial console. */
          UARTPutc((unsigned char)*pRxBuffer);
          pRxBuffer++;     
          count++;

          if(0 == flag && (count == numBytesToRead))
          {
               break;
          }

     }while(1);
     
     return count;
}
Ejemplo n.º 6
0
unsigned int UARTGetHexNum(void)
{
    unsigned char rxByte;
    unsigned int value = 0;
    unsigned int loopIndex;
    unsigned int byteCount = 0;

    for(loopIndex = 0; loopIndex < 2; loopIndex++)
    {
        /* Receiving bytes from the host machine through serial console. */
        rxByte = UARTGetc();

        /*
        ** Checking if the entered character is a carriage return.
        ** Pressing the 'Enter' key on the keyboard executes a
        ** carriage return on the serial console.
        */
        if('\r' == rxByte)
        {
            break;
        }

        /*
        ** Checking if the character entered is one among the alphanumeric
        ** character set A,B,C...F
        */
        if(('A' <= rxByte) && (rxByte <= 'F'))
        {
            /* Echoing the typed characters to the serial console.*/
            UARTPutc(rxByte);
            value = value*16 + (rxByte - 0x37);
            byteCount++;
        }

        /*
        ** Checking if the character entered is one among the alphanumeric
        ** character set a,b,c...f
        */
        else if(('a' <= rxByte) && (rxByte <= 'f'))
        {
            UARTPutc(rxByte);
            value = value*16 + (rxByte - 0x57);
            byteCount++;
        }

        /*
        ** Checking if the character entered is one among the decimal
        ** number set 0,1,2,3,....9
        */
        else if(('0' <= rxByte) && (rxByte <= '9'))
        {
            UARTPutc(rxByte);
            value = value*16 + (rxByte - 0x30);
            byteCount++;
        }

        /*
        ** Checking if the character is either a 'x'(lower-case) or an 'X'
        ** (upper-case).
        */
        else if(('x' == rxByte) || ('X' == rxByte))
        {
            UARTPutc(rxByte);
            value = 0;
            break;
        }
    }

    if(0 == value)
    {
        byteCount = 0;
    }

    do
    {
        rxByte = UARTGetc();

        if('\r' == rxByte)
        {
            break;
        }

        /*
        ** Checking if the character entered is one among the alphanumeric
        ** character set A,B,C...F
        */
        if(('A' <= rxByte) && (rxByte <= 'F'))
        {
            UARTPutc(rxByte);
            value = value*16 + (rxByte - 0x37);
            byteCount++;
        }

        /*
        ** Checking if the character entered is one among the alphanumeric
        ** character set a,b,c...f
        */
        else if(('a' <= rxByte) && (rxByte <= 'f'))
        {
            UARTPutc(rxByte);
            value = value*16 + (rxByte - 0x57);
            byteCount++;
        }

        /*
        ** Checking if the character entered is one among the decimal
        ** number set 0,1,2,3,....9
        */
        else if(('0' <= rxByte) && (rxByte <= '9'))
        {
            UARTPutc(rxByte);
            value = value*16 + (rxByte - 0x30);
            byteCount++;
        }

        /*
        ** Not receiving any other character other than the one belonging
        ** to the above three categories.
        */
        else
        {
            /* Intentionally left empty. */
        }

    }while(byteCount < 8);

    return value;
}
Ejemplo n.º 7
0
/*
** Main function.
*/
int main(void)
{
    volatile char originalData[260] = {0}; 
    volatile char readFlash[260] = {0};
    unsigned int retVal = 0;
    unsigned char choice;

    /* Initializes the UART Instance for serial communication. */
    UARTStdioInit(); 

    UARTPuts("Welcome to SPI EDMA application.\r\n", -1);
    UARTPuts("Here the SPI controller on the SoC communicates with", -1);
    UARTPuts(" the SPI Flash present on the SoM.\r\n\r\n", -1);

    /* Initializes the EDMA3 Instance. */
    EDMA3Initialize();

    /* Initializes the SPI1 Instance. */
    SPIInitialize();

    /* Request EDMA3CC for Tx and Rx channels for SPI1. */
    RequestEDMA3Channels();

    /* Enable SPI communication. */
    SPIEnable(SOC_SPI_1_REGS);

    /* Enable the SPI Flash for writing to it. */
    WriteEnable();

    UARTPuts("Do you want to erase a sector of the flash before writing to it ?.", -1);
    UARTPuts("\r\nInput y(Y)/n(N) to proceed.\r\n", -1);

    choice = UARTGetc();
    UARTPutc(choice); 

    if(('y' == choice) || ('Y' == choice))
    {
        /* Erasing the specified sector of SPI Flash. */
        FlashSectorErase();
    }
    
    WriteEnable(); 

    /* Program a specified Page of the SPI Flash. */
    FlashPageProgram(originalData); 

    /* Read the contents of the page that was previously written to. */
    ReadFromFlash(readFlash);

    /* Verify whether the written and the read contents are equal. */
    retVal = verifyData(&originalData[4], &readFlash[4], 256); 

    if(TRUE == retVal)
    {
        UARTPuts("\r\nThe data in the Flash and the one written ", -1); 
        UARTPuts("to it are equal.\r\n", -1);
    }
    else
    {
        UARTPuts("\r\n\r\nThe data in the Flash and the one written to it", -1);
        UARTPuts(" are not equal.\r\n", -1);
    } 
    
    while(1);
}
Ejemplo n.º 8
0
/******************************************************************************
**                      INTERNAL FUNCTION DEFINITIONS                       
******************************************************************************/
int main(void)
{
    volatile unsigned int count = 0x0FFFu;
    unsigned int retVal = FALSE;
    unsigned char choice = 0;

    /* Enable the clocks for McSPI0 module.*/
    McSPI0ModuleClkConfig();

    /* Perform Pin-Muxing for SPI0 Instance */
    McSPIPinMuxSetup(0);

    /* Perform Pin-Muxing for CS0 of SPI0 Instance */
    McSPI0CSPinMuxSetup(chNum);

    /* Initialize the UART utility functions */
    UARTStdioInit();

    UARTPuts("Here the McSPI controller on the SoC communicates with", -1);
    UARTPuts(" the SPI Flash.\r\n\r\n", -1);

    /* Enable IRQ in CPSR.*/
    IntMasterIRQEnable();

    /* Map McSPI Interrupts to AINTC */
    McSPI0AintcConfigure();
					
    /* Do the necessary set up configurations for McSPI.*/
    McSPISetUp();

    /* Pass the write enable command to flash.*/
    WriteEnable();

    /* Wait until write enable command is successfully written to flash.*/
    while(FALSE == retVal)
    {
        retVal = IsWriteSuccess();
    }

    retVal = FALSE;

    UARTPuts("Do you want to erase a sector of the flash before ", -1);
    UARTPuts("writing to it ?.", -1);
    UARTPuts("\r\nInput y(Y)/n(N) to proceed.\r\n", -1);

    choice = UARTGetc();
    UARTPutc(choice);

    if(('Y' == choice) || ('y' == choice))
    {
        /* Erase a sector of flash.*/
        SectorErase();
    }

    /* Pass the write enable command to flash.*/
    WriteEnable();

    /* Wait until write enable command is successfully written to flash.*/
    while(FALSE == retVal)
    {
        retVal = IsWriteSuccess();
    }

    /* Write data of 1 page size to flash.*/
    WriteToFlash();

    while(count--);
    count = 0x0FFFu;

    /* Read data of 1 page size from flash.*/
    ReadFromFlash();

    while(count--);

    /* Verify the data written to and read from flash are same or not.*/
    VerifyData();

    while(1);
}
Ejemplo n.º 9
0
/*
** Main function. The application starts here.
*/
int main(void)
{
    unsigned char rxByte;
    unsigned int value = (unsigned int)E_FAIL;

    #ifdef __TMS470__
    /* Relocate the required section to internal RAM */
    memcpy((void *)(&relocstart), (const void *)(&iram_start),
           (unsigned int)(&iram_size));
    #elif defined(__IAR_SYSTEMS_ICC__)
    #pragma section = "CodeRelocOverlay"
    #pragma section = "DataRelocOverlay"
    #pragma section = "DataOverlayBlk"
    #pragma section = "CodeOverlayBlk"
    char* srcAddr = (__section_begin("CodeRelocOverlay"));
    char* endAddr = (__section_end("DataRelocOverlay"));

    memcpy((void *)(__section_begin("CodeRelocOverlay")),
           (const void *)(__section_begin("CodeOverlayBlk")),
           endAddr - srcAddr);

    #else
    memcpy((void *)&(relocstart), (const void *)&(iram_start),
           (unsigned int)(((&(relocend)) -
            (&(relocstart))) * (sizeof(unsigned int))));
    #endif

    MMUConfigAndEnable();    

    /* Enable Instruction Cache */
    CacheEnable(CACHE_ALL);

    PeripheralsSetUp();

    /* Initialize the ARM Interrupt Controller */
    IntAINTCInit();

    /* Register the ISRs */  
    Timer2IntRegister();
    Timer4IntRegister();
    EnetIntRegister();
    RtcIntRegister();
    CM3IntRegister();
    HSMMCSDIntRegister();
    IntRegister(127, dummyIsr);

    IntMasterIRQEnable();

    pageIndex = 0;
    prevAction = 0;

    /* Enable system interrupts */
    IntSystemEnable(SYS_INT_RTCINT);
    IntPrioritySet(SYS_INT_RTCINT, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_3PGSWTXINT0);
    IntPrioritySet(SYS_INT_3PGSWTXINT0, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_3PGSWRXINT0);
    IntPrioritySet(SYS_INT_3PGSWRXINT0, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_TINT2);
    IntPrioritySet(SYS_INT_TINT2, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_TINT4);
    IntPrioritySet(SYS_INT_TINT4, 0, AINTC_HOSTINT_ROUTE_IRQ);	
    IntSystemEnable(SYS_INT_MMCSD0INT);
    IntPrioritySet(SYS_INT_MMCSD0INT, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_EDMACOMPINT);
    IntPrioritySet(SYS_INT_EDMACOMPINT, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntPrioritySet(SYS_INT_M3_TXEV, 0, AINTC_HOSTINT_ROUTE_IRQ );
    IntSystemEnable(SYS_INT_M3_TXEV);
    IntSystemEnable(127);
    IntPrioritySet(127, 0, AINTC_HOSTINT_ROUTE_IRQ);

    IntSystemEnable(SYS_INT_UART0INT);
    IntPrioritySet(SYS_INT_UART0INT, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntRegister(SYS_INT_UART0INT, uartIsr);

     /*	GPIO interrupts	*/
    IntSystemEnable(SYS_INT_GPIOINT0A);
    IntPrioritySet(SYS_INT_GPIOINT0A, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntRegister(SYS_INT_GPIOINT0A, gpioIsr);
    IntSystemEnable(SYS_INT_GPIOINT0B);
    IntPrioritySet(SYS_INT_GPIOINT0B, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntRegister(SYS_INT_GPIOINT0B, gpioIsr);

    BoardInfoInit();
    deviceVersion = DeviceVersionGet();

    CM3EventsClear();
    CM3LoadAndRun();
    waitForM3Txevent();

    /* Initialize console for communication with the Host Machine */
    ConsoleUtilsInit();

    /*
    ** Select the console type based on compile time check
    ** Note: This example is not fully complaint to semihosting. It is
    **       recommended to use Uart console interface only.
    */
    ConsoleUtilsSetType(CONSOLE_UART);

    /* Print Board and SoC information on console */
    ConsoleUtilsPrintf("\n\r Board Name          : %s", BoardNameGet());
    ConsoleUtilsPrintf("\n\r Board Version       : %s", BoardVersionGet());
    ConsoleUtilsPrintf("\n\r SoC Version         : %d", deviceVersion);

    /* On CM3 init firmware version is loaded onto the IPC Message Reg */
    ConsoleUtilsPrintf("\n CM3 Firmware Version: %d", readCM3FWVersion());

    I2CIntRegister(I2C_0);
    IntPrioritySet(SYS_INT_I2C0INT, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_I2C0INT);
    I2CInit(I2C_0);

    IntSystemEnable(SYS_INT_TINT1_1MS);
    IntPrioritySet(SYS_INT_TINT1_1MS, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntRegister(SYS_INT_TINT1_1MS,clearTimerInt);

    configVddOpVoltage();
    RtcInit();
    HSMMCSDContolInit();
    DelayTimerSetup();

    initializeTimer1();
    ConsoleUtilsPrintf("\r\n After intializing timer");
    Timer2Config();
    Timer4Config();
    LedIfConfig();
    MailBoxInit();

    Timer2IntEnable();
    Timer4IntEnable();
    RtcSecIntEnable();
    	
    Timer4Start(); 
    while(FALSE == tmr4Flag);
    tmr4Flag = FALSE;
    Timer4Stop();

    ConsoleUtilsPrintf("\n\r Configuring for maximum OPP");
    mpuOpp = ConfigMaximumOPP();

    mpuFreq = FrequencyGet(mpuOpp);
    mpuVdd1 = VddVoltageGet(mpuOpp);
    PrintConfigDVFS();

    /*  Create menu page */
    pageIndex = MENU_IDX_MAIN;

    ActionEnetInit();

    /*
    ** Loop for ever. Necessary actions shall be taken
    ** after detecting the click.
    */
    while(1)
    {
        /*
        ** Check for any any activity on Uart Console and process it.
        */
        if (true == UARTCharsAvail(SOC_UART_0_REGS))
        {

            /* Receiving bytes from the host machine through serial console. */
            rxByte = UARTGetc();

            /*
            ** Checking if the entered character is a carriage return.
            ** Pressing the 'Enter' key on the keyboard executes a
            ** carriage return on the serial console.
            */
            if('\r' == rxByte)
            {
                ConsoleUtilsPrintf("\n");
                UartAction(value);
                value = (unsigned int)E_FAIL;
                rxByte = 0;
            }

            /*
            ** Checking if the character entered is one among the decimal
            ** number set 0,1,2,3,....9
            */
            if(('0' <= rxByte) && (rxByte <= '9'))
            {
                ConsoleUtilsPrintf("%c", rxByte);

                if((unsigned int)E_FAIL == value)
                {
                    value = 0;
                }

                value = value*10 + (rxByte - 0x30);
            }

        }

         /*
         ** Check if click is detected
         */
         if(clickIdx != 0)
         {
             /*
             ** Take the Action for click
             */
             ClickAction();

             clickIdx = 0;
         }
       
         /*
         ** Check if the Timer Expired
         */ 
         if(TRUE == tmrFlag)
         {
             /* Toggle the LED state */
             LedToggle();
             tmrFlag = FALSE;
         }
 
         /*
         ** Check if RTC Time is set
         */
         if(TRUE == rtcSetFlag)
         {
             if(TRUE == rtcSecUpdate)
             { 
                 rtcSecUpdate = FALSE;
                 RtcTimeCalDisplay();
                 ConsoleUtilsPrintf(" --- Selected:  ");
             }
         } 
   
         if(TRUE == tmr4Flag)
         {
            tmr4Flag = FALSE;
             /* Make sure that interrupts are disabled and no lwIP functions
                are executed while calling an lwIP exported API */
             IntMasterIRQDisable();
             etharp_tmr();
             IntMasterIRQEnable();
         }
    }
}