OOSMOS API Reference
NOTE: For improved readability, the 'oosmos_' prefix has been suppressed from the table of contents and from each See Also list.
ActiveObjectInit
Allocate
AllocateVisible
AnalogMapAccurate
AnalogMapFast
ASSERT
ClockSpeedInMHz
COMPLETE
CompositeInit
Days2Hours
Days2Minutes
Days2MS
Days2Seconds
Days2US
Debug
DebugPrint
DEFAULT
DelayMS
DelaySeconds
DelayUS
Divide_Integral_Rounded
EndProgram
ENTER
EventCode
EXIT
FinalInit
FOREVER
GetFreeRunningUS
Hours2Days_Rounded
Hours2Days_Truncated
Hours2Minutes
Hours2MS
Hours2Seconds
Hours2US
IsInState
LeafInit
Minutes2Days_Rounded
Minutes2Days_Truncated
Minutes2Hours_Rounded
Minutes2Hours_Truncated
Minutes2MS
Minutes2Seconds
Minutes2US
MS2Days_Rounded
MS2Days_Truncated
MS2Hours_Rounded
MS2Hours_Truncated
MS2Minutes_Rounded
MS2Minutes_Truncated
MS2Seconds_Rounded
MS2Seconds_Truncated
MS2US
ObjectThreadInit
ObjectThreadStart
ObjectThreadStop
ORTHO
OrthoInit
OrthoRegionInit
POINTER_GUARD
POLL
PushEvent
PushEventCode
QueueConstruct
QueuePop
QueuePush
RunStateMachine
RunStateMachines
sActiveObject
sComposite
Seconds2Days_Rounded
Seconds2Days_Truncated
Seconds2Hours_Rounded
Seconds2Hours_Truncated
Seconds2Minutes_Rounded
Seconds2Minutes_Truncated
Seconds2MS
Seconds2US
sEvent
sFinal
sLeaf
sObjectThread
sOrtho
sOrthoRegion
sQueue
sState
sStateMachine
sStateMachineNoQueue
sSubscriberList
StateMachineInit
StateMachineInitNoQueue
StateTimeoutMS
StateTimeoutSeconds
StateTimeoutUS
sTimeout
SubscriberListAdd
SubscriberListInit
SubscriberListNotify
SubscriberListNotifyWithArgs
ThreadBegin
ThreadDelayMS
ThreadDelaySeconds
ThreadDelayUS
ThreadEnd
ThreadExit
ThreadFinally
ThreadWaitCond
ThreadWaitCond_TimeoutMS
ThreadWaitEvent
ThreadWaitEvent_TimeoutMS
ThreadYield
TIMEOUT
TimeoutHasExpired
TimeoutInMS
TimeoutInSeconds
TimeoutInUS
Transition
TransitionAction
UNUSED
US2Days_Rounded
US2Days_Truncated
US2Hours_Rounded
US2Hours_Truncated
US2Minutes_Rounded
US2Minutes_Truncated
US2MS_Rounded
US2MS_Truncated
US2Seconds_Rounded
US2Seconds_Truncated
Important: All of these APIs are available to you to code by hand, however many of them are generated by the OOSMOS code generator while parsing your UMLet state chart. We urge you to draw state charts and generate your code using the OOSMOS code generator.

oosmos_ActiveObjectInit

An active OOSMOS object is an object that has reactive behavior but does not have the complexity to warrant using a full OOSMOS state machine object.
To establish your object as an active object, you must register it with OOSMOS like this: create a subroutine for OOSMOS to call (line 118), then create an oosmos_sActiveObject member in your object (line 54) and then finally call oosmos_ActiveObjectInit (line 66).
1
2
3
 
void oosmos_ActiveObjectInit(void * pObject, oosmos_sActiveObject * pActiveObject, oosmos_tActiveObjectFunc pFunc);
 
Prototype
pObject
Pointer to your active object.
pActiveObject
Pointer to the oosmos_sActiveObject object member.
pFunction
Address of the function to call each time through the OOSMOS main loop.
See Also
1
22
23
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
[GPLv2]
 
[...]
 
struct swTag
{
pin * m_pPin;
eStates m_State;
 
oosmos_sActiveObject m_ActiveObject;
oosmos_sSubscriberList m_CloseEvent[swMaxCloseSubscribers];
oosmos_sSubscriberList m_OpenEvent[swMaxOpenSubscribers];
};
 
extern sw * swNewDetached(pin * pPin)
{
oosmos_Allocate(pSwitch, sw, swMaxSwitches, NULL);
 
pSwitch->m_pPin = pPin;
pSwitch->m_State = Unknown_State;
 
oosmos_ActiveObjectInit(pSwitch, m_ActiveObject, swRunStateMachine);
 
oosmos_SubscriberListInit(pSwitch->m_CloseEvent);
oosmos_SubscriberListInit(pSwitch->m_OpenEvent);
 
return pSwitch;
}
 
[...]
 
extern void swRunStateMachine(void * pObject)
{
oosmos_POINTER_GUARD(pObject);
 
sw * pSwitch = (sw *) pObject;
 
switch (pSwitch->m_State) {
case Open_State: {
if (pinIsOn(pSwitch->m_pPin)) {
pSwitch->m_State = Closed_State;
oosmos_SubscriberListNotify(pSwitch->m_CloseEvent);
}
 
break;
}
case Closed_State: {
if (pinIsOff(pSwitch->m_pPin)) {
pSwitch->m_State = Open_State;
oosmos_SubscriberListNotify(pSwitch->m_OpenEvent);
}
 
break;
}
case Unknown_State: {
pSwitch->m_State = pinIsOn(pSwitch->m_pPin) ? Closed_State : Open_State;
break;
}
}
}
oosmos/Classes/sw.c

oosmos_Allocate

oosmos_Allocate is a macro that returns a pointer to an unused object from a fixed number of statically preallocated objects. The static preallocation is done automatically within the macro. Once allocated, objects cannot be returned to the pool. See the example on line 82.
If you need dynamic memory, use malloc in place of this function and then create a complementary toggleDelete function and then do a free to release it.
1
2
3
 
Type * oosmos_Allocate(Pointer, Type, Elements, pOutOfMemory);
 
Prototype
Pointer
The name of the variable that will hold the pointer to the allocated object. You'll use this to initialize your object's members, including the state machine (if the object has one). You must return this pointer to the caller. (See toggle.c line 97 below.)
Type
The data type of the object. (See line 29 of toggle.h below.)
Elements
The number of objects to pre-allocate. You can specify a number here, but it would be better to use the macro technique used in lines 23-25 of the toggle.c where you specify a default amount that can be overridden on the compilation command line. This is commonly done with most compilers like this: -D toggleMax=10.
pOutOfMemory
The address of a subroutine to call if all preallocated objects have been exhausted. See type oosmos_tOutOfMemory for information about how to implement the called routine.
If NULL, oosmos_Allocate will loop forever when all objects of this type are exhausted.
See Also
1
22
23
28
29
30
31
32
33
[GPLv2]
 
[...]
 
typedef struct toggleTag toggle;
 
extern toggle * toggleNew(pin * pPin, uint32_t TimeOnMS, uint32_t TimeOffMS);
 
#endif
oosmos/Classes/toggle.h
1
22
23
24
25
26
27
[GPLv2]
 
#ifndef toggleMAX
#define toggleMAX 5
#endif
 
[...]
oosmos/Classes/toggle.c

oosmos_AllocateVisible

oosmos_AllocateVisible is functionally the same as oosmos_Allocate but allows the user to allocate the array of objects in an outer scope thereby allowing access to that array by other parts of the implementation of the object. (See line 83 of the example below.)
1
2
3
 
Type * oosmos_AllocateVisible(Pointer, Type, List, Count, Elements, pOutOfMemory);
 
Prototype
Pointer
The name of the variable that will hold the pointer to the allocated object. You'll use this to initialize your object's members, including the state machine (if the object has one). You must return this pointer to the caller (see line 90).
Type
The data type of the object. (See line 32 of Interrupt.c.)
List
The address of the array of objects you pre-allocated. (See line 46.)
Count
The number of objects that have been returned from oosmos_AllocateVisible. (See line 47.)
Elements
The number of objects to pre-allocate.
pOutOfMemory
The address of a subroutine to call if all preallocated objects have been exhausted. See type oosmos_tOutOfMemory for information about how to implement the called routine.
If NULL is specified, oosmos_AllocateVisible will loop forever when all objects of this type are exhausted.
See Also
1
22
23
27
28
29
30
31
32
33
34
43
44
45
46
47
48
49
64
81
82
83
84
85
86
87
88
89
90
91
92
93
94
[GPLv2]
 
[...]
 
//
// Demonstrates structure of how to react to interrupts using OOSMOS.
//
 
typedef struct uartTag uart;
 
struct uartTag {...}
 
#define MAX_UARTS 5
 
static uart UartList[MAX_UARTS];
static unsigned UartCount = 0;
 
static void ReceiverStateMachine(...) {...}
static void ISR(...) {...}
extern uart * uartNew(unsigned UartId)
{
oosmos_AllocateVisible(pUART, uart, UartList, UartCount, MAX_UARTS, NULL);
 
pUART->m_UartId = (uint8_t) UartId;
 
oosmos_QueueConstruct(&pUART->m_ReceiveDataQueue, pUART->m_ReceiveDataQueueData);
oosmos_ActiveObjectInit(pUART, m_ActiveObject, ReceiverStateMachine);
 
return pUART;
}
 
extern int main(void)
extern int main(void) {...}
oosmos/Examples/Interrupt/Windows/Interrupt.c

oosmos_AnalogMapAccurate

Scales a value from a point within one range to the proportionate point in a different range. This function uses a floating point type to guarantee the most accurate result. If speed is more important than accuracy, use oosmos_AnalogMapFast.
See example on line 36, below.
1
2
3
 
double oosmos_AnalogMapAccurate(double Value, double InMin, double InMax, double OutMin, double OutMax);
 
Prototype
Value
The value to be scaled.
InMin
The low end of the source range.
InMax
The high end of the source range.
OutMin
The low end of the target range.
OutMax
The high end of the target range.
RETURN
Returns the scaled number as a floating point value.
See Also
1
22
23
33
34
35
36
37
38
39
40
41
42
43
44
[GPLv2]
 
[...]
 
static void TestAccurate(double Value, double InMin, double InMax, double OutMin, double OutMax)
{
const double Result = oosmos_AnalogMapAccurate(Value, InMin, InMax, OutMin, OutMax);
 
printf("Value:%f, InMin:%f, InMax:%f, OutMin:%f, OutMax:%f, Result:%f\n", Value, InMin, InMax, OutMin, OutMax, Result);
 
const long IntResult = (long) (Result + .5f);
AccurateDistribution[IntResult]++;
}
 
[...]
oosmos/Examples/AnalogMap/Windows/AnalogMap.c

oosmos_AnalogMapFast

Scales a value from a point within one range to the proportionate point in a different range. This function uses a long integral data type in order to calculate the result quickly. If accuracy is more important thqan speed, use oosmos_AnalogMapAccurate.
See example on line 46, below.
1
2
3
 
int32_t oosmos_AnalogMapFast(int32_t Value, int32_t InMin, int32_t InMax, int32_t OutMin, int32_t OutMax));
 
Prototype
Value
The value to be scaled.
InMin
The low end of the source range.
InMax
The high end of the source range.
OutMin
The low end of the target range.
OutMax
The high end of the target range.
RETURN
Returns the scaled number as a long integral value.
See Also
1
22
23
43
44
45
46
47
48
49
50
51
52
53
[GPLv2]
 
[...]
 
static void TestFast(int32_t Value, int32_t InMin, int32_t InMax, int32_t OutMin, int32_t OutMax)
{
const int32_t Result = oosmos_AnalogMapFast(Value, InMin, InMax, OutMin, OutMax);
printf("Value:%ld, InMin:%ld, InMax:%ld, OutMin:%ld, OutMax:%ld, Result:%ld\n",
(long) Value, (long) InMin, (long) InMax, (long) OutMin, (long) OutMax, (long) Result);
 
FastDistribution[Result]++;
}
 
[...]
oosmos/Examples/AnalogMap/Windows/AnalogMap.c

oosmos_ASSERT

oosmos_ASSERT works just like the standard C assert, but instead of aborting the program (which doesn't mean much on an embedded system), it will loop endlessly.
1
22
23
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
[GPLv2]
 
[...]
 
extern void regSamples(reg * pReg, const regSample * pSamples, uint32_t Samples)
{
const float MeanX = MeanOfX(pSamples, Samples);
const float MeanY = MeanOfY(pSamples, Samples);
 
float SumXY = 0.0f;
float SumXX = 0.0f;
 
for (uint32_t SampleIndex = 0; SampleIndex < Samples; SampleIndex++) {
const regSample * pSample = &pSamples[SampleIndex];
 
const float XiMinusMeanX = pSample->X - MeanX;
const float YiMinusMeanY = pSample->Y - MeanY;
 
SumXY += XiMinusMeanX * YiMinusMeanY;
SumXX += XiMinusMeanX * XiMinusMeanX;
}
 
oosmos_ASSERT(SumXX > 0.0f);
 
pReg->m_Slope = SumXY / SumXX;
pReg->m_Intercept = MeanY - pReg->m_Slope * MeanX;
}
 
[...]
oosmos/Classes/reg.c

oosmos_ClockSpeedInMHz

oosmos_ClockSpeedInMHz tells OOSMOS the speed of the processor as configured externally. This call only applies to the PIC32 architecture.
1
2
3
 
void oosmos_ClockSpeedInMHz(uint32_t ClockSpeedMHz);
 
Prototype

oosmos_COMPLETE

oosmos_COMPLETE is one of the six predefined event macros. This event is generated when the final states within all orthogonal regions have been entered. See The User's Guide for more information.
See Also

oosmos_CompositeInit

oosmos_CompositeInit initializes an oosmos_sComposite state.
See line 122 of the code snippet below for an example.
1
2
3
 
void oosmos_CompositeInit(pObject, CompositeState, ParentState, DefaultState, pCode);
 
Prototype
pObject
The address of the object that contains the state machine.
CompositeState
The name of the composite state.
ParentState
The name of the parent state.
DefaultState
The name of the default state.
pCode
Pointer to event handler function.
1
22
23
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
[GPLv2]
 
[...]
 
static test * testNew(void)
{
oosmos_Allocate(pTest, test, 1, NULL);
 
//>>>INIT
oosmos_StateMachineInitNoQueue(pTest, ROOT, NULL, A_State);
oosmos_CompositeInit(pTest, A_State, ROOT, A_Choice1_State, A_State_Code);
oosmos_LeafInit(pTest, A_Choice1_State, A_State, A_Choice1_State_Code);
oosmos_LeafInit(pTest, A_Left_State, A_State, A_Left_State_Code);
oosmos_LeafInit(pTest, A_Right_State, A_State, A_Right_State_Code);
oosmos_FinalInit(pTest, A_Final1_State, A_State, NULL);
oosmos_LeafInit(pTest, B_State, ROOT, NULL);
 
oosmos_Debug(pTest, NULL);
//<<<INIT
 
return pTest;
}
 
[...]
oosmos/Examples/Basic/Windows/Final.c

oosmos_Days2Hours

oosmos_Days2Hours is a macro that converts days to hours.
1
2
3
 
oosmos_Days2Hours(Days)
 
Macro
See Also
Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_Days2Minutes

oosmos_Days2Minutes is a macro that converts days to minutes.
1
2
3
 
oosmos_Days2Minutes(Days)
 
Macro
See Also
Days2Hours, Days2MS, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_Days2MS

oosmos_Days2MS is a macro that converts days to milliseconds.
1
2
3
 
oosmos_Days2MS(Days)
 
Macro
See Also
Days2Hours, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_Days2Seconds

oosmos_Days2Seconds is a macro that converts days to seconds.
1
2
3
 
oosmos_Days2Seconds(Days)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_Days2US

oosmos_Days2US is a macro that converts days to microseconds.
1
2
3
 
oosmos_Days2US(Days)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_Debug

A call to oosmos_Debug is generated by the OOSMOS code generator when the debug option is specified in your .json generator configuration file. oosmos_Debug enables debug output indicating when transitions are made into and out of states and when events occur. See line 168 in the code snippet below for an example.
1
2
3
 
oosmos_Debug(oosmos_sStateMachine * pStateMachine, const char * (*pNameTable)(int));
 
Prototype
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
Completion.c: ==> Ortho_State
Completion.c: ==> Ortho_Region2_Idle_State
Completion.c: ==> Ortho_Region1_Idle_State
Completion.c: EVENT: evA (1)
Completion.c: Ortho_Region1_Idle_State -->
Completion.c: --> Ortho_Region1_Moving_State
Completion.c: EVENT: evB (2)
Completion.c: Ortho_Region2_Idle_State -->
Completion.c: --> Ortho_Region2_Moving_State
Completion.c: EVENT: evStop (3)
Completion.c: Ortho_Region2_Moving_State -->
Completion.c: --> Ortho_Region2_Final2_State
Completion.c: Ortho_Region1_Moving_State -->
Completion.c: --> Ortho_Region1_Final1_State
Completion.c: ((( Ortho_State Complete )))
Completion.c: Ortho_Region2_Final2_State -->
Completion.c: Ortho_Region1_Final1_State -->
Completion.c: Ortho_State -->
Completion.c: --> Complete_State
 
--Goal State Achieved--
SUCCESS
 
Output from running Completion.exe
pStateMachine
The address of the object's state machine.
pNameTable
This argument specifies the address of a function that returns the string representation of an event code.
1
22
23
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
[GPLv2]
 
[...]
 
static test * testNew(void)
{
oosmos_Allocate(pTest, test, 1, NULL);
 
//>>>INIT
oosmos_StateMachineInit(pTest, ROOT, NULL, Ortho_State);
oosmos_OrthoInit(pTest, Ortho_State, ROOT, Ortho_State_Code);
oosmos_OrthoRegionInit(pTest, Ortho_Region1_State, Ortho_State, Ortho_Region1_Idle_State, NULL);
oosmos_LeafInit(pTest, Ortho_Region1_Moving_State, Ortho_Region1_State, Ortho_Region1_Moving_State_Code);
oosmos_LeafInit(pTest, Ortho_Region1_Idle_State, Ortho_Region1_State, Ortho_Region1_Idle_State_Code);
oosmos_FinalInit(pTest, Ortho_Region1_Final1_State, Ortho_Region1_State, NULL);
oosmos_OrthoRegionInit(pTest, Ortho_Region2_State, Ortho_State, Ortho_Region2_Idle_State, NULL);
oosmos_LeafInit(pTest, Ortho_Region2_Idle_State, Ortho_Region2_State, Ortho_Region2_Idle_State_Code);
oosmos_LeafInit(pTest, Ortho_Region2_Moving_State, Ortho_Region2_State, Ortho_Region2_Moving_State_Code);
oosmos_FinalInit(pTest, Ortho_Region2_Final2_State, Ortho_Region2_State, NULL);
oosmos_LeafInit(pTest, Complete_State, ROOT, Complete_State_Code);
 
oosmos_Debug(pTest, OOSMOS_EventNames);
//<<<INIT
 
return pTest;
}
 
[...]
oosmos/Examples/Ortho/Windows/Completion.c

oosmos_DebugPrint

oosmos_DebugPrint
1
22
23
88
89
90
91
92
93
94
95
96
97
98
99
100
101
[GPLv2]
 
[...]
 
static void ToggleOption1(control * pControl)
{
pControl->m_Option1 = !(pControl->m_Option1);
oosmos_DebugPrint("Option1: %d\n", pControl->m_Option1);
}
 
static void ToggleOption2(control * pControl)
{
pControl->m_Option2 = !(pControl->m_Option2);
oosmos_DebugPrint("Option2: %d\n", pControl->m_Option1);
}
 
[...]
oosmos/Examples/EventDemo/Windows/control.c

oosmos_DEFAULT

oosmos_DEFAULT is one of the six predefined event macros. This event is sent to the state once, before the state is entered, to allow the user the opportunity to execute initialization code. See line 61 in the code snippet below for an example.
See Also
1
22
23
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
[GPLv2]
 
[...]
static bool A_State_Code(void * pObject, oosmos_sState * pState, const oosmos_sEvent * pEvent)
{
test * pTest = (test *) pObject;
 
switch (oosmos_EventCode(pEvent)) {
case oosmos_DEFAULT: {
Default();
return true;
}
case oosmos_COMPLETE: {
return oosmos_Transition(pTest, pState, B_State);
}
}
 
return false;
}
[...]
oosmos/Examples/Basic/Windows/Final.c

oosmos_DelayMS

oosmos_DelayMS suspends all processing for a specified number of milliseconds. oosmos_DelayMS is a thread blocker, not an object blocker. If you want to suspend only the current object, use the oosmos_TimeoutInMS or oosmos_ThreadDelayMS (inside of a thread group) instead. See line 29 of the snippet below for an example.
1
2
3
 
void oosmos_DelayMS(uint32_t Milliseconds);
 
Prototype
See Also
1
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
[GPLv2]
 
#include <stdio.h>
#include "oosmos.h"
 
extern int main(void)
{
for (unsigned LoopCount = 1; LoopCount <= 5; LoopCount++) {
oosmos_DelayMS(500);
printf("Work...\n");
}
 
printf("SUCCESS\n");
 
return 0;
}
DelayMS.c

oosmos_DelaySeconds

oosmos_DelaySeconds suspends all processing for a specified number of seconds. See line 29 of the snippet below for an example.
oosmos_DelaySeconds is a thread blocker, not an object blocker. If you want to suspend only the current object, use the oosmos_TimeoutInSeconds or oosmos_ThreadDelayMS inside of a thread group instead.
1
2
3
 
void oosmos_DelaySeconds(uint32_t Seconds);
 
Prototype
See Also
1
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
[GPLv2]
 
#include <stdio.h>
#include "oosmos.h"
 
extern int main(void)
{
for (unsigned LoopCount = 1; LoopCount <= 5; LoopCount++) {
oosmos_DelaySeconds(1);
printf("Work...\n");
}
 
printf("SUCCESS\n");
 
return 0;
}
DelaySeconds.c

oosmos_DelayUS

oosmos_DelayUS suspends all processing for a specified number of microseconds. See line 29 of the snippet below for an example.
If you want to suspend only the current object, use the oosmos_TimeoutInUS instead.
Note that oosmos_DelayUS is not implemented on Windows.
1
2
3
 
void oosmos_DelayUS(uint32_t Microseconds);
 
Prototype
See Also
1
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
[GPLv2]
 
#include <stdio.h>
#include "oosmos.h"
 
extern int main(void)
{
for (unsigned LoopCount = 1; LoopCount <= 5; LoopCount++) {
oosmos_DelayUS(1000 * 1000);
printf("Work...\n");
}
 
printf("SUCCESS\n");
 
return 0;
}
DelayUS.c

oosmos_Divide_Integral_Rounded

oosmos_Divide_Integral_Rounded is a macro that is used internally by the time unit conversion APIs, but it is externalized for your use.
1
2
3
 
oosmos_Divide_Integral_Rounded(Dividend, Divisor)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_EndProgram

oosmos_EndProgram exits the program on platforms where that makes sense, like Windows and Linux. On other platforms, it is implemented as an endless loop, effectively stopping the program.

oosmos_ENTER

oosmos_ENTER is one of the six predefined event macros. This event is generated when the state is being entered. See line 53 in the code snippet below for an example.
See Also
1
22
23
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
[GPLv2]
 
[...]
 
//>>>CODE
static bool Off_State_Code(void * pObject, oosmos_sState * pState, const oosmos_sEvent * pEvent)
{
toggle * pToggle = (toggle *) pObject;
 
switch (oosmos_EventCode(pEvent)) {
case oosmos_ENTER: {
return oosmos_StateTimeoutMS(pState, (uint32_t) pToggle->m_TimeOffMS);
}
case oosmos_TIMEOUT: {
return oosmos_Transition(pToggle, pState, On_State);
}
}
 
return false;
}
 
[...]
oosmos/Classes/toggle_state.c (State machine version)

oosmos_EventCode

oosmos_EventCode is a macro that accesses the event code from within an OOSMOS event structure to improve readability of the generated code.
See line 52 for an example.
See Also
1
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
[...]
static bool Off_State_Code(void * pObject, oosmos_sState * pState, const oosmos_sEvent * pEvent)
{
toggle * pToggle = (toggle *) pObject;
 
switch (oosmos_EventCode(pEvent)) {
case oosmos_ENTER: {
return oosmos_StateTimeoutMS(pState, (uint32_t) pToggle->m_TimeOffMS);
}
case oosmos_TIMEOUT: {
return oosmos_Transition(pToggle, pState, On_State);
}
}
 
return false;
}
[...]
oosmos/Classes/toggle_state.c (State machine version)

oosmos_EXIT

oosmos_EXIT is one of the six predefined event macros. This event is generated when the state is being exited as part of a transition to another state. See line 73 in the code snippet below for an example.
See Also
1
22
23
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
[GPLv2]
 
[...]
 
static bool On_State_Code(void * pObject, oosmos_sState * pState, const oosmos_sEvent * pEvent)
{
toggle * pToggle = (toggle *) pObject;
 
switch (oosmos_EventCode(pEvent)) {
case oosmos_ENTER: {
pinOn(pToggle->m_pPin);
return oosmos_StateTimeoutMS(pState, (uint32_t) pToggle->m_TimeOnMS);
}
case oosmos_EXIT: {
pinOff(pToggle->m_pPin);
return true;
}
case oosmos_TIMEOUT: {
return oosmos_Transition(pToggle, pState, Off_State);
}
}
 
return false;
}
[...]
oosmos/Classes/toggle_state.c (State machine version)

oosmos_FinalInit

Initializes a Final state. See line 126 for an example.
1
2
3
 
void oosmos_FinalInit(pObject, StateName, Parent, pCode);
 
Prototype
pObject
Pointer to the object that holds the state machine.
StateName
State name of the Final element.
Parent
The name of this state's parent state.
pCode
Pointer to event handler function. NULL if there is no function to call.
1
22
23
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
[GPLv2]
 
[...]
 
static test * testNew(void)
{
oosmos_Allocate(pTest, test, 1, NULL);
 
//>>>INIT
oosmos_StateMachineInitNoQueue(pTest, ROOT, NULL, A_State);
oosmos_CompositeInit(pTest, A_State, ROOT, A_Choice1_State, A_State_Code);
oosmos_LeafInit(pTest, A_Choice1_State, A_State, A_Choice1_State_Code);
oosmos_LeafInit(pTest, A_Left_State, A_State, A_Left_State_Code);
oosmos_LeafInit(pTest, A_Right_State, A_State, A_Right_State_Code);
oosmos_FinalInit(pTest, A_Final1_State, A_State, NULL);
oosmos_LeafInit(pTest, B_State, ROOT, NULL);
 
oosmos_Debug(pTest, NULL);
//<<<INIT
 
return pTest;
}
 
[...]
oosmos/Examples/Basic/Windows/Final.c

oosmos_FOREVER

oosmos_FOREVER loops forever. Useful to stop a program once a problem has been programmatically identified.
See Also

oosmos_GetFreeRunningUS

oosmos_GetFreeRunningUS returns the number of microseconds since program start. Returning a uint32_t, the maximum number of microseconds that can be represented is 4,294,967,295, which is a little over 1 hour. Therefore, this value will wrap around to 0 about once an hour. The OOSMOS timeout capabilities handle the wrap around correctly, as does the accum class.
1
2
3
 
uint32_t oosmos_GetFreeRunningUS(void)
 
Prototype
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_Hours2Days_Rounded

oosmos_Hours2Days_Rounded is a macro that converts hours to days with the result being rounded for better precision. If speed is more important than accuracy, see the truncated version of this macro.
1
2
3
 
oosmos_Hours2Days_Rounded(Hours)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_Hours2Days_Truncated

oosmos_Hours2Days_Truncated is a macro that converts hours to days with the result being truncated due to default integral division behavior. If precision is important, see the rounded version of this macro.
1
2
3
 
oosmos_Hours2Days_Truncated(Hours)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_Hours2Minutes

oosmos_Hours2Minutes is a macro that converts hours to minutes.
1
2
3
 
oosmos_Hours2Minutes(Hours)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_Hours2MS

oosmos_Hours2MS is a macro that converts hours to milliseconds.
1
2
3
 
oosmos_Hours2MS(Hours)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_Hours2Seconds

oosmos_Hours2Seconds is a macro that converts hours to seconds.
1
2
3
 
oosmos_Hours2Seconds(Hours)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_Hours2US

oosmos_Hours2US is a macro that converts hours to microseconds.
1
2
3
 
oosmos_Hours2US(Hours)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_IsInState

oosmos_IsInState returns true if the object is in state pState or any of its substates, false otherwise. See line 142 of the code snippet below for an example.
1
2
3
 
bool oosmos_IsInState(const oosmos_sStateMachine * pStateMachine, const oosmos_sState * pState);
 
Prototype
pStateMachine
The address of the state machine within the object.
pState
The address of the state within the current object.
RETURN
Returns true if the object is in the state specified by pState or any of its subordinate states, false otherwise.
1
22
23
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
[GPLv2]
 
[...]
 
extern int main(void)
{
test * pTest = (test *) testNew();
 
for (;;) {
oosmos_RunStateMachines();
 
if (oosmos_IsInState(pTest, &pTest->B_State)) {
printf("SUCCESS.\n");
break;
}
 
oosmos_DelayMS(1);
}
}
oosmos/Examples/Basic/Windows/Final.c

oosmos_LeafInit

oosmos_LeafInit initializes an oosmos_sLeaf state.
See line 92 in the code snippet below for an example.
1
2
3
 
void oosmos_LeafInit(pObject, LeafState, ParentState, pCode);
 
Prototype
pObject
The address of the object that contains the state machine.
LeafState
The name of the leaf state.
ParentState
The name of the parent state.
pCode
The address of the event code function or NULL.
1
22
23
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
[GPLv2]
 
[...]
 
extern toggle * toggleNew(pin * pPin, uint32_t TimeOnMS, uint32_t TimeOffMS)
{
oosmos_Allocate(pToggle, toggle, toggleMAX, NULL);
 
//>>>INIT
oosmos_StateMachineInitNoQueue(pToggle, ROOT, NULL, On_State);
oosmos_LeafInit(pToggle, Off_State, ROOT, Off_State_Code);
oosmos_LeafInit(pToggle, On_State, ROOT, On_State_Code);
//<<<INIT
 
pToggle->m_pPin = pPin;
pToggle->m_TimeOnMS = TimeOnMS;
pToggle->m_TimeOffMS = TimeOffMS;
 
return pToggle;
}
oosmos/Classes/toggle_state.c

oosmos_Minutes2Days_Rounded

oosmos_Minutes2Days_Rounded is a macro that converts minutes to days with the result being rounded for better precision. If speed is more important than accuracy, see the truncated version of this macro.
1
2
3
 
oosmos_Minutes2Days_Rounded(Minutes)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_Minutes2Days_Truncated

oosmos_Minutes2Days_Truncated is a macro that converts minutes to days with the result being truncated due to default integral division behavior. If precision is important, see the rounded version of this macro.
1
2
3
 
oosmos_Minutes2Days_Truncated(Minutes)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_Minutes2Hours_Rounded

oosmos_Minutes2Hours_Rounded is a macro that converts minutes to hours with the result being rounded for better precision. If speed is more important than accuracy, see the truncated version of this macro.
1
2
3
 
oosmos_Minutes2Hours_Rounded(Minutes)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_Minutes2Hours_Truncated

oosmos_Minutes2Hours_Truncated is a macro that converts minutes to hours with the result being truncated due to default integral division behavior. If precision is important, see the rounded version of this macro.
1
2
3
 
oosmos_Minutes2Hours_Truncated(Minutes)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_Minutes2MS

oosmos_Minutes2MS is a macro that converts minutes to milliseconds.
1
2
3
 
oosmos_Minutes2MS(Minutes)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_Minutes2Seconds

oosmos_Minutes2Seconds is a macro that converts minutes to seconds.
1
2
3
 
oosmos_Minutes2Seconds(Minutes)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_Minutes2US

oosmos_Minutes2US is a macro that converts minutes to microseconds.
1
2
3
 
oosmos_Minutes2US(Minutes)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_MS2Days_Rounded

oosmos_MS2Days_Rounded is a macro that converts milliseconds to days with the result being rounded for better precision. If speed is more important than accuracy, see the truncated version of this macro.
1
2
3
 
oosmos_MS2Days_Rounded(Hours)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_MS2Days_Truncated

oosmos_MS2Days_Truncated is a macro that converts milliseconds to days with the result being truncated due to default integral division behavior. If precision is important, see the rounded version of this macro.
1
2
3
 
oosmos_MS2Days_Truncated(Hours)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_MS2Hours_Rounded

oosmos_MS2Hours_Rounded is a macro that converts milliseconds to hours with the result being rounded for better precision. If speed is more important than accuracy, see the truncated version of this macro.
1
2
3
 
oosmos_MS2Hours_Rounded(Hours)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_MS2Hours_Truncated

oosmos_MS2Hours_Truncated is a macro that converts milliseconds to hours with the result being truncated due to default integral division behavior. If precision is important, see the rounded version of this macro.
1
2
3
 
oosmos_MS2Hours_Truncated(Hours)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_MS2Minutes_Rounded

oosmos_MS2Minutes_Rounded is a macro that converts milliseconds to minutes with the result being rounded for better precision. If speed is more important than accuracy, see the truncated version of this macro.
1
2
3
 
oosmos_MS2Minutes_Rounded(Milliseconds)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_MS2Minutes_Truncated

oosmos_MS2Minutes_Truncated is a macro that converts milliseconds to minutes with the result being truncated due to default integral division behavior. If precision is important, see the rounded version of this macro.
1
2
3
 
oosmos_MS2Minutes_Truncated(Milliseconds)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_MS2Seconds_Rounded

oosmos_MS2Seconds_Rounded is a macro that converts milliseconds to seconds with the result being rounded for better precision. If speed is more important than accuracy, see the truncated version of this macro.
1
2
3
 
oosmos_MS2Seconds_Rounded(Milliseconds)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_MS2Seconds_Truncated

oosmos_MS2Seconds_Truncated is a macro that converts milliseconds to seconds with the result being truncated due to default integral division behavior. If precision is important, see the rounded version of this macro.
1
2
3
 
oosmos_MS2Seconds_Truncated(Milliseconds)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_MS2US

oosmos_MS2US is a macro that converts milliseconds to microseconds.
1
2
3
 
oosmos_MS2US(Milliseconds)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_ObjectThreadInit

Creates an Object Thread. See line 38 for an example of the declaration and line 65 for an example of its creation. See lines 45-59 for the thread itself.
1
2
3
 
void oosmos_ObjectThreadInit(pObject, pObjectThread, pFunc, bRunning);
 
Macro
pObject
Pointer to the object.
ObjectThread
The name of the object member of type oosmos_sObjectThread.
pFunc
The thread function.
bRunning
Indicates whether the thread should start right away. If false, then use oosmos_ObjectThreadStart() and oosmos_ObjectThreadStop() to start and stop the thread.
See Also
1
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
[GPLv2]
 
#ifndef toggleMAX
#define toggleMAX 5
#endif
 
//===================================
 
#include "oosmos.h"
#include "toggle.h"
#include "pin.h"
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
 
struct toggleTag
{
oosmos_sObjectThread m_ObjectThread;
 
pin * m_pPin;
uint32_t m_TimeOnMS;
uint32_t m_TimeOffMS;
};
 
static void ToggleThread(const toggle * pToggle, oosmos_sState * pState)
{
oosmos_POINTER_GUARD(pToggle);
oosmos_POINTER_GUARD(pState);
 
oosmos_ThreadBegin();
for (;;) {
pinOn(pToggle->m_pPin);
oosmos_ThreadDelayMS(pToggle->m_TimeOnMS);
 
pinOff(pToggle->m_pPin);
oosmos_ThreadDelayMS(pToggle->m_TimeOffMS);
}
oosmos_ThreadEnd();
}
 
extern toggle * toggleNew(pin * pPin, uint32_t TimeOnMS, uint32_t TimeOffMS)
{
oosmos_Allocate(pToggle, toggle, toggleMAX, NULL);
 
oosmos_ObjectThreadInit(pToggle, m_ObjectThread, ToggleThread, true);
 
pToggle->m_pPin = pPin;
pToggle->m_TimeOnMS = TimeOnMS;
pToggle->m_TimeOffMS = TimeOffMS;
 
return pToggle;
}
oosmos/Classes/toggle.c

oosmos_ObjectThreadStart

Starts a previously created Object Thread.
1
2
3
 
void oosmos_ObjectThreadStart(oosmos_ObjectThread * pObject);
 
Prototype
pObject
Pointer to the object.
See Also

oosmos_ObjectThreadStop

Stops an Object Thread. Use oosmos_ObjectThreadStart to restart it.
1
2
3
 
void oosmos_ObjectThreadStop(oosmos_ObjectThread * pObject);
 
Prototype
pObject
Pointer to the object.
See Also

oosmos_ORTHO

oosmos_ORTHO is a preprocessor macro that, when defined, compiles in all the OOSMOS orthogonal state machine features.
The default is #undef which will compile the smallest possible footprint. Of course if you use orthogonal states in any object in your build, you will have to #define it during compilation.
You can either define it on the compilation command line (usually -Doosmos_ORTHO), or add a #define oosmos_ORTHO at the top of both oosmos.h and oosmos.c.
See Also

oosmos_OrthoInit

oosmos_OrthoInit initializes an oosmos_sOrtho state.
See line 157 of the code snippet below for an example.
1
2
3
 
void oosmos_OrthoInit(pObject, OrthoState, ParentState, pCode)
 
Prototype
pObject
The address of the object that contains the state machine.
OrthoState
The name of the Ortho state.
ParentState
The name of the parent state.
pCode
The address of the event code function or NULL.
1
22
23
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
[GPLv2]
 
[...]
 
static test * testNew(void)
{
oosmos_Allocate(pTest, test, 1, NULL);
 
//>>>INIT
oosmos_StateMachineInit(pTest, ROOT, NULL, Ortho_State);
oosmos_OrthoInit(pTest, Ortho_State, ROOT, Ortho_State_Code);
oosmos_OrthoRegionInit(pTest, Ortho_Region1_State, Ortho_State, Ortho_Region1_Idle_State, NULL);
oosmos_LeafInit(pTest, Ortho_Region1_Moving_State, Ortho_Region1_State, Ortho_Region1_Moving_State_Code);
oosmos_LeafInit(pTest, Ortho_Region1_Idle_State, Ortho_Region1_State, Ortho_Region1_Idle_State_Code);
oosmos_FinalInit(pTest, Ortho_Region1_Final1_State, Ortho_Region1_State, NULL);
oosmos_OrthoRegionInit(pTest, Ortho_Region2_State, Ortho_State, Ortho_Region2_Idle_State, NULL);
oosmos_LeafInit(pTest, Ortho_Region2_Idle_State, Ortho_Region2_State, Ortho_Region2_Idle_State_Code);
oosmos_LeafInit(pTest, Ortho_Region2_Moving_State, Ortho_Region2_State, Ortho_Region2_Moving_State_Code);
oosmos_FinalInit(pTest, Ortho_Region2_Final2_State, Ortho_Region2_State, NULL);
oosmos_LeafInit(pTest, Complete_State, ROOT, Complete_State_Code);
 
oosmos_Debug(pTest, OOSMOS_EventNames);
//<<<INIT
 
return pTest;
}
 
[...]
oosmos/Examples/Ortho/Windows/Completion.c

oosmos_OrthoRegionInit

oosmos_OrthoRegionInit initializes an oosmos_sOrthoRegion state.
See line 100 of the code snippet below for an example.
1
2
3
 
void oosmos_OrthoRegionInit(pObject, LeafState, ParentState, DefaultState, pCode);
 
Prototype
pObject
The address of the object that contains state machine.
OrthoState
The name of the ortho state.
ParentState
The name of the parent state.
DefaultState
The name of the default state.
pCode
The address of the event code function or NULL.
1
22
23
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
[GPLv2]
 
[...]
 
static test * testNew(void)
{
oosmos_Allocate(pTest, test, 1, NULL);
 
//>>>INIT
oosmos_StateMachineInit(pTest, ROOT, NULL, Active_State);
oosmos_OrthoInit(pTest, Active_State, ROOT, Active_State_Code);
oosmos_OrthoRegionInit(pTest, Active_Region1_State, Active_State, Active_Region1_Moving_State, NULL);
oosmos_LeafInit(pTest, Active_Region1_Moving_State, Active_Region1_State, NULL);
oosmos_OrthoRegionInit(pTest, Active_Region2_State, Active_State, Active_Region2_Outer_State, NULL);
oosmos_CompositeInit(pTest, Active_Region2_Outer_State, Active_Region2_State, Active_Region2_Outer_Inner_State, NULL);
oosmos_LeafInit(pTest, Active_Region2_Outer_Inner_State, Active_Region2_Outer_State, NULL);
oosmos_OrthoRegionInit(pTest, Active_Region3_State, Active_State, Active_Region3_Leaf_State, NULL);
oosmos_LeafInit(pTest, Active_Region3_Leaf_State, Active_Region3_State, Active_Region3_Leaf_State_Code);
oosmos_LeafInit(pTest, Active_Region3_Running_State, Active_Region3_State, NULL);
 
oosmos_Debug(pTest, OOSMOS_EventNames);
//<<<INIT
 
return pTest;
}
 
[...]
oosmos/Examples/Ortho/Windows/EnterExit.c

oosmos_POINTER_GUARD

oosmos_POINTER_GUARD guarantees that the passed argument is not NULL. See line 47 in the code snippet below for an example.
See Also
1
22
23
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
[GPLv2]
 
[...]
};
 
static void ToggleThread(const toggle * pToggle, oosmos_sState * pState)
{
oosmos_POINTER_GUARD(pToggle);
oosmos_POINTER_GUARD(pState);
 
oosmos_ThreadBegin();
for (;;) {
pinOn(pToggle->m_pPin);
oosmos_ThreadDelayMS(pToggle->m_TimeOnMS);
 
pinOff(pToggle->m_pPin);
oosmos_ThreadDelayMS(pToggle->m_TimeOffMS);
}
oosmos_ThreadEnd();
}
[...]
oosmos/Classes/toggle.c (thread version)

oosmos_POLL

oosmos_POLL is one of the six predefined event macros. This event is generated each time the state machine is executed and this is the current active state. See line 150 in the code snippet below for an example.
See Also
1
22
23
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
[GPLv2]
 
[...]
 
static bool Ortho_State_Code(void * pObject, oosmos_sState * pState, const oosmos_sEvent * pEvent)
{
test * pTest = (test *) pObject;
 
switch (oosmos_EventCode(pEvent)) {
case oosmos_POLL: {
OrthoPoll(pTest);
if (CheckCounts(pTest)) {
return oosmos_Transition(pTest, pState, TestNullTransitionWithPoll_State);
}
return true;
}
}
 
return false;
}
 
[...]
oosmos/Tests/Poll.c (thread version)

oosmos_PushEvent

Allows you to push a complex event onto the object's event queue. Useful for pushing complex events. That is, events that hold more than just an event code.
1
2
3
 
oosmos_PushEvent(pObject, Event)
 
Macro
pObject
Pointer to the object pointer.
Event
Event object to push onto the object's event queue.
See Also
1
22
23
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
[GPLv2]
 
[...]
 
static void EventDriverThread(const test * pTest, oosmos_sState * pState)
{
static const sTestEvent TestEvent998 = { { evTestEvent, NULL }, 998 };
static const sTestEvent TestEvent999 = { { evTestEvent, NULL }, 999 };
 
oosmos_ThreadBegin();
printf("EventDriverThread: Enter\n");
oosmos_ThreadDelayMS(1000);
 
printf("EventDriverThread: Push 998\n");
oosmos_PushEvent(pTest, TestEvent998);
 
printf("EventDriverThread: Push 999\n");
oosmos_PushEvent(pTest, TestEvent999);
oosmos_ThreadEnd();
}
 
[...]
oosmos/Tests/ThreadEvents.c

oosmos_PushEventCode

oosmos_PushEventCode sends an event to an OOSMOS object. (It actually pushes the event to the object's event queue.) If the event is handled by the current state or any of its parent states, then the appropriate action is taken in that state. If the current active state (or its parents) do not handle the event, it will be popped from the queue and no action will take place.
See line 127 for an example.
1
2
3
 
bool oosmos_PushEventCode(void * pObject, int EventCode);
 
Prototype
pObject
Pointer to the object that will react to the event.
EventCode
The event code to send. Will always be an event defined inside the implementation's .c file.
RETURN
Always returns true.
1
22
23
122
123
124
125
126
127
128
[GPLv2]
 
[...]
oosmos_PushEventCode(pMotor, evStart);
}
 
extern void motorOff(const motor * pMotor)
{
oosmos_PushEventCode(pMotor, evStop);
}
oosmos/Examples/EventDemo/Windows/motor.c

oosmos_QueueConstruct

Constructs a queue of type oosmos_sQueue.
See lines 248 and 250 in the code snippet below for examples.
1
2
3
 
bool oosmos_QueueConstruct(oosmos_sQueue * pQueue, void * pQueueData);
 
Prototype
pQueue
Pointer to a oosmos_sQueue item that holds the meta data for the queue.
pQueueData
A pointer to an array that will hold the data for the queue.
oosmos_QueueConstruct is a macro that requires that the memory area be an array in order to properly calculate queue limits.
See Also
1
22
23
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
[GPLv2]
 
[...]
}
 
//
// 'UartModule' is 1, 2, etc.
//
extern uart * uartNew(const unsigned UartModule, const unsigned BaudRate)
{
oosmos_AllocateVisible(pUART, uart, UartList, UartCount, MaxUARTS, NULL);
 
pUART->m_UartModule = UartModule;
 
const unsigned PlibUartID = UartIndex_to_PlibUartId[UartModule-1];
pUART->m_PlibUartID = PlibUartID;
 
UARTConfigure(PlibUartID, UART_ENABLE_PINS_TX_RX_ONLY);
UARTSetFifoMode(PlibUartID, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
UARTSetLineControl(PlibUartID, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
UARTSetDataRate(PlibUartID, GetPeripheralClock(), BaudRate);
 
const unsigned Priority = 1;
INTSetVectorPriority(INT_VECTOR_UART(PlibUartID), GetPriorityBits(Priority));
INTSetVectorSubPriority(INT_VECTOR_UART(PlibUartID), INT_SUB_PRIORITY_LEVEL_0);
 
oosmos_QueueConstruct(&pUART->m_SendDataQueue, pUART->m_SendDataQueueData);
 
oosmos_QueueConstruct(&pUART->m_ReceiveDataQueue, pUART->m_ReceiveDataQueueData);
oosmos_SubscriberListInit(pUART->m_ReceivedByteEventSubscribers);
 
oosmos_ActiveObjectInit(pUART, m_ActiveObject, RunStateMachine);
 
return pUART;
}
[...]
oosmos/Classes/PIC32/uart.c

oosmos_QueuePop

If the queue is not empty, oosmos_QueuePop will pop an element off the queue and copy it into an item that you allocate.
See lines 123 and 138 in the code snippet below for examples.
1
2
3
 
bool oosmos_QueuePop(oosmos_sQueue * pQueue, void * pPoppedItem, size_t ElementSize);
 
Prototype
pQueue
Pointer to a oosmos_sQueue item that holds the meta data for the queue.
pPoppedItem
A pointer to an item of ElementSize size into which the queue item will be popped.
ElementSize
Size of one element of the queue.
RETURN
Returns true if an item was popped off the queue, false otherwise.
See Also
1
22
23
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
[GPLv2]
 
[...]
 
static void RunReceiverStateMachine(void * pObject)
{
uart * pUART = (uart *) pObject;
uint8_t Byte;
 
DisableInterrupt(pUART);
const bool PopSuccess = oosmos_QueuePop(&pUART->m_ReceiveDataQueue, &Byte, sizeof(Byte));
EnableInterrupt(pUART);
 
if (PopSuccess) {
uart_sReceivedByteEvent ReceivedByteEvent = { oosmos_EMPTY_EVENT, Byte };
oosmos_SubscriberListNotifyWithArgs(pUART->m_ReceivedByteEventSubscribers, ReceivedByteEvent);
}
}
 
static void RunSenderStateMachine(void * pObject)
{
uart * pUART = (uart *) pObject;
 
switch (pUART->m_SendState) {
case sendAwaitingCharToSend_State: {
const bool PopSuccess = oosmos_QueuePop(&pUART->m_SendDataQueue, &pUART->m_CharToSend, sizeof(pUART->m_CharToSend));
 
if (PopSuccess)
pUART->m_SendState = sendAwaitingReady_State;
 
break;
}
case sendAwaitingReady_State: {
if (UARTTransmitterIsReady(pUART->m_PlibUartID)) {
UARTSendDataByte(pUART->m_PlibUartID, pUART->m_CharToSend);
pUART->m_SendState = sendAwaitingComplete_State;
}
 
break;
}
case sendAwaitingComplete_State: {
if (UARTTransmissionHasCompleted(pUART->m_PlibUartID))
pUART->m_SendState = sendAwaitingCharToSend_State;
 
break;
}
}
}
 
[...]
oosmos/Classes/PIC32/uart.c

oosmos_QueuePush

Pushes a single item of size ElementSize onto the queue specified by pQueue.
If the queue is already full at the time of this call, the program will loop forever.
See lines 183 and 207 in the code snippet below for examples.
1
2
3
 
void oosmos_QueuePush(oosmos_sQueue * pQueue, const void * pItemToPush, size_t ElementSize);
 
Prototype
pQueue
Pointer to a oosmos_sQueue item that holds the meta data for the queue.
pItemToPush
A pointer to an item of ElementSize size that will be pushed (i.e. copied) onto the queue.
ElementSize
Size of one element of the queue.
See Also
1
22
23
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
203
204
205
206
207
208
209
[GPLv2]
 
[...]
 
static void ISR(const unsigned UartModule)
{
uart * pUART = UartList;
 
for (unsigned Count = 1; Count <= UartCount; pUART++, Count++) {
if (UartModule <= pUART->m_UartModule) {
break;
}
}
 
const unsigned PlibUartId = pUART->m_PlibUartID;
 
if (INTGetFlag(INT_SOURCE_UART_RX(PlibUartId))) {
while (UARTReceivedDataIsAvailable(PlibUartId)) {
const uint8_t Byte = UARTGetDataByte(PlibUartId);
oosmos_QueuePush(&pUART->m_ReceiveDataQueue, &Byte, sizeof(Byte));
}
 
INTClearFlag(INT_SOURCE_UART_RX(PlibUartId));
}
}
[...]
}
 
extern void uartSendChar(uart * pUART, const char Char)
{
oosmos_QueuePush(&pUART->m_SendDataQueue, &Char, sizeof(Char));
}
[...]
oosmos/Classes/PIC32/uart.c

oosmos_RunStateMachine

This API is experimental and may change. See example on line 222 in the code snippet.
1
2
3
 
void oosmos_RunStateMachine(oosmos_sStateMachine * pStateMachine);
 
Prototype
pStateMachine
Address of the state machine within the object.
See Also
1
22
23
218
219
220
221
222
223
224
225
[GPLv2]
 
[...]
 
static void QueueEvent(motion * pMotion, int EventCode)
{
oosmos_PushEventCode(pMotion, EventCode);
oosmos_RunStateMachine(pMotion);
}
 
[...]
oosmos/Examples/Ortho/Windows/Motion.c

oosmos_RunStateMachines

oosmos_RunStateMachines runs all OOSMOS state machine objects as well as all registered Active Objects (see oosmos_ActiveObjectInit.)
See line 42 in the code snippet below for an example.
1
2
3
 
void oosmos_RunStateMachines();
 
Prototype
See Also
1
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
[GPLv2]
 
#include "oosmos.h"
#include "pin.h"
#include "toggle.h"
 
static void SetupToggle(int Pin, int OnTimeMS, int OffTimeMS)
{
pin * pPin = pinNew(Pin, pinOut, pinActiveHigh);
toggleNew(pPin, OnTimeMS, OffTimeMS);
}
 
extern void setup()
{
SetupToggle(13, 50, 500);
SetupToggle(12, 2000, 2000);
SetupToggle(11, 50, 1500);
}
 
extern void loop()
{
oosmos_RunStateMachines();
}
oosmos/Examples/Blink/Arduino/BlinkExample/BlinkExample.ino

oosmos_sActiveObject

See oosmos_ActiveObjectInit.

oosmos_sComposite

oosmos_sComposite declares a composite state in an OOSMOS state machine object.
See line 36 in the code snippet below for an example.
1
22
23
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
[GPLv2]
 
[...]
 
struct testTag
{
//>>>DECL
oosmos_sStateMachineNoQueue(ROOT);
oosmos_sComposite A_State;
oosmos_sLeaf A_Choice1_State;
oosmos_sLeaf A_Left_State;
oosmos_sLeaf A_Right_State;
oosmos_sFinal A_Final1_State;
oosmos_sLeaf B_State;
//<<<DECL
};
 
[...]
oosmos/Examples/Basic/Windows/Final.c

oosmos_Seconds2Days_Rounded

oosmos_Seconds2Days_Rounded is a macro that converts seconds to days with the result being rounded for better precision. If speed is more important than accuracy, see the truncated version of this macro.
1
2
3
 
oosmos_Seconds2Days_Rounded(Seconds)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_Seconds2Days_Truncated

oosmos_Seconds2Days_Truncated is a macro that converts seconds to days with the result being truncated due to default integral division behavior. If precision is important, see the rounded version of this macro.
1
2
3
 
oosmos_Seconds2Days_Truncated(Seconds)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_Seconds2Hours_Rounded

oosmos_Seconds2Hours_Rounded is a macro that converts seconds to hours with the result being rounded for better precision. If speed is more important than accuracy, see the truncated version of this macro.
1
2
3
 
oosmos_Seconds2Hours_Rounded(Seconds)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_Seconds2Hours_Truncated

oosmos_Seconds2Hours_Truncated is a macro that converts seconds to hours with the result being truncated due to default integral division behavior. If precision is important, see the rounded version of this macro.
1
2
3
 
oosmos_Seconds2Hours_Truncated(Seconds)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_Seconds2Minutes_Rounded

oosmos_Seconds2Minutes_Rounded is a macro that converts seconds to minutes with the result being rounded for better precision. If speed is more important than accuracy, see the truncated version of this macro.
1
2
3
 
oosmos_Seconds2Minutes_Rounded(Seconds)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_Seconds2Minutes_Truncated

oosmos_Seconds2Minutes_Truncated is a macro that converts seconds to minutes with the result being truncated due to default integral division behavior. If precision is important, see the rounded version of this macro.
1
2
3
 
oosmos_Seconds2Minutes_Truncated(Seconds)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_Seconds2MS

oosmos_Seconds2MS is a macro that converts seconds to milliseconds.
1
2
3
 
oosmos_Seconds2MS(Seconds)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_Seconds2US

oosmos_Seconds2US is a macro that converts seconds to microseconds.
1
2
3
 
oosmos_Seconds2US(Seconds)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_sEvent

oosmos_sEvent is the principle event structure. It holds an event code called Code and a context pointer called pContext.
See line 47 for an example of use.
1
2
3
4
5
6
7
 
typedef struct
{
int m_Code;
void * m_pContext;
} oosmos_sEvent;
 
oosmos_sEvent Data Type
Code
Member m_Code holds the event code to be delivered.
pContext
Member m_pContext is a user-defined pointer to help the notified entity determine the context of the action.
See Also
1
22
23
27
28
29
44
45
46
47
48
49
50
51
52
53
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
103
104
105
106
107
108
109
110
115
116
117
118
119
120
[GPLv2]
 
[...]
 
//>>>EVENTS
[Code Generated by OOSMOS]
//<<<EVENTS
 
typedef union {
oosmos_sEvent Event;
} uEvents;
 
struct motorTag
{
//>>>DECL
[Code Generated by OOSMOS]
//<<<DECL
};
 
#ifndef motorMAX
#define motorMAX 3
#endif
 
static void MovingThread(oosmos_sState * pState)
{
oosmos_ThreadBegin();
for (;;) {
printf("motor: MOVING...\n");
oosmos_ThreadDelayMS(500);
}
oosmos_ThreadEnd();
}
 
//>>>CODE
[Code Generated by OOSMOS]
//<<<CODE
 
extern motor * motorNew(void)
{
oosmos_Allocate(pMotor, motor, motorMAX, NULL);
 
//>>>INIT
[Code Generated by OOSMOS]
//<<<INIT
 
return pMotor;
}
 
[...]
oosmos/Examples/EventDemo/Windows/motor.c

oosmos_sFinal

oosmos_sFinal declares a final state in your OOSMOS state machine object.
See line 40 in the code snippet for an example.
1
22
23
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
[GPLv2]
 
[...]
 
struct testTag
{
//>>>DECL
oosmos_sStateMachineNoQueue(ROOT);
oosmos_sComposite A_State;
oosmos_sLeaf A_Choice1_State;
oosmos_sLeaf A_Left_State;
oosmos_sLeaf A_Right_State;
oosmos_sFinal A_Final1_State;
oosmos_sLeaf B_State;
//<<<DECL
};
 
[...]
oosmos/Examples/Basic/Windows/Final.c

oosmos_sLeaf

oosmos_sLeaf declares a leaf state in an OOSMOS state machine object.
See line 38 in the code snippet below for an example.
1
22
23
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
[GPLv2]
 
[...]
 
struct toggleTag
{
//>>>DECL
oosmos_sStateMachineNoQueue(ROOT);
oosmos_sLeaf Off_State;
oosmos_sLeaf On_State;
//<<<DECL
 
pin * m_pPin;
uint32_t m_TimeOnMS;
uint32_t m_TimeOffMS;
};
 
[...]
oosmos/Classes/toggle_state.c

oosmos_sObjectThread

Type that declares an Object Thread inside an OOSMOS object. See line 38 for an example of the declaration and line 65 for an example of its creation. See lines 45-59 for the thread itself.
See Also
1
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
[GPLv2]
 
#ifndef toggleMAX
#define toggleMAX 5
#endif
 
//===================================
 
#include "oosmos.h"
#include "toggle.h"
#include "pin.h"
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
 
struct toggleTag
{
oosmos_sObjectThread m_ObjectThread;
 
pin * m_pPin;
uint32_t m_TimeOnMS;
uint32_t m_TimeOffMS;
};
 
static void ToggleThread(const toggle * pToggle, oosmos_sState * pState)
{
oosmos_POINTER_GUARD(pToggle);
oosmos_POINTER_GUARD(pState);
 
oosmos_ThreadBegin();
for (;;) {
pinOn(pToggle->m_pPin);
oosmos_ThreadDelayMS(pToggle->m_TimeOnMS);
 
pinOff(pToggle->m_pPin);
oosmos_ThreadDelayMS(pToggle->m_TimeOffMS);
}
oosmos_ThreadEnd();
}
 
extern toggle * toggleNew(pin * pPin, uint32_t TimeOnMS, uint32_t TimeOffMS)
{
oosmos_Allocate(pToggle, toggle, toggleMAX, NULL);
 
oosmos_ObjectThreadInit(pToggle, m_ObjectThread, ToggleThread, true);
 
pToggle->m_pPin = pPin;
pToggle->m_TimeOnMS = TimeOnMS;
pToggle->m_TimeOffMS = TimeOffMS;
 
return pToggle;
}
oosmos/Classes/toggle.c

oosmos_sOrtho

Declares an orthogonal state in your OOSMOS state machine object.
See line 53 in the code snippet below for an example.
1
22
23
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
[GPLv2]
 
[...]
 
struct testTag
{
//>>>DECL
oosmos_sStateMachine(ROOT, uEvents, 3);
oosmos_sOrtho Active_State;
oosmos_sOrthoRegion Active_Region1_State;
oosmos_sLeaf Active_Region1_Moving_State;
oosmos_sOrthoRegion Active_Region2_State;
oosmos_sComposite Active_Region2_Outer_State;
oosmos_sLeaf Active_Region2_Outer_Inner_State;
oosmos_sOrthoRegion Active_Region3_State;
oosmos_sLeaf Active_Region3_Leaf_State;
oosmos_sLeaf Active_Region3_Running_State;
//<<<DECL
};
 
[...]
oosmos/Examples/Ortho/Windows/EnterExit.c

oosmos_sOrthoRegion

oosmos_sOrthoRegion declares an orthogonal region state in your OOSMOS state machine object.
See line 54 in the code snippet below for an example.
1
22
23
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
[GPLv2]
 
[...]
oosmos_sEvent Base;
} uEvents;
 
struct testTag
{
//>>>DECL
oosmos_sStateMachine(ROOT, uEvents, 3);
oosmos_sOrtho Active_State;
oosmos_sOrthoRegion Active_Region1_State;
oosmos_sLeaf Active_Region1_Moving_State;
oosmos_sOrthoRegion Active_Region2_State;
oosmos_sComposite Active_Region2_Outer_State;
oosmos_sLeaf Active_Region2_Outer_Inner_State;
oosmos_sOrthoRegion Active_Region3_State;
oosmos_sLeaf Active_Region3_Leaf_State;
oosmos_sLeaf Active_Region3_Running_State;
//<<<DECL
[...]
oosmos/Examples/Ortho/Windows/EnterExit.c

oosmos_sQueue

OOSMOS has a generalized queue mechanism that serves two purposes:
  1. To hold events. A state machine object can have a queue onto which events are queued to be handled by the current state. If the event is not handled by the current state or any of its parent states, the event is thrown away.
  2. To hold work. An object then periodically checks the queue for work to be done. In this way, the queue mechanism supports a server model.
Study the uart example below. Note that there is no state machine in this object. There are, however, two work queues. One that stores data received from the UART that is pushed onto the queue in an interrupt service routine (ISR). See line 46. The other stores data to be sent. See line 41.
1
22
23
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
[GPLv2]
 
[...]
 
struct uartTag
{
oosmos_sActiveObject m_ActiveObject;
 
oosmos_sQueue m_SendDataQueue;
uint8_t m_SendDataQueueData[200];
eSendStates m_SendState;
uint8_t m_CharToSend;
 
oosmos_sQueue m_ReceiveDataQueue;
uint8_t m_ReceiveDataQueueData[10];
oosmos_sSubscriberList m_ReceivedByteEventSubscribers[1];
 
uint8_t m_PlibUartID;
uint8_t m_UartModule;
};
 
[...]
oosmos/Classes/PIC32/uart.c

oosmos_sState

oosmos_sState is a data type that holds state meta data and is never used directly - only contained by other OOSMOS state types.

oosmos_sStateMachine

oosmos_sStateMachine declares the state machine in your OOSMOS object. It also preallocates the object's event queue.
See line 52 in the code snippet below for an example.
1
2
3
 
oosmos_sStateMachine(ROOT, EventType, MaxEvents);
 
Prototype
StateMachine
The name of the state machine. Conventionally, should always be StateMachine.
EventType
Datatype of elements queued to the event queue. Can be a union of other types.
MaxEvents
The maximum number of elements that the event queue can hold.
See Also
1
22
23
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
[GPLv2]
 
[...]
 
struct testTag
{
//>>>DECL
oosmos_sStateMachine(ROOT, uEvents, 3);
oosmos_sOrtho Active_State;
oosmos_sOrthoRegion Active_Region1_State;
oosmos_sLeaf Active_Region1_Moving_State;
oosmos_sOrthoRegion Active_Region2_State;
oosmos_sComposite Active_Region2_Outer_State;
oosmos_sLeaf Active_Region2_Outer_Inner_State;
oosmos_sOrthoRegion Active_Region3_State;
oosmos_sLeaf Active_Region3_Leaf_State;
oosmos_sLeaf Active_Region3_Running_State;
//<<<DECL
};
 
[...]
oosmos/Examples/Ortho/Windows/EnterExit.c

oosmos_sStateMachineNoQueue

oosmos_sStateMachineNoQueue declares the state machine in your OOSMOS object. Use this form when your object will not accept events.
See line 37 in the code snippet below for an example.
1
2
3
 
oosmos_sStateMachineNoQueue(ROOT);
 
Prototype
StateMachine
The name of the state machine. Conventionally, should always be StateMachine.
See Also
1
22
23
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
[GPLv2]
 
[...]
 
struct toggleTag
{
//>>>DECL
oosmos_sStateMachineNoQueue(ROOT);
oosmos_sLeaf Off_State;
oosmos_sLeaf On_State;
//<<<DECL
 
pin * m_pPin;
uint32_t m_TimeOnMS;
uint32_t m_TimeOffMS;
};
 
[...]
oosmos/Classes/toggle_state.c

oosmos_sSubscriberList

oosmos_SubscriberList is a data type that holds a list of subscribers interested in the occurrence of a particular event.
See lines  55 and 56 of the code snippet below for examples.
See Also
1
22
23
48
49
50
51
52
53
54
55
56
57
58
59
[GPLv2]
 
[...]
 
struct swTag
{
pin * m_pPin;
eStates m_State;
 
oosmos_sActiveObject m_ActiveObject;
oosmos_sSubscriberList m_CloseEvent[swMaxCloseSubscribers];
oosmos_sSubscriberList m_OpenEvent[swMaxOpenSubscribers];
};
 
[...]
oosmos/Classes/sw.c

oosmos_StateMachineInit

oosmos_StateMachineInit initializes an oosmos_sStateMachine object member.
See line 110 of the code snippet below for an example.
1
2
3
 
oosmos_StateMachineInit(pObject, StateMachine, ParentState, DefaultState);
 
Prototype
pObject
The address of the object that contains state machine.
StateMachine
The name of the state machine.
ParentState
The name of the parent state. Must always be NULL. This argument exists for overall state machine initialization readability.
DefaultState
The name of the default state.
See Also
1
22
23
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
[GPLv2]
 
[...]
 
extern motor * motorNew(void)
{
oosmos_Allocate(pMotor, motor, motorMAX, NULL);
 
//>>>INIT
oosmos_StateMachineInit(pMotor, ROOT, NULL, Idle_State);
oosmos_LeafInit(pMotor, Idle_State, ROOT, Idle_State_Code);
oosmos_LeafInit(pMotor, Moving_State, ROOT, Moving_State_Code);
 
oosmos_Debug(pMotor, OOSMOS_EventNames);
//<<<INIT
 
return pMotor;
}
 
[...]
oosmos/Examples/EventDemo/Windows/motor.c

oosmos_StateMachineInitNoQueue

oosmos_StateMachineInitNoQueue initializes an oosmos_sStateMachineNoQueue object member.
See line 91 of the code snippet below for an example.
1
2
3
 
oosmos_StateMachineInitNoQueue(pObject, StateMachine, ParentState, DefaultState);
 
Prototype
pObject
The address of the object that contains state machine.
StateMachine
The name of the state machine.
ParentState
The name of the parent state. Must always be NULL. This argument exists for overall state machine initialization readability.
DefaultState
The name of the default state.
See Also
1
22
23
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
[GPLv2]
 
[...]
 
extern toggle * toggleNew(pin * pPin, uint32_t TimeOnMS, uint32_t TimeOffMS)
{
oosmos_Allocate(pToggle, toggle, toggleMAX, NULL);
 
//>>>INIT
oosmos_StateMachineInitNoQueue(pToggle, ROOT, NULL, On_State);
oosmos_LeafInit(pToggle, Off_State, ROOT, Off_State_Code);
oosmos_LeafInit(pToggle, On_State, ROOT, On_State_Code);
//<<<INIT
 
pToggle->m_pPin = pPin;
pToggle->m_TimeOnMS = TimeOnMS;
pToggle->m_TimeOffMS = TimeOffMS;
 
return pToggle;
}
oosmos/Classes/toggle_state.c

oosmos_StateTimeoutMS

oosmos_StateTimeoutMS is used to set a state's timeout value. If another event or condition does not transition you out of the current state before the number of milliseconds in your timeout value, then an oosmos_TIMEOUT event will be delivered to the current state's event handler.
You will typically set your state's timeout value upon entry to the state in the oosmos_ENTER event action.
See StateTimeout.c, below, line 52 for an example of setting the timeout and line 54 for an example of an oosmos_TIMEOUT event handler.
1
2
3
 
bool oosmos_StateTimeoutMS(oosmos_sState * pState, uint32_t Milliseconds)
 
Prototype
pState
The same pState argument that was passed into the containing state handler.
Milliseconds
The timeout value in milliseconds.
RETURN
Always returns true.
See Also
1
22
23
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
[GPLv2]
 
[...]
 
//>>>CODE
static bool MS_State_Code(void * pObject, oosmos_sState * pState, const oosmos_sEvent * pEvent)
{
test * pTest = (test *) pObject;
 
switch (oosmos_EventCode(pEvent)) {
case oosmos_ENTER: {
return oosmos_StateTimeoutMS(pState, (uint32_t) pTest->m_TimeMS);
}
case oosmos_TIMEOUT: {
return oosmos_Transition(pTest, pState, Seconds_State);
}
}
 
return false;
}
 
[...]
oosmos/Examples/Basic/Windows/StateTimeout.c

oosmos_StateTimeoutSeconds

oosmos_StateTimeoutSeconds is used to set a state's timeout value. If another event or condition does not transition you out of the current state before the number of seconds in your timeout value, then an oosmos_TIMEOUT event will be delivered to the current state's event handler.
You will typically set your state's timeout value upon entry to the state in the oosmos_ENTER event action.
See StateTimeout.c, below, line 68 for an example of setting the timeout and line 70 for an example of an oosmos_TIMEOUT event handler.
1
2
3
 
bool oosmos_StateTimeoutSeconds(oosmos_sState * pState, uint32_t Seconds)
 
Prototype
pState
The same pState argument that was passed into the containing state handler.
Seconds
The timeout value in seconds.
RETURN
Always returns true.
See Also
1
22
23
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
[GPLv2]
 
[...]
 
static bool Seconds_State_Code(void * pObject, oosmos_sState * pState, const oosmos_sEvent * pEvent)
{
test * pTest = (test *) pObject;
 
switch (oosmos_EventCode(pEvent)) {
case oosmos_ENTER: {
return oosmos_StateTimeoutSeconds(pState, (uint32_t) 1);
}
case oosmos_TIMEOUT: {
return oosmos_Transition(pTest, pState, US_State);
}
}
 
return false;
}
 
[...]
oosmos/Examples/Basic/Windows/StateTimeout.c

oosmos_StateTimeoutUS

oosmos_StateTimeoutUS is used to set a state's timeout value. If another event or condition does not transition you out of the current state before the number of microseconds in your timeout value, then an oosmos_TIMEOUT event will be delivered to the current state's event handler.
You will typically set your state's timeout value upon entry to the state in the oosmos_ENTER event action.
See StateTimeout.c, below, line 84 for an example of setting the timeout and line 86 for an example of an oosmos_TIMEOUT event handler.
1
2
3
 
oosmos_StateTimeoutUS(oosmos_sState * pState, uint32_t Microseconds)
 
Prototype
pState
The same pState argument that was passed into the containing state handler.
Microseconds
The timeout value in microseconds.
RETURN
Always returns true.
See Also
1
22
23
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
[GPLv2]
 
[...]
 
static bool US_State_Code(void * pObject, oosmos_sState * pState, const oosmos_sEvent * pEvent)
{
test * pTest = (test *) pObject;
 
switch (oosmos_EventCode(pEvent)) {
case oosmos_ENTER: {
return oosmos_StateTimeoutUS(pState, (uint32_t) 100000);
}
case oosmos_TIMEOUT: {
return oosmos_Transition(pTest, pState, Done_State);
}
}
 
return false;
}
[...]
oosmos/Examples/Basic/Windows/StateTimeout.c

oosmos_sTimeout

oosmos_sTimeout is a data type that holds timeout meta data supporting the oosmos_TimeoutInSeconds call. See line 34, line 39 and line 47 in the snippet for an example of use.
1
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
[GPLv2]
 
#include "oosmos.h"
#include <stdio.h>
#include <stdint.h>
 
static const uint32_t WaitTimeSeconds = 2;
 
extern int main(void)
{
//
// Allocate a Timeout object.
//
oosmos_sTimeout Timeout;
 
//
// Set timeout.
//
oosmos_TimeoutInSeconds(&Timeout, WaitTimeSeconds);
 
printf("Waiting for %lu seconds...\n", (unsigned long) WaitTimeSeconds);
 
for (;;) {
//
// Check if the time has expired.
//
if (oosmos_TimeoutHasExpired(&Timeout)) {
break;
}
 
//
// Be polite. Prevent 100% CPU usage on multi-tasked
// machines (e.g. Windows or Linux).
//
oosmos_DelayMS(1);
}
 
printf("SUCCESS\n");
 
return 0;
}
oosmos/Examples/Basic/Windows/TimeoutInSeconds.c

oosmos_SubscriberListAdd

Publishers notify subscribers of events that occur within the publisher's object.
oosmos_SubscriberListAdd is called within the publisher's implementation file to add a subscriber to the list of subscribers interested in the occurrence of a particular event.
See lines 55 and 68, 84 and 128 in the code snippet below for an example.
1
2
3
4
5
6
 
void oosmos_SubscriberListAdd(oosmos_sSubscriberList * pSubscriberList,
oosmos_sQueue * pNotifyQueue,
int EventCode,
void * pContext);
 
Prototype
pSubscriberList
Pointer to a oosmos_sSubscriberList member inside an OOSMOS object.
pNotifyQueue
Points to the queue of the subscriber onto which published events will be pushed.
EventCode
When the associated event occurs within a publisher, the publisher should post this event code to the subscriber's event queue.
Note that the event code is defined within the subscriber's object, not the publisher's.
pContext
A pointer to some type of context information that a notified subscriber can use in any way. Can be NULL.
See Also
1
22
23
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
79
80
81
82
83
84
85
86
87
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
[GPLv2]
 
[...]
 
struct swTag
{
pin * m_pPin;
eStates m_State;
 
oosmos_sActiveObject m_ActiveObject;
oosmos_sSubscriberList m_CloseEvent[swMaxCloseSubscribers];
oosmos_sSubscriberList m_OpenEvent[swMaxOpenSubscribers];
};
 
extern sw * swNewDetached(pin * pPin)
{
oosmos_Allocate(pSwitch, sw, swMaxSwitches, NULL);
 
pSwitch->m_pPin = pPin;
pSwitch->m_State = Unknown_State;
 
oosmos_ActiveObjectInit(pSwitch, m_ActiveObject, swRunStateMachine);
 
oosmos_SubscriberListInit(pSwitch->m_CloseEvent);
oosmos_SubscriberListInit(pSwitch->m_OpenEvent);
 
return pSwitch;
}
 
[...]
 
extern void swSubscribeCloseEvent(sw * pSwitch, oosmos_sQueue * pQueue, int CloseEventCode, void * pContext)
{
oosmos_POINTER_GUARD(pSwitch);
 
oosmos_SubscriberListAdd(pSwitch->m_CloseEvent, pQueue, CloseEventCode, pContext);
}
 
[...]
 
extern void swRunStateMachine(void * pObject)
{
oosmos_POINTER_GUARD(pObject);
 
sw * pSwitch = (sw *) pObject;
 
switch (pSwitch->m_State) {
case Open_State: {
if (pinIsOn(pSwitch->m_pPin)) {
pSwitch->m_State = Closed_State;
oosmos_SubscriberListNotify(pSwitch->m_CloseEvent);
}
 
break;
}
case Closed_State: {
if (pinIsOff(pSwitch->m_pPin)) {
pSwitch->m_State = Open_State;
oosmos_SubscriberListNotify(pSwitch->m_OpenEvent);
}
 
break;
}
case Unknown_State: {
pSwitch->m_State = pinIsOn(pSwitch->m_pPin) ? Closed_State : Open_State;
break;
}
}
}
oosmos/Classes/sw.c

oosmos_SubscriberListInit

oosmos_SubscriberListInit initializes a subscriber list. Subscriber lists are stored within the publisher's object.
See lines 55 and 68, 84 and 128 in the code snippet below for an example.
1
2
3
 
void oosmos_SubscriberListInit(oosmos_sSubscriberList * pSubscriberList);
 
Prototype
pSubscriberList
Pointer to a oosmos_sSubscriberList member inside an OOSMOS object.
See Also
1
22
23
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
79
80
81
82
83
84
85
86
87
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
[GPLv2]
 
[...]
 
struct swTag
{
pin * m_pPin;
eStates m_State;
 
oosmos_sActiveObject m_ActiveObject;
oosmos_sSubscriberList m_CloseEvent[swMaxCloseSubscribers];
oosmos_sSubscriberList m_OpenEvent[swMaxOpenSubscribers];
};
 
extern sw * swNewDetached(pin * pPin)
{
oosmos_Allocate(pSwitch, sw, swMaxSwitches, NULL);
 
pSwitch->m_pPin = pPin;
pSwitch->m_State = Unknown_State;
 
oosmos_ActiveObjectInit(pSwitch, m_ActiveObject, swRunStateMachine);
 
oosmos_SubscriberListInit(pSwitch->m_CloseEvent);
oosmos_SubscriberListInit(pSwitch->m_OpenEvent);
 
return pSwitch;
}
 
[...]
 
extern void swSubscribeCloseEvent(sw * pSwitch, oosmos_sQueue * pQueue, int CloseEventCode, void * pContext)
{
oosmos_POINTER_GUARD(pSwitch);
 
oosmos_SubscriberListAdd(pSwitch->m_CloseEvent, pQueue, CloseEventCode, pContext);
}
 
[...]
 
extern void swRunStateMachine(void * pObject)
{
oosmos_POINTER_GUARD(pObject);
 
sw * pSwitch = (sw *) pObject;
 
switch (pSwitch->m_State) {
case Open_State: {
if (pinIsOn(pSwitch->m_pPin)) {
pSwitch->m_State = Closed_State;
oosmos_SubscriberListNotify(pSwitch->m_CloseEvent);
}
 
break;
}
case Closed_State: {
if (pinIsOff(pSwitch->m_pPin)) {
pSwitch->m_State = Open_State;
oosmos_SubscriberListNotify(pSwitch->m_OpenEvent);
}
 
break;
}
case Unknown_State: {
pSwitch->m_State = pinIsOn(pSwitch->m_pPin) ? Closed_State : Open_State;
break;
}
}
}
oosmos/Classes/sw.c

oosmos_SubscriberListNotify

Called by a publisher, oosmos_SubscriberListNotify notifies all subscribers of the occurrence of an event.
See lines 55 and 68, 84 and 128 in the code snippet below for an example.
1
2
3
 
void oosmos_SubscriberListNotify(oosmos_sSubscriberList * pSubscriberList);
 
Prototype
pSubscriberList
Pointer to a oosmos_sSubscriberList member inside an OOSMOS object.
See Also
1
22
23
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
79
80
81
82
83
84
85
86
87
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
[GPLv2]
 
[...]
 
struct swTag
{
pin * m_pPin;
eStates m_State;
 
oosmos_sActiveObject m_ActiveObject;
oosmos_sSubscriberList m_CloseEvent[swMaxCloseSubscribers];
oosmos_sSubscriberList m_OpenEvent[swMaxOpenSubscribers];
};
 
extern sw * swNewDetached(pin * pPin)
{
oosmos_Allocate(pSwitch, sw, swMaxSwitches, NULL);
 
pSwitch->m_pPin = pPin;
pSwitch->m_State = Unknown_State;
 
oosmos_ActiveObjectInit(pSwitch, m_ActiveObject, swRunStateMachine);
 
oosmos_SubscriberListInit(pSwitch->m_CloseEvent);
oosmos_SubscriberListInit(pSwitch->m_OpenEvent);
 
return pSwitch;
}
 
[...]
 
extern void swSubscribeCloseEvent(sw * pSwitch, oosmos_sQueue * pQueue, int CloseEventCode, void * pContext)
{
oosmos_POINTER_GUARD(pSwitch);
 
oosmos_SubscriberListAdd(pSwitch->m_CloseEvent, pQueue, CloseEventCode, pContext);
}
 
[...]
 
extern void swRunStateMachine(void * pObject)
{
oosmos_POINTER_GUARD(pObject);
 
sw * pSwitch = (sw *) pObject;
 
switch (pSwitch->m_State) {
case Open_State: {
if (pinIsOn(pSwitch->m_pPin)) {
pSwitch->m_State = Closed_State;
oosmos_SubscriberListNotify(pSwitch->m_CloseEvent);
}
 
break;
}
case Closed_State: {
if (pinIsOff(pSwitch->m_pPin)) {
pSwitch->m_State = Open_State;
oosmos_SubscriberListNotify(pSwitch->m_OpenEvent);
}
 
break;
}
case Unknown_State: {
pSwitch->m_State = pinIsOn(pSwitch->m_pPin) ? Closed_State : Open_State;
break;
}
}
}
oosmos/Classes/sw.c

oosmos_SubscriberListNotifyWithArgs

Called by a publisher, oosmos_SubscriberListNotifyWithArgs notifies all subscribers of the occurrence of an event and passes additional arguments that the subscriber can use.
See line 128 in the code snippet below for an example.
1
2
3
 
void oosmos_SubscriberListNotifyWithArgs(oosmos_sSubscriberList * pSubscriberList, oosmos_sEvent * pEvent);
 
Prototype
pSubscriberList
Pointer to a oosmos_sSubscriberList member inside an OOSMOS object.
See Also
1
22
23
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
[GPLv2]
 
[...]
 
static void RunReceiverStateMachine(void * pObject)
{
uart * pUART = (uart *) pObject;
uint8_t Byte;
 
DisableInterrupt(pUART);
const bool PopSuccess = oosmos_QueuePop(&pUART->m_ReceiveDataQueue, &Byte, sizeof(Byte));
EnableInterrupt(pUART);
 
if (PopSuccess) {
uart_sReceivedByteEvent ReceivedByteEvent = { oosmos_EMPTY_EVENT, Byte };
oosmos_SubscriberListNotifyWithArgs(pUART->m_ReceivedByteEventSubscribers, ReceivedByteEvent);
}
}
 
[...]
oosmos/Classes/PIC32/uart.c

oosmos_ThreadBegin

oosmos_ThreadBegin and oosmos_ThreadEnd bracket OOSMOS Thread calls within and oosmos_POLL event handler.
See line 50 in the code snippet below for an example.
1
2
3
 
void oosmos_ThreadBegin();
 
Prototype
See Also
1
22
23
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
[GPLv2]
 
[...]
};
 
static void ToggleThread(const toggle * pToggle, oosmos_sState * pState)
{
oosmos_POINTER_GUARD(pToggle);
oosmos_POINTER_GUARD(pState);
 
oosmos_ThreadBegin();
for (;;) {
pinOn(pToggle->m_pPin);
oosmos_ThreadDelayMS(pToggle->m_TimeOnMS);
 
pinOff(pToggle->m_pPin);
oosmos_ThreadDelayMS(pToggle->m_TimeOffMS);
}
oosmos_ThreadEnd();
}
[...]
oosmos/Classes/toggle.c

oosmos_ThreadDelayMS

oosmos_ThreadDelayMS blocks the thread for the specified number of Milliseconds.
See line 53 in the code snippet below for an example.
1
2
3
 
void oosmos_ThreadDelayMS(uint32_t Milliseconds);
 
Prototype
Milliseconds
The number of milliseconds to block the thread.
See Also
1
22
23
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
[GPLv2]
 
[...]
 
static void ToggleThread(const toggle * pToggle, oosmos_sState * pState)
{
oosmos_POINTER_GUARD(pToggle);
oosmos_POINTER_GUARD(pState);
 
oosmos_ThreadBegin();
for (;;) {
pinOn(pToggle->m_pPin);
oosmos_ThreadDelayMS(pToggle->m_TimeOnMS);
 
pinOff(pToggle->m_pPin);
oosmos_ThreadDelayMS(pToggle->m_TimeOffMS);
}
oosmos_ThreadEnd();
}
 
[...]
oosmos/Classes/toggle.c

oosmos_ThreadDelaySeconds

oosmos_ThreadDelaySeconds blocks the thread for the specified number of Seconds.
See line 37 in the code snippet below for an example.
1
2
3
 
void oosmos_ThreadDelaySeconds(uint32_t Seconds);
 
Prototype
Seconds
The number of seconds to block the thread.
See Also
1
22
23
31
32
33
34
35
36
37
38
39
40
41
42
43
[GPLv2]
 
[...]
 
static void Thread(test * pTest, oosmos_sState * pState)
{
oosmos_ThreadBegin();
printf("Wait for 3 seconds...\n");
 
oosmos_ThreadDelaySeconds(3);
 
printf("Done. Press CNTL-C to exit.\n");
oosmos_ThreadEnd();
}
 
[...]
oosmos/Tests/ThreadDelaySeconds.c

oosmos_ThreadDelayUS

oosmos_ThreadDelayUS blocks the thread for the specified number of Microseconds.
See line 44 in the code snippet below for an example.
1
2
3
 
void oosmos_ThreadDelayUS(uint32_t Microseconds);
 
Prototype
Milliseconds
The number of microseconds to block the thread.
See Also
1
22
23
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
[GPLv2]
 
[...]
 
static void Thread(test * pTest, oosmos_sState * pState)
{
oosmos_ThreadBegin();
printf("Starting Thread\n");
 
pTest->Before = oosmos_GetFreeRunningUS();
 
for (pTest->I = 1; pTest->I <= 5; pTest->I++) {
oosmos_ThreadDelayUS(1000);
}
 
pTest->After = oosmos_GetFreeRunningUS();
 
pTest->Diff = pTest->After - pTest->Before;
 
printf("Diff: %u %u %u\n", (unsigned) pTest->Diff, (unsigned) pTest->Before, (unsigned) pTest->After);
 
if (pTest->Diff >= 5000 && pTest->Diff <= 5100) {
printf("Success\n");
}
else {
printf("Failed\n");
}
 
printf("Press CNTL-C to exit.\n");
oosmos_ThreadEnd();
}
 
[...]
oosmos/Tests/ThreadDelayUS.c

oosmos_ThreadEnd

oosmos_ThreadBegin and oosmos_ThreadEnd bracket OOSMOS Thread calls within and oosmos_POLL event handler.
See line 58 in the code snippet below for an example.
1
2
3
 
void oosmos_ThreadEnd();
 
Prototype
See Also
1
22
23
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
[GPLv2]
 
[...]
};
 
static void ToggleThread(const toggle * pToggle, oosmos_sState * pState)
{
oosmos_POINTER_GUARD(pToggle);
oosmos_POINTER_GUARD(pState);
 
oosmos_ThreadBegin();
for (;;) {
pinOn(pToggle->m_pPin);
oosmos_ThreadDelayMS(pToggle->m_TimeOnMS);
 
pinOff(pToggle->m_pPin);
oosmos_ThreadDelayMS(pToggle->m_TimeOffMS);
}
oosmos_ThreadEnd();
}
[...]
oosmos/Classes/toggle.c

oosmos_ThreadExit

oosmos_ThreadExit exits the thread. If there is an oosmos_ThreadFinally() function between the oosmos_ThreadExit and the oosmos_ThreadEnd, the code in the Finally block will be executed prior to exiting the thread.
See line 181 in the code snippet below for an example.
1
2
3
 
void oosmos_ThreadExit();
 
Prototype
See Also
1
22
23
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
[GPLv2]
 
[...]
 
static void ThreadExitFinally_Thread(threadtest * pThreadTest, oosmos_sState * pState)
{
oosmos_ThreadBegin();
pThreadTest->m_ThreadExitCount = 0;
oosmos_ThreadYield();
pThreadTest->m_ThreadExitCount++;
oosmos_ThreadExit();
oosmos_ThreadFinally();
pThreadTest->m_ThreadExitCount++;
 
if (pThreadTest->m_ThreadExitCount == 2) {
prtFormatted("ThreadExitFinally SUCCESS\n");
} else {
prtFormatted("ThreadExitFinally FAILURE\n");
}
oosmos_ThreadEnd();
}
 
[...]
oosmos/Classes/Tests/threadtest.c

oosmos_ThreadFinally

oosmos_ThreadFinally is an optional construct that begins a section of code to be executed before exiting the Thread block.
oosmos_ThreadFinally and its code must be placed immediately before the oosmos_ThreadEnd.
See threadtest.c, below, line 182 for an example.
1
2
3
 
void oosmos_ThreadFinally();
 
Prototype
See Also
1
22
23
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
[GPLv2]
 
[...]
 
static void ThreadExitFinally_Thread(threadtest * pThreadTest, oosmos_sState * pState)
{
oosmos_ThreadBegin();
pThreadTest->m_ThreadExitCount = 0;
oosmos_ThreadYield();
pThreadTest->m_ThreadExitCount++;
oosmos_ThreadExit();
oosmos_ThreadFinally();
pThreadTest->m_ThreadExitCount++;
 
if (pThreadTest->m_ThreadExitCount == 2) {
prtFormatted("ThreadExitFinally SUCCESS\n");
} else {
prtFormatted("ThreadExitFinally FAILURE\n");
}
oosmos_ThreadEnd();
}
 
[...]
oosmos/Classes/Tests/threadtest.c

oosmos_ThreadWaitCond

oosmos_ThreadWaitCond effectively blocks execution of this object until a condition is met. See line 113 in the code snippet below for an example.
This form of oosmos_ThreadWaitCond does not accept a timeout, so you must be certain that the condition will be met eventually. There are other forms of oosmos_ThreadWaitCond that do accept a timeout value.
1
2
3
 
void oosmos_ThreadWaitCond(bool Condition);
 
Prototype
Condition
When this condition is false, OOSMOS returns from the function to run other objects and then re-enters this statement to check the condition again. It keeps doing this until the condition is true, and then execution continues to the next statement.
See Also
1
22
23
108
109
110
111
112
113
114
115
116
117
118
[GPLv2]
 
[...]
 
static void WaitCond_Thread(threadtest * pThreadTest, oosmos_sState * pState)
{
oosmos_ThreadBegin();
prtFormatted("ThreadWaitCond...\n");
oosmos_ThreadWaitCond(ConditionRandom(2));
prtFormatted("ThreadWaitCond SUCCESS\n\n");
oosmos_ThreadEnd();
}
 
[...]
oosmos/Classes/Tests/threadtest.c

oosmos_ThreadWaitCond_TimeoutMS

oosmos_ThreadWaitCond_TimeoutMS effectively blocks execution of this object until a condition is met or a timeout expires. See line 155 in the code snippet below for examples.
1
2
3
4
5
 
void oosmos_ThreadWaitCond_TimeoutMS(bool Condition,
uint32_t TimeoutMS,
bool * pTimeoutStatus);
 
Prototype
Condition
When this condition is false, OOSMOS returns from the function to run other objects and then re-enters this statement to check the condition again. It keeps doing this until the condition is true and then execution continues to the next statement.
TimeoutMS
The timeout value in milliseconds.
pTimeoutStatus
The address of a bool variable that will indicate whether the timeout expired first (true) or the condition occurred first (false).
See Also
1
22
23
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
[GPLv2]
 
[...]
 
static void WaitEvent_TimeoutMS_Thread(threadtest * pThreadTest, oosmos_sState * pState)
{
oosmos_ThreadBegin();
bool TimedOut;
pThreadTest->m_WE_Timeout_Successes = 0;
 
prtFormatted("ThreadWaitEvent_TimeoutMS...\n");
 
oosmos_PushEventCode(pThreadTest, evPrint);
oosmos_ThreadWaitEvent_TimeoutMS(evPrint, 100, &TimedOut);
pThreadTest->m_WE_Timeout_Successes += (TimedOut == false);
 
oosmos_ThreadWaitEvent_TimeoutMS(evPrint, 100, &TimedOut);
pThreadTest->m_WE_Timeout_Successes += (TimedOut == true);
prtFormatted("ThreadWaitEvent_TimeoutMS %s\n\n", pThreadTest->m_WE_Timeout_Successes == 2 ? "SUCCESS" : "FAILURE");
oosmos_ThreadEnd();
}
 
[...]
oosmos/Classes/Tests/threadtest.c

oosmos_ThreadWaitEvent

oosmos_ThreadWaitEvent effectively blocks execution of this object until the specified event is received. See line 141 in the code snippet below for an example.
This form of oosmos_ThreadWaitEvent does not accept a timeout, so you should be certain that the event will be received eventually. There are other forms of oosmos_ThreadWaitEvent that do accept a timeout value.
1
2
3
 
void oosmos_ThreadWaitEvent(int WaitEventCode);
 
Prototype
WaitEventCode
The event code that must be received before execution can continue.
See Also
1
22
23
134
135
136
137
138
139
140
141
142
143
144
145
146
[GPLv2]
 
[...]
 
static void WaitEvent_Thread(threadtest * pThreadTest, oosmos_sState * pState)
{
oosmos_ThreadBegin();
prtFormatted("ThreadWaitEvent...\n");
 
oosmos_PushEventCode(pThreadTest, evPrint);
oosmos_ThreadWaitEvent(evDone);
prtFormatted("ThreadWaitEvent SUCCESS\n\n");
oosmos_ThreadEnd();
}
 
[...]
oosmos/Classes/Tests/threadtest.c

oosmos_ThreadWaitEvent_TimeoutMS

oosmos_ThreadWaitEvent_TimeoutMS effectively blocks execution of this object until a condition is met or a timeout expires. See line 155 in the code snippet below for an example.
1
2
3
4
5
 
void oosmos_ThreadWaitEvent_TimeoutMS(int WaitEventCode
uint32_t TimeoutMS,
bool * pTimeoutStatus);
 
Prototype
WaitEventCode
The event code that must be received before execution can continue.
TimeoutMS
The timeout value in milliseconds.
pTimeoutStatus
The address of a bool variable that will indicate whether the timeout expired first (true) or the condition occurred first (false).
See Also
1
22
23
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
[GPLv2]
 
[...]
 
static void WaitEvent_TimeoutMS_Thread(threadtest * pThreadTest, oosmos_sState * pState)
{
oosmos_ThreadBegin();
bool TimedOut;
pThreadTest->m_WE_Timeout_Successes = 0;
 
prtFormatted("ThreadWaitEvent_TimeoutMS...\n");
 
oosmos_PushEventCode(pThreadTest, evPrint);
oosmos_ThreadWaitEvent_TimeoutMS(evPrint, 100, &TimedOut);
pThreadTest->m_WE_Timeout_Successes += (TimedOut == false);
 
oosmos_ThreadWaitEvent_TimeoutMS(evPrint, 100, &TimedOut);
pThreadTest->m_WE_Timeout_Successes += (TimedOut == true);
prtFormatted("ThreadWaitEvent_TimeoutMS %s\n\n", pThreadTest->m_WE_Timeout_Successes == 2 ? "SUCCESS" : "FAILURE");
oosmos_ThreadEnd();
}
 
[...]
oosmos/Classes/Tests/threadtest.c

oosmos_ThreadYield

If you have a loop that will use a lot of CPU time, it could hold up execution of other OOSMOS objects in the system, you can use the oosmos_ThreadYield call to relinquish control occasionally in your loop.
See line 51 in the code snippet below for an example. In this example, we relinquish control every time through the loop, but you could use the C modulo operator (%) to relinquish every N iterations through the loop.
1
2
3
 
void oosmos_ThreadYield();
 
Prototype
See Also
1
22
23
45
46
47
48
49
50
51
52
53
54
55
56
[GPLv2]
 
[...]
 
static void Thread(threadyieldtest * pThreadYieldTest, oosmos_sState * pState)
{
oosmos_ThreadBegin();
for (pThreadYieldTest->m_Count = 1; pThreadYieldTest->m_Count <= pThreadYieldTest->m_Iterations; pThreadYieldTest->m_Count++) {
prtFormatted("Test threadyieldtest, '%s'...\n", pThreadYieldTest->m_pID);
oosmos_ThreadYield();
}
oosmos_ThreadEnd();
}
 
[...]
oosmos/Classes/Tests/threadyieldtest.c

oosmos_TIMEOUT

oosmos_TIMEOUT is one of the six predefined event macros. This event is generated if a timeout for this state has been previously established and that timeout has expired.
To establish a timeout, use one of oosmos_StateTimeoutMS, oosmos_StateTimeoutSeconds or oosmos_StateTimeoutUS.
See line 54 in the code snippet below for an example.
See Also
1
22
23
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
[GPLv2]
 
[...]
 
//>>>CODE
static bool MS_State_Code(void * pObject, oosmos_sState * pState, const oosmos_sEvent * pEvent)
{
test * pTest = (test *) pObject;
 
switch (oosmos_EventCode(pEvent)) {
case oosmos_ENTER: {
return oosmos_StateTimeoutMS(pState, (uint32_t) pTest->m_TimeMS);
}
case oosmos_TIMEOUT: {
return oosmos_Transition(pTest, pState, Seconds_State);
}
}
 
return false;
}
 
[...]
oosmos/Examples/Basic/Windows/StateTimeout.c

oosmos_TimeoutHasExpired

oosmos_TimeoutHasExpired checks to see if a previously established timeout has expired.
See line 47 in the code snippet below for an example.
1
2
3
 
bool oosmos_TimeoutHasExpired(oosmos_sTimeout * pTimeout);
 
Prototype
pTimeout
Address of the oosmos_sTimeout meta data item.
See Also
1
22
23
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
[GPLv2]
 
[...]
 
extern int main(void)
{
//
// Allocate a Timeout object.
//
oosmos_sTimeout Timeout;
 
//
// Set timeout.
//
oosmos_TimeoutInMS(&Timeout, WaitTimeMS);
 
printf("Waiting for %lu milliseconds...\n", (unsigned long) WaitTimeMS);
 
for (;;) {
//
// Check if the time has expired.
//
if (oosmos_TimeoutHasExpired(&Timeout)) {
break;
}
 
//
// Be polite. Prevent 100% CPU usage on multi-tasked
// machines (e.g. Windows or Linux).
//
oosmos_DelayMS(1);
}
 
printf("SUCCESS\n");
 
return 0;
}
oosmos/Examples/Basic/Windows/TimeoutInMS.c

oosmos_TimeoutInMS

oosmos_TimeoutInMS is the low-level timeout mechanism used by the state machine engine. It is provided to give your program the flexibility to have timeout capability without having to add a state machine to your object.
To use it, first execute the oosmos_TimeoutInMS call (line 39) providing the address of a oosmos_sTimeout object (line 34), then periodically check if the timeout has expired using the oosmos_TimeoutHasExpired call (line 47).
1
2
3
 
oosmos_TimeoutInMS(oosmos_sTimeout * pTimeout, uint32_t Milliseconds);
 
Prototype
pTimeout
Address of the oosmos_sTimeout item.
Milliseconds
Number of milliseconds before timeout.
See Also
1
22
23
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
[GPLv2]
 
[...]
 
extern int main(void)
{
//
// Allocate a Timeout object.
//
oosmos_sTimeout Timeout;
 
//
// Set timeout.
//
oosmos_TimeoutInMS(&Timeout, WaitTimeMS);
 
printf("Waiting for %lu milliseconds...\n", (unsigned long) WaitTimeMS);
 
for (;;) {
//
// Check if the time has expired.
//
if (oosmos_TimeoutHasExpired(&Timeout)) {
break;
}
 
//
// Be polite. Prevent 100% CPU usage on multi-tasked
// machines (e.g. Windows or Linux).
//
oosmos_DelayMS(1);
}
 
printf("SUCCESS\n");
 
return 0;
}
oosmos/Examples/Basic/Windows/TimeoutInMS.c

oosmos_TimeoutInSeconds

oosmos_TimeoutInSeconds is the low-level timeout mechanism used by the state machine engine. It is provided to give your program the flexibility to have timeout capability without having to add a state machine to your object.
To use it, first execute the oosmos_TimeoutInSeconds call (line 39) providing the address of a oosmos_sTimeout object (line 34), then periodically check if the timeout has expired using the oosmos_TimeoutHasExpired call (line 47).
1
2
3
 
void oosmos_TimeoutInSeconds(oosmos_sTimeout * pTimeout, uint32_t Seconds);
 
Prototype
pTimeout
Address of the oosmos_sTimeout item.
Seconds
Number of seconds before timeout.
See Also
1
22
23
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
[GPLv2]
 
[...]
 
extern int main(void)
{
//
// Allocate a Timeout object.
//
oosmos_sTimeout Timeout;
 
//
// Set timeout.
//
oosmos_TimeoutInSeconds(&Timeout, WaitTimeSeconds);
 
printf("Waiting for %lu seconds...\n", (unsigned long) WaitTimeSeconds);
 
for (;;) {
//
// Check if the time has expired.
//
if (oosmos_TimeoutHasExpired(&Timeout)) {
break;
}
 
//
// Be polite. Prevent 100% CPU usage on multi-tasked
// machines (e.g. Windows or Linux).
//
oosmos_DelayMS(1);
}
 
printf("SUCCESS\n");
 
return 0;
}
oosmos/Examples/Basic/Windows/TimeoutInSeconds.c

oosmos_TimeoutInUS

oosmos_TimeoutInUS is the low-level timeout mechanism used by the state machine engine. It is provided to give your program the flexibility to have timeout capability without having to add a state machine to your object.
To use it, first execute the oosmos_TimeoutInUS call (line 39) providing the address of a oosmos_sTimeout object (line 34), then periodically check if the timeout has expired using the oosmos_TimeoutHasExpired call (line 47).
1
2
3
 
void oosmos_TimeoutInUS(oosmos_sTimeout * pTimeout, uint32_t Microseconds);
 
Prototype
pTimeout
Address of the oosmos_sTimeout item.
Microseconds
Number of microseconds before timeout.
See Also
1
22
23
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
[GPLv2]
 
[...]
 
extern int main(void)
{
//
// Allocate a Timeout object.
//
oosmos_sTimeout Timeout;
 
//
// Set timeout.
//
oosmos_TimeoutInUS(&Timeout, WaitTimeUS);
 
printf("Waiting for %lu microseconds...\n", (unsigned long) WaitTimeUS);
 
for (;;) {
//
// Check if the time has expired.
//
if (oosmos_TimeoutHasExpired(&Timeout)) {
break;
}
 
//
// Be polite. Prevent 100% CPU usage on multi-tasked
// machines (e.g. Windows or Linux).
//
oosmos_DelayMS(75);
}
 
printf("SUCCESS\n");
 
return 0;
}
oosmos/Examples/Basic/Windows/TimeoutInUS.c

oosmos_Transition

oosmos_Transition causes a transition from the current state to the specified target state. During this transition process, we execute all the nested oosmos_EXIT event handlers as we exit the from states and then execute all the oosmos_ENTER event handlers as we enter into all the (possibly nested) states to the target state. (See line 57.)
Note: In the example, we use the state version of the toggle object in the oosmos/Classes directory instead of the Thread version.
1
2
3
4
5
 
bool oosmos_Transition(void * pObject,
oosmos_sState * pFromState,
oosmos_sState * pToState);
 
Prototype
pFromState
The same pFromState argument that was passed into the containing state handler.
pToState
pToState is pointer to the state we are transitioning to.
RETURN
Always returns true.
1
22
23
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
[GPLv2]
 
[...]
static bool Off_State_Code(void * pObject, oosmos_sState * pState, const oosmos_sEvent * pEvent)
{
toggle * pToggle = (toggle *) pObject;
 
switch (oosmos_EventCode(pEvent)) {
case oosmos_ENTER: {
return oosmos_StateTimeoutMS(pState, (uint32_t) pToggle->m_TimeOffMS);
}
case oosmos_TIMEOUT: {
return oosmos_Transition(pToggle, pState, On_State);
}
}
 
return false;
}
[...]
oosmos/Classes/toggle_state.c

oosmos_TransitionAction

oosmos_Transition causes a transition from the current state to the specified target state. During this transition process, we execute all the nested oosmos_EXIT event handlers as we exit the from states and then execute all the oosmos_ENTER event handlers as we enter into all the (possibly nested) states to the target state. (See lines 51 and 78.)
Note: In the example, we use the state version of the toggle object in the oosmos/Classes directory instead of the Thread version.
1
2
3
4
5
6
 
bool oosmos_TransitionAction(void * pObject,
oosmos_sState * pFromState,
oosmos_sState * pToState,
oosmos_tAction pActionFunction);
 
Prototype
pFromState
The same pFromState argument that was passed into the containing state handler.
pToState
pToState is pointer to the state we are transitioning to.
pActionFunction
pActionFunction is a pointer to a function to call after all oosmos_EXIT and before all oosmos_ENTER events are triggered.
RETURN
Always returns true.
1
22
23
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
[GPLv2]
 
[...]
static void OOSMOS_Action1(void * pObject, oosmos_sState * pState, const oosmos_sEvent * pEvent)
{
test * pTest = (test *) pObject;
 
printf("Count: %u\n", Count);
ActionCount = Count;
printf("%s\n", oosmos_IsInState(pTest, &pTest->ROOT) ? "SUCCESS" : "FAILURE");
 
oosmos_UNUSED(pState);
oosmos_UNUSED(pEvent);
}
 
static bool A_State_Code(void * pObject, oosmos_sState * pState, const oosmos_sEvent * pEvent)
{
test * pTest = (test *) pObject;
 
switch (oosmos_EventCode(pEvent)) {
case oosmos_EXIT: {
Count++;
return true;
}
case oosmos_DEFAULT: {
Count = 0;
printf("INITIAL\n");
return true;
}
case oosmos_COMPLETE: {
return oosmos_TransitionAction(pTest, pState, B_State, pEvent, OOSMOS_Action1);
}
}
 
return false;
}
 
[...]
oosmos/Tests/Action.c

oosmos_UNUSED

oosmos_UNUSED assures that a reference is made to a function argument. Prevents compiler or LINT messages. Usually used by the OOSMOS code generator.
See Also

oosmos_US2Days_Rounded

oosmos_US2Days_Rounded is a macro that converts microseconds to days with the result being rounded for better precision. If speed is more important than accuracy, see the truncated version of this macro.
1
2
3
 
oosmos_US2Days_Rounded(Microseconds)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_US2Days_Truncated

oosmos_US2Days_Truncated is a macro that converts microseconds to days with the result being truncated due to default integral division behavior. If precision is important, see the rounded version of this macro.
1
2
3
 
oosmos_US2Days_Truncated(Microseconds)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_US2Hours_Rounded

oosmos_US2Hours_Rounded is a macro that converts microseconds to hours with the result being rounded for better precision. If speed is more important than accuracy, see the truncated version of this macro.
1
2
3
 
oosmos_US2Hours_Rounded(Microseconds)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_US2Hours_Truncated

oosmos_US2Hours_Truncated is a macro that converts microseconds to hours with the result being truncated due to default integral division behavior. If precision is important, see the rounded version of this macro.
1
2
3
 
oosmos_US2Hours_Truncated(Microseconds)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_US2Minutes_Rounded

oosmos_US2Minutes_Rounded is a macro that converts microseconds to minutes with the result being rounded for better precision. If speed is more important than accuracy, see the truncated version of this macro.
1
2
3
 
oosmos_US2Minutes_Rounded(Microseconds)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_US2Minutes_Truncated

oosmos_US2Minutes_Truncated is a macro that converts microseconds to minutes with with the result being truncated due to default integral division behavior. If precision is important, see the rounded version of this macro.
1
2
3
 
oosmos_US2Minutes_Truncated(Microseconds)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_US2MS_Rounded

oosmos_US2MS_Rounded is a macro that converts microseconds to milliseconds with the result being rounded for better precision. If speed is more important than accuracy, see the truncated version of this macro.
1
2
3
 
oosmos_US2MS_Rounded(Microseconds)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_US2MS_Truncated

oosmos_US2MS_Truncated is a macro that converts microseconds to milliseconds with the result being truncated due to default integral division behavior. If precision is important, see the rounded version of this macro.
1
2
3
 
oosmos_US2MS_Truncated(Microseconds)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded, US2Seconds_Truncated

oosmos_US2Seconds_Rounded

oosmos_US2Seconds_Rounded is a macro that converts microseconds to seconds with the result being rounded for better precision. If speed is more important than accuracy, see the truncated version of this macro.
1
2
3
 
oosmos_US2Seconds_Rounded(Microseconds)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Truncated

oosmos_US2Seconds_Truncated

oosmos_US2Seconds_Truncated is a macro that converts microseconds to seconds with the result being truncated due to default integral division behavior. If precision is important, see the rounded version of this macro.
1
2
3
 
oosmos_US2Seconds_Truncated(Microseconds)
 
Macro
See Also
Days2Hours, Days2MS, Days2Minutes, Days2Seconds, Days2US, Divide_Integral_Rounded, Hours2Days_Rounded, Hours2Days_Truncated, Hours2MS, Hours2Minutes, Hours2Seconds, Hours2US, MS2Days_Rounded, MS2Days_Truncated, MS2Hours_Rounded, MS2Hours_Truncated, MS2Minutes_Rounded, MS2Minutes_Truncated, MS2Seconds_Rounded, MS2Seconds_Truncated, MS2US, Minutes2Days_Rounded, Minutes2Days_Truncated, Minutes2Hours_Rounded, Minutes2Hours_Truncated, Minutes2MS, Minutes2Seconds, Minutes2US, Seconds2Days_Rounded, Seconds2Days_Truncated, Seconds2Hours_Rounded, Seconds2Hours_Truncated, Seconds2MS, Seconds2Minutes_Rounded, Seconds2Minutes_Truncated, Seconds2US, US2Days_Rounded, US2Days_Truncated, US2Hours_Rounded, US2Hours_Truncated, US2MS_Rounded, US2MS_Truncated, US2Minutes_Rounded, US2Minutes_Truncated, US2Seconds_Rounded
Copyright © 2014-2025  OOSMOS, LLC