-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathThreads.h
51 lines (42 loc) · 1.41 KB
/
Threads.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*****************************************************************************
* Project Name: CKOS
* Authors: Casey Artner & Kenny Deardorff
* Class: CST 352 - Operating Systems
* File: Threads.h - CKOS Cooperative and Preemptive Threading
*****************************************************************************/
#ifndef CKOS_THREADS
#define CKOS_THREADS
#include "Scheduler.h"
//Register Map
//extern unsigned short __tmp __asm__("_.tmp");
//extern unsigned short __z __asm__("_.z");
//extern unsigned short __xy __asm__("_.xy");
//extern unsigned short __frame __asm__("_.frame");
//Critical Section Defines
#define T_CRITICAL_BEGIN asm volatile("sei");
#define T_CRITICAL_END asm volatile("cli");
//Global Vars
extern unsigned short int _address;
extern unsigned short int _current_sp;
extern unsigned short int _next_sp;
typedef struct SemiphoreN
{
int m_count;
SchBlockedNode * m_blocked;
} Semiphore;
//Threads Functions
static void inline Push();
static void inline Pop();
void InitThreading();
void inline Preempt();
void SWI_ISR(void) __attribute__((interrupt));
void RTI_ISR(void) __attribute__((interrupt));
void CreateThread(unsigned short int address);
void inline Yield();
//Semiphore Functions
Semiphore * CreateSemiphore(int count);
Semiphore * CreateMutex();
void DestroySemiphore(Semiphore * sem);
void Wait(Semiphore * sem);
void Signal(Semiphore * sem);
#endif /* CKOS_THREADS */