-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathuc_ao.h
87 lines (70 loc) · 2.99 KB
/
uc_ao.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*****************************************************************************
* Active Object pattern implementation based on uC/OS-II (uC/AO)
*
* Q u a n t u m L e a P s
* ------------------------
* Modern Embedded Software
*
* Copyright (C) 2020 Quantum Leaps, LLC. All rights reserved.
*
* SPDX-License-Identifier: APACHE-2.0
*
* This software is distributed by Quantum Leaps, LLC under the terms of
* Apache License Version 2.0, which is the same license used for uC/OS-II RTOS.
* The text of the license is available at: www.apache.org/licenses/LICENSE-2.0.
*
* Contact information:
* <www.state-machine.com>
* <info@state-machine.com>
*****************************************************************************/
#ifndef UC_AO_H
#define UC_AO_H
#include "ucos_ii.h" /* uC/OS-II API, port and compile-time configuration */
#include "qassert.h" /* embedded-systems-friendly assertions (DbC) */
/*---------------------------------------------------------------------------*/
/* Event facilities... */
typedef uint16_t Signal; /* event signal */
enum ReservedSignals {
INIT_SIG, /* dispatched to AO before entering event-loop */
USER_SIG /* first signal available to the users */
};
/* Event base class */
typedef struct {
Signal sig; /* event signal */
/* event parameters added in subclasses of Event */
} Event;
/*---------------------------------------------------------------------------*/
/* Actvie Object facilities... */
typedef struct Active Active; /* forward declaration */
typedef void (*DispatchHandler)(Active * const me, Event const * const e);
/* Active Object base class */
struct Active {
INT8U thread; /* private thread (the unique uC/OS-II task priority) */
OS_EVENT *queue; /* private message queue */
DispatchHandler dispatch; /* pointer to the dispatch() function */
/* active object data added in subclasses of Active */
};
void Active_ctor(Active * const me, DispatchHandler dispatch);
void Active_start(Active * const me,
uint8_t prio, /* priority (1-based) */
Event **queueSto,
uint32_t queueLen,
void *stackSto,
uint32_t stackSize,
uint16_t opt);
void Active_post(Active * const me, Event const * const e);
/*---------------------------------------------------------------------------*/
/* Time Event facilities... */
/* Time Event class */
typedef struct {
Event super; /* inherit Event */
Active *act; /* the AO that requested this TimeEvent */
uint32_t timeout; /* timeout counter; 0 means not armed */
uint32_t interval; /* interval for periodic TimeEvent, 0 means one-shot */
} TimeEvent;
void TimeEvent_ctor(TimeEvent * const me, Signal sig, Active *act);
void TimeEvent_arm(TimeEvent * const me, uint32_t timeout, uint32_t interval);
void TimeEvent_disarm(TimeEvent * const me);
/* static (i.e., class-wide) operation */
void TimeEvent_tick(void);
#endif /* UC_AO_H */