1 /* -------------------------------- Arctic Core ------------------------------
\r
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
\r
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
\r
6 * This source code is free software; you can redistribute it and/or modify it
\r
7 * under the terms of the GNU General Public License version 2 as published by the
\r
8 * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
\r
10 * This program is distributed in the hope that it will be useful, but
\r
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
\r
14 * -------------------------------- Arctic Core ------------------------------*/
\r
17 #include "internal.h"
\r
18 #include "stm32f10x.h"
\r
21 #include "counter_i.h"
\r
25 * Init of free running timer.
\r
27 void Os_SysTickInit( void ) {
\r
28 ISR_INSTALL_ISR2("OsTick",OsTick,SysTick_IRQn,6,0);
\r
31 tid = Os_Arc_CreateIsr(OsTick,6/*prio*/,"OsTick");
\r
32 Irq_AttachIsr2(tid,NULL, SysTick_IRQn);
\r
37 * Start the Sys Tick timer
\r
39 * @param period_ticks How long the period in timer ticks should be.
\r
43 void Os_SysTickStart(uint32_t period_ticks) {
\r
45 /* Cortex-M3 have a 24-bit system timer that counts down
\r
46 * from the reload value to zero.
\r
49 SysTick_Config(period_ticks);
\r
52 // SysTick interrupt each 250ms with counter clock equal to 9MHz
\r
53 if (SysTick_Config((SystemFrequency / 8) / 4)) {
\r
58 // Select HCLK/8 as SysTick clock source
\r
59 SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
\r
68 uint32_t Os_SysTickGetValue( void )
\r
70 return (SysTick->LOAD) - (SysTick->VAL);
\r
74 TickType Os_SysTickGetElapsedValue( uint32_t preValue ) {
\r
78 curr = (SysTick->VAL);
\r
79 max = (SysTick->LOAD);
\r
80 return Os_CounterDiff((max - curr),preValue,max);
\r