* for more details.
* -------------------------------- Arctic Core ------------------------------*/
-\r
-#include <sys/stat.h>\r
-#include <sys/types.h>\r
-#include <errno.h>\r
-#include <stdlib.h>\r
-//#include "clibsupport_gcc.h"\r
+
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include "Std_Types.h"
+#include "Ramlog.h"
+//#include "clibsupport_gcc.h"
#if defined(CFG_ARM)
#define open _open
#define write _write
#define lseek _lseek
#endif
-\r
-// Operation on Winidea terminal buffer\r
-#define TWBUFF_SIZE 0x100\r
-#define TRBUFF_SIZE 0x100\r
-\r
-#define TBUFF_PTR 2\r
-\r
-#define TWBUFF_LEN (TWBUFF_SIZE+TBUFF_PTR)\r
-#define TRBUFF_LEN (TRBUFF_SIZE+TBUFF_PTR)\r
-#define TWBUFF_TPTR (g_TWBuffer[TWBUFF_SIZE+0])\r
-#define TWBUFF_CPTR (g_TWBuffer[TWBUFF_SIZE+1])\r
-#define TWBUFF_INC(n) ((n + 1)&(TWBUFF_SIZE-1))\r
-#define TWBUFF_FULL() (TWBUFF_TPTR==((TWBUFF_CPTR-1)&(TWBUFF_SIZE-1)))\r
-\r
-#ifdef USE_WINIDEA_TERM\r
-static volatile unsigned char g_TWBuffer[TWBUFF_LEN] __attribute__ ((aligned (0x100))); // Transmit to WinIDEA terminal\r
-static volatile unsigned char g_TRBuffer[TRBUFF_LEN] __attribute__ ((aligned (0x100)));\r
-static volatile char g_TConn __attribute__ ((section (".winidea_port")));\r
-#endif\r
+
+// Operation on Winidea terminal buffer
+#define TWBUFF_SIZE 0x100
+#define TRBUFF_SIZE 0x100
+
+#define TBUFF_PTR 2
+
+#define TWBUFF_LEN (TWBUFF_SIZE+TBUFF_PTR)
+#define TRBUFF_LEN (TRBUFF_SIZE+TBUFF_PTR)
+#define TWBUFF_TPTR (g_TWBuffer[TWBUFF_SIZE+0])
+#define TWBUFF_CPTR (g_TWBuffer[TWBUFF_SIZE+1])
+#define TWBUFF_INC(n) ((n + 1)&(TWBUFF_SIZE-1))
+#define TWBUFF_FULL() (TWBUFF_TPTR==((TWBUFF_CPTR-1)&(TWBUFF_SIZE-1)))
+
+#ifdef USE_WINIDEA_TERM
+static volatile unsigned char g_TWBuffer[TWBUFF_LEN] __attribute__ ((aligned (0x100))); // Transmit to WinIDEA terminal
+static volatile unsigned char g_TRBuffer[TRBUFF_LEN] __attribute__ ((aligned (0x100)));
+static volatile char g_TConn __attribute__ ((section (".winidea_port")));
+#endif
#define FILE_RAMLOG 3
-\r
-/*\r
- * T32 stuff\r
- */\r
-
-// This must be in un-cached space....\r
-static volatile char t32_outport __attribute__ ((section (".t32_outport")));\r
-\r
-\r
-int arc_putchar(int c) {\r
- char cc = c;\r
- write( 1,&cc,1);\r
-\r
- return 0;\r
-}\r
-\r
-void t32_writebyte(char c)\r
+
+/*
+ * T32 stuff
+ */
+
+// This must be in un-cached space....
+static volatile char t32_outport __attribute__ ((section (".t32_outport")));
+
+
+
+
+void t32_writebyte(char c)
{
/* T32 can hang here for several reasons;
- * - term.view e:address.offset(v.address(t32_outport)) e:0\r
- */\r
-\r
- while (t32_outport != 0 ) ; /* wait until port is free */\r
- t32_outport = c; /* send character */\r
-}\r
-\r
-/*\r
- * clib support\r
- */\r
-\r
-/* Do nothing */\r
-int close( int fd ) {\r
- (void)fd;\r
- return (-1);\r
-}\r
-\r
-char *__env[1] = { 0 };\r
-char **environ = __env;\r
-\r
-\r
-#include <errno.h>\r
-#undef errno\r
-extern int errno;\r
-\r
-int execve(char *name, char **argv, char **env){\r
- (void)name;\r
- (void)argv;\r
- (void)env;\r
- errno=ENOMEM;\r
- return -1;\r
-}\r
-\r
-int fork() {\r
- errno=EAGAIN;\r
- return -1;\r
-}\r
-\r
-#include <sys/stat.h>\r
-int fstat(int file, struct stat *st) {\r
- (void)file;\r
- st->st_mode = S_IFCHR;\r
- return 0;\r
-}\r
-\r
-/* Returns 1 if connected to a terminal. T32 can be a terminal\r
- */\r
-\r
-int isatty( int fd )\r
-{\r
- (void)fd;\r
- return 1;\r
-}\r
-\r
-/*\r
-int fstat( int fd, struct stat *buf )\r
-{\r
- buf->st_mode = S_IFCHR;\r
- buf->st_blksize = 0;\r
-\r
- return (0);\r
-}\r
-*/\r
-\r
-/* reposition read/write file offset\r
- * We can't seek, return error.*/\r
-off_t lseek( int fd, off_t offset,int whence)\r
-{\r
- (void)fd;\r
- (void)offset;\r
- (void)whence;\r
-\r
- errno = ESPIPE;\r
- return ((off_t)-1);\r
-}\r
-\r
-int open(const char *name, int flags, int mode){\r
- (void)name;\r
- (void)flags;\r
- (void)mode;\r
-\r
- if( strcmp(name,"ramlog") == 0 ) {\r
- return FILE_RAMLOG;\r
- }\r
-\r
- return -1;\r
-}\r
-\r
-int read( int fd, char *buf, int nbytes )\r
-{\r
- (void)fd;\r
- (void)buf;\r
- (void)nbytes;\r
-#ifdef USE_WINIDEA_TERM\r
- (void)g_TRBuffer[0];\r
-#endif\r
-\r
- /* Only support write for now, return 0 read */\r
- return 0;\r
-}\r
-\r
-\r
-int write( int fd, char *buf, int nbytes)\r
-{\r
- //(void)fd; // Normally 0- ?, 1-stdout, 2-stderr,\r
- // Added 3-ramlog,\r
-\r
- if( fd < 3 ) {\r
-#ifdef USE_WINIDEA_TERM\r
- if (g_TConn)\r
- {\r
- unsigned char nCnt,nLen;\r
- for(nCnt=0; nCnt<nbytes; nCnt++)\r
- {\r
- while(TWBUFF_FULL());\r
- nLen=TWBUFF_TPTR;\r
- g_TWBuffer[nLen]=buf[nCnt];\r
- nLen=TWBUFF_INC(nLen);\r
- TWBUFF_TPTR=nLen;\r
- }\r
- }\r
-#endif\r
-\r
-#ifdef USE_T32_TERM\r
- for (int i = 0; i < nbytes; i++) {\r
- if (*(buf + i) == '\n') {\r
- t32_writebyte ('\r');\r
-// t32_writebyte ('\n');\r
- }\r
- t32_writebyte (*(buf + i));\r
- }\r
+ * - term.view e:address.offset(v.address(t32_outport)) e:0
+ */
+
+ while (t32_outport != 0 ) ; /* wait until port is free */
+ t32_outport = c; /* send character */
+}
+
+/*
+ * clib support
+ */
+
+/* Do nothing */
+int close( int fd ) {
+ (void)fd;
+ return (-1);
+}
+
+char *__env[1] = { 0 };
+char **environ = __env;
+
+
+#include <errno.h>
+#undef errno
+extern int errno;
+
+int execve(char *name, char **argv, char **env){
+ (void)name;
+ (void)argv;
+ (void)env;
+ errno=ENOMEM;
+ return -1;
+}
+
+int fork() {
+ errno=EAGAIN;
+ return -1;
+}
+
+#include <sys/stat.h>
+int fstat(int file, struct stat *st) {
+ (void)file;
+ st->st_mode = S_IFCHR;
+ return 0;
+}
+
+/* Returns 1 if connected to a terminal. T32 can be a terminal
+ */
+
+int isatty( int fd )
+{
+ (void)fd;
+ return 1;
+}
+
+/*
+int fstat( int fd, struct stat *buf )
+{
+ buf->st_mode = S_IFCHR;
+ buf->st_blksize = 0;
+
+ return (0);
+}
+*/
+
+/* reposition read/write file offset
+ * We can't seek, return error.*/
+off_t lseek( int fd, off_t offset,int whence)
+{
+ (void)fd;
+ (void)offset;
+ (void)whence;
+
+ errno = ESPIPE;
+ return ((off_t)-1);
+}
+
+int open(const char *name, int flags, int mode){
+ (void)name;
+ (void)flags;
+ (void)mode;
+
+ if( strcmp(name,"ramlog") == 0 ) {
+ return FILE_RAMLOG;
+ }
+
+ return -1;
+}
+
+int read( int fd, char *buf, int nbytes )
+{
+ (void)fd;
+ (void)buf;
+ (void)nbytes;
+#ifdef USE_WINIDEA_TERM
+ (void)g_TRBuffer[0];
+#endif
+
+ /* Only support write for now, return 0 read */
+ return 0;
+}
+
+
+int write( int fd, char *buf, int nbytes)
+{
+ //(void)fd; // Normally 0- ?, 1-stdout, 2-stderr,
+ // Added 3-ramlog,
+
+ if( fd < 3 ) {
+#ifdef USE_WINIDEA_TERM
+ if (g_TConn)
+ {
+ unsigned char nCnt,nLen;
+ for(nCnt=0; nCnt<nbytes; nCnt++)
+ {
+ while(TWBUFF_FULL());
+ nLen=TWBUFF_TPTR;
+ g_TWBuffer[nLen]=buf[nCnt];
+ nLen=TWBUFF_INC(nLen);
+ TWBUFF_TPTR=nLen;
+ }
+ }
+#endif
+
+#ifdef USE_T32_TERM
+ for (int i = 0; i < nbytes; i++) {
+ if (*(buf + i) == '\n') {
+ t32_writebyte ('\r');
+// t32_writebyte ('\n');
+ }
+ t32_writebyte (*(buf + i));
+ }
#endif
#ifdef USE_ARM_ITM_TERM
for (int i = 0; i < nbytes; i++) {
}
#endif
- }\r
- else\r
+ }
+ else
{
- /* RAMLOG support */\r
- if(fd == FILE_RAMLOG) {\r
- for (int i = 0; i < nbytes; i++) {\r
- ramlog_chr (*(buf + i));\r
- }\r
- }\r
- }\r
-\r
- return (nbytes);\r
-}\r
-\r
-/* If we use malloc and it runs out of memory it calls sbrk()\r
- */\r
-#if 1\r
-\r
-extern char _end[];\r
-\r
-//static char *curbrk = _end;\r
-\r
-#define HEAPSIZE 16000\r
-unsigned char _heap[HEAPSIZE];\r
-\r
-caddr_t sbrk( int incr )\r
-{\r
- static unsigned char *heap_end;\r
- unsigned char *prev_heap_end;\r
-\r
-/* initialize */\r
- if( heap_end == 0 )\r
- heap_end = _heap;\r
-\r
- prev_heap_end = heap_end;\r
-\r
- if( heap_end + incr - _heap > HEAPSIZE ) {\r
- /* heap overflow - announce on stderr */\r
- write( 2, "Heap overflow!\n", 15 );\r
- abort();\r
- }\r
-\r
- heap_end += incr;\r
-\r
- return (caddr_t) prev_heap_end;\r
-}\r
-#else\r
-void *sbrk(int inc )\r
-{\r
- /* We use our own malloc */\r
- return (void *)(-1);\r
-}\r
-#endif\r
-\r
-int stat( const char *file, struct stat *st ) {\r
-//int stat(char *file, struct stat *st) {\r
- (void)file;\r
- st->st_mode = S_IFCHR;\r
- return 0;\r
-}\r
-\r
-\r
-int getpid() {\r
- return 1;\r
-}\r
-\r
-#include <errno.h>\r
-#undef errno\r
-extern int errno;\r
-int kill(int pid, int sig){\r
- (void)pid;\r
- (void)sig;\r
- errno=EINVAL;\r
- return(-1);\r
-}\r
-\r
-\r
-/* Should not really be here, but .. */\r
-\r
-void _fini( void )\r
-{\r
-\r
-}\r
-\r
-\r
-void __init( void )\r
-{\r
-\r
-}\r
-#if defined(CFG_ARM)\r
-void _exit( int status ) {\r
- while(1);\r
-}\r
-#endif\r
-\r
+ /* RAMLOG support */
+ if(fd == FILE_RAMLOG) {
+ for (int i = 0; i < nbytes; i++) {
+ ramlog_chr (*(buf + i));
+ }
+ }
+ }
+
+ return (nbytes);
+}
+
+int arc_putchar(int c) {
+ char cc = c;
+ write( 1,&cc,1);
+
+ return 0;
+}
+
+/* If we use malloc and it runs out of memory it calls sbrk()
+ */
+#if 1
+
+extern char _end[];
+
+//static char *curbrk = _end;
+
+#define HEAPSIZE 16000
+unsigned char _heap[HEAPSIZE];
+
+caddr_t sbrk( int incr )
+{
+ static unsigned char *heap_end;
+ unsigned char *prev_heap_end;
+
+/* initialize */
+ if( heap_end == 0 )
+ heap_end = _heap;
+
+ prev_heap_end = heap_end;
+
+ if( heap_end + incr - _heap > HEAPSIZE ) {
+ /* heap overflow - announce on stderr */
+ write( 2, "Heap overflow!\n", 15 );
+ abort();
+ }
+
+ heap_end += incr;
+
+ return (caddr_t) prev_heap_end;
+}
+#else
+void *sbrk(int inc )
+{
+ /* We use our own malloc */
+ return (void *)(-1);
+}
+#endif
+
+int stat( const char *file, struct stat *st ) {
+//int stat(char *file, struct stat *st) {
+ (void)file;
+ st->st_mode = S_IFCHR;
+ return 0;
+}
+
+
+int getpid() {
+ return 1;
+}
+
+#include <errno.h>
+#undef errno
+extern int errno;
+int kill(int pid, int sig){
+ (void)pid;
+ (void)sig;
+ errno=EINVAL;
+ return(-1);
+}
+
+
+/* Should not really be here, but .. */
+
+void _fini( void )
+{
+
+}
+
+
+void __init( void )
+{
+
+}
+#if defined(CFG_ARM)
+void _exit( int status ) {
+ while(1);
+}
+#endif
+
+#include <stdio.h>
+#include <stdarg.h>
+extern int simple_sprintf(char *, const char *format, ...);
+#define CONFIG_RAMLOG_SIZE 2000
+static unsigned char ramlog[CONFIG_RAMLOG_SIZE] __attribute__ ((section (".ramlog")));
+static unsigned ramlog_curr __attribute__ ((section (".ramlog")));
+static unsigned ramlog_session __attribute__ ((section (".ramlog")));
+static FILE *ramlogFile = 0;
-\r
-#include <stdio.h>\r
-#include <stdarg.h>\r
-\r
-extern int simple_sprintf(char *, const char *format, ...);\r
-\r
-#define CONFIG_RAMLOG_SIZE 2000\r
-\r
-static unsigned char ramlog[CONFIG_RAMLOG_SIZE] __attribute__ ((section (".ramlog")));\r
-static unsigned ramlog_curr __attribute__ ((section (".ramlog")));\r
-static unsigned ramlog_session __attribute__ ((section (".ramlog")));\r
-\r
-static FILE *ramlogFile = 0;\r
-\r
-\r
-void ramlog_chr( char c ) {\r
- ramlog[ramlog_curr++] = c;\r
- if( ramlog_curr >= 2000 ) {\r
- ramlog_curr = 0;\r
- }\r
-}\r
-\r
-void ramlog_puts( char *str ) {\r
-\r
- while(*str!=0) {\r
- ramlog_chr(*str++);\r
- }\r
- ramlog_chr('\n');\r
-}\r
-\r
-void ramlog_printf( const char *format, ... ) {\r
-\r
- // Fast and ugly ramlog support.\r
- volatile int rv;\r
- va_list args;\r
- va_start(args,format);\r
-\r
- rv = vfprintf(ramlogFile,format, args);\r
- va_end(args);\r
-}\r
-\r
-void ramlog_init()\r
-{\r
- char buf[32];\r
- if( ramlog_curr>CONFIG_RAMLOG_SIZE)\r
- {\r
- ramlog_curr = 0;\r
- ramlog_session = 0;\r
- }\r
-\r
- ramlogFile = fopen("ramlog","a");\r
-\r
- ramlog_session++;\r
-\r
- simple_sprintf(buf, "Session (%d)\n", ramlog_session);\r
- ramlog_puts(buf);\r
-}\r
+
+void ramlog_chr( char c ) {
+ ramlog[ramlog_curr++] = c;
+ if( ramlog_curr >= 2000 ) {
+ ramlog_curr = 0;
+ }
+}
+
+void ramlog_puts( char *str ) {
+
+ while(*str!=0) {
+ ramlog_chr(*str++);
+ }
+ ramlog_chr('\n');
+}
+
+void ramlog_printf( const char *format, ... ) {
+
+ // Fast and ugly ramlog support.
+ volatile int rv;
+ va_list args;
+ va_start(args,format);
+
+ rv = vfprintf(ramlogFile,format, args);
+ va_end(args);
+}
+
+void ramlog_init()
+{
+ char buf[32];
+ if( ramlog_curr>CONFIG_RAMLOG_SIZE)
+ {
+ ramlog_curr = 0;
+ ramlog_session = 0;
+ }
+
+ ramlogFile = fopen("ramlog","a");
+
+ ramlog_session++;
+
+ simple_sprintf(buf, "Session (%d)\n", ramlog_session);
+ ramlog_puts(buf);
+}
+/*
+ * Ramlog.h
+ *
+ * Created on: 2009-apr-19
+ * Author: mahi
+ */
+#ifndef RAMLOG_H_
+#define RAMLOG_H_
+#include "xtoa.h"
+void ramlog_puts( char *str );
+void ramlog_chr( char c );
-
-/*\r
- * Ramlog.h\r
- *\r
- * Created on: 2009-apr-19\r
- * Author: mahi\r
- */\r
-\r
-#ifndef RAMLOG_H_\r
-#define RAMLOG_H_\r
-\r
-#include "xtoa.h"\r
-\r
-void ramlog_puts( char *str );\r
-\r
-/*\r
+/*
* Fast ramlog functions
- */\r
-static inline void ramlog_str( char *str ) {\r
- ramlog_puts(str);\r
-}\r
-\r
-static inline void ramlog_dec( int val ) {\r
- char str[10]; // include '-' and \0\r
- ultoa(val,str,10);\r
- ramlog_str(str);\r
-}\r
-\r
-static inline void ramlog_hex( uint32_t val ) {\r
- char str[10]; // include '-' and \0\r
- ultoa(val,str,16);\r
- ramlog_str(str);\r
-}\r
-\r
-/*\r
- * var args ramlog functions\r
- */\r
-int ramlog_printf(const char *format, ...);\r
-\r
-#endif /* RAMLOG_H_ */\r
+ */
+static inline void ramlog_str( char *str ) {
+ ramlog_puts(str);
+}
+
+static inline void ramlog_dec( int val ) {
+ char str[10]; // include '-' and \0
+ ultoa(val,str,10);
+ ramlog_str(str);
+}
+
+static inline void ramlog_hex( uint32_t val ) {
+ char str[10]; // include '-' and \0
+ ultoa(val,str,16);
+ ramlog_str(str);
+}
+
+/*
+ * var args ramlog functions
+ */
+int ramlog_printf(const char *format, ...);
+
+#endif /* RAMLOG_H_ */
* -------------------------------- Arctic Core ------------------------------*/
+#include "Os.h"
+#include "sys.h"
+#include <stdlib.h>
+#include <string.h>
+#include "ext_config.h"
+//#include "Pool.h"
+//#include "ppc_asm.h"
+#include "arch.h"
+#include "kernel.h"
+#include "swap.h"
+#include "hooks.h"
+#include "task_i.h"
+#include "alarm_i.h"
+#include "sched_table_i.h"
+#include "Trace.h"
+extern void Oil_GetInterruptStackInfo( stack_t *stack );
+sys_t os_sys;
+/**
+ * Initialize alarms and schedule-tables for the counters
+ */
+static void os_counter_init( void ) {
+ counter_obj_t *counter;
+ alarm_obj_t *alarm_obj;
+ sched_table_t *sched_obj;
+ /* Create a list from the counter to the alarms */
+ for(int i=0; i < Oil_GetCounterCnt() ; i++) {
+ counter = Oil_GetCounter(i);
+ // Alarms
+ SLIST_INIT(&counter->alarm_head);
+ for(int j=0; j < Oil_GetAlarmCnt(); j++ ) {
+ alarm_obj = Oil_GetAlarmObj(j);
+ // Add the alarms
+ SLIST_INSERT_HEAD(&counter->alarm_head,alarm_obj, alarm_list);
+ }
+ // Schedule tables
+ SLIST_INIT(&counter->sched_head);
+ for(int j=0; j < Oil_GetSchedCnt(); j++ ) {
+ sched_obj = Oil_GetSched(j);
+ // Add the alarms
+ SLIST_INSERT_HEAD(&counter->sched_head,
+ sched_obj,
+ sched_list);
+ }
+
+
+ }
+}
+
+/**
+ * Copy rom pcb data(r_pcb) to ram data
+ *
+ * @param pcb ram data
+ * @param r_pcb rom data
+ */
+
+static void os_pcb_rom_copy( pcb_t *pcb, rom_pcb_t *r_pcb ) {
+
+#if 0 //?????
+ // Check to that the memory is ok
+ {
+ int cnt = sizeof(pcb_t);
+ for(int i=0;i<cnt;i++) {
+ if( *((unsigned char *)pcb) != 0 ) {
+ while(1);
+ }
+ }
+ }
+#endif
+
+// memset(pcb,sizeof(pcb_t),0);
+ pcb->pid = r_pcb->pid;
+ pcb->prio = r_pcb->prio;
+ pcb->application = Oil_GetApplObj(r_pcb->application_id);
+ pcb->entry = r_pcb->entry;
+ pcb->proc_type = r_pcb->proc_type;
+ pcb->autostart = r_pcb->autostart;
+ pcb->stack= r_pcb->stack;
+ pcb->pcb_rom_p = r_pcb;
+ pcb->resource_int_p = r_pcb->resource_int_p;
+ pcb->scheduling = r_pcb->scheduling;
+// pcb->app = &app_list[r_pcb->app];
+// pcb->app_mask = app_mask[r_pcb->app];
+ strncpy(pcb->name,r_pcb->name,16);
+}
+
+static _Bool init_os_called = 0;
+
+/**
+ * Initialization of kernel structures and start of the first
+ * task.
+ */
+
+void InitOS( void ) {
+ int i;
+ pcb_t *tmp_pcb;
+ stack_t int_stack;
+
+ init_os_called = 1;
+
+ DEBUG(DEBUG_LOW,"os_init");
+
+ /* Clear sys */
+ memset(&os_sys,0,sizeof(sys_t));
+
+ os_arch_init();
+
+ // Assign pcb list and init ready queue
+ os_sys.pcb_list = pcb_list;
+ TAILQ_INIT(& os_sys.ready_head);
+ TAILQ_INIT(& os_sys.pcb_head);
+
+ // Calc interrupt stack
+ Oil_GetInterruptStackInfo(&int_stack);
+ os_sys.int_stack = int_stack.top + int_stack.size - 16; // TODO: 16 is arch dependent
+
+ // Init counter.. with alarms and schedule tables
+ os_counter_init();
+ os_stbl_init();
+
+ // Put all tasks in the pcb list
+ // Put the one that belong in the ready queue there
+ // TODO: we should really hash on priority here to get speed, but I don't care for the moment
+ // TODO: Isn't this just EXTENED tasks ???
+ for( i=0; i < Oil_GetTaskCnt(); i++) {
+ tmp_pcb = os_get_pcb(i);
+ os_pcb_rom_copy(tmp_pcb,os_get_rom_pcb(i));
+ if( !(tmp_pcb->proc_type & PROC_ISR) ) {
+ os_pcb_make_virgin(tmp_pcb);
+ }
+
+ os_add_task(tmp_pcb);
+
+ DEBUG(DEBUG_LOW,"pid:%d name:%s prio:%d\n",tmp_pcb->pid,tmp_pcb->name,tmp_pcb->prio);
+ }
+
+ // Now all tasks should be created.
+}
+
+static void os_start( void ) {
+ pcb_t *tmp_pcb;
+
+ assert(init_os_called);
+
+ /* find highest prio process and run it */
+ tmp_pcb = os_find_top_prio_proc();
+
+ /* TODO: fix ugly */
+ /* Call the startup hook */
+ extern struct os_conf_global_hooks_s os_conf_global_hooks;
+ os_sys.hooks = &os_conf_global_hooks;
+ if( os_sys.hooks->StartupHook!=NULL ) {
+ os_sys.hooks->StartupHook();
+ }
+
+ /* handle autostart */
+ for(int j=0; j < Oil_GetAlarmCnt(); j++ ) {
+ alarm_obj_t *alarmPtr;
+ alarmPtr = Oil_GetAlarmObj(j);
+ if(alarmPtr->autostart.active) {
+ alarm_autostart_t *autoPtr = &alarmPtr->autostart;
+
+ SetAbsAlarm(j,autoPtr->alarmtime, autoPtr->cycletime);
+ }
+ }
+
+ // Swap in prio proc.
+ {
+ // FIXME: Do this in a more structured way.. setting os_sys.curr_pcb manually is not the way to go..
+ os_sys.curr_pcb = tmp_pcb;
+ // NOTE! We don't go for os_swap_context() here..
+ // first arg(NULL) is dummy only
+ os_swap_context_to(NULL,tmp_pcb);
+ // We should not return here
+ assert(0);
+ }
+}
+#if 0
+static void os_start( void ) {
+
+}
+#endif
+
+#define TEST_DATA 12345
+int test_data = TEST_DATA;
+int test_bss = 0;
+
+
+void noooo( void ) {
+ while(1);
+}
+
+extern void EcuM_Init();
+int main( void )
+{
+ EcuM_Init();
+
+}
+
+/**
+ * Starts the OS
+ *
+ * @param Mode - Application mode to start in
+ *
+ */
+void StartOS( AppModeType Mode ) {
+
+ /* Check link file */
+ if( TEST_DATA != test_data ) {
+ noooo();
+ }
+
+ if( test_bss != 0 ) {
+ noooo();
+ }
+
+ os_start();
+
+}
+
+
+/**
+ * OS shutdown
+ *
+ * @param Error - Reason for shutdown
+ */
+
+void ShutdownOS( StatusType Error ) {
+
+ if( os_sys.hooks->ShutdownHook != NULL ) {
+ os_sys.hooks->ShutdownHook(Error);
+ }
+ /* TODO: */
+ while(1);
+
+}
-\r
-#include "Os.h"\r
-#include "sys.h"\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include "ext_config.h"\r
-//#include "Pool.h"\r
-//#include "ppc_asm.h"\r
-#include "arch.h"\r
-#include "kernel.h"\r
-#include "swap.h"\r
-#include "hooks.h"\r
-#include "task_i.h"\r
-#include "alarm_i.h"\r
-#include "sched_table_i.h"\r
-#include "Trace.h"\r
-\r
-\r
-\r
-extern void Oil_GetInterruptStackInfo( stack_t *stack );\r
-sys_t os_sys;\r
-\r
-/**\r
- * Initialize alarms and schedule-tables for the counters\r
- */\r
-static void os_counter_init( void ) {\r
- counter_obj_t *counter;\r
- alarm_obj_t *alarm_obj;\r
- sched_table_t *sched_obj;\r
- /* Create a list from the counter to the alarms */\r
- for(int i=0; i < Oil_GetCounterCnt() ; i++) {\r
- counter = Oil_GetCounter(i);\r
- // Alarms\r
- SLIST_INIT(&counter->alarm_head);\r
- for(int j=0; j < Oil_GetAlarmCnt(); j++ ) {\r
- alarm_obj = Oil_GetAlarmObj(j);\r
- // Add the alarms\r
- SLIST_INSERT_HEAD(&counter->alarm_head,alarm_obj, alarm_list);\r
- }\r
- // Schedule tables\r
- SLIST_INIT(&counter->sched_head);\r
- for(int j=0; j < Oil_GetSchedCnt(); j++ ) {\r
- sched_obj = Oil_GetSched(j);\r
- // Add the alarms\r
- SLIST_INSERT_HEAD(&counter->sched_head,\r
- sched_obj,\r
- sched_list);\r
- }\r
-\r
-\r
- }\r
-}\r
-\r
-/**\r
- * Copy rom pcb data(r_pcb) to ram data\r
- *\r
- * @param pcb ram data\r
- * @param r_pcb rom data\r
- */\r
-\r
-static void os_pcb_rom_copy( pcb_t *pcb, rom_pcb_t *r_pcb ) {\r
-\r
-#if 0 //?????\r
- // Check to that the memory is ok\r
- {\r
- int cnt = sizeof(pcb_t);\r
- for(int i=0;i<cnt;i++) {\r
- if( *((unsigned char *)pcb) != 0 ) {\r
- while(1);\r
- }\r
- }\r
- }\r
-#endif\r
-\r
-// memset(pcb,sizeof(pcb_t),0);\r
- pcb->pid = r_pcb->pid;\r
- pcb->prio = r_pcb->prio;\r
- pcb->application = Oil_GetApplObj(r_pcb->application_id);\r
- pcb->entry = r_pcb->entry;\r
- pcb->proc_type = r_pcb->proc_type;\r
- pcb->autostart = r_pcb->autostart;\r
- pcb->stack= r_pcb->stack;\r
- pcb->pcb_rom_p = r_pcb;\r
- pcb->resource_int_p = r_pcb->resource_int_p;\r
- pcb->scheduling = r_pcb->scheduling;\r
-// pcb->app = &app_list[r_pcb->app];\r
-// pcb->app_mask = app_mask[r_pcb->app];\r
- strncpy(pcb->name,r_pcb->name,16);\r
-}\r
-\r
-static _Bool init_os_called = 0;\r
-\r
-/**\r
- * Initialization of kernel structures and start of the first\r
- * task.\r
- */\r
-\r
-void InitOS( void ) {\r
- int i;\r
- pcb_t *tmp_pcb;\r
- stack_t int_stack;\r
-\r
- init_os_called = 1;\r
-\r
- DEBUG(DEBUG_LOW,"os_init");\r
-\r
- /* Clear sys */\r
- memset(&os_sys,0,sizeof(sys_t));\r
-\r
- os_arch_init();\r
-\r
- // Assign pcb list and init ready queue\r
- os_sys.pcb_list = pcb_list;\r
- TAILQ_INIT(& os_sys.ready_head);\r
- TAILQ_INIT(& os_sys.pcb_head);\r
-\r
- // Calc interrupt stack\r
- Oil_GetInterruptStackInfo(&int_stack);\r
- os_sys.int_stack = int_stack.top + int_stack.size - 16; // TODO: 16 is arch dependent\r
-\r
- // Init counter.. with alarms and schedule tables\r
- os_counter_init();\r
- os_stbl_init();\r
-\r
- // Put all tasks in the pcb list\r
- // Put the one that belong in the ready queue there\r
- // TODO: we should really hash on priority here to get speed, but I don't care for the moment\r
- // TODO: Isn't this just EXTENED tasks ???\r
- for( i=0; i < Oil_GetTaskCnt(); i++) {\r
- tmp_pcb = os_get_pcb(i);\r
- os_pcb_rom_copy(tmp_pcb,os_get_rom_pcb(i));\r
- if( !(tmp_pcb->proc_type & PROC_ISR) ) {\r
- os_pcb_make_virgin(tmp_pcb);\r
- }\r
-\r
- os_add_task(tmp_pcb);\r
-\r
- DEBUG(DEBUG_LOW,"pid:%d name:%s prio:%d\n",tmp_pcb->pid,tmp_pcb->name,tmp_pcb->prio);\r
- }\r
-\r
- // Now all tasks should be created.\r
-}\r
-\r
-static void os_start( void ) {\r
- pcb_t *tmp_pcb;\r
-\r
- assert(init_os_called);\r
-\r
- /* find highest prio process and run it */\r
- tmp_pcb = os_find_top_prio_proc();\r
-\r
- /* TODO: fix ugly */\r
- /* Call the startup hook */\r
- extern struct os_conf_global_hooks_s os_conf_global_hooks;\r
- os_sys.hooks = &os_conf_global_hooks;\r
- if( os_sys.hooks->StartupHook!=NULL ) {\r
- os_sys.hooks->StartupHook();\r
- }\r
-\r
- /* handle autostart */\r
- for(int j=0; j < Oil_GetAlarmCnt(); j++ ) {\r
- alarm_obj_t *alarmPtr;\r
- alarmPtr = Oil_GetAlarmObj(j);\r
- if(alarmPtr->autostart.active) {\r
- alarm_autostart_t *autoPtr = &alarmPtr->autostart;\r
-\r
- SetAbsAlarm(j,autoPtr->alarmtime, autoPtr->cycletime);\r
- }\r
- }\r
-\r
- // Swap in prio proc.\r
- {\r
- // FIXME: Do this in a more structured way.. setting os_sys.curr_pcb manually is not the way to go..\r
- os_sys.curr_pcb = tmp_pcb;\r
- // NOTE! We don't go for os_swap_context() here..\r
- // first arg(NULL) is dummy only\r
- os_swap_context_to(NULL,tmp_pcb);\r
- // We should not return here\r
- assert(0);\r
- }\r
-}\r
-#if 0\r
-static void os_start( void ) {\r
-\r
-}\r
-#endif\r
-\r
-#define TEST_DATA 12345\r
-int test_data = TEST_DATA;\r
-int test_bss = 0;\r
-\r
-\r
-void noooo( void ) {\r
- while(1);\r
-}\r
-\r
-extern EcuM_Init();\r
-int main( void )\r
-{\r
- EcuM_Init();\r
-\r
-}\r
-\r
-/**\r
- * Starts the OS\r
- *\r
- * @param Mode - Application mode to start in\r
- *\r
- */\r
-void StartOS( AppModeType Mode ) {\r
-\r
- /* Check link file */\r
- if( TEST_DATA != test_data ) {\r
- noooo();\r
- }\r
-\r
- if( test_bss != 0 ) {\r
- noooo();\r
- }\r
-\r
- os_start();\r
-\r
-}\r
-\r
-\r
-/**\r
- * OS shutdown\r
- *\r
- * @param Error - Reason for shutdown\r
- */\r
-\r
-void ShutdownOS( StatusType Error ) {\r
-\r
- if( os_sys.hooks->ShutdownHook != NULL ) {\r
- os_sys.hooks->ShutdownHook(Error);\r
- }\r
- /* TODO: */\r
- while(1);\r
-\r
-}\r
-\r
-\r
-\r
-\r
-#include "types.h"\r
-#include "Os.h"\r
-#include "assert.h"\r
-#include "sys.h"\r
-#include "stdlib.h"\r
-#include "kernel.h"\r
-#include "internal.h"\r
-#include "hooks.h"\r
-#include "task_i.h"\r
-#include "ext_config.h"\r
-\r
-\r
-#define valid_standard_id() (rid->nr < Oil_GetResourceCnt()) //&& !(rid->type == RESOURCE_TYPE_INTERNAL) )\r
-#define valid_internal_id() (rid->nr < Oil_GetResourceCnt()) //&& (rid->type == RESOURCE_TYPE_INTERNAL) )\r
-\r
-\r
-static StatusType GetResource_( resource_obj_t * );\r
-StatusType ReleaseResource_( resource_obj_t * );\r
-\r
-StatusType GetResource( ResourceType ResID ) {\r
- resource_obj_t *rid = Oil_GetResource(ResID);\r
- StatusType rv = GetResource_(rid);\r
-\r
- if (rv != E_OK)\r
- goto err;\r
-\r
- OS_STD_END_1(OSServiceId_GetResource,ResID);\r
-}\r
-\r
-#if 0\r
-StatusType GetResourceInternal( ResourceType ResID ) {\r
- return GetResource_(ResID,1);\r
-}\r
-#endif\r
-\r
-static StatusType GetResource_( resource_obj_t * rid ) {\r
- StatusType rv = E_OK;\r
-\r
- if( rid->nr == RES_SCHEDULER ) {\r
- // Lock the sheduler\r
-#warning Check this\r
- os_sys.scheduler_lock = 1;\r
- //simple_printf("RES_SCHEDULER, NOT supported yet\n");\r
- //while(1);\r
- }\r
- // Check if valid resource\r
- if( !valid_standard_id() ) {\r
- rv = E_OS_ID;\r
- goto err;\r
- }\r
- // Check that the resource does not belong to another application or task\r
- if( ( (os_task_nr_to_mask(get_curr_pid()) & rid->task_mask ) == 0 )\r
- || ( get_curr_application_id() != rid->application_owner_id)\r
- || ( rid->owner != (TaskType)(-1)))\r
- {\r
- rv = E_OS_ACCESS;\r
- goto err;\r
- }\r
-\r
- rid->owner = get_curr_pid();\r
- rid->old_task_prio = os_pcb_set_prio(os_get_curr_pcb() ,rid->ceiling_priority);\r
- goto ok;\r
-err:\r
- ERRORHOOK(rv);\r
-ok:\r
- return rv;\r
-}\r
-\r
-StatusType ReleaseResource( ResourceType ResID) {\r
- StatusType rv = E_OK;\r
- if( ResID == RES_SCHEDULER ) {\r
- #warning check this\r
- os_sys.scheduler_lock=0;\r
- } else {\r
- resource_obj_t *rid = Oil_GetResource(ResID);\r
- rv = ReleaseResource_(rid);\r
- }\r
-\r
- if (rv != E_OK)\r
- goto err;\r
-\r
- OS_STD_END_1(OSServiceId_ReleaseResource,ResID);\r
-}\r
-\r
-StatusType ReleaseResource_( resource_obj_t * rid ) {\r
- if (!valid_standard_id()) {\r
- return E_OS_ID;\r
- } else {\r
-\r
- // Release it...\r
- rid->owner = (TaskType) (-1);\r
- os_pcb_set_prio(os_get_curr_pcb(), rid->old_task_prio);\r
-\r
- return E_OK;\r
- }\r
-}\r
-\r
-// TODO: Remove this function later.. this is done in oil generator\r
-// instead.\r
-void os_resource_calc_attributes( void ) {\r
- // Calc ceiling\r
-// ResourceType *rsrc;\r
- for( int i=0;i<Oil_GetResourceCnt();i++) {\r
-// rsrc = Oil_GetResource();\r
- /* TODO: Do this when there's more time */\r
-// rsrc\r
- }\r
-}\r
-\r
-//\r
-void os_resource_get_internal( void ) {\r
- resource_obj_t *rt = os_get_resource_int_p();\r
-\r
- if( rt != NULL ) {\r
- //simple_printf("Get IR proc:%s prio:%d old_task_prio:%d\n",get_curr_pcb()->name, rt->ceiling_priority,rt->old_task_prio);\r
- GetResource_(rt);\r
- }\r
- //GetResourceInternal(os_get_curr_pcb()->resource_internal);\r
-}\r
-\r
-void os_resource_release_internal( void ) {\r
- resource_obj_t *rt = os_get_resource_int_p();\r
-\r
- if( rt != NULL ) {\r
- //simple_printf("Rel IR proc:%s prio:%d old_task_prio:%d\n",get_curr_pcb()->name,rt->ceiling_priority,rt->old_task_prio);\r
- ReleaseResource_(rt);\r
- }\r
- //ReleaseResource(os_get_curr_pcb()->resource_internal);\r
-}\r
-\r
-\r
-\r
+
+#include "types.h"
+#include "Os.h"
+#include "assert.h"
+#include "sys.h"
+#include "stdlib.h"
+#include "kernel.h"
+#include "internal.h"
+#include "hooks.h"
+#include "task_i.h"
+#include "ext_config.h"
+
+
+#define valid_standard_id() (rid->nr < Oil_GetResourceCnt()) //&& !(rid->type == RESOURCE_TYPE_INTERNAL) )
+#define valid_internal_id() (rid->nr < Oil_GetResourceCnt()) //&& (rid->type == RESOURCE_TYPE_INTERNAL) )
+
+
+static StatusType GetResource_( resource_obj_t * );
+StatusType ReleaseResource_( resource_obj_t * );
+
+StatusType GetResource( ResourceType ResID ) {
+ resource_obj_t *rid = Oil_GetResource(ResID);
+ StatusType rv = GetResource_(rid);
+
+ if (rv != E_OK)
+ goto err;
+
+ OS_STD_END_1(OSServiceId_GetResource,ResID);
+}
+
+#if 0
+StatusType GetResourceInternal( ResourceType ResID ) {
+ return GetResource_(ResID,1);
+}
+#endif
+
+static StatusType GetResource_( resource_obj_t * rid ) {
+ StatusType rv = E_OK;
+
+ if( rid->nr == RES_SCHEDULER ) {
+ // Lock the sheduler
+#warning Check this
+ os_sys.scheduler_lock = 1;
+ //simple_printf("RES_SCHEDULER, NOT supported yet\n");
+ //while(1);
+ }
+ // Check if valid resource
+ if( !valid_standard_id() ) {
+ rv = E_OS_ID;
+ goto err;
+ }
+ // Check that the resource does not belong to another application or task
+ if( ( (os_task_nr_to_mask(get_curr_pid()) & rid->task_mask ) == 0 )
+ || ( get_curr_application_id() != rid->application_owner_id)
+ || ( rid->owner != (TaskType)(-1)))
+ {
+ rv = E_OS_ACCESS;
+ goto err;
+ }
+
+ rid->owner = get_curr_pid();
+ rid->old_task_prio = os_pcb_set_prio(os_get_curr_pcb() ,rid->ceiling_priority);
+ goto ok;
+err:
+ ERRORHOOK(rv);
+ok:
+ return rv;
+}
+
+StatusType ReleaseResource( ResourceType ResID) {
+ StatusType rv = E_OK;
+ if( ResID == RES_SCHEDULER ) {
+ #warning check this
+ os_sys.scheduler_lock=0;
+ } else {
+ resource_obj_t *rid = Oil_GetResource(ResID);
+ rv = ReleaseResource_(rid);
+ }
+
+ if (rv != E_OK)
+ goto err;
+
+ OS_STD_END_1(OSServiceId_ReleaseResource,ResID);
+}
+
+StatusType ReleaseResource_( resource_obj_t * rid ) {
+ if (!valid_standard_id()) {
+ return E_OS_ID;
+ } else {
+
+ // Release it...
+ rid->owner = (TaskType) (-1);
+ os_pcb_set_prio(os_get_curr_pcb(), rid->old_task_prio);
+
+ return E_OK;
+ }
+}
+
+// TODO: Remove this function later.. this is done in oil generator
+// instead.
+void os_resource_calc_attributes( void ) {
+ // Calc ceiling
+// ResourceType *rsrc;
+ for( int i=0;i<Oil_GetResourceCnt();i++) {
+// rsrc = Oil_GetResource();
+ /* TODO: Do this when there's more time */
+// rsrc
+ }
+}
+
+//
+void os_resource_get_internal( void ) {
+ resource_obj_t *rt = os_get_resource_int_p();
+
+ if( rt != NULL ) {
+ //simple_printf("Get IR proc:%s prio:%d old_task_prio:%d\n",get_curr_pcb()->name, rt->ceiling_priority,rt->old_task_prio);
+ GetResource_(rt);
+ }
+ //GetResourceInternal(os_get_curr_pcb()->resource_internal);
+}
+
+void os_resource_release_internal( void ) {
+ resource_obj_t *rt = os_get_resource_int_p();
+
+ if( rt != NULL ) {
+ //simple_printf("Rel IR proc:%s prio:%d old_task_prio:%d\n",get_curr_pcb()->name,rt->ceiling_priority,rt->old_task_prio);
+ ReleaseResource_(rt);
+ }
+ //ReleaseResource(os_get_curr_pcb()->resource_internal);
+}
+
+
+