]> rtime.felk.cvut.cz Git - arc.git/blob - arch/ppc/mpc55xx/drivers/sys_tick.c
Updated installation of ISRs in mpc55xx drivers
[arc.git] / arch / ppc / mpc55xx / drivers / 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 "isr.h"\r
19 #include "arc.h"\r
20 #include "irq_types.h"\r
21 \r
22 /**\r
23  * Init of free running timer.\r
24  */\r
25 void Os_SysTickInit( void ) {\r
26 \r
27         ISR_INSTALL_ISR2( "OsTick", OsTick, INTC_SSCIR0_CLR7, 6, 0 );\r
28 \r
29 //      TaskType tid;\r
30 \r
31 //      Irq_Attach(INTC_SSCIR0_CLR7);\r
32 //      Irq_Attach2( INTC_SSCIR0_CLR7 );\r
33 \r
34 #if 0\r
35         IRQ_DECL_ISR2("MyIsr", 7 , CPU_CORE0, 6 , OsTick, 0 , NULL );\r
36         IRQ_ATTACH(7);\r
37 \r
38 // else\r
39         tid = ISR_INSTALL_ISR2( "OsTick", OsTick, _vector, 6/*prio*/, 0 );\r
40         Irq_AttachIsr2(tid,NULL,7);\r
41 #endif\r
42 }\r
43 \r
44 /**\r
45  *\r
46  *\r
47  * @param period_ticks How long the period in timer ticks should be. The timer\r
48  *                     on PowerPC often driver by the CPU clock or some platform clock.\r
49  *\r
50  */\r
51 void Os_SysTickStart(uint32_t period_ticks) {\r
52         uint32_t tmp;\r
53 \r
54         // Enable the TB\r
55         tmp = get_spr(SPR_HID0);\r
56         tmp |= HID0_TBEN;\r
57         set_spr(SPR_HID0, tmp);\r
58 \r
59         /* Initialize the Decrementer */\r
60         set_spr(SPR_DEC, period_ticks);\r
61         set_spr(SPR_DECAR, period_ticks);\r
62 \r
63         /* Set autoreload */\r
64         tmp = get_spr(SPR_TCR);\r
65         tmp |= TCR_ARE;\r
66         set_spr(SPR_TCR, tmp);\r
67 \r
68         /* Enable notification */\r
69     tmp = get_spr(SPR_TCR);\r
70     tmp |= TCR_DIE;\r
71     set_spr(SPR_TCR, tmp );\r
72 }\r
73 \r
74 /**\r
75  * ???\r
76  * TODO: This function just subtract the max value?! ok??\r
77  *\r
78  * @return\r
79  */\r
80 \r
81 /** @req OS383 */\r
82 TickType Os_SysTickGetValue( void )\r
83 {\r
84         uint32_t timer = get_spr(SPR_DECAR) - get_spr(SPR_DEC);\r
85         return (timer);\r
86 }
87
88 TickType Os_SysTickGetElapsedValue( uint32_t preValue ) {
89         uint32_t curr;
90         uint32_t max;
91
92         curr = get_spr(SPR_DEC);
93         max  = get_spr(SPR_DECAR);
94         return Os_CounterDiff((max - curr),preValue,max);
95 }
96 \r