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
20 #include "mpc55xx.h"
\r
23 * Init of free running timer.
\r
26 extern void OsTick( void );
\r
27 extern OsTickType OsTickFreq;
\r
28 void Os_SysTickInit( void ) {
\r
30 tid = Os_Arc_CreateIsr(OsTick, 6 /*prio*/, "OsTick");
\r
31 #if defined(CFG_MPC5606S)
\r
32 Irq_AttachIsr2(tid, NULL, RTC_INT); /* Attach ISR2 to RTC interrupt */
\r
34 Irq_AttachIsr2(tid, NULL, 7); /* Attach ISR2 to INTC_SSCIR0_CLR7 */
\r
41 * @param period_ticks How long the period in timer ticks should be. The timer
\r
42 * on PowerPC often driver by the CPU clock or some platform clock.
\r
45 void Os_SysTickStart(uint32_t period_ticks) {
\r
46 #if defined(CFG_MPC5606S)
\r
47 CGM.SXOSC_CTL.B.OSCON = 1; // enable the osc for RTC
\r
48 RTC.RTCC.B.CNTEN = 0; // disable RTC
\r
49 RTC.RTCC.B.APIEN = 0; // disable API
\r
50 RTC.RTCS.B.RTCF = 1; // clear RTC interrupt flag
\r
51 RTC.RTCS.B.APIF = 1; // clear API interrupt flag
\r
52 RTC.RTCC.B.RTCIE = 1; // enable RTC interrupt
\r
53 RTC.RTCC.B.APIIE = 0; // disable API interrupt
\r
54 RTC.RTCC.B.FRZEN = 1; // enable freeze mode
\r
55 RTC.RTCC.B.CLKSEL = 2; // set 16MHz FIRC as input clock
\r
56 // ignore period_ticks, and set RTC compare value
\r
57 RTC.RTCC.B.RTCVAL = ( ( (uint32_t)(16000000/OsTickFreq) ) >> 10);
\r
60 RTC.RTCC.B.CNTEN = 1; // start RTC
\r
65 tmp = get_spr(SPR_HID0);
\r
67 set_spr(SPR_HID0, tmp);
\r
69 /* Initialize the Decrementer */
\r
70 set_spr(SPR_DEC, period_ticks);
\r
71 set_spr(SPR_DECAR, period_ticks);
\r
73 /* Set autoreload */
\r
74 tmp = get_spr(SPR_TCR);
\r
76 set_spr(SPR_TCR, tmp);
\r
78 /* Enable notification */
\r
79 tmp = get_spr(SPR_TCR);
\r
81 set_spr(SPR_TCR, tmp );
\r
87 * TODO: This function just subtract the max value?! ok??
\r
93 TickType Os_SysTickGetValue( void )
\r
95 uint32_t timer = get_spr(SPR_DECAR) - get_spr(SPR_DEC);
\r
99 TickType Os_SysTickGetElapsedValue( uint32_t preValue ) {
103 curr = get_spr(SPR_DEC);
104 max = get_spr(SPR_DECAR);
105 return Os_CounterDiff((max - curr),preValue,max);