Example #1
0
void
disk_page_io_save_me_async(disk_page_io *me)
{
    if(_DEBUG) hal_printf("disk_page_io alloc... ");
    disk_page_io_allocate(me);
    if(_DEBUG) hal_printf("disk_page_io wait... ");
    disk_page_io_wait(me);
    if(_DEBUG) hal_printf("disk_page_io kick pager... ");
    pager_enqueue_for_pageout_fast( &me->req );
    if(_DEBUG) hal_printf("disk_page_io after kick... ");
}
Example #2
0
////////////////////////////////////////////////////////////////////////////////
// The SectorOverlapsBootstrapRegion method enables you to deny access for writing
// certain sectors.  Returning true does not guarrantee that Tinybooter will be 
// able to write to the sector.  It performes other checks (including signature 
// validation) to determine if the write operation is valid.
////////////////////////////////////////////////////////////////////////////////
bool CheckFlashSectorPermission( BlockStorageDevice *pDevice, ByteAddress address )
{
    bool fAllowWrite = false;
    UINT32 BlockType, iRegion, iRange;
    

    if(pDevice->FindRegionFromAddress(address, iRegion, iRange))
    {
        const BlockRange& range = pDevice->GetDeviceInfo()->Regions[iRegion].BlockRanges[iRange];
        
        if (range.IsBootstrap())
        {
#if defined(TARGETLOCATION_RAM) // do not allow overwriting the bootstrap sector unless Tinybooter is RAM build.
            fAllowWrite = true;
#else
            hal_printf( "Trying to write to bootstrap region\r\n" );
            fAllowWrite = false;
#endif
        }
        else
        {
            fAllowWrite = true;
        }
    }
    
    return fAllowWrite;   
}
BOOL SimpleHeap_IsAllocated( void *ptr )
{
    if(ptr)
    {
        struct BlockHeader* blk = (struct BlockHeader*)ptr; blk--;

        if(blk->signature == c_Busy)
        {
            return TRUE;
        }
        else if(blk->signature == c_Free)
        {
            return FALSE;
        }
        else
        {
            // corrupt pointer to memory
            hal_printf( "SimpleHeap: Bad Ptr: 0x%08x\r\n", (size_t)ptr );
            ASSERT(0);
            return FALSE;
        }
    }

    return FALSE;
}
void StartApplication( void (*StartAddress)() )
{
    PortBooterLoadProgram((void**)&StartAddress);

    hal_printf( "Starting main application at 0x%08x\r\n", (size_t)StartAddress );

    LCD_Clear();

    USART_Flush( ConvertCOM_ComPort(g_State.UsartPort) );

    if(g_State.UsingUsb)
    {
        USB_Flush( ConvertCOM_UsbStream( g_State.UsbPort ) );
        USB_CloseStream( ConvertCOM_UsbStream(g_State.UsbPort) );
        USB_Uninitialize( ConvertCOM_UsbController(g_State.UsbPort) );     //disable the USB for the next application
    }

    DISABLE_INTERRUPTS();

    LCD_Uninitialize();

    CPU_DisableCaches();

    (*StartAddress)();

}
BOOL LPC22XX_SPI_Driver::Xaction_nWrite16_nRead16( SPI_XACTION_16& Transaction )
{
        lcd_printf("\fSPI Peripheral does not support 16 bit transfer\r\n");
        hal_printf("\fSPI Peripheral does not support 16 bit transfer\r\n");
        HARD_BREAKPOINT();

        return FALSE;
}
BOOL LPC22XX_SPI_Driver::nWrite16_nRead16( const SPI_CONFIGURATION& Configuration, UINT16* Write16, INT32 WriteCount, UINT16* Read16, INT32 ReadCount, INT32 ReadStartOffset )
{

        lcd_printf("\fSPI Peripheral does not support 16 bit transfer\r\n");
        hal_printf("\fSPI Peripheral does not support 16 bit transfer\r\n");
        HARD_BREAKPOINT();
        return FALSE;
}
void ApplicationEntryPoint()
{
    while(true)
    {
        hal_printf("Hello World!\n");

        Events_WaitForEvents(0, 3000);
    }
}
BOOL AT91_SPI_Driver::nWrite16_nRead16(const SPI_CONFIGURATION &Configuration, UINT16 *Write16, INT32 WriteCount, UINT16 *Read16, INT32 ReadCount, INT32 ReadStartOffset)
{
    NATIVE_PROFILE_HAL_PROCESSOR_SPI();
    GLOBAL_LOCK(irq);
    
    SPI_DEBUG_PRINT(" spi write 16 \r\n");
    
    if(g_AT91_SPI_Driver.m_Enabled[Configuration.SPI_mod])
    {
        lcd_printf("\fSPI Xaction 1\r\n");
        hal_printf("\fSPI Xaction 1\r\n");
        HARD_BREAKPOINT();
        return FALSE;
    }

    if(Configuration.SPI_mod > AT91_SPI::c_MAX_SPI)
    {
        lcd_printf("\fSPI wrong mod\r\n");
        hal_printf("\fSPI wrong mod\r\n");
        HARD_BREAKPOINT();
        return FALSE;
    }

    if(!Xaction_Start(Configuration))
        return FALSE;
    {
        SPI_XACTION_16 Transaction;

        Transaction.Read16 = Read16;
        Transaction.ReadCount = ReadCount;
        Transaction.ReadStartOffset = ReadStartOffset;
        Transaction.Write16 = Write16;
        Transaction.WriteCount = WriteCount;
        Transaction.SPI_mod = Configuration.SPI_mod;
        Transaction.BusyPin = Configuration.BusyPin;

        if(!Xaction_nWrite16_nRead16(Transaction))
            return FALSE;
    }

    SPI_DEBUG_PRINT(" B4 xs 16 \r\n");

    return Xaction_Stop(Configuration);
}
Example #9
0
///////////////////////////////////////////////////////////////////////////////
//
// default debug channel LOG support
//
void Log::Output_DefaultDebugChannelStream( char* message, char* format )
{
    if(!format)
    {
        // debug channel specific format is just a simple string with a carriage return
        format = "%s\r\n";
    }

    hal_printf( format, message );
}
Example #10
0
void SignalActivity( void )
{
    g_State.WaitForActivity = FALSE;

    if(g_State.SerialPortActive) return;

    g_State.SerialPortActive = TRUE;

    hal_printf( "Receiving upload of SREC file...\r\n" );

    LCD_Clear();
    hal_fprintf( STREAM_LCD, "\fFlashing...\r\n\r\n" );
}
void eth_displayRxDescStatus()
{
    if (!s_pRxDesc)
    {
        return;
    }

    for (uint32_t i = 0; i < N_RX_DESC; i++)
    {
        hal_printf("%d: 0x%08x %s\r\n", i, s_rxDescriptor[i].rdes0,
                   s_pRxDesc == &s_rxDescriptor[i] ? "<===" : "");
    }
}
Example #12
0
void pagelist_init( pagelist *me, disk_page_no_t root_page, int  _init, int magic )
{
    if(_DEBUG) hal_printf("pagelist init... ");
    me->root_page = root_page;
    me->magic = magic;

    if(_DEBUG) hal_printf("disk_page_cache_init... ");
    disk_page_cache_init(&me->curr_p);
    if(_DEBUG) hal_printf("disk_page_cache_init OK... ");

    //if( _init ) init();
    if(_init)
    {
        disk_page_io            head_p;

        if(_DEBUG) hal_printf("pagelist: create empty... ");
        disk_page_io_init(&head_p);

        struct phantom_disk_blocklist* head = (struct phantom_disk_blocklist *)disk_page_io_data(&head_p);


        head->head.magic = me->magic;
        head->head.used = 0;
        head->head.next = 0;

        // to maker sure compiler will barf if field will be renamed
        head->head._reserved = 0;

        if(_DEBUG) hal_printf("pagelist saving head... ");
        disk_page_io_save_sync(&head_p,root_page);
        if(_DEBUG) hal_printf("pagelist releasing io... ");
        disk_page_io_release(&head_p);
        if(_DEBUG) hal_printf("pagelist create done... ");
    }

    if(_DEBUG) hal_printf("pagelist load head... ");
    disk_page_cache_seek_async( &me->curr_p, me->root_page ); //load_head();
    me->curr_displ = 0;

    me->curr = (struct phantom_disk_blocklist *)disk_page_cache_data(&me->curr_p);
    if(_DEBUG) hal_printf("pagelist init DONE\n");
}
/**
 * Initialize the RX descriptors as a chain structure.
 */
void eth_initRxDescriptors()
{
    uint32_t i;

    // Initialize the descriptor pointer to the first RX descriptor
    s_pRxDesc = &s_rxDescriptor[0];

    // Initialize each descriptor
    for (i = 0; i < N_RX_DESC; i++)
    {
        // Owned by DMA
        s_rxDescriptor[i].rdes0 = RDES0_OWNED_BY_DMA;

        // Chained structure
        s_rxDescriptor[i].rdes1 |= RDES1_RCH;

        // Buffer size
        s_rxDescriptor[i].rdes1 |= RX_BUFFER_LENGTH;

        // Buffer address
        s_rxDescriptor[i].rdes2 = (uint32_t)s_rxBuffer[i];

        // Assign next descriptor address
        if (i < (N_RX_DESC - 1))
        {
            s_rxDescriptor[i].rdes3 = (uint32_t)&s_rxDescriptor[i + 1];
        }
        else
        {
            s_rxDescriptor[i].rdes3 = (uint32_t)&s_rxDescriptor[0];
        }
    }

#if DEBUG_RX_DESC
    hal_printf("----- After init RX desc -----\r\n");
    eth_displayRxDescStatus();
#endif

    // Initialize receive descriptor list address register
    eth_initRxDescList((uint32_t)&s_rxDescriptor[0]);
}
//--//
BOOL __section(SectionForFlashOperations) AM29DL_16_BS_Driver::ChipInitialize( void* context )
{
    NATIVE_PROFILE_HAL_DRIVERS_FLASH();

    MEMORY_MAPPED_NOR_BLOCK_CONFIG* config = (MEMORY_MAPPED_NOR_BLOCK_CONFIG*)context;
    
    // first setup the memory for wait states, read only, etc.
    CPU_EBIU_ConfigMemoryBlock( config->Memory );

    ChipReadOnly( config, FALSE, FLASH_PROTECTION_KEY );
    
    // the flash are now not write protected
    {
        FLASH_WORD ManufacturerCode = 0;
        FLASH_WORD DeviceCode       = 0;

        if(ReadProductID(config, ManufacturerCode, DeviceCode ))
        {
            hal_printf( "Flash product Manufacturer Code = 0x%08x, Device Code = 0x%08x\r\n", ManufacturerCode, DeviceCode );

            if(ManufacturerCode != config->ManufacturerCode) 
            {
                debug_printf( "ERROR: Unsupported Flash Manufacturer code: 0x%08x\r\n", ManufacturerCode );
            }

            if(DeviceCode != config->DeviceCode) 
            {
                debug_printf( "ERROR: Unsupported Flash Device code: 0x%08x\r\n", DeviceCode );
            }
        }
        else
        {
            debug_printf( "Flash_ReadProductID() failed.\r\n" );
        }
    }

    ChipReadOnly(config, TRUE, FLASH_PROTECTION_KEY );
    // the flash are now write protected

    return TRUE;
}
static void findPhyAddr()
{
    uint32_t phyAddress = 0;
    uint16_t value;
    uint32_t rc = 0xFF;
    uint32_t cnt = 31;          // 5 bit address
    uint16_t ret;
    do
    {
        ret = eth_readPhyRegister(phyAddress, PHY_IDENTIFIER_REGISTER_1, &value );
        if ((value == PHY_KENDIN_OUI_ID1) || (value == PHY_ST802RT1X_OUI_ID1))
        {
            rc = phyAddress;
            hal_printf( "Valid PHY Found: %x (%x)\r\n", rc, value);
            g_foundPhyAddress = TRUE;
            g_phyAddress = phyAddress;
            
            break;
        }
        phyAddress = (phyAddress + 1) & 0x1F;

    }while(--cnt);

}
// 81 Interrupt IRQ5
    void INT_IRQ5(void){hal_printf( "INT_IRQ5\r\n" );/* sleep(); */}
BOOL MC9328MXL_SPI_Driver::Xaction_Start( const SPI_CONFIGURATION& Configuration )
{
    NATIVE_PROFILE_HAL_PROCESSOR_SPI();
    if(!g_MC9328MXL_SPI_Driver.m_Enabled[Configuration.SPI_mod])
    {
        g_MC9328MXL_SPI_Driver.m_Enabled[Configuration.SPI_mod] = TRUE;

        UINT32 index = Configuration.SPI_mod;

        MC9328MXL_SPI & SPI = MC9328MXL::SPI(index);

        // make sure we didn't start one in the middle of an existing transaction
        if( SPI.CONTROLREG & SPI.CONTROLREG_SPIEN )
        {
            lcd_printf("\fSPI Collision 1\r\n");
            hal_printf("\fSPI Collision 1\r\n");
            HARD_BREAKPOINT();

            return FALSE;
        }

        // first build the mode register
        SPI.CONTROLREG = MC9328MXL_SPI::ConfigurationToMode( Configuration );

        // LCD Controller needs to have Pulse mode enabled
#if (HARDWARE_BOARD_TYPE >= HARDWARE_BOARD_i_MXS_DEMO_REV_V1_2)
        if(Configuration.DeviceCS == MC9328MXL_SPI::c_SPI1_SS)
        {
            SPI.PERIODREG = 2;

            SPI.CONTROLREG |= MC9328MXL_SPI::CONTROLREG_SSCTL_PULSE;       // Pulse SS between bursts

            // set the SSPOL to active lo as it is force at the ConfigurationMOde to not trigger SS for other SPI operation
            SPI.CONTROLREG &= (~MC9328MXL_SPI::CONTROLREG_SSPOL_HIGH);       // Pulse SS between bursts
            CPU_GPIO_DisablePin( MC9328MXL_SPI::c_SPI1_SS,RESISTOR_DISABLED, 0, GPIO_ALT_PRIMARY);

        }
#endif


        SPI.CONTROLREG |= MC9328MXL_SPI::CONTROLREG_SPIEN;

#if (SPI_LOOP_BACK)
        // for spi testing
        SPI.TESTREG |= SPI.TESTREG_LBC;
#endif

        // everything should be clean and idle
        ASSERT( SPI.TransmitBufferEmpty());
        ASSERT( SPI.ReceiveBufferEmpty());
        ASSERT( SPI.ShiftBufferEmpty  ());

        // make sure not trigger the SS pin for the LCD when doing any SPI activity.
        // but we can have LCD SPI activity, if so, we want the SS be able to drive
#if (HARDWARE_BOARD_TYPE >= HARDWARE_BOARD_i_MXS_DEMO_REV_V1_2)
        if(Configuration.DeviceCS != MC9328MXL_SPI::c_SPI1_SS)
        {
            CPU_GPIO_EnableInputPin( MC9328MXL_SPI::c_SPI1_SS, FALSE, NULL, GPIO_INT_NONE, RESISTOR_PULLUP );
        }
#endif

#if defined(PLATFORM_ARM_MC9328MXS)
        // make sure that we don't trigger the SS pin for LCD
        CPU_GPIO_DisablePin( MC9328MXL_SPI::c_SPI1_SCLK, RESISTOR_DISABLED, 0, GPIO_ALT_PRIMARY);
        CPU_GPIO_DisablePin( MC9328MXL_SPI::c_SPI1_MOSI, RESISTOR_DISABLED, 0, GPIO_ALT_PRIMARY);
#else  // MC9328MXL
        if (index == MC9328MXL_SPI::c_SPI1)
        {
            // allow peripheral control of pins
            CPU_GPIO_DisablePin( MC9328MXL_SPI::c_SPI1_SCLK, RESISTOR_DISABLED, 0, GPIO_ALT_PRIMARY);
            CPU_GPIO_DisablePin( MC9328MXL_SPI::c_SPI1_MOSI, RESISTOR_DISABLED, 0, GPIO_ALT_PRIMARY);
        }
        else
        {
            // SPI2 need to set to Alternate function - AIN
            CPU_GPIO_DisablePin(MC9328MXL_SPI::c_SPI2_SCLK, RESISTOR_DISABLED, MC9328MXL_GPIO::DDIR__OUT, GPIO_ALT_MODE_1);
            CPU_GPIO_DisablePin(MC9328MXL_SPI::c_SPI2_MOSI, RESISTOR_DISABLED, MC9328MXL_GPIO::DDIR__OUT, GPIO_ALT_MODE_1);
        }
#endif

        // first set CS active as soon as clock and data pins are in proper initial state
        if((Configuration.DeviceCS != MC9328MXL_GPIO::c_Pin_None) && (Configuration.DeviceCS != MC9328MXL_SPI::c_SPI1_SS))
        {
            CPU_GPIO_EnableOutputPin( Configuration.DeviceCS, Configuration.CS_Active );
        }

#if defined(PLATFORM_ARM_MC9328MXS)
        CPU_GPIO_DisablePin( MC9328MXL_SPI::c_SPI1_MISO, RESISTOR_DISABLED, 0, GPIO_ALT_PRIMARY );
#else
        if (index == MC9328MXL_SPI::c_SPI1)
        {
            CPU_GPIO_DisablePin( MC9328MXL_SPI::c_SPI1_MISO, RESISTOR_DISABLED, 0, GPIO_ALT_PRIMARY );
        }
        else
        {
            // set AOUT mode for MISO for SPI 2
            CPU_GPIO_DisablePin(MC9328MXL_SPI::c_SPI2_MISO, RESISTOR_DISABLED,MC9328MXL_GPIO::DDIR__IN ,GPIO_ALT_MODE_4);
            MC9328MXL::SC().FMCR |= MC9328MXL_SC::FMCR__SPI2_RXD_SEL;
        }
#endif

        if(Configuration.CS_Setup_uSecs)
        {
            HAL_Time_Sleep_MicroSeconds_InterruptEnabled( Configuration.CS_Setup_uSecs );
        }
    }
    else
    {
        lcd_printf( "\fSPI Collision 3\r\n" );
        HARD_BREAKPOINT();

        return FALSE;
    }

    return TRUE;
}
void KeyPad_Test()
{
    NATIVE_PROFILE_PAL_BUTTONS();
    int return_value;
    
    hal_printf("\r\n\nKeyscan Test (press 'Stop' to exit)\r\n");
    
    g_GPIO_KEYPAD_Driver.KeyPad_Initialize();
        
    /* start keyscan */
    /* NOTE: enter "Stop" to exit the loop */
    while (1)
    {
        return_value = g_GPIO_KEYPAD_Driver.KeyPad_Search();
        
        if ( return_value != -1 ) 
        {           
            switch ( return_value ) 
            {   
                case 1:
                    hal_printf("UP\r\n");
                    break;
                case 2:
                    hal_printf("DOWN\r\n");
                    break;
                case 3:
                    hal_printf("LEFT\r\n");
                    break;
                case 4:
                    hal_printf("RIGHT\r\n");
                    break;
                case 5:
                    hal_printf("OK\r\n");
                    break;
                case 6:
                    hal_printf("Fn\r\n");
                    break;
                case 7:
                    hal_printf("C\r\n");
                    break;
                case 8:
                    hal_printf("Dial\r\n");
                    break;
                case 9:
                    hal_printf("Hang Up\r\n");
                    break;
                case 10:
                    hal_printf("1\r\n");                    
                    break;
                case 11:
                    hal_printf("2\r\n");
                    break;
                case 12:
                    hal_printf("3\r\n");
                    break;
                case 13:
                    hal_printf("4\r\n");
                    break;
                case 14:
                    hal_printf("5\r\n");
                    break;
                case 15:
                    hal_printf("6\r\n");
                    break;
                case 16:
                    hal_printf("7\r\n");
                    break;
                case 17:
                    hal_printf("8\r\n");
                    break;
                case 18:
                    hal_printf("9\r\n");
                    break;
                case 19:
                    hal_printf("*\r\n");
                    break;
                case 20:
                    hal_printf("0\r\n");
                    break;
                case 21:
                    hal_printf("#\r\n");
                    break;
                case 22:
                    hal_printf("Prev\r\n");
                    break;
                case 23:
                    hal_printf("Stop\r\n");
                    hal_printf("Exit Keypad Test");
                    return;                 
                    break;
                case 24:
                    hal_printf("Play\r\n");
                    break;
                case 25:
                    hal_printf("Next\r\n");
                    break;                  
            }       
        }
        else
        {
            //hal_printf("ERROR!!\r\n");
        }  
    }
}
Example #19
0
////////////////////////////////////////////////////////////////////////////////
// The TinyBooter_OnStateChange method is an event handler for state changes in 
// the TinyBooter.  It is designed to help porting kit users control the tinybooter
// execution and allow them to add diagnostics.
////////////////////////////////////////////////////////////////////////////////
void TinyBooter_OnStateChange( TinyBooterState state, void* data, void ** retData )
{
    switch(state)
    {
        ////////////////////////////////////////////////////////////////////////////////////
        // State_EnterBooterMode - TinyBooter has entered upload mode
        ////////////////////////////////////////////////////////////////////////////////////
        case State_EnterBooterMode:
            CPU_GPIO_EnableOutputPin(LED1, TRUE);
            CPU_GPIO_EnableOutputPin(LED2, TRUE);
            CPU_GPIO_EnableOutputPin(LED3, TRUE);
#if defined(TARGETLOCATION_RAM)
            CPU_GPIO_EnableOutputPin(LED4, TRUE);
#else
            CPU_GPIO_EnableOutputPin(LED4, FALSE);
#endif
            hal_fprintf( STREAM_LCD, "Waiting\r" );
            break;

        ////////////////////////////////////////////////////////////////////////////////////
        // State_ButtonPress - A button was pressed while Tinybooter 
        // The data parameter is a pointer to the timeout value for the booter mode.
        ////////////////////////////////////////////////////////////////////////////////////
        case State_ButtonPress:
            if(NULL != data)
            {
                UINT32 down, up;
                INT32* timeout_ms = (INT32*)data;
                
                // wait forever if a button was pressed
                *timeout_ms = -1;

                // process buttons
                while(Buttons_GetNextStateChange(down, up))
                {
                    // leave a way to exit boot mode incase it was accidentally entered
                     if(0 != (down & BUTTON_ENTR)) 
                     {
                        // force an enumerate and launch
                        *timeout_ms = 0; 
                     }
                }
            }
            break;

        ////////////////////////////////////////////////////////////////////////////////////
        // State_ValidCommunication - TinyBooter has received valid communication from the host
        // The data parameter is a pointer to the timeout value for the booter mode.
        ////////////////////////////////////////////////////////////////////////////////////
        case State_ValidCommunication:
            if(NULL != data)
            {
                INT32* timeout_ms = (INT32*)data;

                // if we received any com/usb data then let's change the timeout to at least 20 seconds
                if(*timeout_ms != -1 && *timeout_ms < 20000)
                {
                    *timeout_ms = 20000;
                }
            }
            break;

        ////////////////////////////////////////////////////////////////////////////////////
        // State_Timeout - The default timeout for TinyBooter has expired and TinyBooter will 
        // perform an EnumerateAndLaunch
        ////////////////////////////////////////////////////////////////////////////////////
        case State_Timeout:
            break;

        ////////////////////////////////////////////////////////////////////////////////////
        // State_MemoryXXX - Identifies memory accesses.
        ////////////////////////////////////////////////////////////////////////////////////
        case State_MemoryWrite:
            hal_fprintf( STREAM_LCD, "Wr: 0x%08x\r", (UINT32)data );
            break;
        case State_MemoryErase:
            hal_fprintf( STREAM_LCD, "Er: 0x%08x\r", (UINT32)data );
            break;

            
        ////////////////////////////////////////////////////////////////////////////////////
        // State_CryptoXXX - Start and result of Crypto signature check
        ////////////////////////////////////////////////////////////////////////////////////
        case State_CryptoStart:
            hal_fprintf( STREAM_LCD,     "Chk signature \r" );
            hal_printf( "Chk signature \r" );
            break;
        // The data parameter is a boolean that represents signature PASS/FAILURE
        case State_CryptoResult:
            if((bool)data)
            {
                hal_fprintf( STREAM_LCD, "Signature PASS\r\n\r\n" );
                hal_printf( "Signature PASS\r\n\r\n" );
            }
            else
            {
                hal_fprintf( STREAM_LCD, "Signature FAIL\r\n\r\n" );
                hal_printf( "Signature FAIL\r\n\r\n"  );
            }
            DebuggerPort_Flush(HalSystemConfig.DebugTextPort);
            break;

        ////////////////////////////////////////////////////////////////////////////////////
        // State_Launch - The host has requested to launch an application at a given address, 
        //                or a timeout has occured and TinyBooter is about to launch the 
        //                first application it finds in FLASH.
        //
        // The data parameter is a UINT32 value representing the launch address
        ////////////////////////////////////////////////////////////////////////////////////
        case State_Launch:
            if(NULL != data)
            {
                CPU_GPIO_EnableOutputPin(LED1, FALSE);
                hal_fprintf( STREAM_LCD, "Starting application at 0x%08x\r\n", (UINT32)data );
                // copy the native code from the Load area to execute area.
                // set the *retAddres to real execute address after loading the data
                // *retData =  exeAddress 
               *retData =(void*) ((UINT32)data | 1); // set Thumb bit!
            }
            break;
    }
            
}
Example #20
0
BOOL USART_Driver::AddCharToRxBuffer( int ComPortNum, char c )
{
    ASSERT_IRQ_MUST_BE_OFF();

    if((ComPortNum < 0) || (ComPortNum >= TOTAL_USART_PORT)) return FALSE;

    HAL_USART_STATE& State = Hal_Usart_State[ComPortNum];

    if (USART_FLAG_STATE(State, HAL_USART_STATE::c_TX_SWFLOW_CTRL))

    {
        switch( c )
        {
            case XOFF:
                State.TicksStartTxXOFF = HAL_Time_CurrentTicks();
                CLEAR_USART_FLAG(State, HAL_USART_STATE::c_TX_XON_STATE);
                return TRUE;
            case XON:
                SET_USART_FLAG(State, HAL_USART_STATE::c_TX_XON_STATE);
                return TRUE;
        }
    }


    {
        GLOBAL_LOCK(irq);

        UINT8* Dst = State.RxQueue.Push();

        if(Dst)
        {
            *Dst = c;

            if( State.RxQueue.NumberOfElements() >= State.RxBufferHighWaterMark )
            {
                if( USART_FLAG_STATE(State, HAL_USART_STATE::c_RX_SWFLOW_CTRL) )
                {
                    // Set our XOFF state
                    SendXOFF( ComPortNum, XOFF_FLAG_FULL );
                }
                if( USART_FLAG_STATE(State, HAL_USART_STATE::c_RX_HWFLOW_CTRL) )
                {
                    // Hold off receiving characters (should pull HW handshake automatically)
                    CPU_USART_RxBufferFullInterruptEnable(ComPortNum, FALSE);
                }
            }
        }
        
        else
        {
            SetEvent( ComPortNum, USART_EVENT_ERROR_RXOVER );
                
#if !defined(BUILD_RTM)
            lcd_printf("\fBuffer OVFLW\r\n");
            hal_printf("Buffer OVFLW\r\n");
#endif
            return FALSE;
        }
    }

    SetEvent( ComPortNum, USART_EVENT_DATA_CHARS );

    Events_Set( SYSTEM_EVENT_FLAG_COM_IN );

    return TRUE;
}
void ApplicationEntryPoint()
{
    char Data[1], previousChar = '\0';
    int ret = 0, TestItem = 0;
    BOOL validCommand = TRUE;
	
	MEMORY_MAPPED_NOR_BLOCK_CONFIG* config;
	
//    BlockStorageDevice *device;
//    ByteAddress datByteAddress;

//    BlockStorageList::FindDeviceForPhysicalAddress( &device, 0, datByteAddress );
//    const BlockDeviceInfo * deviceInfo=device->GetDeviceInfo();


    
    Data[1] = '\0';
    char ip[15];
    int length;
    unsigned long dest_ip=0;
    UINT32 sleep = 100;

//    TimedEvents eventsTest;
 //   UART        usartTest  ( COMTestPort, 9600, USART_PARITY_NONE, 8, USART_STOP_BITS_ONE, USART_FLOW_NONE );
//    GPIO        gpioTest   ( GPIOTestPin );

    do
    {
        lcd_printf( "\n\n\n\n\n\n\n\n   SH7619 EVB\n" );
        lcd_printf( " Renesas America       Inc." );
                
        //Serial TEST
        hal_printf( "\r\nSH7619 EVB .NET Micro Framework NativeSample\r\n" );
        hal_printf( "Renesas Electronics America Inc.\r\n" );
        hal_printf( "61 MHz Clk,Big-endian\r\n" );      
        hal_printf( ">" );
        
        NATIVE_PROFILE_PAL_EVENTS();
        do
        {
            UINT32 Events = Events_WaitForEvents( SYSTEM_EVENT_FLAG_COM_IN | SYSTEM_EVENT_FLAG_ETHER, sleep );

            // if(Events == 0)
            // {
                // hal_printf("Slept %d sec\r\n", sleep / 1000);
                // sleep += 1000; 
                // continue;
            // }
            
            if(Events & SYSTEM_EVENT_FLAG_ETHER)            
            {
                //Network_Interface_Process_Packet();
				//hal_printf("ETHER event\r\n");
                Events_Clear( SYSTEM_EVENT_FLAG_ETHER );
            }
                        
            if(Events & SYSTEM_EVENT_FLAG_COM_IN)           
            {
                Events_Clear( SYSTEM_EVENT_FLAG_COM_IN );
                while((ret = DebuggerPort_Read( HalSystemConfig.DebugTextPort, Data, 1 )) > 0)
                {                   
                    switch(TestItem)
                    {
                        case 0:     //None
                            if(Data[0] == 0xD)              //0xD: ENTER key
                            {                               
                                hal_printf( "\r\n" );
                                if(validCommand)
                                {
                                    TestItem = 1;           //Enter test
                                    validCommand = FALSE;
                                    previousChar = '\0';
                                    hal_printf( "\r\nTest Menu:\r\n" );
                                    hal_printf( "   [L]CD Tests\r\n" );
                                    hal_printf( "   [K]eypad Tests\r\n" );
                                    hal_printf( "   [N]etwork Tests\r\n" );
                                    hal_printf( "   [F]lash memory Tests\r\n" );
                                    hal_printf( "   E[x]it\r\n" );
                                    hal_printf( "Your choice: " );
                                }
                                else if(previousChar == 'I')
                                {
                                    hal_printf("** Invalid Selection\r\n>");
                                    previousChar = '\0';
                                }
                                else
                                    hal_printf( ">" );
                            }
                            else
                            {
                                hal_printf( Data );
                                if(Data[0] == 'd' || Data[0] == 'D')
                                {
                                    if(previousChar == '\0')
                                        previousChar = 'd';
                                    else
                                    {
                                        validCommand = FALSE;
                                        previousChar = 'I';     //Invalid character input
                                    }
                                }
                                else if(Data[0] == 't' || Data[0] == 'T')
                                {
                                    if(previousChar == 'd')
                                    {
                                        previousChar = 't';
                                        validCommand = TRUE;
                                    }
                                    else
                                    {
                                        validCommand = FALSE;
                                        previousChar = 'I';     //Invalid character input
                                    }
                                }
                                else
                                {
                                    validCommand = FALSE;
                                    previousChar = 'I';         //Invalid character input
                                }
                            }
                            break;
                        case 1:     //Enter test
                            hal_printf( Data );
                            switch(Data[0])
                            {
                                case 'X':
                                case 'x':
                                    TestItem = 0;
                                    hal_printf( "\r\n\n>" );
                                    break;
                                case 'L':
                                case 'l':
                                    TestItem = 5;
                                    hal_printf( "\r\n\nLCD Menu:\r\n" );
                                    hal_printf( "   1: Display colorful rectangles\r\n" );
                                    hal_printf( "   2: Colorful wireframe rectangle\r\n" );
                                    hal_printf( "   3: Colorful solid rectangle\r\n" );
                                    hal_printf( "   E[x]it\r\n" );
                                    hal_printf( "Your choice: " );
                                    break;
                                case 'K':
                                case 'k':
                                    KeyPad_Test();                                  
                                    break;
                                case 'N':
                                case 'n':
                                    TestItem = 7;
                                    hal_printf( "\r\n\nEthernet Menu:\r\n" );
                                    hal_printf( "   [1]Read IP Address\r\n" );
                                    hal_printf( "   [2]Read EtherC Registers\r\n" );
                                    hal_printf( "   [3]Read E-DMAC Registers\r\n" );
                                    hal_printf( "   [4]Ping Test\r\n" );
                                    hal_printf( "   E[x]it\r\n" );
                                    hal_printf( "Your choice: " );
                                    break;                              
                                case 'F':
                                case 'f':
                                    TestItem = 8;
                                    hal_printf( "\r\n\nFlash memory Menu:\r\n" );
                                    hal_printf( "   [1]Erase block\r\n" );
                                    hal_printf( "   [2]write block\r\n" );
                                    hal_printf( "   E[x]it\r\n" );
                                    hal_printf( "Your choice: " );
                                    break;                              
                                default:
                                    hal_printf( "\r\n\nTest Menu:\r\n" );
                                    hal_printf( "   [L]CD Tests\r\n" );
                                    hal_printf( "   [K]eypad Tests\r\n" );
                                    hal_printf( "   [N]etwork Tests\r\n" );
                                    hal_printf( "   [F]lash memory Tests\r\n" );
                                    hal_printf( "   E[x]it\r\n" );
                                    hal_printf( "Your choice: " );
                                    break;
                            }
                            break;
                        case 5:     //LCD test
                            hal_printf( Data );
                            switch(Data[0])
                            {
                                case 'X':
                                case 'x':
                                    TestItem = 1;
                                    hal_printf( "\r\n\nTest Menu:\r\n" );
                                    hal_printf( "   [L]CD Tests\r\n" );
                                    hal_printf( "   [K]eypad Tests\r\n" );
                                    hal_printf( "   [N]etwork Tests\r\n" );
                                    hal_printf( "   [F]lash memory Tests\r\n" );
                                    hal_printf( "   E[x]it\r\n" );
                                    hal_printf( "Your choice: " );
                                    break;
                                case '1':
                                    LCDTest_Driver::LCD_Sample1();
                                    hal_printf( "\r\n\nLCD Menu:\r\n" );
                                    hal_printf( "   1: Display colorful rectangles\r\n" );
                                    hal_printf( "   2: Colorful wireframe rectangle\r\n" );
                                    hal_printf( "   3: Colorful solid rectangle\r\n" );
                                    hal_printf( "   E[x]it\r\n" );
                                    hal_printf( "Your choice: " );
                                    break;
                                case '2':
                                    LCDTest_Driver::LCD_Sample2(0);
                                    hal_printf( "\r\n\nLCD Menu:\r\n" );
                                    hal_printf( "   1: Display colorful rectangles\r\n" );
                                    hal_printf( "   2: Colorful wireframe rectangle\r\n" );
                                    hal_printf( "   3: Colorful solid rectangle\r\n" );
                                    hal_printf( "   E[x]it\r\n" );
                                    hal_printf( "Your choice: " );
                                    break;
                                case '3':
                                    LCDTest_Driver::LCD_Sample2(1);
                                    hal_printf( "\r\n\nLCD Menu:\r\n" );
                                    hal_printf( "   1: Display colorful rectangles\r\n" );
                                    hal_printf( "   2: Colorful wireframe rectangle\r\n" );
                                    hal_printf( "   3: Colorful solid rectangle\r\n" );
                                    hal_printf( "   E[x]it\r\n" );
                                    hal_printf( "Your choice: " );
                                    break;
                                default:
                                    hal_printf( "\r\n\nLCD Menu:\r\n" );
                                    hal_printf( "   1: Display colorful rectangles\r\n" );
                                    hal_printf( "   2: Colorful wireframe rectangle\r\n" );
                                    hal_printf( "   3: Colorful solid rectangle\r\n" );
                                    hal_printf( "   E[x]it\r\n" );
                                    hal_printf( "Your choice: " );
                                    break;
                            }
                            break;
                        case 7:     //Ethernet test
                            hal_printf( Data );
                            hal_printf( "\r\n" );
                            switch(Data[0])
                            {
                                case 'X':
                                case 'x':
                                    TestItem = 1;
                                    hal_printf( "\r\n\nTest Menu:\r\n" );
                                    hal_printf( "   [L]CD Tests\r\n" );
                                    hal_printf( "   [K]eypad Tests\r\n" );
                                    hal_printf( "   [N]etwork Tests\r\n" );
                                    hal_printf( "   [F]lash memory Tests\r\n" );
                                    hal_printf( "   E[x]it\r\n" );
                                    hal_printf( "Your choice: " );
                                    break;
                                case '1':
                                    //Network_Interface_IP_Address();                                 
                                    hal_printf( "\r\n\nEthernet Menu:\r\n" );
                                    hal_printf( "   [1]Read IP Address\r\n" );
                                    hal_printf( "   [2]Read EtherC Registers\r\n" );
                                    hal_printf( "   [3]Read E-DMAC Registers\r\n" );
                                    hal_printf( "   [4]Ping Test\r\n" );
                                    hal_printf( "   E[x]it\r\n" );
                                    hal_printf( "Your choice: " );
                                    break;
                                case '2':
                                    //Network_Interface_EtherC_Registers();
                                    hal_printf( "\r\n\nEthernet Menu:\r\n" );
                                    hal_printf( "   [1]Read IP Address\r\n" );
                                    hal_printf( "   [2]Read EtherC Registers\r\n" );
                                    hal_printf( "   [3]Read E-DMAC Registers\r\n" );
                                    hal_printf( "   [4]Ping Test\r\n" );
                                    hal_printf( "   E[x]it\r\n" );
                                    hal_printf( "Your choice: " );
                                    break;
                                case '3':
                                    //Network_Interface_EDMAC_Registers();
                                    hal_printf( "\r\n\nEthernet Menu:\r\n" );
                                    hal_printf( "   [1]Read IP Address\r\n" );
                                    hal_printf( "   [2]Read EtherC Registers\r\n" );
                                    hal_printf( "   [3]Read E-DMAC Registers\r\n" );
                                    hal_printf( "   [4]Ping Test\r\n" );
                                    hal_printf( "   E[x]it\r\n" );
                                    hal_printf( "Your choice: " );
                                    break;                              
                                case '4':
                                    //do
                                    //{
                                    //    hal_printf( "\r\nEnter dest IP: " );
                                    //    Get_IP_String(ip, &length);
                                    //    if( (dest_ip = Is_IP_Address(ip, length)) == 0)
                                    //        hal_printf( "\r\n*** Invalid IP Address!\r\n" );
                                    //}while(dest_ip == 0);
                                    //Ether_Ping(dest_ip, 4); 
                                    hal_printf( "\r\n\nEthernet Menu:\r\n" );
                                    hal_printf( "   [1]Read IP Address\r\n" );
                                    hal_printf( "   [2]Read EtherC Registers\r\n" );
                                    hal_printf( "   [3]Read E-DMAC Registers\r\n" );
                                    hal_printf( "   [4]Ping Test\r\n" );
                                    hal_printf( "   E[x]it\r\n" );
                                    hal_printf( "Your choice: " );
                                    break;                          
                                default:
                                    hal_printf( "\r\n\nEthernet Menu:\r\n" );
                                    hal_printf( "   [1]Read IP Address\r\n" );
                                    hal_printf( "   [2]Read EtherC Registers\r\n" );
                                    hal_printf( "   [3]Read E-DMAC Registers\r\n" );
                                    hal_printf( "   [4]Ping Test\r\n" );
                                    hal_printf( "   E[x]it\r\n" );
                                    hal_printf( "Your choice: " );
                                    break;
                            }
                            break;
                        case 8:     //Flash memory test
                            hal_printf( Data );
                            hal_printf( "\r\n" );
                            switch(Data[0])
                            {
                                case 'X':
                                case 'x':
                                    TestItem = 1;
                                    hal_printf( "\r\n\nTest Menu:\r\n" );
                                    hal_printf( "   [L]CD Tests\r\n" );
                                    hal_printf( "   [K]eypad Tests\r\n" );
                                    hal_printf( "   [N]etwork Tests\r\n" );
                                    hal_printf( "   [F]lash memory Tests\r\n" );
                                    hal_printf( "   E[x]it\r\n" );
                                    hal_printf( "Your choice: " );
                                    break;
                                case '1':
									g_AM29DL_16_BS_DeviceTable.InitializeDevice(pBLOCK_CONFIG);
									g_AM29DL_16_BS_DeviceTable.EraseBlock(pBLOCK_CONFIG,0xa0080000);
                                    hal_printf( "\r\n\nFlash memory Menu:\r\n" );
                                    hal_printf( "   [1]Erase block\r\n" );
                                    hal_printf( "   [2]write block\r\n" );
                                    hal_printf( "   E[x]it\r\n" );
                                    hal_printf( "Your choice: " );
                                    break;
                                case '2':
									BYTE Buff[0x10];
									for(int i=0; i<0x10; i++) Buff[i]=i;
									g_AM29DL_16_BS_DeviceTable.InitializeDevice(pBLOCK_CONFIG);
									g_AM29DL_16_BS_DeviceTable.Write(pBLOCK_CONFIG,0xa0080000,0x10,Buff,0x0);
                                    hal_printf( "\r\n\nFlash memory Menu:\r\n" );
                                    hal_printf( "   [1]Erase block\r\n" );
                                    hal_printf( "   [2]write block\r\n" );
                                    hal_printf( "   E[x]it\r\n" );
                                    hal_printf( "Your choice: " );
                                    break;
                                default:
                                    hal_printf( "\r\n\nFlash memory Menu:\r\n" );
                                    hal_printf( "   [1]Erase block\r\n" );
                                    hal_printf( "   [2]write block\r\n" );
                                    hal_printf( "   E[x]it\r\n" );
                                    hal_printf( "Your choice: " );
                                    break;
                            }
                            break;
                    }
                }
            }           
        } while(TRUE);
    } while(FALSE); // run only once!
}
void SH7619_EDMAC_recv(PIFACE pi)
{
	DCU               	msg;
	RTP_UINT16         	FrameLength = 0;
	long 				leng;
	UINT16             	BufferLength;
	UINT32  			tmpIdx = rxTd.idx;
	char*				recv_packet;
	int					tries = 100;
	BOOL				recv_error = FALSE;
	BOOL				mem_error = FALSE;
	EmacTDescriptor 	*pRxTd;
	BOOL isFrame = FALSE;
	
	GLOBAL_LOCK(encIrq);

	pRxTd = *(rxTd.td + rxTd.idx);

	while ((pRxTd->status & ACT) != 0 && tries-- > 0)
	{
		for(int i = 0; i < 500; i++);
	}

	if(tries <= 0)
	{
		//while ((pRxTd->status & ACT) != 0 && tries++ < RX_BUFFERS)
		//{
		//	CIRC_INC(rxTd.idx, RX_BUFFERS);
		//	pRxTd = *(rxTd.td + rxTd.idx);
		//}
		//tmpIdx = rxTd.idx;
		return;
	}

	while ((pRxTd->status & ACT) == 0)
	{
		leng = pRxTd->RDL;
		// A start of frame has been received
		if((pRxTd->status & FP1) != 0) 
		{
			// Skip previous fragment
			while (tmpIdx != rxTd.idx)
			{
				pRxTd = *(rxTd.td + rxTd.idx);
				pRxTd->status |= ACT;
				CIRC_INC(rxTd.idx, RX_BUFFERS);
			}

			FrameLength = 0;

			// Start to gather buffers in a frame
			isFrame = TRUE;
		}

		// Increment the pointer
		CIRC_INC(tmpIdx, RX_BUFFERS);

		if(isFrame)
		{
			if (tmpIdx == rxTd.idx) 
			{
				hal_printf("Receive buffer is too small for the current frame!\r\n");
				do
				{
					//FrameLength += pRxTd->RDL;
					pRxTd = *(rxTd.td + rxTd.idx);
					pRxTd->status |= ACT;
					CIRC_INC(rxTd.idx, RX_BUFFERS);
				} while(tmpIdx != rxTd.idx);
			}

			if((pRxTd->status & FE) != 0) 
			{
				recv_error = TRUE;
			}

			FrameLength += leng;

			// An end of frame has been received
			if((pRxTd->status & FP0) != 0)
			{
				tries = 0;

				if(recv_error == FALSE)
				{				
					do
					{
						msg = os_alloc_packet_input(FrameLength, DRIVER_ALLOC);
						if(!msg)
							for(int i = 0; i < 5000; i++);		//delay
					}while(!msg && tries++ < 50);

					if (msg)
					{
						recv_packet = (char*)DCUTODATA(msg);
						msg->length = FrameLength;
					}
					else
					{
						mem_error = TRUE;
					}
				}
				else
				{
					mem_error = TRUE;
				}

				BufferLength = EMAC_RX_UNITSIZE;
				// Get all the data
				while (rxTd.idx != tmpIdx)
				{                   
					pRxTd = *(rxTd.td + rxTd.idx);

					if(mem_error == FALSE)
					{
						if(BufferLength >= FrameLength)
						{
							memcpy(recv_packet, (void*)(pRxTd->TRBA), FrameLength);
						}
						else
						{
							memcpy(recv_packet, (void*)(pRxTd->TRBA), BufferLength);
							FrameLength -= BufferLength;
							recv_packet += BufferLength;
						}
					}

					pRxTd->status |= ACT;
					CIRC_INC(rxTd.idx, RX_BUFFERS);
				}
                
				// signal IP layer that a packet is on its exchange
				if(mem_error == FALSE)
					rtp_net_invoke_input(pi, msg, msg->length);

				// Prepare for the next Frame
				isFrame = FALSE;
				recv_error = FALSE;
				mem_error = FALSE;
			}
		}// if(isFrame) ends
		else
		{
			pRxTd->status |= ACT;
			rxTd.idx = tmpIdx;		   
		}

		// Process the next buffer
		pRxTd = *(rxTd.td + tmpIdx);
	}
}
RTP_BOOL SH7619_EDMAC_open(PIFACE pi)   
{
	PSH7619_EDMAC_SOFTC sc = iface_to_softc(pi);
    char c[1],Buffer[17];
	int i;
    UINT32 Events;
	BYTE Buff[6];

	if (!sc)
	{
		RTP_DEBUG_ERROR("SH7619_EDMAC_open: softc invalid!\r\n", NOVAR, 0, 0);
		set_errno(ENUMDEVICE);
		return(RTP_FALSE);
	}

	// Set Interface
	sc->iface = pi;
	iface = pi;

	int macLen = __min(g_NetworkConfig.NetworkInterfaces[NETWORK_INTERFACE_INDEX_SH7619EMAC].macAddressLen, sizeof(sc->mac_address));

	if(macLen > 0)
	{

	    int addr = MAC_address_area;
		for(i=0; i<macLen; i++) g_NetworkConfig.NetworkInterfaces[NETWORK_INTERFACE_INDEX_SH7619EMAC].macAddressBuffer[i] = *(volatile char *)(addr+i);
	
        debug_printf( "MAC Address: %x.%x.%x.%x.%x.%x\r\n", (UINT8)g_NetworkConfig.NetworkInterfaces[NETWORK_INTERFACE_INDEX_SH7619EMAC].macAddressBuffer[0], 
                                                             (UINT8)g_NetworkConfig.NetworkInterfaces[NETWORK_INTERFACE_INDEX_SH7619EMAC].macAddressBuffer[1],
                                                             (UINT8)g_NetworkConfig.NetworkInterfaces[NETWORK_INTERFACE_INDEX_SH7619EMAC].macAddressBuffer[2],
                                                             (UINT8)g_NetworkConfig.NetworkInterfaces[NETWORK_INTERFACE_INDEX_SH7619EMAC].macAddressBuffer[3],
                                                             (UINT8)g_NetworkConfig.NetworkInterfaces[NETWORK_INTERFACE_INDEX_SH7619EMAC].macAddressBuffer[4],
                                                             (UINT8)g_NetworkConfig.NetworkInterfaces[NETWORK_INTERFACE_INDEX_SH7619EMAC].macAddressBuffer[5]);
	    debug_printf( "Do you need to change MAC Address? If yes, press 'Enter' key\r\n" );
		c[0] = 0x0;
    	for (i=0; i<0xff; i++){
			DebuggerPort_Read( HalSystemConfig.DebugTextPort, c, 1);
			if (c[0] == 0x0d){
			    hal_printf( "new MAC Address :" );
				while(c[0] == 0x0d) DebuggerPort_Read( HalSystemConfig.DebugTextPort, c, 1);
				for(i=0; i<17; ){
		            Events = Events_WaitForEvents( SYSTEM_EVENT_FLAG_COM_IN, 100 );
		            if(Events & SYSTEM_EVENT_FLAG_COM_IN){
						Events_Clear( SYSTEM_EVENT_FLAG_COM_IN );
						DebuggerPort_Read( HalSystemConfig.DebugTextPort, c, 1);
						Buffer[i] = c[0];
						i++;
					}
				}
				for (i=0; i<17; i++) hal_printf( "%c",Buffer[i] );
				hal_printf( "\r\n");

				for(i=0; i<macLen; i++) {
					Buff[i]=SH7619_EDMAC_AtoH(Buffer[i*3])*0x10;
					Buff[i]+=SH7619_EDMAC_AtoH(Buffer[i*3+1]);
				}

				for(i=0; i<macLen; i++) {
					g_NetworkConfig.NetworkInterfaces[NETWORK_INTERFACE_INDEX_SH7619EMAC].macAddressBuffer[i]=Buff[i];
				}


				debug_printf( "Updating...\r\n" );
				g_AM29DL_16_BS_DeviceTable.InitializeDevice(pBLOCK_CONFIG);
				g_AM29DL_16_BS_DeviceTable.EraseBlock(pBLOCK_CONFIG,MAC_address_area);
				g_AM29DL_16_BS_DeviceTable.Write(pBLOCK_CONFIG,MAC_address_area,macLen,Buff,0x0);
				debug_printf( "Done\r\n" );

				i=0x100;
			}
		}
		memcpy(&sc->mac_address[0], &g_NetworkConfig.NetworkInterfaces[NETWORK_INTERFACE_INDEX_SH7619EMAC].macAddressBuffer[0], macLen);
	}
	else
	{
		RTP_DEBUG_ERROR("Device initialize without MAC address!!!\r\n", NOVAR, 0, 0);
}
    
	/* Now put in a dummy ethernet address */
	rtp_memcpy(&pi->addr.my_hw_addr[0], sc->mac_address, 6); // Get the ethernet address
    
	/* clear statistic information */
	sc->stats.packets_in     = 0L;
	sc->stats.packets_out    = 0L;
	sc->stats.bytes_in       = 0L;
	sc->stats.bytes_out      = 0L;
	sc->stats.errors_in      = 0L;
	sc->stats.errors_out     = 0L;    

	if(RTP_FALSE == SH7619_EDMAC_SetupDevice())
	{
		return RTP_FALSE;
	}
    
	rtp_irq_hook_interrupt( (RTP_PFVOID) pi, 
							(RTP_IRQ_FN_POINTER)SH7619_EDMAC_recv, 
							(RTP_IRQ_FN_POINTER) 0);

	return(RTP_TRUE);
}
Example #24
0
void ApplicationEntryPoint()
{
    UINT32 ComEvent;

    g_State.Initialize();

    ComEvent = 0;
    if(COM_IsSerial(g_State.UsartPort) && (g_State.UsartPort != COM_NULL))
    {
        ComEvent = SYSTEM_EVENT_FLAG_COM_IN;
    }

#if !defined(TARGETLOCATION_RAM)
    g_State.WaitForActivity = (g_State.ProgramCount != 0); // is there a main app?

#else
    g_State.WaitForActivity = FALSE;      // forever
#endif

    {
        UINT32 ButtonsPressed;
        UINT32 ButtonsReleased;
        char   c;

        // clear any events present from startup
        while(Events_Get( SYSTEM_EVENT_FLAG_ALL ));

        // clear any junk from com port buffers
        while(DebuggerPort_Read( g_State.UsartPort, &c, sizeof(c) ));

        // clear any junk from button buffer
        while(Buttons_GetNextStateChange( ButtonsPressed, ButtonsReleased ));
    }

    {
        BOOL       ProcessingSREC     = FALSE;
        BOOL       ProcessingXREC     = FALSE;
        INT32      ProcessingZENFLASH = 0;
        INT32      Mode               = 0;
        INT32      MenuChoice         = 1;      // main application location when USB not enabled
        BOOL       MenuUpdate         = TRUE;
        UINT32     USBEvent           = 0;
        COM_HANDLE ReadPort           = COM_NULL;
        int        MenuOffset         = 1;      // no USB enabled
        INT64      WaitTimeout        = 0;

#if defined(PLATFORM_ARM_MOTE2)
        CPU_GPIO_SetPinState( LED1_GREEN, LED_ON );
#endif

        if(g_State.WaitForActivity)
        {
            WaitTimeout = HAL_Time_CurrentTime() + (INT64)g_State.WaitInterval * (10 * 1000);

            hal_printf( "Waiting %d.%03d second(s) for hex upload\r\n", g_State.WaitInterval / 1000, g_State.WaitInterval % 1000 );
        }
        else
        {
            hal_printf( "Waiting forever for hex upload\r\n" );
        }

        // checking the existence of Usb Driver, all the default values are set to no USB
        if( USB_DEVICE_STATE_NO_CONTROLLER != USB_GetStatus( ConvertCOM_UsbController(g_State.UsbPort) ) )
        {
            g_State.UsingUsb = TRUE;

            MenuChoice = 2;
            MenuOffset = 2;
        }


        while(true)
        {
            if(MenuUpdate)
            {
                MenuUpdate = FALSE;

                LCD_Clear();
                hal_fprintf( STREAM_LCD, "\f");

                switch(Mode)
                {
                case 0:
                    hal_fprintf( STREAM_LCD, "   Zen Boot\r\n\r\n" );

                    hal_fprintf( STREAM_LCD, "%c PortBooter\r\n", MenuChoice == 0 ? '*' : ' ' );

                    if(g_State.UsingUsb)
                    {
                        hal_fprintf( STREAM_LCD, "%c FlashUSB\r\n", MenuChoice == 1 ? '*' : ' ' );
                    }


                    for(int i = 0; i < g_State.ProgramCount; i++)
                    {
                        hal_fprintf( STREAM_LCD, "%c Prg:%08x\r\n", (i+MenuOffset) == MenuChoice ? '*' : ' ', g_State.Programs[i] );
                    }
                    break;

                case 1:
                    hal_printf( "PortBooter v%d.%d.%d.%d\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_REVISION);
                    hal_fprintf( STREAM_LCD, "Waiting forever for hex upload\r\n"         );
                    break;

                case 2:
                    hal_fprintf( STREAM_LCD, "FlashUSB\r\n"                       );
                    hal_fprintf( STREAM_LCD, "Waiting forever for hex upload\r\n" );
                    break;
                }
            }

            UINT32 Events = Events_WaitForEvents( ComEvent | SYSTEM_EVENT_FLAG_BUTTON | SYSTEM_EVENT_FLAG_USB_IN, 2000 );

            if(Events & SYSTEM_EVENT_FLAG_BUTTON)
            {
                UINT32 ButtonsPressed;
                UINT32 ButtonsReleased;

                Events_Clear( SYSTEM_EVENT_FLAG_BUTTON );

                while(Buttons_GetNextStateChange( ButtonsPressed, ButtonsReleased ));
                {
                    if(g_State.SerialPortActive == FALSE)
                    {
                        //printf("%02x %02x\r\n", ButtonsPressed, ButtonsReleased);

                        // up
                        if(ButtonsPressed & BUTTON_UP)
                        {
                            switch(Mode)
                            {
                            case 0:
                                MenuChoice = __max( MenuChoice-1, 0 );
                                break;
                            }

                            g_State.WaitForActivity = FALSE;
                            MenuUpdate              = TRUE;
                        }

                        // down
                        if(ButtonsPressed & BUTTON_DOWN)
                        {
                            switch(Mode)
                            {
                            case 0:
                                MenuChoice = __min( MenuChoice+1, g_State.ProgramCount + MenuOffset-1 );
                                break;
                            }

                            g_State.WaitForActivity = FALSE;
                            MenuUpdate              = TRUE;
                        }

                        // enter button
                        if(ButtonsPressed & BUTTON_ENTR)
                        {
                            switch(Mode)
                            {
                            case 0:
                                if(MenuChoice == 0)
                                {
                                    Mode = 1;

                                    //UsingUsb = FALSE;
                                }
                                else if(g_State.UsingUsb && MenuChoice == 1)
                                {
                                    Mode = 2;
                                    USB_Configure( ConvertCOM_UsbController(g_State.UsbPort), &UsbDefaultConfiguration );
                                    USB_Initialize( ConvertCOM_UsbController(g_State.UsbPort) );
                                    USB_OpenStream( ConvertCOM_UsbStream(g_State.UsbPort), USB_DEBUG_EP_WRITE, USB_DEBUG_EP_READ );
                                    //UsingUsb = TRUE;
                                }
                                else
                                {
                                    StartApplication( (void (*)())g_State.Programs[MenuChoice-MenuOffset] );
                                }
                                break;

                            case 1:
                                Mode = 0;
                                break;

                            case 2:
                                // USB_Uninitialize();
                                Mode = 0;
                                break;
                            }

                            g_State.WaitForActivity = FALSE;
                            MenuUpdate              = TRUE;
                        }

                        if(ButtonsReleased)
                        {
                            MenuUpdate = TRUE;
                        }
                    }
                }
            }

            if((Events & ComEvent) || (Events & SYSTEM_EVENT_FLAG_USB_IN))
            {
                char c;

                if(Events & ComEvent)
                {
                    Events_Clear( ComEvent );

                    ReadPort              = g_State.UsartPort;
                    g_State.pStreamOutput = ReadPort;
                }
                else
                {
                    USBEvent = USB_GetEvent( ConvertCOM_UsbController(g_State.UsbPort), USB_EVENT_ALL );
                    if( !(USBEvent & g_State.UsbEventCode) )
                        continue;

                    g_State.pStreamOutput = g_State.UsbPort;
                    ReadPort              = g_State.UsbPort;
                }

                while(DebuggerPort_Read( ReadPort, &c, sizeof(c) ))
                {
                    if(ProcessingSREC)
                    {
                        ProcessingSREC = g_SREC.Process( c );
                    }
                    else if(ProcessingXREC)
                    {
                        ProcessingXREC = g_XREC.Process( c );
                    }
                    else if(ProcessingZENFLASH)
                    {
                        const char Signature[] = "ZENFLASH\r";

                        //printf( "Got %d at %d\r\n", c, ProcessingZENFLASH );
                        if(Signature[ProcessingZENFLASH++] == c)
                        {
                            if(Signature[ProcessingZENFLASH] == 0)
                            {
                                SignalActivity();
                                ProcessingZENFLASH = 0;
                            }
                        }
                        else
                        {
                            ProcessingZENFLASH = 0;
                        }
                    }
                    else if('S' == c)
                    {
                        ProcessingSREC = TRUE;
                    }
                    else if('X' == c)
                    {
                        ProcessingXREC = TRUE;
                    }
                    else if('Z' == c)
                    {
                        ProcessingZENFLASH = 1;
                    }
                }
            }

            if(g_State.WaitForActivity && WaitTimeout < HAL_Time_CurrentTime())
            {
#if defined(PLATFORM_ARM_MOTE2)
                CPU_GPIO_SetPinState(LED1_GREEN, LED_OFF);        // Turn off Green LED for iMOTE2
#endif
                // we didn't see anything on serial port for wait interval (2 seconds nominally),
                // continue with code - just run the normal application
                StartApplication( (void (*)())g_State.Programs[0] );
            }

        }
    }
}
Example #25
0
    void Initialize()
    {
#if defined(PLATFORM_ARM_MOTE2)
        if (COM_IsUsb(HalSystemConfig.DebugTextPort))
            WaitInterval = 5000;        // The USB port must be selected and the Start button pressed all during this time
        else
            WaitInterval = 2000;        // The USART port may be selected before powering on the Imote2, so it takes less time
#else
        WaitInterval     = 2000;
#endif

        SerialPortActive = FALSE;

        UsartPort        = USART_DEFAULT_PORT;

        UsingUsb         = FALSE;
        UsbPort          = USB1;
        UsbEventCode     = USB_DEBUG_EVENT_IN;

        //--//

        // wait an extra second for buttons and COM port to stabilize
        Events_WaitForEvents( 0, 1000 );

        // COM init is now delayed for TinyBootloader, so we need to initialize it here
        CPU_InitializeCommunication();

        //--//

        // set default baud rate
        if(UsartPort != DEBUG_TEXT_PORT)
        {
            DebuggerPort_Initialize( UsartPort );
        }
        // extra time to allow USB setup, so that we can see the printf
        Events_WaitForEvents( 0, 1000 );


        hal_printf( "PortBooter v%d.%d.%d.%d\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_REVISION);
        hal_printf( "Build Date: %s %s\r\n",  __DATE__, __TIME__);

#if defined(__GNUC__)
        hal_printf( "GNU Compiler version %d\r\n", __GNUC__);
#elif defined(__ADSPBLACKFIN__)
        hal_printf( "Blackfin Compiler version %d\r\n", __VERSIONNUM__ );
#else
        hal_printf( "ARM Compiler version %d\r\n", __ARMCC_VERSION);
#endif
       
        //--//

        BlockStorageStream stream;
        FLASH_WORD ProgramWordCheck;

        if(!stream.Initialize(BlockUsage::CODE)) return;



        do
        {
            do
            {
            
                UINT32 addr = stream.CurrentAddress();
    			FLASH_WORD *pWord = &ProgramWordCheck;

                stream.Read( (BYTE**)&pWord, sizeof(FLASH_WORD) );

                if(*pWord == PROGRAM_WORD_CHECK)
                {
                    hal_printf("*** nXIP Program found at 0x%08x\r\n", addr );
    				Programs[ProgramCount++] = (UINT32)addr;
                }

                if(ProgramCount == MAX_PROGRAMS) break;
            }
            while( stream.Seek( BlockStorageStream::STREAM_SEEK_NEXT_BLOCK, BlockStorageStream::SeekCurrent ) );

        } while(stream.NextStream());

    }
Example #26
0
    BOOL Process( UINT8 c )
    {
        while(true)
        {
            switch(m_phase)
            {
                //
                // Setup 'address' reception.
                //
            case 0:
                m_ptr = (char*)&m_address;
                m_len = sizeof(m_address);
                m_phase++;
                break;
    
                //
                // Setup 'size' reception.
                //
            case 2:
                //printf( "Got address %08x\r\n", m_address );
    
                m_ptr = (char*)&m_size;
                m_len = sizeof(m_size);
                m_phase++;
                return TRUE;
    
                //
                // Setup 'crc' reception.
                //
            case 4:
                //printf( "Got size %08x\r\n", m_size );
    
                m_ptr = (char*)&m_crc;
                m_len = sizeof(m_crc);
                m_phase++;
                return TRUE;
    
                //
                // Setup 'data' reception or jump to entrypoint.
                //
            case 6:
                //printf( "Got crc %08x\r\n", m_crc );
    
                m_crc += m_address;
                m_crc += m_size;
    
                if(m_size == 0)
                {
                    if(m_crc != 0)
                    {
                        hal_fprintf( g_State.pStreamOutput, "X crc %08x %08x\r\n", m_address, m_crc );
    
                       // bad characters! realign
                        m_phase = 0;
                        return FALSE;
                    }
    
                    hal_fprintf( g_State.pStreamOutput, "X start %08x\r\n", m_address );

#if defined(PLATFORM_ARM_MOTE2)
                    CPU_GPIO_SetPinState(LED1_GREEN, LED_OFF);        // Turn off Green LED for iMote2
#endif                
    
                    StartApplication( (void (*)())m_address );
                }
    
                if(m_size > sizeof(m_data) || (m_size % sizeof(FLASH_WORD)) != 0)
                {
                    hal_fprintf( g_State.pStreamOutput, "X size %d\r\n", m_size );
    
                    // bad characters! realign
                    m_phase = 0;
                    return FALSE;
                }
    
                m_ptr = (char*)m_data;
                m_len =        m_size;
                m_phase++;
                return TRUE;
    
            case 8:
                {
                    FLASH_WORD* src     = (FLASH_WORD*)m_data;
                    FLASH_WORD* dst     = (FLASH_WORD*)m_address;
                    BOOL        success = TRUE;
                    int         i;
                    BlockStorageDevice * pDevice;
                    ByteAddress WriteByteAddress ;
    
                    for(i=0; i<m_size; i++)
                    {
                        m_crc += m_data[i];
                    }
    
                    if(m_crc != 0)
                    {
                        hal_fprintf( g_State.pStreamOutput, "X crc %08x %08x\r\n", m_address, m_crc );
    
                        // bad characters! realign
                        m_phase = 0;
                        return FALSE;
                    }
    
                    SignalActivity();

                    // this slows things down to print every address, only print once per line
                    hal_fprintf( STREAM_LCD, "WR: 0x%08x\r", (UINT32)dst );

                    // if it not Block Device, assume it is RAM 
                    if (BlockStorageList::FindDeviceForPhysicalAddress( & pDevice, m_address, WriteByteAddress))
                    {
                        UINT32 regionIndex, rangeIndex;
                        const BlockDeviceInfo* deviceInfo = pDevice->GetDeviceInfo() ;

                        if(!(pDevice->FindRegionFromAddress(WriteByteAddress, regionIndex, rangeIndex))) 
                        {
#if !defined(BUILD_RTM)
                           hal_printf(" Invalid condition - Fail to find the block number from the ByteAddress %x \r\n",WriteByteAddress);  
#endif
                            return FALSE;
                        }

                        // start from the block where the sector sits.
                        UINT32        iRegion = regionIndex;
                        UINT32        accessPhyAddress = (UINT32)m_address;
                                
                        BYTE*         bufPtr           = (BYTE*)src;
                        BOOL          success          = TRUE;
                        INT32         writeLenInBytes  = m_size;


                        while (writeLenInBytes > 0)
                        {
                            for(; iRegion < deviceInfo->NumRegions; iRegion++)
                            {
                                const BlockRegionInfo *pRegion = &(deviceInfo->Regions[iRegion]);

                                ByteAddress blkAddr = pRegion->Start;

                                while(blkAddr < accessPhyAddress)
                                {
                                    blkAddr += pRegion->BytesPerBlock;
                                }

                                //writeMaxLength =the current largest number of bytes can be read from the block from the address to its block boundary.
                                UINT32 NumOfBytes = __min(pRegion->BytesPerBlock, writeLenInBytes);
                                if (accessPhyAddress == blkAddr && !pDevice->IsBlockErased(blkAddr, pRegion->BytesPerBlock))
                                {
                                    hal_fprintf( STREAM_LCD, "ER: 0x%08x\r", blkAddr );

                                    pDevice->EraseBlock(blkAddr);
                                    blkAddr += pRegion->BytesPerBlock;
                                }
                                success = pDevice->Write(accessPhyAddress , NumOfBytes, (BYTE *)bufPtr, FALSE);

                                writeLenInBytes -= NumOfBytes;
								
                                if ((writeLenInBytes <=0) || (!success)) break;

                                bufPtr += NumOfBytes;

                            }

                            if ((writeLenInBytes <=0) || (!success)) break;
                        }
                        
                    }
                    else
                    {
                        // must be RAM but don't verify, we write anyway, possibly causing a data abort if the address is bogus
                        memcpy( dst, src, m_size );
                    }
    
                    hal_fprintf( g_State.pStreamOutput, "X %s %08x\r\n", success ? "ack" : "nack", m_address );
    
                    m_phase = 0;
                    return FALSE;
                }
                break;
    
                //
                // Read data.
                //
            case 1:
            case 3:
            case 5:
            case 7:
                *m_ptr++ = c; if(--m_len) return TRUE;
    
                m_phase++;
                break;
            }
        }
    }
Example #27
0
    BOOL ParseLine( const char* SRECLine )
    {
        UINT32               Address;
        int                  i;
        UINT32               BytesRemaining = 0;
        UINT32               Temp           = 0;
        UINT32               Data32;
        UINT32               RecordType;
        UINT32               CheckSum;
        UINT32               WordCount = 0;
        UINT32               ByteCount = 0;
        FLASH_WORD           WordData[16/sizeof(FLASH_WORD)];     // we support 16 bytes of data per record max, 4 words, 8 shorts
        UINT8                ByteData[16];                        // we support 16 bytes of data per record max, 4 words, 8 shorts

        BlockStorageDevice         *pDevice;
        UINT32               m_size;
        ByteAddress WriteByteAddress;


        RecordType = *SRECLine++;

        SRECLine = htoi( SRECLine, 2, BytesRemaining ); if(!SRECLine) return FALSE;

        // start the checksum with this byte
        CheckSum = BytesRemaining;

        // get the destination address
        // do bytes only to make checksum calc easier
        Data32 = 0;
        for(i = 0; i < 4; i++)
        {
            SRECLine = htoi( SRECLine, 2, Temp ); if(!SRECLine) return FALSE;

            CheckSum += Temp;

            Data32 <<= 8;
            Data32  |= Temp;

            BytesRemaining -= 1;
        }
        Address = Data32;

        // take off one byte for CRC;
        m_size = BytesRemaining -1;

        switch(RecordType)
        {
        case '3':
            {

                while(BytesRemaining > 1)
                {
                    // get bytes into words, and checksum
                    Data32 = 0;
                    for(i = 0; i < sizeof(FLASH_WORD); i++)
                    {
                        SRECLine = htoi( SRECLine, 2, Temp ); if(!SRECLine) return FALSE;

                        CheckSum += Temp;

                        Data32 |= Temp << (i*8);    // little endian format

                        ByteData[ByteCount++] = Temp;

                        BytesRemaining -= 1;

                        // leave the checksum in place
                        if(1 == BytesRemaining) break;
                    }

                    ASSERT(WordCount < (16/sizeof(FLASH_WORD)));

                    WordData[WordCount++] = Data32;
                }
            }
            break;

        case '7':
            // just a return address (starting location)
            m_StartAddress = (UINT32)Address;
            break;

        default:
            // we only support S3 and S7 records, for now
            return FALSE;
        }

        // get the checksum
        SRECLine = htoi( SRECLine, 2, Temp ); if(!SRECLine) return FALSE;

        CheckSum += Temp;

        BytesRemaining -= 1;

        ASSERT(0 == BytesRemaining);

        // make sure we had a NULL terminator for line, and not more characters
        if(*SRECLine != 0)
        {
            return FALSE;
        }

        if(0xff != (CheckSum & 0xff))
        {
            return FALSE;
        }
        else
        {
            // only write if we succeeded the checksum entirely for whole line

            if(m_size > 0)
            {
                SignalActivity();

                // this slows things down to print every address, only print once per line

                hal_fprintf( STREAM_LCD, "WR: 0x%08x\r", (UINT32)Address );

                if (BlockStorageList::FindDeviceForPhysicalAddress( &pDevice, Address, WriteByteAddress)) 
                {

                        UINT32 regionIndex, rangeIndex;
                        const BlockDeviceInfo* deviceInfo = pDevice->GetDeviceInfo() ;

                        if(!(pDevice->FindRegionFromAddress(WriteByteAddress, regionIndex, rangeIndex))) 
                        {
#if !defined(BUILD_RTM)
                            hal_printf(" Invalid condition - Fail to find the block number from the ByteAddress %x \r\n",WriteByteAddress);  
#endif
                            return FALSE;
                        }

                        // start from the block where the sector sits.
                        UINT32        iRegion = regionIndex;
                        UINT32        accessPhyAddress = (UINT32)Address;
                                
                        BYTE*         bufPtr           = (BYTE*)ByteData;
                        BOOL          success          = TRUE;
                        INT32         writeLenInBytes  = m_size;


                        while (writeLenInBytes > 0)
                        {
                            for(; iRegion < deviceInfo->NumRegions; iRegion++)
                            {
                                const BlockRegionInfo *pRegion = &(deviceInfo->Regions[iRegion]);

                                ByteAddress blkAddr = pRegion->Start;

                                while(blkAddr < accessPhyAddress)
                                {
                                    blkAddr += pRegion->BytesPerBlock;
                                }

                                //writeMaxLength =the current largest number of bytes can be read from the block from the address to its block boundary.
                                UINT32 NumOfBytes = __min(pRegion->BytesPerBlock, writeLenInBytes);
                                if (accessPhyAddress == blkAddr && !pDevice->IsBlockErased(blkAddr, pRegion->BytesPerBlock))
                                {
                                    hal_fprintf( STREAM_LCD, "ER: 0x%08x\r", blkAddr );
                                    pDevice->EraseBlock(blkAddr);
                                    blkAddr += pRegion->BytesPerBlock;
                                }
                                success = pDevice->Write(accessPhyAddress , NumOfBytes, (BYTE *)bufPtr, FALSE);

                                writeLenInBytes -= NumOfBytes;

                                if ((writeLenInBytes <=0) || (!success)) break;

                                bufPtr += NumOfBytes;

                            }

                            if ((writeLenInBytes <=0) || (!success)) break;
                        }
                        
                    }
                else
                {
                    FLASH_WORD *Addr = (FLASH_WORD *) Address;
                    for(i = 0; i < WordCount; i++)
                    {
                        // must be RAM but don't verify, we write anyway, possibly causing a data abort if the address is bogus
                         *Addr++ = WordData[i];
                    }
                }
            }
        }

        return TRUE;
    }
BOOL MC9328MXL_SPI_Driver::Xaction_nWrite16_nRead16( SPI_XACTION_16& Transaction )
{
    NATIVE_PROFILE_HAL_PROCESSOR_SPI();
    UINT16 Data16;

    if(!g_MC9328MXL_SPI_Driver.m_Enabled[ Transaction.SPI_mod ])
    {
        hal_printf("\fSPI Xaction OFF\r\n");
        lcd_printf("\fSPI Xaction OFF\r\n");
        ASSERT(FALSE);
        return FALSE;
    }

    SPI_DEBUG_PRINT("\fxwr16\r\n");
    MC9328MXL_SPI& SPI = MC9328MXL::SPI( Transaction.SPI_mod );

    UINT16* Write16         = Transaction.Write16;
    INT32   WriteCount      = Transaction.WriteCount;
    UINT16* Read16          = Transaction.Read16;
    INT32   ReadCount       = Transaction.ReadCount;
    INT32   ReadStartOffset = Transaction.ReadStartOffset;
    INT32   ReadTotal  = 0;

    // as master, we must always write something before reading or not
    if(WriteCount <= 0)                     {
        ASSERT(FALSE);
        return FALSE;
    }
    if(Write16 == NULL)                     {
        ASSERT(FALSE);
        return FALSE;
    }
    if((ReadCount > 0) && (Read16 == NULL)) {
        ASSERT(FALSE);
        return FALSE;
    }


    if(ReadCount)
    {
        ReadTotal = ReadCount + ReadStartOffset;    // we need to read as many bytes as the buffer is long, plus the offset at which we start
    }


    INT32 loopCnt= ReadTotal;

    // take the max of Read+offset or WrCnt
    if (loopCnt < WriteCount)
        loopCnt = WriteCount;


    // we will use WriteCount to move in the Write16 array
    // so we do no want to go past the end when we will check for
    // WriteCount to be bigger than zero
    WriteCount -= 1;

    while(loopCnt--)
    {
        SPI.TXDATAREG = Write16[0];
        SPI.CONTROLREG |= SPI.CONTROLREG_XCH;

        // wait while the transmit buffer is full and receive buffer is empty
        while(!SPI.TransmitBufferEmpty() || !SPI.ShiftBufferEmpty()|| SPI.ReceiveBufferEmpty());

        Data16 = SPI.RXDATAREG;

        // repeat last write word for all subsequent reads
        if(WriteCount)
        {
            WriteCount--;
            Write16++;
        }

        // only save data once we have reached ReadCount-1 portion of words
        ReadTotal--;
        if((ReadTotal>=0) && (ReadTotal < ReadCount))
        {

            Read16[0] = Data16;
            Read16++;
        }

    }

    return TRUE;
}
Example #29
0
void ApplicationEntryPoint()
{
    INT32 timeout       = 20000; // 20 second timeout
    bool  enterBootMode = false;

    // crypto API needs to allocate memory. Initialize simple heap for it. 
    UINT8* BaseAddress;                                 
    UINT32 SizeInBytes;                                 
                                                        
    HeapLocation         ( BaseAddress, SizeInBytes );  
    SimpleHeap_Initialize( BaseAddress, SizeInBytes );  

    g_eng.Initialize( HalSystemConfig.DebuggerPorts[ 0 ] );

    // internal reset and stop check
    enterBootMode = g_PrimaryConfigManager.IsBootLoaderRequired( timeout );

    // ODM defined method to enter bootloader mode
    if(!enterBootMode)
    {
        enterBootMode = WaitForTinyBooterUpload( timeout );
    }
    if(!enterBootMode)   
    {
        if(!g_eng.EnumerateAndLaunch())
        {
            timeout       = -1;
            enterBootMode = true;
        }
    }

    if(enterBootMode)
    {
        LCD_Clear();
        
        hal_fprintf( STREAM_LCD, "TinyBooter v%d.%d.%d.%d\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_REVISION);
        hal_fprintf( STREAM_LCD, "%s Build Date:\r\n\t%s %s\r\n", HalName, __DATE__, __TIME__ );

        DebuggerPort_Initialize( HalSystemConfig.DebuggerPorts[ 0 ] );

        TinyBooter_OnStateChange( State_EnterBooterMode, NULL );

        DebuggerPort_Flush( HalSystemConfig.DebugTextPort  );
        hal_printf( "TinyBooter v%d.%d.%d.%d\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_REVISION);
        hal_printf( "%s Build Date: %s %s\r\n", HalName, __DATE__, __TIME__ );
#if defined(__GNUC__)
        hal_printf("GNU Compiler version %d\r\n", __GNUC__);
#elif defined(_ARC)
        hal_printf("ARC Compiler version %d\r\n", _ARCVER);
#elif defined(__ADSPBLACKFIN__)
        hal_printf( "Blackfin Compiler version %d\r\n", __VERSIONNUM__ );
#elif defined(__RENESAS__)
        hal_printf( "Renesas Compiler version %d\r\n", __RENESAS_VERSION__ );
#else
        hal_printf( "ARM Compiler version %d\r\n", __ARMCC_VERSION );
#endif
        DebuggerPort_Flush( HalSystemConfig.DebugTextPort );

        //
        // Send "presence" ping.
        //
        {
            CLR_DBG_Commands::Monitor_Ping cmd;

            cmd.m_source = CLR_DBG_Commands::Monitor_Ping::c_Ping_Source_TinyBooter;

            g_eng.m_controller.SendProtocolMessage( CLR_DBG_Commands::c_Monitor_Ping, WP_Flags::c_NonCritical, sizeof(cmd), (UINT8*)&cmd );
        }
    
        UINT64 ticksStart = HAL_Time_CurrentTicks();

        //
        // Wait for somebody to press a button; if no button press comes in, lauch the image
        //
        do
        {
            const UINT32 c_EventsMask = SYSTEM_EVENT_FLAG_COM_IN |
                                        SYSTEM_EVENT_FLAG_USB_IN |
                                        SYSTEM_EVENT_FLAG_BUTTON;

            UINT32 events = ::Events_WaitForEvents( c_EventsMask, timeout );

            if(events != 0)
            {
                Events_Clear( events );
            }

            if(events & SYSTEM_EVENT_FLAG_BUTTON)
            {
                TinyBooter_OnStateChange( State_ButtonPress, (void*)&timeout );
            }
            
            if(events & (SYSTEM_EVENT_FLAG_COM_IN | SYSTEM_EVENT_FLAG_USB_IN))
            {
                g_eng.ProcessCommands();
            }

            if(LOADER_ENGINE_ISFLAGSET(&g_eng, Loader_Engine::c_LoaderEngineFlag_ValidConnection))
            {
                LOADER_ENGINE_CLEARFLAG(&g_eng, Loader_Engine::c_LoaderEngineFlag_ValidConnection);
                
                TinyBooter_OnStateChange( State_ValidCommunication, (void*)&timeout );

                ticksStart = HAL_Time_CurrentTicks();
            }
            else if((timeout != -1) && (HAL_Time_CurrentTicks()-ticksStart) > CPU_MillisecondsToTicks((UINT32)timeout))
            {
                TinyBooter_OnStateChange( State_Timeout, NULL );
                g_eng.EnumerateAndLaunch();
            }
        } while(true);
    }

    ::CPU_Reset();
}
Example #30
0
// if program needs to loaded from non-XIP to XIP area, use this routine
// and return the new address for the applicatoin.
void PortBooterLoadProgram(void ** StartAddress)
{
    hal_printf(" Prepare to launcah program %x \r\n", (UINT32)(*StartAddress));
    // if needed, reload data to the desired ram type storage.

}