void uart_event_handler(nrf_drv_uart_event_t * p_event, void* p_context) { switch(p_event->type) { case NRF_DRV_UART_EVT_RX_DONE: for (uint8_t i=0; i < p_event->data.rxtx.bytes; ++i) { //p_event->data.rxtx.p_data[0]; //(void)nrf_drv_uart_rx(&byte,1); QS_RX_PUT(p_event->data.rxtx.p_data[i]); } QS_rxParse(); /* parse all the received bytes */ break; case NRF_DRV_UART_EVT_ERROR: //p_event->data.error.error_mask; case NRF_DRV_UART_EVT_TX_DONE: uart_tx1(); break; } }
/*..........................................................................*/ void QV_onIdle(void) { /* called with interrupts disabled, see NOTE01 */ #ifdef Q_SPY # if 0 QS_rxParse(); /* parse all the received bytes */ // Push out QS buffer to UART if (!nrf_drv_uart_tx_in_progress()) { /* is TXE empty? */ static uint16_t b; QF_INT_DISABLE(); b = QS_getByte(); QF_INT_ENABLE(); if (b != QS_EOD) { /* not End-Of-Data? */ nrf_drv_uart_tx((const uint8_t*)&b, 1); } } # else QF_INT_ENABLE(); //sd_app_evt_wait(); __WFE(); //__SEV(); __WFE(); # endif #elif defined NDEBUG /* Put the CPU and peripherals to the low-power mode. * you might need to customize the clock management for your application, * see the datasheet for your particular Cortex-M MCU. */ /* !!!CAUTION!!! * The QF_CPU_SLEEP() contains the WFI instruction, which stops the CPU * clock, which unfortunately disables the JTAG port, so the ST-Link * debugger can no longer connect to the board. For that reason, the call * to QF_CPU_SLEEP() has to be used with CAUTION. */ //QV_CPU_SLEEP(); //atomically go to SHALLOW sleep and enable interrupts __WFE(); QF_INT_ENABLE(); /* for now, just enable interrupts */ #else QF_INT_ENABLE(); /* just enable interrupts */ #endif }
/*..........................................................................*/ static DWORD WINAPI idleThread(LPVOID par) {/* signature for CreateThread() */ (void)par; while (l_sock != INVALID_SOCKET) { uint16_t nBytes; uint8_t const *block; /* try to receive bytes from the QS socket... */ nBytes = QS_rxGetNfree(); if (nBytes > 0U) { uint8_t buf[64]; int status; if (nBytes > sizeof(buf)) { nBytes = sizeof(buf); } status = recv(l_sock, (char *)buf, (int)nBytes, 0); if (status != SOCKET_ERROR) { uint16_t i; nBytes = (uint16_t)status; for (i = 0U; i < nBytes; ++i) { QS_RX_PUT(buf[i]); } } } QS_rxParse(); /* parse all the received bytes */ nBytes = 1024U; QF_CRIT_ENTRY(dummy); block = QS_getBlock(&nBytes); QF_CRIT_EXIT(dummy); if (block != (uint8_t *)0) { send(l_sock, (char const *)block, nBytes, 0); } Sleep(20); /* sleep for xx milliseconds */ } return (DWORD)0; /* return success */ }