From e8e33017029cee53662ec435c9e6c2153245133c Mon Sep 17 00:00:00 2001 From: Grygoriy Fuchedzhy Date: Sat, 23 Jan 2010 15:48:00 +0200 Subject: [PATCH] added mrf_is_rx_complete, mrf_wait_rx_complete, mrf_is_tx_complete, mrf_wait_tx_complete functions --- fw/mrf/mrf.h | 27 +++++++++++++++++++++++++++ fw/mrf/mrf_impl.h | 3 +++ 2 files changed, 30 insertions(+) diff --git a/fw/mrf/mrf.h b/fw/mrf/mrf.h index 205a341..e03c5af 100644 --- a/fw/mrf/mrf.h +++ b/fw/mrf/mrf.h @@ -33,6 +33,7 @@ void mrf_tx(uint16_t pan_id, uint16_t short_addr, const uint8_t* data, uint8_t d uint8_t mrf_rx(uint16_t *pan_id, uint16_t *short_addr, uint8_t* data, uint8_t data_length); extern uint8_t mrf_rssi, mrf_lqi; +extern volatile uint8_t mrf_status; // wrapper function, with constant addr parameter and optimization compiles into // direct call to appropriate function @@ -69,4 +70,30 @@ static inline uint8_t mrf_get_txretry() return mrf_get_reg(MRF_R_TXSTAT) >> 6; } +static inline uint8_t mrf_is_rx_complete() +{ + if(bit_is_set(mrf_status, MRF_B_RX)) + return 1; + mrf_status |= mrf_get_reg(MRF_R_INTSTAT); + return bit_is_set(mrf_status, MRF_B_RX); +} + +static inline void mrf_wait_rx_complete() +{ + while(!mrf_is_rx_complete()); +} + +static inline uint8_t mrf_is_tx_complete() +{ + if(bit_is_set(mrf_status, MRF_B_TXN)) + return 1; + mrf_status |= mrf_get_reg(MRF_R_INTSTAT); + return bit_is_set(mrf_status, MRF_B_TXN); +} + +static inline void mrf_wait_tx_complete() +{ + while(!mrf_is_tx_complete()); +} + #endif // __MRF__ diff --git a/fw/mrf/mrf_impl.h b/fw/mrf/mrf_impl.h index b277582..b389197 100644 --- a/fw/mrf/mrf_impl.h +++ b/fw/mrf/mrf_impl.h @@ -30,6 +30,7 @@ uint16_t mrf_short_addr = MRF_SHORT_ADDR; uint16_t mrf_pan_id = MRF_PAN_ID; uint8_t mrf_seq_num = 0; uint8_t mrf_rssi = 0, mrf_lqi = 0; +volatile uint8_t mrf_status = 0; // set given short register to given value via spi void mrf_write_short_addr(uint8_t addr, uint8_t val) @@ -161,6 +162,7 @@ void mrf_tx(uint16_t pan_id, uint16_t short_addr, const uint8_t* data, uint8_t d for(uint8_t i = 0; i < data_length; ++i) mrf_write_long_addr(addr++, data[i]); + mrf_status &= ~_BV(MRF_B_TXN); // transmit frame, request acknowledgement mrf_set_reg(MRF_R_TXNCON, _BV(MRF_B_ACKREQ) | _BV(MRF_B_TRIG)); } @@ -193,6 +195,7 @@ uint8_t mrf_rx(uint16_t *pan_id, uint16_t *short_addr, uint8_t* data, uint8_t da // enable receiving packets off air mrf_set_reg(MRF_R_BBREG1, 0); + mrf_status &= ~_BV(MRF_B_RX); return i; } -- 2.11.4.GIT