]> rtime.felk.cvut.cz Git - arc.git/blob - arch/arm/arm_cm3/kernel/sys_tick.c
Merge with mahi-application
[arc.git] / arch / arm / arm_cm3 / kernel / sys_tick.c
1 /* -------------------------------- Arctic Core ------------------------------\r
2  * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
3  *\r
4  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>\r
5  *\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
9  *\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
13  * for more details.\r
14  * -------------------------------- Arctic Core ------------------------------*/\r
15 \r
16 #include "Os.h"\r
17 #include "internal.h"\r
18 #include "stm32f10x.h"\r
19 #include "isr.h"\r
20 #include "arc.h"\r
21 #include "counter_i.h"\r
22 \r
23 \r
24 /**\r
25  * Init of free running timer.\r
26  */\r
27 void Os_SysTickInit( void ) {\r
28         ISR_INSTALL_ISR2("OsTick",OsTick,SysTick_IRQn,6,0);\r
29 #if 0\r
30         TaskType tid;\r
31         tid = Os_Arc_CreateIsr(OsTick,6/*prio*/,"OsTick");\r
32         Irq_AttachIsr2(tid,NULL, SysTick_IRQn);\r
33 #endif\r
34 }\r
35 \r
36 /**\r
37  * Start the Sys Tick timer\r
38  *\r
39  * @param period_ticks How long the period in timer ticks should be.\r
40  *\r
41  */\r
42 \r
43 void Os_SysTickStart(uint32_t period_ticks) {\r
44 \r
45         /* Cortex-M3 have a 24-bit system timer that counts down\r
46          * from the reload value to zero.\r
47          */\r
48 \r
49         SysTick_Config(period_ticks);\r
50 \r
51 #if 0\r
52         // SysTick interrupt each 250ms with counter clock equal to 9MHz\r
53         if (SysTick_Config((SystemFrequency / 8) / 4)) {\r
54                 // Capture error\r
55                 while (1) ;\r
56         }\r
57 \r
58         // Select HCLK/8 as SysTick clock source\r
59         SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);\r
60 #endif\r
61 \r
62 }\r
63 \r
64 /**\r
65  * @return\r
66  */\r
67 \r
68 uint32_t Os_SysTickGetValue( void )\r
69 {\r
70         return (SysTick->LOAD) - (SysTick->VAL);\r
71 }\r
72 \r
73 \r
74 TickType Os_SysTickGetElapsedValue( uint32_t preValue ) {\r
75         uint32_t curr;\r
76         uint32_t max;\r
77 \r
78         curr = (SysTick->VAL);\r
79         max  = (SysTick->LOAD);\r
80         return Os_CounterDiff((max - curr),preValue,max);\r
81 }\r
82 \r