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 ------------------------------*/
24 // How many errors to keep in error log.
\r
25 #define ERROR_LOG_SIZE 20
\r
29 * Just an example of a basic task.
\r
32 void btask_3( void ) {
\r
35 dbg_printf("[%08d] btask_3 start\n", GetOsTick() );
\r
37 GetTaskID(&currTask);
\r
38 Os_Arc_GetStackInfo(currTask,&si);
\r
39 dbg_printf("btask_3: Stack usage %d%%\n",OS_STACK_USAGE(&si));
\r
45 * An extended task is auto-started and is also triggered by an alarm
\r
46 * that sets event 2.
\r
49 void etask_1( void ) {
\r
50 volatile float tryFloatingPoint = 0.0F;
\r
55 dbg_printf("etask_1 start\n");
\r
57 SetEvent(TASK_ID_etask_2,1);
\r
60 tryFloatingPoint += 1.0F;
\r
61 GetTaskID(&currTask);
\r
62 Os_Arc_GetStackInfo(currTask,&si);
\r
63 dbg_printf("etask_1: Stack usage %d%% \n",OS_STACK_USAGE(&si));
\r
69 * An extended task that receives events from someone
\r
70 * and activates task: btask_3.
72 void etask_2( void ) {
\r
73 dbg_printf("etask_2 start\n");
\r
78 ActivateTask(TASK_ID_btask_3);
\r
82 GetTaskID(&currTask);
\r
83 Os_Arc_GetStackInfo(currTask,&si);
\r
84 dbg_printf("etask_1: Stack usage %d%% \n",OS_STACK_USAGE(&si));
\r
91 * Functions that must be supplied by the example
\r
94 void OsIdle( void ) {
\r
100 ProtectionReturnType ProtectionHook( StatusType FatalError ) {
\r
101 dbg_printf("## ProtectionHook\n");
\r
102 return PRO_KILLAPPL;
\r
105 void StartupHook( void ) {
\r
106 uint32_t sys_freq = McuE_GetSystemClock();
\r
108 dbg_printf("## StartupHook\n");
\r
110 dbg_printf("Sys clock %d Hz\n",sys_freq);
\r
113 void ShutdownHook( StatusType Error ) {
\r
114 dbg_printf("## ShutdownHook\n");
\r
123 OsServiceIdType serviceId;
\r
127 void ErrorHook( StatusType Error ) {
\r
130 static struct LogBad_s LogBad[ERROR_LOG_SIZE];
\r
131 static uint8_t ErrorCount = 0;
\r
136 OsServiceIdType service = OSErrorGetServiceId();
\r
138 /* Grab the arguments to the functions
\r
139 * This is the standard way, see 11.2 in OSEK spec
142 case OSServiceId_SetRelAlarm:
\r
144 // Read the arguments to the faulty functions...
145 /* (Commented to remove warnings)
146 AlarmType alarm_id = OSError_SetRelAlarm_AlarmId;
\r
147 TickType increment = OSError_SetRelAlarm_Increment;
\r
148 TickType cycle = OSError_SetRelAlarm_Cycle; */
149 // ... Handle this some way.
\r
153 * The same pattern as above applies for all other OS functions.
\r
154 * See Os.h for names and definitions.
161 dbg_printf("## ErrorHook err=%d\n",Error);
\r
163 /* Log the errors in a buffer for later review */
\r
164 LogBad[ErrorCount].param1 = os_error.param1;
\r
165 LogBad[ErrorCount].param2 = os_error.param2;
\r
166 LogBad[ErrorCount].param3 = os_error.param3;
\r
167 LogBad[ErrorCount].serviceId = service;
\r
168 LogBad[ErrorCount].taskId = task;
\r
169 LogBad[ErrorCount].error = Error;
\r
173 // Stall if buffer is full.
\r
174 while(ErrorCount >= ERROR_LOG_SIZE);
\r
177 void PreTaskHook( void ) {
\r
180 // dbg_printf("## PreTaskHook, taskid=%d\n",task);
\r
183 void PostTaskHook( void ) {
\r
186 // dbg_printf("## PostTaskHook, taskid=%d\n",task);
\r