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
21 #define USE_LDEBUG_PRINTF
\r
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 LDEBUG_PRINTF("[%08u] btask_3 start\n", (unsigned)GetOsTick() );
\r
37 GetTaskID(&currTask);
\r
38 Os_Arc_GetStackInfo(currTask,&si);
\r
39 LDEBUG_PRINTF("btask_3: %u%% stack usage\n",
\r
40 (unsigned)OS_STACK_USAGE(&si));
\r
46 * An extended task is auto-started and is also triggered by an alarm
\r
47 * that sets event 2.
\r
50 void etask_1( void ) {
\r
51 volatile float tryFloatingPoint = 0.0F;
\r
55 LDEBUG_PRINTF("etask_1 start\n");
\r
57 SetEvent(TASK_ID_etask_2,EVENT_MASK_EVENT_1);
\r
58 WaitEvent(EVENT_MASK_EVENT_2);
\r
59 ClearEvent(EVENT_MASK_EVENT_2);
\r
60 tryFloatingPoint += 1.0F;
\r
61 GetTaskID(&currTask);
\r
62 Os_Arc_GetStackInfo(currTask,&si);
\r
63 LDEBUG_PRINTF("etask_1: %u%% stack usage\n",
\r
64 (unsigned)OS_STACK_USAGE(&si));
\r
70 * An extended task that receives events from someone
\r
71 * and activates task: btask_3.
\r
73 void etask_2( void ) {
\r
74 LDEBUG_PRINTF("etask_2 start\n");
\r
77 WaitEvent(EVENT_MASK_EVENT_1);
\r
78 ClearEvent(EVENT_MASK_EVENT_1);
\r
79 ActivateTask(TASK_ID_btask_3);
\r
83 GetTaskID(&currTask);
\r
84 Os_Arc_GetStackInfo(currTask,&si);
\r
85 LDEBUG_PRINTF("etask_2: %u%% stack usage\n",
\r
86 (unsigned)OS_STACK_USAGE(&si));
\r
93 * Functions that must be supplied by the example
\r
96 void OsIdle( void ) {
\r
102 ProtectionReturnType ProtectionHook( StatusType FatalError ) {
\r
103 LDEBUG_PRINTF("## ProtectionHook\n");
\r
104 return PRO_KILLAPPL;
\r
107 void StartupHook( void ) {
\r
108 uint32_t sys_freq = McuE_GetSystemClock();
\r
110 LDEBUG_PRINTF("## StartupHook\n");
\r
112 LDEBUG_PRINTF("Sys clock %u Hz\n",(unsigned)sys_freq);
\r
115 void ShutdownHook( StatusType Error ) {
\r
116 LDEBUG_PRINTF("## ShutdownHook\n");
\r
125 OsServiceIdType serviceId;
\r
129 void ErrorHook( StatusType Error ) {
\r
132 static struct LogBad_s LogBad[ERROR_LOG_SIZE];
\r
133 static uint8_t ErrorCount = 0;
\r
138 OsServiceIdType service = OSErrorGetServiceId();
\r
140 /* Grab the arguments to the functions
\r
141 * This is the standard way, see 11.2 in OSEK spec
\r
144 case OSServiceId_SetRelAlarm:
\r
146 // Read the arguments to the faulty functions...
\r
147 AlarmType alarm_id = OSError_SetRelAlarm_AlarmId;
\r
148 TickType increment = OSError_SetRelAlarm_Increment;
\r
149 TickType cycle = OSError_SetRelAlarm_Cycle;
\r
154 // ... Handle this some way.
\r
158 * The same pattern as above applies for all other OS functions.
\r
159 * See Os.h for names and definitions.
\r
166 LDEBUG_PRINTF("## ErrorHook err=%u\n",Error);
\r
168 /* Log the errors in a buffer for later review */
\r
169 LogBad[ErrorCount].param1 = os_error.param1;
\r
170 LogBad[ErrorCount].param2 = os_error.param2;
\r
171 LogBad[ErrorCount].param3 = os_error.param3;
\r
172 LogBad[ErrorCount].serviceId = service;
\r
173 LogBad[ErrorCount].taskId = task;
\r
174 LogBad[ErrorCount].error = Error;
\r
178 // Stall if buffer is full.
\r
179 while(ErrorCount >= ERROR_LOG_SIZE);
\r
182 void PreTaskHook( void ) {
\r
185 // LDEBUG_PRINTF("## PreTaskHook, taskid=%u\n",task);
\r
188 void PostTaskHook( void ) {
\r
191 // LDEBUG_PRINTF("## PostTaskHook, taskid=%u\n",task);
\r