forked from u-blox/ubxlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathu_port.h
160 lines (140 loc) · 5.34 KB
/
u_port.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
* Copyright 2020 u-blox
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _U_PORT_H_
#define _U_PORT_H_
/* No #includes allowed here */
/** @file
* @brief
* Common stuff for porting layer. These functions are thread-safe.
*/
#ifdef __cplusplus
extern "C" {
#endif
/* ----------------------------------------------------------------
* COMPILE-TIME MACROS
* -------------------------------------------------------------- */
/** Used only by U_PORT_STRINGIFY_QUOTED.
*/
#define U_PORT_STRINGIFY_LITERAL(x) #x
/** Stringify a macro, i.e. if you have:
*
* \#define foo bar
*
* ...U_PORT_STRINGIFY_QUOTED(foo) is "bar".
*/
#define U_PORT_STRINGIFY_QUOTED(x) U_PORT_STRINGIFY_LITERAL(x)
/* ----------------------------------------------------------------
* TYPES
* -------------------------------------------------------------- */
/* ----------------------------------------------------------------
* FUNCTIONS
* -------------------------------------------------------------- */
/** Start the platform. This configures clocks, resources, etc.
* and then calls pEntryPoint, i.e. the application, in an RTOS task.
* This is used as a standard way to start the system for all of the
* u-blox examples and all of the u-blox tests.
* You may have your own mechanism for initialisating the HW and
* starting an RTOS task, in which case you need not use this
* function.
* This function only returns if there is an error;
* code execution ends up in pEntryPoint, which should
* never return.
*
* @param pEntryPoint the function to run.
* @param pParameter a pointer that will be passed to pEntryPoint
* when it is called. Usually NULL.
* @param stackSizeBytes the number of bytes of memory to dynamically
* allocate for stack; ignored if the RTOS
* has already been started and no new
* task needs to be created for the entry point.
* @param priority the priority at which to run a task that
* is pEntryPoint; ignored if the RTOS
* has already been started and no new
* task needs to be created for the entry point.
* @return negative error code.
*/
int32_t uPortPlatformStart(void (*pEntryPoint)(void *),
void *pParameter,
size_t stackSizeBytes,
int32_t priority);
/** Initialise the porting layer. Should be called by
* the application entry point before running any other
* ubxlib function except uPortPlatformStart().
* If the port is already initialised this function does
* nothing and returns success, hence it can safely
* be called at any time.
*
* @return zero on success else negative error code.
*/
int32_t uPortInit();
/** Deinitialise the porting layer.
*/
void uPortDeinit();
/** Get the current OS tick converted to a time in milliseconds.
* This is guaranteed to be unaffected by any time setting activity.
* It is NOT maintained while the processor is in deep sleep, i.e.
* with clocks stopped; port initialisation should be called on
* return from deep sleep and that will restart this time from
* zero once more.
*
* @return the current OS tick converted to milliseconds.
*/
int64_t uPortGetTickTimeMs();
/** Get the heap high watermark, the minimum amount of heap
* free, ever.
*
* @return the minimum amount of heap free in bytes or negative
* error code.
*/
int32_t uPortGetHeapMinFree();
/** Get the current free heap size. This may be called at
* any time, even before uPortInit() or after uPortDeinit().
*
* @return the amount of free heap in bytes or negative
* error code.
*/
int32_t uPortGetHeapFree();
/** Enter a critical section: no interrupts should go off, no
* tasks will be rescheduled, until uPortExitCritical() is
* called. Note that OS-related port APIs (i.e. no uPortTask*,
* uPortMutex*, uPortSemaphore*, uPortQueue*, uPortEventQueue*
* or uPortTimer* functions) should NOT be called within the
* critical section; depending on the platform that may cause
* an assert or may cause the rescheduling you don't want to
* happen anyway. So don't do that. Also, time may not pass,
* i.e. uPortGetTickTimeMs() may not advance, during the critical
* section.
*
* It is NOT a requirement that this API is implemented:
* where it is not implemented U_ERROR_COMMON_NOT_IMPLEMENTED
* should be returned.
*
* @return zero on success else negative error code.
*/
int32_t uPortEnterCritical();
/** Leave a critical section: use this AS SOON AS POSSIBLE
* after uPortEnterCritical().
*
* It is NOT a requirement that this API is implemented:
* where it is not implemented U_ERROR_COMMON_NOT_IMPLEMENTED
* should be returned by uPortEnterCritical().
*/
void uPortExitCritical();
#ifdef __cplusplus
}
#endif
#endif // _U_PORT_H_
// End of file