]> rtime.felk.cvut.cz Git - arc.git/blob - arch/arm/arm_cm3/kernel/sys_tick.c
merge with osek-ctest
[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 "core_cm3.h"\r
20 #include "irq.h"\r
21 #include "arc.h"\r
22 \r
23 \r
24 /**\r
25  * Init of free running timer.\r
26  */\r
27 void Os_SysTickInit( void ) {\r
28         TaskType tid;\r
29         tid = Os_Arc_CreateIsr(OsTick,6/*prio*/,"OsTick");\r
30         Irq_AttachIsr2(tid,NULL, SysTick_IRQn);\r
31 }\r
32 \r
33 /**\r
34  * Start the Sys Tick timer\r
35  *\r
36  * @param period_ticks How long the period in timer ticks should be.\r
37  *\r
38  */\r
39 \r
40 void Os_SysTickStart(uint32_t period_ticks) {\r
41 \r
42         /* Cortex-M3 have a 24-bit system timer that counts down\r
43          * from the reload value to zero.\r
44          */\r
45 \r
46         SysTick_Config(period_ticks);\r
47 \r
48          /* Set SysTick Priority to 3 */\r
49         NVIC_SetPriority(SysTick_IRQn, 0x0C);\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 \r
59         // Select HCLK/8 as SysTick clock source\r
60         SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);\r
61 #endif\r
62 \r
63 }\r
64 \r
65 /**\r
66  * @return\r
67  */\r
68 \r
69 uint32_t Os_SysTickGetValue( void )\r
70 {\r
71         return (SysTick->VAL);\r
72 }\r