Microchip® Advanced Software Framework

rf233.c File Reference
#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 
)
Value:
do { \
t0 = RTIMER_NOW(); \
while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (max_time))); \
} while(0)
unsigned short rtimer_clock_t
Definition: rtimer.h:58
#define RTIMER_NOW()
Get the current clock time.
Definition: rtimer.h:132
while(s->file.len > 0)
Definition: wireless/SmartConnect_6LoWPAN/apps/ip64-webserver/httpd.c:170
#define RTIMER_CLOCK_LT(a, b)
Definition: rtimer.h:59

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 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/.

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of Atmel nor the name of Thingsquare nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
  4. This software may only be redistributed and used in connection with an Atmel microcontroller or Atmel wireless product.

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 void flush_buffer ( void  )
static

References trx_frame_write().

Referenced by rf233_read().

void goto_sleep ( 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.

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 void radiocore_hard_recovery ( void  )
static

References rf233_init().

Referenced by rf233_transmit().

int rf233_channel_clear ( void  )
int rf233_get_txp ( void  )

Get transmission power.

Returns
The transmission power

References PHY_TX_PWR_TXP, PRINTF, RF233_REG_PHY_TX_PWR_CONF, and trx_reg_read().

int rf233_interrupt_poll ( void  )

RF233 radio process poll function, to be called from the interrupt handler to poll the radio process.

Return values
0success

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  )

switch the radio off

Return values
0Success

References off(), and PRINTF.

Referenced by rf233_sleep().

int rf233_on ( void  )

switch the radio on to listen (rx) mode

Return values
0Success

References on(), and PRINTF.

int rf233_pending_packet ( void  )

check whether we have a frame awaiting processing

Return values
>0we have a frame awaiting processing
0we 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

Parameters
payloadPointer to data to copy/send
payload_lenlength of data to copy
Returns
Returns success/fail, refer to radio.h for explanation

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

Parameters
bufpointer to where to copy received data
bufsizeMaximum size we can copy into bufsize
Returns
Returns length of data read (> 0) if successful
Return values
-1Failed, was transmitting so FIFO is invalid
-2Failed, rx timed out (stuck in rx?)
-3Failed, too large frame for buffer
-4Failed, 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

Return values
>0we are currently receiving a frame
0we 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.

Parameters
payloadPointer to data to copy/send
payload_lenlength of data to copy
Returns
Returns success/fail, refer to radio.h for explanation

References PRINTF, RADIO_TX_ERR, rf233_prepare(), and rf233_transmit().

int rf233_set_txp ( uint8_t  txp)

Set transmission power.

Parameters
txpThe transmission power
Return values
-1Fail: transmission power out of bounds
0Success

References PRINTF, RF233_REG_PHY_TX_PWR_CONF, trx_reg_write(), and TXP_M17.

int rf233_sleep ( void  )
int rf233_transmit ( unsigned short  payload_len)
int rf_get_channel ( void  )

Get radio channel.

Returns
The 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.

Parameters
chThe radio channel
Return values
-1Fail: channel number out of bounds
0Success

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  )

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
static

Referenced by off(), and on().

struct radio_driver rf233_radio_driver
Initial value:
=
{
}
int rf233_init(void)
Init the radio.
Definition: rf233.c:228
int rf233_prepare(const void *payload, unsigned short payload_len)
prepare a frame and the radio for immediate transmission
Definition: rf233.c:365
int rf233_send(const void *data, unsigned short len)
Send data: first prepares, then transmits.
Definition: rf233.c:535
int rf233_on(void)
switch the radio on to listen (rx) mode
Definition: rf233.c:742
int rf233_read(void *buf, unsigned short bufsize)
read a received frame out of the radio buffer
Definition: rf233.c:555
int rf233_off(void)
switch the radio off
Definition: rf233.c:754
int rf233_transmit(unsigned short payload_len)
Transmit a frame already put in the radio with &#39;prepare&#39;.
Definition: rf233.c:432
int rf233_receiving_packet(void)
check whether we are currently receiving a frame
Definition: rf233.c:708
int rf233_sleep(void)
Definition: rf233.c:857
int rf233_channel_clear(void)
perform a clear channel assessment
Definition: rf233.c:663
int rf233_pending_packet(void)
check whether we have a frame awaiting processing
Definition: rf233.c:731
volatile int sleep_on = 0
static

Referenced by on(), and rf233_sleep().