Fixed to match the Contiki code style

This commit is contained in:
adamdunkels 2007-11-26 15:31:32 +00:00
parent 6012ef9c21
commit 52a8e8d16b

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: tdma_mac.c,v 1.2 2007/09/18 10:37:17 fros4943 Exp $ * $Id: tdma_mac.c,v 1.3 2007/11/26 15:31:32 adamdunkels Exp $
*/ */
#include "contiki.h" #include "contiki.h"
@ -96,20 +96,17 @@ transmitter(struct rtimer *t, void *ptr)
slot_start = period_start + MY_SLOT*SLOT_LENGTH; slot_start = period_start + MY_SLOT*SLOT_LENGTH;
/* Check if we are inside our slot */ /* Check if we are inside our slot */
if (now < slot_start || if(now < slot_start ||
now > slot_start + SLOT_LENGTH - GUARD_PERIOD) now > slot_start + SLOT_LENGTH - GUARD_PERIOD) {
{
PRINTF("TIMER We are outside our slot: %u != [%u,%u]\n", now, slot_start, slot_start + SLOT_LENGTH); PRINTF("TIMER We are outside our slot: %u != [%u,%u]\n", now, slot_start, slot_start + SLOT_LENGTH);
while (now > slot_start + SLOT_LENGTH - GUARD_PERIOD) while(now > slot_start + SLOT_LENGTH - GUARD_PERIOD) {
{
slot_start += PERIOD_LENGTH; slot_start += PERIOD_LENGTH;
} }
PRINTF("TIMER Rescheduling until %u\n", slot_start); PRINTF("TIMER Rescheduling until %u\n", slot_start);
r = rtimer_set(&rtimer, slot_start, 1, r = rtimer_set(&rtimer, slot_start, 1,
(void (*)(struct rtimer *, void *))transmitter, NULL); (void (*)(struct rtimer *, void *))transmitter, NULL);
if(r) if(r) {
{
PRINTF("TIMER Error #1: %d\n", r); PRINTF("TIMER Error #1: %d\n", r);
} }
@ -117,19 +114,14 @@ transmitter(struct rtimer *t, void *ptr)
} }
/* Transmit queued packets */ /* Transmit queued packets */
while (nextsend != freeslot) while(nextsend != freeslot) {
{
PRINTF("RADIO Transmitting packet #%i\n", id[nextsend]); PRINTF("RADIO Transmitting packet #%i\n", id[nextsend]);
if(!radio->send( if(!radio->send(queuebuf_dataptr(data[nextsend]),
queuebuf_dataptr(data[nextsend]), queuebuf_datalen(data[nextsend]))) {
queuebuf_datalen(data[nextsend])))
{
sent_counter++; sent_counter++;
PRINTF("RADIO Transmit OK for #%i, total=%i\n", id[nextsend], sent_counter); PRINTF("RADIO Transmit OK for #%i, total=%i\n", id[nextsend], sent_counter);
DLEDS_TOGGLE(LEDS_GREEN); DLEDS_TOGGLE(LEDS_GREEN);
} } else {
else
{
PRINTF("RADIO Transmit failed for #%i, total=%i\n", id[nextsend], sent_counter); PRINTF("RADIO Transmit failed for #%i, total=%i\n", id[nextsend], sent_counter);
DLEDS_TOGGLE(LEDS_RED); DLEDS_TOGGLE(LEDS_RED);
} }
@ -137,8 +129,7 @@ transmitter(struct rtimer *t, void *ptr)
nextsend = (nextsend + 1) % NUM_PACKETS; nextsend = (nextsend + 1) % NUM_PACKETS;
/* Recalculate new slot */ /* Recalculate new slot */
if (RTIMER_NOW() > slot_start + SLOT_LENGTH - GUARD_PERIOD) if(RTIMER_NOW() > slot_start + SLOT_LENGTH - GUARD_PERIOD) {
{
PRINTF("TIMER No more time to transmit\n"); PRINTF("TIMER No more time to transmit\n");
break; break;
} }
@ -149,8 +140,7 @@ transmitter(struct rtimer *t, void *ptr)
PRINTF("TIMER Rescheduling until %u\n", slot_start); PRINTF("TIMER Rescheduling until %u\n", slot_start);
r = rtimer_set(&rtimer, slot_start, 1, r = rtimer_set(&rtimer, slot_start, 1,
(void (*)(struct rtimer *, void *))transmitter, NULL); (void (*)(struct rtimer *, void *))transmitter, NULL);
if(r) if(r) {
{
PRINTF("TIMER Error #2: %d\n", r); PRINTF("TIMER Error #2: %d\n", r);
} }
@ -164,8 +154,7 @@ send(void)
id_counter++; id_counter++;
/* Clean up already sent packets */ /* Clean up already sent packets */
while (lastqueued != nextsend) while(lastqueued != nextsend) {
{
PRINTF("BUFFER Cleaning up packet #%i\n", id[lastqueued]); PRINTF("BUFFER Cleaning up packet #%i\n", id[lastqueued]);
queuebuf_free(data[lastqueued]); queuebuf_free(data[lastqueued]);
data[lastqueued] = NULL; data[lastqueued] = NULL;
@ -173,8 +162,7 @@ send(void)
lastqueued = (lastqueued + 1) % NUM_PACKETS; lastqueued = (lastqueued + 1) % NUM_PACKETS;
} }
if ((freeslot + 1) % NUM_PACKETS == lastqueued) if((freeslot + 1) % NUM_PACKETS == lastqueued) {
{
PRINTF("BUFFER Buffer full, dropping packet #%i\n", (id_counter+1)); PRINTF("BUFFER Buffer full, dropping packet #%i\n", (id_counter+1));
return UIP_FW_DROPPED; return UIP_FW_DROPPED;
} }
@ -182,8 +170,7 @@ send(void)
/* Allocate queue buf for packet */ /* Allocate queue buf for packet */
data[freeslot] = queuebuf_new_from_rimebuf(); data[freeslot] = queuebuf_new_from_rimebuf();
id[freeslot] = id_counter; id[freeslot] = id_counter;
if (data[freeslot] == NULL) if(data[freeslot] == NULL) {
{
PRINTF("BUFFER Queuebuffer full, dropping packet #%i\n", id[freeslot]); PRINTF("BUFFER Queuebuffer full, dropping packet #%i\n", id[freeslot]);
return UIP_FW_DROPPED; return UIP_FW_DROPPED;
} }
@ -191,17 +178,13 @@ send(void)
freeslot = (freeslot + 1) % NUM_PACKETS; freeslot = (freeslot + 1) % NUM_PACKETS;
if (!timer_on) if(!timer_on) {
{
PRINTF("TIMER Starting timer\n"); PRINTF("TIMER Starting timer\n");
r = rtimer_set(&rtimer, RTIMER_NOW() + RTIMER_SECOND, 1, r = rtimer_set(&rtimer, RTIMER_NOW() + RTIMER_SECOND, 1,
(void (*)(struct rtimer *, void *))transmitter, NULL); (void (*)(struct rtimer *, void *))transmitter, NULL);
if(r) if(r) {
{
PRINTF("TIMER Error #3: %d\n", r); PRINTF("TIMER Error #3: %d\n", r);
} } else {
else
{
timer_on = 1; timer_on = 1;
} }
} }
@ -247,8 +230,7 @@ void
tdma_mac_init(const struct radio_driver *d) tdma_mac_init(const struct radio_driver *d)
{ {
int i; int i;
for (i=0; i < NUM_PACKETS; i++) for(i = 0; i < NUM_PACKETS; i++) {
{
data[i] = NULL; data[i] = NULL;
} }