|
ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
|
nRF24L01+ radio driver (PROTOCORE_ENABLE_NRF24) - Nordic 2.4 GHz over SPI. More...
#include "protocore_config.h"Go to the source code of this file.
Classes | |
| struct | nrf_bus |
| The bus a driver call uses: your SPI transfer + CE control behind it. More... | |
| struct | nrf_config |
| Radio configuration applied by protocore_nrf24_init(). More... | |
| struct | Nrf24Ns |
| Dispatch table. Addressed by offset, so the layout is asserted below. More... | |
Typedefs | |
| typedef void(* | nrf_spi_fn) (const uint8_t *tx, uint8_t *rx, uint8_t len, void *ctx) |
Full-duplex SPI transfer of len bytes (chip-select toggled by the callback). | |
| typedef void(* | nrf_ce_fn) (proto_bool level, void *ctx) |
| Drive the CE pin (true = high). | |
Functions | |
| PROTOCORE_NS_LAYOUT (Nrf24Ns, init, send, tx_done, set_rx, recv) | |
| proto_bool | protocore_nrf24_init (uint8_t *work, const nrf_bus *bus, const nrf_config *cfg) |
| Configure the nRF24L01+ and power it up (standby). | |
| proto_bool | protocore_nrf24_send (uint8_t *work, const nrf_bus *bus, const uint8_t *data, uint8_t len) |
| Transmit len bytes (zero-padded to PROTOCORE_NRF24_PAYLOAD). Poll . | |
| proto_bool | protocore_nrf24_tx_done (uint8_t *work, const nrf_bus *bus) |
| True once a transmit has finished (STATUS TX_DS); clears the flag. | |
| void | protocore_nrf24_set_rx (uint8_t *work, const nrf_bus *bus) |
| Enter receive mode (PRX + CE high); then poll protocore_nrf24_recv(). | |
| int | protocore_nrf24_recv (uint8_t *work, const nrf_bus *bus, uint8_t *buf, uint8_t cap, uint8_t *pipe) |
| If a frame is waiting, copy it into buf and report the pipe it . | |
Variables | |
| PROTOCORE_NS Nrf24Ns Nrf24 | PROTOCORE_UNUSED |
| Module namespace. | |
nRF24L01+ radio driver (PROTOCORE_ENABLE_NRF24) - Nordic 2.4 GHz over SPI.
A radio driver plugin for the gateway (PROTOCORE_ENABLE_GATEWAY): cheap point-to-multipoint 2.4 GHz sensor links bridged to the web stack. Unlike the SX127x (plain register read/write), the nRF24L01+ speaks an SPI command protocol (each transaction is a command byte + data, and every command returns the STATUS register) and needs a separate CE pin to key RX/TX - so the driver runs over an nrf_bus that carries a full-duplex SPI transfer plus a CE-set callback. That is the only board-specific code.
The nRF24 does its own hardware addressing (5-byte pipe addresses), so a received frame's "source" is the pipe number it arrived on - there is no in-payload header and therefore no separate codec. It uses a static payload width (PROTOCORE_NRF24_PAYLOAD): every frame is that many bytes (a short send is zero-padded). Bridge received payloads northbound with protocore_gateway_uplink(port, pipe, payload, width, 0). The register/command protocol is host-testable against a mock; the RF link needs the module.
work is bytes the CALLER holds. This module reads none of them: it carries nothing between calls, so there is no state to keep and nothing to wipe. The parameter is there so a caller drives every namespace the same way.
Definition in file nrf24.h.
| typedef void(* nrf_spi_fn)(const uint8_t *tx, uint8_t *rx, uint8_t len, void *ctx) |
| typedef void(* nrf_ce_fn) (proto_bool level, void *ctx) |
| PROTOCORE_NS_LAYOUT | ( | Nrf24Ns | , |
| init | , | ||
| send | , | ||
| tx_done | , | ||
| set_rx | , | ||
| recv | |||
| ) |
| proto_bool protocore_nrf24_init | ( | uint8_t * | work, |
| const nrf_bus * | bus, | ||
| const nrf_config * | cfg | ||
| ) |
Configure the nRF24L01+ and power it up (standby).
| work | PROTOCORE_NRF24_BORROW bytes the caller took. Not held past the call. |
| bus | Bus |
| cfg | Cfg |
| proto_bool protocore_nrf24_send | ( | uint8_t * | work, |
| const nrf_bus * | bus, | ||
| const uint8_t * | data, | ||
| uint8_t | len | ||
| ) |
Transmit len bytes (zero-padded to PROTOCORE_NRF24_PAYLOAD). Poll .
| work | PROTOCORE_NRF24_BORROW bytes the caller took. Not held past the call. |
| bus | Bus |
| data | Data |
| len | Len |
| proto_bool protocore_nrf24_tx_done | ( | uint8_t * | work, |
| const nrf_bus * | bus | ||
| ) |
True once a transmit has finished (STATUS TX_DS); clears the flag.
| work | PROTOCORE_NRF24_BORROW bytes the caller took. Not held past the call. |
| bus | Bus |
| void protocore_nrf24_set_rx | ( | uint8_t * | work, |
| const nrf_bus * | bus | ||
| ) |
Enter receive mode (PRX + CE high); then poll protocore_nrf24_recv().
| work | PROTOCORE_NRF24_BORROW bytes the caller took. Not held past the call. |
| bus | Bus |
| int protocore_nrf24_recv | ( | uint8_t * | work, |
| const nrf_bus * | bus, | ||
| uint8_t * | buf, | ||
| uint8_t | cap, | ||
| uint8_t * | pipe | ||
| ) |
If a frame is waiting, copy it into buf and report the pipe it .
| work | PROTOCORE_NRF24_BORROW bytes the caller took. Not held past the call. |
| bus | Bus |
| buf | Buf |
| cap | Cap |
| pipe | Pipe |
| PROTOCORE_NS Nrf24Ns Nrf24 PROTOCORE_UNUSED |
Module namespace.