ptt-fhss
Bare-metal PTT firmware for nRF52840 with FHSS
Loading...
Searching...
No Matches
Macros | Functions | Variables
radio.c File Reference

RADIO peripheral driver implementation. More...

#include "radio.h"
#include "fhss.h"
#include "regs.h"
#include <nrf52840.h>
#include <string.h>

Macros

#define MAX_PAYLOAD   255u
 
#define BUF_SIZE   (1u + MAX_PAYLOAD)
 
#define DEFAULT_CHANNEL   20u /* 2400 + 20 = 2420 MHz (MAP=0) */
 
#define RADIO_BASE0   0x12345678u
 
#define RADIO_PREFIX0   0xABu /* logical address 0: RADIO_BASE0 + RADIO_PREFIX0[7:0] */
 

Functions

static void timer_init (void)
 
static void dwell_start (void)
 
static void dwell_wait (void)
 
void radio_init (void)
 Configure the RADIO peripheral (mode, packet format, address, CRC, power).
 
void radio_set_channel (uint8_t ch)
 Set the RF channel.
 
void radio_tx (const uint8_t *data, uint8_t len)
 Transmit one packet synchronously.
 
void radio_tx_burst (void)
 Transmit one FHSS hop: advance channel, send PTT frame, hold dwell time.
 
bool radio_rx_burst (ptt_frame_t *frame_out)
 Receive one FHSS hop: advance channel, listen for FHSS_DWELL_MS ms.
 

Variables

static uint8_t pkt_buf [BUF_SIZE]
 

Detailed Description

RADIO peripheral driver implementation.

Macro Definition Documentation

◆ BUF_SIZE

#define BUF_SIZE   (1u + MAX_PAYLOAD)

◆ DEFAULT_CHANNEL

#define DEFAULT_CHANNEL   20u /* 2400 + 20 = 2420 MHz (MAP=0) */

◆ MAX_PAYLOAD

#define MAX_PAYLOAD   255u

◆ RADIO_BASE0

#define RADIO_BASE0   0x12345678u

◆ RADIO_PREFIX0

#define RADIO_PREFIX0   0xABu /* logical address 0: RADIO_BASE0 + RADIO_PREFIX0[7:0] */

Function Documentation

◆ dwell_start()

static void dwell_start ( void  )
static

◆ dwell_wait()

static void dwell_wait ( void  )
static

◆ radio_init()

void radio_init ( void  )

Configure the RADIO peripheral (mode, packet format, address, CRC, power).

◆ radio_rx_burst()

bool radio_rx_burst ( ptt_frame_t frame_out)

Receive one FHSS hop: advance channel, listen for FHSS_DWELL_MS ms.

If a packet with a valid CRC arrives during the dwell window, frame_out is filled and the function returns true. The caller should then call fhss_set_slot(frame_out->slot + 1) to synchronise the hopping sequence.

Parameters
frame_outDestination for the received frame (must not be NULL).
Returns
true if a valid packet was received, false on timeout or CRC error.

◆ radio_set_channel()

void radio_set_channel ( uint8_t  ch)

Set the RF channel.

Parameters
chChannel index 0-39, maps to 2400+ch MHz (MAP=0).

◆ radio_tx()

void radio_tx ( const uint8_t *  data,
uint8_t  len 
)

Transmit one packet synchronously.

Loads data into the internal packet buffer, asserts TASKS_TXEN, and returns after EVENTS_END fires. RADIO is DISABLED automatically via the END_DISABLE shortcut before the function returns.

Parameters
dataPayload bytes.
lenPayload length (0-255 bytes).

◆ radio_tx_burst()

void radio_tx_burst ( void  )

Transmit one FHSS hop: advance channel, send PTT frame, hold dwell time.

Call repeatedly in a loop while the PTT button is held. Each call occupies exactly FHSS_DWELL_MS milliseconds.

◆ timer_init()

static void timer_init ( void  )
static

Variable Documentation

◆ pkt_buf

uint8_t pkt_buf[BUF_SIZE]
static