Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 129 lines (91 sloc) 6.256 kb
11e11e9 @Zuph Added Readme and License
authored
1 AVRQueue
2 ========
3
4 AVRQueue is a task queuing library for AVR and Arduino processors. Included here are two different branches, **AVR** and **Arduino**.
5
6 This is a simple queuing library. Add functions to the queue, along with a unique identifier, an initial run time, and a recurrence time. If your time scale is in seconds, an item with an initial run time of 1, and a recurrence of 5 will run after time 1 second, and every 5 seconds thereafter.
7
8 Functions are not guaranteed to execute deterministic when they're scheduled. This is a very primitive library. The run function simply waits for a function in the queue to reach its run time, runs the function, then continues through the queue. If queued functions take a very long time to execute, then functions may not execute precisely when desired. For this reason, a "now" variable is passed into every function in order to let it know when it actually runs.
9
10 AVR
11 ---
12
13 The AVR library is oriented towards enthusiasts. Compile **queue.c** with your project, and include **queue.h** in any files that need to add, modify, remove, or execute functions from the queue.
14
15 All settings are in **queue.h**:
16
17 * ***QUEUE_DEPTH***: The number of functions that you can store in the queue. More functions = more RAM required. (_Default:_ 10)
18
19 * ***NAME_LIMIT***: The number of characters used to store unique IDs for tasks. (_Default:_ 8)
20
21 * ***queue_time_t***: Typedef for the storage of timing data. Use the native type for whatever time system you're using. (If you're using AVR timers, change this to uint_16t). (_Default:_ uint_32t)
22
23 ### Usage
24
25 * ***Queued Functions***: All queued functions must have the following C signature:
26 > int queued\_function(queue\_time\_t now)<br />
27 > The _now_ variable will contain the time the function was called.
28
29 * int scheduleFunction(queuedFunction **pFunction**, const char ***pId**, queue\_time\_t **pInitialRun**, queue\_time\_t **pRecur**)
30 > Add a function to the queue.<br/>
31 > ***Return Values:***<br/>
32 >> **0** if successful.<br/>
33 >> **-1** if unsuccessful (queue is full).<br/>
34
35 * **pFunction**: Function to put in the queue.
36 * ***pId**: Up to 8 character unique identifier. (Unless you change the length).
37 * **pInitialRun**: Initial run time, in whatever time units you feed into **run**.
38 * **pRecur**: Recurrence period, in whatever time units you feed into **run**.
39
40 * int scheduleRemoveFunction(const char ***pId**)
41 > Remove a function with given unique ID from the queue.<br />
42 > ***Return Values:***<br/>
43 >> **0** if successful. <br/>
44 >> **-1** if unsuccessful.
45
46 * ***pId**: Unique id
47
48 * int scheduleChangeFunction(const char ***pId**, queue_time_t **pNewNext**, queue_time_t **pNewRecur**)
49 > Change function in the queue.<br/>
50 > ***Return Values:***<br/>
51 >> **0** if successful. <br/>
52 >> **-1** if unsuccessful.
53
54 * ***pId**: Unique identifier.
55 * **pNewNext**: Next time to run the function.
56 * **pNewRecur**: New recurrence time.
57
58 * int scheduleRun(queue_time_t **pNow**)
59 > Run all the queued items. Run this in a loop to execute the queue.<br/>
60 > ***Return Values:***<br/>
61 >> **-1** if unsuccessful.
62 >> **Number of queue items successfully ran** otherwise.
63
64 * **pNow**: the current time.
65
66 Arduino
67 -------
68
69 The Arduino library is much easier to use. Extract to <Arduino Root>/Libraries/Queue/, restart the IDE, and start using.
70
71 * Maximum of 10 items in the queue.
72 * Unique IDs are up to 8 characters, no more.
73 * Use with ```millis();```
74
75 ### Usage
76
77 * ***Queued Functions***: All queued functions must have a C signature (either not class-members, or static class-members) of:
78 > int queued\_function(unsigned long now)<br />
79 > The _now_ variable will contain the time the function was called.
80
81 * ***Creating a Queue***: Create a queue like this: ```Queue myQueue;```
82
83 * int Queue::scheduleFunction(queuedFunction **pFunction**, const char ***pId**, unsigned long **pInitialRun**, unsigned long **pRecur**)
84 > Add a function to the queue.<br/>
85 > ***Return Values:***<br/>
86 >> **0** if successful.<br/>
87 >> **-1** if unsuccessful (queue is full).<br/>
88
89 * **pFunction**: Function to put in the queue.
90 * ***pId**: Up to 8 character unique identifier. (Unless you change the length).
91 * **pInitialRun**: Initial run time, in milliseconds.
92 * **pRecur**: Recurrence period, in milliseconds.
93
94 * int Queue::scheduleRemoveFunction(const char ***pId**)
95 > Remove a function with given unique ID from the queue.<br />
96 > ***Return Values:***<br/>
97 >> **0** if successful. <br/>
98 >> **-1** if unsuccessful.
99
100 * ***pId**: Unique id
101
102 * int Queue::scheduleChangeFunction(const char ***pId**, unsigned long **pNewNext**, unsigned long **pNewRecur**)
103 > Change function in the queue.<br/>
104 > ***Return Values:***<br/>
105 >> **0** if successful. <br/>
106 >> **-1** if unsuccessful.
107
108 * ***pId**: Unique identifier.
109 * **pNewNext**: Next time to run the function.
110 * **pNewRecur**: New recurrence time.
111
112 * int Queue::scheduleRun(unsigned long **pNow**)
113 > Run all the queued items. Run this in a loop to execute the queue.<br/>
114 > ***Return Values:***<br/>
115 >> **-1** if unsuccessful.
116 >> **Number of queue items successfully ran** otherwise.
117
118 * **pNow**: the current time, in Milliseconds.
119
120 License
121 -------
122
123 Copyright (c) 2012 Brad Luyster
124
125 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
126
127 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
128
129 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Something went wrong with that request. Please try again.