[arm-m] add simple systick driver

This commit is contained in:
Travis Geiselbrecht
2012-05-10 18:59:29 -07:00
parent 220b77f5ae
commit 9ef4e385fa
5 changed files with 66 additions and 1 deletions

View File

@@ -75,6 +75,9 @@ void arch_early_init(void)
/* set the svc and pendsv priority level to pretty low */
SCB->SHP[11-4] = cm3_lowest_priority();
SCB->SHP[14-4] = cm3_lowest_priority();
/* initialize the systick mechanism */
cm3_systick_init();
}
void arch_init(void)

View File

@@ -85,7 +85,8 @@ void _usagefault(void)
halt();
}
void _systick(void)
/* systick handler */
void __WEAK _systick(void)
{
printf("systick\n");
halt();

View File

@@ -106,5 +106,11 @@ static __ALWAYS_INLINE inline void cm3_trigger_preempt(void)
SCB->ICSR |= SCB_ICSR_PENDSVSET_Msk;
}
/* systick */
void cm3_systick_init(void);
void cm3_systick_set_periodic(uint32_t systick_clk_freq, time_t period);
void cm3_systick_cancel_periodic(void);
/* extern void _systick(void); // override this */
#endif

54
arch/arm/arm-m/systick.c Normal file
View File

@@ -0,0 +1,54 @@
/*
* Copyright (c) 2012 Travis Geiselbrecht
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
#include <debug.h>
#include <kernel/thread.h>
#include <arch/arm.h>
#include <arch/arm/cm3.h>
#define LOCAL_TRACE 0
void cm3_systick_init(void)
{
NVIC_SetPriority(SysTick_IRQn, cm3_medium_priority());
}
void cm3_systick_set_periodic(uint32_t systick_clk_freq, time_t period)
{
LTRACEF("clk_freq %u, period %u\n", systick_clk_freq, period);
uint32_t ticks = ((uint64_t)systick_clk_freq) / (1000 / period);
LTRACEF("ticks %d\n", ticks);
SysTick->LOAD = (ticks & SysTick_LOAD_RELOAD_Msk) - 1;
SysTick->VAL = 0;
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk;
}
void cm3_systick_cancel_periodic(void)
{
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
}

View File

@@ -126,6 +126,7 @@ OBJS += \
$(LOCAL_DIR)/arm-m/start.o \
$(LOCAL_DIR)/arm-m/exceptions.o \
$(LOCAL_DIR)/arm-m/thread.o \
$(LOCAL_DIR)/arm-m/systick.o \
$(LOCAL_DIR)/arm-m/CMSIS/CM3/CoreSupport/core_cm3.o
INCLUDES += \