diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2024-12-02 20:43:43 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2024-12-02 20:43:43 +0800 |
| commit | 8096af0fd2902e4143f645bde4ff49b4340b3b34 (patch) | |
| tree | aa012f7532d5485ddd5dabb0830d54e4cccffc6a | |
| parent | dd71d17145af4993b9e731e206230f2c0e9ae90a (diff) | |
| download | smart-home-8096af0fd2902e4143f645bde4ff49b4340b3b34.tar.gz | |
wip: rx.
| -rw-r--r-- | rf_test/send.c | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/rf_test/send.c b/rf_test/send.c index 752d231..7290c71 100644 --- a/rf_test/send.c +++ b/rf_test/send.c @@ -22,11 +22,6 @@ #define RX_PCMSK PCMSK0 #define RX_PCINTVEC PCINT0_vect -#define RX_BUFLEN 32 - -static char rxbuf[RX_BUFLEN]; -static volatile uint8_t rx_ready = 0; - static inline uint8_t read_reg(uint8_t reg) { SPI_PORT &= ~(1 << SPI_SS); @@ -81,13 +76,25 @@ static inline void radio_send(const char *data, uint8_t n) while ((read_reg(0x27) >> 7) != 1) ; - // STDBY + ListenOn mode + // enable ListenOn in STDBY mode write_reg(0x01, (read_reg(0x01) | 0x40)); } -static inline void radio_recv(char *buf, uint8_t n) +static inline uint8_t radio_recv(char *buf, uint8_t n) { uint8_t i; + + if ((read_reg(0x28) & 0x04) != 0) + { + write_reg(0x01, 0x04); + while ((read_reg(0x27) >> 7) != 1) + ; + + for (i = 0; i < n; i++) { + } + } + + return i; } static inline void radio_init(void) @@ -121,12 +128,10 @@ int main(void) ISR(RX_PCINTVEC) { - uint8_t i; - char buf[RX_BUFLEN]; + uint8_t n; - if ((read_reg(0x28) & 0x04) != 0) - { - for (i = 0; i < RX_BUFLEN; i++) { - } - } + const uint8_t buflen = 32; + char buf[buflen]; + + n = radio_recv(buf, buflen); } |
