Skip to content

Commit

Permalink
openwsn: adaption layer completed
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaseichinger committed Jul 19, 2014
1 parent af2b6ac commit 0524b4c
Show file tree
Hide file tree
Showing 16 changed files with 1,561 additions and 19 deletions.
15 changes: 13 additions & 2 deletions boards/iot-lab_M3/include/periph_conf.h
Expand Up @@ -22,9 +22,10 @@
* @brief Timer configuration
* @{
*/
#define TIMER_NUMOF (2U)
#define TIMER_NUMOF (3U)
#define TIMER_0_EN 1
#define TIMER_1_EN 1
#define TIMER_2_EN 1

/* Timer 0 configuration */
#define TIMER_0_DEV TIM2
Expand All @@ -45,6 +46,16 @@
#define TIMER_1_ISR isr_tim3
#define TIMER_1_IRQ_CHAN TIM3_IRQn
#define TIMER_1_IRQ_PRIO 1

/* Timer 2 configuration */
#define TIMER_2_DEV TIM4
#define TIMER_2_CHANNELS 2
#define TIMER_2_PRESCALER (36000U)
#define TIMER_2_MAX_VALUE (0xffff)
#define TIMER_2_CLKEN() (RCC->APB1ENR |= RCC_APB1ENR_TIM4EN)
#define TIMER_2_ISR isr_tim4
#define TIMER_2_IRQ_CHAN TIM4_IRQn
#define TIMER_2_IRQ_PRIO 1
/** @} */

/**
Expand Down Expand Up @@ -84,7 +95,7 @@
/**
* @brief GPIO configuration
*/
#define GPIO_NUMOF 15
#define GPIO_NUMOF 16
#define GPIO_0_EN 1
#define GPIO_1_EN 1
#define GPIO_2_EN 1
Expand Down
59 changes: 59 additions & 0 deletions cpu/stm32f1/periph/timer.c
Expand Up @@ -67,6 +67,16 @@ int timer_init(tim_t dev, unsigned int ticks_per_us, void (*callback)(int))
/* select timer */
timer = TIMER_1_DEV;
break;
#endif
#if TIMER_2_EN
case TIMER_2:
/* enable timer peripheral clock */
TIMER_2_CLKEN();
/* set timer's IRQ priority */
NVIC_SetPriority(TIMER_2_IRQ_CHAN, TIMER_2_IRQ_PRIO);
/* select timer */
timer = TIMER_2_DEV;
break;
#endif
case TIMER_UNDEFINED:
default:
Expand Down Expand Up @@ -113,6 +123,11 @@ int timer_set_absolute(tim_t dev, int channel, unsigned int value)
case TIMER_1:
timer = TIMER_1_DEV;
break;
#endif
#if TIMER_2_EN
case TIMER_2:
timer = TIMER_2_DEV;
break;
#endif
case TIMER_UNDEFINED:
default:
Expand Down Expand Up @@ -160,6 +175,11 @@ int timer_clear(tim_t dev, int channel)
case TIMER_1:
timer = TIMER_1_DEV;
break;
#endif
#if TIMER_2_EN
case TIMER_2:
timer = TIMER_2_DEV;
break;
#endif
case TIMER_UNDEFINED:
default:
Expand Down Expand Up @@ -196,6 +216,11 @@ unsigned int timer_read(tim_t dev)
case TIMER_1:
return TIMER_1_DEV->CNT;
break;
#endif
#if TIMER_2_EN
case TIMER_2:
return TIMER_2_DEV->CNT;
break;
#endif
case TIMER_UNDEFINED:
default:
Expand All @@ -215,6 +240,11 @@ void timer_start(tim_t dev)
case TIMER_1:
TIMER_1_DEV->CR1 |= TIM_CR1_CEN;
break;
#endif
#if TIMER_2_EN
case TIMER_2:
TIMER_2_DEV->CR1 |= TIM_CR1_CEN;
break;
#endif
case TIMER_UNDEFINED:
break;
Expand All @@ -233,6 +263,11 @@ void timer_stop(tim_t dev)
case TIMER_1:
TIMER_1_DEV->CR1 &= ~TIM_CR1_CEN;
break;
#endif
#if TIMER_2_EN
case TIMER_2:
TIMER_2_DEV->CR1 &= ~TIM_CR1_CEN;
break;
#endif
case TIMER_UNDEFINED:
break;
Expand All @@ -251,6 +286,11 @@ void timer_irq_enable(tim_t dev)
case TIMER_1:
NVIC_EnableIRQ(TIMER_1_IRQ_CHAN);
break;
#endif
#if TIMER_2_EN
case TIMER_2:
NVIC_EnableIRQ(TIMER_2_IRQ_CHAN);
break;
#endif
case TIMER_UNDEFINED:
break;
Expand All @@ -269,6 +309,11 @@ void timer_irq_disable(tim_t dev)
case TIMER_1:
NVIC_DisableIRQ(TIMER_1_IRQ_CHAN);
break;
#endif
#if TIMER_2_EN
case TIMER_2:
NVIC_DisableIRQ(TIMER_2_IRQ_CHAN);
break;
#endif
case TIMER_UNDEFINED:
break;
Expand All @@ -287,6 +332,11 @@ void timer_reset(tim_t dev)
case TIMER_1:
TIMER_1_DEV->CNT = 0;
break;
#endif
#if TIMER_2_EN
case TIMER_2:
TIMER_2_DEV->CNT = 0;
break;
#endif
case TIMER_UNDEFINED:
break;
Expand Down Expand Up @@ -314,6 +364,15 @@ __attribute__ ((naked)) void TIMER_1_ISR(void)
}
#endif

#if TIMER_2_EN
__attribute__ ((naked)) void TIMER_2_ISR(void)
{
ISR_ENTER();
irq_handler(TIMER_2, TIMER_2_DEV);
ISR_EXIT();
}
#endif

static inline void irq_handler(tim_t timer, TIM_TypeDef *dev)
{
if (dev->SR & TIM_SR_UIF) {
Expand Down
1 change: 1 addition & 0 deletions sys/net/openwsn_stack/Makefile
Expand Up @@ -35,6 +35,7 @@ DIRS += openwsn/03b-IPv6
DIRS += openwsn/04-TRAN
DIRS += openwsn/cross-layers
DIRS += openwsn/07-App/rinfo
DIRS += openwsn/07-App/rleds
DIRS += openwsn/07-App/rwellknown
DIRS += openwsn/07-App/r6t
DIRS += openwsn/07-App/ohlone
Expand Down

0 comments on commit 0524b4c

Please sign in to comment.