/**@brief Function for handling timeslots in a context with elevated priority. */ void QDEC_IRQHandler(void) { // This is called here instead of in the uesb_event_handler for two reasons: // 1) Updating the uESB params shouldn't have to lag behind transmissions // 2) m_tx_callback should not be run at RADIO_IRQHandler priority syma_update((uint8_t*)&m_uesb_config.rf_channel, (uint8_t*)&m_uesb_config.rx_address_p0[0], (uint8_t*)&m_uesb_config.rf_addr_length, (uint8_t*)&m_tx_payload.data[0], (uint8_t*)&m_tx_payload.length); m_uesb_config.payload_length = m_tx_payload.length; if (UESB_SUCCESS != uesb_init((uesb_config_t*)&m_uesb_config)) { app_error_handler(PROPRIETARY_RF_DEBUG, __LINE__, (const uint8_t*)__FILE__); } if(UESB_SUCCESS != uesb_write_tx_payload((uesb_payload_t*) &m_tx_payload)) { app_error_handler(PROPRIETARY_RF_DEBUG, __LINE__, (const uint8_t*)__FILE__); } }
/**@brief IRQHandler used for execution context management. * Any available handler can be used as we're not using the associated hardware. * This handler is used to initiate UESB RX/TX */ void TIMESLOT_BEGIN_IRQHandler(void) { uesb_payload_t payload; uint32_t payload_len; uint32_t err_code; uesb_init(&m_uesb_config); // Packet transmission is syncrhonized to the beginning of timeslots // Check FIFO for packets and transmit if not empty if (m_transmit_fifo.free_items < sizeof(m_transmit_fifo.buf) && m_ut_state != UT_STATE_TX) { // There are packets in the FIFO: Start transmitting payload_len = sizeof(payload); // Copy packet from FIFO. Packet isn't removed until transmissions succeeds or max retries has been exceeded if (m_tx_attempts < MAX_TX_ATTEMPTS) { fifo_peek_pkt(&m_transmit_fifo, (uint8_t *) &payload, &payload_len); APP_ERROR_CHECK_BOOL(payload_len == sizeof(payload)); } else { fifo_get_pkt(&m_transmit_fifo, (uint8_t *) &payload, &payload_len); APP_ERROR_CHECK_BOOL(payload_len == sizeof(payload)); m_tx_attempts = 0; } if (m_ut_state == UT_STATE_RX) { uesb_stop_rx(); } err_code = uesb_write_tx_payload(&payload); APP_ERROR_CHECK(err_code); m_ut_state = UT_STATE_TX; } else { // No packets in the FIFO: start reception err_code = uesb_start_rx(); m_ut_state = UT_STATE_RX; } }
/** @brief Function for main application entry. */ int main(void) { TaskHandle_t compress_task_handle; TimerHandle_t spi_timer_handle; uint32_t err_code; err_code = nrf_drv_clock_init(); APP_ERROR_CHECK(err_code); // Setup bsp module. //bsp_configuration(); //uart initialization const app_uart_comm_params_t comm_params = { RX_PIN_NUMBER, TX_PIN_NUMBER, RTS_PIN_NUMBER, CTS_PIN_NUMBER, APP_UART_FLOW_CONTROL_ENABLED, false, UART_BAUDRATE_BAUDRATE_Baud38400 }; APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_error_handle, APP_IRQ_PRIORITY_LOW, err_code); APP_ERROR_CHECK(err_code); //nrf_drv_gpiote_out_config_t config = GPIOTE_CONFIG_OUT_TASK_HIGH; //config.init_state = true; //err_code = nrf_drv_gpiote_out_init(20, &config); //while(app_uart_put(65) != NRF_SUCCESS); //printf("1 ms = %d\n", pdMS_TO_TICKS(1)); intan_setup(); //while(app_uart_put(65) != NRF_SUCCESS); compression_init(); uesb_config_t uesb_config = UESB_DEFAULT_CONFIG; uesb_config.event_handler = uesb_event_handler; if (uesb_init(&uesb_config)!= UESB_SUCCESS) { printf("ESB init messed up\r\n"); } tx_payload.length = UESB_CORE_MAX_PAYLOAD_LENGTH; tx_payload.pipe = 0; while(app_uart_put(66) != NRF_SUCCESS); //printf("yo\n"); UNUSED_VARIABLE(xTaskCreate(compress_task, "c_task", configMINIMAL_STACK_SIZE + 200, NULL, 1, &compress_task_handle)); if(compress_task_handle == NULL) { printf("compression task init messed up\r\n"); } while(app_uart_put(67) != NRF_SUCCESS); //Test read intan company ID timer //spi_timer_handle = xTimerCreate("s_timer", 1, pdTRUE, NULL, spi_intan_id_handler); // Sample timer spi_timer_handle = xTimerCreate("s_timer", 1, pdTRUE, NULL, spi_data_collection_evt_handler); // LED1 timer creation if(spi_timer_handle == NULL) { printf("SPI timer init messed up\r\n"); } while(app_uart_put(68) != NRF_SUCCESS); if(xTimerStart(spi_timer_handle, 0) != pdPASS) { printf("Timer could not be started\r\n"); } while(app_uart_put(69) != NRF_SUCCESS); /* Activate deep sleep mode */ SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; // Start FreeRTOS scheduler. vTaskStartScheduler(); //timers_init(); //while(app_uart_put(67) != NRF_SUCCESS); //data_collection_timers_start(); //while(app_uart_put(68) != NRF_SUCCESS); for (;;) { printf("Messed up\r\n"); //power_manage(); /*if (m_transfer_completed) { //while(app_uart_put(72) != NRF_SUCCESS); m_transfer_completed = false; intan_convert(m_tx_data_spi, m_rx_data_spi,intan_convert_channel); //while(app_uart_put(73) != NRF_SUCCESS); intan_convert_channel ++; intan_convert_channel = intan_convert_channel % 32; //print m_rx_data_spi results switch_state(); //while(app_uart_put(74) != NRF_SUCCESS); //for (int i; i< RX_MSG_LENGTH; i++){ // while(app_uart_put(m_rx_data_spi[i]) != NRF_SUCCESS); //} nrf_delay_ms(DELAY_MS); //while(app_uart_put(75) != NRF_SUCCESS); }*/ //while(app_uart_put(76) != NRF_SUCCESS); } }