1 /* -------------------------------- Arctic Core ------------------------------
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
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>.
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
14 * -------------------------------- Arctic Core ------------------------------*/
23 // How many errors to keep in error log.
\r
24 #define ERROR_LOG_SIZE 20
\r
28 * Just an example of a basic task.
\r
31 void btask_3( void ) {
\r
34 dbg_printf("[%08d] btask_3 start\n", GetOsTick() );
\r
36 GetTaskID(&currTask);
\r
37 Os_Arc_GetStackInfo(currTask,&si);
\r
38 dbg_printf("btask_3: Stack usage %d%%\n",OS_STACK_USAGE(&si));
\r
44 * An extended task is auto-started and is also triggered by an alarm
\r
45 * that sets event 2.
\r
48 void etask_1( void ) {
\r
49 volatile float tryFloatingPoint = 0.0F;
\r
54 dbg_printf("etask_1 start\n");
\r
56 SetEvent(TASK_ID_etask_2,1);
\r
59 tryFloatingPoint += 1.0F;
\r
60 GetTaskID(&currTask);
\r
61 Os_Arc_GetStackInfo(currTask,&si);
\r
62 dbg_printf("etask_1: Stack usage %d%% \n",OS_STACK_USAGE(&si));
\r
68 * An extended task that receives events from someone
\r
69 * and activates task: btask_3.
71 void etask_2( void ) {
\r
72 dbg_printf("etask_2 start\n");
\r
77 ActivateTask(TASK_ID_btask_3);
\r
81 GetTaskID(&currTask);
\r
82 Os_Arc_GetStackInfo(currTask,&si);
\r
83 dbg_printf("etask_1: Stack usage %d%% \n",OS_STACK_USAGE(&si));
\r
90 * Functions that must be supplied by the example
\r
93 void OsIdle( void ) {
\r
99 ProtectionReturnType ProtectionHook( StatusType FatalError ) {
\r
100 dbg_printf("## ProtectionHook\n");
\r
101 return PRO_KILLAPPL;
\r
104 void StartupHook( void ) {
\r
105 uint32_t sys_freq = McuE_GetSystemClock();
\r
107 dbg_printf("## StartupHook\n");
\r
109 dbg_printf("Sys clock %d Hz\n",sys_freq);
\r
112 void ShutdownHook( StatusType Error ) {
\r
113 dbg_printf("## ShutdownHook\n");
\r
122 OsServiceIdType serviceId;
\r
126 void ErrorHook( StatusType Error ) {
\r
129 static struct LogBad_s LogBad[ERROR_LOG_SIZE];
\r
130 static uint8_t ErrorCount = 0;
\r
135 OsServiceIdType service = OSErrorGetServiceId();
\r
137 /* Grab the arguments to the functions
\r
138 * This is the standard way, see 11.2 in OSEK spec
141 case OSServiceId_SetRelAlarm:
\r
143 // Read the arguments to the faulty functions...
\r
144 AlarmType alarm_id = OSError_SetRelAlarm_AlarmId;
\r
145 TickType increment = OSError_SetRelAlarm_Increment;
\r
146 TickType cycle = OSError_SetRelAlarm_Cycle;
\r
147 // ... Handle this some way.
\r
151 * The same pattern as above applies for all other OS functions.
\r
152 * See Os.h for names and definitions.
159 dbg_printf("## ErrorHook err=%d\n",Error);
\r
161 /* Log the errors in a buffer for later review */
\r
162 LogBad[ErrorCount].param1 = os_error.param1;
\r
163 LogBad[ErrorCount].param2 = os_error.param2;
\r
164 LogBad[ErrorCount].param3 = os_error.param3;
\r
165 LogBad[ErrorCount].serviceId = service;
\r
166 LogBad[ErrorCount].taskId = task;
\r
167 LogBad[ErrorCount].error = Error;
\r
171 // Stall if buffer is full.
\r
172 while(ErrorCount >= ERROR_LOG_SIZE);
\r
175 void PreTaskHook( void ) {
\r
178 // dbg_printf("## PreTaskHook, taskid=%d\n",task);
\r
181 void PostTaskHook( void ) {
\r
184 // dbg_printf("## PostTaskHook, taskid=%d\n",task);
\r