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 "irq_types.h"
\r
23 * Init of free running timer.
\r
25 void Os_SysTickInit( void ) {
\r
27 ISR_INSTALL_ISR2( "OsTick", OsTick, INTC_SSCIR0_CLR7, 6, 0 );
\r
31 // Irq_Attach(INTC_SSCIR0_CLR7);
\r
32 // Irq_Attach2( INTC_SSCIR0_CLR7 );
\r
35 IRQ_DECL_ISR2("MyIsr", 7 , CPU_CORE0, 6 , OsTick, 0 , NULL );
\r
39 tid = ISR_INSTALL_ISR2( "OsTick", OsTick, _vector, 6/*prio*/, 0 );
\r
40 Irq_AttachIsr2(tid,NULL,7);
\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
51 void Os_SysTickStart(uint32_t period_ticks) {
\r
55 tmp = get_spr(SPR_HID0);
\r
57 set_spr(SPR_HID0, tmp);
\r
59 /* Initialize the Decrementer */
\r
60 set_spr(SPR_DEC, period_ticks);
\r
61 set_spr(SPR_DECAR, period_ticks);
\r
63 /* Set autoreload */
\r
64 tmp = get_spr(SPR_TCR);
\r
66 set_spr(SPR_TCR, tmp);
\r
68 /* Enable notification */
\r
69 tmp = get_spr(SPR_TCR);
\r
71 set_spr(SPR_TCR, tmp );
\r
76 * TODO: This function just subtract the max value?! ok??
\r
82 TickType Os_SysTickGetValue( void )
\r
84 uint32_t timer = get_spr(SPR_DECAR) - get_spr(SPR_DEC);
\r
88 TickType Os_SysTickGetElapsedValue( uint32_t preValue ) {
92 curr = get_spr(SPR_DEC);
93 max = get_spr(SPR_DECAR);
94 return Os_CounterDiff((max - curr),preValue,max);