radio_tx_burst(): captures current slot, calls fhss_next_channel() to advance the sequence, sets channel, transmits ptt_frame_t, then holds the dwell window via TIMER0 so the receiver has the full 2 ms to listen. radio_rx_burst(): advances to the same channel, enables RX, waits for EVENTS_END or TIMER0 COMPARE0 expiry. On a valid CRC the ptt_frame_t is returned; caller syncs FHSS with fhss_set_slot(frame.slot + 1). TIMER0: configured once in radio_init() (MODE=Timer, BITMODE=16-bit, PRESCALER=4 -> 1 MHz tick, CC[0]=2000 -> 2 ms, COMPARE0_STOP shortcut). fhss.c: replace zero key with a non-trivial 128-bit value; add fhss_set_slot() and fhss_get_slot() for RX synchronisation. power.c: add BUTTON_ACTIVE_LOW flag (default 1 = pull-up + GND button); configure PIN_CNF accordingly; implement power_button_pressed() via NRF_P0->IN. regs.h: add gpio_pin_cnf_t with GPIO_PULL_* constants. main.c: tight PTT loop -- radio_tx_burst() while button held, otherwise radio_rx_burst() with slot sync on reception. No WFI in RX mode.
39 lines
1.0 KiB
C
39 lines
1.0 KiB
C
/**
|
|
* @file fhss.h
|
|
* @brief FHSS channel sequencer based on AES-128-ECB.
|
|
*
|
|
* Both link endpoints derive the same hopping sequence independently from a
|
|
* shared 128-bit key and a monotonically increasing slot counter. No
|
|
* synchronisation traffic is required as long as both sides start from the
|
|
* same slot.
|
|
*/
|
|
#pragma once
|
|
#include <stdint.h>
|
|
|
|
/** Dwell time per channel in milliseconds. */
|
|
#define FHSS_DWELL_MS 2u
|
|
|
|
/** Number of channels in the hopping sequence. */
|
|
#define FHSS_CHANNELS 40u
|
|
|
|
/** @brief Reset the slot counter to zero. */
|
|
void fhss_init(void);
|
|
|
|
/**
|
|
* @brief Return the next channel in the hopping sequence and advance the slot.
|
|
* @return Channel index in [0, 39].
|
|
*/
|
|
uint8_t fhss_next_channel(void);
|
|
|
|
/** @brief Advance the slot counter by one (receiver side, no packet received). */
|
|
void fhss_sync_tick(void);
|
|
|
|
/**
|
|
* @brief Force the slot counter to a specific value for RX synchronisation.
|
|
* @param s New slot value.
|
|
*/
|
|
void fhss_set_slot(uint32_t s);
|
|
|
|
/** @brief Return the current slot counter value. */
|
|
uint32_t fhss_get_slot(void);
|