initial commit
This commit is contained in:
77
source/firmware/arch/stm32f4xx/driver/timer/stm32_sys_tick.c
Executable file
77
source/firmware/arch/stm32f4xx/driver/timer/stm32_sys_tick.c
Executable file
@@ -0,0 +1,77 @@
|
||||
//! \file stm32_sys_tick.c
|
||||
//! \author tkl
|
||||
//! \date Feb 15, 2012
|
||||
//! \brief Source file of the stm32f10x architecture dependent sys tick timer implementation.
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "stm32f4xx.h"
|
||||
|
||||
#include "stm32_sys_tick.h"
|
||||
#include "stm32f4xx_isr.h"
|
||||
|
||||
struct stm32_sys_tick_obj {
|
||||
stm32_sys_tick_cb_t sys_tick_cb;
|
||||
void *sys_tick_cb_param;
|
||||
};
|
||||
|
||||
static struct stm32_sys_tick_obj stm32_sys_tick_obj;
|
||||
|
||||
int stm32_sys_tick_open(const void *sys_tick) {
|
||||
if(sys_tick == NULL)
|
||||
return -1;
|
||||
|
||||
struct stm32_sys_tick *this = (struct stm32_sys_tick *)sys_tick;
|
||||
uint32_t div = 1000;
|
||||
switch(*this->tick_time_base) {
|
||||
case STM32_SYS_TICK_TIME_BASE_US:
|
||||
div = 1000000;
|
||||
break;
|
||||
|
||||
case STM32_SYS_TICK_TIME_BASE_MS:
|
||||
div = 1000;
|
||||
break;
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
if(SysTick_Config(SystemCoreClock / div))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int stm32_sys_tick_close(const void *sys_tick)
|
||||
{
|
||||
if(sys_tick == NULL)
|
||||
return -1;
|
||||
|
||||
SysTick->CTRL = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int stm32_sys_tick_set_cb(const void *sys_tick, const void *callback, const void *param)
|
||||
{
|
||||
if((sys_tick == NULL) || (callback == NULL))
|
||||
return -1;
|
||||
|
||||
stm32_sys_tick_obj.sys_tick_cb = (stm32_sys_tick_cb_t)callback;
|
||||
stm32_sys_tick_obj.sys_tick_cb_param = (void*)param;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
enter_isr();
|
||||
|
||||
if(stm32_sys_tick_obj.sys_tick_cb != NULL) {
|
||||
stm32_sys_tick_cb_t cb = stm32_sys_tick_obj.sys_tick_cb;
|
||||
void *param = stm32_sys_tick_obj.sys_tick_cb_param;
|
||||
cb(param);
|
||||
}
|
||||
|
||||
exit_isr();
|
||||
}
|
49
source/firmware/arch/stm32f4xx/driver/timer/stm32_sys_tick.h
Executable file
49
source/firmware/arch/stm32f4xx/driver/timer/stm32_sys_tick.h
Executable file
@@ -0,0 +1,49 @@
|
||||
//! \file stm32_sys_tick.h
|
||||
//! \author tkl
|
||||
//! \date Feb 15, 2012
|
||||
//! \brief Header file of the stm32f10x architecture dependent sys tick timer implementation.
|
||||
#ifndef STM32_SYS_TICK_H_
|
||||
#define STM32_SYS_TICK_H_
|
||||
|
||||
#include "timer.h"
|
||||
|
||||
typedef void* (*stm32_sys_tick_cb_t)(void*); //!< callback for the external interrupt
|
||||
|
||||
//! \brief Type of sys tick base time.
|
||||
enum stm32_sys_tick_time_base {
|
||||
STM32_SYS_TICK_TIME_BASE_NONE = 0, //!< Not init
|
||||
STM32_SYS_TICK_TIME_BASE_US, //!< Tick time = 1 us.
|
||||
STM32_SYS_TICK_TIME_BASE_MS //!< Tick time = 1 ms.
|
||||
};
|
||||
|
||||
//! \brief The sys tick device.
|
||||
struct stm32_sys_tick {
|
||||
const enum stm32_sys_tick_time_base *tick_time_base; //!< time base for the system tick
|
||||
stm32_sys_tick_cb_t sys_tick_cb; //!< callback for the sys tick interrupt
|
||||
void *sys_tick_cb_param; //!< parameter for the callback
|
||||
};
|
||||
|
||||
//! \brief Open a sys tick timer.
|
||||
//! \param sys_tick The sys tick to open. Must be of type const stm32_sys_tick_t*.
|
||||
//! \return -1 in error case.
|
||||
int stm32_sys_tick_open(const void *sys_tick);
|
||||
|
||||
//! \brief Close a sys tick timer.
|
||||
//! \param sys_tick The sys tick to close. Must be of type const stm32_sys_tick_t*.
|
||||
//! \return -1 in error case.
|
||||
int stm32_sys_tick_close(const void *sys_tick);
|
||||
|
||||
//! \brief Set the call back for a sys tick timer.
|
||||
//! \param sys_tick The sys tick to open. Mus be of type const stm32_sys_tick_t*.
|
||||
//! \param callback The function pointer of the call back function.
|
||||
//! \param param The parameter for the call back function.
|
||||
//! \return -1 in error case.
|
||||
int stm32_sys_tick_set_cb(const void *sys_tick, const void *callback, const void *param);
|
||||
|
||||
static const struct timer_fp timer_fp = {
|
||||
stm32_sys_tick_open,
|
||||
stm32_sys_tick_close,
|
||||
stm32_sys_tick_set_cb
|
||||
};
|
||||
|
||||
#endif /* STM32_SYS_TICK_H_ */
|
3
source/firmware/arch/stm32f4xx/driver/timer/timer.mk
Executable file
3
source/firmware/arch/stm32f4xx/driver/timer/timer.mk
Executable file
@@ -0,0 +1,3 @@
|
||||
SUB_FOLDER += firmware/arch/stm32f4xx/driver/timer
|
||||
INCLUDES += firmware/arch/stm32f4xx/driver/timer
|
||||
DOC_SRC += firmware/arch/stm32f4xx/driver/timer
|
Reference in New Issue
Block a user