summaryrefslogtreecommitdiffstats
path: root/rf_test
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2024-12-08 08:49:25 +0800
committerSadeep Madurange <sadeep@asciimx.com>2024-12-08 08:49:25 +0800
commit831d421e5bc9c6949cb97395acf909f1983c270c (patch)
tree40fa93fd49ab74713c16f899c555854c638461c6 /rf_test
parent65308e3d3ab191f601557a51dd4eec01ff8bf5b8 (diff)
downloadsmart-home-831d421e5bc9c6949cb97395acf909f1983c270c.tar.gz
wip: sendto.
Diffstat (limited to 'rf_test')
-rw-r--r--rf_test/radio.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/rf_test/radio.c b/rf_test/radio.c
index 4b5cfbf..a2dea45 100644
--- a/rf_test/radio.c
+++ b/rf_test/radio.c
@@ -41,6 +41,8 @@
#define MAX_POWER_LEVEL 23
+static uint8_t payload_len = 0;
+
static inline uint8_t read_reg(uint8_t reg)
{
SPI_PORT &= ~(1 << SPI_SS);
@@ -67,6 +69,11 @@ static inline void write_reg(uint8_t reg, uint8_t val)
SPI_PORT |= (1 << SPI_SS);
}
+static inline uint8_t rssi(void)
+{
+ return (-1 * (read_reg(0x24) >> 1));
+}
+
static inline void set_power_level(uint8_t pwl)
{
uint8_t pa_mask;
@@ -88,16 +95,17 @@ void radio_sendto(uint8_t addr, const char *data, uint8_t n)
{
uint8_t i;
- // force the receiver into WAIT mode
+ // force-stop rx
write_reg(0x3D, ((read_reg(0x3D) & 0xFB) | 0x04));
+ //while (((read_reg(0x01) & 0x1C) == 0x10) && payload_len == 0 && rssi() < -90)
+ // write_reg(0x01, 0x04);
- // todo: implement the rest...
-
- // STDBY + ListenAbort
write_reg(0x01, 0x04);
- while ((read_reg(0x27) >> 7) != 1)
+ while (!(read_reg(0x27) & 0x80))
;
+ // todo: implement the rest...
+
SPI_PORT &= ~(1 << SPI_SS);
SPDR = 0x00 | 0x80;
while (!(SPSR & (1 << SPIF)))