int nRFUartEvthandler(UARTDEV *pDev, UART_EVT EvtId, uint8_t *pBuffer, int BufferLen) { int cnt = 0; uint8_t buff[20]; switch (EvtId) { case UART_EVT_RXTIMEOUT: case UART_EVT_RXDATA: { /* g_DelayCnt++; if (g_DelayCnt > 20) { g_DelayCnt = 0; cnt = UARTRx(&g_UartDev, buff, 20); if (cnt > 0) UARTTx(&g_UartDev, buff, cnt); }*/ //cnt = UARTRx(&g_UartDev, buff, 1); //if (cnt > 0) // UARTTx(&g_UartDev, buff, cnt); } break; case UART_EVT_TXREADY: break; case UART_EVT_LINESTATE: cnt = UARTRx(&g_UartDev, pBuffer, 6); if (cnt > 0) UARTTx(&g_UartDev, pBuffer, cnt); break; } return cnt; }
int main() { bool res; #ifdef DEMO_C res = UARTInit(&g_UartDev, &g_UartCfg); #else res = g_Uart.Init(g_UartCfg); #endif uint8_t d = 0xff; uint8_t val = 0; uint32_t errcnt = 0; uint32_t cnt = 0; auto t_start = std::chrono::high_resolution_clock::now(); auto t_end = std::chrono::high_resolution_clock::now(); std::chrono::duration<float> elapse = std::chrono::duration<float>(0); t_start = std::chrono::high_resolution_clock::now(); time_t t; double e = 0.0; bool isOK = false; // do { #ifdef DEMO_C while (UARTRx(&g_UartDev, &d, 1) <= 0); #else while (g_Uart.Rx(&d, 1) <= 0); #endif if (val == d) isOK = true; val = Prbs8(d); // } while (!isOK); while(1) { // t_start = std::chrono::high_resolution_clock::now(); t = time(NULL); #ifdef DEMO_C while (UARTRx(&g_UartDev, &d, 1) <= 0); #else while (g_Uart.Rx(&d, 1) <= 0); #endif { e += difftime(time(NULL), t); // t_end = std::chrono::high_resolution_clock::now(); //elapse += std::chrono::duration<float>(t_end-t_start); cnt++; // If success send next code // printf("%x ", d); if (val != d) { errcnt++; // printf("PRBS %u errors %x %x\n", errcnt, val, d); } else if ((cnt & 0x7fff) == 0) { printf("PRBS rate %.3f B/s, err : %u\n", cnt / e, errcnt); // printf("PRBS rate %.3f B/s, err : %u\n", cnt / elapse.count(), errcnt); } val = Prbs8(d); } } return 0; }
int main() { bool res; char *data = "nRF UART Hello World\r\n"; uint8_t buff[20]; /* nrf_gpio_cfg_output(9); while (1) { nrf_gpio_pin_toggle(9); usDelay(1000); }*/ //NRF_MPU->PERR0 &= ~(1 << 2); //uart_init(); //simple_uart_config(UART_RTS_PIN, UART_TX_PIN, UART_CTS_PIN, UART_RX_PIN, false); #ifdef C_CODE res = UARTInit(&g_UartDev, &g_UartCfg); UARTprintf(&g_UartDev, data); #else res = g_Uart.Init(g_UartCfg); g_Uart.printf(data);dfg #endif // nrf_drv_gpiote_in_config_t cts_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(false); // nrf_drv_gpiote_in_init(p_comm_params->cts_pin_no, &cts_config, gpiote_uart_event_handler); //for (int i = 0; i < 20; i++) // simple_uart_put(data[i]); //simple_uart_putstring((const uint8_t*)data); while(1) { uint8_t d; //usDelay(1000); //d = simple_uart_get(); //simple_uart_put(d); #ifndef TEST_INTERRUPT if (UARTRx(&g_UartDev, &d, 1) > 0) { UARTTx(&g_UartDev, &d, 1); // UARTTx(&g_UartDev, (uint8_t*)data, 22); //usDelay(1000); } #else int cnt = UARTRx(&g_UartDev, buff, 20); if (cnt > 0) { uint8_t *p = buff; while (cnt > 0) { int l = UARTTx(&g_UartDev, p, cnt); cnt -= l; p += l; } // UARTTx(&g_UartDev, (uint8_t*)data, 22); //usDelay(1000); } #endif //__WFI(); } return 0; }