36 #include "sys/cooja_mt.h" 37 #include "lib/simEnvChange.h" 44 #include "dev/cooja-radio.h" 51 #ifdef COOJA_RADIO_CONF_BUFSIZE 52 #define COOJA_RADIO_BUFSIZE COOJA_RADIO_CONF_BUFSIZE 54 #define COOJA_RADIO_BUFSIZE 125 57 #define CCA_SS_THRESHOLD -95 59 const struct simInterface radio_interface;
71 RSSI_NO_SIGNAL = -110,
81 char simReceiving = 0;
82 char simInDataBuffer[COOJA_RADIO_BUFSIZE];
84 rtimer_clock_t simLastPacketTimestamp = 0;
85 char simOutDataBuffer[COOJA_RADIO_BUFSIZE];
87 char simRadioHWOn = 1;
88 int simSignalStrength = RSSI_NO_SIGNAL;
89 int simLastSignalStrength = RSSI_NO_SIGNAL;
91 int simRadioChannel = 26;
92 int simLQI = LQI_NO_SIGNAL;
93 int simLastLQI = LQI_NO_SIGNAL;
97 static const void *pending_data;
100 static int poll_mode = 0;
101 static int auto_ack = 0;
102 static int addr_filter = 0;
103 static int send_on_cca = (COOJA_TRANSMIT_ON_CCA != 0);
105 PROCESS(cooja_radio_process,
"cooja radio process");
108 set_send_on_cca(uint8_t enable)
110 send_on_cca = enable;
114 set_frame_filtering(
int enable)
116 addr_filter = enable;
120 set_auto_ack(
int enable)
126 set_poll_mode(
int enable)
132 radio_set_channel(
int channel)
134 simRadioChannel = channel;
138 radio_set_txpower(
unsigned char power)
145 radio_signal_strength_last(
void)
147 return simLastSignalStrength;
151 radio_signal_strength_current(
void)
153 return simSignalStrength;
163 int radio_lqi_last(
void)
172 ENERGEST_ON(ENERGEST_TYPE_LISTEN);
180 ENERGEST_OFF(ENERGEST_TYPE_LISTEN);
186 doInterfaceActionsBeforeTick(
void)
193 simLastSignalStrength = simSignalStrength;
204 doInterfaceActionsAfterTick(
void)
209 radio_read(
void *buf,
unsigned short bufsize)
216 if(bufsize < simInSize) {
221 memcpy(buf, simInDataBuffer, simInSize);
224 packetbuf_set_attr(PACKETBUF_ATTR_RSSI, radio_signal_strength_last());
225 packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, radio_lqi_last() );
234 if(simSignalStrength > CCA_SS_THRESHOLD) {
241 radio_send(
const void *payload,
unsigned short payload_len)
244 int radio_was_on = simRadioHWOn;
246 if(payload_len > COOJA_RADIO_BUFSIZE) {
249 if(payload_len == 0) {
257 ENERGEST_SWITCH(ENERGEST_TYPE_LISTEN, ENERGEST_TYPE_TRANSMIT);
261 ENERGEST_ON(ENERGEST_TYPE_TRANSMIT);
264 #if COOJA_SIMULATE_TURNAROUND 265 simProcessRunValue = 1;
267 if(payload_len > 3) {
268 simProcessRunValue = 1;
274 if(COOJA_TRANSMIT_ON_CCA && send_on_cca && !channel_clear()) {
278 memcpy(simOutDataBuffer, payload, payload_len);
279 simOutSize = payload_len;
282 while(simOutSize > 0) {
290 ENERGEST_SWITCH(ENERGEST_TYPE_TRANSMIT, ENERGEST_TYPE_LISTEN);
292 ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT);
295 simRadioHWOn = radio_was_on;
300 prepare_packet(
const void *data,
unsigned short len)
302 if(len > COOJA_RADIO_BUFSIZE) {
310 transmit_packet(
unsigned short len)
313 if(pending_data != NULL) {
314 ret = radio_send(pending_data, len);
320 receiving_packet(
void)
328 return !simReceiving && simInSize > 0;
347 NETSTACK_MAC.
input();
384 *value = radio_signal_strength_last();
388 *value = radio_lqi_last();
392 *value = radio_signal_strength_current();
395 case RADIO_CONST_MAX_PAYLOAD_LEN:
417 set_frame_filtering((value & RADIO_RX_MODE_ADDRESS_FILTER) != 0);
420 if ((value & RADIO_RX_MODE_ADDRESS_FILTER) != 0) {
440 radio_set_channel(value);
448 get_object(radio_param_t param,
void *dest,
size_t size)
451 if(size !=
sizeof(rtimer_clock_t) || !dest) {
454 *(rtimer_clock_t *)dest = (rtimer_clock_t)simLastPacketTimestamp;
461 set_object(radio_param_t param,
const void *src,
size_t size)
484 SIM_INTERFACE(radio_interface,
485 doInterfaceActionsBeforeTick,
486 doInterfaceActionsAfterTick);
radio_result_t(* get_object)(radio_param_t param, void *dest, size_t size)
Get a radio parameter object.
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
#define PROCESS(name, strname)
Declare a process.
The parameter is not supported.
void packetbuf_clear(void)
Clear and reset the packetbuf.
Header file for the energy estimation mechanism
TX failed due to a collision.
#define PROCESS_YIELD_UNTIL(c)
Yield the currently running process until a condition occurs.
Header file for the radio API
#define PROCESS_BEGIN()
Define the beginning of a process.
#define PROCESS_END()
Define the end of a process.
Received signal strength indicator in dBm.
int(* receiving_packet)(void)
Check if the radio driver is currently receiving a packet.
radio_result_t(* set_value)(radio_param_t param, radio_value_t value)
Set a radio parameter value.
int(* pending_packet)(void)
Check if a packet has been received and is available in the radio driver's buffers.
The structure of a Contiki-NG radio device driver.
Channel used for radio communication.
The value argument was incorrect.
The parameter was set/read successfully.
int(* channel_clear)(void)
Perform a Clear-Channel Assessment (CCA) to find out if there is a packet in the air or not...
int radio_value_t
Each radio has a set of parameters that designate the current configuration and state of the radio...
Radio transmission mode determines if the radio has send on CCA (RADIO_TX_MODE_SEND_ON_CCA) enabled o...
The RSSI value of the last received packet.
void(* input)(void)
Callback for getting notified of incoming packet.
void process_poll(struct process *p)
Request a process to be polled.
Radio receiver mode determines if the radio has address filter (RADIO_RX_MODE_ADDRESS_FILTER) and aut...
#define PACKETBUF_SIZE
The size of the packetbuf, in bytes.
#define RADIO_RX_MODE_ADDRESS_FILTER
Enable address-based frame filtering.
enum radio_result_e radio_result_t
Radio return values when setting or getting radio parameters.
#define RADIO_TX_MODE_SEND_ON_CCA
Radio TX mode control / retrieval.
#define RADIO_RX_MODE_AUTOACK
Enable automatic transmission of ACK frames.
int(* init)(void)
Initialise the radio hardware.
#define RADIO_RX_MODE_POLL_MODE
Enable/disable/get the state of radio driver poll mode operation.
Link quality indicator of the last received packet.
Header file for the Packet buffer (packetbuf) management
Include file for the Contiki low-layer network stack (NETSTACK)
radio_result_t(* get_value)(radio_param_t param, radio_value_t *value)
Get a radio parameter value.
PROCESS_THREAD(cc2538_rf_process, ev, data)
Implementation of the cc2538 RF driver process.
Last packet timestamp, of type rtimer_clock_t.
An error occurred during transmission.
radio_result_t(* set_object)(radio_param_t param, const void *src, size_t size)
Set a radio parameter object.
void packetbuf_set_datalen(uint16_t len)
Set the length of the data in the packetbuf.
TX was successful and where an ACK was requested one was received.
void process_start(struct process *p, process_data_t data)
Start a process.