2013-06-18 17:21:38 +02:00
|
|
|
/**
|
2013-06-22 05:11:53 +02:00
|
|
|
* Generic transceiver module as an interface to NIC driver.
|
2013-06-18 17:21:38 +02:00
|
|
|
*
|
|
|
|
* Copyright (C) 2013 INRIA.
|
|
|
|
*
|
|
|
|
* This file subject to the terms and conditions of the GNU Lesser General
|
|
|
|
* Public License. See the file LICENSE in the top level directory for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* @ingroup transceiver
|
|
|
|
* @{
|
|
|
|
* @file transceiver.c
|
|
|
|
* @brief Providing a generic interface to the driver implementation for any supported network device.
|
|
|
|
* @author Oliver Hahm <oliver.hahm@inria.fr>
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2010-11-19 20:10:09 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
2010-11-23 11:37:13 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <thread.h>
|
|
|
|
#include <msg.h>
|
2010-11-19 20:10:09 +01:00
|
|
|
|
|
|
|
#include <transceiver.h>
|
2010-11-26 10:23:46 +01:00
|
|
|
#include <radio/types.h>
|
2010-11-19 20:10:09 +01:00
|
|
|
|
|
|
|
/* supported transceivers */
|
2012-03-01 22:12:25 +01:00
|
|
|
#ifdef MODULE_CC110X
|
|
|
|
#include <cc1100-interface.h>
|
|
|
|
#if (CC1100_MAX_DATA_LENGTH > PAYLOAD_SIZE)
|
2013-06-22 05:11:53 +02:00
|
|
|
#undef PAYLOAD_SIZE
|
|
|
|
#define PAYLOAD_SIZE (CC1100_MAX_DATA_LENGTH)
|
2012-03-01 22:12:25 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2010-11-23 11:37:13 +01:00
|
|
|
#ifdef MODULE_CC110X_NG
|
2010-12-11 12:09:20 +01:00
|
|
|
#include <cc110x_ng.h>
|
2010-11-23 11:37:13 +01:00
|
|
|
#if (CC1100_MAX_DATA_LENGTH > PAYLOAD_SIZE)
|
2013-06-22 05:11:53 +02:00
|
|
|
#undef PAYLOAD_SIZE
|
|
|
|
#define PAYLOAD_SIZE (CC1100_MAX_DATA_LENGTH)
|
2010-11-23 11:37:13 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2010-12-02 15:38:28 +01:00
|
|
|
//#define ENABLE_DEBUG (1)
|
2010-11-23 11:37:13 +01:00
|
|
|
#include <debug.h>
|
2010-11-19 20:10:09 +01:00
|
|
|
|
2010-11-26 10:23:46 +01:00
|
|
|
/*------------------------------------------------------------------------------------*/
|
2010-11-21 14:00:24 +01:00
|
|
|
/* used transceiver types */
|
2010-11-23 11:37:13 +01:00
|
|
|
transceiver_type_t transceivers = TRANSCEIVER_NONE;
|
2010-11-21 14:00:24 +01:00
|
|
|
|
2010-11-26 10:23:46 +01:00
|
|
|
/* registered upper layer threads */
|
2010-11-21 14:00:24 +01:00
|
|
|
registered_t reg[TRANSCEIVER_MAX_REGISTERED];
|
|
|
|
|
|
|
|
/* packet buffers */
|
2010-11-19 20:10:09 +01:00
|
|
|
radio_packet_t transceiver_buffer[TRANSCEIVER_BUFFER_SIZE];
|
2013-06-22 05:11:53 +02:00
|
|
|
uint8_t data_buffer[TRANSCEIVER_BUFFER_SIZE *PAYLOAD_SIZE];
|
2010-11-19 20:10:09 +01:00
|
|
|
|
2010-11-27 19:27:05 +01:00
|
|
|
/* message buffer */
|
2011-07-10 22:49:41 +02:00
|
|
|
msg_t msg_buffer[TRANSCEIVER_MSG_BUFFER_SIZE];
|
2010-11-27 19:27:05 +01:00
|
|
|
|
2010-11-26 10:23:46 +01:00
|
|
|
uint32_t response; ///< response bytes for messages to upper layer threads
|
|
|
|
|
2013-06-24 22:12:57 +02:00
|
|
|
int transceiver_pid = -1; ///< the transceiver thread's pid
|
2010-11-27 11:09:42 +01:00
|
|
|
|
2010-11-19 20:10:09 +01:00
|
|
|
static volatile uint8_t rx_buffer_pos = 0;
|
|
|
|
static volatile uint8_t transceiver_buffer_pos = 0;
|
|
|
|
|
2012-03-01 22:12:25 +01:00
|
|
|
#ifdef MODULE_CC110X
|
|
|
|
void *cc1100_payload;
|
|
|
|
int cc1100_payload_size;
|
|
|
|
packet_info_t *cc1100_packet_info;
|
|
|
|
uint8_t cc1100_pkt[CC1100_MAX_DATA_LENGTH];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2010-11-21 14:00:24 +01:00
|
|
|
/* transceiver stack */
|
2010-11-24 11:20:27 +01:00
|
|
|
char transceiver_stack[TRANSCEIVER_STACK_SIZE];
|
2010-11-19 20:10:09 +01:00
|
|
|
|
2010-11-26 10:23:46 +01:00
|
|
|
/*------------------------------------------------------------------------------------*/
|
2010-11-21 14:00:24 +01:00
|
|
|
/* function prototypes */
|
2010-11-23 11:37:13 +01:00
|
|
|
static void run(void);
|
2010-11-24 11:20:27 +01:00
|
|
|
static void receive_packet(uint16_t type, uint8_t pos);
|
2012-03-01 22:12:25 +01:00
|
|
|
#ifdef MODULE_CC110X_NG
|
2010-12-11 12:09:20 +01:00
|
|
|
static void receive_cc110x_packet(radio_packet_t *trans_p);
|
2012-03-01 22:12:25 +01:00
|
|
|
#elif MODULE_CC110X
|
2013-06-22 05:11:53 +02:00
|
|
|
void cc1100_packet_monitor(void *payload, int payload_size, protocol_t protocol, packet_info_t *packet_info);
|
2012-03-01 22:12:25 +01:00
|
|
|
void receive_cc1100_packet(radio_packet_t *trans_p);
|
|
|
|
#endif
|
2010-11-24 21:45:38 +01:00
|
|
|
static uint8_t send_packet(transceiver_type_t t, void *pkt);
|
2010-11-26 10:23:46 +01:00
|
|
|
static int16_t get_channel(transceiver_type_t t);
|
|
|
|
static int16_t set_channel(transceiver_type_t t, void *channel);
|
|
|
|
static int16_t get_address(transceiver_type_t t);
|
|
|
|
static int16_t set_address(transceiver_type_t t, void *address);
|
2010-11-27 10:50:18 +01:00
|
|
|
static void set_monitor(transceiver_type_t t, void *mode);
|
2010-12-02 15:38:28 +01:00
|
|
|
static void powerdown(transceiver_type_t t);
|
|
|
|
static void switch_to_rx(transceiver_type_t t);
|
2010-11-19 20:10:09 +01:00
|
|
|
|
2012-02-08 17:14:50 +01:00
|
|
|
#ifdef DBG_IGNORE
|
|
|
|
static void ignore_add(transceiver_type_t t, void *address);
|
|
|
|
#endif
|
|
|
|
|
2010-11-26 10:23:46 +01:00
|
|
|
/*------------------------------------------------------------------------------------*/
|
|
|
|
/* Transceiver init */
|
2013-06-22 05:11:53 +02:00
|
|
|
void transceiver_init(transceiver_type_t t)
|
|
|
|
{
|
2010-11-21 14:00:24 +01:00
|
|
|
uint8_t i;
|
2011-12-26 02:59:58 +01:00
|
|
|
|
2013-06-24 22:12:57 +02:00
|
|
|
if (transceiver_pid >= 0) {
|
|
|
|
/* do not re-initialize an already running transceiver */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-26 02:59:58 +01:00
|
|
|
/* Initializing transceiver buffer and data buffer */
|
|
|
|
memset(transceiver_buffer, 0, TRANSCEIVER_BUFFER_SIZE);
|
|
|
|
memset(data_buffer, 0, TRANSCEIVER_BUFFER_SIZE * PAYLOAD_SIZE);
|
|
|
|
|
2013-06-22 05:11:53 +02:00
|
|
|
for(i = 0; i < TRANSCEIVER_MAX_REGISTERED; i++) {
|
2010-11-23 11:37:13 +01:00
|
|
|
reg[i].transceivers = TRANSCEIVER_NONE;
|
|
|
|
reg[i].pid = 0;
|
2010-11-21 14:00:24 +01:00
|
|
|
}
|
2013-06-22 05:11:53 +02:00
|
|
|
|
|
|
|
if(t & TRANSCEIVER_CC1100) {
|
2010-11-23 11:37:13 +01:00
|
|
|
transceivers |= t;
|
2010-11-21 14:00:24 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
puts("Invalid transceiver type");
|
2010-11-19 20:10:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-26 10:23:46 +01:00
|
|
|
/* Start the transceiver thread */
|
2013-06-22 05:11:53 +02:00
|
|
|
int transceiver_start(void)
|
|
|
|
{
|
|
|
|
transceiver_pid = thread_create(transceiver_stack, TRANSCEIVER_STACK_SIZE, PRIORITY_MAIN - 3, CREATE_STACKTEST, run, "Transceiver");
|
|
|
|
|
|
|
|
if(transceiver_pid < 0) {
|
2010-11-19 20:10:09 +01:00
|
|
|
puts("Error creating transceiver thread");
|
|
|
|
}
|
2013-06-22 05:11:53 +02:00
|
|
|
else if(transceivers & TRANSCEIVER_CC1100) {
|
2010-11-24 11:20:27 +01:00
|
|
|
DEBUG("Transceiver started for CC1100\n");
|
2012-03-01 22:12:25 +01:00
|
|
|
#ifdef MODULE_CC110X_NG
|
2010-12-11 12:09:20 +01:00
|
|
|
cc110x_init(transceiver_pid);
|
2012-03-01 22:12:25 +01:00
|
|
|
#else
|
|
|
|
cc1100_init();
|
|
|
|
cc1100_set_packet_monitor(cc1100_packet_monitor);
|
|
|
|
#endif
|
2010-11-23 11:37:13 +01:00
|
|
|
}
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-11-27 11:09:42 +01:00
|
|
|
return transceiver_pid;
|
2010-11-19 20:10:09 +01:00
|
|
|
}
|
|
|
|
|
2010-11-26 10:23:46 +01:00
|
|
|
/* Register an upper layer thread */
|
2013-06-22 05:11:53 +02:00
|
|
|
uint8_t transceiver_register(transceiver_type_t t, int pid)
|
|
|
|
{
|
|
|
|
uint8_t i;
|
|
|
|
|
|
|
|
for(i = 0; ((reg[i].pid != pid) &&
|
|
|
|
(i < TRANSCEIVER_MAX_REGISTERED) &&
|
|
|
|
(reg[i].transceivers != TRANSCEIVER_NONE)); i++);
|
|
|
|
|
|
|
|
if(i >= TRANSCEIVER_MAX_REGISTERED) {
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
reg[i].transceivers |= t;
|
|
|
|
reg[i].pid = pid;
|
|
|
|
DEBUG("Thread %i registered for %i\n", reg[i].pid, reg[i].transceivers);
|
|
|
|
return 1;
|
|
|
|
}
|
2010-11-21 14:00:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------------------*/
|
|
|
|
/* Internal functions */
|
|
|
|
/*------------------------------------------------------------------------------------*/
|
2010-11-26 10:23:46 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief The main thread run, receiving and processing messages in an infinite
|
|
|
|
* loop
|
|
|
|
*/
|
2013-06-22 05:11:53 +02:00
|
|
|
void run(void)
|
|
|
|
{
|
2011-07-10 22:49:41 +02:00
|
|
|
msg_t m;
|
2010-11-24 21:45:38 +01:00
|
|
|
transceiver_command_t *cmd;
|
2010-11-24 11:20:27 +01:00
|
|
|
|
2010-11-27 19:27:05 +01:00
|
|
|
msg_init_queue(msg_buffer, TRANSCEIVER_MSG_BUFFER_SIZE);
|
2013-06-22 05:11:53 +02:00
|
|
|
|
|
|
|
while(1) {
|
2012-02-16 12:34:24 +01:00
|
|
|
DEBUG("Waiting for next message\n");
|
2010-11-19 20:10:09 +01:00
|
|
|
msg_receive(&m);
|
2010-11-26 10:23:46 +01:00
|
|
|
/* only makes sense for messages for upper layers */
|
2013-06-22 05:11:53 +02:00
|
|
|
cmd = (transceiver_command_t *) m.content.ptr;
|
2010-11-24 11:20:27 +01:00
|
|
|
DEBUG("Transceiver: Message received\n");
|
2013-06-22 05:11:53 +02:00
|
|
|
|
|
|
|
switch(m.type) {
|
2010-11-24 11:20:27 +01:00
|
|
|
case RCV_PKT_CC1020:
|
|
|
|
case RCV_PKT_CC1100:
|
|
|
|
receive_packet(m.type, m.content.value);
|
2010-11-19 20:10:09 +01:00
|
|
|
break;
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-11-21 14:00:24 +01:00
|
|
|
case SND_PKT:
|
2010-11-26 10:23:46 +01:00
|
|
|
response = send_packet(cmd->transceivers, cmd->data);
|
|
|
|
m.content.value = response;
|
|
|
|
msg_reply(&m, &m);
|
2010-11-24 21:45:38 +01:00
|
|
|
break;
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-11-24 21:45:38 +01:00
|
|
|
case GET_CHANNEL:
|
2013-06-22 05:11:53 +02:00
|
|
|
*((int16_t *) cmd->data) = get_channel(cmd->transceivers);
|
2010-11-24 21:45:38 +01:00
|
|
|
msg_reply(&m, &m);
|
|
|
|
break;
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-11-24 21:45:38 +01:00
|
|
|
case SET_CHANNEL:
|
2013-06-22 05:11:53 +02:00
|
|
|
*((int16_t *) cmd->data) = set_channel(cmd->transceivers, cmd->data);
|
2010-11-26 10:23:46 +01:00
|
|
|
msg_reply(&m, &m);
|
|
|
|
break;
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-11-26 10:23:46 +01:00
|
|
|
case GET_ADDRESS:
|
2013-06-22 05:11:53 +02:00
|
|
|
*((int16_t *) cmd->data) = get_address(cmd->transceivers);
|
2010-11-26 10:23:46 +01:00
|
|
|
msg_reply(&m, &m);
|
|
|
|
break;
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-11-26 10:23:46 +01:00
|
|
|
case SET_ADDRESS:
|
2013-06-22 05:11:53 +02:00
|
|
|
*((int16_t *) cmd->data) = set_address(cmd->transceivers, cmd->data);
|
2010-11-24 21:45:38 +01:00
|
|
|
msg_reply(&m, &m);
|
2010-11-21 14:00:24 +01:00
|
|
|
break;
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-11-27 10:50:18 +01:00
|
|
|
case SET_MONITOR:
|
|
|
|
set_monitor(cmd->transceivers, cmd->data);
|
|
|
|
break;
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-12-02 15:38:28 +01:00
|
|
|
case POWERDOWN:
|
|
|
|
powerdown(cmd->transceivers);
|
|
|
|
break;
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-12-02 15:38:28 +01:00
|
|
|
case SWITCH_RX:
|
|
|
|
switch_to_rx(cmd->transceivers);
|
|
|
|
break;
|
2012-02-08 17:14:50 +01:00
|
|
|
#ifdef DBG_IGNORE
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2012-02-08 17:14:50 +01:00
|
|
|
case DBG_IGN:
|
2012-02-16 12:34:24 +01:00
|
|
|
printf("Transceiver PID: %i (%p), rx_buffer_next: %u\n", transceiver_pid, &transceiver_pid, rx_buffer_next);
|
2012-02-08 17:14:50 +01:00
|
|
|
ignore_add(cmd->transceivers, cmd->data);
|
|
|
|
break;
|
|
|
|
#endif
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-11-19 20:10:09 +01:00
|
|
|
default:
|
|
|
|
DEBUG("Unknown message received\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-01 22:12:25 +01:00
|
|
|
#ifdef MODULE_CC110X
|
2013-06-22 05:11:53 +02:00
|
|
|
void cc1100_packet_monitor(void *payload, int payload_size, protocol_t protocol, packet_info_t *packet_info)
|
|
|
|
{
|
2012-03-01 22:12:25 +01:00
|
|
|
cc1100_payload = payload;
|
|
|
|
cc1100_payload_size = payload_size - 3;
|
|
|
|
cc1100_packet_info = packet_info;
|
|
|
|
receive_packet(TRANSCEIVER_CC1100, 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-11-26 10:23:46 +01:00
|
|
|
/*------------------------------------------------------------------------------------*/
|
|
|
|
/*
|
|
|
|
* @brief Processes a packet received by any transceiver device
|
|
|
|
*
|
|
|
|
* @param type The message type to determine which device has received the
|
|
|
|
* packet
|
|
|
|
* @param pos The current device driver's buffer position
|
|
|
|
*/
|
2013-06-22 05:11:53 +02:00
|
|
|
static void receive_packet(uint16_t type, uint8_t pos)
|
|
|
|
{
|
2010-11-21 14:00:24 +01:00
|
|
|
uint8_t i = 0;
|
2010-11-24 11:20:27 +01:00
|
|
|
transceiver_type_t t;
|
|
|
|
rx_buffer_pos = pos;
|
2011-07-10 22:49:41 +02:00
|
|
|
msg_t m;
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-11-24 13:47:31 +01:00
|
|
|
DEBUG("Packet received\n");
|
2013-06-22 05:11:53 +02:00
|
|
|
|
|
|
|
switch(type) {
|
2010-11-24 11:20:27 +01:00
|
|
|
case RCV_PKT_CC1020:
|
|
|
|
t = TRANSCEIVER_CC1020;
|
|
|
|
break;
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-11-24 11:20:27 +01:00
|
|
|
case RCV_PKT_CC1100:
|
|
|
|
t = TRANSCEIVER_CC1100;
|
|
|
|
break;
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-11-24 11:20:27 +01:00
|
|
|
default:
|
|
|
|
t = TRANSCEIVER_NONE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* search first free position in transceiver buffer */
|
2013-06-22 05:11:53 +02:00
|
|
|
for(i = 0; (i < TRANSCEIVER_BUFFER_SIZE) && (transceiver_buffer[transceiver_buffer_pos].processing); i++) {
|
|
|
|
if(++transceiver_buffer_pos == TRANSCEIVER_BUFFER_SIZE) {
|
2010-11-27 19:27:05 +01:00
|
|
|
transceiver_buffer_pos = 0;
|
|
|
|
}
|
2010-11-23 11:37:13 +01:00
|
|
|
}
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-11-24 11:20:27 +01:00
|
|
|
/* no buffer left */
|
2013-06-22 05:11:53 +02:00
|
|
|
if(i >= TRANSCEIVER_BUFFER_SIZE) {
|
2010-11-24 11:20:27 +01:00
|
|
|
/* inform upper layers of lost packet */
|
2010-11-23 11:37:13 +01:00
|
|
|
m.type = ENOBUFFER;
|
|
|
|
m.content.value = t;
|
|
|
|
}
|
2010-11-24 11:20:27 +01:00
|
|
|
/* copy packet and handle it */
|
2010-11-23 11:37:13 +01:00
|
|
|
else {
|
2010-11-26 15:02:43 +01:00
|
|
|
radio_packet_t *trans_p = &(transceiver_buffer[transceiver_buffer_pos]);
|
2010-11-23 11:37:13 +01:00
|
|
|
m.type = PKT_PENDING;
|
|
|
|
|
2013-06-22 05:11:53 +02:00
|
|
|
if(type == RCV_PKT_CC1100) {
|
2012-03-01 22:12:25 +01:00
|
|
|
#ifdef MODULE_CC110X_NG
|
2013-06-22 05:11:53 +02:00
|
|
|
receive_cc110x_packet(trans_p);
|
2012-03-01 22:12:25 +01:00
|
|
|
#else
|
|
|
|
receive_cc1100_packet(trans_p);
|
|
|
|
#endif
|
2010-11-23 11:37:13 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
puts("Invalid transceiver type");
|
|
|
|
return;
|
2010-11-21 14:00:24 +01:00
|
|
|
}
|
2010-11-19 20:10:09 +01:00
|
|
|
}
|
2010-11-23 11:37:13 +01:00
|
|
|
|
2010-11-24 11:20:27 +01:00
|
|
|
/* finally notify waiting upper layers
|
|
|
|
* this is done non-blocking, so packets can get lost */
|
2010-11-27 19:27:05 +01:00
|
|
|
i = 0;
|
2013-06-22 05:11:53 +02:00
|
|
|
|
|
|
|
while(reg[i].transceivers != TRANSCEIVER_NONE) {
|
|
|
|
if(reg[i].transceivers & t) {
|
|
|
|
m.content.ptr = (char *) & (transceiver_buffer[transceiver_buffer_pos]);
|
2010-11-24 13:47:31 +01:00
|
|
|
DEBUG("Notify thread %i\n", reg[i].pid);
|
2013-06-22 05:11:53 +02:00
|
|
|
|
|
|
|
if(msg_send(&m, reg[i].pid, false) && (m.type != ENOBUFFER)) {
|
2010-11-27 19:27:05 +01:00
|
|
|
transceiver_buffer[transceiver_buffer_pos].processing++;
|
|
|
|
}
|
2010-11-23 11:37:13 +01:00
|
|
|
}
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-11-23 11:37:13 +01:00
|
|
|
i++;
|
2010-11-21 14:00:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-01 22:12:25 +01:00
|
|
|
#ifdef MODULE_CC110X_NG
|
2010-11-26 10:23:46 +01:00
|
|
|
/*
|
|
|
|
* @brief process packets from CC1100
|
|
|
|
*
|
|
|
|
* @param trans_p The current entry in the transceiver buffer
|
|
|
|
*/
|
2013-06-22 05:11:53 +02:00
|
|
|
static void receive_cc110x_packet(radio_packet_t *trans_p)
|
|
|
|
{
|
2010-11-24 13:47:31 +01:00
|
|
|
DEBUG("Handling CC1100 packet\n");
|
2010-11-23 11:37:13 +01:00
|
|
|
/* disable interrupts while copying packet */
|
|
|
|
dINT();
|
2010-12-11 12:09:20 +01:00
|
|
|
cc110x_packet_t p = cc110x_rx_buffer[rx_buffer_pos].packet;
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-11-23 11:37:13 +01:00
|
|
|
trans_p->src = p.phy_src;
|
|
|
|
trans_p->dst = p.address;
|
2010-12-11 12:09:20 +01:00
|
|
|
trans_p->rssi = cc110x_rx_buffer[rx_buffer_pos].rssi;
|
|
|
|
trans_p->lqi = cc110x_rx_buffer[rx_buffer_pos].lqi;
|
2010-11-26 17:06:54 +01:00
|
|
|
trans_p->length = p.length - CC1100_HEADER_LENGTH;
|
2013-06-22 05:11:53 +02:00
|
|
|
memcpy((void *)&(data_buffer[transceiver_buffer_pos * PAYLOAD_SIZE]), p.data, CC1100_MAX_DATA_LENGTH);
|
2010-11-23 11:37:13 +01:00
|
|
|
eINT();
|
|
|
|
|
2010-11-27 19:27:05 +01:00
|
|
|
DEBUG("Packet %p was from %hu to %hu, size: %u\n", trans_p, trans_p->src, trans_p->dst, trans_p->length);
|
2013-06-22 05:11:53 +02:00
|
|
|
trans_p->data = (uint8_t *)&(data_buffer[transceiver_buffer_pos * CC1100_MAX_DATA_LENGTH]);
|
2010-11-23 11:37:13 +01:00
|
|
|
}
|
2012-03-01 22:12:25 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MODULE_CC110X
|
2013-06-22 05:11:53 +02:00
|
|
|
void receive_cc1100_packet(radio_packet_t *trans_p)
|
|
|
|
{
|
2012-03-01 22:12:25 +01:00
|
|
|
dINT();
|
|
|
|
trans_p->src = cc1100_packet_info->source;
|
|
|
|
trans_p->dst = cc1100_packet_info->destination;
|
|
|
|
trans_p->rssi = cc1100_packet_info->rssi;
|
|
|
|
trans_p->lqi = cc1100_packet_info->lqi;
|
|
|
|
trans_p->length = cc1100_payload_size;
|
2013-06-22 05:11:53 +02:00
|
|
|
memcpy((void *)&(data_buffer[transceiver_buffer_pos * PAYLOAD_SIZE]), cc1100_payload, CC1100_MAX_DATA_LENGTH);
|
2012-03-01 22:12:25 +01:00
|
|
|
eINT();
|
|
|
|
|
2013-06-22 05:11:53 +02:00
|
|
|
trans_p->data = (uint8_t *)&(data_buffer[transceiver_buffer_pos * CC1100_MAX_DATA_LENGTH]);
|
2012-03-01 22:12:25 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-11-26 10:23:46 +01:00
|
|
|
/*------------------------------------------------------------------------------------*/
|
|
|
|
/*
|
|
|
|
* @brief Sends a radio packet to the receiver
|
|
|
|
*
|
|
|
|
* @param t The transceiver device
|
|
|
|
* @param pkt Generic pointer to the packet
|
|
|
|
*
|
|
|
|
* @return 1 on success, 0 otherwise
|
|
|
|
*/
|
2013-06-22 05:11:53 +02:00
|
|
|
static uint8_t send_packet(transceiver_type_t t, void *pkt)
|
|
|
|
{
|
2010-11-24 11:20:27 +01:00
|
|
|
uint8_t res = 0;
|
2012-11-27 15:34:53 +01:00
|
|
|
#ifdef MODULE_CC110X
|
2012-03-01 22:12:25 +01:00
|
|
|
int snd_ret;
|
2012-11-07 15:11:10 +01:00
|
|
|
#endif
|
2013-06-22 05:11:53 +02:00
|
|
|
radio_packet_t p = *((radio_packet_t *)pkt);
|
|
|
|
|
2012-03-01 22:12:25 +01:00
|
|
|
#ifdef MODULE_CC110X_NG
|
2010-12-11 12:09:20 +01:00
|
|
|
cc110x_packet_t cc110x_pkt;
|
2012-03-01 22:12:25 +01:00
|
|
|
#endif
|
2010-11-26 10:23:46 +01:00
|
|
|
|
2013-06-22 05:11:53 +02:00
|
|
|
switch(t) {
|
2010-11-26 10:23:46 +01:00
|
|
|
case TRANSCEIVER_CC1100:
|
2012-03-01 22:12:25 +01:00
|
|
|
#ifdef MODULE_CC110X_NG
|
2010-12-11 12:09:20 +01:00
|
|
|
cc110x_pkt.length = p.length + CC1100_HEADER_LENGTH;
|
|
|
|
cc110x_pkt.address = p.dst;
|
|
|
|
cc110x_pkt.flags = 0;
|
|
|
|
memcpy(cc110x_pkt.data, p.data, p.length);
|
|
|
|
res = cc110x_send(&cc110x_pkt);
|
2012-03-01 22:12:25 +01:00
|
|
|
#else
|
|
|
|
memcpy(cc1100_pkt, p.data, p.length);
|
2013-06-22 05:11:53 +02:00
|
|
|
|
|
|
|
if((snd_ret = cc1100_send_csmaca(p.dst, 4, 0, (char *) cc1100_pkt, p.length)) < 0) {
|
2012-11-07 15:11:10 +01:00
|
|
|
DEBUG("snd_ret (%u) = %i\n", p.length, snd_ret);
|
2012-03-01 22:12:25 +01:00
|
|
|
res = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
res = 1;
|
|
|
|
}
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2012-03-01 22:12:25 +01:00
|
|
|
#endif
|
2010-11-26 10:23:46 +01:00
|
|
|
break;
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-11-26 10:23:46 +01:00
|
|
|
default:
|
|
|
|
puts("Unknown transceiver");
|
|
|
|
break;
|
|
|
|
}
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-11-23 11:37:13 +01:00
|
|
|
return res;
|
2010-11-19 20:10:09 +01:00
|
|
|
}
|
2010-11-24 21:45:38 +01:00
|
|
|
|
2010-11-26 10:23:46 +01:00
|
|
|
/*------------------------------------------------------------------------------------*/
|
|
|
|
/*
|
|
|
|
* @brief Sets the radio channel for any transceiver device
|
|
|
|
*
|
|
|
|
* @param t The transceiver device
|
|
|
|
* @param channel The channel to be set
|
|
|
|
*
|
|
|
|
* @return The radio channel AFTER calling the set command, -1 on error
|
|
|
|
*/
|
2013-06-22 05:11:53 +02:00
|
|
|
static int16_t set_channel(transceiver_type_t t, void *channel)
|
|
|
|
{
|
|
|
|
uint8_t c = *((uint8_t *)channel);
|
|
|
|
|
|
|
|
switch(t) {
|
2010-11-24 21:45:38 +01:00
|
|
|
case TRANSCEIVER_CC1100:
|
2012-03-01 22:12:25 +01:00
|
|
|
#ifdef MODULE_CC110X_NG
|
2010-12-11 12:09:20 +01:00
|
|
|
return cc110x_set_channel(c);
|
2012-03-01 22:12:25 +01:00
|
|
|
#else
|
|
|
|
return cc1100_set_channel(c);
|
|
|
|
#endif
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-11-24 21:45:38 +01:00
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-26 10:23:46 +01:00
|
|
|
/*
|
|
|
|
* @brief Get the radio channel of any transceiver device
|
|
|
|
*
|
|
|
|
* @param t The transceiver device
|
|
|
|
*
|
|
|
|
* @return The current radio channel of the transceiver, -1 on error
|
|
|
|
*/
|
2013-06-22 05:11:53 +02:00
|
|
|
static int16_t get_channel(transceiver_type_t t)
|
|
|
|
{
|
|
|
|
switch(t) {
|
2010-11-24 21:45:38 +01:00
|
|
|
case TRANSCEIVER_CC1100:
|
2012-03-01 22:12:25 +01:00
|
|
|
#ifdef MODULE_CC110X_NG
|
2010-12-11 12:09:20 +01:00
|
|
|
return cc110x_get_channel();
|
2012-03-01 22:12:25 +01:00
|
|
|
#else
|
|
|
|
return cc1100_get_channel();
|
|
|
|
#endif
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-11-24 21:45:38 +01:00
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2010-11-26 10:23:46 +01:00
|
|
|
/*------------------------------------------------------------------------------------*/
|
|
|
|
/*
|
|
|
|
* @brief Get the current address of transceiver device
|
|
|
|
*
|
|
|
|
* @param t The transciever device
|
|
|
|
*
|
|
|
|
* @return The configured address of the device, -1 on error
|
|
|
|
*/
|
2013-06-22 05:11:53 +02:00
|
|
|
static int16_t get_address(transceiver_type_t t)
|
|
|
|
{
|
|
|
|
switch(t) {
|
2010-11-26 10:23:46 +01:00
|
|
|
case TRANSCEIVER_CC1100:
|
2012-03-01 22:12:25 +01:00
|
|
|
#ifdef MODULE_CC110X_NG
|
2010-12-11 12:09:20 +01:00
|
|
|
return cc110x_get_address();
|
2012-03-01 22:12:25 +01:00
|
|
|
#else
|
|
|
|
return cc1100_get_address();
|
|
|
|
#endif
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-11-26 10:23:46 +01:00
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Set the address of the transceiver device
|
|
|
|
*
|
|
|
|
* @param t The transceiver device
|
|
|
|
* @param address Generic pointer to the address to set
|
|
|
|
*
|
|
|
|
* @return The new radio address of the device
|
|
|
|
*/
|
2013-06-22 05:11:53 +02:00
|
|
|
static int16_t set_address(transceiver_type_t t, void *address)
|
|
|
|
{
|
|
|
|
radio_address_t addr = *((radio_address_t *)address);
|
|
|
|
|
|
|
|
switch(t) {
|
2010-11-26 10:23:46 +01:00
|
|
|
case TRANSCEIVER_CC1100:
|
2012-03-01 22:12:25 +01:00
|
|
|
#ifdef MODULE_CC110X_NG
|
2010-12-11 12:09:20 +01:00
|
|
|
return cc110x_set_address(addr);
|
2012-03-01 22:12:25 +01:00
|
|
|
#else
|
|
|
|
return cc1100_set_address(addr);
|
|
|
|
#endif
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-11-26 10:23:46 +01:00
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2010-11-27 10:50:18 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @brief Set the transceiver device into monitor mode (disabling address check)
|
|
|
|
*
|
|
|
|
* @param t The transceiver device
|
|
|
|
* @param mode 1 for enabling monitor mode, 0 for enabling address check
|
|
|
|
*/
|
2013-06-22 05:11:53 +02:00
|
|
|
static void set_monitor(transceiver_type_t t, void *mode)
|
|
|
|
{
|
|
|
|
switch(t) {
|
2010-11-27 10:50:18 +01:00
|
|
|
case TRANSCEIVER_CC1100:
|
2012-03-01 22:12:25 +01:00
|
|
|
#ifdef MODULE_CC110X_NG
|
2013-06-22 05:11:53 +02:00
|
|
|
cc110x_set_monitor(*((uint8_t *)mode));
|
2012-03-01 22:12:25 +01:00
|
|
|
#endif
|
2010-11-27 10:50:18 +01:00
|
|
|
break;
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-11-27 10:50:18 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-12-02 15:38:28 +01:00
|
|
|
/*------------------------------------------------------------------------------------*/
|
2013-06-22 05:11:53 +02:00
|
|
|
static void powerdown(transceiver_type_t t)
|
|
|
|
{
|
|
|
|
switch(t) {
|
2010-12-02 15:38:28 +01:00
|
|
|
case TRANSCEIVER_CC1100:
|
2012-03-01 22:12:25 +01:00
|
|
|
#ifdef MODULE_CC110X_NG
|
2010-12-11 12:09:20 +01:00
|
|
|
cc110x_switch_to_pwd();
|
2012-03-01 22:12:25 +01:00
|
|
|
#endif
|
2010-12-02 15:38:28 +01:00
|
|
|
break;
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-12-02 15:38:28 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------------------*/
|
2013-06-22 05:11:53 +02:00
|
|
|
static void switch_to_rx(transceiver_type_t t)
|
|
|
|
{
|
|
|
|
switch(t) {
|
2010-12-02 15:38:28 +01:00
|
|
|
case TRANSCEIVER_CC1100:
|
2012-03-01 22:12:25 +01:00
|
|
|
#ifdef MODULE_CC110X_NG
|
2010-12-11 12:09:20 +01:00
|
|
|
cc110x_switch_to_rx();
|
2012-03-01 22:12:25 +01:00
|
|
|
#endif
|
2010-12-02 15:38:28 +01:00
|
|
|
break;
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2010-12-02 15:38:28 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-02-08 17:14:50 +01:00
|
|
|
|
|
|
|
#ifdef DBG_IGNORE
|
2013-06-22 05:11:53 +02:00
|
|
|
static void ignore_add(transceiver_type_t t, void *address)
|
|
|
|
{
|
|
|
|
radio_address_t addr = *((radio_address_t *)address);
|
|
|
|
|
|
|
|
switch(t) {
|
2012-02-08 17:14:50 +01:00
|
|
|
case TRANSCEIVER_CC1100:
|
2012-02-16 12:34:24 +01:00
|
|
|
cc110x_add_ignored(addr);
|
2012-02-08 17:14:50 +01:00
|
|
|
break;
|
2013-06-22 05:11:53 +02:00
|
|
|
|
2012-02-08 17:14:50 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|