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
19 #include "internal.h"
\r
22 #define COUNTER_STD_END \
\r
30 /* Accessor functions */
\r
31 #if ( OS_SC2 == STD_ON ) || ( OS_SC4 == STD_ON )
\r
32 static inline OsSchTblAdjExpPointType *getAdjExpPoint( OsSchTblType *stblPtr ) {
\r
33 return &stblPtr->adjExpPoint;
\r
38 static inline const struct OsSchTblAutostart *getAutoStart( OsSchTblType *stblPtr ) {
\r
39 return stblPtr->autostartPtr;
\r
42 #if ( OS_SC2 == STD_ON ) || ( OS_SC4 == STD_ON )
\r
43 static inline struct OsScheduleTableSync *getSync( OsSchTblType *stblPtr ) {
\r
44 return &stblPtr->sync;
\r
49 #define IsCounterValid(_counterId) ((_counterId) <= OS_COUNTER_CNT)
\r
58 StatusType IncrementCounter( CounterType counter_id ) {
\r
59 StatusType rv = E_OK;
\r
60 OsCounterType *cPtr;
\r
62 cPtr = Os_CfgGetCounter(counter_id);
\r
66 if( !IsCounterValid(counter_id) ) {
\r
74 if( ( cPtr->type != COUNTER_TYPE_SOFT ) ||
\r
75 ( counter_id >= OS_COUNTER_CNT ) ) {
\r
82 cPtr->val = Os_CounterAdd( cPtr->val, Os_CounterGetMaxValue(cPtr), 1 );
\r
85 Os_AlarmCheck(cPtr);
\r
87 #if OS_SCHTBL_CNT!=0
\r
88 Os_SchTblCheck(cPtr);
\r
99 StatusType GetCounterValue( CounterType counter_id , TickRefType tick_ref)
\r
101 StatusType rv = E_OK;
\r
102 OsCounterType *cPtr;
\r
103 cPtr = Os_CfgGetCounter(counter_id);
\r
106 if( !IsCounterValid(counter_id) ) {
\r
112 if( cPtr->type == COUNTER_TYPE_HARD ) {
\r
113 if( cPtr->driver == NULL ) {
\r
114 /* It's OSINTERNAL */
\r
115 *tick_ref = os_sys.tick;
\r
118 /* We support only GPT for now */
\r
119 *tick_ref = (TickType)Gpt_GetTimeElapsed(cPtr->driver.OsGptChannelRef);
\r
124 *tick_ref = cPtr->val;
\r
132 * @param counter_id The counter to be read
\r
133 * @param val[in,out] in, The previously read tick value of the counter
\r
134 * out, Contains the current tick value of the counter.
\r
135 * @param elapsed_val[out] The difference
\r
140 StatusType GetElapsedCounterValue( CounterType counter_id, TickRefType val, TickRefType elapsed_val)
\r
142 StatusType rv = E_OK;
\r
143 OsCounterType *cPtr;
\r
144 TickType currTick = 0;
\r
147 cPtr = Os_CfgGetCounter(counter_id);
\r
150 if( !IsCounterValid(counter_id) ) {
\r
155 max = Os_CounterGetMaxValue(cPtr);
\r
162 GetCounterValue(counter_id,&currTick);
\r
165 *elapsed_val = Os_CounterDiff(currTick,*val,max);
\r
175 * 1. The Decrementer is setup by Os_SysTickStart(period_ticks)
\r
176 * 2. Os_SysTickInit() setup INTC[7] to trigger OsTick
\r
177 * 3. OsTick() then increment counter os_tick_counter if used
\r
181 * Non-Autosar stuff
\r
184 /* The id of the counter driven by the os tick, or -1 if not used.
\r
185 * Using weak linking to set default value -1 if not set by config.
\r
187 CounterType Os_Arc_OsTickCounter __attribute__((weak)) = -1;
\r
189 void OsTick( void ) {
\r
190 // if not used, os_tick_counter < 0
\r
191 if (Os_Arc_OsTickCounter >= 0) {
\r
193 OsCounterType *cPtr = Os_CfgGetCounter(Os_Arc_OsTickCounter);
\r
197 cPtr->val = Os_CounterAdd( cPtr->val, Os_CounterGetMaxValue(cPtr), 1 );
\r
199 // os_sys.tick = cPtr->val;
\r
200 #if OS_ALARM_CNT!=0
\r
201 Os_AlarmCheck(cPtr);
\r
203 #if OS_SCHTBL_CNT!=0
\r
204 Os_SchTblCheck(cPtr);
\r
209 TickType GetOsTick( void ) {
\r
210 return get_os_tick();
\r
215 * Initialize alarms and schedule-tables for the counters
\r
217 void Os_CounterInit( void ) {
\r
218 #if OS_ALARM_CNT!=0
\r
220 OsCounterType *cPtr;
\r
223 /* Add the alarms to counters */
\r
224 for (int i = 0; i < OS_ALARM_CNT; i++) {
\r
225 aPtr = Os_CfgGetAlarmObj(i);
\r
226 cPtr = aPtr->counter;
\r
227 SLIST_INSERT_HEAD(&cPtr->alarm_head, aPtr, alarm_list);
\r
232 #if OS_SCHTBL_CNT!=0
\r
234 OsCounterType *cPtr;
\r
235 OsSchTblType *sPtr;
\r
237 /* Add the schedule tables to counters */
\r
238 for(int i=0; i < OS_SCHTBL_CNT; i++ ) {
\r
240 sPtr = Os_CfgGetSched(i);
\r
241 cPtr = sPtr->counter;
\r
242 SLIST_INSERT_HEAD(&cPtr->sched_head, sPtr, sched_list);
\r