]> rtime.felk.cvut.cz Git - arc.git/blob - arch/ppc/mpc55xx/drivers/Frt.c
Again, loads of refactoring and removing and adding files.
[arc.git] / arch / ppc / mpc55xx / drivers / Frt.c
1 /* -------------------------------- Arctic Core ------------------------------
2  * Arctic Core - the open source AUTOSAR platform http://arccore.com
3  *
4  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>
5  *
6  * This source code is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 as published by the
8  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13  * for more details.
14  * -------------------------------- Arctic Core ------------------------------*/
15 \r
16 #include "Os.h"\r
17 #include "internal.h"
18 #include "irq.h"
19 #include "arc.h"
20 \r
21 /**\r
22  * Init of free running timer.\r
23  */\r
24 void Frt_Init( void ) {\r
25         TaskType tid;\r
26         tid = Os_Arc_CreateIsr(OsTick,6/*prio*/,"OsTick");\r
27         Irq_AttachIsr2(tid,NULL,7);\r
28 }\r
29 \r
30 /**\r
31  *\r
32  *
33  * @param period_ticks How long the period in timer ticks should be. The timer\r
34  *                     on PowerPC often driver by the CPU clock or some platform clock.\r
35  *
36  */\r
37 void Frt_Start(uint32_t period_ticks) {\r
38         uint32_t tmp;\r
39 \r
40         // Enable the TB\r
41         tmp = get_spr(SPR_HID0);\r
42         tmp |= HID0_TBEN;\r
43         set_spr(SPR_HID0, tmp);\r
44 \r
45         /* Initialize the Decrementer */\r
46         set_spr(SPR_DEC, period_ticks);\r
47         set_spr(SPR_DECAR, period_ticks);\r
48 \r
49         /* Set autoreload */\r
50         tmp = get_spr(SPR_TCR);\r
51         tmp |= TCR_ARE;\r
52         set_spr(SPR_TCR, tmp);\r
53 \r
54         /* Enable notification */\r
55     tmp = get_spr(SPR_TCR);\r
56     tmp |= TCR_DIE;\r
57     set_spr(SPR_TCR, tmp );\r
58 }\r
59 \r
60 /**\r
61  * ???\r
62  * TODO: This function just subtract the max value?! ok??\r
63  *
64  * @return
65  */\r
66
67 /** @req OS383 */\r
68 uint32_t Frt_GetTimeElapsed( void )\r
69 {\r
70         uint32_t timer = get_spr(SPR_DECAR) - get_spr(SPR_DEC);\r
71         return (timer);\r
72 }\r