void InitContinuations( struct netif *pNetIf )
{
    InterruptTaskContinuation.InitializeCallback( (HAL_CALLBACK_FPN)STM32F4_ETH_LWIP_recv, (void*)pNetIf );

    LwipUpTimeCompletion.InitializeForUserMode( (HAL_CALLBACK_FPN)lwip_network_uptime_completion, (void*)pNetIf );
    LwipUpTimeCompletion.EnqueueDelta64( 2000000 );
}
void HAL_COMPLETION::EnqueueTicks( UINT64 EventTimeTicks )
{
    NATIVE_PROFILE_PAL_ASYNC_PROC_CALL();
    ASSERT(EventTimeTicks != 0);

    GLOBAL_LOCK(irq);

    this->EventTimeTicks  = EventTimeTicks;
#if defined(_DEBUG)
    this->Start_RTC_Ticks = HAL_Time_CurrentTicks();
#endif

    HAL_COMPLETION* ptr     = (HAL_COMPLETION*)g_HAL_Completion_List.FirstNode();
    HAL_COMPLETION* ptrNext;

    for(;(ptrNext = (HAL_COMPLETION*)ptr->Next()); ptr = ptrNext)
    {
        if(EventTimeTicks < ptr->EventTimeTicks) break;
    }

    g_HAL_Completion_List.InsertBeforeNode( ptr, this );
    
    if(this == g_HAL_Completion_List.FirstNode())
    {
        HAL_Time_SetCompare( EventTimeTicks );
    }
}
Пример #3
0
void InitContinuations( struct netif *pNetIf )
{
    InterruptTaskContinuation.InitializeCallback( (HAL_CALLBACK_FPN)LPC24XX_EMAC_lwip_recv, pNetIf );

    LwipUpTimeCompletion.InitializeForUserMode( (HAL_CALLBACK_FPN)lwip_network_uptime_completion, pNetIf );
    LwipUpTimeCompletion.EnqueueDelta64( 2000000 );
}
void InitContinuations( struct netif* pNetIf )
{
    InterruptTaskContinuation.InitializeCallback( (HAL_CALLBACK_FPN)enc28j60_lwip_interrupt, &g_ENC28J60_NetIF );

    LwipUpTimeCompletion.InitializeForUserMode( (HAL_CALLBACK_FPN)lwip_network_uptime_completion, pNetIf );
    
    LwipUpTimeCompletion.EnqueueDelta64( 500000 );
}
Пример #5
0
/*----------------------------------------------------------------------*
                            rtp_thread_spawn
 *----------------------------------------------------------------------*/
int rtp_thread_spawn (RTP_HANDLE         * newThread,
                      RTP_ENTRY_POINT_FN   entryPoint,
                      const char         * name,
                      int                  stackSizeIndex,
                      int                  priorityIndex,
                      void               * userData)
{
    PIFACE pi;
    int * index = (int *) userData;
    
    if ((rtp_strcmp(name, "ip interpret") == 0) && !IPTaskInitialized[*index])
    {
        IPTaskInitialized[*index] = 1;

        IPTaskContinuation[*index].InitializeCallback((HAL_CALLBACK_FPN) entryPoint, userData);
    }
    
    else if ((rtp_strcmp(name, "timer comp") == 0) && !TimerTaskCompInitialized)
    {
        TimerTaskCompInitialized = 1;
        
        TimerTaskCompletion.InitializeForUserMode((HAL_CALLBACK_FPN) entryPoint, userData);
            
        TimerTaskCompletion.EnqueueDelta(cfg_protocol_data.timer_freq * 1000);
    }       
    
    else if ((rtp_strcmp(name, "timer cont") == 0) && !TimerTaskContInitialized)
    {      
        TimerTaskContInitialized = 1;

        TimerTaskContinuation.InitializeCallback((HAL_CALLBACK_FPN) entryPoint,userData);    
    } 
    
    else if ((rtp_strcmp(name, "interrupt task") == 0) && !InterruptTaskContInitialized[*index])
    {
        pi = (PIFACE) &ifaces[*index];
        if (!pi)
        {
            return -1;
        }

        InterruptTaskContInitialized[*index] = 1;
        
        InterruptTaskContinuation[*index].InitializeCallback((HAL_CALLBACK_FPN) entryPoint,pi);
    }
    
    else if ((rtp_strcmp(name, "dhcp") == 0) && !DHCPTaskInitialized)
    {
        DHCPTaskInitialized = 1;
        
        DHCPTaskContinuation.InitializeCallback((HAL_CALLBACK_FPN) entryPoint,userData);
    }
    
    return (0);    
}
Пример #6
0
void Events_SetBoolTimer( BOOL* TimerCompleteFlag, UINT32 MillisecondsFromNow )
{
    NATIVE_PROFILE_PAL_EVENTS();
    // we assume only 1 can be active, abort previous just in case
    g_Events_BoolTimerCompletion.Abort();

    if(TimerCompleteFlag)
    {
        g_Events_BoolTimerCompletion.InitializeForISR( local_Events_SetBoolTimer_Callback, TimerCompleteFlag );

        g_Events_BoolTimerCompletion.EnqueueDelta( MillisecondsFromNow * 1000 );
    }
}
BOOL ENC28J60_LWIP_Driver::Close( ENC28J60_LWIP_DRIVER_CONFIG* config, int index )
{
    NATIVE_PROFILE_HAL_DRIVERS_ETHERNET();

    if(config == NULL) return FALSE;

    LwipUpTimeCompletion.Abort();

    netif_set_link_down( &g_ENC28J60_NetIF );
    netif_set_down( &g_ENC28J60_NetIF );
    netif_remove( &g_ENC28J60_NetIF );

    /* Disable the INTERRUPT pin */                            
    CPU_GPIO_EnableInputPin2(config->INT_Pin, 
                              FALSE,                         /* Glitch filter enable */
                              NULL,                          /* ISR                  */
                              0,                             /* minor number         */
                              GPIO_INT_NONE,                 /* Interrupt edge       */
                              RESISTOR_PULLUP);              /* Resistor State       */

    InterruptTaskContinuation.Abort();

    LwipNetworkStatus = FALSE;
    
    enc28j60_lwip_close( &g_ENC28J60_NetIF );

    memset(&g_ENC28J60_NetIF, 0, sizeof(g_ENC28J60_NetIF));

    return TRUE;

}
Пример #8
0
void lwip_network_uptime_completion(void *arg)
{
    NATIVE_PROFILE_PAL_NETWORK();

    BOOL status = ENET_PHY_lwip_get_link_status( );

    if(status != LwipNetworkStatus)
    {
        struct netif* pNetIf = (struct netif*)arg;

        if(status)
        {
            SOCK_NetworkConfiguration *pNetCfg = &g_NetworkConfig.NetworkInterfaces[0];

            ENET_PHY_lwip_set_link_speed( );
            netif_set_up( pNetIf );

            if(pNetCfg->flags & SOCK_NETWORKCONFIGURATION_FLAGS_DHCP)
            {
                dhcp_start( pNetIf );
            }
            Network_PostEvent( NETWORK_EVENT_TYPE__AVAILABILITY_CHANGED, NETWORK_EVENT_FLAGS_IS_AVAILABLE );
        }
        else
        {
            netif_set_down( (struct netif*)arg );
            Network_PostEvent( NETWORK_EVENT_TYPE__AVAILABILITY_CHANGED, 0);
        }

        LwipNetworkStatus = status;
    }

    LwipUpTimeCompletion.EnqueueDelta64( 2000000 );
}
void lwip_network_uptime_completion(void *arg)
{
    NATIVE_PROFILE_PAL_NETWORK();

    struct netif* pNetIf = (struct netif*)arg;

    BOOL status = enc28j60_get_link_status(&g_ENC28J60_LWIP_Config.DeviceConfigs[0].SPI_Config);

    if(status != LwipNetworkStatus)
    {        
        if(status)
        {
            tcpip_callback((sys_timeout_handler)netif_set_link_up, (void*)pNetIf);
            tcpip_callback((sys_timeout_handler)netif_set_up, (void*)pNetIf);

            Network_PostEvent( NETWORK_EVENT_TYPE__AVAILABILITY_CHANGED, NETWORK_EVENT_FLAGS_IS_AVAILABLE );
        }
        else
        {
            tcpip_callback((sys_timeout_handler)netif_set_link_down, (void*)pNetIf);
            tcpip_callback((sys_timeout_handler)netif_set_down, (void*)pNetIf);

            Network_PostEvent( NETWORK_EVENT_TYPE__AVAILABILITY_CHANGED, 0);
        }

        Events_Set(SYSTEM_EVENT_FLAG_SOCKET);
        Events_Set(SYSTEM_EVENT_FLAG_NETWORK);

        LwipNetworkStatus = status;
    }

    LwipUpTimeCompletion.EnqueueDelta64( 2000000 );
}
Пример #10
0
BOOL Events_Initialize()
{
    NATIVE_PROFILE_PAL_EVENTS();
    g_Events_BoolTimerCompletion.Initialize();

    SystemEvents        = 0;

    return TRUE;
}
void HAL_COMPLETION::DequeueAndExec()
{
    NATIVE_PROFILE_PAL_ASYNC_PROC_CALL();
    GLOBAL_LOCK(irq);

    HAL_COMPLETION* ptr     = (HAL_COMPLETION*)g_HAL_Completion_List.FirstNode();
    HAL_COMPLETION* ptrNext = (HAL_COMPLETION*)ptr->Next();

    // waitforevents does not have an associated completion, therefore we need to verify
    // than their is a next completion and that the current one has expired.
    if(ptrNext)
    {
        ASSERT(ptr->EventTimeTicks <= HAL_Time_CurrentTicks());
        
        Events_Set(SYSTEM_EVENT_FLAG_SYSTEM_TIMER);

        ptr->Unlink();

        //
        // In case there's no other request to serve, set the next interrupt to be 356 years since last powerup (@25kHz).
        //
        HAL_Time_SetCompare( ptrNext->Next() ? ptrNext->EventTimeTicks : HAL_Completion_IdleValue );

#if defined(_DEBUG)
        ptr->EventTimeTicks = 0;
#endif  // defined(_DEBUG)

        // let the ISR turn on interrupts, if it needs to
        ptr->Execute();
    }
}
void LargeBuffer_ManagedToNative( UINT16 marshalId, const BYTE* pData, size_t size )
{
    if(!g_LargeBufferCompletionInit)
    {
        g_LargeBufferTestCompletion.InitializeForUserMode(LargeBufferTest_Completion, (void*)marshalId);
        g_LargeBufferCompletionInit = TRUE;
    }

    if(!g_LargeBufferTestCompletion.IsLinked()) 
    {
        g_LargeBufferTestCompletion.EnqueueDelta(1000);
    }

    int len = (size > ARRAYSIZE(s_Data)) ? ARRAYSIZE(s_Data) : size;
    
    for(int i=0; i<len; i++)
    {
        s_Data[i] = pData[size - 1 - i];
    }

    s_LastSize = len;
}
Пример #13
0
BOOL TEvents::TEvents_1()
{
   UINT32         count = 100;
   UINT32         signaled;
   HAL_COMPLETION compObj;


   compObj.InitializeForISR(CompletionCallback, NULL);

    while (count--)
    {
        compObj.EnqueueDelta(1000*2);
        signaled = Events_WaitForEvents(s_event,50);

        if (signaled != s_event)
        {
            return false; 
        }
    }


    return true; 
}
void HAL_COMPLETION::WaitForInterrupts( UINT64 Expire, UINT32 sleepLevel, UINT64 wakeEvents )
{
    NATIVE_PROFILE_PAL_ASYNC_PROC_CALL();
    const int c_SetCompare   = 1;
    const int c_ResetCompare = 2;
    const int c_NilCompare   = 4;

    ASSERT_IRQ_MUST_BE_OFF();

    HAL_COMPLETION* ptr = (HAL_COMPLETION*)g_HAL_Completion_List.FirstNode();
    int             state;

    if(ptr->Next() == NULL)
    {
        state = c_SetCompare | c_NilCompare;
    }
    else if(ptr->EventTimeTicks > Expire)
    {
        state = c_SetCompare | c_ResetCompare;
    }
    else
    {
        state = 0;
    }

    if(state & c_SetCompare) HAL_Time_SetCompare( Expire );

    CPU_Sleep( (SLEEP_LEVEL)sleepLevel, wakeEvents );

    if(state & (c_ResetCompare | c_NilCompare))
    {   
        // let's get the first node again
        // it could have changed since CPU_Sleep re-enabled interrupts
        ptr = (HAL_COMPLETION*)g_HAL_Completion_List.FirstNode();
        HAL_Time_SetCompare( (state & c_ResetCompare) ? ptr->EventTimeTicks : HAL_Completion_IdleValue );
    }
}
Пример #15
0
/*----------------------------------------------------------------------*
                            rtp_thrd_timer_completion
 *----------------------------------------------------------------------*/
void rtp_thrd_timer_completion(void* arg)
{
    NATIVE_PROFILE_PAL_NETWORK();
    /* Schedule the timer task to run as a continuation */
    if(!TimerTaskContinuation.IsLinked())
    {
        TimerTaskContinuation.Enqueue();
    }
    /////////////////////////////////////////////////////////////////
    // DO NT CHANGE!
    // KEEP the timeout IN SYNC with _CFG_TIMER_FREQ
    TimerTaskCompletion.EnqueueDelta(cfg_protocol_data.timer_freq * 1000);    
    // DO NT CHANGE!
    /////////////////////////////////////////////////////////////////
}
Пример #16
0
/*----------------------------------------------------------------------*
                            rtp_thread_kill
 *----------------------------------------------------------------------*/
int rtp_thread_kill (RTP_HANDLE         * newThread,
                      RTP_ENTRY_POINT_FN   entryPoint,
                      const char         * name,
                      int                  stackSizeIndex,
                      int                  priorityIndex,
                      void               * userData)
{
    int * index = (int *) userData;
    
    if ((rtp_strcmp(name, "ip interpret") == 0) && IPTaskInitialized[*index])
    {
        IPTaskInitialized[*index] = 0;

        IPTaskContinuation[*index].Abort();
    }
    
    else if ((rtp_strcmp(name, "timer comp") == 0) && TimerTaskCompInitialized)
    {
        TimerTaskCompInitialized = 0;
        
        TimerTaskCompletion.Abort();
    }       
    
    else if ((rtp_strcmp(name, "timer cont") == 0) && TimerTaskContInitialized)
    {      
        TimerTaskContInitialized = 0;

        TimerTaskContinuation.Abort();
    } 
    
    else if ((rtp_strcmp(name, "interrupt task") == 0) && InterruptTaskContInitialized[*index])
    {
        InterruptTaskContInitialized[*index] = 0;
        
        InterruptTaskContinuation[*index].Abort();
    }
    
    else if ((rtp_strcmp(name, "dhcp") == 0) && DHCPTaskInitialized)
    {
        DHCPTaskInitialized = 0;
        
        DHCPTaskContinuation.Abort();
    }
    
    return (0);    
}
Пример #17
0
/* ********************************************************************
   open the loop back driver interface.
   
   This routine opens a loop back device driver
  
   The address of this function must be placed into the "devices" table in
   iface.c either at compile time or before a device open is called.

   ********************************************************************     */  
bool loop_lwip_open( struct netif *pNetIF )                            
{
    NATIVE_PROFILE_HAL_DRIVERS_ETHERNET();
    
    /* Now put in a dummy ethernet address get the ethernet address */
   
    memcpy( pNetIF->hwaddr, phony_addr, ETHARP_HWADDR_LEN ); 
    
#if defined(FAKE_ASYNC_LOOPBACK_PROCESSING)
    memset(&g_dummy_pbuf_chain,0,PBUF_CHAIN_DEPTH*sizeof(pbuf*));

    g_fake_loopback_ISR.InitializeForISR( loop_lwip_send_packet, pNetIF );
#endif

    /* JJM Possibly initialize Continuation here. loop_lwip_interrupt_continuation */

    return( TRUE );
}
Пример #18
0
BOOL AT91_EMAC_LWIP_Driver::Close(void)
{
    LwipUpTimeCompletion.Abort();

    CPU_INTC_DeactivateInterrupt(AT91C_ID_EMAC);

    InterruptTaskContinuation.Abort();

    LwipNetworkStatus = 0;

    netif_set_down( &g_AT91_EMAC_NetIF );
    netif_remove( &g_AT91_EMAC_NetIF );

    AT91_EMAC_LWIP_close( &g_AT91_EMAC_NetIF );
    
    memset( &g_AT91_EMAC_NetIF, 0, sizeof g_AT91_EMAC_NetIF );

    return TRUE;
}
Пример #19
0
BOOL LPC24XX_EMAC_LWIP_Driver::Close( )
{
    LwipUpTimeCompletion.Abort();

    /* Disable the interrupt */
    CPU_INTC_DeactivateInterrupt(LPC24XX_VIC::c_IRQ_INDEX_EMAC);

    InterruptTaskContinuation.Abort();

    LwipNetworkStatus = 0;

    netif_set_down( &g_LPC24XX_EMAC_NetIF );
    netif_remove( &g_LPC24XX_EMAC_NetIF );

    LPC24XX_EMAC_lwip_close( &g_LPC24XX_EMAC_NetIF );
    
    memset( &g_LPC24XX_EMAC_NetIF, 0, sizeof g_LPC24XX_EMAC_NetIF);

    return TRUE;
}
BOOL SH7264_SMSC_LWIP_Driver::Close(void)
{
    LwipUpTimeCompletion.Abort();

    //CPU_INTC_DeactivateInterrupt(SH7264C_ID_EDMAC);
    CPU_INTC_DeactivateInterrupt(81);

    InterruptTaskContinuation.Abort();

    LwipNetworkStatus = 0;

    netif_set_down( &g_SH7264_SMSC_NetIF );
    netif_remove( &g_SH7264_SMSC_NetIF );

    SH7264_SMSC_lwip_close( &g_SH7264_SMSC_NetIF );
    
    memset( &g_SH7264_SMSC_NetIF, 0, sizeof g_SH7264_SMSC_NetIF);

    return TRUE;
}
Пример #21
0
/* ********************************************************************
   Transmit. a packet over the packet driver interface.
   
   This routine is called when a packet needs sending. The packet contains a
   full ethernet frame to be transmitted. The length of the packet is 
   provided.
  
   Returns 0 if successful or errno if unsuccessful
  
   ********************************************************************     */
err_t loop_lwip_xmit( struct netif *pNetIF, struct pbuf *pPBuf)
{
    NATIVE_PROFILE_HAL_DRIVERS_ETHERNET();

#if defined(FAKE_ASYNC_LOOPBACK_PROCESSING)
    // store the packet and process it asynchronously by calling SOCKETS_RestartTcpIpProcessor()
    // this would also require fakign an interrupt to 'receive' the packet
    
    g_dummy_pbuf_chain[g_dummy_pbuf_current] = pPBuf;
    if(++g_dummy_pbuf_current == PBUF_CHAIN_DEPTH) g_dummy_pbuf_current = 0;

    g_fake_loopback_ISR.EnqueueDelta(10 * 1000);

    SOCKETS_RestartTcpIpProcessor(10 * 1000);
    
#else
    pNetIF->input( pPBuf, pNetIF );
#endif

    return( ERR_OK );    
}
Пример #22
0
void lwip_network_uptime_completion(void *arg)
{
    NATIVE_PROFILE_PAL_NETWORK();

    BOOL status = dm9161_lwip_GetLinkStatus( ) != 0;

    if(!status)
    {
        status = dm9161_lwip_GetLinkStatus( ) != 0;
    }

    if(status != LWIP_STATUS_isset(LWIP_STATUS_LinkUp) )
    {
        struct netif* pNetIf = (struct netif*)arg;

        if(status)
        {
            tcpip_timeout(1000, (sys_timeout_handler)netif_set_link_up, (void*)pNetIf);
            tcpip_timeout(1000, (sys_timeout_handler)netif_set_up, (void*)pNetIf);

            Network_PostEvent( NETWORK_EVENT_TYPE__AVAILABILITY_CHANGED, NETWORK_EVENT_FLAGS_IS_AVAILABLE );
        }
        else
        {
            tcpip_callback((sys_timeout_handler)netif_set_link_down, (void*)pNetIf);
            tcpip_callback((sys_timeout_handler)netif_set_down, (void*)pNetIf);

            Network_PostEvent( NETWORK_EVENT_TYPE__AVAILABILITY_CHANGED, 0);
        }

        Events_Set(SYSTEM_EVENT_FLAG_SOCKET);
        Events_Set(SYSTEM_EVENT_FLAG_NETWORK);

        LWIP_STATUS_setorclear( LWIP_STATUS_LinkUp, status );
    }

    LwipUpTimeCompletion.EnqueueDelta64( 2000000 );
}
Пример #23
0
BOOL Events_Uninitialize()
{
    NATIVE_PROFILE_PAL_EVENTS();
    g_Events_BoolTimerCompletion.Abort();
    return TRUE;
}
void lwip_network_uptime_completion(void *arg)
{
    NATIVE_PROFILE_PAL_NETWORK();
    static BOOL isPhyPoweringUp = FALSE;
    static int nAttempts = 0;
    BOOL status;
    
    /* Power up PHY and wait while it starts */
    if (!LwipNetworkStatus && !isPhyPoweringUp)
    {
        eth_powerUpPhy(TRUE);
        isPhyPoweringUp = TRUE;
        LwipUpTimeCompletion.EnqueueDelta64( 2500000 );
        nAttempts++;
        return;
    }
    
    /* PHY should now have started, get the network status */
    isPhyPoweringUp = FALSE;
    status = eth_isPhyLinkValid(FALSE);

    /* Check whether network status has changed */
    if (status != LwipNetworkStatus)
    {
        struct netif* pNetIf = (struct netif*)arg;

        /* Check status */
        if (status)
        {   
            /* Network is up, open ethernet driver */
            SOCK_NetworkConfiguration *pNetCfg = &g_NetworkConfig.NetworkInterfaces[0];
            STM32F4_ETH_LWIP_open(pNetIf);
            netif_set_up( pNetIf );
            
            if(pNetCfg->flags & SOCK_NETWORKCONFIGURATION_FLAGS_DHCP)
            {
              dhcp_start( pNetIf );
            }
            
            nAttempts = 0;
            
            Network_PostEvent( NETWORK_EVENT_TYPE__AVAILABILITY_CHANGED, NETWORK_EVENT_FLAGS_IS_AVAILABLE );
        }
        else
        {
            /* Network is down, close ethernet driver */
            STM32F4_ETH_LWIP_close(FALSE);
            netif_set_down( (struct netif*)arg );
            Network_PostEvent( NETWORK_EVENT_TYPE__AVAILABILITY_CHANGED, 0);
        }
    
        /* Save new network status */
        LwipNetworkStatus = status;
    }

    /* Power down PHY if network is down */
    if (!LwipNetworkStatus)
    {
        eth_powerUpPhy(FALSE);
    }    
    
    /* Schedule the next network status check */
    if (LwipNetworkStatus || (nAttempts < 12) )
    {
        /* When network is up or has been up, check every 5 seconds */
        LwipUpTimeCompletion.EnqueueDelta64(  2500000 );
    }
    else
    {
        /* When network is down, check only once every minute */
        LwipUpTimeCompletion.EnqueueDelta64( 57500000 );
    }   
}
void DeInitContinuations()
{
    LwipUpTimeCompletion.Abort();
    InterruptTaskContinuation.Abort();
}