-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathactionQueue.c
More file actions
136 lines (120 loc) · 4.16 KB
/
actionQueue.c
File metadata and controls
136 lines (120 loc) · 4.16 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
Routines for CBUS FLiM operations - part of CBUS libraries for PIC 18F
This work is licensed under the:
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
To view a copy of this license, visit:
http://creativecommons.org/licenses/by-nc-sa/4.0/
or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
License summary:
You are free to:
Share, copy and redistribute the material in any medium or format
Adapt, remix, transform, and build upon the material
The licensor cannot revoke these freedoms as long as you follow the license terms.
Attribution : You must give appropriate credit, provide a link to the license,
and indicate if changes were made. You may do so in any reasonable manner,
but not in any way that suggests the licensor endorses you or your use.
NonCommercial : You may not use the material for commercial purposes. **(see note below)
ShareAlike : If you remix, transform, or build upon the material, you must distribute
your contributions under the same license as the original.
No additional restrictions : You may not apply legal terms or technological measures that
legally restrict others from doing anything the license permits.
** For commercial use, please contact the original copyright holder(s) to agree licensing terms
**************************************************************************************************************
The FLiM routines have no code or definitions that are specific to any
module, so they can be used to provide FLiM facilities for any module
using these libraries.
*/
/*
* File: actionQueue.c
* Author: Ian
*
* Created on 1 June 2017, 13:14
*
* A queue of actions waiting to be processed by the main loop.
* Implemented as two separated queues - a normal and an expedited priority queue.
*/
#include "GenericTypeDefs.h"
#include "module.h"
#include "computeEvents.h"
#include "actionQueue.h"
#include "queue.h"
//BYTE normalReadIdx[NUM_ACTION_QUEUES]; // index of the next to read
//BYTE normalWriteIdx[NUM_ACTION_QUEUES]; // index of the next to write
COMPUTE_ACTION_T normalQueueBuf[NUM_ACTION_QUEUES][ACTION_QUEUE_SIZE]; // the actual cyclic buffer space
Queue normalQueue[NUM_ACTION_QUEUES];
static BYTE currentPushQueue;
/**
* Initialise the action queue.
*/
void actionQueueInit(void) {
BYTE i;
for (i=0; i<NUM_ACTION_QUEUES;i++) {
normalQueue[i].size = ACTION_QUEUE_SIZE;
normalQueue[i].readIdx = 0;
normalQueue[i].writeIdx = 0;
normalQueue[i].queue = normalQueueBuf[i];
}
currentPushQueue = 0;
}
/**
* Put the action onto the list of actions to be processed.
*
* @param a the action to be processed
*/
BOOL pushAction(COMPUTE_ACTION_T a) {
return push(&(normalQueue[currentPushQueue]), a);
}
/**
* Get the action we need to be progressing.
*
* @return the action
*/
COMPUTE_ACTION_T getAction(BYTE q) {
return peekActionQueue(q, 0);
}
/**
* Pull the next action from the buffer.
*
* @return the next action
*/
COMPUTE_ACTION_T popAction(BYTE q) {
return pop(&(normalQueue[q]));
}
/**
* Change the value on a queue.
* @param q
* @param newVal
*/
void changeAction(BYTE q, COMPUTE_ACTION_T newVal) {
change(&(normalQueue[q]), newVal);
}
/**
* Mark as having completed the current action.
*/
void doneAction(BYTE q) {
popAction(q);
}
/**
* Peek an item in the queue. Does not remove the item from the queue.
* @param index the item index within the queue
* @return the Action or NO_ACTION
*/
COMPUTE_ACTION_T peekActionQueue(BYTE q, unsigned char index) {
if (index < quantity(&(normalQueue[q]))) {
return peek(&(normalQueue[q]), index);
}
return NO_ACTION;
}
/**
* Delete an item in the queue. Replace the item with NO_ACTION.
* @param index the item index within the queue
*/
void deleteActionQueue(BYTE q, unsigned char index) {
delete(&(normalQueue[q]), index);
}
void nextQueue(void) {
currentPushQueue++;
if (currentPushQueue >= NUM_ACTION_QUEUES) {
currentPushQueue = 0;
}
}