Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stm32f103_rey6: implement std periph driver #26

Merged
merged 2 commits into from
May 21, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions stm32f103rey6/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ endif

DIRS += $(RIOTCPU)/STM32F10x_StdPeriph_Lib_V3.5.0
DIRS += $(RIOTCPU)/cortex_common
DIRS += $(RIOTCPU)/$(CPU)/periph

all: $(BINDIR)$(MODULE).a
@for i in $(DIRS) ; do "$(MAKE)" -C $$i ; done ;
Expand Down
1 change: 1 addition & 0 deletions stm32f103rey6/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ INCLUDES += -I$(RIOTCPU)/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdP
INCLUDES += -I$(RIOTBASE)/core/include -I$(RIOTBASE)/sys/include -I$(RIOTBASE)/sys/lib

export USEMODULE += cortex_common
export USEMODULE += periph

10 changes: 5 additions & 5 deletions stm32f103rey6/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ void ctx_switch(void)
asm("mov r12, sp");
asm("stmfd r12!, {r4-r11}");

/* save user mode stack pointer in *active_thread */
asm("ldr r1, =active_thread"); /* r1 = &active_thread */
asm("ldr r1, [r1]"); /* r1 = *r1 = active_thread */
/* save user mode stack pointer in *sched_active_thread */
asm("ldr r1, =sched_active_thread"); /* r1 = &sched_active_thread */
asm("ldr r1, [r1]"); /* r1 = *r1 = sched_active_thread */
asm("str r12, [r1]"); /* store stack pointer in tasks pdc*/

sched_task_return();
Expand All @@ -145,8 +145,8 @@ void sched_task_return(void)
mode.b.nPRIV = 0; // privilege
__set_CONTROL(mode.w);
/* load pdc->stackpointer in r0 */
asm("ldr r0, =active_thread"); /* r0 = &active_thread */
asm("ldr r0, [r0]"); /* r0 = *r0 = active_thread */
asm("ldr r0, =sched_active_thread"); /* r0 = &sched_active_thread */
asm("ldr r0, [r0]"); /* r0 = *r0 = sched_active_thread */
asm("ldr sp, [r0]"); /* sp = r0 restore stack pointer*/
asm("pop {r4}"); /* skip exception return */
asm("pop {r4-r11}");
Expand Down
4 changes: 2 additions & 2 deletions stm32f103rey6/include/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ __attribute__((always_inline)) __INLINE void save_context(void)
asm("stmdb r0!,{lr}" ); // exception return value
// asm("vstmdb sp!, {s16-s31}" ); // FIXME save fpu registers if needed
/* load address of currend pdc */
asm("ldr r1, =active_thread" ); /* load address of currend tcb */
asm("ldr r1, =sched_active_thread" );/* load address of currend tcb */
/* deref pdc */
asm("ldr r1, [r1]" ); /* deref pdc */
/* write r0 to pdc->sp means current threads stack pointer */
Expand All @@ -82,7 +82,7 @@ __attribute__((always_inline)) __INLINE void save_context(void)

__attribute__((always_inline)) __INLINE void restore_context(void)
{
asm("ldr r0, =active_thread" ); /* load address of currend tcb */
asm("ldr r0, =sched_active_thread" );/* load address of currend tcb */
asm("ldr r0, [r0]" ); /* deref tcb */
asm("ldr r1, [r0]" ); /* load tcb->sp to register 1 */
asm("ldmia r1!, {r0}" ); /* restore exception retrun value from stack */
Expand Down
6 changes: 3 additions & 3 deletions stm32f103rey6/include/hwtimer_cpu.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef HWTIMER_CPU_H_
#define HWTIMER_CPU_H_

#define HWTIMER_MAXTIMERS 4
#define HWTIMER_SPEED 2000
#define HWTIMER_MAXTICKS (0xFFFF)
#define HWTIMER_MAXTIMERS (4)
#define HWTIMER_SPEED (2303U)
#define HWTIMER_MAXTICKS (0xFFFF)

#endif /* HWTIMER_CPU_H_ */
131 changes: 131 additions & 0 deletions stm32f103rey6/include/timer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Copyright (C) 2014 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the LGPLv2 License.
* See the file LICENSE in the top level directory for more details.
*/

/**
* @ingroup driver_periph
* @brief Low-level timer peripheral driver
* @{
*
* @file timer.h
* @brief Low-level timer peripheral driver interface definitions
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*/

#ifndef __TIMER_H
#define __TIMER_H

#include "periph_conf.h"


/**
* @brief Definition of available timers
*
* Each timer is based on a hardware timer, which can further have 1 or more channels.
* To this point 4 timers are possible, might need to be expanded for some cases.
*/
typedef enum {
#if TIMER_0_EN
TIMER_0 = 0, /*< 1st timer */
#endif
#if TIMER_1_EN
TIMER_1, /*< 2nd timer */
#endif
#if TIMER_2_EN
TIMER_2, /*< 3rd timer */
#endif
#if TIMER_3_EN
TIMER_3, /*< 4th timer */
#endif
TIMER_UNDEFINED /*< fall-back if no timer is defined */
} tim_t; /* named tim instead of timer to avoid conflicts with vendor libraries */

/**
* @brief Initialize the given timer
*
* Each timer device is running with the given speed. Each can contain one or more channels
* as defined in periph_conf.h. The timer is configured in up-counting mode and will count
* until TIMER_x_MAX_VALUE as defined in used board's periph_conf.h until overflowing.
*
* The timer will be started automatically after initialization with interrupts enabled.
*
* @param dev the timer to initialize
* @param ticks_per_us the timers speed in ticks per us
* @param callback this callback is called in interrupt context, the emitting channel is
* passed as argument
* @return returns 0 on success, -1 if speed not applicable of unknown device given
*/
int timer_init(tim_t dev, unsigned int ticks_per_us, void (*callback)(int));

/**
* @brief Set a given timer channel for the given timer device. The callback given during
* initialization is called when timeout ticks have passed after calling this function
*
* @param dev the timer device to set
* @param channel the channel to set
* @param timeout timeout in ticks after that the registered callback is executed
* @return 1 on success, -1 on error
*/
int timer_set(tim_t dev, int channel, unsigned int timeout);

/**
* @brief Clear the given channel of the given timer device
*
* @param dev the timer device to clear
* @param channel the channel on the given device to clear
* @return 1 on success, -1 on error
*/
int timer_clear(tim_t dev, int channel);

/**
* @brief Read the current value of the given timer device
*
* @param dev the timer to read the current value from
* @return the timers current value
*/
unsigned int timer_read(tim_t dev);

/**
* @brief Start the given timer. This function is only needed if the timer was stopped manually before
*
* @param dev the timer device to stop
*/
void timer_start(tim_t dev);

/**
* @brief Stop the given timer - this will effect all of the timer's channels
*
* @param dev the timer to stop
*/
void timer_stop(tim_t dev);

/**
* @brief Enable the interrupts for the given timer
*
* @param dev timer to enable interrupts for
*/
void timer_irq_enable(tim_t dev);

/**
* @brief Disable interrupts for the given timer
*
* @param dev the timer to disable interrupts for
*/
void timer_irq_disable(tim_t dev);

/**
* @brief Reset the up-counting value to zero for the given timer
*
* Note that this function effects all currently set channels and it can lead to non-deterministic timeouts
* if any channel is active when this function is called.
*
* @param dev the timer to reset
*/
void timer_reset(tim_t dev);

#endif /* __TIMER_H */
/** @} */
5 changes: 5 additions & 0 deletions stm32f103rey6/periph/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# define the module name
MODULE = periph

# include RIOTs generic Makefile
include $(RIOTBASE)/Makefile.base