ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
cc1101.h
Go to the documentation of this file.
1// ProtoCore v1.0.16 - Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4#ifndef PROTOCORE_CC1101_H
5#define PROTOCORE_CC1101_H
6
7#include "protocore_config.h" // the entry point: protocore_types.h for the widths
8
10
11/**
12 * @file cc1101.h
13 * @brief CC1101 sub-GHz radio driver (PROTOCORE_ENABLE_CC1101) - TI 300-928 MHz over SPI.
14 *
15 * A radio driver plugin for the gateway (PROTOCORE_ENABLE_GATEWAY): generic ISM-band remotes and sensors
16 * (OOK / 2-FSK on 315/433/868/915 MHz) bridged to the web stack. Like the nRF24, the CC1101 speaks an
17 * **SPI header protocol** - every transaction begins with a header byte (bit7 = read, bit6 = burst,
18 * bits5-0 = address) and returns the **chip status byte** (CHIP_RDYn, the 3-bit state machine value, and
19 * the FIFO-bytes-available count). Config registers live at 0x00-0x2E, the 13 command **strobes** at
20 * 0x30-0x3D (a single write triggers the command), the read-only **status** registers at 0x30-0x3D read
21 * with the burst bit set, and both FIFOs at 0x3F.
22 *
23 * The huge modem configuration (band, data rate, deviation, sync word) is board/tool-specific, so the
24 * caller supplies it as a register table (a TI SmartRF Studio export); the driver resets the chip, writes
25 * that table, sets the channel, and verifies the VERSION status register talks back. Packets use variable
26 * length mode (a leading length byte) with appended RSSI/LQI status. Bridge received payloads northbound
27 * with protocore_gateway_uplink. The register/strobe/FIFO protocol is host-testable against a mock; the RF link
28 * needs the module.
29 *
30 * @c work is bytes the CALLER holds. This module reads none of them: it carries nothing
31 * between calls, so there is no state to keep and nothing to wipe. The parameter is there so
32 * a caller drives every namespace the same way.
33 */
34
35// PROTOCORE_CC1101_BORROW - the bytes this module runs out of - is stated in protocore_config.h, which sums
36// it into its arena. Its size and its offset are each a static_assert, so a feature
37// combination that does not fit fails to compile rather than overrunning at run time.
38
39/** @brief Full-duplex SPI transfer of @p len bytes (chip-select toggled by the callback). */
40typedef void (*protocore_cc1101_spi_fn)(const uint8_t *tx, uint8_t *rx, uint8_t len, void *ctx);
41
42/** @brief The bus a driver call uses: your SPI transfer behind it. */
48
49/** @brief One modem-config register write (address + value). */
50typedef struct
51{
52 uint8_t addr;
53 uint8_t value;
55
56/** @brief Radio configuration applied by protocore_cc1101_init(). */
57typedef struct
58{
59 const protocore_cc1101_reg *regs; ///< SmartRF-exported register settings (may be null for none).
60 size_t nregs;
61 uint8_t channel; ///< CHANNR (0x0A): channel number on top of the base frequency.
63
64/** @brief Dispatch table. Addressed by offset, so the layout is asserted below. */
65typedef struct
66{
67 proto_bool (*init)(uint8_t *, const protocore_cc1101_bus *, const protocore_cc1101_config *);
68 proto_bool (*send)(uint8_t *, const protocore_cc1101_bus *, const uint8_t *, uint8_t);
69 proto_bool (*tx_done)(uint8_t *, const protocore_cc1101_bus *);
70 void (*set_rx)(uint8_t *, const protocore_cc1101_bus *);
71 int (*recv)(uint8_t *, const protocore_cc1101_bus *, uint8_t *, uint8_t, int16_t *);
72 int16_t (*rssi_dbm)(uint8_t *, uint8_t);
73} Cc1101Ns;
74PROTOCORE_NS_LAYOUT(Cc1101Ns, init, send, tx_done, set_rx, recv, rssi_dbm);
75
76/**
77 * @brief Reset the CC1101, apply cfg, set the channel, and confirm it is .
78 * @param work PROTOCORE_CC1101_BORROW bytes the caller took. Not held past the call.
79 * @param bus Bus
80 * @param cfg Cfg
81 * @return PROTO_TRUE on success.
82 */
84/**
85 * @brief Transmit len bytes as a variable-length packet (leading length .
86 * @param work PROTOCORE_CC1101_BORROW bytes the caller took. Not held past the call.
87 * @param bus Bus
88 * @param data Data
89 * @param len Len
90 * @return PROTO_TRUE on success.
91 */
92proto_bool protocore_cc1101_send(uint8_t *work, const protocore_cc1101_bus *bus, const uint8_t *data, uint8_t len);
93/**
94 * @brief True once the state machine has returned to IDLE after a transmit.
95 * @param work PROTOCORE_CC1101_BORROW bytes the caller took. Not held past the call.
96 * @param bus Bus
97 * @return PROTO_TRUE on success.
98 */
100/**
101 * @brief Flush RX and enter receive mode (strobe RX). Then poll .
102 * @param work PROTOCORE_CC1101_BORROW bytes the caller took. Not held past the call.
103 * @param bus Bus
104 */
105void protocore_cc1101_set_rx(uint8_t *work, const protocore_cc1101_bus *bus);
106/**
107 * @brief If a packet is waiting, read it (length byte + payload + appended .
108 * @param work PROTOCORE_CC1101_BORROW bytes the caller took. Not held past the call.
109 * @param bus Bus
110 * @param buf Buf
111 * @param cap Cap
112 * @param rssi_dbm Rssi dbm
113 * @return The int.
114 */
115int protocore_cc1101_recv(uint8_t *work, const protocore_cc1101_bus *bus, uint8_t *buf, uint8_t cap, int16_t *rssi_dbm);
116/**
117 * @brief Convert a raw CC1101 RSSI register value to dBm (TI datasheet .
118 * @param work PROTOCORE_CC1101_BORROW bytes the caller took. Not held past the call.
119 * @param raw Raw
120 * @return The int16_t.
121 */
122int16_t protocore_cc1101_rssi_dbm(uint8_t *work, uint8_t raw);
123
124/** @brief Full-duplex SPI transfer of @p len bytes (chip-select toggled by the callback). */
125typedef void (*protocore_cc1101_spi_fn)(const uint8_t *tx, uint8_t *rx, uint8_t len, void *ctx);
126
127/** @brief Module namespace. */
134
136
137#endif // PROTOCORE_CC1101_H
int16_t protocore_cc1101_rssi_dbm(uint8_t *work, uint8_t raw)
Convert a raw CC1101 RSSI register value to dBm (TI datasheet .
void protocore_cc1101_set_rx(uint8_t *work, const protocore_cc1101_bus *bus)
Flush RX and enter receive mode (strobe RX). Then poll .
proto_bool protocore_cc1101_tx_done(uint8_t *work, const protocore_cc1101_bus *bus)
True once the state machine has returned to IDLE after a transmit.
proto_bool protocore_cc1101_init(uint8_t *work, const protocore_cc1101_bus *bus, const protocore_cc1101_config *cfg)
Reset the CC1101, apply cfg, set the channel, and confirm it is .
proto_bool protocore_cc1101_send(uint8_t *work, const protocore_cc1101_bus *bus, const uint8_t *data, uint8_t len)
Transmit len bytes as a variable-length packet (leading length .
int protocore_cc1101_recv(uint8_t *work, const protocore_cc1101_bus *bus, uint8_t *buf, uint8_t cap, int16_t *rssi_dbm)
If a packet is waiting, read it (length byte + payload + appended .
void(* protocore_cc1101_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).
Definition cc1101.h:40
PROTOCORE_NS Cc1101Ns Cc1101 PROTOCORE_UNUSED
Module namespace.
Definition cc1101.h:128
#define PROTOCORE_NS_LAYOUT(T,...)
Pin every dispatch slot of a table that is nothing but function pointers.
#define PROTOCORE_NS
Storage for a dispatch table. The const is load bearing.
Dispatch table. Addressed by offset, so the layout is asserted below.
Definition cc1101.h:66
proto_bool(* init)(uint8_t *, const protocore_cc1101_bus *, const protocore_cc1101_config *)
Definition cc1101.h:67
The bus a driver call uses: your SPI transfer behind it.
Definition cc1101.h:44
protocore_cc1101_spi_fn spi
Definition cc1101.h:45
Radio configuration applied by protocore_cc1101_init().
Definition cc1101.h:58
const protocore_cc1101_reg * regs
SmartRF-exported register settings (may be null for none).
Definition cc1101.h:59
uint8_t channel
CHANNR (0x0A): channel number on top of the base frequency.
Definition cc1101.h:61
One modem-config register write (address + value).
Definition cc1101.h:51
#define PROTOCORE_BEGIN_DECLS
Give a header's declarations C linkage, so their symbol names carry no parameter types.
Definition types.h:96
_Bool proto_bool
The truth value.
Definition types.h:64
#define PROTOCORE_END_DECLS
Definition types.h:97