1 
2 #include <os.h>
3 
4 /************************************************/
5 /*    Azure RTOS Implementation Specific        */
6 /************************************************/
7 
8 /* Osek application definition.  */
9 APPLICATION_INFO    Application1;
10 
11 /* Task definition.  */
12 TaskType      Task1;
13 
14 /* Alarm definition.  */
15 AlarmType     Alarm1;
16 
17 /* Resource definition.  */
18 ResourceType  Resource1;
19 
20 /* Event definition.  */
21 EventMaskType       Event1;
22 
23 /* Counter definition.  */
24 CounterType       SystemTimer;
25 
26 /* Demo ISR definition.  */
27 ISRType DemoISR;
28 
29 /* Task body declaration.  */
30 DeclareTask(Task1);
31 
32 /* Demo ISR body declaration.  */
33 DeclareISR(DemoISR);
34 
35 /* User hooks declarations.  */
36 static void ShutdownHook(StatusType Error);
37 
38 static void PreTaskHook(void);
39 
40 static void PostTaskHook(void);
41 
42 static void StartupHook(void);
43 
44 static void ErrorHook(StatusType Error);
45 
46 
47 /* ThreadX timer for demo ISR.  */
48 TX_TIMER demo_isr_timer;
49 
50 /* Entry function for the ThreadX timer.  */
51 VOID demo_isr_timer_entry(ULONG arg);
52 
53 
54 /* Main function.  */
main()55 int main()
56 {
57 
58     tx_kernel_enter();
59 
60 }
61 ULONG free_memory[64*1024 / sizeof(ULONG)];
62 
tx_application_define(VOID * first_unused_memory)63 VOID tx_application_define(VOID * first_unused_memory)
64 {
65 
66 CHAR    * pointer;
67 
68     /* Put the first available address into character pointer.  */
69     pointer = (CHAR * )free_memory;
70 
71     /* Setup hook pointers (optional). */
72     Application1.shutdown_hook_handler = ShutdownHook;
73     Application1.pretask_hook_handler = PreTaskHook;
74     Application1.posttask_hook_handler = PostTaskHook;
75     Application1.startup_hook_handler = StartupHook;
76     Application1.error_hook_handler = ErrorHook;
77 
78     /* Initialize a pointer.  */
79     osek_initialize(pointer,&Application1);
80 
81     /* Create the system counter  */
82     SystemTimer = CreateCounter("SystemTimer", 0x7FFFFFFF, 2, 2, 0);
83     DefineSystemCounter(SystemTimer);
84 
85     /* Create the first Task.  */
86     Task1 = CreateTask("Task1", TaskEntry(Task1), 3, 1, 1024, NON, TRUE, EXTENDED, 0);
87 
88     /* Create an event. */
89     Event1 = CreateEvent();
90 
91     /* Register Event1 to Task1.  */
92     RegisterEventtoTask(Event1 , Task1);
93 
94     /* Create a resource.  */
95     Resource1 = CreateResource("Resource1", STANDARD, 0);
96 
97     /* Register Resource1 to Task1.  */
98     RegisterTasktoResource(Resource1, Task1);
99 
100     /* Create a demo ISR triggered by a ThreadX timer. */
101     DemoISR = CreateISR("Demo ISR", ISREntry(DemoISR), CATEGORY2, 1024);
102 
103     /* Create a ThreadX timer to simulate an ISR.  */
104     tx_timer_create(&demo_isr_timer, "Demo ISR timer", demo_isr_timer_entry, DemoISR,
105                      1000, 1000, TX_AUTO_ACTIVATE);
106 
107     /* Start OSEK  */
108     StartOS(OSDEFAULTAPPMODE);
109 
110 }
111 
112 /* Task body.  */
TASK(Task1)113 TASK(Task1)
114 {
115     /* Task body. */
116     while(1)
117     {
118     }
119 }
120 
121 /* Demo category 2 ISR function body.  */
ISR(DemoISR)122 ISR(DemoISR)
123 {
124     /* ISR body. */
125 }
126 
ShutdownHook(StatusType Error)127 static void ShutdownHook(StatusType Error)
128 {
129     /* Hook body.  */
130 }
131 
PreTaskHook(void)132 static void PreTaskHook(void)
133 {
134     /* Hook body.  */
135 }
136 
PostTaskHook(void)137 static void PostTaskHook(void)
138 {
139     /* Hook body.  */
140 }
141 
StartupHook(void)142 static void StartupHook(void)
143 {
144     /* Hook body.  */
145 }
146 
ErrorHook(StatusType Error)147 static void ErrorHook(StatusType Error)
148 {
149     /* Hook body.  */
150 }
151 
152 /* ThreadX timer handler to simulate an ISR.  */
demo_isr_timer_entry(ULONG arg)153 VOID demo_isr_timer_entry(ULONG arg)
154 {
155     /* Call OSEK to process the ISR.  */
156     process_ISR2(arg);
157 }
158