Exemple #1
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();
         }
    }
}
Exemple #2
0
/*
** Main function. The application starts here.
*/
int main(void)
{
    unsigned int index;
    unsigned int j;

    int result = 0;

    /*
    ** Sets up Section page tables. This is only first level
    ** page table, each page is of size 1MB
    */
    for(index = 0; index < (4*1024); index++)
    {
         /* Set the cacheable memory attributes */
         if((index >= 0x800 && index < 0x880) || (index == 0x403))
         {
              pageTable[index] = (index << 20) | CACHEABLE_TLB_ATTR;
         }

         /* Set the non-cacheable memory attributes */
         else
         {
              pageTable[index] = (index << 20) | NORM_TLB_ATTR;
         }
    }


    /* Invalidate the TLB, pipeline */
    CP15TlbInvalidate();
    CP15BranchPredictorInvalidate();

    CP15BranchPredictionEnable();

    CP15DomainAccessClientSet();

    /* Set TTB0 value. We use only TTB0 here (N = 0) */
    CP15Ttb0Set(((unsigned int )pageTable) | RGN_L2_WBWA);

    /* Enables MMU */
    CP15MMUEnable();

    /* Flush and enable Instruction Cache */
    CP15ICacheFlush();
    CP15ICacheEnable();

    PeripheralsSetUp();

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

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

    IntMasterIRQEnable();

    /* 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);
    IntSystemEnable(127);
    IntPrioritySet(127, 0, AINTC_HOSTINT_ROUTE_IRQ);

    RtcInit();
    UARTStdioInit();
    HSMMCSDContolInit();
    DelayTimerSetup();

    Timer2Config();
    Timer4Config();
    LedIfConfig();

    Timer2IntEnable();
    Timer4IntEnable();
    RtcSecIntEnable();

    InitI2C();

    Timer4Start(); 

    // Read config from files
    HSMMCSDCardAccessSetup();

    configRead();

    LedOn( USER_LED_1 );
    for( j = 0; j < 1000000; ++j );
    LedOff( USER_LED_1 );
    LedOn( USER_LED_2 );
    for( j = 0; j < 1000000; ++j );
    LedOff( USER_LED_2 );
    LedOn( USER_LED_3 );
    for( j = 0; j < 1000000; ++j );
    LedOff( USER_LED_3 );
    LedOn( USER_LED_4 );
    for( j = 0; j < 1000000; ++j );
    LedOff( USER_LED_4 );

    // TEMP
    //i2cTest();

    /*
    ** Loop for ever. Necessary actions shall be taken
    ** after detecting the click.
    */
    while( 1 )
    {
        EnetStatusCheckNUpdate();

        if( runCommand )
        {
            // Command blink
            LedOn( USER_LED_1 );

            if( runData[ runIndex + 1 ] == 'D' )
            {
                if( runData[ runIndex + 2 ] == 'S' )
                {
                    UARTPuts( "** DAC SET\n\r", -1 );

                    if( runData[ runIndex + 3 ] == 'A' )
                    {
                        i2cDAC_Set( 0,
                          runData[ runIndex + 4 ], runData[ runIndex + 5 ] );
                    }
                    if( runData[ runIndex + 6 ] == 'B' )
                    {
                        i2cDAC_Set( 1,
                          runData[ runIndex + 7 ], runData[ runIndex + 8 ] );
                    }
                    if( runData[ runIndex + 9 ] == 'C' )
                    {
                        i2cDAC_Set( 2,
                          runData[ runIndex + 10 ], runData[ runIndex + 11 ] );
                    }
                    if( runData[ runIndex + 12 ] == 'D' )
                    {
                        i2cDAC_Set( 3,
                          runData[ runIndex + 13 ], runData[ runIndex + 14 ] );
                    }
                }
                else if( runData[ runIndex + 2 ] == 'G' )
                {
                    UARTPuts( "** DAC GET\n\r", -1 );

                    uartData[ 0 ] = 15;
                    uartData[ 1 ] = 'D';
                    uartData[ 2 ] = 'G';

                    uartData[ 3 ] = 'A';
                    i2cDAC_Get( 0, &uartData[ 4 ] );

                    uartData[ 6 ] = 'B';
                    i2cDAC_Get( 1, &uartData[ 7 ] );

                    uartData[ 9 ] = 'C';
                    i2cDAC_Get( 2, &uartData[ 10 ] );

                    uartData[ 12 ] = 'D';
                    i2cDAC_Get( 3, &uartData[ 13 ] );

                    net_ext_send( uartData, 15 );
                }
            }
            else if( runData[ runIndex + 1 ] == 'G' )
            {
                if( runData[ runIndex + 2 ] == 'S' )
                {
                    if( runData[ runIndex + 3 ] == 0 ) // Off
                    {
                        UARTPuts( "** GPIO OFF\n\r", -1 );
                        i2cGPIO_Off( 0, 1 << runData[ runIndex + 4 ] );
                    }
                    else if( runData[ runIndex + 3 ] == 1 ) // On
                    {
                        UARTPuts( "** GPIO ON\n\r", -1 );
                        i2cGPIO_On( 0, 1 << runData[ runIndex + 4 ] );
                    }
                }
                else if( runData[ runIndex + 2 ] == 'G' )
                {
                    UARTPuts( "** GPIO GET\n\r", -1 );

                    uartData[ 0 ] = 5;
                    uartData[ 1 ] = 'G';
                    uartData[ 2 ] = 'G';

                    i2cGPIO_Get( &uartData[ 3 ] );

                    net_ext_send( uartData, 5 );
                }
            }
            else if( runData[ runIndex + 1 ] == 'U' )
            {
                UARTPuts( "** UART\n\r", -1 );
                i2cUART_Send( &(runData[ runIndex + 2 ]), 6 );
            }

            runCommand -= runData[ runIndex + 0 ];

            if( runCommand > 0 )
            {
                runIndex += runData[ runIndex + 0 ];
            }
            else
            {
                runIndex = 0;
            }

            LedOff( USER_LED_1 );
        }

        result = i2cUART_Recv( &( uartData[ 2 ] ), 30 );

        if( result > 0 )
        {
            UARTPuts( "** UART Recv: ", -1 );

            for( index = 0; index < result; ++index )
            {
                UARTPutHexNum( uartData[ index + 2 ] );
                UARTPutc( ' ' );
            }

            UARTPutc( '\n' );
            UARTPutc( '\r' );

            // Return the stage position info to the GUI
            if( uartData[ 3 ] == 0x0A ||
                uartData[ 3 ] == 0x3C )
            {
                uartData[ 0 ] = result + 2;
                uartData[ 1 ] = 'U';

                net_ext_send( uartData, result + 2 );
            }
        }
    }
}