void HardwareInit() { g_Uart.Init(g_UartCfg); IOPinCfg(s_LedPins, s_NbLedPins); IOPinSet(BLUEIO_LED_BLUE_PORT, BLUEIO_LED_BLUE_PIN); IOPinSet(BLUEIO_LED_GREEN_PORT, BLUEIO_LED_GREEN_PIN); IOPinSet(BLUEIO_LED_RED_PORT, BLUEIO_LED_RED_PIN); IOPinCfg(s_ButPins, s_NbButPins); IOPinEnableInterrupt(0, APP_IRQ_PRIORITY_LOW, s_ButPins[0].PortNo, s_ButPins[0].PinNo, IOPINSENSE_LOW_TRANSITION, ButEvent); }
int main() { g_Uart.Init(s_UartCfg); // Retarget printf to UART UARTRetargetEnable(g_Uart, STDOUT_FILENO); UARTRetargetEnable(g_Uart, STDIN_FILENO); printf("Flash Memory Demo\r\n"); getchar(); g_Spi.Init(s_SpiCfg); IOPinConfig(FLASH_HOLD_PORT, FLASH_HOLD_PIN, FLASH_HOLD_PINOP, IOPINDIR_OUTPUT, IOPINRES_PULLUP, IOPINTYPE_NORMAL); g_FlashDiskIO.Init(s_FlashDiskCfg, &g_Spi, &g_FlashCache, 1); uint8_t buff[512]; uint8_t tmp[512]; uint16_t *p = (uint16_t*)buff; memset(tmp, 0, 512); for (int i = 0; i < 256; i++) { p[i] = i; } printf("Erasing... Please wait\r\n"); // Ease could take a few minutes g_FlashDiskIO.Erase(); printf("Writing 2KB data...\r\n"); g_FlashDiskIO.SectWrite(0, buff); g_FlashDiskIO.SectWrite(2, buff); g_FlashDiskIO.SectWrite(4, buff); g_FlashDiskIO.SectWrite(8, buff); printf("Validate readback...\r\n"); g_FlashDiskIO.SectRead(0, tmp); if (memcmp(buff, tmp, 512) != 0) { printf("Sector 0 verify failed\r\n"); } else { printf("Sector 0 verify success\r\n"); } memset(tmp, 0, 512); g_FlashDiskIO.SectRead(2, tmp); if (memcmp(buff, tmp, 512) != 0) { printf("Sector 2 verify failed\r\n"); } else { printf("Sector 2 verify success\r\n"); } memset(tmp, 0, 512); g_FlashDiskIO.SectRead(4, tmp); if (memcmp(buff, tmp, 512) != 0) { printf("Sector 4 verify failed\r\n"); } else { printf("Sector 4 verify success\r\n"); } memset(tmp, 0, 512); g_FlashDiskIO.SectRead(8, tmp); if (memcmp(buff, tmp, 512) != 0) { printf("Sector 8 verify failed\r\n"); } else { printf("Sector 8 verify success\r\n"); } }
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; }