Skip to content

Commit 7fa1de7

Browse files
Merge pull request #26 from thomaseichinger/periph_timer
stm32f103_rey6: implement std periph driver
2 parents e32bece + 7ef1b70 commit 7fa1de7

File tree

10 files changed

+514
-178
lines changed

10 files changed

+514
-178
lines changed

stm32f103rey6/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ endif
88

99
DIRS += $(RIOTCPU)/STM32F10x_StdPeriph_Lib_V3.5.0
1010
DIRS += $(RIOTCPU)/cortex_common
11+
DIRS += $(RIOTCPU)/$(CPU)/periph
1112

1213
all: $(BINDIR)$(MODULE).a
1314
@for i in $(DIRS) ; do "$(MAKE)" -C $$i ; done ;

stm32f103rey6/Makefile.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ INCLUDES += -I$(RIOTCPU)/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdP
66
INCLUDES += -I$(RIOTBASE)/core/include -I$(RIOTBASE)/sys/include -I$(RIOTBASE)/sys/lib
77

88
export USEMODULE += cortex_common
9+
export USEMODULE += periph
910

stm32f103rey6/cpu.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ void ctx_switch(void)
128128
asm("mov r12, sp");
129129
asm("stmfd r12!, {r4-r11}");
130130

131-
/* save user mode stack pointer in *active_thread */
132-
asm("ldr r1, =active_thread"); /* r1 = &active_thread */
133-
asm("ldr r1, [r1]"); /* r1 = *r1 = active_thread */
131+
/* save user mode stack pointer in *sched_active_thread */
132+
asm("ldr r1, =sched_active_thread"); /* r1 = &sched_active_thread */
133+
asm("ldr r1, [r1]"); /* r1 = *r1 = sched_active_thread */
134134
asm("str r12, [r1]"); /* store stack pointer in tasks pdc*/
135135

136136
sched_task_return();
@@ -145,8 +145,8 @@ void sched_task_return(void)
145145
mode.b.nPRIV = 0; // privilege
146146
__set_CONTROL(mode.w);
147147
/* load pdc->stackpointer in r0 */
148-
asm("ldr r0, =active_thread"); /* r0 = &active_thread */
149-
asm("ldr r0, [r0]"); /* r0 = *r0 = active_thread */
148+
asm("ldr r0, =sched_active_thread"); /* r0 = &sched_active_thread */
149+
asm("ldr r0, [r0]"); /* r0 = *r0 = sched_active_thread */
150150
asm("ldr sp, [r0]"); /* sp = r0 restore stack pointer*/
151151
asm("pop {r4}"); /* skip exception return */
152152
asm("pop {r4-r11}");

stm32f103rey6/include/cpu.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ __attribute__((always_inline)) __INLINE void save_context(void)
7373
asm("stmdb r0!,{lr}" ); // exception return value
7474
// asm("vstmdb sp!, {s16-s31}" ); // FIXME save fpu registers if needed
7575
/* load address of currend pdc */
76-
asm("ldr r1, =active_thread" ); /* load address of currend tcb */
76+
asm("ldr r1, =sched_active_thread" );/* load address of currend tcb */
7777
/* deref pdc */
7878
asm("ldr r1, [r1]" ); /* deref pdc */
7979
/* write r0 to pdc->sp means current threads stack pointer */
@@ -82,7 +82,7 @@ __attribute__((always_inline)) __INLINE void save_context(void)
8282

8383
__attribute__((always_inline)) __INLINE void restore_context(void)
8484
{
85-
asm("ldr r0, =active_thread" ); /* load address of currend tcb */
85+
asm("ldr r0, =sched_active_thread" );/* load address of currend tcb */
8686
asm("ldr r0, [r0]" ); /* deref tcb */
8787
asm("ldr r1, [r0]" ); /* load tcb->sp to register 1 */
8888
asm("ldmia r1!, {r0}" ); /* restore exception retrun value from stack */

stm32f103rey6/include/hwtimer_cpu.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#ifndef HWTIMER_CPU_H_
22
#define HWTIMER_CPU_H_
33

4-
#define HWTIMER_MAXTIMERS 4
5-
#define HWTIMER_SPEED 2000
6-
#define HWTIMER_MAXTICKS (0xFFFF)
4+
#define HWTIMER_MAXTIMERS (4)
5+
#define HWTIMER_SPEED (2303U)
6+
#define HWTIMER_MAXTICKS (0xFFFF)
77

88
#endif /* HWTIMER_CPU_H_ */

stm32f103rey6/include/timer.h

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* Copyright (C) 2014 Freie Universität Berlin
3+
*
4+
* This file is subject to the terms and conditions of the LGPLv2 License.
5+
* See the file LICENSE in the top level directory for more details.
6+
*/
7+
8+
/**
9+
* @ingroup driver_periph
10+
* @brief Low-level timer peripheral driver
11+
* @{
12+
*
13+
* @file timer.h
14+
* @brief Low-level timer peripheral driver interface definitions
15+
*
16+
* @author Hauke Petersen <[email protected]>
17+
*/
18+
19+
#ifndef __TIMER_H
20+
#define __TIMER_H
21+
22+
#include "periph_conf.h"
23+
24+
25+
/**
26+
* @brief Definition of available timers
27+
*
28+
* Each timer is based on a hardware timer, which can further have 1 or more channels.
29+
* To this point 4 timers are possible, might need to be expanded for some cases.
30+
*/
31+
typedef enum {
32+
#if TIMER_0_EN
33+
TIMER_0 = 0, /*< 1st timer */
34+
#endif
35+
#if TIMER_1_EN
36+
TIMER_1, /*< 2nd timer */
37+
#endif
38+
#if TIMER_2_EN
39+
TIMER_2, /*< 3rd timer */
40+
#endif
41+
#if TIMER_3_EN
42+
TIMER_3, /*< 4th timer */
43+
#endif
44+
TIMER_UNDEFINED /*< fall-back if no timer is defined */
45+
} tim_t; /* named tim instead of timer to avoid conflicts with vendor libraries */
46+
47+
/**
48+
* @brief Initialize the given timer
49+
*
50+
* Each timer device is running with the given speed. Each can contain one or more channels
51+
* as defined in periph_conf.h. The timer is configured in up-counting mode and will count
52+
* until TIMER_x_MAX_VALUE as defined in used board's periph_conf.h until overflowing.
53+
*
54+
* The timer will be started automatically after initialization with interrupts enabled.
55+
*
56+
* @param dev the timer to initialize
57+
* @param ticks_per_us the timers speed in ticks per us
58+
* @param callback this callback is called in interrupt context, the emitting channel is
59+
* passed as argument
60+
* @return returns 0 on success, -1 if speed not applicable of unknown device given
61+
*/
62+
int timer_init(tim_t dev, unsigned int ticks_per_us, void (*callback)(int));
63+
64+
/**
65+
* @brief Set a given timer channel for the given timer device. The callback given during
66+
* initialization is called when timeout ticks have passed after calling this function
67+
*
68+
* @param dev the timer device to set
69+
* @param channel the channel to set
70+
* @param timeout timeout in ticks after that the registered callback is executed
71+
* @return 1 on success, -1 on error
72+
*/
73+
int timer_set(tim_t dev, int channel, unsigned int timeout);
74+
75+
/**
76+
* @brief Clear the given channel of the given timer device
77+
*
78+
* @param dev the timer device to clear
79+
* @param channel the channel on the given device to clear
80+
* @return 1 on success, -1 on error
81+
*/
82+
int timer_clear(tim_t dev, int channel);
83+
84+
/**
85+
* @brief Read the current value of the given timer device
86+
*
87+
* @param dev the timer to read the current value from
88+
* @return the timers current value
89+
*/
90+
unsigned int timer_read(tim_t dev);
91+
92+
/**
93+
* @brief Start the given timer. This function is only needed if the timer was stopped manually before
94+
*
95+
* @param dev the timer device to stop
96+
*/
97+
void timer_start(tim_t dev);
98+
99+
/**
100+
* @brief Stop the given timer - this will effect all of the timer's channels
101+
*
102+
* @param dev the timer to stop
103+
*/
104+
void timer_stop(tim_t dev);
105+
106+
/**
107+
* @brief Enable the interrupts for the given timer
108+
*
109+
* @param dev timer to enable interrupts for
110+
*/
111+
void timer_irq_enable(tim_t dev);
112+
113+
/**
114+
* @brief Disable interrupts for the given timer
115+
*
116+
* @param dev the timer to disable interrupts for
117+
*/
118+
void timer_irq_disable(tim_t dev);
119+
120+
/**
121+
* @brief Reset the up-counting value to zero for the given timer
122+
*
123+
* Note that this function effects all currently set channels and it can lead to non-deterministic timeouts
124+
* if any channel is active when this function is called.
125+
*
126+
* @param dev the timer to reset
127+
*/
128+
void timer_reset(tim_t dev);
129+
130+
#endif /* __TIMER_H */
131+
/** @} */

stm32f103rey6/periph/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# define the module name
2+
MODULE = periph
3+
4+
# include RIOTs generic Makefile
5+
include $(RIOTBASE)/Makefile.base

0 commit comments

Comments
 (0)