1 /* -------------------------------- Arctic Core ------------------------------
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
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>.
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
14 * -------------------------------- Arctic Core ------------------------------*/
26 * | |--- Platform_Types.h (std?)
27 * | |--- Compiler.h (std?)
38 * kernel.h (shared types between config and OS source... pointless?)
40 * |------------------|
45 * -------------------------------------
46 * Os.h - OS API and types
47 * os_config_func.h - Inline API for Os_Cfg.c
48 * ext_config.h - API for os_config_func.h, used by kernel
49 * internal.h - Internal API for kernel, do NOT expose outside kernel
51 * os_types.h - Internal types for the kernel
63 extern uint32_t os_dbg_mask;
\r
66 * 0 master print normal, 1-print
\r
67 * 1 master print isr 1-print
\r
68 * 2 normal 0-stdout,1-ramlog
\r
77 * So when debugging the kernel using the ISS you want to use:
\r
80 * Ramlog all the way:
\r
84 extern uint32_t os_dbg_mask;
\r
86 #define STR_TASK "OS_TASK"
\r
87 #define STR_ALARM "OS_ALARM"
\r
88 #define STR_STBL "OS_STBL"
\r
91 #define os_dbg_printf(format,...) \
\r
92 if( os_dbg_mask & OS_DBG_MASTER_PRINT ) { \
\r
93 simple_printf(format,## __VA_ARGS__ ); \
\r
96 #define os_dbg_isr_printf(format,...) \
\r
97 if( os_dbg_mask & OS_DBG_ISR_MASTER_PRINT ) { \
\r
98 simple_printf(format,## __VA_ARGS__ ); \
\r
101 #define os_isr_printf(_mask,format,...) \
\r
102 if( (os_dbg_mask & OS_DBG_ISR_MASTER_PRINT) && ((_mask)>255 ) ) { \
\r
103 if( os_dbg_mask & D_ISR_STDOUT ) { \
\r
104 simple_printf("[%08d] : ",GetOsTick()); \
\r
105 simple_printf(format,## __VA_ARGS__ ); \
\r
107 ramlog_printf("[%08d] : ",GetOsTick()); \
\r
108 ramlog_printf(format,## __VA_ARGS__ ); \
\r
112 #define os_std_printf(_mask,format,...) \
\r
113 if( (os_dbg_mask & OS_DBG_MASTER_PRINT) && ((_mask)>255 ) ) { \
\r
114 if( os_dbg_mask & D_STDOUT) { \
\r
115 simple_printf("[%08d] : ",GetOsTick()); \
\r
116 simple_printf(format,## __VA_ARGS__ ); \
\r
118 ramlog_printf("[%08d] : ",GetOsTick()); \
\r
119 ramlog_printf(format,## __VA_ARGS__ ); \
\r
126 #include "ext_config.h"
131 * Macros for error handling
132 * Registers service id of the erroneous function and the applicable parameters
133 * to os_error. Functions that have less than three parameters do not touch
134 * os_error.param3. Same rule follows for other parameter counts.
137 /* Error handling for functions that take no arguments */
138 #define OS_STD_END(_service_id) \
141 os_error.serviceId=_service_id;\
146 /* Error handling for functions that take one argument */
147 #define OS_STD_END_1(_service_id, _p1) \
150 os_error.serviceId=_service_id;\
151 os_error.param1 = (uint32_t) _p1; \
156 /* Error handling for functions that take two arguments */
157 #define OS_STD_END_2(_service_id, _p1,_p2) \
160 os_error.serviceId=_service_id;\
161 os_error.param1 = (uint32_t) _p1; \
162 os_error.param2 = (uint32_t) _p2; \
167 /* Error handling for functions that take three arguments */
168 #define OS_STD_END_3(_service_id,_p1,_p2,_p3) \
171 os_error.serviceId=_service_id;\
172 os_error.param1 = (uint32_t) _p1; \
173 os_error.param2 = (uint32_t) _p2; \
174 os_error.param3 = (uint32_t) _p3; \
181 /* Called for sequence of error hook calls in case a service
182 * does not return with E_OK. Note that in this case the general error hook and the OS-
183 * Application specific error hook are called.
186 #define ERRORHOOK(x) \
187 if( os_sys.hooks->ErrorHook != NULL ) { \
188 os_sys.hooks->ErrorHook(x); \
192 #define PRETASKHOOK() \
193 if( os_sys.hooks->PreTaskHook != NULL ) { \
194 os_sys.hooks->PreTaskHook(); \
197 #define POSTTASKHOOK() \
198 if( os_sys.hooks->PostTaskHook != NULL ) { \
199 os_sys.hooks->PostTaskHook(); \
203 * PCB manipulating functions
\r
206 static inline OsTaskidType get_curr_pid( void ) {
\r
207 return os_sys.curr_pcb->pid;
\r
210 static inline OsPcbType *get_curr_pcb( void ) {
\r
211 return os_sys.curr_pcb;
\r
214 static inline void set_curr_pcb( OsPcbType *pcb ) {
\r
215 os_sys.curr_pcb = pcb;
\r
218 static inline _Bool is_idle_task( OsPcbType *pcb ){
\r
219 return (pcb->pid == 0);
\r
222 static inline OsTaskidType get_curr_prio( void ){
\r
223 return os_sys.curr_pcb->prio;
\r
226 static inline TickType get_os_tick( void ) {
\r
227 return os_sys.tick;
\r
230 #if ( OS_SC1 == STD_ON ) || ( OS_SC4 == STD_ON )
\r
231 static inline OsApplicationType *get_curr_application( void ) {
\r
232 return get_curr_pcb()->application;
\r
235 static inline uint32_t get_curr_application_id( void ) {
\r
236 return get_curr_pcb()->application->application_id;
\r
240 static inline struct OsResource *os_get_resource_int_p( void ) {
\r
241 return get_curr_pcb()->resource_int_p;
\r
248 static inline uint32_t os_task_nr_to_mask( uint32_t nr ) {
\r
253 OsPcbType *Os_TaskGetTop( void );
\r
254 OsPcbType *os_find_task( TaskType tid );
\r
257 void Os_ResourceGetInternal(void );
\r
258 void Os_ResourceReleaseInternal( void );
261 static inline void Os_ResourceCheckAndRelease( OsPcbType *pcb ) {
262 if( !TAILQ_EMPTY(&pcb->resource_head) ) {
263 OsResourceType *rPtr;
265 TAILQ_FOREACH(rPtr, &pcb->resource_head, listEntry ) {
266 ReleaseResource(rPtr->nr);
267 /* Requirements are a little fuzzy here, no explicit
268 * requirement for this.
270 ERRORHOOK(E_OS_RESOURCE);
277 OsPcbType * os_alloc_new_pcb( void );
\r
279 void os_dispatch(void);
\r
281 void OsTick( void );
\r
283 void *Os_Isr( void *stack, void *pcb_p );
284 void Os_Dispatch( _Bool force );
286 #define STACK_PATTERN 0x42
288 static inline void *Os_StackGetUsage( OsPcbType *pcb ) {
290 uint8_t *p = pcb->stack.curr;
291 uint8_t *end = pcb->stack.top;
293 while( (*end == STACK_PATTERN) && (end<p)) {
299 static inline void Os_StackSetEndmark( OsPcbType *pcbPtr ) {
300 uint8_t *end = pcbPtr->stack.top;
301 *end = STACK_PATTERN;
304 static inline _Bool Os_StackIsEndmarkOk( OsPcbType *pcbPtr ) {
305 uint8_t *end = pcbPtr->stack.top;
306 return ( *end == STACK_PATTERN);
310 int Oil_GetTaskCnt(void);
311 void Os_ContextReInit( OsPcbType *pcbPtr );
314 static inline _Bool Os_IrqAnyDisabled( void ) {
315 return ((Os_IntDisableAllCnt | Os_IntSuspendAllCnt | Os_IntSuspendOsCnt) != 0);
318 static inline void Os_IrqClearAll( void ) {
319 Os_IntDisableAllCnt = 0;
320 Os_IntSuspendAllCnt = 0;
321 Os_IntSuspendOsCnt = 0;
325 #endif /*INTERNAL_H_*/
\r