From 833dc89f7c76c07c17c26ad017d0c89837f6285a Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 16 Jul 2016 17:07:05 +0100 Subject: [PATCH 1/4] Fix code style --- cpu/cc2538/dev/cc2538-rf.c | 47 +++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/cpu/cc2538/dev/cc2538-rf.c b/cpu/cc2538/dev/cc2538-rf.c index 52708e0ca..dfbdfb699 100644 --- a/cpu/cc2538/dev/cc2538-rf.c +++ b/cpu/cc2538/dev/cc2538-rf.c @@ -185,8 +185,8 @@ get_channel() { uint8_t chan = REG(RFCORE_XREG_FREQCTRL) & RFCORE_XREG_FREQCTRL_FREQ; - return ((chan - CC2538_RF_CHANNEL_MIN) / CC2538_RF_CHANNEL_SPACING - + CC2538_RF_CHANNEL_MIN); + return (chan - CC2538_RF_CHANNEL_MIN) / CC2538_RF_CHANNEL_SPACING + + CC2538_RF_CHANNEL_MIN; } /*---------------------------------------------------------------------------*/ /** @@ -207,14 +207,15 @@ set_channel(uint8_t channel) } /* Changes to FREQCTRL take effect after the next recalibration */ - + /* If we are off, save state, otherwise switch off and save state */ if((REG(RFCORE_XREG_FSMSTAT0) & RFCORE_XREG_FSMSTAT0_FSM_FFCTRL_STATE) != 0) { was_on = 1; off(); } - REG(RFCORE_XREG_FREQCTRL) = (CC2538_RF_CHANNEL_MIN - + (channel - CC2538_RF_CHANNEL_MIN) * CC2538_RF_CHANNEL_SPACING); + REG(RFCORE_XREG_FREQCTRL) = (CC2538_RF_CHANNEL_MIN + + (channel - CC2538_RF_CHANNEL_MIN) * + CC2538_RF_CHANNEL_SPACING); /* switch radio back on only if radio was on before - otherwise will turn on radio foor sleepy nodes */ if(was_on) { on(); @@ -222,7 +223,7 @@ set_channel(uint8_t channel) rf_channel = channel; - return (int8_t) channel; + return (int8_t)channel; } /*---------------------------------------------------------------------------*/ static radio_value_t @@ -351,15 +352,15 @@ static void set_poll_mode(uint8_t enable) { poll_mode = enable; - + if(enable) { mac_timer_init(); - REG(RFCORE_XREG_RFIRQM0) &= ~RFCORE_XREG_RFIRQM0_FIFOP; // mask out FIFOP interrupt source - REG(RFCORE_SFR_RFIRQF0) &= ~RFCORE_SFR_RFIRQF0_FIFOP; // clear pending FIFOP interrupt - nvic_interrupt_disable(NVIC_INT_RF_RXTX); // disable RF interrupts + REG(RFCORE_XREG_RFIRQM0) &= ~RFCORE_XREG_RFIRQM0_FIFOP; /* mask out FIFOP interrupt source */ + REG(RFCORE_SFR_RFIRQF0) &= ~RFCORE_SFR_RFIRQF0_FIFOP; /* clear pending FIFOP interrupt */ + nvic_interrupt_disable(NVIC_INT_RF_RXTX); /* disable RF interrupts */ } else { - REG(RFCORE_XREG_RFIRQM0) |= RFCORE_XREG_RFIRQM0_FIFOP; // enable FIFOP interrupt source - nvic_interrupt_enable(NVIC_INT_RF_RXTX); // enable RF interrupts + REG(RFCORE_XREG_RFIRQM0) |= RFCORE_XREG_RFIRQM0_FIFOP; /* enable FIFOP interrupt source */ + nvic_interrupt_enable(NVIC_INT_RF_RXTX); /* enable RF interrupts */ } } /*---------------------------------------------------------------------------*/ @@ -527,7 +528,7 @@ init(void) */ udma_set_channel_src(CC2538_RF_CONF_RX_DMA_CHAN, RFCORE_SFR_RFDATA); } - + set_poll_mode(poll_mode); process_start(&cc2538_rf_process, NULL); @@ -782,10 +783,10 @@ read(void *buf, unsigned short bufsize) } } } - + CC2538_RF_CSP_ISFLUSHRX(); - return (len); + return len; } /*---------------------------------------------------------------------------*/ static int @@ -799,9 +800,9 @@ receiving_packet(void) * * FSMSTAT1 & (TX_ACTIVE | SFD) == SFD <=> receiving */ - return ((REG(RFCORE_XREG_FSMSTAT1) - & (RFCORE_XREG_FSMSTAT1_TX_ACTIVE | RFCORE_XREG_FSMSTAT1_SFD)) - == RFCORE_XREG_FSMSTAT1_SFD); + return (REG(RFCORE_XREG_FSMSTAT1) + & (RFCORE_XREG_FSMSTAT1_TX_ACTIVE | RFCORE_XREG_FSMSTAT1_SFD)) + == RFCORE_XREG_FSMSTAT1_SFD; } /*---------------------------------------------------------------------------*/ static int @@ -809,7 +810,7 @@ pending_packet(void) { PRINTF("RF: Pending\n"); - return (REG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_FIFOP); + return REG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_FIFOP; } /*---------------------------------------------------------------------------*/ static radio_result_t @@ -963,15 +964,15 @@ get_object(radio_param_t param, void *dest, size_t size) return RADIO_RESULT_OK; } - + if(param == RADIO_PARAM_LAST_PACKET_TIMESTAMP) { if(size != sizeof(rtimer_clock_t) || !dest) { return RADIO_RESULT_INVALID_VALUE; } - *(rtimer_clock_t*)dest = get_sfd_timestamp(); + *(rtimer_clock_t *)dest = get_sfd_timestamp(); return RADIO_RESULT_OK; } - + return RADIO_RESULT_NOT_SUPPORTED; } /*---------------------------------------------------------------------------*/ @@ -1075,7 +1076,7 @@ void cc2538_rf_rx_tx_isr(void) { ENERGEST_ON(ENERGEST_TYPE_IRQ); - + if(!poll_mode) { process_poll(&cc2538_rf_process); } From 6ef9509dfb87b249a019cd34892eec2844a38742 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 16 Jul 2016 17:07:52 +0100 Subject: [PATCH 2/4] Change get_sfd_timestamp() to static We also move the function to a different location so we won't have to provide the prototype separately --- cpu/cc2538/dev/cc2538-rf.c | 56 +++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/cpu/cc2538/dev/cc2538-rf.c b/cpu/cc2538/dev/cc2538-rf.c index dfbdfb699..17cbf7a1d 100644 --- a/cpu/cc2538/dev/cc2538-rf.c +++ b/cpu/cc2538/dev/cc2538-rf.c @@ -137,7 +137,6 @@ static int8_t rssi; static uint8_t crc_corr; void mac_timer_init(void); -uint32_t get_sfd_timestamp(void); /*---------------------------------------------------------------------------*/ static uint8_t rf_flags; static uint8_t rf_channel = CC2538_RF_CHANNEL; @@ -380,6 +379,34 @@ set_auto_ack(uint8_t enable) } } /*---------------------------------------------------------------------------*/ +static uint32_t +get_sfd_timestamp(void) +{ + uint64_t sfd, timer_val, buffer; + + REG(RFCORE_SFR_MTMSEL) = (REG(RFCORE_SFR_MTMSEL) & ~RFCORE_SFR_MTMSEL_MTMSEL) | 0x00000000; + REG(RFCORE_SFR_MTCTRL) |= RFCORE_SFR_MTCTRL_LATCH_MODE; + timer_val = REG(RFCORE_SFR_MTM0) & RFCORE_SFR_MTM0_MTM0; + timer_val |= ((REG(RFCORE_SFR_MTM1) & RFCORE_SFR_MTM1_MTM1) << 8); + REG(RFCORE_SFR_MTMSEL) = (REG(RFCORE_SFR_MTMSEL) & ~RFCORE_SFR_MTMSEL_MTMOVFSEL) | 0x00000000; + timer_val |= ((REG(RFCORE_SFR_MTMOVF0) & RFCORE_SFR_MTMOVF0_MTMOVF0) << 16); + timer_val |= ((REG(RFCORE_SFR_MTMOVF1) & RFCORE_SFR_MTMOVF1_MTMOVF1) << 24); + buffer = REG(RFCORE_SFR_MTMOVF2) & RFCORE_SFR_MTMOVF2_MTMOVF2; + timer_val |= (buffer << 32); + + REG(RFCORE_SFR_MTMSEL) = (REG(RFCORE_SFR_MTMSEL) & ~RFCORE_SFR_MTMSEL_MTMSEL) | 0x00000001; + REG(RFCORE_SFR_MTCTRL) |= RFCORE_SFR_MTCTRL_LATCH_MODE; + sfd = REG(RFCORE_SFR_MTM0) & RFCORE_SFR_MTM0_MTM0; + sfd |= ((REG(RFCORE_SFR_MTM1) & RFCORE_SFR_MTM1_MTM1) << 8); + REG(RFCORE_SFR_MTMSEL) = (REG(RFCORE_SFR_MTMSEL) & ~RFCORE_SFR_MTMSEL_MTMOVFSEL) | 0x00000010; + sfd |= ((REG(RFCORE_SFR_MTMOVF0) & RFCORE_SFR_MTMOVF0_MTMOVF0) << 16); + sfd |= ((REG(RFCORE_SFR_MTMOVF1) & RFCORE_SFR_MTMOVF1_MTMOVF1) << 24); + buffer = REG(RFCORE_SFR_MTMOVF2) & RFCORE_SFR_MTMOVF2_MTMOVF2; + sfd |= (buffer << 32); + + return RTIMER_NOW() - RADIO_TO_RTIMER(timer_val - sfd); +} +/*---------------------------------------------------------------------------*/ /* Netstack API radio driver functions */ /*---------------------------------------------------------------------------*/ static int @@ -1128,33 +1155,6 @@ cc2538_rf_set_promiscous_mode(char p) set_frame_filtering(p); } /*---------------------------------------------------------------------------*/ -uint32_t get_sfd_timestamp(void) -{ - uint64_t sfd, timer_val, buffer; - - REG(RFCORE_SFR_MTMSEL) = (REG(RFCORE_SFR_MTMSEL) & ~RFCORE_SFR_MTMSEL_MTMSEL) | 0x00000000; - REG(RFCORE_SFR_MTCTRL) |= RFCORE_SFR_MTCTRL_LATCH_MODE; - timer_val = REG(RFCORE_SFR_MTM0) & RFCORE_SFR_MTM0_MTM0; - timer_val |= ((REG(RFCORE_SFR_MTM1) & RFCORE_SFR_MTM1_MTM1) << 8); - REG(RFCORE_SFR_MTMSEL) = (REG(RFCORE_SFR_MTMSEL) & ~RFCORE_SFR_MTMSEL_MTMOVFSEL) | 0x00000000; - timer_val |= ((REG(RFCORE_SFR_MTMOVF0) & RFCORE_SFR_MTMOVF0_MTMOVF0) << 16); - timer_val |= ((REG(RFCORE_SFR_MTMOVF1) & RFCORE_SFR_MTMOVF1_MTMOVF1) << 24); - buffer = REG(RFCORE_SFR_MTMOVF2) & RFCORE_SFR_MTMOVF2_MTMOVF2; - timer_val |= (buffer << 32); - - REG(RFCORE_SFR_MTMSEL) = (REG(RFCORE_SFR_MTMSEL) & ~RFCORE_SFR_MTMSEL_MTMSEL) | 0x00000001; - REG(RFCORE_SFR_MTCTRL) |= RFCORE_SFR_MTCTRL_LATCH_MODE; - sfd = REG(RFCORE_SFR_MTM0) & RFCORE_SFR_MTM0_MTM0; - sfd |= ((REG(RFCORE_SFR_MTM1) & RFCORE_SFR_MTM1_MTM1) << 8); - REG(RFCORE_SFR_MTMSEL) = (REG(RFCORE_SFR_MTMSEL) & ~RFCORE_SFR_MTMSEL_MTMOVFSEL) | 0x00000010; - sfd |= ((REG(RFCORE_SFR_MTMOVF0) & RFCORE_SFR_MTMOVF0_MTMOVF0) << 16); - sfd |= ((REG(RFCORE_SFR_MTMOVF1) & RFCORE_SFR_MTMOVF1_MTMOVF1) << 24); - buffer = REG(RFCORE_SFR_MTMOVF2) & RFCORE_SFR_MTMOVF2_MTMOVF2; - sfd |= (buffer << 32); - - return (RTIMER_NOW() - RADIO_TO_RTIMER(timer_val - sfd)); -} -/*---------------------------------------------------------------------------*/ void mac_timer_init(void) { CLOCK_STABLE(); From c359e98bf18bf81b7f58f48cb9f16283b166742d Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 16 Jul 2016 17:10:21 +0100 Subject: [PATCH 3/4] Change mac_timer_init() to static We also move the function to a different location so we won't have to provide the prototype separately --- cpu/cc2538/dev/cc2538-rf.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/cpu/cc2538/dev/cc2538-rf.c b/cpu/cc2538/dev/cc2538-rf.c index 17cbf7a1d..b5b04da8c 100644 --- a/cpu/cc2538/dev/cc2538-rf.c +++ b/cpu/cc2538/dev/cc2538-rf.c @@ -135,8 +135,6 @@ static uint8_t volatile poll_mode = 0; static uint8_t send_on_cca = 1; static int8_t rssi; static uint8_t crc_corr; - -void mac_timer_init(void); /*---------------------------------------------------------------------------*/ static uint8_t rf_flags; static uint8_t rf_channel = CC2538_RF_CHANNEL; @@ -348,6 +346,20 @@ set_frame_filtering(uint8_t enable) } /*---------------------------------------------------------------------------*/ static void +mac_timer_init(void) +{ + CLOCK_STABLE(); + REG(RFCORE_SFR_MTCTRL) |= RFCORE_SFR_MTCTRL_SYNC; + REG(RFCORE_SFR_MTCTRL) |= RFCORE_SFR_MTCTRL_RUN; + while(!(REG(RFCORE_SFR_MTCTRL) & RFCORE_SFR_MTCTRL_STATE)); + REG(RFCORE_SFR_MTCTRL) &= ~RFCORE_SFR_MTCTRL_RUN; + while(REG(RFCORE_SFR_MTCTRL) & RFCORE_SFR_MTCTRL_STATE); + REG(RFCORE_SFR_MTCTRL) |= RFCORE_SFR_MTCTRL_SYNC; + REG(RFCORE_SFR_MTCTRL) |= (RFCORE_SFR_MTCTRL_RUN); + while(!(REG(RFCORE_SFR_MTCTRL) & RFCORE_SFR_MTCTRL_STATE)); +} +/*---------------------------------------------------------------------------*/ +static void set_poll_mode(uint8_t enable) { poll_mode = enable; @@ -1155,17 +1167,4 @@ cc2538_rf_set_promiscous_mode(char p) set_frame_filtering(p); } /*---------------------------------------------------------------------------*/ -void mac_timer_init(void) -{ - CLOCK_STABLE(); - REG(RFCORE_SFR_MTCTRL) |= RFCORE_SFR_MTCTRL_SYNC; - REG(RFCORE_SFR_MTCTRL) |= RFCORE_SFR_MTCTRL_RUN; - while(!(REG(RFCORE_SFR_MTCTRL) & RFCORE_SFR_MTCTRL_STATE)); - REG(RFCORE_SFR_MTCTRL) &= ~RFCORE_SFR_MTCTRL_RUN; - while(REG(RFCORE_SFR_MTCTRL) & RFCORE_SFR_MTCTRL_STATE); - REG(RFCORE_SFR_MTCTRL) |= RFCORE_SFR_MTCTRL_SYNC; - REG(RFCORE_SFR_MTCTRL) |= (RFCORE_SFR_MTCTRL_RUN); - while(!(REG(RFCORE_SFR_MTCTRL) & RFCORE_SFR_MTCTRL_STATE)); -} -/*---------------------------------------------------------------------------*/ /** @} */ From 7fdb9849de9469836680f802bcd7787b7bbb7f60 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 16 Jul 2016 22:33:59 +0100 Subject: [PATCH 4/4] Remove unnecessary parentheses --- cpu/cc2538/dev/cc2538-rf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cpu/cc2538/dev/cc2538-rf.c b/cpu/cc2538/dev/cc2538-rf.c index b5b04da8c..6916524d2 100644 --- a/cpu/cc2538/dev/cc2538-rf.c +++ b/cpu/cc2538/dev/cc2538-rf.c @@ -210,9 +210,9 @@ set_channel(uint8_t channel) was_on = 1; off(); } - REG(RFCORE_XREG_FREQCTRL) = (CC2538_RF_CHANNEL_MIN + - (channel - CC2538_RF_CHANNEL_MIN) * - CC2538_RF_CHANNEL_SPACING); + REG(RFCORE_XREG_FREQCTRL) = CC2538_RF_CHANNEL_MIN + + (channel - CC2538_RF_CHANNEL_MIN) * CC2538_RF_CHANNEL_SPACING; + /* switch radio back on only if radio was on before - otherwise will turn on radio foor sleepy nodes */ if(was_on) { on();