#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "contiki.h"
#include "leds.h"
#include "rtimer.h"
#include "netstack.h"
#include "net/packetbuf.h"
#include "rf212b-const.h"
#include "rf212b-config.h"
#include "rf212b-arch.h"
#include "rf212b.h"
#include "trx_access.h"
#include "delay.h"
#include "system_interrupt.h"
Macros | |
#define | _DEBUG_ 0 |
#define | BUSYWAIT_UNTIL(cond, max_time) |
#define | DEBUG_PRINTDATA 0 /* print frames to/from the radio; requires DEBUG == 1 */ |
#define | FOOTER_LEN 3 /* bytes */ |
#define | MAX_PACKET_LEN 127 /* bytes, excluding the length (first) byte */ |
#define | PREV_TX_TIMEOUT (10 * RTIMER_SECOND/1000) |
#define | PRINTF(...) |
#define | RF212_COMMAND(c) trx_reg_write(RF212_REG_TRX_STATE, c) |
#define | RF212_STATUS() rf212_status() |
#define | RSSI_OFFSET (91) |
#define | STR(x) STR_HELPER(x) |
#define | STR_HELPER(x) #x |
Copyright (c) 2015 Microchip Technology Inc and 2012 – 2013, Thingsquare, http://www.thingsquare.com/. More... | |
Functions | |
static void | flush_buffer (void) |
void | goto_sleep (void) |
static int | off (void) |
static int | on (void) |
PROCESS (rf212_radio_process,"RF212 radio driver") | |
PROCESS_THREAD (rf212_radio_process, ev, data) | |
Radio RF212 process, infinitely awaits a poll, then checks radio state and handles received data. More... | |
static void | radiocore_hard_recovery (void) |
static int | rf212_channel_clear (void) |
perform a clear channel assessment More... | |
int | rf212_get_txp (void) |
Get transmission power. More... | |
static int | rf212_init (void) |
Init the radio. More... | |
int | rf212_interrupt_poll (void) |
RF212 radio process poll function, to be called from the interrupt handler to poll the radio process. More... | |
static int | rf212_off (void) |
switch the radio off More... | |
static int | rf212_on (void) |
switch the radio on to listen (rx) mode More... | |
static int | rf212_pending_packet (void) |
check whether we have a frame awaiting processing More... | |
static int | rf212_prepare (const void *payload, unsigned short payload_len) |
prepare a frame and the radio for immediate transmission More... | |
static int | rf212_read (void *buf, unsigned short bufsize) |
read a received frame out of the radio buffer More... | |
static int | rf212_receiving_packet (void) |
check whether we are currently receiving a frame More... | |
static int | rf212_send (const void *payload, unsigned short payload_len) |
Send data: first prepares, then transmits. More... | |
int | rf212_set_txp (uint8_t txp) |
Set transmission power. More... | |
int | rf212_sleep (void) |
uint8_t | rf212_status () |
static int | rf212_transmit (unsigned short payload_len) |
Transmit a frame already put in the radio with 'prepare'. More... | |
static void | rf_generate_random_seed (void) |
int | rf_get_channel (void) |
Get radio channel. More... | |
int | rf_set_channel (uint8_t ch) |
Set radio channel. More... | |
void | SetIEEEAddr (uint8_t *ieee_addr) |
void | SetPanId (uint16_t panId) |
void | SetShortAddr (uint16_t addr) |
void | wake_from_sleep (void) |
Variables | |
static uint8_t | flag_transmit = 0 |
static volatile int | interrupt_callback_in_progress = 0 |
static volatile int | interrupt_callback_wants_poll = 0 |
static volatile int | pending_frame = 0 |
static volatile int | radio_is_on = 0 |
struct radio_driver | rf212_radio_driver |
static volatile int | sleep_on = 0 |
#define _DEBUG_ 0 |
#define BUSYWAIT_UNTIL | ( | cond, | |
max_time | |||
) |
Referenced by rf212_channel_clear(), and rf212_transmit().
#define DEBUG_PRINTDATA 0 /* print frames to/from the radio; requires DEBUG == 1 */ |
#define FOOTER_LEN 3 /* bytes */ |
#define MAX_PACKET_LEN 127 /* bytes, excluding the length (first) byte */ |
Referenced by rf212_prepare().
#define PREV_TX_TIMEOUT (10 * RTIMER_SECOND/1000) |
#define PRINTF | ( | ... | ) |
#define RF212_COMMAND | ( | c | ) | trx_reg_write(RF212_REG_TRX_STATE, c) |
Referenced by off(), on(), rf212_channel_clear(), rf212_interrupt_poll(), and rf212_transmit().
#define RF212_STATUS | ( | ) | rf212_status() |
Referenced by on(), rf212_channel_clear(), and rf212_transmit().
#define RSSI_OFFSET (91) |
Referenced by rf212_read().
#define STR | ( | x | ) | STR_HELPER(x) |
#define STR_HELPER | ( | x | ) | #x |
Copyright (c) 2015 Microchip Technology Inc and 2012 – 2013, Thingsquare, http://www.thingsquare.com/.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
static |
References trx_frame_write().
Referenced by rf212_read().
void goto_sleep | ( | void | ) |
Referenced by rf212_sleep(), and rf233_sleep().
|
static |
References ENERGEST_OFF, ENERGEST_TYPE_LISTEN, radio_is_on, RF212_COMMAND, rf212_status(), STATE_RX_AACK_ON, STATE_RX_ON, and TRXCMD_TRX_OFF.
Referenced by nm_read_block(), nm_write_block(), rf212_off(), and uhi_aoa_register_hid().
|
static |
References ENERGEST_ON, ENERGEST_TYPE_LISTEN, radio_is_on, RF212_COMMAND, RF212_STATUS, STATE_PLL_ON, STATE_TRX_OFF, STATE_TX_ARET_ON, TRXCMD_RX_AACK_ON, and TRXCMD_RX_ON.
Referenced by rf212_on().
PROCESS | ( | rf212_radio_process | , |
"RF212 radio driver" | |||
) |
PROCESS_THREAD | ( | rf212_radio_process | , |
ev | , | ||
data | |||
) |
Radio RF212 process, infinitely awaits a poll, then checks radio state and handles received data.
References rdc_driver::input, len, NETSTACK_RDC, packetbuf_clear(), packetbuf_dataptr(), packetbuf_set_datalen(), PACKETBUF_SIZE, PRINTF, PROCESS_BEGIN, PROCESS_END, PROCESS_EVENT_POLL, PROCESS_YIELD_UNTIL, rf212_interrupt_poll(), and rf212_read().
|
static |
References printf, and rf212_init().
Referenced by rf212_transmit().
|
static |
perform a clear channel assessment
>0 | Channel is clear |
0 | Channel is not clear |
References BUSYWAIT_UNTIL, PHY_CC_CCA_DO_CCA, PHY_CC_CCA_MODE_CS_OR_ED, PRINTF, RF212_COMMAND, RF212_REG_PHY_CC_CCA, RF212_REG_TRX_STATUS, RF212_STATUS, RTIMER_SECOND, STATE_RX_ON, TRX_CCA_DONE, TRX_CCA_STATUS, trx_reg_read(), trx_reg_write(), TRXCMD_RX_AACK_ON, TRXCMD_RX_ON, and TRXCMD_TRX_OFF.
int rf212_get_txp | ( | void | ) |
Get transmission power.
References PHY_TX_PWR_TXP, PRINTF, RF212_REG_PHY_TX_PWR_CONF, and trx_reg_read().
|
static |
Init the radio.
0 | Success |
References delay_cycles_ms(), FUNC_PTR, NULL, port_pin_set_output_level(), printf, PRINTF, process_start(), rf212_interrupt_poll(), RF212_REG_IRQ_MASK, RF212_REG_IRQ_MASK_CONF, RF212_REG_IRQ_STATUS, RF212_REG_PHY_CC_CCA, RF212_REG_PHY_CC_CCA_CONF, RF212_REG_PHY_TX_PWR_CONF, RF212_REG_TRX_CTRL_1, RF212_REG_TRX_CTRL_1_CONF, RF212_REG_TRX_CTRL_2, RF212_REG_TRX_CTRL_2_CONF, RF212_REG_TRX_STATE, rf212_status(), rf_generate_random_seed(), SetPanId(), SR_MAX_CSMA_RETRIES, SR_MAX_FRAME_RETRIES, STATE_P_ON, system_interrupt_enable_global(), trx_bit_write(), trx_irq_init(), trx_reg_read(), trx_reg_write(), trx_spi_init(), and TRXCMD_TRX_OFF.
Referenced by radiocore_hard_recovery().
int rf212_interrupt_poll | ( | void | ) |
RF212 radio process poll function, to be called from the interrupt handler to poll the radio process.
0 | success |
References flag_transmit, IRQ_BAT_LOW, IRQ_CCA_ED_DONE, IRQ_PLL_LOCK, IRQ_PLL_UNLOCK, IRQ_RX_ADDRESS_MATCH, IRQ_TRX_DONE, IRQ_TRXBUF_ACCESS_VIOLATION, pending_frame, PRINTF, process_poll(), RF212_COMMAND, RF212_REG_IRQ_STATUS, RF212_REG_TRX_STATE, trx_reg_read(), TRX_STATE_TRAC_STATUS, and TRXCMD_RX_AACK_ON.
Referenced by PROCESS_THREAD(), and rf212_init().
|
static |
|
static |
|
static |
check whether we have a frame awaiting processing
>0 | we have a frame awaiting processing |
0 | we have not a frame awaiting processing |
References pending_frame, and PRINTF.
|
static |
prepare a frame and the radio for immediate transmission
payload | Pointer to data to copy/send |
payload_len | length of data to copy |
References data, i, MAX_PACKET_LEN, PRINTF, RADIO_TX_ERR, RADIO_TX_OK, rf212_status(), STATE_BUSY_RX, STATE_BUSY_RX_AACK, STATE_BUSY_TX, STATE_BUSY_TX_ARET, and trx_frame_write().
Referenced by rf212_send().
|
static |
read a received frame out of the radio buffer
buf | pointer to where to copy received data |
bufsize | Maximum size we can copy into bufsize |
-1 | Failed, was transmitting so FIFO is invalid |
-2 | Failed, rx timed out (stuck in rx?) |
-3 | Failed, too large frame for buffer |
-4 | Failed, CRC/FCS failed (if USE_HW_FCS_CHECK is true) |
References flush_buffer(), len, PACKETBUF_ATTR_RSSI, packetbuf_set_attr(), pending_frame, PRINTF, RF212_REG_PHY_ED_LEVEL, RSSI_OFFSET, trx_frame_read(), trx_reg_read(), and trx_sram_read().
Referenced by PROCESS_THREAD().
|
static |
check whether we are currently receiving a frame
>0 | we are currently receiving a frame |
0 | we are not currently receiving a frame |
References PRINTF, rf212_status(), STATE_BUSY_RX, and STATE_BUSY_RX_AACK.
|
static |
Send data: first prepares, then transmits.
payload | Pointer to data to copy/send |
payload_len | length of data to copy |
References PRINTF, RADIO_TX_ERR, rf212_prepare(), and rf212_transmit().
int rf212_set_txp | ( | uint8_t | txp | ) |
Set transmission power.
txp | The transmission power |
-1 | Fail: transmission power out of bounds |
0 | Success |
References PRINTF, RF212_REG_PHY_TX_PWR_CONF, trx_reg_write(), and TXP_M17.
int rf212_sleep | ( | void | ) |
References goto_sleep(), rf212_off(), sleep_on, and status.
uint8_t rf212_status | ( | void | ) |
References RF212_REG_TRX_STATUS, trx_reg_read(), and TRX_STATUS.
Referenced by off(), rf212_init(), rf212_prepare(), rf212_receiving_packet(), rf212_transmit(), and rf_generate_random_seed().
|
static |
Transmit a frame already put in the radio with 'prepare'.
payload_len | Length of the frame to send |
References BUSYWAIT_UNTIL, ENERGEST_OFF, ENERGEST_ON, ENERGEST_TYPE_LISTEN, ENERGEST_TYPE_TRANSMIT, flag_transmit, printf, PRINTF, RADIO_TX_ERR, RADIO_TX_NOACK, RADIO_TX_OK, radiocore_hard_recovery(), RF212_COMMAND, RF212_REG_TRX_STATE, RF212_STATUS, rf212_status(), RTIMER_SECOND, STATE_BUSY_RX, STATE_BUSY_RX_AACK, STATE_BUSY_TX, STATE_BUSY_TX_ARET, STATE_PLL_ON, trx_bit_read(), trx_reg_write(), TRXCMD_PLL_ON, TRXCMD_RX_ON, TRXCMD_TX_ARET_ON, and TRXCMD_TX_START.
Referenced by rf212_send().
|
static |
References delay_us, i, RF212_REG_IRQ_STATUS, RF212_REG_TRX_STATE, rf212_status(), RX_ENABLE, SR_RND_VALUE, SR_RX_PDT_DIS, trx_bit_read(), trx_bit_write(), trx_irq_flag_clr, trx_reg_read(), trx_reg_write(), TRXCMD_PLL_ON, TRXCMD_RX_ON, and TRXCMD_TRX_OFF.
Referenced by rf212_init().
int rf_get_channel | ( | void | ) |
int rf_set_channel | ( | uint8_t | ch | ) |
Set radio channel.
ch | The radio channel |
-1 | Fail: channel number out of bounds |
0 | Success |
Referenced by main().
void SetIEEEAddr | ( | uint8_t * | ieee_addr | ) |
Referenced by main().
void SetPanId | ( | uint16_t | panId | ) |
Referenced by rf212_init(), and rf233_init().
void SetShortAddr | ( | uint16_t | addr | ) |
void wake_from_sleep | ( | void | ) |
Referenced by on().
|
static |
Referenced by rf212_interrupt_poll(), and rf212_transmit().
|
static |
|
static |
|
static |
Referenced by rf212_interrupt_poll(), rf212_pending_packet(), and rf212_read().
struct radio_driver rf212_radio_driver |
|
static |
Referenced by rf212_sleep().