]> rtime.felk.cvut.cz Git - arc.git/blob - examples/pwm_node/Hooks.c
Added pwm_node example for hcs12
[arc.git] / examples / pwm_node / Hooks.c
1 /* -------------------------------- Arctic Core ------------------------------\r
2  * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
3  *\r
4  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>\r
5  *\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
9  *\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
13  * for more details.\r
14  * -------------------------------- Arctic Core ------------------------------*/\r
15 \r
16 \r
17 \r
18 \r
19 \r
20 \r
21 \r
22 \r
23 #include "Os.h"\r
24 #include "mcu.h"\r
25 #include "Pwm.h"\r
26 #include <stdio.h>\r
27 #include <assert.h>\r
28 #define USE_TRACE       1\r
29 #define USE_LDEBUG_PRINTF 1\r
30 #include "debug.h"\r
31 \r
32 /* Notification callback from channel 0 */\r
33 void MyPwmNotificationRoutine(void) {\r
34         static uint32 count = 0;\r
35         static uint32 highcount = 0;\r
36         static uint32 lowcount = 0;\r
37         Pwm_OutputStateType outputState = Pwm_GetOutputState(PWM_CHANNEL_1);\r
38 \r
39         if (outputState == PWM_HIGH) {\r
40                 highcount++;\r
41         } else {\r
42                 lowcount++;\r
43         }\r
44 \r
45         count++;\r
46 }\r
47 \r
48 \r
49 /* Global hooks */\r
50 ProtectionReturnType ProtectionHook( StatusType FatalError ) {\r
51         LDEBUG_PRINTF("## ProtectionHook\n");\r
52         return PRO_KILLAPPL;\r
53 }\r
54 \r
55 void StartupHook( void ) {\r
56         LDEBUG_PRINTF("## StartupHook\n");\r
57 \r
58         uint32_t sys_freq = McuE_GetSystemClock();\r
59 \r
60         LDEBUG_PRINTF("Sys clock %d Hz\n",sys_freq);\r
61 }\r
62 \r
63 void ShutdownHook( StatusType Error ) {\r
64         LDEBUG_PRINTF("## ShutdownHook\n");\r
65         while(1);\r
66 }\r
67 \r
68 void ErrorHook( StatusType Error ) {\r
69         DisableAllInterrupts();\r
70 \r
71         LDEBUG_PRINTF("## ErrorHook err=%d\n",Error);\r
72         while(1);\r
73 }\r
74 \r
75 void PreTaskHook( void ) {\r
76         TaskType task;\r
77         GetTaskID(&task);\r
78         if( task > 10 ) {\r
79                 while(1);\r
80         }\r
81 //      LDEBUG_PRINTF("## PreTaskHook, taskid=%d\n",task);\r
82 }\r
83 \r
84 void PostTaskHook( void ) {\r
85         TaskType task;\r
86         GetTaskID(&task);\r
87         if( task > 10 ) {\r
88                 while(1);\r
89         }\r
90 //      LDEBUG_PRINTF("## PostTaskHook, taskid=%d\n",task);\r
91 }\r
92 \r
93 #if 0\r
94 struct OsHooks os_conf_global_hooks = {\r
95                 .StartupHook = StartupHook,\r
96                 .ProtectionHook = ProtectionHook,\r
97                 .ShutdownHook = ShutdownHook,\r
98                 .ErrorHook = ErrorHook,\r
99                 .PreTaskHook = PreTaskHook,\r
100                 .PostTaskHook = PostTaskHook\r
101                 };\r
102 #endif\r