Skip to content

Commit

Permalink
TDMA: bsp/radio. scope global define
Browse files Browse the repository at this point in the history
  • Loading branch information
SaidAlvarado committed Sep 19, 2024
1 parent 9294054 commit da99b7c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions bsp/nrf/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
typedef struct __attribute__((packed)) {
uint8_t header; ///< PDU header (depends on the type of PDU - advertising physical channel or Data physical channel)
uint8_t length; ///< Length of the payload + MIC (if any)
uint8_t payload[PAYLOAD_MAX_LENGTH]; ///< Payload + MIC (if any)
uint8_t payload[DB_RADIO_PAYLOAD_MAX_LENGTH]; ///< Payload + MIC (if any)
} ble_radio_pdu_t;

typedef struct {
Expand Down Expand Up @@ -115,7 +115,7 @@ void db_radio_init(radio_cb_t callback, db_radio_ble_mode_t mode) {
(RADIO_PCNF0_PLEN_8bit << RADIO_PCNF0_PLEN_Pos); // PREAMBLE length is 1 byte in BLE 1Mbit/s and 2Mbit/s

NRF_RADIO->PCNF1 = (4UL << RADIO_PCNF1_BALEN_Pos) | // The base address is 4 Bytes long
(PAYLOAD_MAX_LENGTH << RADIO_PCNF1_MAXLEN_Pos) |
(DB_RADIO_PAYLOAD_MAX_LENGTH << RADIO_PCNF1_MAXLEN_Pos) |
(0 << RADIO_PCNF1_STATLEN_Pos) |
(RADIO_PCNF1_ENDIAN_Little << RADIO_PCNF1_ENDIAN_Pos) | // Make the on air packet be little endian (this enables some useful features)
(RADIO_PCNF1_WHITEEN_Enabled << RADIO_PCNF1_WHITEEN_Pos); // Enable data whitening feature.
Expand All @@ -138,7 +138,7 @@ void db_radio_init(radio_cb_t callback, db_radio_ble_mode_t mode) {
(RADIO_PCNF1_ENDIAN_Little << RADIO_PCNF1_ENDIAN_Pos) |
(3 << RADIO_PCNF1_BALEN_Pos) |
(0 << RADIO_PCNF1_STATLEN_Pos) |
(PAYLOAD_MAX_LENGTH << RADIO_PCNF1_MAXLEN_Pos);
(DB_RADIO_PAYLOAD_MAX_LENGTH << RADIO_PCNF1_MAXLEN_Pos);
}

// Configuring the on-air radio address.
Expand Down
2 changes: 1 addition & 1 deletion bsp/radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#define DEFAULT_NETWORK_ADDRESS 0x12345678UL ///< Default network address
#endif

#define PAYLOAD_MAX_LENGTH UINT8_MAX
#define DB_RADIO_PAYLOAD_MAX_LENGTH UINT8_MAX

/// BLE modes supported by the radio
typedef enum {
Expand Down
16 changes: 8 additions & 8 deletions drv/tdma_client/tdma_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#define TDMA_CLIENT_TIMER_HF 2

typedef struct {
uint8_t buffer[TDMA_CLIENT_RING_BUFFER_SIZE][PAYLOAD_MAX_LENGTH]; ///< arrays of radio messages waiting to be sent
uint8_t buffer[TDMA_CLIENT_RING_BUFFER_SIZE][DB_RADIO_PAYLOAD_MAX_LENGTH]; ///< arrays of radio messages waiting to be sent
uint32_t packet_length[TDMA_CLIENT_RING_BUFFER_SIZE]; ///< arrays of the lenght of the packets in the buffer
uint8_t writeIndex; ///< Index for next write
uint8_t readIndex; ///< Index for next read
Expand Down Expand Up @@ -108,7 +108,7 @@ static void _message_rb_init(tdma_client_ring_buffer_t *rb);
* @param[in] data pointer to the data array to save in the ring buffer
* @param[in] packet_length length of the packet to send trough the radio
*/
static void _message_rb_add(tdma_client_ring_buffer_t *rb, uint8_t data[PAYLOAD_MAX_LENGTH], uint8_t packet_length);
static void _message_rb_add(tdma_client_ring_buffer_t *rb, uint8_t data[DB_RADIO_PAYLOAD_MAX_LENGTH], uint8_t packet_length);

/**
* @brief retreive the oldest element from the ring buffer for tdma captures
Expand All @@ -117,7 +117,7 @@ static void _message_rb_add(tdma_client_ring_buffer_t *rb, uint8_t data[PAYLOAD_
* @param[out] data pointer to the array where the ring buffer data will be saved
* @param[out] packet_length length of the packet to send trough the radio
*/
static bool _message_rb_get(tdma_client_ring_buffer_t *rb, uint8_t data[PAYLOAD_MAX_LENGTH], uint8_t *packet_length);
static bool _message_rb_get(tdma_client_ring_buffer_t *rb, uint8_t data[DB_RADIO_PAYLOAD_MAX_LENGTH], uint8_t *packet_length);

/**
* @brief Sends all the queued messages that can be sent in during the TX timeslot
Expand Down Expand Up @@ -246,9 +246,9 @@ static void _message_rb_init(tdma_client_ring_buffer_t *rb) {
rb->count = 0;
}

static void _message_rb_add(tdma_client_ring_buffer_t *rb, uint8_t data[PAYLOAD_MAX_LENGTH], uint8_t packet_length) {
static void _message_rb_add(tdma_client_ring_buffer_t *rb, uint8_t data[DB_RADIO_PAYLOAD_MAX_LENGTH], uint8_t packet_length) {

memcpy(rb->buffer[rb->writeIndex], data, PAYLOAD_MAX_LENGTH);
memcpy(rb->buffer[rb->writeIndex], data, DB_RADIO_PAYLOAD_MAX_LENGTH);
rb->packet_length[rb->writeIndex] = packet_length;
rb->writeIndex = (rb->writeIndex + 1) % TDMA_CLIENT_RING_BUFFER_SIZE;

Expand All @@ -260,13 +260,13 @@ static void _message_rb_add(tdma_client_ring_buffer_t *rb, uint8_t data[PAYLOAD_
}
}

static bool _message_rb_get(tdma_client_ring_buffer_t *rb, uint8_t data[PAYLOAD_MAX_LENGTH], uint8_t *packet_length) {
static bool _message_rb_get(tdma_client_ring_buffer_t *rb, uint8_t data[DB_RADIO_PAYLOAD_MAX_LENGTH], uint8_t *packet_length) {
if (rb->count <= 0) {
// Buffer is empty
return false;
}

memcpy(data, rb->buffer[rb->readIndex], PAYLOAD_MAX_LENGTH);
memcpy(data, rb->buffer[rb->readIndex], DB_RADIO_PAYLOAD_MAX_LENGTH);
*packet_length = rb->packet_length[rb->readIndex];
rb->readIndex = (rb->readIndex + 1) % TDMA_CLIENT_RING_BUFFER_SIZE;
rb->count--;
Expand All @@ -279,7 +279,7 @@ static bool _message_rb_tx_queue(uint16_t max_tx_duration_us) {
// initialize variables
uint32_t start_tx_slot = db_timer_hf_now(TDMA_CLIENT_TIMER_HF);
uint8_t length = 0;
uint8_t packet[PAYLOAD_MAX_LENGTH];
uint8_t packet[DB_RADIO_PAYLOAD_MAX_LENGTH];
bool packet_sent_flag = false; ///< flag to keep track if a packet get sent during this function call

// check if there is something to send
Expand Down
16 changes: 8 additions & 8 deletions drv/tdma_server/tdma_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#define TDMA_SERVER_TIMER_HF 2

typedef struct {
uint8_t buffer[TDMA_RING_BUFFER_SIZE][PAYLOAD_MAX_LENGTH]; ///< arrays of radio messages waiting to be sent
uint8_t buffer[TDMA_RING_BUFFER_SIZE][DB_RADIO_PAYLOAD_MAX_LENGTH]; ///< arrays of radio messages waiting to be sent
uint32_t packet_length[TDMA_RING_BUFFER_SIZE]; ///< arrays of the lenght of the packets in the buffer
uint8_t writeIndex; ///< Index for next write
uint8_t readIndex; ///< Index for next read
Expand Down Expand Up @@ -111,7 +111,7 @@ static void _message_rb_init(tdma_ring_buffer_t *rb);
* @param[in] data pointer to the data array to save in the ring buffer
* @param[in] packet_length length of the packet to send trough the radio
*/
static void _message_rb_add(tdma_ring_buffer_t *rb, uint8_t data[PAYLOAD_MAX_LENGTH], uint8_t packet_length);
static void _message_rb_add(tdma_ring_buffer_t *rb, uint8_t data[DB_RADIO_PAYLOAD_MAX_LENGTH], uint8_t packet_length);

/**
* @brief retreive the oldest element from the ring buffer for tdma captures
Expand All @@ -120,7 +120,7 @@ static void _message_rb_add(tdma_ring_buffer_t *rb, uint8_t data[PAYLOAD_MAX_LEN
* @param[out] data pointer to the array where the ring buffer data will be saved
* @param[out] packet_length length of the packet to send trough the radio
*/
static bool _message_rb_get(tdma_ring_buffer_t *rb, uint8_t data[PAYLOAD_MAX_LENGTH], uint8_t *packet_length);
static bool _message_rb_get(tdma_ring_buffer_t *rb, uint8_t data[DB_RADIO_PAYLOAD_MAX_LENGTH], uint8_t *packet_length);

/**
* @brief Sends all the queued messages that can be sent in during the TX timeslot
Expand Down Expand Up @@ -286,9 +286,9 @@ static void _message_rb_init(tdma_ring_buffer_t *rb) {
rb->count = 0;
}

static void _message_rb_add(tdma_ring_buffer_t *rb, uint8_t data[PAYLOAD_MAX_LENGTH], uint8_t packet_length) {
static void _message_rb_add(tdma_ring_buffer_t *rb, uint8_t data[DB_RADIO_PAYLOAD_MAX_LENGTH], uint8_t packet_length) {

memcpy(rb->buffer[rb->writeIndex], data, PAYLOAD_MAX_LENGTH);
memcpy(rb->buffer[rb->writeIndex], data, DB_RADIO_PAYLOAD_MAX_LENGTH);
rb->packet_length[rb->writeIndex] = packet_length;
rb->writeIndex = (rb->writeIndex + 1) % TDMA_RING_BUFFER_SIZE;

Expand All @@ -300,13 +300,13 @@ static void _message_rb_add(tdma_ring_buffer_t *rb, uint8_t data[PAYLOAD_MAX_LEN
}
}

static bool _message_rb_get(tdma_ring_buffer_t *rb, uint8_t data[PAYLOAD_MAX_LENGTH], uint8_t *packet_length) {
static bool _message_rb_get(tdma_ring_buffer_t *rb, uint8_t data[DB_RADIO_PAYLOAD_MAX_LENGTH], uint8_t *packet_length) {
if (rb->count <= 0) {
// Buffer is empty
return false;
}

memcpy(data, rb->buffer[rb->readIndex], PAYLOAD_MAX_LENGTH);
memcpy(data, rb->buffer[rb->readIndex], DB_RADIO_PAYLOAD_MAX_LENGTH);
*packet_length = rb->packet_length[rb->readIndex];
rb->readIndex = (rb->readIndex + 1) % TDMA_RING_BUFFER_SIZE;
rb->count--;
Expand All @@ -318,7 +318,7 @@ static bool _message_rb_tx_queue(tdma_ring_buffer_t *rb, uint16_t max_tx_duratio

// initialize variables
uint8_t length = 0;
uint8_t packet[PAYLOAD_MAX_LENGTH];
uint8_t packet[DB_RADIO_PAYLOAD_MAX_LENGTH];
bool packet_sent_flag = false; ///< flag to keep track if a packet get sent during this function call

// check if there is something to send
Expand Down

0 comments on commit da99b7c

Please sign in to comment.