#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 "rf233-const.h"
#include "rf233-config.h"
#include "rf233-arch.h"
#include "trx_access.h"
#include "rf233.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 | RF233_COMMAND(c) trx_reg_write(RF233_REG_TRX_STATE, c) |
#define | RF233_STATUS() rf233_status() |
Copyright (c) 2015 Microchip Technology Inc and 2012 – 2013, Thingsquare, http://www.thingsquare.com/. More... | |
#define | RSSI_OFFSET (91) |
Functions | |
static void | flush_buffer (void) |
void | goto_sleep (void) |
static int | off (void) |
static int | on (void) |
PROCESS (rf233_radio_process,"RF233 radio driver") | |
PROCESS_THREAD (rf233_radio_process, ev, data) | |
Radio RF233 process, infinitely awaits a poll, then checks radio state and handles received data. More... | |
static void | radiocore_hard_recovery (void) |
int | rf233_channel_clear (void) |
perform a clear channel assessment More... | |
int | rf233_get_txp (void) |
Get transmission power. More... | |
int | rf233_init (void) |
Init the radio. More... | |
int | rf233_interrupt_poll (void) |
RF233 radio process poll function, to be called from the interrupt handler to poll the radio process. More... | |
int | rf233_off (void) |
switch the radio off More... | |
int | rf233_on (void) |
switch the radio on to listen (rx) mode More... | |
int | rf233_pending_packet (void) |
check whether we have a frame awaiting processing More... | |
int | rf233_prepare (const void *payload, unsigned short payload_len) |
prepare a frame and the radio for immediate transmission More... | |
int | rf233_read (void *buf, unsigned short bufsize) |
read a received frame out of the radio buffer More... | |
int | rf233_receiving_packet (void) |
check whether we are currently receiving a frame More... | |
int | rf233_send (const void *payload, unsigned short payload_len) |
Send data: first prepares, then transmits. More... | |
int | rf233_set_txp (uint8_t txp) |
Set transmission power. More... | |
int | rf233_sleep (void) |
uint8_t | rf233_status () |
int | rf233_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 | rf233_radio_driver |
static volatile int | sleep_on = 0 |
#define _DEBUG_ 0 |
#define BUSYWAIT_UNTIL | ( | cond, | |
max_time | |||
) |
Referenced by rf233_channel_clear(), and rf233_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 rf233_prepare().
#define PREV_TX_TIMEOUT (10 * RTIMER_SECOND/1000) |
#define PRINTF | ( | ... | ) |
#define RF233_COMMAND | ( | c | ) | trx_reg_write(RF233_REG_TRX_STATE, c) |
Referenced by off(), on(), rf233_channel_clear(), rf233_interrupt_poll(), and rf233_transmit().
#define RF233_STATUS | ( | ) | rf233_status() |
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.
#define RSSI_OFFSET (91) |
Referenced by rf233_read().
|
static |
References trx_frame_write().
Referenced by rf233_read().
void goto_sleep | ( | void | ) |
References port_pin_set_output_level().
|
static |
References ENERGEST_OFF, ENERGEST_TYPE_LISTEN, radio_is_on, RF233_COMMAND, rf233_status(), STATE_RX_AACK_ON, STATE_RX_ON, and TRXCMD_TRX_OFF.
Referenced by rf233_off().
|
static |
References delay_ms, ENERGEST_ON, ENERGEST_TYPE_LISTEN, radio_is_on, RF233_COMMAND, rf233_status(), sleep_on, STATE_PLL_ON, STATE_TRX_OFF, STATE_TX_ARET_ON, TRXCMD_RX_AACK_ON, TRXCMD_RX_ON, and wake_from_sleep().
Referenced by rf233_on().
PROCESS | ( | rf233_radio_process | , |
"RF233 radio driver" | |||
) |
PROCESS_THREAD | ( | rf233_radio_process | , |
ev | , | ||
data | |||
) |
Radio RF233 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, rf233_interrupt_poll(), and rf233_read().
|
static |
References rf233_init().
Referenced by rf233_transmit().
int rf233_channel_clear | ( | void | ) |
perform a clear channel assessment
>0 | Channel is clear |
0 | Channel is not clear |
References BUSYWAIT_UNTIL, delay_us, PHY_CC_CCA_DO_CCA, PHY_CC_CCA_MODE_CS_OR_ED, PRINTF, RF233_COMMAND, RF233_REG_PHY_CC_CCA, RF233_REG_TRX_STATUS, rf233_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 rf233_get_txp | ( | void | ) |
Get transmission power.
References PHY_TX_PWR_TXP, PRINTF, RF233_REG_PHY_TX_PWR_CONF, and trx_reg_read().
int rf233_init | ( | void | ) |
Init the radio.
0 | Success |
References delay_cycles_ms(), FUNC_PTR, i, NULL, port_pin_set_output_level(), PRINTF, process_start(), rf233_interrupt_poll(), RF233_REG_IRQ_MASK, RF233_REG_IRQ_MASK_CONF, RF233_REG_IRQ_STATUS, RF233_REG_PHY_CC_CCA, RF233_REG_PHY_CC_CCA_CONF, RF233_REG_PHY_TX_PWR, RF233_REG_PHY_TX_PWR_CONF, RF233_REG_TRX_CTRL_1, RF233_REG_TRX_CTRL_1_CONF, RF233_REG_TRX_CTRL_2, RF233_REG_TRX_CTRL_2_CONF, RF233_REG_TRX_RPC, RF233_REG_TRX_STATE, rf233_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 rf233_interrupt_poll | ( | void | ) |
RF233 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(), RF233_COMMAND, RF233_REG_IRQ_STATUS, RF233_REG_TRX_STATE, trx_reg_read(), TRX_STATE_TRAC_STATUS, and TRXCMD_RX_AACK_ON.
Referenced by PROCESS_THREAD(), and rf233_init().
int rf233_off | ( | void | ) |
int rf233_on | ( | void | ) |
int rf233_pending_packet | ( | void | ) |
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.
int rf233_prepare | ( | const void * | payload, |
unsigned short | payload_len | ||
) |
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, rf233_status(), STATE_BUSY_RX, STATE_BUSY_RX_AACK, STATE_BUSY_TX, STATE_BUSY_TX_ARET, and trx_frame_write().
Referenced by rf233_send().
int rf233_read | ( | void * | buf, |
unsigned short | bufsize | ||
) |
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, RF233_REG_PHY_ED_LEVEL, RSSI_OFFSET, trx_frame_read(), trx_reg_read(), and trx_sram_read().
Referenced by PROCESS_THREAD().
int rf233_receiving_packet | ( | void | ) |
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, rf233_status(), STATE_BUSY_RX, and STATE_BUSY_RX_AACK.
int rf233_send | ( | const void * | payload, |
unsigned short | payload_len | ||
) |
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, rf233_prepare(), and rf233_transmit().
int rf233_set_txp | ( | uint8_t | txp | ) |
Set transmission power.
txp | The transmission power |
-1 | Fail: transmission power out of bounds |
0 | Success |
References PRINTF, RF233_REG_PHY_TX_PWR_CONF, trx_reg_write(), and TXP_M17.
int rf233_sleep | ( | void | ) |
References goto_sleep(), rf233_off(), sleep_on, and status.
uint8_t rf233_status | ( | void | ) |
References RF233_REG_TRX_STATUS, trx_reg_read(), and TRX_STATUS.
Referenced by off(), on(), rf233_channel_clear(), rf233_init(), rf233_prepare(), rf233_receiving_packet(), rf233_transmit(), and rf_generate_random_seed().
int rf233_transmit | ( | unsigned short | payload_len | ) |
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, RADIO_TX_ERR, RADIO_TX_NOACK, RADIO_TX_OK, radiocore_hard_recovery(), RF233_COMMAND, RF233_REG_TRX_STATE, rf233_status(), RTIMER_SECOND, state, 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 rf233_send().
|
static |
References delay_us, i, RF233_REG_IRQ_STATUS, RF233_REG_TRX_STATE, rf233_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 rf233_init().
int rf_get_channel | ( | void | ) |
Get radio channel.
References PHY_CC_CCA_CHANNEL, RF212_REG_PHY_CC_CCA, RF233_REG_PHY_CC_CCA, and trx_reg_read().
int rf_set_channel | ( | uint8_t | ch | ) |
Set radio channel.
ch | The radio channel |
-1 | Fail: channel number out of bounds |
0 | Success |
References PHY_CC_CCA_CHANNEL, PRINTF, RF212_REG_PHY_CC_CCA, RF233_REG_PHY_CC_CCA, trx_reg_read(), and trx_reg_write().
void SetIEEEAddr | ( | uint8_t * | ieee_addr | ) |
References trx_reg_write().
void SetPanId | ( | uint16_t | panId | ) |
References trx_reg_write().
void SetShortAddr | ( | uint16_t | addr | ) |
References trx_reg_write().
void wake_from_sleep | ( | void | ) |
References port_pin_set_output_level().
|
static |
Referenced by rf233_interrupt_poll(), and rf233_transmit().
|
static |
|
static |
|
static |
Referenced by rf233_interrupt_poll(), rf233_pending_packet(), and rf233_read().
struct radio_driver rf233_radio_driver |
|
static |
Referenced by on(), and rf233_sleep().