2 /* -------------------------------- Arctic Core ------------------------------
\r
3 * Arctic Core - the open source AUTOSAR platform http://arccore.com
\r
5 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
\r
7 * This source code is free software; you can redistribute it and/or modify it
\r
8 * under the terms of the GNU General Public License version 2 as published by the
\r
9 * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
\r
11 * This program is distributed in the hope that it will be useful, but
\r
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
\r
15 * -------------------------------- Arctic Core ------------------------------*/
\r
18 * Hold all OSEK system hooks.
\r
21 /* ----------------------------[includes]------------------------------------*/
\r
29 /* ----------------------------[private define]------------------------------*/
\r
30 #define ERROR_LOG_SIZE 1
\r
32 //#define USE_LDEBUG_PRINTF 1
\r
35 /* ----------------------------[private macro]-------------------------------*/
\r
38 /* ----------------------------[private typedef]-----------------------------*/
\r
40 typedef struct ErrorEntry {
\r
44 OsServiceIdType serviceId;
\r
48 typedef struct ErrorLog {
\r
50 ErrorEntryType log[ERROR_LOG_SIZE];
\r
58 OsServiceIdType serviceId;
\r
63 /* ----------------------------[private function prototypes]-----------------*/
\r
64 /* ----------------------------[private variables]---------------------------*/
\r
65 ErrorLogType ErrorLog;
\r
66 /* ----------------------------[private functions]---------------------------*/
\r
67 /* ----------------------------[public functions]----------------------------*/
\r
74 ProtectionReturnType ProtectionHook( StatusType FatalError ) {
\r
75 printf("## ProtectionHook\n");
\r
76 return PRO_KILLAPPL;
\r
82 void StartupHook( void ) {
\r
83 // LDEBUG_PRINTF("## StartupHook\n");
\r
85 uint32_t sys_freq = McuE_GetSystemClock();
\r
87 LDEBUG_PRINTF("Sys clock %d Hz\n",sys_freq);
\r
94 void ShutdownHook( StatusType error ) {
\r
95 LDEBUG_FPUTS("## ShutdownHook\n");
\r
107 void ErrorHook( StatusType error ) {
\r
110 static struct LogBad LogBad[ERROR_LOG_SIZE];
\r
111 static uint8_t ErrorCount = 0;
\r
116 OsServiceIdType service = OSErrorGetServiceId();
\r
118 /* Grab the arguments to the functions
\r
119 * This is the standard way, see 11.2 in OSEK spec
\r
122 case OSServiceId_SetRelAlarm:
\r
124 // Read the arguments to the faulty functions...
\r
125 AlarmType alarm_id = OSError_SetRelAlarm_AlarmId;
\r
126 TickType increment = OSError_SetRelAlarm_Increment;
\r
127 TickType cycle = OSError_SetRelAlarm_Cycle;
\r
132 // ... Handle this some way.
\r
136 * The same pattern as above applies for all other OS functions.
\r
137 * See Os.h for names and definitions.
\r
144 LDEBUG_PRINTF("## ErrorHook err=%u\n",Error);
\r
146 /* Log the errors in a buffer for later review */
\r
147 LogBad[ErrorCount].param1 = os_error.param1;
\r
148 LogBad[ErrorCount].param2 = os_error.param2;
\r
149 LogBad[ErrorCount].param3 = os_error.param3;
\r
150 LogBad[ErrorCount].serviceId = service;
\r
151 LogBad[ErrorCount].taskId = task;
\r
152 LogBad[ErrorCount].error = error;
\r
156 // Stall if buffer is full.
\r
157 while(ErrorCount >= ERROR_LOG_SIZE);
\r
164 void PreTaskHook( void ) {
\r
167 TaskStateType state;
\r
169 rv = GetTaskID(&task);
\r
170 assert( rv == E_OK );
\r
171 LDEBUG_PRINTF("## PreTaskHook, taskid=%d\n",task);
\r
172 rv = GetTaskState(task,&state);
\r
173 assert( rv == E_OK );
\r
174 assert( state == TASK_STATE_RUNNING );
\r
180 void PostTaskHook( void ) {
\r
183 TaskStateType state;
\r
185 rv = GetTaskID(&task);
\r
186 assert( rv == E_OK );
\r
187 LDEBUG_PRINTF("## PostTaskHook, taskid=%d\n",task);
\r
188 rv = GetTaskState(task,&state);
\r
189 assert( rv == E_OK );
\r
190 assert( state == TASK_STATE_RUNNING );
\r