1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Fix coding conventions in sys/transceiver/transceiver.c

This commit is contained in:
Martin Lenders 2014-01-31 14:36:09 +01:00 committed by Martin Lenders
parent 049838841a
commit 1e4badf85a

View File

@ -86,10 +86,10 @@ static volatile uint8_t rx_buffer_pos = 0;
static volatile uint8_t transceiver_buffer_pos = 0;
#ifdef MODULE_CC110X
void *cc1100_payload;
int cc1100_payload_size;
packet_info_t *cc1100_packet_info;
uint8_t cc1100_pkt[CC1100_MAX_DATA_LENGTH];
void *cc1100_payload;
int cc1100_payload_size;
packet_info_t *cc1100_packet_info;
uint8_t cc1100_pkt[CC1100_MAX_DATA_LENGTH];
#endif
@ -158,6 +158,7 @@ void transceiver_init(transceiver_type_t t)
reg[i].transceivers = TRANSCEIVER_NONE;
reg[i].pid = 0;
}
/* check if a non defined bit is set */
if (t & ~(TRANSCEIVER_CC1100 | TRANSCEIVER_CC2420 | TRANSCEIVER_MC1322X | TRANSCEIVER_NATIVE | TRANSCEIVER_AT86RF231)) {
puts("Invalid transceiver type");
@ -175,11 +176,13 @@ int transceiver_start(void)
if (transceiver_pid < 0) {
puts("Error creating transceiver thread");
}
#ifdef MODULE_CC110X_NG
else if (transceivers & TRANSCEIVER_CC1100) {
DEBUG("transceiver: Transceiver started for CC1100\n");
cc110x_init(transceiver_pid);
}
#endif
#ifdef MODULE_CC110X
else if (transceivers & TRANSCEIVER_CC1100) {
@ -187,28 +190,33 @@ int transceiver_start(void)
cc1100_init();
cc1100_set_packet_monitor(cc1100_packet_monitor);
}
#endif
#ifdef MODULE_CC2420
else if(transceivers & TRANSCEIVER_CC2420) {
else if (transceivers & TRANSCEIVER_CC2420) {
DEBUG("transceiver: Transceiver started for CC2420\n");
cc2420_init(transceiver_pid);
}
#endif
#ifdef MODULE_AT86RF231
else if(transceivers & TRANSCEIVER_AT86RF231) {
else if (transceivers & TRANSCEIVER_AT86RF231) {
DEBUG("transceiver: Transceiver started for AT86RF231\n");
at86rf231_init(transceiver_pid);
}
#endif
#ifdef MODULE_MC1322X
else if (transceivers & TRANSCEIVER_MC1322X) {
maca_init();
}
#endif
#ifdef MODULE_NATIVENET
else if (transceivers & TRANSCEIVER_NATIVE) {
nativenet_init(transceiver_pid);
}
#endif
return transceiver_pid;
}
@ -220,8 +228,8 @@ uint8_t transceiver_register(transceiver_type_t t, int pid)
/* find pid in registered threads or first unused space */
for (i = 0; ((i < TRANSCEIVER_MAX_REGISTERED) &&
(reg[i].pid != pid) &&
(reg[i].transceivers != TRANSCEIVER_NONE)); i++);
(reg[i].pid != pid) &&
(reg[i].transceivers != TRANSCEIVER_NONE)); i++);
if (i >= TRANSCEIVER_MAX_REGISTERED) {
return ENOMEM;
@ -256,7 +264,7 @@ void run(void)
cmd = (transceiver_command_t *) m.content.ptr;
DEBUG("transceiver: Transceiver: Message received, type: %02X\n", m.type);
switch(m.type) {
switch (m.type) {
case RCV_PKT_CC1020:
case RCV_PKT_CC1100:
case RCV_PKT_CC2420:
@ -265,6 +273,7 @@ void run(void)
case RCV_PKT_AT86RF231:
receive_packet(m.type, m.content.value);
break;
case SND_PKT:
response = send_packet(cmd->transceivers, cmd->data);
m.content.value = response;
@ -302,17 +311,20 @@ void run(void)
case SWITCH_RX:
switch_to_rx(cmd->transceivers);
break;
case GET_PAN:
*((int32_t *) cmd->data) = get_pan(cmd->transceivers);
msg_reply(&m, &m);
break;
case SET_PAN:
*((int32_t *) cmd->data) = set_pan(cmd->transceivers, cmd->data);
msg_reply(&m, &m);
break;
#ifdef DBG_IGNORE
case DBG_IGN:
*((int16_t*) cmd->data) = ignore_add(cmd->transceivers, cmd->data);
*((int16_t *) cmd->data) = ignore_add(cmd->transceivers, cmd->data);
msg_reply(&m, &m);
break;
#endif
@ -341,7 +353,7 @@ static void receive_packet(uint16_t type, uint8_t pos)
DEBUG("Packet received\n");
switch(type) {
switch (type) {
case RCV_PKT_CC1020:
t = TRANSCEIVER_CC1020;
break;
@ -349,18 +361,23 @@ static void receive_packet(uint16_t type, uint8_t pos)
case RCV_PKT_CC1100:
t = TRANSCEIVER_CC1100;
break;
case RCV_PKT_CC2420:
t = TRANSCEIVER_CC2420;
break;
case RCV_PKT_MC1322X:
t = TRANSCEIVER_MC1322X;
break;
case RCV_PKT_NATIVE:
t = TRANSCEIVER_NATIVE;
break;
case RCV_PKT_NATIVE:
t = TRANSCEIVER_NATIVE;
break;
case RCV_PKT_AT86RF231:
t = TRANSCEIVER_AT86RF231;
break;
default:
t = TRANSCEIVER_NONE;
break;
@ -427,14 +444,18 @@ static void receive_packet(uint16_t type, uint8_t pos)
puts("Invalid transceiver type");
return;
}
#ifdef DBG_IGNORE
for (uint8_t i = 0; (i < MAX_IGNORED_ADDR) && (ignored_addr[i]); i++) {
DEBUG("check if source (%u) is ignored -> %u\n", trans_p->src, ignored_addr[i]);
if (trans_p->src == ignored_addr[i]) {
DEBUG("ignored packet from %" PRIu16 "\n", trans_p->src);
return;
}
}
#endif
}
@ -444,7 +465,7 @@ static void receive_packet(uint16_t type, uint8_t pos)
while (reg[i].transceivers != TRANSCEIVER_NONE) {
if (reg[i].transceivers & t) {
m.content.ptr = (char *) & (transceiver_buffer[transceiver_buffer_pos]);
m.content.ptr = (char *) &(transceiver_buffer[transceiver_buffer_pos]);
DEBUG("transceiver: Notify thread %i\n", reg[i].pid);
if (msg_send(&m, reg[i].pid, false) && (m.type != ENOBUFFER)) {
@ -474,10 +495,10 @@ static void receive_cc110x_packet(radio_packet_t *trans_p)
trans_p->rssi = cc110x_rx_buffer[rx_buffer_pos].rssi;
trans_p->lqi = cc110x_rx_buffer[rx_buffer_pos].lqi;
trans_p->length = p.length - CC1100_HEADER_LENGTH;
memcpy((void *)&(data_buffer[transceiver_buffer_pos * PAYLOAD_SIZE]), p.data, CC1100_MAX_DATA_LENGTH);
memcpy((void *) &(data_buffer[transceiver_buffer_pos * PAYLOAD_SIZE]), p.data, CC1100_MAX_DATA_LENGTH);
eINT();
trans_p->data = (uint8_t *)&(data_buffer[transceiver_buffer_pos * CC1100_MAX_DATA_LENGTH]);
trans_p->data = (uint8_t *) &(data_buffer[transceiver_buffer_pos * CC1100_MAX_DATA_LENGTH]);
DEBUG("transceiver: Packet %p (%p) was from %hu to %hu, size: %u\n", trans_p, trans_p->data, trans_p->src, trans_p->dst, trans_p->length);
}
#endif
@ -491,16 +512,17 @@ void receive_cc1100_packet(radio_packet_t *trans_p)
trans_p->rssi = cc1100_packet_info->rssi;
trans_p->lqi = cc1100_packet_info->lqi;
trans_p->length = cc1100_payload_size;
memcpy((void *)&(data_buffer[transceiver_buffer_pos * PAYLOAD_SIZE]), cc1100_payload, CC1100_MAX_DATA_LENGTH);
memcpy((void *) &(data_buffer[transceiver_buffer_pos * PAYLOAD_SIZE]), cc1100_payload, CC1100_MAX_DATA_LENGTH);
eINT();
trans_p->data = (uint8_t *)&(data_buffer[transceiver_buffer_pos * CC1100_MAX_DATA_LENGTH]);
trans_p->data = (uint8_t *) &(data_buffer[transceiver_buffer_pos * CC1100_MAX_DATA_LENGTH]);
}
#endif
#ifdef MODULE_CC2420
void receive_cc2420_packet(radio_packet_t *trans_p) {
void receive_cc2420_packet(radio_packet_t *trans_p)
{
DEBUG("transceiver: Handling CC2420 packet\n");
dINT();
cc2420_packet_t p = cc2420_rx_buffer[rx_buffer_pos];
@ -519,23 +541,25 @@ void receive_cc2420_packet(radio_packet_t *trans_p) {
#endif
#ifdef MODULE_MC1322X
void receive_mc1322x_packet(radio_packet_t *trans_p) {
maca_packet_t* maca_pkt;
void receive_mc1322x_packet(radio_packet_t *trans_p)
{
maca_packet_t *maca_pkt;
dINT();
maca_pkt = maca_get_rx_packet ();
maca_pkt = maca_get_rx_packet();
trans_p->lqi = maca_pkt->lqi;
trans_p->length = maca_pkt->length;
memcpy((void*) &(data_buffer[transceiver_buffer_pos * PAYLOAD_SIZE]), maca_pkt->data, MACA_MAX_PAYLOAD_SIZE);
maca_free_packet( maca_pkt );
memcpy((void *) &(data_buffer[transceiver_buffer_pos * PAYLOAD_SIZE]), maca_pkt->data, MACA_MAX_PAYLOAD_SIZE);
maca_free_packet(maca_pkt);
eINT();
trans_p->data = (uint8_t*) &(data_buffer[transceiver_buffer_pos * MACA_MAX_PAYLOAD_SIZE]);
trans_p->data = (uint8_t *) &(data_buffer[transceiver_buffer_pos * MACA_MAX_PAYLOAD_SIZE]);
}
#endif
#ifdef MODULE_NATIVENET
void receive_nativenet_packet(radio_packet_t *trans_p) {
void receive_nativenet_packet(radio_packet_t *trans_p)
{
unsigned state;
radio_packet_t *p = &_nativenet_rx_buffer[rx_buffer_pos].packet;
@ -546,7 +570,7 @@ void receive_nativenet_packet(radio_packet_t *trans_p) {
memcpy(trans_p, p, sizeof(radio_packet_t));
memcpy(&(data_buffer[transceiver_buffer_pos * PAYLOAD_SIZE]), p->data, p->length);
trans_p->data = (uint8_t*) &(data_buffer[transceiver_buffer_pos * PAYLOAD_SIZE]);
trans_p->data = (uint8_t *) &(data_buffer[transceiver_buffer_pos * PAYLOAD_SIZE]);
DEBUG("Packet %p was from %" PRIu16 " to %" PRIu16 ", size: %" PRIu8 "\n", trans_p, trans_p->src, trans_p->dst, trans_p->length);
@ -556,7 +580,8 @@ void receive_nativenet_packet(radio_packet_t *trans_p) {
#endif
#ifdef MODULE_AT86RF231
void receive_at86rf231_packet(radio_packet_t *trans_p) {
void receive_at86rf231_packet(radio_packet_t *trans_p)
{
DEBUG("Handling AT86RF231 packet\n");
dINT();
at86rf231_packet_t p = at86rf231_rx_buffer[rx_buffer_pos];
@ -591,7 +616,7 @@ static int8_t send_packet(transceiver_type_t t, void *pkt)
cc110x_packet_t cc110x_pkt;
#endif
#ifdef MODULE_MC1322X
maca_packet_t* maca_pkt = maca_get_free_packet();
maca_packet_t *maca_pkt = maca_get_free_packet();
#endif
#ifdef MODULE_CC2420
@ -603,6 +628,7 @@ static int8_t send_packet(transceiver_type_t t, void *pkt)
#endif
DEBUG("transceiver: Send packet to %" PRIu16 "\n", p.dst);
switch (t) {
case TRANSCEIVER_CC1100:
#ifdef MODULE_CC110X_NG
@ -621,6 +647,7 @@ static int8_t send_packet(transceiver_type_t t, void *pkt)
#endif
break;
#ifdef MODULE_CC2420
case TRANSCEIVER_CC2420:
cc2420_pkt.frame.payload_len = p.length;
cc2420_pkt.frame.dest_addr[1] = (uint8_t)(p.dst >> 8);
@ -640,7 +667,7 @@ static int8_t send_packet(transceiver_type_t t, void *pkt)
case TRANSCEIVER_MC1322X:
maca_pkt->length = p.length;
memcpy(maca_pkt->data, p.data, p.length);
maca_set_tx_packet( maca_pkt );
maca_set_tx_packet(maca_pkt);
res = 1;
break;
#endif
@ -665,6 +692,7 @@ static int8_t send_packet(transceiver_type_t t, void *pkt)
res = at86rf231_send(&at86rf231_pkt);
break;
#endif
default:
puts("Unknown transceiver");
break;
@ -686,7 +714,7 @@ static int32_t set_channel(transceiver_type_t t, void *channel)
{
uint8_t c = *((uint8_t *)channel);
switch(t) {
switch (t) {
case TRANSCEIVER_CC1100:
#ifdef MODULE_CC110X_NG
return cc110x_set_channel(c);
@ -696,22 +724,27 @@ static int32_t set_channel(transceiver_type_t t, void *channel)
return -1;
#endif
#ifdef MODULE_CC2420
case TRANSCEIVER_CC2420:
return cc2420_set_channel(c);
#endif
#ifdef MODULE_MC1322X
case TRANSCEIVER_MC1322X:
maca_set_channel(c);
return c; ///< TODO: should be changed! implement get channel
return c; ///< TODO: should be changed!implement get channel
#endif
#ifdef MODULE_NATIVENET
case TRANSCEIVER_NATIVE:
return nativenet_set_channel(c);
#endif
#ifdef MODULE_AT86RF231
case TRANSCEIVER_AT86RF231:
return at86rf231_set_channel(c);
#endif
default:
return -1;
}
@ -726,7 +759,7 @@ static int32_t set_channel(transceiver_type_t t, void *channel)
*/
static int32_t get_channel(transceiver_type_t t)
{
switch(t) {
switch (t) {
case TRANSCEIVER_CC1100:
#ifdef MODULE_CC110X_NG
return cc110x_get_channel();
@ -736,22 +769,27 @@ static int32_t get_channel(transceiver_type_t t)
return -1;
#endif
#ifdef MODULE_CC2420
case TRANSCEIVER_CC2420:
return cc2420_get_channel();
#endif
#ifdef MODULE_MC1322X
case TRANSCEIVER_MC1322X:
///< TODO:implement return maca_get_channel();
return -1;
#endif
#ifdef MODULE_NATIVENET
case TRANSCEIVER_NATIVE:
return nativenet_get_channel();
#endif
#ifdef MODULE_AT86RF231
case TRANSCEIVER_AT86RF231:
return at86rf231_get_channel();
#endif
default:
return -1;
}
@ -766,25 +804,32 @@ static int32_t get_channel(transceiver_type_t t)
*
* @return The pan AFTER calling the set command, -1 on error
*/
static int32_t set_pan(transceiver_type_t t, void *pan) {
uint16_t c = *((uint16_t*) pan);
static int32_t set_pan(transceiver_type_t t, void *pan)
{
uint16_t c = *((uint16_t *) pan);
switch (t) {
#ifdef MODULE_CC2420
case TRANSCEIVER_CC2420:
return cc2420_set_pan(c);
#endif
#ifdef MODULE_NATIVENET
case TRANSCEIVER_NATIVE:
return nativenet_set_pan(c);
#endif
#ifdef MODULE_AT86RF231
case TRANSCEIVER_AT86RF231:
return at86rf231_set_pan(c);
#endif
#ifdef MODULE_MC1322X
case TRANSCEIVER_MC1322X:
return maca_set_pan(c);
#endif
default:
/* get rid of compiler warning about unused variable */
(void) c;
@ -799,24 +844,30 @@ static int32_t set_pan(transceiver_type_t t, void *pan) {
*
* @return The current pan of the transceiver, -1 on error
*/
static int32_t get_pan(transceiver_type_t t) {
static int32_t get_pan(transceiver_type_t t)
{
switch (t) {
#ifdef MODULE_CC2420
case TRANSCEIVER_CC2420:
return cc2420_get_pan();
#endif
#ifdef MODULE_NATIVENET
case TRANSCEIVER_NATIVE:
return nativenet_get_pan();
#endif
#ifdef MODULE_AT86RF231
case TRANSCEIVER_AT86RF231:
return at86rf231_get_pan();
#endif
#ifdef MODULE_MC1322X
case TRANSCEIVER_MC1322X:
return maca_get_pan();
#endif
default:
return -1;
}
@ -833,7 +884,7 @@ static int32_t get_pan(transceiver_type_t t) {
*/
static radio_address_t get_address(transceiver_type_t t)
{
switch(t) {
switch (t) {
case TRANSCEIVER_CC1100:
#ifdef MODULE_CC110X_NG
return cc110x_get_address();
@ -843,21 +894,26 @@ static radio_address_t get_address(transceiver_type_t t)
return 0; /* XXX see TODO above */
#endif
#ifdef MODULE_CC2420
case TRANSCEIVER_CC2420:
return cc2420_get_address();
#endif
#ifdef MODULE_MC1322X
case TRANSCEIVER_MC1322X:
return maca_get_address();
#endif
#ifdef MODULE_NATIVENET
case TRANSCEIVER_NATIVE:
return nativenet_get_address();
#endif
#ifdef MODULE_AT86RF231
case TRANSCEIVER_AT86RF231:
return at86rf231_get_address();
#endif
default:
return 0; /* XXX see TODO above */
}
@ -877,7 +933,7 @@ static radio_address_t set_address(transceiver_type_t t, void *address)
{
radio_address_t addr = *((radio_address_t *)address);
switch(t) {
switch (t) {
case TRANSCEIVER_CC1100:
#ifdef MODULE_CC110X_NG
return cc110x_set_address(addr);
@ -887,21 +943,26 @@ static radio_address_t set_address(transceiver_type_t t, void *address)
return 0; /* XXX see TODO above */
#endif
#ifdef MODULE_CC2420
case TRANSCEIVER_CC2420:
return cc2420_set_address(addr);
#endif
#ifdef MODULE_MC1322X
case TRANSCEIVER_MC1322X:
return maca_set_address(addr);
#endif
#ifdef MODULE_NATIVENET
case TRANSCEIVER_NATIVE:
return nativenet_set_address(addr);
#endif
#ifdef MODULE_AT86RF231
case TRANSCEIVER_AT86RF231:
return at86rf231_set_address(addr);
#endif
default:
return 0; /* XXX see TODO above */
}
@ -917,26 +978,31 @@ static void set_monitor(transceiver_type_t t, void *mode)
{
(void) mode;
switch(t) {
switch (t) {
#ifdef MODULE_CC110X_NG
case TRANSCEIVER_CC1100:
cc110x_set_monitor(*((uint8_t *)mode));
break;
#endif
#ifdef MODULE_CC2420
case TRANSCEIVER_CC2420:
cc2420_set_monitor(*((uint8_t*) mode));
cc2420_set_monitor(*((uint8_t *) mode));
break;
#endif
#ifdef MODULE_NATIVENET
case TRANSCEIVER_NATIVE:
nativenet_set_monitor(*((uint8_t*) mode));
nativenet_set_monitor(*((uint8_t *) mode));
break;
#endif
#ifdef MODULE_AT86RF231
case TRANSCEIVER_AT86RF231:
at86rf231_set_monitor(*((uint8_t*) mode));
at86rf231_set_monitor(*((uint8_t *) mode));
#endif
default:
break;
}
@ -957,22 +1023,26 @@ void cc1100_packet_monitor(void *payload, int payload_size, protocol_t protocol,
/*------------------------------------------------------------------------------------*/
static void powerdown(transceiver_type_t t)
{
switch(t) {
switch (t) {
#ifdef MODULE_CC110X_NG
case TRANSCEIVER_CC1100:
cc110x_switch_to_pwd();
break;
#endif
#ifdef MODULE_MC1322X
case TRANSCEIVER_MC1322X:
maca_off();
break;
#endif
#ifdef MODULE_NATIVENET
case TRANSCEIVER_NATIVE:
nativenet_powerdown();
break;
#endif
default:
break;
}
@ -981,27 +1051,32 @@ static void powerdown(transceiver_type_t t)
/*------------------------------------------------------------------------------------*/
static void switch_to_rx(transceiver_type_t t)
{
switch(t) {
switch (t) {
#ifdef MODULE_CC110X_NG
case TRANSCEIVER_CC1100:
cc110x_switch_to_rx();
break;
#endif
#ifdef MODULE_CC2420
case TRANSCEIVER_CC2420:
cc2420_switch_to_rx();
break;
#endif
#ifdef MODULE_NATIVENET
case TRANSCEIVER_NATIVE:
nativenet_switch_to_rx();
break;
#endif
#ifdef MODULE_AT86RF231
case TRANSCEIVER_AT86RF231:
at86rf231_switch_to_rx();
#endif
default:
break;
}
@ -1020,6 +1095,7 @@ static int16_t ignore_add(transceiver_type_t transceiver, void *address)
return i;
}
}
return -1;
}
#endif