// --------------------------------------------------------------------------- void USART_IRQHandler(int ComPortNum, int Direction) { LPC_USART_T *usart = USART_REG(ComPortNum); char c; switch (Direction) { case 1: // Transmit if (USART_RemoveCharFromTxBuffer(ComPortNum, c)) { usart->THR = c; // Write data } else { CPU_USART_TxBufferEmptyInterruptEnable(ComPortNum, FALSE); // Disable interrupt } Events_Set(SYSTEM_EVENT_FLAG_COM_OUT); break; case 2: // Receive c = (char)(usart->RBR); // Read data USART_AddCharToRxBuffer(ComPortNum, c); Events_Set(SYSTEM_EVENT_FLAG_COM_IN); break; default: break; } }
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 ); }
void LPC22XX_USART_Driver::UART_IntHandler (void *param) { GLOBAL_LOCK(irq); ASSERT(LPC22XX_USART_Driver::IsValidPortNum((UINT32)param)); char c; UINT32 ComNum = (UINT32)param; UINT32 i,rxcnt; LPC22XX_USART& USARTC = LPC22XX::UART(ComNum); volatile UINT32 IIR_Value; volatile UINT32 LSR_Value; // Read data from Rx FIFO LSR_Value = USARTC.UART_LSR; while (LSR_Value & LPC22XX_USART::UART_LSR_RFDR) { UINT8 rxdata = (UINT8 )USARTC.SEL1.RBR.UART_RBR; rxcnt++; if ( 0 == (LSR_Value & ( LPC22XX_USART::UART_LSR_PEI | LPC22XX_USART::UART_LSR_OEI | LPC22XX_USART::UART_LSR_FEI ) ) ) { // No errors in Rx data USART_AddCharToRxBuffer(ComNum, rxdata); Events_Set( SYSTEM_EVENT_FLAG_COM_IN ); } LSR_Value = USARTC.UART_LSR; } // Send up to 2 bytes of Tx data for (i = 0; i <2; i++) { if (USART_RemoveCharFromTxBuffer( ComNum, c )) { WriteCharToTxBuffer( ComNum, c ); Events_Set( SYSTEM_EVENT_FLAG_COM_OUT ); } else { // Disable further TxBufferEmptyInterrupt. It will be // enabled by the PAL uart driver when a character to the // TxBuffer is added TxBufferEmptyInterruptEnable( ComNum, FALSE ); break; } } // Check if IIR read is required to clear the uart Rx interrupt IIR_Value = USARTC.SEL3.IIR.UART_IIR; }
void PXA271_USART_Driver::USART_ISR( void* param ) { // we lock since we are low priority and anyone might try to add a char in another ISR GLOBAL_LOCK(irq); UINT32 comPort = (UINT32)param; PXA271_USART& USART = PXA271::USART( comPort ); switch( USART.IIR & PXA271_USART::IIR__IID_MASK ) { case PXA271_USART::IIR__IID_RECEIVE_DATA: // If data in input FIFO // if the charger came in and turned off the serial port, bail now, as the source // will be going away if(c_RefFlagRx & g_PXA271_USART_Driver.m_RefFlags[comPort]) { if(USART.LSR & PXA271_USART::LSR__DR) { USART_AddCharToRxBuffer( comPort, (char)(USART.RBR & PXA271_USART::RBR__DATA_MASK8) ); Events_Set( SYSTEM_EVENT_FLAG_COM_IN ); } } break; case PXA271_USART::IIR__IID_TRANSMIT_FIFO: // If transmit FIFO can accept more characters // if the charger came in and turned off the serial port, bail now, as the source // will be going away if(c_RefFlagTx & g_PXA271_USART_Driver.m_RefFlags[comPort]) { char c; if(USART_RemoveCharFromTxBuffer( comPort, c )) { WriteCharToTxBuffer( comPort, c ); } else { // disable further Tx interrupts since we are level triggered TxBufferEmptyInterruptEnable( comPort, FALSE ); } Events_Set( SYSTEM_EVENT_FLAG_COM_OUT ); } break; #if defined(_DEBUG) case PXA271_USART::IIR__IID_RECEIVE_ERROR: // If there was an error receiving a character if(0 != (c_RefFlagRx & g_PXA271_USART_Driver.m_RefFlags[comPort])) { lcd_printf("\fLSR=%02x\r\n", USART.LSR & PXA271_USART::LSR__ERRORS); } break; #endif } }
void LWIP_SOCKETS_Driver::Link_callback(struct netif *netif) { if (netif_is_link_up(netif)) { if (!PostAvailabilityOnContinuation.IsLinked()) PostAvailabilityOnContinuation.Enqueue(); } else { if (!PostAvailabilityOffContinuation.IsLinked()) PostAvailabilityOffContinuation.Enqueue(); } Events_Set(SYSTEM_EVENT_FLAG_SOCKET); Events_Set(SYSTEM_EVENT_FLAG_NETWORK); }
void SH7619_EDMAC_interrupt(void *param) { long eesr0_val; GLOBAL_LOCK(encIrq); Events_Set( SYSTEM_EVENT_FLAG_SOCKET ); eesr0_val = EESR0; if((eesr0_val & 0x00010000) == 0x00010000) { Flush_All(iface); return; } // a Frame is transmitted if((eesr0_val & 0x00200000) == 0x00200000) { //signal IP task that xmit has completed rtp_net_invoke_output(iface, 1); } // Frame(s) received if((eesr0_val & 0x00040000) == 0x00040000) { rtp_thrd_interrupt_continuation(iface->ctrl.index); } ECSR0 = 0x00000007; EESR0 = 0x47FF0F9F; }
void HAL_SOCK_EventsSet( UINT32 events ) { NATIVE_PROFILE_PAL_NETWORK(); ASSERT( (events == SOCKET_EVENT_FLAG_SOCKET) || (events == SOCKET_EVENT_FLAG_SOCKETS_READY)); Events_Set( SYSTEM_EVENT_FLAG_SOCKET ); }
void LPC22XX_USART_Driver::TxBufferEmptyInterruptEnable( int ComPortNum, BOOL Enable ) { GLOBAL_LOCK(irq); LPC22XX_USART& USARTC = LPC22XX::UART(ComPortNum); ASSERT(LPC22XX_USART_Driver::IsValidPortNum(ComPortNum)); if (Enable) { USARTC.SEL2.IER.UART_IER |= (LPC22XX_USART::UART_IER_THREIE); char c; for (int i=0; i<2; i++) { if (USART_RemoveCharFromTxBuffer( ComPortNum, c )) { WriteCharToTxBuffer( ComPortNum, c ); Events_Set( SYSTEM_EVENT_FLAG_COM_OUT ); } else break; } } else { USARTC.SEL2.IER.UART_IER &= ~(LPC22XX_USART::UART_IER_THREIE); } }
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 LWIP_SOCKETS_Driver::Status_callback(struct netif *netif) { if (!PostAddressChangedContinuation.IsLinked()) PostAddressChangedContinuation.Enqueue(); #if !defined(BUILD_RTM) lcd_printf("\f\n\n\n\n\n\nLink Update: %s\n", (netif_is_up(netif) ? "UP " : "DOWN")); lcd_printf(" IP: %d.%d.%d.%d\n", (netif->ip_addr.addr >> 0) & 0xFF, (netif->ip_addr.addr >> 8) & 0xFF, (netif->ip_addr.addr >> 16) & 0xFF, (netif->ip_addr.addr >> 24) & 0xFF); lcd_printf(" SM: %d.%d.%d.%d\n", (netif->netmask.addr >> 0) & 0xFF, (netif->netmask.addr >> 8) & 0xFF, (netif->netmask.addr >> 16) & 0xFF, (netif->netmask.addr >> 24) & 0xFF); lcd_printf(" GW: %d.%d.%d.%d\n", (netif->gw.addr >> 0) & 0xFF, (netif->gw.addr >> 8) & 0xFF, (netif->gw.addr >> 16) & 0xFF, (netif->gw.addr >> 24) & 0xFF); debug_printf("IP Address: %d.%d.%d.%d\n", (netif->ip_addr.addr >> 0) & 0xFF, (netif->ip_addr.addr >> 8) & 0xFF, (netif->ip_addr.addr >> 16) & 0xFF, (netif->ip_addr.addr >> 24) & 0xFF); #if LWIP_DNS if (netif->flags & NETIF_FLAG_DHCP) { struct ip_addr dns1 = dns_getserver(0); struct ip_addr dns2 = dns_getserver(1); lcd_printf(" dns1: %d.%d.%d.%d\n", (dns1.addr >> 0) & 0xFF, (dns1.addr >> 8) & 0xFF, (dns1.addr >> 16) & 0xFF, (dns1.addr >> 24) & 0xFF); lcd_printf(" dns2: %d.%d.%d.%d\n", (dns2.addr >> 0) & 0xFF, (dns2.addr >> 8) & 0xFF, (dns2.addr >> 16) & 0xFF, (dns2.addr >> 24) & 0xFF); } #endif #endif Events_Set(SYSTEM_EVENT_FLAG_SOCKET); Events_Set(SYSTEM_EVENT_FLAG_NETWORK); }
void STM32F4_USART_Handle_RX_IRQ (int ComPortNum, USART_TypeDef* uart) { INTERRUPT_START; char c = (char)(uart->DR); // read RX data USART_AddCharToRxBuffer(ComPortNum, c); Events_Set(SYSTEM_EVENT_FLAG_COM_IN); INTERRUPT_END; }
void sys_sem_signal(sys_sem_t sem) { volatile UINT32* semaphore = (volatile UINT32*)sem; ReleaseSemaphore(semaphore); if(IsSemaphoreGreen(semaphore)) { Events_Set(SYSTEM_EVENT_FLAG_NETWORK); } }
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 ); }
void STM32F4_USART_Handle_TX_IRQ (int ComPortNum, USART_TypeDef* uart) { INTERRUPT_START; char c; if (USART_RemoveCharFromTxBuffer(ComPortNum, c)) { uart->DR = c; // write TX data } else { uart->CR1 &= ~USART_CR1_TXEIE; // TX int disable } Events_Set(SYSTEM_EVENT_FLAG_COM_OUT); INTERRUPT_END; }
void PolyphonicPiezo_Driver::ToneDone_ISR( void* Param ) { ASSERT_IRQ_MUST_BE_OFF(); Events_Set( SYSTEM_EVENT_FLAG_TONE_COMPLETE ); PIEZO_POLY_TONE* Tone = g_PolyphonicPiezo_Driver.m_TonePlaying; if(Tone) { g_PolyphonicPiezo_Driver.m_ToneToRelease.LinkAtBack( Tone ); if(g_PolyphonicPiezo_Driver.m_ToneRelease.IsLinked() == false) { g_PolyphonicPiezo_Driver.m_ToneRelease.Enqueue(); } } else { Events_Set( SYSTEM_EVENT_FLAG_TONE_BUFFER_EMPTY ); } StartNext(); }
void USART_TxISR( UINT32 port ) { char c; GLOBAL_LOCK(irq); if(USART_RemoveCharFromTxBuffer( port, c )) { CPU_USART_WriteCharToTxBuffer( port, c ); Events_Set( SYSTEM_EVENT_FLAG_COM_OUT ); } else { CPU_USART_TxBufferEmptyInterruptEnable( port, FALSE ); } }
void USART_RxISR( UINT32 port ) { char c; GLOBAL_LOCK(irq); volatile unsigned short* rxReg; volatile unsigned char* rxData; switch(port) { case 0: rxReg = &SCIF0.SCFSR.WORD; rxData = &SCIF0.SCFRDR; break; case 1: rxReg = &SCIF1.SCFSR.WORD; rxData = &SCIF1.SCFRDR; break; case 2: rxReg = &SCIF2.SCFSR.WORD; rxData = &SCIF2.SCFRDR; break; default: ASSERT(FALSE); return; } while((*rxReg) & 0x0002) { c = *rxData; *rxReg &= 0xFFFD; if(!USART_AddCharToRxBuffer(port, c)) { break; } Events_Set( SYSTEM_EVENT_FLAG_COM_IN ); } }
void I2C_Driver::CompletedCallback( void* arg ) { NATIVE_PROFILE_PAL_COM(); I2C_HAL_XACTION* xAction = (I2C_HAL_XACTION*)arg; // is the transaction is the last of a series of related // transactions then free the bus for whoever comes next if(( xAction->m_current == (xAction->m_numXActionUnits)) || xAction->CheckState( I2C_HAL_XACTION::c_Status_Aborted | I2C_HAL_XACTION::c_Status_Cancelled )) { // signal the waiting thread; since continuations are executed one at a time for every round // of the scheduler there is no need to check for lost events on the waiting thread Events_Set( SYSTEM_EVENT_I2C_XACTION ); StartNext(); } }
void SH7264_SMSC_interrupt(void *param) { long int_sts; GLOBAL_LOCK(encIrq); int_sts = INT_STS; // Frame(s) received if(int_sts & INTSTS_RSFL_INT) { Events_Set( SYSTEM_EVENT_FLAG_SOCKET ); SMSC9218_RX_ISR(); rtp_thrd_interrupt_continuation(iface->ctrl.index); INT_STS = INTSTS_RSFL_INT; } // Clear interrupt status INT_STS = 0xFFFFFFFF; }
HRESULT Library_spot_net_native_Microsoft_SPOT_Net_SocketNative::close___STATIC__I4__OBJECT( CLR_RT_StackFrame& stack ) { NATIVE_PROFILE_CLR_NETWORK(); TINYCLR_HEADER(); CLR_INT32 handle, ret; CLR_RT_HeapBlock* socket = stack.Arg0().Dereference(); FAULT_ON_NULL(socket); handle = socket[ FIELD__m_Handle ].NumericByRef().s4; ret = SOCK_close( handle ); //If a socket gets closed, we need to make sure to wake up any threads that are waiting on it. Events_Set( SYSTEM_EVENT_FLAG_SOCKET ); stack.SetResult_I4( ret ); TINYCLR_NOCLEANUP(); }
BOOL USART_Driver::RemoveCharFromTxBuffer( int ComPortNum, char& c ) { if((ComPortNum < 0) || (ComPortNum >= TOTAL_USART_PORT)) return FALSE; HAL_USART_STATE& State = Hal_Usart_State[ComPortNum]; { GLOBAL_LOCK(irq); if (USART_FLAG_STATE(State,HAL_USART_STATE::c_TX_BUFFERXOFF)) { CLEAR_USART_FLAG(State,HAL_USART_STATE::c_TX_BUFFERXOFF); c = XOFF; return TRUE; } if( USART_FLAG_STATE(State,HAL_USART_STATE::c_TX_BUFFERXON)) { CLEAR_USART_FLAG(State, HAL_USART_STATE::c_TX_BUFFERXON); c = XON; return TRUE; } UINT8* Src = State.TxQueue.Pop(); if(Src) { c = *Src; Events_Set(SYSTEM_EVENT_FLAG_COM_OUT); return TRUE; } return FALSE; } }
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 CompletionCallback(void * context) { Events_Set(s_event); }
BOOL GPIO_BUTTON_Driver::RegisterStateChange( UINT32 ButtonPressed, UINT32 ButtonReleased ) { NATIVE_PROFILE_PAL_BUTTONS(); GLOBAL_LOCK(irq); // limit to legitimate transitions from previous state UINT32 TransitionDown = ButtonPressed & ~g_GPIO_BUTTON_Driver.m_CurrentButtonState; UINT32 TransitionUp = ButtonReleased & g_GPIO_BUTTON_Driver.m_CurrentButtonState; // do we have any buttons remaining after debouncing? // also, only limit to changes to previous state if(TransitionDown | TransitionUp) { BUTTON_STATE_CHANGE* ptr = g_GPIO_BUTTON_Driver.m_ButtonFifo.Push(); if(ptr) { ptr->Down = TransitionDown; ptr->Up = TransitionUp; // update current state g_GPIO_BUTTON_Driver.m_CurrentButtonState |= TransitionDown; g_GPIO_BUTTON_Driver.m_CurrentButtonState &= ~TransitionUp; } else { // if the queue is full, just return lcd_printf ( "\fBUTTON QUEUE FULL\r\n" ); debug_printf( "BUTTON QUEUE FULL\r\n" ); // let's make sure the app knows that it is supposed to drain the queue Events_Set( SYSTEM_EVENT_FLAG_BUTTON ); return FALSE; } // set the event for the waiter, as the queue may be full (how?) Events_Set( SYSTEM_EVENT_FLAG_BUTTON ); } #if defined(HAL_TIMEWARP) if(ButtonReleased) { switch(s_timewarp_armingState) { case 0: case 1: if(ButtonReleased & BUTTON_B0) { s_timewarp_armingState++; } else { s_timewarp_armingState = 0; } break; case 2: if(ButtonReleased & BUTTON_B0) // Backlight == DISABLE { s_timewarp_lastButton = TIMEWARP_DISABLE; } if(ButtonReleased & BUTTON_B4) // Select == ARM { s_timewarp_lastButton = Time_TicksToTime( Time_CurrentTicks() ); } s_timewarp_armingState = 0; break; } } #endif return TRUE; }
void sys_signal_sock_event() { Events_Set(SYSTEM_EVENT_FLAG_SOCKET); }
u32_t sys_arch_mbox_fetch(sys_mbox_t* mbox, void **msg, u32_t timeout) { if(mbox == NULL || *mbox == NULL) { ASSERT(FALSE); return SYS_ARCH_TIMEOUT; } Hal_Queue_UnknownSize<OpaqueQueueNode>* queue = (Hal_Queue_UnknownSize<OpaqueQueueNode>*)*mbox; bool didTimeout = false; if(timeout == 0) { timeout = 0xFFFFFFFF; } INT64 now = ::HAL_Time_CurrentTime(); INT64 elapsed = now + (timeout * 10000); while(elapsed > ::HAL_Time_CurrentTime() || timeout == 1) { OpaqueQueueNode* node = queue->Pop(); if(node) { *msg = node->payload; Events_Set(SYSTEM_EVENT_FLAG_NETWORK); SOCKETS_RestartTcpIpProcessor(0); return 0; } else if(timeout == 1) { break; } if(INTERRUPTS_ENABLED_STATE()) { if(Events_WaitForEvents(SYSTEM_EVENT_FLAG_NETWORK, timeout)) { Events_Clear(SYSTEM_EVENT_FLAG_NETWORK); INT64 curTime = ::HAL_Time_CurrentTime(); if(elapsed > curTime) { timeout -= (elapsed - HAL_Time_CurrentTime()) / 10000; } } else { break; } } else { break; } } if(timeout != 1) { Events_Set(SYSTEM_EVENT_FLAG_NETWORK); } else { didTimeout = true; } *msg = NULL; return didTimeout ? SYS_ARCH_TIMEOUT : SYS_MBOX_EMPTY; }
u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout) { volatile UINT32* semaphore = (volatile UINT32*)sem; if(timeout != 0) { INT64 now = ::HAL_Time_CurrentTime(); INT64 elapsed = now + (timeout * 10000); while(elapsed > ::HAL_Time_CurrentTime()) { if(IsSemaphoreGreen(semaphore)) { AcquireSemaphore(semaphore); break; } if(INTERRUPTS_ENABLED_STATE()) { if(Events_WaitForEvents(SYSTEM_EVENT_FLAG_NETWORK, timeout)) { Events_Clear(SYSTEM_EVENT_FLAG_NETWORK); INT64 curTime = ::HAL_Time_CurrentTime(); if(elapsed > curTime) { timeout -= (elapsed - HAL_Time_CurrentTime()) / 10000; } } else { break; } } else { break; } } } else { while(1) { // wait and call the continuation for tcpip_thread if(IsSemaphoreGreen(semaphore)) { AcquireSemaphore(semaphore); break; } if(INTERRUPTS_ENABLED_STATE()) { Events_WaitForEvents(SYSTEM_EVENT_FLAG_NETWORK, EVENTS_TIMEOUT_INFINITE); Events_Clear(SYSTEM_EVENT_FLAG_NETWORK); } else { break; } } } Events_Set(SYSTEM_EVENT_FLAG_NETWORK); return *semaphore; }
void LPC24XX_USART_Driver::UART_IntHandler (void *param) { GLOBAL_LOCK(irq); ASSERT(LPC24XX_USART_Driver::IsValidPortNum((UINT32)param)); char c; UINT32 ComNum = (UINT32)param; UINT32 i; UINT32 rxcnt=0; LPC24XX_USART& USARTC = LPC24XX::UART(ComNum); volatile UINT32 IIR_Value; volatile UINT32 LSR_Value; volatile register UINT32 * regRBR = &(USARTC.SEL1.RBR.UART_RBR); volatile register UINT32 * regLSR = &(USARTC.UART_LSR); IIR_Value = USARTC.SEL3.IIR.UART_IIR & LPC24XX_USART::UART_IIR_IID_mask; if (IIR_Value & LPC24XX_USART::UART_IIR_NIP) ASSERT(0); // Read data from Rx FIFO while (true) { LSR_Value = *regLSR ; if (LSR_Value & LPC24XX_USART::UART_LSR_RFDR) { volatile UINT8 rxdata = (UINT8 ) *regRBR; // No errors in Rx data USART_AddCharToRxBuffer(ComNum, rxdata); } else break; } // Send up to 2 bytes of Tx data for (i = 0; i <2; i++) { if (USART_RemoveCharFromTxBuffer( ComNum, c )) { WriteCharToTxBuffer( ComNum, c ); Events_Set( SYSTEM_EVENT_FLAG_COM_OUT ); } else { // Disable further TxBufferEmptyInterrupt. It will be // enabled by the PAL uart driver when a character to the // TxBuffer is added TxBufferEmptyInterruptEnable( ComNum, FALSE ); break; } } }