(void)flags;
(void)mode;
+#if defined(USE_RAMLOG)
if( strcmp(name,"ramlog") == 0 ) {
return FILE_RAMLOG;
}
+#endif
return -1;
}
* for more details.
* -------------------------------- Arctic Core ------------------------------*/
+/**
+ * A very simple ramlog.
+ *
+ * Features:
+ * - Prints to a ram space in section ".ramlog"
+ * - The size is configurable using CFG_RAMLOG_SIZE (default is 1000)
+ * - The ramlog section should not be cleared by the linkfile if one wants
+ * to have a ramlog that survives reset.
+ *
+ * Assumes some c-lib support:
+ * - The clib support should be able to open a file called "ramlog".
+ * - Printing to that file will print to the ramlog.
+ *
+ */
+
#include <stdio.h>
#include <stdarg.h>
#include "simple_printf.h"
static FILE *ramlogFile = 0;
+/**
+ * Print a char to the ramlog
+ * @param c
+ */
void ramlog_chr( char c ) {
ramlog[ramlog_curr++] = c;
if( ramlog_curr >= CFG_RAMLOG_SIZE ) {
}
}
+/**
+ * Print a string to the ramlog
+ * @param str
+ */
void ramlog_puts( char *str ) {
while(*str!=0) {
ramlog_chr('\n');
}
+/**
+ * Formatted print for the ramlog.
+ *
+ * @param format The format string.
+ */
void ramlog_printf( const char *format, ... ) {
// Fast and ugly ramlog support.
va_end(args);
}
+
+/**
+ * Initialize the ramlog. Must be called before any other ramlog functions.
+ */
void ramlog_init()
{
char buf[32];
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
* -------------------------------- Arctic Core ------------------------------*/
-
-
-
-
-
-
-
-
/*\r
* strace.c\r
*\r
* System trace...\r
* Idea to trace\r
*\r
- *\r
* Inspiration:\r
* http://ltt.polymtl.ca/tracingwiki/index.php/TracingBook\r
* http://developer.apple.com/tools/performance/optimizingwithsystemtrace.html\r
* for more details.
* -------------------------------- Arctic Core ------------------------------*/
+#include <stdlib.h>
+/**
+ * K & R itoa
+ */
+void strreverse(char* begin, char* end) {
+ char c;
+ while (end > begin) {
+ c = *end;
+ *end-- = *begin;
+ *begin++ = c;
+ }
+}
+/**
+ * Convert a number to a string
+ *
+ * @param val The value to convert
+ * @param str Pointer to a space where to put the string
+ * @param base The base
+ * @param negative If negative or not.
+ */
+void xtoa( unsigned long val, char* str, int base, int negative) {
+ static char num[] = "0123456789abcdefghijklmnopqrstuvwxyz";
+ char* wstr = str;
+ int value = (int) val;
+
+ div_t res;
+
+ // Validate base
+ if (base < 2 || base > 35) {
+ *wstr = '\0';
+ return;
+ }
+
+ // Check sign
+ if (negative) {
+ value = -value;
+ }
+
+ do {
+ res = div(value, base);
+ *wstr++ = num[res.rem];
+ } while ((value = res.quot));
+ if (negative)
+ *wstr++ = '-';
+ *wstr = '\0';
+
+ // Reverse string
+ strreverse(str, wstr - 1);
+}
+
+/**
+ * Converts an unsigned long to a string
+ *
+ * @param value The value to convert
+ * @param str Pointer to the string
+ * @param base The base
+ */
+void ultoa(unsigned long value, char* str, int base) {
+ xtoa(value, str, base, 0);
+}
+
+/**
+ * Converts an integer to a string
+ *
+ * @param value The value to convert
+ * @param str Pointer to the string to write to
+ * @param base The base
+ */
+void itoa(int value, char* str, int base) {
+ xtoa(value, str, base, (value < 0));
+}
-\r
-#include <stdlib.h>\r
-/**\r
- * Ansi C "itoa" based on Kernighan & Ritchie's "Ansi C"\r
- * with slight modification to optimize for specific architecture:\r
- */\r
-\r
-void strreverse(char* begin, char* end) {\r
-\r
- char aux;\r
-\r
- while (end > begin) {\r
- aux = *end, *end-- = *begin, *begin++ = aux;\r
- }\r
-}\r
-\r
-\r
-// int to string\r
-void xtoa(unsigned long val, char* str, int base,int negative) {\r
- static char num[] = "0123456789abcdefghijklmnopqrstuvwxyz";\r
- char* wstr = str;\r
- int value = (int)val;\r
-\r
- div_t res;\r
-\r
- // Validate base\r
- if (base < 2 || base > 35) {\r
- *wstr = '\0';\r
- return;\r
- }\r
-\r
- // Check sign\r
- if ( negative ) {\r
- value = -value;\r
- }\r
-\r
- do {\r
- res = div(value, base);\r
- *wstr++ = num[res.rem];\r
- } while ((value = res.quot));\r
-\r
- if (negative)\r
- *wstr++ = '-';\r
-\r
- *wstr = '\0';\r
-\r
- // Reverse string\r
- strreverse(str, wstr - 1);\r
-}\r
-\r
-\r
-// unsigned long to string\r
-void ultoa(unsigned long value, char* str, int base) {\r
- xtoa(value,str,base,0);\r
-}\r
-\r
-// int to string\r
-void itoa(int value, char* str, int base) {\r
- xtoa(value,str,base,(value<0));\r
-}\r
-\r
\r
// --- ALARMS ---\r
#define ALARM_USE\r
+
+GEN_ALARM_AUTOSTART( 0, ALARM_AUTOSTART_ABSOLUTE, 100, 10, OSDEFAULTAPPMODE );
\r
GEN_ALARM_HEAD {\r
GEN_ALARM( 0,"Alarm1",COUNTER_ID_OsTick,
- 1,100,10,0, /*active,start,cycle,app_mask */\r
+ GEN_ALARM_AUTOSTART_NAME(0),\r
ALARM_ACTION_SETEVENT, TASK_ID_etask_1, 2, 0 ),\r
};\r
\r
#include <stdlib.h>
#include <stdint.h>
-#include "os_config_macros.h"
#include "Platform_Types.h"
#include "Os.h" // includes Os_Cfg.h
+#include "os_config_macros.h"
#include "kernel.h"
#include "kernel_offset.h"
#include "alist_i.h"
// --- ALARMS ---\r
#define ALARM_USE\r
\r
-GEN_ALARM_HEAD {\r
- GEN_ALARM( 0,"Alarm_4ms",COUNTER_ID_OsTick,\r
- 1,100,2,0, /*active,start,cycle,app_mask */\r
- ALARM_ACTION_SETEVENT, TASK_ID_etask_1, 2, 0 ),\r
-};\r
+GEN_ALARM_AUTOSTART( 0, ALARM_AUTOSTART_ABSOLUTE, 100, 2 , OSDEFAULTAPPMODE );
+
+GEN_ALARM_HEAD {
+ GEN_ALARM( 0,"Alarm_4ms",COUNTER_ID_OsTick,
+ GEN_ALARM_AUTOSTART_NAME(0),
+ ALARM_ACTION_SETEVENT, TASK_ID_etask_1, 2, 0 ),
+};
\r
// --- SCHEDULETABLES ---\r
\r
typedef TaskStateType *TaskStateRefType;\r
\r
/* FIXME: OSMEMORY_IS__ , see 8.2*/\r
-\r
+
+#define OSDEFAULTAPPMODE 1\r
\r
#define INVALID_OSAPPLICATION (-1)\r
\r
* for more details.
* -------------------------------- Arctic Core ------------------------------*/
+/* Configure "rules"
+ * - Don't pollute the namespace with the generator tools. The tools should
+ * ONLY know the GEN_xxx macros.
+ * - If something is a container with multiplicity 1 and above, make it a pointer.
+ * - ...
+ */
+
#ifndef _OS_CONFIG_MACROS_H\r
#define _OS_CONFIG_MACROS_H\r
\r
// For now...
.driver.OsGptChannelRef = _gpt_ch
#endif
+
+
+#define GEN_ALARM_AUTOSTART_NAME(_id) &(Os_AlarmAutoStart_ ## _id)
+
+/**
+ * _id
+ * _type
+ * _alarms_time
+ * _cycle_time
+ * _app_mode
+ */
+#define GEN_ALARM_AUTOSTART(_id, _type, _alarm_time, _cycle_time, _app_mode ) \
+ const OsAlarmAutostartType Os_AlarmAutoStart_ ## _id = \
+ { \
+ .autostartType = _type, \
+ .alarmTime = _alarm_time, \
+ .cycleTime = _cycle_time, \
+ .appModeRef = _app_mode \
+ }
\r
#define GEN_ALARM_HEAD OsAlarmType alarm_list[] =\r
* _counter_id
* The id of the counter to drive the alarm
*
- * _autostart_active
- * If the alarm should be auto-started.
- *
- * _autostart_alarmtime
- * Only used if active = 1
- *
- * _autostart_cycletime
- * Only used if active = 1
- *
- * _autostart_application_mode_mask
- * Set to 0 for now
+ * _autostart_ref
*
* _X_type - Any of:
* ALARM_ACTION_ACTIVATETASK
* _X_counter_id - The counter ID if type is ALARM_ACTION_INCREMENTCOUNTER
*
*/
-#define GEN_ALARM( _id, _name, _counter_id, \\r
- _autostart_active, \\r
- _autostart_alarmtime, \\r
- _autostart_cycletime, \\r
- _autostart_application_mode_mask,\\r
+#define GEN_ALARM( _id, _name, _counter_id, \
+ _autostart_ref, \\r
_action_type, \\r
_action_task_id, \\r
_action_event_id, \\r
.name = _name, \\r
.counter = &counter_list[_counter_id], \\r
.counter_id = _counter_id, \\r
- .autostart = { \\r
- .active = _autostart_active, \\r
- .alarmtime = _autostart_alarmtime, \\r
- .cycletime = _autostart_cycletime, \\r
- .appmode_mask = _autostart_application_mode_mask, \\r
- }, \\r
+ .autostartPtr = _autostart_ref, \\r
.action = { \\r
.type = _action_type, \\r
.task_id = _action_task_id, \\r
.event_id = _action_event_id, \\r
.counter_id = _action_counter_id \\r
}, \\r
-}\r
+}
+
+/*\r
+ *---------------------- SCHEDULE TABLES -----------------------------------
+ */
+
+#define GEN_SCHTBL_EXPIRY_POINT_HEAD(_id ) \
+ OsScheduleTableExpiryPointType Os_SchTblExpPointList_##_id[] =
+
+#define GEN_SCHTBL_EXPIRY_POINT_W_TASK_EVENT(_id, _offset ) \
+ { \
+ .offset = _offset, \
+ .taskList = Os_SchTblTaskList_ ## _id ## _ ## _offset, \
+ .taskListCnt = ARRAY_SIZE(Os_SchTblTaskList_ ## _id ## _ ## _offset), \
+ .eventList = Os_SchTblEventList_ ## _id ## _ ## _offset, \
+ .eventListCnt = ARRAY_SIZE(Os_SchTblEventList_ ## _id ## _ ## _offset) \
+ }
+
+#define GEN_SCHTBL_EXPIRY_POINT_W_TASK(_id, _offset ) \
+ { \
+ .offset = _offset, \
+ .taskList = Os_SchTblTaskList_ ## _id ## _ ## _offset, \
+ .taskListCnt = ARRAY_SIZE(Os_SchTblTaskList_ ## _id ## _ ## _offset), \
+ }
+
+#define GEN_SCHTBL_EXPIRY_POINT_W_EVENT(_id, _offset ) \
+ { \
+ .offset = _offset, \
+ .eventList = Os_SchTblEventList_ ## _id ## _ ## _offset, \
+ .eventListCnt = ARRAY_SIZE(Os_SchTblEventList_ ## _id ## _ ## _offset) \
+ }
+
+#define GEN_SCHTBL_TASK_LIST_HEAD( _id, _offset ) \
+ const TaskType Os_SchTblTaskList_ ## _id ## _ ## _offset[] =
+
+#define GEN_SCHTBL_EVENT_LIST_HEAD( _id, _offset ) \
+ const OsScheduleTableEventSettingType Os_SchTblEventList_ ## _id ## _ ## _offset[] =
+
+#define GEN_SCHTBL_AUTOSTART(_id, _type, _offset, _app_mode ) \
+ const struct OsSchTblAutostart Os_SchTblAutoStart_ ## _id = \
+ { \
+ .type = _type, \
+ .offset = _offset, \
+ .appMode = _app_mode, \
+ }
+
+#define GEN_SCHTBL_AUTOSTART_NAME(_id) &(Os_SchTblAutoStart_ ## _id)
\r
-#define GEN_SCHEDULETABLE_HEAD OsSchTblType sched_list[] =\r
-#define GEN_SCHEDULETABLE( _id, _name, _counter, _repeating, _length, _application_mask, \\r
- _action_cnt, _action_expire_ref, \\r
- _autostart_active, _autostart_type, _autostart_rel_offset, _autostart_appmode, \\r
- _sync_strategy, _sync_explicit_precision , \\r
- _adj_max_advance,_adj_max_retard ) \\r
-{ \\r
- .name = _name, \\r
- .counter = &counter_list[_counter], \\r
- .repeating = _repeating, \\r
- .length = _length, \\r
- .app_mask = _application_mask, \\r
- .action_list = SA_LIST_HEAD_INITIALIZER(_action_cnt,_action_expire_ref), \\r
- .autostart = { \\r
- .active = _autostart_active, \\r
- .type = _autostart_type, \\r
- .relOffset = _autostart_rel_offset, \\r
- .appModeRef = _autostart_appmode, \\r
- }, \\r
- .sync = { \\r
- .syncStrategy = _sync_strategy, \\r
- .explicitPrecision = _sync_explicit_precision, \\r
- }, \\r
- .adjExpPoint = { \\r
- .maxAdvance = _adj_max_advance, \\r
- .maxRetard = _adj_max_retard, \\r
- } \\r
-}\r
+#define GEN_SCHTBL_HEAD OsSchTblType sched_list[] =
+
+/**
+ * _id
+ * NOT USED
+ *
+ * _name
+ * Name of the alarm, string
+ *
+ * _counter_ref
+ * Pointer to the counter that drives the table
+ *
+ * _repeating
+ * SINGLE_SHOT or REPEATING
+ *
+ * _duration
+ * The duration of the schedule table
+ *
+ * _autostart_ref
+ * Pointer to autostart configuration.
+ * If autostart is desired set name to GEN_SCHTBL_AUTOSTART_NAME(<id>). It also
+ * requires that GEN_SCHTBL_AUTOSTART(...) is set.
+ * Set to NULL if not autostart configuration is desired.
+ *
+ * The usage of the macro requires that GEN_SCHTBL_EXPIRY_POINT_HEAD(<id>) is also
+ * set.
+ */
+
+#define GEN_SCHEDULETABLE( _id, _name, _counter_id, _repeating, \
+ _duration, \
+ _autostart_ref ) \
+{ \
+ .name = _name, \
+ .counter = &counter_list[_counter_id], \
+ .repeating = _repeating, \
+ .duration = _duration, \
+ .expirePointList = { \
+ .data = (void *)( Os_SchTblExpPointList_ ## _id ), \
+ .cnt = ARRAY_SIZE(Os_SchTblExpPointList_ ## _id), \
+ }, \
+ .autostartPtr = _autostart_ref, \
+}
+
#if ( OS_SC3 == STD_ON) || ( OS_SC4 == STD_ON)
-#error BEPA
+#error OLD or NOT implemented
#define GEN_HOOKS( _startup, _protection, _shutdown, _error, _pretask, _posttask ) \\r
struct OsHooks os_conf_global_hooks = { \\r
.StartupHook = _startup, \
Q?=@\r
export Q\r
export TOPDIR = $(CURDIR)\r
-export CFG_RELEASE = n\r
-export CFG_DEBUG = y\r
+export CFG_RELEASE = y\r
+export CFG_DEBUG = n\r
export PATH\r
\r
ifneq ($(filter clean_all,$(MAKECMDGOALS)),clean_all)\r
#cflags-y += -O0\r
#cflags-y += -O3\r
\r
+#cflags-y += -ffunction-sections\r
+\r
ifneq ($(filter -O2 -O3 -O1,$(cflags-y)),) \r
cflags-y += -fno-schedule-insns -fno-schedule-insns2\r
endif\r
LDMAPFILE = -M > $(subst .$(TE),.map, $@)\r
\r
libitem-y += $(libitem-yy)\r
+#LDFLAGS += --gc-section\r
\r
# ---------------------------------------------------------------------------\r
# Assembler\r
\r
\r
static inline struct OsSchTblAutostart *getAutoStart( OsSchTblType *stblPtr ) {\r
- return &stblPtr->autostart;\r
+ return stblPtr->autostartPtr;\r
}\r
#if ( OS_SC2 == STD_ON ) || ( OS_SC4 == STD_ON )\r
}\r
}\r
\r
-/**\r
- * Go through the schedule tables connected to this counter\r
- *
- * @param c_p Pointer to counter object
- */\r
-
-/** @req OS002 */
-/** @req OS007 */
-static void check_stbl(OsCounterType *c_p) {
- OsSchTblType *sched_obj;\r
-\r
- /* Iterate through the schedule tables */\r
- SLIST_FOREACH(sched_obj,&c_p->sched_head,sched_list) {\r
-\r
- if( sched_obj->state == SCHEDULETABLE_STOPPED ) {\r
- continue;\r
- }\r
-
-#if ( OS_SC2 == STD_ON ) || ( OS_SC4 == STD_ON )\r
- if( sched_obj->sync.syncStrategy == IMPLICIT ) {\r
- // ....\r
-\r
- } else {\r
- int adj;\r
- // Handle EXPLICIT\r
- if( sched_obj->sync.deviation > 0 ) {\r
- // The sync counter was set back ==\r
- // we have more time to complete the table\r
- adj = MIN(sched_obj->sync.deviation, getAdjExpPoint(sched_obj)->maxAdvance );\r
- sched_obj->sync.deviation -= adj;\r
-\r
- } else if( sched_obj->sync.deviation < 0 ) {\r
- // The sync counter was set forward ==\r
- // we have less time to complete the table\r
- adj = MIN((-sched_obj->sync.deviation), getAdjExpPoint(sched_obj)->maxRetard);\r
- sched_obj->sync.deviation -= adj;\r
-\r
- } else {\r
- // all is well\r
- sched_obj->state = SCHEDULETABLE_RUNNING_AND_SYNCHRONOUS;\r
- }\r
- }\r
-#endif
-\r
- /* Check if the expire point have been hit */\r
- if( (sched_obj->state == SCHEDULETABLE_RUNNING ||\r
- SCHEDULETABLE_RUNNING_AND_SYNCHRONOUS ) &&\r
- (c_p->val >= sched_obj->expire_val) )
- {\r
- OsScheduleTableActionType * action;\r
-\r
- action = SA_LIST_GET(&sched_obj->action_list,sched_obj->expire_curr_index);\r
-\r
- switch( action->type ) {
- case SCHEDULE_ACTION_ACTIVATETASK:
- ActivateTask(action->task_id);
- break;
-
- case SCHEDULE_ACTION_SETEVENT:
- SetEvent( action->task_id, action->event_id);
- break;
-
- default:
- /** @req OS407 */
- assert(0);
- }\r
- // Calc new expire val\r
- Os_SchTblCalcExpire(sched_obj);\r
- }\r
-\r
- }\r
-}\r
-\r
\r
/**\r
* Increment a counter. Checks for wraps.\r
IncCounter(counter);\r
\r
check_alarms(counter);\r
- check_stbl(counter);\r
+ Os_SchTblCheck(counter);\r
/** @req OS321 */\r
COUNTER_STD_END;\r
}\r
\r
-\r
+
+/** @req OS383 */\r
StatusType GetCounterValue( CounterType counter_id , TickRefType tick_ref)\r
{
StatusType rv = E_OK;\r
\r
COUNTER_STD_END;
}\r
-\r
+
+/** @req OS392 */\r
StatusType GetElapsedCounterValue( CounterType counter_id, TickRefType val, TickRefType elapsed_val)\r
{
StatusType rv = E_OK;\r
GetCounterValue(counter_id,&tick);
-#warning missing....OS382
+ /** @req OS382 */
+ *elapsed_val = tick - *val;
COUNTER_STD_END;
}\r
// os_sys.tick = c_p->val;
check_alarms(c_p);
- check_stbl(c_p);
+ Os_SchTblCheck(c_p);
}
}\r
\r
CounterType counter_id;\r
} OsAlarmActionType;\r
+
+enum OsAlarmAutostartTypeType {
+ // Start with SetAbsAlarm()
+ ALARM_AUTOSTART_ABSOLUTE,
+ // Start with SetRelAlarm()
+ ALARM_AUTOSTART_RELATIVE,
+};
+
+
/* STD container : OsAlarmAutostart
* OsAlarmAlarmTime: 1 Int
* OsAlarmAutoStartType: 1 Int, ABSOLUTE, RELATIVE
* OsAlarmCycleTime: 1 Int
* OsAlarmAppModeRef: 1..*
*/\r
-typedef struct OsAlarmAutostart {\r
- _Bool active;\r
- uint32 alarmtime;\r
- uint32 cycletime;\r
- uint32 appmode_mask;\r
+typedef struct OsAlarmAutostart {
+ uint32 alarmTime;
+ enum OsAlarmAutostartTypeType autostartType;\r
+ uint32 cycleTime;\r
+ uint32 appModeRef;\r
} OsAlarmAutostartType;\r
/* STD container : OsAlarm
/* cycle, 0 = no cycle */\r
uint32 alarmtime;\r
uint32 cycletime;\r
- uint32 appmode_mask;\r
+// uint32 appmode_mask;\r
\r
uint32 app_mask;\r
\r
OsAlarmActionType action;\r
/* Autostart */
- OsAlarmAutostartType autostart;
+ const struct OsAlarmAutostart *autostartPtr;
/* List of alarms connected to the same counter */\r
SLIST_ENTRY(OsAlarm) alarm_list;\r
static inline TickType Os_CounterGetMaxValue(OsCounterType *cPtr ) {
return cPtr->alarm_base.maxallowedvalue;
}
+
+static inline TickType Os_CounterGetMinCycle(OsCounterType *cPtr ) {
+ return cPtr->alarm_base.mincycle;
+}
\r
static inline TickType Os_CounterGetValue( OsCounterType *cPtr ) {
return cPtr->val;
\r
enum OsScheduleTableAutostartType {\r
// Start with StartScheduleTableAbs()\r
- ABSOLUTE,\r
+ SCHTBL_AUTOSTART_ABSOLUTE,\r
// Start with StartScheduleTableRel()\r
- RELATIVE,\r
+ SCHTBL_AUTOSTART_RELATIVE,\r
// Start with StartScheduleTableSyncon()\r
- SYNCHRONE,\r
+ SCHTBL_AUTOSTART_SYNCHRONE,\r
};\r
-\r
-typedef struct OsScheduleTableAction {
- // 0 - activate task, 1 - event
- /** @req OS402 */
- /** @req OS403 */
- int type;
- // for debug only???
+
+/* STD container: OsScheduleTableEventSetting
+ * OsScheduleTableSetEventRef: 1
+ * OsScheduleTableSetEventTaskRef: 1
+*/
+typedef struct OsScheduleTableEventSetting {
+ EventMaskType event;
+ TaskType task;
+} OsScheduleTableEventSettingType;
+
+/* OsScheduleTableTaskActivation */
+\r
+/* STD container: OsScheduleTableExpiryPoint
+ * OsScheduleTblExpPointOffset: 1 Int
+ * OsScheduleTableEventSetting: 0..*
+ * OsScheduleTableTaskActivation: 0..*
+ * OsScheduleTblAdjustableExpPoint: 0..1
+ * */
+
+/** @req OS402 */
+/** @req OS403 */
+typedef struct OsScheduleTableExpiryPoint {
+ /* The expiry point offset, OsScheduleTblExpPointOffset */
uint64 offset;
// delta to next action
/** @req OS404 */
uint64 delta;
- TaskType task_id;
- // used only if event..
- EventMaskType event_id;
-} OsScheduleTableActionType;
+
+ /* List of events to activate */
+ const TaskType *taskList;
+ uint8_t taskListCnt;
+
+ /* List of events to activate */
+ const OsScheduleTableEventSettingType *eventList;
+ uint8_t eventListCnt;
+} OsScheduleTableExpiryPointType;
+
#if ( OS_SC2 == STD_ON ) || ( OS_SC4 == STD_ON )\r
typedef struct OsScheduleTableSync {\r
* OsScheduleTableAppModeRef 1..* Ref to OsAppMode
*/\r
struct OsSchTblAutostart {\r
- _Bool active;\r
enum OsScheduleTableAutostartType type;\r
- uint32_t relOffset;\r
- uint32_t appModeRef; // TODO\r
+ /* offset applies to both rel and abs */
+ TickType offset;\r
+ uint32_t appMode; // TODO\r
};\r
*/
\r
typedef struct OsSchTbl {\r
-\r
-// Configuration\r
-\r
- // OsScheduleTableDuration\r
- int duration;\r
-\r
- // If true, the schedule is periodic, OS009\r
- // OsScheduleTableRepeating , 0 - SINGLE_SHOT\r
+ /* OsScheduleTableDuration */\r
+ TickType duration;\r
+
+ char *name;
+ /* If true, the schedule is periodic, OS009\r
+ * OsScheduleTableRepeating , 0 - SINGLE_SHOT */
+ /** @req OS413 */\r
_Bool repeating;\r
\r
- // Application mask\r
- uint32 app_mask;\r
-\r
// pointer to this tables counter\r
// OsScheduleTableCounterRef
/** @req OS409 */\r
struct OsCounter *counter;\r
-\r
- struct OsSchTblAutostart autostart;\r
+
+ /* OsScheduleTableAutostart[C] */\r
+ struct OsSchTblAutostart *autostartPtr;\r
/* NULL if NONE, and non-NULL if EXPLICIT and IMPLICIT */\r
struct OsScheduleTableSync *sync;\r
+#if (OS_SC3 == STD_ON ) || (OS_SC4 == STD_ON )
+ uint32 app_mask;
+#endif
+
#if ( OS_SC2 == STD_ON ) || ( OS_SC4 == STD_ON )\r
struct OsSchTblAdjExpPoint adjExpPoint;\r
#endif
-\r
-// Private stuff\r
-\r
- uint32_t finalOffset;
-\r
- uint32_t initialOffset;\r
- // Name...\r
- char *name;\r
-\r
- // ??\r
// RAM\r
- uint64 length;\r
-\r
+
uint32 id;\r
/* The current index into the expire list
- * The value is updated at each expire point.
- * */\r
+ * The value is updated at each expire point. */\r
int expire_curr_index;
\r
/* When this table expires the next time
* This value should be compared to the counter that drives
* the counter to check if it has expired.
- * The value is updated at each expire point.
- */\r
+ * The value is updated at each expire point. */\r
TickType expire_val;
\r
- // if true, the table is active\r
- //_Bool active;\r
ScheduleTableStatusType state;\r
\r
- // Pointer to next schedule table, if any\r
- // (don't use normal lists here since we have no list head)\r
+ /* Pointer to next schedule table, if any\r
+ * (don't use normal lists here since we have no list head) */\r
struct OsSchTbl *next;\r
\r
- /* Head of static action list */\r
- SA_LIST_HEAD(alist,OsScheduleTableAction) action_list;\r
+ /* Head of static expire point list
+ * OsScheduleTableExpiryPoint[C] */\r
+ SA_LIST_HEAD(alist,OsScheduleTableExpiryPoint) expirePointList;\r
\r
- /* Entry in the list of schedule tables connected to a specfic\r
+ /* Entry in the list of schedule tables connected to a specific\r
* counter */\r
SLIST_ENTRY(OsSchTbl) sched_list;\r
\r
- // TableDuration\r
- //\r
-\r
} OsSchTblType;\r
\r
/*\r
-#define os_stbl_get_action(x) SA_LIST_GET(&(x)->action_list,(x)->expire_curr_index)\r
+#define os_stbl_get_action(x) SA_LIST_GET(&(x)->expirePointList,(x)->expire_curr_index)\r
#define os_stbl_get_action_type(x) os_stbl_get_action(x)->type\r
#define os_stbl_get_action_offset(x) os_stbl_get_action(x)->offset\r
#define os_stbl_get_action_pid(x) os_stbl_get_action(x)->pid\r
\r
void Os_SchTblInit( void );\r
void Os_SchTblCalcExpire( OsSchTblType *stbl );
+void Os_SchTblCheck(OsCounterType *c_p);
static inline TickType Os_SchTblGetInitialOffset( OsSchTblType *sPtr ) {
- return SA_LIST_GET(&sPtr->action_list,0)->offset;
+ return SA_LIST_GET(&sPtr->expirePointList,0)->offset;
}
static inline TickType Os_SchTblGetFinalOffset( OsSchTblType *sPtr ) {
return (sPtr->duration -
- SA_LIST_GET(&sPtr->action_list, SA_LIST_CNT(&sPtr->action_list))->offset);
+ SA_LIST_GET(&sPtr->expirePointList, SA_LIST_CNT(&sPtr->expirePointList)-1)->offset);
}
\r
for(int j=0; j < Oil_GetAlarmCnt(); j++ ) {
OsAlarmType *alarmPtr;
alarmPtr = Oil_GetAlarmObj(j);
- if(alarmPtr->autostart.active) {
- OsAlarmAutostartType *autoPtr = &alarmPtr->autostart;
+ if(alarmPtr->autostartPtr != NULL ) {
+ OsAlarmAutostartType *autoPtr = alarmPtr->autostartPtr;
- SetAbsAlarm(j,autoPtr->alarmtime, autoPtr->cycletime);
+ if( autoPtr->autostartType == ALARM_AUTOSTART_ABSOLUTE ) {
+ SetAbsAlarm(j,autoPtr->alarmTime, autoPtr->cycleTime);
+ } else {
+ SetRelAlarm(j,autoPtr->alarmTime, autoPtr->cycleTime);
+ }
}
}
-/*\r
- * os_arctest.c\r
+/* -------------------------------- Arctic Core ------------------------------\r
+ * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
*\r
- * Created on: 19 jan 2010\r
- * Author: mahi\r
+ * Copyright (C) 2009 ArcCore AB <contact@arccore.com>\r
+ *\r
+ * This source code is free software; you can redistribute it and/or modify it\r
+ * under the terms of the GNU General Public License version 2 as published by the\r
+ * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.\r
+ *\r
+ * This program is distributed in the hope that it will be useful, but\r
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\r
+ * for more details.\r
+ * -------------------------------- Arctic Core ------------------------------*/\r
+/**\r
+ * Holds an API for manipulation of internal OS structures.\r
+ * To be used by the test-system.
*/\r
\r
#include "internal.h"\r
return 0;\r
}\r
\r
+/**\r
+ * Set number of simultaneous interrupts.\r
+ * Used to the test for E_OS_CALLLEVEL.
+ * @param level
+ */\r
+\r
void Os_ArcTest_SetIrqNestLevel( int level ) {\r
\r
return;\r
*
* @return
*/\r
-static void ScheduleTableConsistenyCheck( OsSchTblType *s_p ) {\r
+static void ScheduleTableConsistenyCheck( OsSchTblType *sTblPtr ) {\r
#if ( OS_SC2 == STD_ON ) || ( OS_SC4 == STD_ON )\r
/** @req OS440 */\r
- if( s_p->sync.syncStrategy == IMPLICIT ) {\r
- assert( s_p->duration == (s_p->counter->alarm_base.maxallowedvalue +1) );\r
+ if( sTblPtr->sync.syncStrategy == IMPLICIT ) {\r
+ assert( sTblPtr->duration == (sTblPtr->counter->alarm_base.maxallowedvalue +1) );\r
}\r
\r
/** @req OS431 */\r
- if( s_p->sync.syncStrategy == EXPLICIT ) {\r
- assert( s_p->duration <= (s_p->counter->alarm_base.maxallowedvalue +1) );\r
+ if( sTblPtr->sync.syncStrategy == EXPLICIT ) {\r
+ assert( sTblPtr->duration <= (sTblPtr->counter->alarm_base.maxallowedvalue +1) );\r
}
#endif
/** @req OS401 */
- assert(SA_LIST_CNT(&s_p->action_list)>=1);
+ assert(SA_LIST_CNT(&sTblPtr->expirePointList)>=1);
+
+
+
+ {
+ int iter;
+ TickType delta = 0;
+ TickType minCycle = Os_CounterGetMinCycle(sTblPtr->counter);
+ TickType maxValue = Os_CounterGetMaxValue(sTblPtr->counter);
+
+ /* - start at offset=0
+ * - X expiry points = SA_LIST_CNT
+ * - Final offset.
+ */
+ /** @req OS443 */
+ /** @req OS408 */
+ for(iter=0; iter < SA_LIST_CNT(&sTblPtr->expirePointList) ; iter++) {
+ delta = SA_LIST_GET(&sTblPtr->expirePointList,iter)->offset - delta;
+ assert( delta >= minCycle );
+ assert( delta <= maxValue );
+ }
+
+ /* Final */
+ /** @req OS444 */
+ delta = sTblPtr->duration - SA_LIST_GET(&sTblPtr->expirePointList,iter)->offset;
+ assert( delta >= minCycle );
+ assert( delta <= maxValue );
+ }
}\r
\r
SCHED_STD_END;\r
}\r
#endif
+
+
+
+/**
+ * Go through the schedule tables connected to this counter
+ *
+ * @param c_p Pointer to counter object
+ */
+void Os_SchTblCheck(OsCounterType *c_p) {
+ /** @req OS002 */
+ /** @req OS007 */
+
+ OsSchTblType *sched_obj;
+
+ /* Iterate through the schedule tables */
+ SLIST_FOREACH(sched_obj,&c_p->sched_head,sched_list) {
+
+ if( sched_obj->state == SCHEDULETABLE_STOPPED ) {
+ continue;
+ }
+
+#if ( OS_SC2 == STD_ON ) || ( OS_SC4 == STD_ON )
+ if( sched_obj->sync.syncStrategy == IMPLICIT ) {
+ // ....
+
+ } else {
+ int adj;
+ // Handle EXPLICIT
+ if( sched_obj->sync.deviation > 0 ) {
+ // The sync counter was set back ==
+ // we have more time to complete the table
+ adj = MIN(sched_obj->sync.deviation, getAdjExpPoint(sched_obj)->maxAdvance );
+ sched_obj->sync.deviation -= adj;
+
+ } else if( sched_obj->sync.deviation < 0 ) {
+ // The sync counter was set forward ==
+ // we have less time to complete the table
+ adj = MIN((-sched_obj->sync.deviation), getAdjExpPoint(sched_obj)->maxRetard);
+ sched_obj->sync.deviation -= adj;
+
+ } else {
+ // all is well
+ sched_obj->state = SCHEDULETABLE_RUNNING_AND_SYNCHRONOUS;
+ }
+ }
+#endif
+
+ /* Check if the expire point have been hit */
+ if( (sched_obj->state == SCHEDULETABLE_RUNNING ||
+ SCHEDULETABLE_RUNNING_AND_SYNCHRONOUS ) &&
+ (c_p->val >= sched_obj->expire_val) )
+ {
+ OsScheduleTableExpiryPointType * action;
+ int i;
+
+ action = SA_LIST_GET(&sched_obj->expirePointList,sched_obj->expire_curr_index);
+
+ /** @req OS407 */
+ /** @req OS412 */
+
+ /* According to OS412 activate tasks before events */
+ for(i=0; i< action->taskListCnt;i++ ) {
+ ActivateTask(action->taskList[i]);
+ }
+
+ for(i=0; i< action->eventListCnt;i++ ) {
+ SetEvent( action->eventList[i].task, action->eventList[i].event);
+ }
+ // Calc new expire val
+ Os_SchTblCalcExpire(sched_obj);
+ }
+
+ }
+}
\r
/*\r
*start e e e delta stop\r
* counter I will miss to update the delta values\r
*/\r
static void os_stbl_action_calc_delta( OsSchTblType *stbl ) {\r
- OsScheduleTableActionType * first;\r
- OsScheduleTableActionType * second;\r
+ OsScheduleTableExpiryPointType * first;\r
+ OsScheduleTableExpiryPointType * second;\r
// ALIST_DECL_ITER(iter);\r
int iter;\r
\r
// calculate the delta to next action\r
\r
- for(iter=1; iter < SA_LIST_CNT(&stbl->action_list) ;iter++) {\r
- first = SA_LIST_GET(&stbl->action_list,iter-1);\r
- second = SA_LIST_GET(&stbl->action_list,iter);\r
+ for(iter=1; iter < SA_LIST_CNT(&stbl->expirePointList) ;iter++) {\r
+ first = SA_LIST_GET(&stbl->expirePointList,iter-1);\r
+ second = SA_LIST_GET(&stbl->expirePointList,iter);\r
first->delta = second->offset - first->offset;\r
}\r
// calculate the last delta( to countes max value )\r
- first = SA_LIST_GET(&stbl->action_list, SA_LIST_CNT(&stbl->action_list)-1);\r
+ first = SA_LIST_GET(&stbl->expirePointList, SA_LIST_CNT(&stbl->expirePointList)-1);\r
first->delta = stbl->counter->alarm_base.maxallowedvalue - first->offset;\r
}\r
\r
OsSchTblType *nextStblPtr;
- if( (stbl->expire_curr_index) == SA_LIST_CNT(&stbl->action_list) ) {
+ if( (stbl->expire_curr_index) == SA_LIST_CNT(&stbl->expirePointList) ) {
/* We are at the last expiry point */
finalOffset = Os_SchTblGetFinalOffset(stbl);
stbl->expire_curr_index++;
- } else if( (stbl->expire_curr_index) > SA_LIST_CNT(&stbl->action_list) ) {
+ } else if( (stbl->expire_curr_index) > SA_LIST_CNT(&stbl->expirePointList) ) {
+ /* At final offset */
/** @req OS194 */
if( (stbl->repeating == REPEATING) || (stbl->next != NULL) ) {
stbl->state = SCHEDULETABLE_STOPPED;
nextStblPtr->state = SCHEDULETABLE_RUNNING;
} else {
+ /** @req OS414 */
+
/* REPEATING */
assert( stbl->repeating == REPEATING );
initalOffset = Os_SchTblGetInitialOffset(stbl);
}
} else {
- delta = SA_LIST_GET(&stbl->action_list,stbl->expire_curr_index)->delta;
+ delta = SA_LIST_GET(&stbl->expirePointList,stbl->expire_curr_index)->delta;
stbl->expire_val = Os_CounterCalcModulo(
Os_CounterGetValue(stbl->counter),
*/\r
#define OS_CFG_API_VERSION 2
\r
-#include <stdlib.h>\r
-#include <stdint.h>\r
-#include "os_config_macros.h"\r
-#include "Platform_Types.h"\r
-#include "Os.h" // includes Os_Cfg.h\r
-#include "os_test.h"\r
-#include "kernel.h"\r
-#include "kernel_offset.h"\r
+#include <stdlib.h>
+#include <stdint.h>
+#include "Platform_Types.h"
+#include "Os.h" // includes Os_Cfg.h
+#include "os_config_macros.h"
+#include "kernel.h"
+#include "kernel_offset.h"
#include "alist_i.h"
#include "Mcu.h"
+#include "os_test.h"
OsTickType OsTickFreq = 1000;\r
\r
\r
//-------------------------------------------------------------------\r
-#if ( OS_SC1 == STD_ON ) || ( OS_SC4 == STD_ON )\r
+#if ( OS_SC3 == STD_ON ) || ( OS_SC4 == STD_ON )\r
GEN_APPLICATION_HEAD {\r
GEN_APPLICATON(0,"application_1",true,NULL,NULL,NULL , 0,0,0,0,0,0 )\r
};
\r
\r
#if defined(SCHEDULETABLE_USE)\r
+
+// ---- Table 0 -----
+GEN_SCHTBL_TASK_LIST_HEAD( 0, 5 ) {
+ TASK_ID_etask_sup_m
+};
+
+GEN_SCHTBL_EVENT_LIST_HEAD( 0, 7 ) {
+ { EVENT_2, TASK_ID_etask_sup_m },
+};
+
+GEN_SCHTBL_EXPIRY_POINT_HEAD( 0 ) {
+ GEN_SCHTBL_EXPIRY_POINT_W_TASK( 0, 5 ),
+ GEN_SCHTBL_EXPIRY_POINT_W_EVENT( 0, 7 )
+};
+
+// ---- Table 1 -----
+GEN_SCHTBL_TASK_LIST_HEAD(1,2) {
+ TASK_ID_etask_sup_m ,
+};
+
+GEN_SCHTBL_EXPIRY_POINT_HEAD( 1 ) {
+ GEN_SCHTBL_EXPIRY_POINT_W_TASK( 1, 2 )
+};
\r
+GEN_SCHTBL_AUTOSTART(0,SCHTBL_AUTOSTART_ABSOLUTE, 100, OSDEFAULTAPPMODE );
\r
-OsScheduleTableActionType sched_expire_list_0[] = {\r
- {\r
- .type = SCHEDULE_ACTION_ACTIVATETASK,\r
- .offset = 5,\r
- .task_id = TASK_ID_etask_sup_m,\r
- },{\r
- .type = SCHEDULE_ACTION_SETEVENT,\r
- .offset = 7,\r
- .task_id = TASK_ID_etask_sup_m,\r
- .event_id = EVENT_2,\r
- }\r
-};\r
-\r
-\r
-OsScheduleTableActionType sched_expire_list_1[] = {\r
- {\r
- .type = SCHEDULE_ACTION_ACTIVATETASK,\r
- .offset = 2,\r
- .task_id = TASK_ID_etask_sup_m,\r
- }\r
-};\r
-\r
-\r
-GEN_SCHEDULETABLE_HEAD {\r
+GEN_SCHTBL_HEAD {
GEN_SCHEDULETABLE(\r
- 0, // id\r
- "stable0", // name\r
- COUNTER_ID_soft_2, // counter\r
- REPEATING, // periodic
- SCHEDULETABLE_DURATION_1, // duration\r
- 0, // app_mask\r
- ARRAY_SIZE(sched_expire_list_0), // action count\r
- sched_expire_list_0, // expire ref\r
- 0,0,0,0, // autostart\r
- NONE,0, // sync\r
- 0,0 // adjExpPoint\r
+ 0, // id\r
+ "stable0", // name\r
+ COUNTER_ID_soft_2, // counter\r
+ REPEATING, // periodic
+ SCHEDULETABLE_DURATION_1, // duration
+ GEN_SCHTBL_AUTOSTART_NAME(0)\r
),\r
-\r
+
+
GEN_SCHEDULETABLE(\r
1, // id\r
"stable1", // name\r
COUNTER_ID_soft_2, // counter\r
REPEATING, // periodic\r
- SCHEDULETABLE_DURATION_2, // duration\r
- 0, // app_mask\r
- ARRAY_SIZE(sched_expire_list_1), // action count\r
- sched_expire_list_1, // expire ref\r
- 0,0,0,0, // autostart\r
- NONE,0, // sync\r
- 0,0 // adjExpPoint\r
+ SCHEDULETABLE_DURATION_2, // duration
+ NULL\r
),\r
};\r
\r
#define EVENT_1 (1<<1)\r
#define EVENT_2 (1<<2)\r
\r
-\r
-\r
#endif /* OS_CFG_H_ */\r
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
* -------------------------------- Arctic Core ------------------------------*/
-
-
-
-
-
-
-
-
-/*\r
- * os_test.h\r
- *\r
- * Created on: 2009-jan-08\r
- * Author: mahi\r
- */\r
\r
#ifndef OS_TEST_H_\r
#define OS_TEST_H_\r