/*${AOs::USBTask::SM::main} ................................................*/ static QState USBTask_main(USBTask * const me, QEvt const * const e) { QState status_; switch (e->sig) { /* ${AOs::USBTask::SM::main::USB_DEV_ATTACH} */ case USB_DEV_ATTACH_SIG: { const char* const udastr = "\r\nUSB device attached "; PrintStringEvt* pse = Q_NEW(PrintStringEvt, PRINT_STRING_SIG); pse->str = udastr; QF_PUBLISH((QEvt*)pse, &me ); _DETACHIE = 1; status_ = Q_HANDLED(); break; } /* ${AOs::USBTask::SM::main::USB_DEV_DETACH} */ case USB_DEV_DETACH_SIG: { const char* const uddstr = "\r\nUSB device detached "; PrintStringEvt* pse = Q_NEW(PrintStringEvt, PRINT_STRING_SIG); pse->str = uddstr; QF_PUBLISH((QEvt*)pse, &me ); status_ = Q_TRAN(&USBTask_idle); break; } default: { status_ = Q_SUPER(&QHsm_top); break; } } return status_; }
uint8_t onCommandline(char* line) { char *next_token , *token= strtok_r(line, COMMAND_SEPARATORS, &next_token); if(!token) { return 0; } else { #ifdef SANITY_TEST for(; token; token = strtok_r(NULL, COMMAND_SEPARATORS, &next_token)) printf("%s\n", token); #endif//SANITY_TEST int i; for(i = 0; token[i]; i++) token[i] = toupper(token[i]); /* The following section has to keep up with number of signals */ if(strcmp(token, "START") == 0) { token = strtok_r(NULL, COMMAND_SEPARATORS, &next_token); if(!token) { return 0; } else { uint8_t period_in_tick = atoi(token); StartEvent* e = Q_NEW(StartEvent, START); e->period_in_tick = period_in_tick; QF_PUBLISH((QEvt*)e, NULL /* TODO: declare sender as BSP */); } } else if(strcmp(token, "STOP") == 0) { QF_PUBLISH(Q_NEW(QEvt, STOP), NULL); } else { return 0; } } return 1; }
/*..........................................................................*/ void SysTick_Handler(void) { static uint32_t btn_debounced = USR_SW1; static uint8_t debounce_state = 0U; uint32_t btn; QK_ISR_ENTRY(); /* inform QK about entering an ISR */ #ifdef Q_SPY { uint32_t dummy = SysTick->CTRL; /* clear SysTick_CTRL_COUNTFLAG */ QS_tickTime_ += QS_tickPeriod_; /* account for the clock rollover */ } #endif QF_TICK_X(0U, &l_SysTick_Handler); /* process time events for rate 0 */ /* debounce the SW1 button... */ btn = GPIOF->DATA_Bits[USR_SW1]; /* read the push btn */ switch (debounce_state) { case 0: if (btn != btn_debounced) { debounce_state = 1U; /* transition to the next state */ } break; case 1: if (btn != btn_debounced) { debounce_state = 2U; /* transition to the next state */ } else { debounce_state = 0U; /* transition back to state 0 */ } break; case 2: if (btn != btn_debounced) { debounce_state = 3U; /* transition to the next state */ } else { debounce_state = 0U; /* transition back to state 0 */ } break; case 3: if (btn != btn_debounced) { btn_debounced = btn; /* save the debounced button value */ if (btn == 0U) { /* is the button depressed? */ static QEvt const pauseEvt = { PAUSE_SIG, 0U, 0U}; QF_PUBLISH(&pauseEvt, &l_SysTick_Handler); } else { static QEvt const pauseEvt = { PAUSE_SIG, 0U, 0U}; QF_PUBLISH(&pauseEvt, &l_SysTick_Handler); } } debounce_state = 0U; /* transition back to state 0 */ break; } QK_ISR_EXIT(); /* inform QK about exiting an ISR */ }
/*..........................................................................*/ void SysTick_Handler(void) { static uint32_t btn_debounced = 0; static uint8_t debounce_state = 0; uint32_t volatile tmp; QK_ISR_ENTRY(); /* inform QK about ISR entry */ ++l_nTicks; /* count the number of clock ticks */ #ifdef Q_SPY tmp = SysTick->CTRL; /* clear SysTick_CTRL_COUNTFLAG */ QS_tickTime_ += QS_tickPeriod_; /* account for the clock rollover */ #endif QF_TICK(&l_SysTick_Handler); /* process all armed time events */ tmp = GPIOF->DATA_Bits[USER_BTN]; /* read the User Button */ switch (debounce_state) { case 0: if (tmp != btn_debounced) { debounce_state = 1; /* transition to the next state */ } break; case 1: if (tmp != btn_debounced) { debounce_state = 2; /* transition to the next state */ } else { debounce_state = 0; /* transition back to state 0 */ } break; case 2: if (tmp != btn_debounced) { debounce_state = 3; /* transition to the next state */ } else { debounce_state = 0; /* transition back to state 0 */ } break; case 3: if (tmp != btn_debounced) { btn_debounced = tmp; /* save the debounced button value */ if (tmp == 0) { /* is the button depressed? */ static QEvt const bd = { BTN_DOWN_SIG, 0 }; QF_PUBLISH(&bd, &l_SysTick_Handler); } else { static QEvt const bu = { BTN_UP_SIG, 0 }; QF_PUBLISH(&bu, &l_SysTick_Handler); } } debounce_state = 0; /* transition back to state 0 */ break; } QK_ISR_EXIT(); /* inform QK about ISR exit */ }
/*..........................................................................*/ void QF_onClockTick(void) { QF_TICK(&l_clock_tick); /* perform the QF clock tick processing */ if (_kbhit()) { /* any key pressed? */ int ch = _getch(); if (ch == '\33') { /* see if the ESC key pressed */ QF_PUBLISH(Q_NEW(QEvt, TERMINATE_SIG), &l_clock_tick); } else if (ch == 'p') { QF_PUBLISH(Q_NEW(QEvt, PAUSE_SIG), &l_clock_tick); } } }
/*..........................................................................*/ QState Philo_eating(Philo *me, QEvt const *e) { switch (e->sig) { case Q_ENTRY_SIG: { QTimeEvt_postIn(&me->timeEvt, (QActive *)me, EAT_TIME); return Q_HANDLED(); } case Q_EXIT_SIG: { TableEvt *pe = Q_NEW(TableEvt, DONE_SIG); pe->philoNum = PHILO_ID(me); QF_PUBLISH((QEvt *)pe, me); return Q_HANDLED(); } case TIMEOUT_SIG: { BSP_busyDelay(); return Q_TRAN(&Philo_thinking); } case EAT_SIG: /* intentionally fall-through */ case DONE_SIG: { /* EAT or DONE must be for other Philos than this one */ Q_ASSERT(((TableEvt const *)e)->philoNum != PHILO_ID(me)); return Q_HANDLED(); } } return Q_SUPER(&QHsm_top); }
/* @(/2/0/2/3) .............................................................*/ QState Philo_eating(Philo *me, QEvent const *e) { switch (e->sig) { /* @(/2/0/2/3) */ case Q_ENTRY_SIG: { QTimeEvt_postIn(&me->timeEvt, &me->super, EAT_TIME); return Q_HANDLED(); } /* @(/2/0/2/3) */ case Q_EXIT_SIG: { TableEvt *pe = Q_NEW(TableEvt, DONE_SIG); pe->philoNum = PHILO_ID(me); QF_PUBLISH((QEvent const *)pe, me); return Q_HANDLED(); } /* @(/2/0/2/3/0) */ case TIMEOUT_SIG: { BSP_busyDelay(); return Q_TRAN(&Philo_thinking); } /* @(/2/0/2/3/1) */ case TERMINATE_SIG: /* intentionally fall through */ case DONE_SIG: { Q_ERROR(); return Q_HANDLED(); } /* @(/2/0/2/3/2) */ case EAT_SIG: { Q_ASSERT(((TableEvt const *)e)->philoNum != PHILO_ID(me)); return Q_HANDLED(); } } return Q_SUPER(&QHsm_top); }
QState Philo_eating(Philo * const me, QEvt const * const e) { QState status; switch (e->sig) { case Q_ENTRY_SIG: { QTimeEvt_armX(&me->timeEvt, EAT_TIME, 0U); /* one shot */ status = Q_HANDLED(); break; } case Q_EXIT_SIG: { TableEvt *pe; QTimeEvt_disarm(&me->timeEvt); pe = Q_NEW(TableEvt, DONE_SIG); pe->philNum = me->num; QF_PUBLISH((QEvt *)pe, me); status = Q_HANDLED(); break; } case TIMEOUT_SIG: { status = Q_TRAN(&Philosopher_thinking); break; } default: { status = Q_SUPER(&QHsm_top); break; } } return status; }
/*..........................................................................*/ static void interrupt ISR_kbd() { static uint8_t ship_pos = GAME_SHIP_Y; uint8_t key; uint8_t kcr; QF_ISR_ENTRY(); /* QF-specific ISR entry */ key = inp(0x60); /* key scan code from 8042 kbd controller */ kcr = inp(0x61); /* get keyboard control register */ outp(0x61, (uint8_t)(kcr | 0x80)); /* toggle acknowledge bit high */ outp(0x61, kcr); /* toggle acknowledge bit low */ switch (key) { case 200: /* Up-arrow */ case 208: { /* Down-arrow */ ObjectPosEvt *ope = Q_NEW(ObjectPosEvt, PLAYER_SHIP_MOVE_SIG); if ((key == (uint8_t)200) && (ship_pos > 0x00)) { --ship_pos; } else if ((key == (uint8_t)208) && (ship_pos < (GAME_SCREEN_HEIGHT - 3))) { ++ship_pos; } ope->x = (uint8_t)GAME_SHIP_X; /* x-position is fixed */ ope->y = (uint8_t)ship_pos; QACTIVE_POST(AO_Ship, (QEvt *)ope, &l_kbd); /* to the ship */ Video_printNumAt(24, 24, VIDEO_FGND_YELLOW, ship_pos); break; } case 57: { /* Space */ static uint16_t ntrig = 0; static QEvt const fireEvt = { PLAYER_TRIGGER_SIG, 0, 0 }; QF_PUBLISH(&fireEvt, &l_kbd); Video_printNumAt(47, 24, VIDEO_FGND_YELLOW, ++ntrig); break; } /* Esc */ case 129: { static QEvt const quitEvt = { PLAYER_QUIT_SIG, 0, 0 }; QF_PUBLISH(&quitEvt, &l_kbd); break; } } QF_ISR_EXIT(); /* QF-specific ISR exit */ }
TIMER0_A0_ISR(void) #else #error MSP430 compiler not supported! #endif { /* state of the button debouncing, see below */ static struct ButtonsDebouncing { uint8_t depressed; uint8_t previous; } buttons = { (uint8_t)~0U, (uint8_t)~0U }; uint8_t current; uint8_t tmp; TACTL &= ~TAIFG; /* clear the interrupt pending flag */ #ifdef NDEBUG __low_power_mode_off_on_exit(); /* see NOTE1 */ #endif #ifdef Q_SPY QS_tickTime_ += (((BSP_SMCLK / 8) + BSP_TICKS_PER_SEC/2) / BSP_TICKS_PER_SEC) + 1; #endif QF_TICK_X(0U, (void *)0); /* process all time events at rate 0 */ /* Perform the debouncing of buttons. The algorithm for debouncing * adapted from the book "Embedded Systems Dictionary" by Jack Ganssle * and Michael Barr, page 71. */ current = ~P1IN; /* read P1 port with the state of BTN1 */ tmp = buttons.depressed; /* save the debounced depressed buttons */ buttons.depressed |= (buttons.previous & current); /* set depressed */ buttons.depressed &= (buttons.previous | current); /* clear released */ buttons.previous = current; /* update the history */ tmp ^= buttons.depressed; /* changed debounced depressed */ if ((tmp & BTN1) != 0U) { /* debounced BTN1 state changed? */ if ((buttons.depressed & BTN1) != 0U) { /* is BTN1 depressed? */ static QEvt const pauseEvt = { PAUSE_SIG, 0U, 0U}; QF_PUBLISH(&pauseEvt, &l_timerA_ISR); } else { /* the button is released */ static QEvt const serveEvt = { SERVE_SIG, 0U, 0U}; QF_PUBLISH(&serveEvt, &l_timerA_ISR); } } }
/* ISRs used in the application ==========================================*/ void SysTick_Handler(void) { /* system clock tick ISR */ /* state of the button debouncing, see below */ static struct ButtonsDebouncing { uint32_t depressed; uint32_t previous; } buttons = { ~0U, ~0U }; uint32_t current; uint32_t tmp; QK_ISR_ENTRY(); /* inform QK about entering an ISR */ #ifdef Q_SPY { tmp = SysTick->CTRL; /* clear CTRL_COUNTFLAG */ QS_tickTime_ += QS_tickPeriod_; /* account for the clock rollover */ } #endif QF_TICK_X(0U, &l_SysTick_Handler); /* process time events for rate 0 */ /* get state of the user button */ /* Perform the debouncing of buttons. The algorithm for debouncing * adapted from the book "Embedded Systems Dictionary" by Jack Ganssle * and Michael Barr, page 71. */ current = ~GPIOC->IDR; /* read Port C with the state of Button B1 */ tmp = buttons.depressed; /* save the debounced depressed buttons */ buttons.depressed |= (buttons.previous & current); /* set depressed */ buttons.depressed &= (buttons.previous | current); /* clear released */ buttons.previous = current; /* update the history */ tmp ^= buttons.depressed; /* changed debounced depressed */ if ((tmp & BTN_B1) != 0U) { /* debounced B1 state changed? */ if ((buttons.depressed & BTN_B1) != 0U) { /* is B1 depressed? */ static QEvt const pauseEvt = { PAUSE_SIG, 0U, 0U}; QF_PUBLISH(&pauseEvt, &l_SysTick_Handler); } else { /* the button is released */ static QEvt const serveEvt = { SERVE_SIG, 0U, 0U}; QF_PUBLISH(&serveEvt, &l_SysTick_Handler); } } QK_ISR_EXIT(); /* inform QK about exiting an ISR */ }
/*..........................................................................*/ void SysTick_Handler(void) { /* state of the button debouncing, see below */ static struct ButtonsDebouncing { uint32_t depressed; uint32_t previous; } buttons = { ~0U, ~0U }; uint32_t current; uint32_t volatile tmp; QK_ISR_ENTRY(); /* inform QK about ISR entry */ ++l_nTicks; /* count the number of clock ticks */ #ifdef Q_SPY tmp = SysTick->CTRL; /* clear SysTick_CTRL_COUNTFLAG */ QS_tickTime_ += QS_tickPeriod_; /* account for the clock rollover */ #endif QF_TICK_X(0U, &l_SysTick_Handler); /* process time events for rate 0 */ /* Perform the debouncing of buttons. The algorithm for debouncing * adapted from the book "Embedded Systems Dictionary" by Jack Ganssle * and Michael Barr, page 71. */ current = ~GPIOF->DATA_Bits[USER_BTN]; /* read USER_BTN */ tmp = buttons.depressed; /* save the debounced depressed buttons */ buttons.depressed |= (buttons.previous & current); /* set depressed */ buttons.depressed &= (buttons.previous | current); /* clear released */ buttons.previous = current; /* update the history */ tmp ^= buttons.depressed; /* changed debounced depressed */ if ((tmp & USER_BTN) != 0U) { /* debounced USER_BTN state changed? */ if ((buttons.depressed & USER_BTN) != 0U) { /* is BTN depressed? */ static QEvt const bd = { BTN_DOWN_SIG, 0U, 0U }; QF_PUBLISH(&bd, &l_SysTick_Handler); } else { /* the button is released */ static QEvt const bu = { BTN_UP_SIG, 0U, 0U }; QF_PUBLISH(&bu, &l_SysTick_Handler); } } QK_ISR_EXIT(); /* inform QK about ISR exit */ }
/* UDP receive handler -----------------------------------------------------*/ static void udp_rx_handler(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, u16_t port) { TextEvt *te = Q_NEW(TextEvt, DISPLAY_UDP_SIG); strncpy(te->text, (char *)p->payload, Q_DIM(te->text)); QF_PUBLISH((QEvt *)te, AO_LwIPMgr); udp_connect(upcb, addr, port); /* connect to the remote host */ pbuf_free(p); /* don't leak the pbuf! */ }
/*..........................................................................*/ static void interrupt ISR_tmr() { static QEvt const tickEvt = { TIME_TICK_SIG, 0, 0 }; QF_ISR_ENTRY(); /* QF-specific ISR entry */ QF_TICK(&l_tmr); /* call QF_tick() outside of critical section */ QF_PUBLISH(&tickEvt, &l_tmr); /* publish the tick event */ #ifdef Q_SPY l_tickTime += 0x10000; #endif QF_ISR_EXIT(); /* QF-specific ISR exit */ }
/* ISRs --------------------------------------------------------------------*/ __ramfunc static void ISR_tick(void) { /* state of the button debouncing, see below */ static struct ButtonsDebouncing { uint32_t depressed; uint32_t previous; } buttons = { ~0U, ~0U }; uint32_t current; uint32_t volatile tmp; /* clear the interrupt source */ tmp = AT91C_BASE_PITC->PITC_PIVR; QF_TICK_X(0U, &l_ISR_tick); /* process all time events at tick rate 0 */ /* Perform the debouncing of buttons. The algorithm for debouncing * adapted from the book "Embedded Systems Dictionary" by Jack Ganssle * and Michael Barr, page 71. */ current = ~AT91C_BASE_PIOA->PIO_PDSR;/* read PIOA with state of Buttons */ tmp = buttons.depressed; /* save the debounced depressed buttons */ buttons.depressed |= (buttons.previous & current); /* set depressed */ buttons.depressed &= (buttons.previous | current); /* clear released */ buttons.previous = current; /* update the history */ tmp ^= buttons.depressed; /* changed debounced depressed */ if ((tmp & l_btn[0]) != 0U) { /* debounced BTN_P1 state changed? */ if ((buttons.depressed & l_btn[0]) != 0U) { /* is BTN_P1 depressed? */ static QEvt const pauseEvt = { PAUSE_SIG, 0U, 0U}; QF_PUBLISH(&pauseEvt, &l_ISR_tick); } else { /* the button is released */ static QEvt const serveEvt = { SERVE_SIG, 0U, 0U}; QF_PUBLISH(&serveEvt, &l_ISR_tick); } } }
inline void Serial_DMASendCallback( void ) { /* Test on DMA Stream Transfer Complete interrupt */ if ( RESET != DMA_GetITStatus(DMA2_Stream7, DMA_IT_TCIF7) ) { /* Disable DMA so it doesn't keep outputting the buffer. */ DMA_Cmd(DMA2_Stream7, DISABLE); /* Publish event stating that the count has been reached */ QEvt *qEvt = Q_NEW(QEvt, UART_DMA_DONE_SIG); QF_PUBLISH((QEvent *)qEvt, AO_SerialMgr ); /* Clear DMA Stream Transfer Complete interrupt pending bit */ DMA_ClearITPendingBit(DMA2_Stream7, DMA_IT_TCIF7); } }
__interrupt void timer2_ISR(void) { /* state of the button debouncing, see below */ static struct ButtonsDebouncing { uint8_t depressed; uint8_t previous; } buttons = { 0xFFU, 0xFFU }; uint8_t current; uint8_t tmp; QF_TICK_X(0U, &l_ISR_TIMER2_COMPA); /* process time events at rate 0 */ #ifdef Q_SPY BSP_tickTime += (F_CPU / BSP_TICKS_PER_SEC / 1024U); #endif /* Perform the debouncing of buttons. The algorithm for debouncing * adapted from the book "Embedded Systems Dictionary" by Jack Ganssle * and Michael Barr, page 71. */ current = PIND; /* read PORTD with the state of BTN_EXT */ tmp = buttons.depressed; /* save the debounced depressed buttons */ buttons.depressed |= (buttons.previous & current); /* set depressed */ buttons.depressed &= (buttons.previous | current); /* clear released */ buttons.previous = current; /* update the history */ tmp ^= buttons.depressed; /* changed debounced depressed */ if ((tmp & BTN_EXT) != 0U) { /* debounced BTN_EXT state changed? */ if ((buttons.depressed & BTN_EXT) != 0U) { /* is BTN_EXT depressed? */ static QEvt const pauseEvt = { PAUSE_SIG, 0U, 0U}; QF_PUBLISH(&pauseEvt, &l_ISR_TIMER2_COMPA); } else { /* the button is released */ static QEvt const serveEvt = { SERVE_SIG, 0U, 0U}; QF_PUBLISH(&serveEvt, &l_ISR_TIMER2_COMPA); } } }
/* Common Gateway Iinterface (CG) handler ..................................*/ static char const *cgi_display(int index, int numParams, char const *param[], char const *value[]) { int i; for (i = 0; i < numParams; ++i) { if (strstr(param[i], "text") != (char *)0) { /* param text found? */ TextEvt *te = Q_NEW(TextEvt, DISPLAY_CGI_SIG); strncpy(te->text, value[i], Q_DIM(te->text)); QF_PUBLISH((QEvt *)te, AO_LwIPMgr); return "/thank_you.htm"; } } return (char *)0;/*no URI, HTTPD will send 404 error page to the browser*/ }
/*..........................................................................*/ void interrupt ISR_kbd(void) { uint8_t key; uint8_t kcr; QF_ISR_ENTRY(); /* QF-specific ISR entry */ key = inp(0x60); /* key scan code from the 8042 kbd controller */ kcr = inp(0x61); /* get keyboard control register */ outp(0x61, (uint8_t)(kcr | 0x80)); /* toggle acknowledge bit high */ outp(0x61, kcr); /* toggle acknowledge bit low */ if (key == (uint8_t)129) { /* ESC key pressed? */ static QEvt term = {TERMINATE_SIG, 0, 0 }; /* static event */ QF_PUBLISH(&term, &l_kbd); /* publish to all interested AOs */ } QF_ISR_EXIT(); /* QF-specific ISR exit */ }
/*..........................................................................*/ void ucosTask(void *pdata) { (void)pdata; /* avoid the compiler warning about unused parameter */ QF_onStartup(); /* start interrupts including the clock tick, NOTE01 */ for (;;) { OSTimeDly(OS_TICKS_PER_SEC/10); /* sleep for 1/10 s */ if (kbhit()) { /* poll for a new keypress */ uint8_t key = (uint8_t)getch(); if (key == 0x1B) { /* is this the ESC key? */ QF_PUBLISH(Q_NEW(QEvt, TERMINATE_SIG), &l_kbdTask); } else { /* other key pressed */ Video_printNumAt(30, 13 + N_PHILO, VIDEO_FGND_YELLOW, key); } } } }
/*..........................................................................*/ static void playerTrigger(void) { static QEvt const fireEvt = { PLAYER_TRIGGER_SIG, 0U, 0U }; QF_PUBLISH(&fireEvt, (void*)0); }
/*..........................................................................*/ void QF_onClockTick(void) { static QEvt const tickEvt = { TIME_TICK_SIG, 0U, 0U }; QF_TICK_X(0U, &l_clock_tick); /* process time events for rate 0 */ QF_PUBLISH(&tickEvt, &l_clock_tick); /* publish the tick event */ }
/* ${AOs::Philo::SM::eating} */ static QState Philo_eating_x(Philo * const me) { TableEvt *pe = Q_NEW(TableEvt, DONE_SIG); pe->philoNum = PHILO_ID(me); QF_PUBLISH(&pe->super, me); return QM_EXIT(&Philo_eating_s); }
inline void Serial_UART1Callback(void) { while (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) { uint8_t data = (uint8_t)USART_ReceiveData(USART1); if ( '\n' == data && a_UARTSettings[SERIAL_UART1].indexRX > 0 ) { /* If a newline is received and the buffer is not empty, post event * with the buffer data */ a_UARTSettings[SERIAL_UART1].bufferRX[ a_UARTSettings[SERIAL_UART1].indexRX++ ] = data; #if 0 // TODO: Old menu stuff. Keep for now but get rid of eventually /* Serial can only receive menu commands */ MenuEvt *menuEvt = Q_NEW( MenuEvt, DBG_MENU_REQ_SIG ); /* 2. Fill the msg payload with payload (the actual received msg)*/ MEMCPY( menuEvt->buffer, a_UARTSettings[SERIAL_UART1].bufferRX, a_UARTSettings[SERIAL_UART1].indexRX ); menuEvt->bufferLen = a_UARTSettings[SERIAL_UART1].indexRX; menuEvt->msgSrc = _DC3_Serial; /* 3. Publish the newly created event to current AO */ QF_PUBLISH( (QEvent *)menuEvt, AO_SerialMgr ); #endif /* 1. Construct a new msg event indicating that a msg has been received */ LrgDataEvt *msgEvt = Q_NEW(LrgDataEvt, SER_RECEIVED_SIG); /* 2. Fill the msg payload and get the msg source and length */ MEMCPY( msgEvt->dataBuf, a_UARTSettings[SERIAL_UART1].bufferRX, a_UARTSettings[SERIAL_UART1].indexRX ); msgEvt->dataLen = a_UARTSettings[SERIAL_UART1].indexRX; msgEvt->src = _DC3_Serial; msgEvt->dst = _DC3_Serial; /* 3.Publish the newly created event */ QF_PUBLISH((QEvent *)msgEvt, AO_SerialMgr); a_UARTSettings[SERIAL_UART1].indexRX = 0; /* Reset the RX buffer */ } else if ( '\r' == data ) { /* If a linefeed is received, toss it out. */ data = 0; } else { if ( a_UARTSettings[SERIAL_UART1].indexRX >= DC3_MAX_MSG_LEN ) { WRN_printf( "Attempting to RX a serial msg over %d bytes which will overrun the buffer. Ignoring\n", DC3_MAX_MSG_LEN ); a_UARTSettings[SERIAL_UART1].indexRX = 0; /* Reset the RX buffer */ } else { /* If any other data is recieved, add it to the buffer */ a_UARTSettings[SERIAL_UART1].bufferRX[ a_UARTSettings[SERIAL_UART1].indexRX++ ] = data; } } } }
//............................................................................ void Gui::onQuit() { // slot static QEvt const e = { TERMINATE_SIG, 0U, 0U }; QF_PUBLISH(&e, (void *)0); qDebug("onQuit"); }
//............................................................................ void Gui::onPauseReleased() { // slot static QEvt const e = { PAUSE_SIG, 0U, 0U }; QF_PUBLISH(&e, (void *)0); qDebug("onPauseReleased"); }
/*..........................................................................*/ QState LwIPMgr_running(LwIPMgr *me, QEvent const *e) { switch (e->sig) { case Q_ENTRY_SIG: { QTimeEvt_postEvery(&me->te_LWIP_SLOW_TICK, (QActive *)me, (LWIP_SLOW_TICK_MS * BSP_TICKS_PER_SEC) / 1000); return Q_HANDLED(); } case Q_EXIT_SIG: { QTimeEvt_disarm(&me->te_LWIP_SLOW_TICK); return Q_HANDLED(); } case SEND_UDP_SIG: { if (me->upcb->remote_port != (uint16_t)0) { struct pbuf *p = pbuf_new((u8_t *)((TextEvt const *)e)->text, strlen(((TextEvt const *)e)->text) + 1); if (p != (struct pbuf *)0) { udp_send(me->upcb, p); printf("Sent: %s\n", ((TextEvt const *)e)->text); pbuf_free(p); /* don't leak the pbuf! */ } } return Q_HANDLED(); } case LWIP_RX_READY_SIG: { eth_driver_read(); return Q_HANDLED(); } case LWIP_TX_READY_SIG: { eth_driver_write(); return Q_HANDLED(); } case LWIP_SLOW_TICK_SIG: { /* has IP address changed? */ if (me->ip_addr != me->netif->ip_addr.addr) { TextEvt *te; uint32_t ip_net; /* IP address in the network byte order */ me->ip_addr = me->netif->ip_addr.addr; /* save the IP addr. */ ip_net = ntohl(me->ip_addr); /* publish the text event to display the new IP address */ te = Q_NEW(TextEvt, DISPLAY_IPADDR_SIG); snprintf(te->text, Q_DIM(te->text), "%d.%d.%d.%d", ((ip_net) >> 24) & 0xFF, ((ip_net) >> 16) & 0xFF, ((ip_net) >> 8) & 0xFF, ip_net & 0xFF); QF_PUBLISH((QEvent *)te, me); } #if LWIP_TCP me->tcp_tmr += LWIP_SLOW_TICK_MS; if (me->tcp_tmr >= TCP_TMR_INTERVAL) { me->tcp_tmr = 0; tcp_tmr(); } #endif #if LWIP_ARP me->arp_tmr += LWIP_SLOW_TICK_MS; if (me->arp_tmr >= ARP_TMR_INTERVAL) { me->arp_tmr = 0; etharp_tmr(); } #endif #if LWIP_DHCP me->dhcp_fine_tmr += LWIP_SLOW_TICK_MS; if (me->dhcp_fine_tmr >= DHCP_FINE_TIMER_MSECS) { me->dhcp_fine_tmr = 0; dhcp_fine_tmr(); } me->dhcp_coarse_tmr += LWIP_SLOW_TICK_MS; if (me->dhcp_coarse_tmr >= DHCP_COARSE_TIMER_MSECS) { me->dhcp_coarse_tmr = 0; dhcp_coarse_tmr(); } #endif #if LWIP_AUTOIP me->auto_ip_tmr += LWIP_SLOW_TICK_MS; if (me->auto_ip_tmr >= AUTOIP_TMR_INTERVAL) { me->auto_ip_tmr = 0; autoip_tmr(); } #endif return Q_HANDLED(); } case LWIP_RX_OVERRUN_SIG: { LINK_STATS_INC(link.err); return Q_HANDLED(); } }