void QK_onIdle(void) { #ifdef Q_SPY /* use the idle cycles for QS transmission */ if ((AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXBUFE) != 0) { /* not busy? */ uint16_t nBytes = 0xFFFF; uint8_t const *block; QF_INT_DISABLE(); if ((block = QS_getBlock(&nBytes)) != (uint8_t *)0) { /* new block? */ AT91C_BASE_DBGU->DBGU_TPR = (uint32_t)block; AT91C_BASE_DBGU->DBGU_TCR = (uint32_t)nBytes; nBytes = 0xFFFF; if ((block = QS_getBlock(&nBytes)) != (uint8_t *)0) {/*another? */ AT91C_BASE_DBGU->DBGU_TNPR = (uint32_t)block; AT91C_BASE_DBGU->DBGU_TNCR = (uint32_t)nBytes; } } QF_INT_ENABLE(); } #elif defined NDEBUG /* only if not debugging (idle mode hinders debugging) */ AT91C_BASE_PMC->PMC_SCDR = 1;/* Power-Management: disable the CPU clock */ /* NOTE: an interrupt starts the CPU clock again */ #endif }
/*..........................................................................*/ __ramfunc void QK_onIdle(void) { /* toggle first LED on and off, see NOTE01 */ QF_INT_DISABLE(); LED_ON(3); /* turn LED on */ LED_OFF(3); /* turn LED off */ QF_INT_ENABLE(); #ifdef Q_SPY /* use the idle cycles for QS transmission... */ if ((AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXBUFE) != 0) { /* not busy? */ uint16_t nBytes = 0xFFFFU; /* get all available bytes */ uint8_t const *block; QF_INT_DISABLE(); if ((block = QS_getBlock(&nBytes)) != (uint8_t *)0) { /* new block? */ AT91C_BASE_DBGU->DBGU_TPR = (uint32_t)block; AT91C_BASE_DBGU->DBGU_TCR = (uint32_t)nBytes; nBytes = 0xFFFFU; /* get all available bytes */ if ((block = QS_getBlock(&nBytes)) != (uint8_t *)0) {/*another? */ AT91C_BASE_DBGU->DBGU_TNPR = (uint32_t)block; AT91C_BASE_DBGU->DBGU_TNCR = (uint32_t)nBytes; } } QF_INT_ENABLE(); } #elif defined NDEBUG /* only if not debugging (idle mode hinders debugging) */ AT91C_BASE_PMC->PMC_SCDR = 1;/* Power-Management: disable the CPU clock */ /* NOTE: an interrupt starts the CPU clock again */ #endif }
/*..........................................................................*/ void QK_onIdle(void) { /* toggle the User LED on and then off, see NOTE02 */ QF_INT_LOCK(dummy); GPIOC->DATA_Bits[USER_LED] = USER_LED; /* turn the User LED on */ GPIOC->DATA_Bits[USER_LED] = 0; /* turn the User LED off */ QF_INT_UNLOCK(dummy); #ifdef Q_SPY if ((UART0->FR & UART_FR_TXFE) != 0) { /* TX done? */ uint16_t fifo = UART_TXFIFO_DEPTH; /* max bytes we can accept */ uint8_t const *block; QF_INT_LOCK(dummy); block = QS_getBlock(&fifo); /* try to get next block to transmit */ QF_INT_UNLOCK(dummy); while (fifo-- != 0) { /* any bytes in the block? */ UART0->DR = *block++; /* put into the FIFO */ } } #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-M3 MCU. */ __WFI(); /* Wait-For-Interrupt */ #endif }
/*..........................................................................*/ void QK_onIdle(void) { float volatile x; /* toggle the User LED on and then off, see NOTE01 */ QF_INT_DISABLE(); GPIOF->DATA_Bits[LED_GREEN] = LED_GREEN; /* turn the Green LED on */ GPIOF->DATA_Bits[LED_GREEN] = 0; /* turn the Green LED off */ QF_INT_ENABLE(); x = 3.1415926F; x = x + 2.7182818F; #ifdef Q_SPY if ((UART0->FR & UART_FR_TXFE) != 0) { /* TX done? */ uint16_t fifo = UART_TXFIFO_DEPTH; /* max bytes we can accept */ uint8_t const *block; QF_INT_DISABLE(); block = QS_getBlock(&fifo); /* try to get next block to transmit */ QF_INT_ENABLE(); while (fifo-- != 0) { /* any bytes in the block? */ UART0->DR = *block++; /* put into the FIFO */ } } #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-M3 MCU. */ __WFI(); /* Wait-For-Interrupt */ #endif }
/*..........................................................................*/ static DWORD WINAPI idleThread(LPVOID par) {/* signature for CreateThread() */ (void)par; l_running = (uint8_t)1; while (l_running) { Sleep(10); /* wait for a while */ if (_kbhit()) { /* any key pressed? */ char payload[1024]; if(!gets_s(payload, sizeof(payload))) { // EOF reached printf("EOF received; exiting\n"); QF_stop(); } else { uint16_t len = strlen(payload); onPacket(payload, len, BSPConsole_print, NULL); } } #ifdef Q_SPY { uint16_t nBytes = 1024; uint8_t const *block; 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); } } #endif } return 0; /* return success */ }
/*..........................................................................*/ void QS_onFlush(void) { uint16_t nBytes = 1000; uint8_t const *block; while ((block = QS_getBlock(&nBytes)) != (uint8_t *)0) { send(l_sock, (char const *)block, nBytes, 0); nBytes = 1000; } }
/*..........................................................................*/ void QS_onFlush(void) { #ifdef Q_SPY uint8_t const *block; uint16_t nBytes = QS_SPY_BLOCK; while (np.dev && (block = QS_getBlock(&nBytes)) != (uint8_t *)0) { QS_send(block, nBytes); nBytes = QS_SPY_BLOCK; } #endif }
/*..........................................................................*/ void QS_onFlush(void) { uint16_t fifo = UART_16550_TXFIFO_DEPTH; /* 16550 Tx FIFO depth */ uint8_t const *block; while ((block = QS_getBlock(&fifo)) != (uint8_t *)0) { /* busy-wait until TX FIFO empty */ while ((inp(l_uart_base + 5) & (1 << 5)) == 0) { } while (fifo-- != 0) { /* any bytes in the block? */ outp(l_uart_base + 0, *block++); } fifo = UART_16550_TXFIFO_DEPTH; /* re-load 16550 Tx FIFO depth */ } }
/*..........................................................................*/ void QF_onIdle(void) { /* called with interrupts LOCKED */ QF_INT_ENABLE(); /* always enable interrupts */ #ifdef Q_SPY if ((inp(l_uart_base + 5) & (1 << 5)) != 0) { /* THR empty? */ uint16_t fifo = UART_16550_TXFIFO_DEPTH; /* 16550 Tx FIFO depth */ uint8_t const *block; QF_INT_DISABLE(); block = QS_getBlock(&fifo); /* try to get next block to transmit */ QF_INT_ENABLE(); while (fifo-- != 0) { /* any bytes in the block? */ outp(l_uart_base + 0, *block++); } } #endif }
/*..........................................................................*/ void QS_onFlush(void) { for (;;) { uint16_t nBytes = 1024; uint8_t const *block; QF_CRIT_ENTRY(dummy); block = QS_getBlock(&nBytes); QF_CRIT_EXIT(dummy); if (block != (uint8_t const *)0) { QSPY_parse(block, nBytes); nBytes = 1024; } else { break; } } }
/*..........................................................................*/ static DWORD WINAPI idleThread(LPVOID par) {/* signature for CreateThread() */ (void)par; SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_IDLE); l_running = (uint8_t)1; while (l_running) { uint16_t nBytes = 256; uint8_t const *block; QF_CRIT_ENTRY(dummy); block = QS_getBlock(&nBytes); QF_CRIT_EXIT(dummy); if (block != (uint8_t *)0) { QSPY_parse(block, nBytes); } Sleep(10); /* wait for a while */ } return 0; /* return success */ }
/*..........................................................................*/ void QS_onFlush(void) { uint16_t fifo = UART_TXFIFO_DEPTH; /* Tx FIFO depth */ uint8_t const *block; QF_INT_DISABLE(); while ((block = QS_getBlock(&fifo)) != (uint8_t *)0) { QF_INT_ENABLE(); /* busy-wait until TX FIFO empty */ while ((UART0->FR & UART_FR_TXFE) == 0) { } while (fifo-- != 0) { /* any bytes in the block? */ UART0->DR = *block++; /* put into the TX FIFO */ } fifo = UART_TXFIFO_DEPTH; /* re-load the Tx FIFO depth */ QF_INT_DISABLE(); } QF_INT_ENABLE(); }
static int idleThread(void *arg) { complete(&idle_done); while (idle_running) { QF_INT_KEY_TYPE dummy; uint8_t const *block; uint16_t nBytes = QS_SPY_BLOCK; QF_INT_LOCK(dummy); block = QS_getBlock(&nBytes); QF_INT_UNLOCK(dummy); QS_send(block, nBytes); schedule_timeout(HZ); } complete(&idle_done); return 0; }
/*..........................................................................*/ 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 */ }
/*..........................................................................*/ void QV_onIdle(void) { /* called with interrupts disabled, see NOTE01 */ /* toggle the LED on and then off, see NOTE02 */ QF_INT_DISABLE(); LPC_GPIO1->FIOSET = LED_4; /* turn LED on */ __NOP(); /* a couple of NOPs to actually see the LED glow */ __NOP(); __NOP(); __NOP(); LPC_GPIO1->FIOCLR = LED_4; /* turn LED off */ QF_INT_ENABLE(); #ifdef Q_SPY if ((LPC_UART0->LSR & 0x20U) != 0U) { /* TX Holding Register empty? */ uint16_t fifo = UART_TXFIFO_DEPTH; /* max bytes we can accept */ uint8_t const *block; QF_INT_DISABLE(); block = QS_getBlock(&fifo); /* try to get next block to transmit */ QF_INT_ENABLE(); while (fifo-- != 0) { /* any bytes in the block? */ LPC_UART0->THR = *block++; /* put into the FIFO */ } } #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. */ QV_CPU_SLEEP(); /* atomically go to sleep and enable interrupts */ #else QF_INT_ENABLE(); /* just enable interrupts */ #endif }