void radio_end_listen(void) { /* Stop the radio task */ radio_shutdown(0); _debug_printf("XCVR should shutdown%s", ""); }
void test_main(void) { radio_shutdown(); // put radio into shutdown to avoid damage when writing to radio output pins // testing dec_to_str char test_buf[10]; const uint32_t a = 1023; udec_to_str(test_buf, 9, a); const int32_t b = -1023; dec_to_str(test_buf, 9, b); // setup uart uart_init(); // setup packet handler ph_setup(); test_ph_setup(); // start packet receiving ph_start(); while (1) { // testing packet handler _delay_cycles(10000000); test_packet_handler(test_message_0); _delay_cycles(10000000); test_packet_handler(test_message_1); _delay_cycles(10000000); test_packet_handler(test_message_2); } }
void radio_start_listen(volatile radio_packet_t * data, uint8_t is_manufacturing_mode) { if (!data) { _debug_printf("NULL data pointer%s", ""); return; } /* Set up the radio */ radio_init(); /* Set the pipe to some value that could never happen */ data->pipe = RADIO_PIPE_NONE; /* Turn off the RADIO Task */ radio_shutdown(0); /* Set the packet source pointer */ RadioPtr->PACKETPTR = (uint32_t)data->payload; /* Set up the RADIO parameters */ RadioPtr->PCNF1 = /* Disable data whitening agent */ (RADIO_PCNF1_WHITEEN_Disabled << RADIO_PCNF1_WHITEEN_Pos) | /* Set endianness to BIG */ (RADIO_PCNF1_ENDIAN_Big << RADIO_PCNF1_ENDIAN_Pos) | /* Set 'base' address length */ ((ADDRESS_LENGTH - 1) << RADIO_PCNF1_BALEN_Pos) | /* Set expected packet length */ (data->payloadLength << RADIO_PCNF1_STATLEN_Pos) | /* Set the maximum length to the actual max packet size */ (MAX_PACKET_SIZE << RADIO_PCNF1_MAXLEN_Pos); /* Set the listen addresses */ if (is_manufacturing_mode) { RadioPtr->PREFIX0 = radio_convert_byte('S') << 24 | /* 4. Manufacture secrets */ radio_convert_byte('M') << 16; /* 3. Manufacture uuid? */ RadioPtr->RXADDRESSES = 0x0C; } else { RadioPtr->PREFIX0 = radio_convert_byte('R') << 8 | radio_convert_byte('K'); RadioPtr->RXADDRESSES = 0x03; } /* Set address bases */ RadioPtr->BASE0 = radio_convert_bytes("KIWI"); /* Beacon pipe */ RadioPtr->BASE1 = radio_convert_bytes("RNKI"); /* Random pipe */ /* Clear the event ready task flag */ RadioPtr->EVENTS_READY = 0U; /* Tell the radio that the task is now receiving */ RadioPtr->TASKS_RXEN = 1U; /* Wait for radio to ramp up */ wait_for_val_ne(&RadioPtr->EVENTS_READY); _debug_printf("XCVR Turned on in RX mode%s", ""); }
/* * Transmit a packet * * to the specified address * * the specified number of times * * and wait a certain amount of microseconds between each packet. */ void radio_send_packet(volatile radio_packet_t * data, char * address, uint8_t count, uint8_t us_wait_after) { if (!count || !data || !address) { return; } /* Turn off the RADIO Task */ RadioPtr->TASKS_DISABLE = 1U; /* Block until the radio is off */ wait_for_val_ne(&RadioPtr->EVENTS_DISABLED); /* Set the packet source pointer */ RadioPtr->PACKETPTR = (uint32_t)data->payload; /* Set up the RADIO parameters */ RadioPtr->PCNF1 = /* Disable data whitening agent */ (RADIO_PCNF1_WHITEEN_Disabled << RADIO_PCNF1_WHITEEN_Pos) | /* Set endianness to BIG */ (RADIO_PCNF1_ENDIAN_Big << RADIO_PCNF1_ENDIAN_Pos) | /* Set 'base' address length */ ((ADDRESS_LENGTH - 1) << RADIO_PCNF1_BALEN_Pos) | /* Set packet length */ ((data->payloadLength) << RADIO_PCNF1_STATLEN_Pos) | /* Set the maximum length to zero (ignore) */ (MAX_PACKET_SIZE << RADIO_PCNF1_MAXLEN_Pos); /* Clear the SHORTS register */ RadioPtr->SHORTS = 0b00000000; /* Calculate the proper addresses */ RadioPtr->PREFIX0 = (uint32_t)radio_convert_byte(address[0]); RadioPtr->BASE0 = radio_convert_bytes(address); _debug_printf("Sending packet to address %s 0x%02x%08x", address, RadioPtr->PREFIX0, RadioPtr->BASE0); /* Tell the RADIO to use the above address */ RadioPtr->TXADDRESS = 0; /* Clear event ready */ RadioPtr->EVENTS_READY = 0U; /* Enable the TX Task */ RadioPtr->TASKS_TXEN = 1U; /* Block until Radio is powered up */ wait_for_val_ne(&RadioPtr->EVENTS_READY); while (count--) { /* Clear event flag */ RadioPtr->EVENTS_END = 0U; /* Start the task */ RadioPtr->TASKS_START = 1U; /* Reset the hold-down timer */ uint8_t hold_down_timer = 255; /* Block until sent */ while (!RadioPtr->EVENTS_END && hold_down_timer--); /* Wait the packet spacing */ nrf_delay_us(us_wait_after); } /* Stop Radio Task */ radio_shutdown(0); }