]> rtime.felk.cvut.cz Git - arc.git/blob - system/kernel/include/internal.h
Initial ARM port
[arc.git] / system / kernel / include / internal.h
1 /* -------------------------------- Arctic Core ------------------------------
2  * Arctic Core - the open source AUTOSAR platform http://arccore.com
3  *
4  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>
5  *
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>.
9  *
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
13  * for more details.
14  * -------------------------------- Arctic Core ------------------------------*/
15
16 #ifndef INTERNAL_H_\r
17 #define INTERNAL_H_\r
18 \r
19 #include <assert.h>\r
20 #include "Ramlog.h"\r
21 #include "simple_printf.h"\r
22 \r
23 extern uint32 os_dbg_mask;\r
24 \r
25 /*\r
26  * 0  master print normal, 1-print\r
27  * 1  master print isr     1-print\r
28  * 2  normal 0-stdout,1-ramlog\r
29  * 3  isr    0-stdout,\r
30  *\r
31  * 16 task_low\r
32  * 17 task high\r
33  *\r
34  * 20 alarm\r
35  *\r
36  *\r
37  * So when debugging the kernel using the ISS you want to use:\r
38  * 0xB\r
39  *\r
40  * Ramlog all the way:\r
41  * 0x7\r
42  */\r
43 \r
44 extern uint32 os_dbg_mask;\r
45 \r
46 #define STR_TASK                "OS_TASK"\r
47 #define STR_ALARM               "OS_ALARM"\r
48 #define STR_STBL                "OS_STBL"\r
49 \r
50 \r
51 #define os_dbg_printf(format,...) \\r
52                         if( os_dbg_mask & OS_DBG_MASTER_PRINT ) { \\r
53                                         simple_printf(format,## __VA_ARGS__ );  \\r
54                         }\r
55 \r
56 #define os_dbg_isr_printf(format,...) \\r
57                         if( os_dbg_mask & OS_DBG_ISR_MASTER_PRINT ) { \\r
58                                         simple_printf(format,## __VA_ARGS__ );  \\r
59                         }\r
60 \r
61 #define os_isr_printf(_mask,format,...) \\r
62                         if( (os_dbg_mask & OS_DBG_ISR_MASTER_PRINT) && ((_mask)>255 ) ) { \\r
63                                 if( os_dbg_mask & D_ISR_STDOUT ) { \\r
64                                         simple_printf("[%08d] : ",GetOsTick()); \\r
65                                         simple_printf(format,## __VA_ARGS__ );  \\r
66                                 } else {                                    \\r
67                                         ramlog_printf("[%08d] : ",GetOsTick()); \\r
68                                         ramlog_printf(format,## __VA_ARGS__ );  \\r
69                                 }                                           \\r
70                         }\r
71 \r
72 #define os_std_printf(_mask,format,...) \\r
73                 if( (os_dbg_mask & OS_DBG_MASTER_PRINT) && ((_mask)>255 ) ) { \\r
74                         if( os_dbg_mask & D_STDOUT) { \\r
75                                 simple_printf("[%08d] : ",GetOsTick()); \\r
76                                 simple_printf(format,## __VA_ARGS__ );  \\r
77                         } else {                                    \\r
78                                 ramlog_printf("[%08d] : ",GetOsTick()); \\r
79                                 ramlog_printf(format,## __VA_ARGS__ );  \\r
80                         }                                           \\r
81                 }\r
82 \r
83 #if 0\r
84 #define os_isr_printf(D_TASK,format,...) \\r
85                         if( (os_dbg_mask | OS_DBG_ISR_MASTER_PRINT | OS_DBG_TASK) \\r
86                                         == os_dbg_mask ) { \\r
87                                         simple_printf("[%08d] %s: ",GetOsTick(), STR_TASK); \\r
88                                         simple_printf(format,## __VA_ARGS__ );  \\r
89                         }\r
90 \r
91 #define os_dbg_task_printf(format,...) \\r
92                         if( (os_dbg_mask | OS_DBG_MASTER_PRINT | OS_DBG_TASK) \\r
93                                         == os_dbg_mask ) { \\r
94                                         simple_printf("[%08d] %s: ",GetOsTick(), STR_TASK); \\r
95                                         simple_printf(format,## __VA_ARGS__ );  \\r
96                         }\r
97 #endif\r
98 \r
99 #if 0\r
100 static inline void Irq_Disable( void ) {\r
101         Irq_Disable();\r
102 }\r
103 \r
104 static inline void Irq_Enable( void ) {\r
105         Irq_Enable();\r
106 }\r
107 #endif\r
108 \r
109 \r
110 #if 0\r
111 #define os_dbg_m_printf(_x,format,...) \\r
112                         if( (os_dbg_mask | OS_DBG_ISR_MASTER_PRINT | (_x)) == os_dbg_mask) { \\r
113                                         simple_printf(format,## __VA_ARGS__ );  \\r
114                         }\r
115 #endif\r
116 \r
117 /*\r
118  * PCB manipulating functions\r
119  */\r
120 \r
121 static inline procid_t get_curr_pid( void ) {\r
122         return os_sys.curr_pcb->pid;\r
123 }\r
124 \r
125 static inline pcb_t *get_curr_pcb( void ) {\r
126         return os_sys.curr_pcb;\r
127 }\r
128 \r
129 static inline void set_curr_pcb( pcb_t *pcb ) {\r
130         os_sys.curr_pcb = pcb;\r
131 }\r
132 \r
133 static inline _Bool is_idle_task( pcb_t *pcb ){\r
134         return (pcb->pid == 0);\r
135 }\r
136 \r
137 static inline procid_t get_curr_prio( void ){\r
138         return os_sys.curr_pcb->prio;\r
139 }\r
140 \r
141 static inline TickType get_os_tick( void ) {\r
142         return os_sys.tick;\r
143 }\r
144 \r
145 static inline app_t *get_curr_application( void ) {\r
146         return get_curr_pcb()->application;\r
147 }\r
148 \r
149 static inline uint32_t get_curr_application_id( void ) {\r
150         return get_curr_pcb()->application->application_id;\r
151 }\r
152 \r
153 static inline struct resource_obj_s *os_get_resource_int_p( void ) {\r
154         return get_curr_pcb()->resource_int_p;\r
155 }\r
156 \r
157 /*\r
158  * Misc
159  */\r
160 \r
161 static inline uint32_t os_task_nr_to_mask( uint32_t nr ) {\r
162         return (1<<nr);\r
163 }\r
164 \r
165 // task_i.c\r
166 pcb_t *os_find_top_prio_proc( void );\r
167 pcb_t *os_find_task( TaskType tid );\r
168 \r
169 // resource.c\r
170 void os_resource_get_internal(void );\r
171 void os_resource_release_internal( void );\r
172 // Create.c\r
173 pcb_t * os_alloc_new_pcb( void );\r
174 \r
175 \r
176 void OsTick( void );\r
177 \r
178 void *Os_Isr( void *stack, void *pcb_p );\r
179 \r
180 \r
181 #endif /*INTERNAL_H_*/\r