aboutsummaryrefslogtreecommitdiff
path: root/core.h
diff options
context:
space:
mode:
authorOtto Mattik <otto@mattik.org>2021-07-08 18:10:55 +0200
committerOtto Mattik <otto@mattik.org>2021-07-08 18:10:55 +0200
commitda34d97efb21719b2b332f8c60b2750d11bcde1f (patch)
tree2de9fe89f6d79b8ebfcde64c5e86204e904aedf2 /core.h
downloadarmen-da34d97efb21719b2b332f8c60b2750d11bcde1f.tar.gz
armen-da34d97efb21719b2b332f8c60b2750d11bcde1f.zip
git: update to v1.0HEADv1.0master
Diffstat (limited to 'core.h')
-rw-r--r--core.h113
1 files changed, 113 insertions, 0 deletions
diff --git a/core.h b/core.h
new file mode 100644
index 0000000..6dd5348
--- /dev/null
+++ b/core.h
@@ -0,0 +1,113 @@
+/************************************************************************/
+/* */
+/* File: core.h */
+/* Description: armen internals */
+/* Version: 1.0 */
+/* Author: Otto Mattik */
+/* */
+/* (C)Copyright Otto Mattik 2014-2021. */
+/* */
+/* This file is a part of 'armen' (a tiny operating system). */
+/* 'armen' is distributed under the CeCILL-V2.1 licence. For more */
+/* details about this licence, please visit the website cecill.info */
+/* */
+/************************************************************************/
+
+#ifndef _ARMEN_CORE_H_
+#define _ARMEN_CORE_H_
+
+#include "armen.h"
+
+#ifdef __AVR_ARCH__
+ #include "avr/core.h"
+#endif
+
+/*
+ * number of threads
+*/
+#define ARMEN_THREAD_MIN 2
+#define ARMEN_THREAD_MAX 8
+#if defined(THREAD)
+ #if (THREAD < 0) || (THREAD > (ARMEN_THREAD_MAX-ARMEN_THREAD_MIN))
+ #error "invalid number of threads"
+ #endif
+#else
+ #define THREAD 1
+#endif
+#define ARMEN_THREADS (ARMEN_THREAD_MIN+THREAD)
+
+/*
+ * number of timers
+*/
+#define ARMEN_TIMER_MIN 1
+#define ARMEN_TIMER_MAX 2
+#if defined(TIMER)
+ #if (TIMER < ARMEN_TIMER_MIN) || (TIMER > ARMEN_TIMER_MAX)
+ #error "invalid number of timers"
+ #endif
+ #define ARMEN_TIMERS TIMER
+#else
+ #define ARMEN_TIMERS ARMEN_TIMER_MIN
+#endif
+
+typedef struct {
+ uint8_t lock;
+ uint8_t value;
+ uint8_t count;
+ uint8_t pad;
+} _sem_t;
+
+typedef struct {
+ uint8_t status; /* status (see below) */
+ uint8_t rank; /* priority set by user */
+ uint8_t order; /* priority set by kernel */
+ uint8_t joinid; /* thread where waiting for termination */
+ uint16_t events; /* events for whitch thread is suspended */
+ uint16_t event; /* last event */
+ timer_t timer1; /* timer counter 1 (used by sleep function) */
+#if (ARMEN_TIMERS == 2)
+ timer_t timer2; /* timer counter 2 */
+#endif
+ void* (*entry)(void*); /* thread entry point */
+ void* param; /* calling argument or returned value */
+ void* istack; /* initial value of stack pointer */
+ void* cstack; /* current stack pointer */
+#if defined(USE_SEM)
+ void* sem; /* semaphore on thread is waiting */
+#endif
+} _thread_t;
+
+/*
+ * status of a thread
+*/
+#define TS_UNUSED 0
+#define TS_RUNNING 1
+#define TS_SUSPENDED 2
+
+/*
+ * events (see also armen.h)
+*/
+#define EVENT_JOIN 0x4000
+#define EVENT_SEM 0x8000
+
+extern uint8_t volatile _cur_thread; /* id of current thread */
+extern _thread_t _threads[]; /* table of threads */
+
+extern void _thread_exit( void );
+
+extern void* _idle( void* );
+extern void _schedule( void );
+extern uint8_t _disable_intr( void );
+extern void _enable_intr( uint8_t flag );
+extern void* _init_context( void* (*entry)(void*), void* param, void* sp );
+extern void* _save_context( void );
+extern void _restore_context( void* sp );
+
+extern void _sys_init( void* ram_start, void* ram_end );
+extern void _sys_clock( void );
+extern void _scheduler( void* sp );
+extern void _wakeup( uint16_t event, void* param );
+
+extern void _uart_init( void );
+
+#endif