-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtiming.c
85 lines (74 loc) · 1.89 KB
/
timing.c
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//
// timing.c
// mOS
//
// Created by Markus Axelsson on 2015-02-10.
// Copyright (c) 2015 Markus & Oskar. All rights reserved.
//
#include "timing.h"
#include "main.h"
#include "kernel.h"
#include "list_admin.h"
#include "memwatch.h"
int w_firstrun = TRUE;
int sd_firstrun = TRUE;
exception wait1( uint nTicks ){
int status = DEADLINE_REACHED;
listobj * tempObj;
isr_off();
SaveContext();
if (w_firstrun) {
w_firstrun = FALSE;
tempObj = extract_ready_timer_list(g_readylist);
tempObj->nTCnt = nTicks + TC;
insert_timerlist(tempObj, tempObj->nTCnt);
LoadContext();
}
else{
if (TC >= g_readylist->pHead->pNext->pTask->DeadLine) {
status=DEADLINE_REACHED;
}
else{
status = OK;
}
}
return status;
}
void set_ticks(uint nTicks){
TC = nTicks;
}
uint ticks(void){
return TC;
}
uint deadline(void){
return g_readylist->pHead->pTask->DeadLine;
}
void set_deadline( uint nNew ){
volatile int firstrun = TRUE;
isr_off();
SaveContext();
if (sd_firstrun) {
sd_firstrun = FALSE;
g_readylist->pHead->pNext->pTask->DeadLine = nNew;
listobj *temp = extract_ready_timer_list(g_readylist);
insert_waiting_ready_list(g_readylist, temp);
LoadContext();
}
}
void TimerInt(void){
TC++;
listobj *newObj = g_timerlist->pHead->pNext;
while (newObj != g_timerlist->pTail && TC >= newObj->nTCnt) {
extract_timerlist();
insert_waiting_ready_list(g_readylist, newObj);
newObj = g_timerlist->pHead->pNext;
}
newObj = g_waitinglist->pHead->pNext;
while(newObj != g_waitinglist->pTail){
if(newObj->pTask->DeadLine <= TC){
insert_waiting_ready_list(g_readylist, newObj);
extract_waitinglist(newObj);
newObj = g_waitinglist->pHead->pNext;
}
}
}