• R/O
  • SSH
  • HTTPS

chibios: Commit


Commit MetaInfo

Revision12949 (tree)
Time2019-08-11 21:13:52
Authorgdisirio

Log Message

Removed old OSAL implementations.

Change Summary

  • delete: trunk/os/hal/osal/nil/osal.c
  • delete: trunk/os/hal/osal/nil/osal.h
  • delete: trunk/os/hal/osal/nil/osal.mk
  • delete: trunk/os/hal/osal/nil
  • delete: trunk/os/hal/osal/rt/osal.c
  • delete: trunk/os/hal/osal/rt/osal.h
  • delete: trunk/os/hal/osal/rt/osal.mk
  • delete: trunk/os/hal/osal/rt

Incremental Difference

--- trunk/os/hal/osal/nil/osal.c (revision 12948)
+++ trunk/os/hal/osal/nil/osal.c (nonexistent)
@@ -1,51 +0,0 @@
1-/*
2- ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3-
4- Licensed under the Apache License, Version 2.0 (the "License");
5- you may not use this file except in compliance with the License.
6- You may obtain a copy of the License at
7-
8- http://www.apache.org/licenses/LICENSE-2.0
9-
10- Unless required by applicable law or agreed to in writing, software
11- distributed under the License is distributed on an "AS IS" BASIS,
12- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- See the License for the specific language governing permissions and
14- limitations under the License.
15-*/
16-
17-/**
18- * @file osal.c
19- * @brief OSAL module code.
20- *
21- * @addtogroup OSAL
22- * @{
23- */
24-
25-#include "osal.h"
26-
27-/*===========================================================================*/
28-/* Module local definitions. */
29-/*===========================================================================*/
30-
31-/*===========================================================================*/
32-/* Module exported variables. */
33-/*===========================================================================*/
34-
35-/*===========================================================================*/
36-/* Module local types. */
37-/*===========================================================================*/
38-
39-/*===========================================================================*/
40-/* Module local variables. */
41-/*===========================================================================*/
42-
43-/*===========================================================================*/
44-/* Module local functions. */
45-/*===========================================================================*/
46-
47-/*===========================================================================*/
48-/* Module exported functions. */
49-/*===========================================================================*/
50-
51-/** @} */
--- trunk/os/hal/osal/nil/osal.h (revision 12948)
+++ trunk/os/hal/osal/nil/osal.h (nonexistent)
@@ -1,989 +0,0 @@
1-/*
2- ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3-
4- Licensed under the Apache License, Version 2.0 (the "License");
5- you may not use this file except in compliance with the License.
6- You may obtain a copy of the License at
7-
8- http://www.apache.org/licenses/LICENSE-2.0
9-
10- Unless required by applicable law or agreed to in writing, software
11- distributed under the License is distributed on an "AS IS" BASIS,
12- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- See the License for the specific language governing permissions and
14- limitations under the License.
15-*/
16-
17-/**
18- * @file osal.h
19- * @brief OSAL module header.
20- *
21- * @addtogroup OSAL
22- * @{
23- */
24-
25-#ifndef OSAL_H
26-#define OSAL_H
27-
28-#include <stddef.h>
29-#include <stdint.h>
30-#include <stdbool.h>
31-
32-#include "ch.h"
33-
34-#if defined(__SPC5_HAL__)
35-#include "platform.h"
36-#endif
37-
38-/*===========================================================================*/
39-/* Module constants. */
40-/*===========================================================================*/
41-
42-/**
43- * @name Common constants
44- * @{
45- */
46-#if !defined(FALSE) || defined(__DOXYGEN__)
47-#define FALSE 0
48-#endif
49-
50-#if !defined(TRUE) || defined(__DOXYGEN__)
51-#define TRUE 1
52-#endif
53-
54-#define OSAL_SUCCESS false
55-#define OSAL_FAILED true
56-/** @} */
57-
58-#if 0
59-/**
60- * @name Messages
61- * @{
62- */
63-#define MSG_OK (msg_t)0
64-#define MSG_TIMEOUT (msg_t)-1
65-#define MSG_RESET (msg_t)-2
66-/** @} */
67-#endif
68-
69-#if 0
70-/**
71- * @name Special time constants
72- * @{
73- */
74-#define TIME_IMMEDIATE ((sysinterval_t)0)
75-#define TIME_INFINITE ((sysinterval_t)-1)
76-/** @} */
77-#endif
78-
79-/**
80- * @name Systick modes.
81- * @{
82- */
83-#define OSAL_ST_MODE_NONE 0
84-#define OSAL_ST_MODE_PERIODIC 1
85-#define OSAL_ST_MODE_FREERUNNING 2
86-/** @} */
87-
88-/**
89- * @name Systick parameters.
90- * @{
91- */
92-/**
93- * @brief Size in bits of the @p systick_t type.
94- */
95-#define OSAL_ST_RESOLUTION CH_CFG_ST_RESOLUTION
96-
97-/**
98- * @brief Required systick frequency or resolution.
99- */
100-#define OSAL_ST_FREQUENCY CH_CFG_ST_FREQUENCY
101-
102-/**
103- * @brief Systick mode required by the underlying OS.
104- */
105-#if (CH_CFG_ST_TIMEDELTA == 0) || defined(__DOXYGEN__)
106-#define OSAL_ST_MODE OSAL_ST_MODE_PERIODIC
107-#else
108-#define OSAL_ST_MODE OSAL_ST_MODE_FREERUNNING
109-#endif
110-/** @} */
111-
112-/*===========================================================================*/
113-/* Module pre-compile time settings. */
114-/*===========================================================================*/
115-
116-/*===========================================================================*/
117-/* Derived constants and error checks. */
118-/*===========================================================================*/
119-
120-#if CH_CFG_USE_SEMAPHORES == FALSE
121-#error "OSAL requires CH_CFG_USE_SEMAPHORES=TRUE"
122-#endif
123-
124-#if CH_CFG_USE_EVENTS == FALSE
125-#error "OSAL requires CH_CFG_USE_EVENTS=TRUE"
126-#endif
127-
128-#if !(OSAL_ST_MODE == OSAL_ST_MODE_NONE) && \
129- !(OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC) && \
130- !(OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING)
131-#error "invalid OSAL_ST_MODE setting in osal.h"
132-#endif
133-
134-#if (OSAL_ST_RESOLUTION != 16) && (OSAL_ST_RESOLUTION != 32)
135-#error "invalid OSAL_ST_RESOLUTION, must be 16 or 32"
136-#endif
137-
138-/*===========================================================================*/
139-/* Module data structures and types. */
140-/*===========================================================================*/
141-
142-#if 0
143-/**
144- * @brief Type of a system status word.
145- */
146-typedef uint32_t syssts_t;
147-#endif
148-
149-#if 0
150-/**
151- * @brief Type of a message.
152- */
153-typedef int32_t msg_t;
154-#endif
155-
156-#if 0
157-/**
158- * @brief Type of system time counter.
159- */
160-typedef uint32_t systime_t;
161-#endif
162-
163-#if 0
164-/**
165- * @brief Type of system time interval.
166- */
167-typedef uint32_t sysinterval_t;
168-#endif
169-
170-#if 0
171-/**
172- * @brief Type of realtime counter.
173- */
174-typedef uint32_t rtcnt_t;
175-#endif
176-
177-#if 0
178-/**
179- * @brief Type of a thread reference.
180- */
181-typedef thread_t * thread_reference_t;
182-#endif
183-
184-#if 0
185-/**
186- * @brief Type of an event flags mask.
187- */
188-typedef uint32_t eventflags_t;
189-#endif
190-
191-/**
192- * @brief Type of an event flags object.
193- * @note The content of this structure is not part of the API and should
194- * not be relied upon. Implementers may define this structure in
195- * an entirely different way.
196- * @note Retrieval and clearing of the flags are not defined in this
197- * API and are implementation-dependent.
198- */
199-typedef struct event_source event_source_t;
200-
201-/**
202- * @brief Type of an event source callback.
203- * @note This type is not part of the OSAL API and is provided
204- * exclusively as an example and for convenience.
205- */
206-typedef void (*eventcallback_t)(event_source_t *esp);
207-
208-/**
209- * @brief Events source object.
210- * @note The content of this structure is not part of the API and should
211- * not be relied upon. Implementers may define this structure in
212- * an entirely different way.
213- * @note Retrieval and clearing of the flags are not defined in this
214- * API and are implementation-dependent.
215- */
216-struct event_source {
217- volatile eventflags_t flags; /**< @brief Stored event flags. */
218- eventcallback_t cb; /**< @brief Event source callback. */
219- void *param; /**< @brief User defined field. */
220-};
221-
222-/**
223- * @brief Type of a mutex.
224- * @note If the OS does not support mutexes or there is no OS then them
225- * mechanism can be simulated.
226- */
227-typedef semaphore_t mutex_t;
228-
229-#if 0
230-/**
231- * @brief Type of a thread queue.
232- * @details A thread queue is a queue of sleeping threads, queued threads
233- * can be dequeued one at time or all together.
234- * @note In this implementation it is implemented as a single reference
235- * because there are no real threads.
236- */
237-typedef struct {
238- thread_reference_t tr;
239-} threads_queue_t;
240-#endif
241-
242-/*===========================================================================*/
243-/* Module macros. */
244-/*===========================================================================*/
245-
246-/**
247- * @name Debug related macros
248- * @{
249- */
250-/**
251- * @brief Condition assertion.
252- * @details If the condition check fails then the OSAL panics with a
253- * message and halts.
254- * @note The condition is tested only if the @p OSAL_ENABLE_ASSERTIONS
255- * switch is enabled.
256- * @note The remark string is not currently used except for putting a
257- * comment in the code about the assertion.
258- *
259- * @param[in] c the condition to be verified to be true
260- * @param[in] remark a remark string
261- *
262- * @api
263- */
264-#define osalDbgAssert(c, remark) chDbgAssert(c, remark)
265-
266-/**
267- * @brief Function parameters check.
268- * @details If the condition check fails then the OSAL panics and halts.
269- * @note The condition is tested only if the @p OSAL_ENABLE_CHECKS switch
270- * is enabled.
271- *
272- * @param[in] c the condition to be verified to be true
273- *
274- * @api
275- */
276-#define osalDbgCheck(c) chDbgCheck(c)
277-
278-/**
279- * @brief I-Class state check.
280- */
281-#define osalDbgCheckClassI() chDbgCheckClassI()
282-
283-/**
284- * @brief S-Class state check.
285- */
286-#define osalDbgCheckClassS() chDbgCheckClassS()
287-/** @} */
288-
289-/**
290- * @name IRQ service routines wrappers
291- * @{
292- */
293-/**
294- * @brief Priority level verification macro.
295- */
296-#define OSAL_IRQ_IS_VALID_PRIORITY(n) CH_IRQ_IS_VALID_KERNEL_PRIORITY(n)
297-
298-/**
299- * @brief IRQ prologue code.
300- * @details This macro must be inserted at the start of all IRQ handlers.
301- */
302-#define OSAL_IRQ_PROLOGUE() CH_IRQ_PROLOGUE()
303-
304-/**
305- * @brief IRQ epilogue code.
306- * @details This macro must be inserted at the end of all IRQ handlers.
307- */
308-#define OSAL_IRQ_EPILOGUE() CH_IRQ_EPILOGUE()
309-
310-/**
311- * @brief IRQ handler function declaration.
312- * @details This macro hides the details of an ISR function declaration.
313- *
314- * @param[in] id a vector name as defined in @p vectors.s
315- */
316-#define OSAL_IRQ_HANDLER(id) CH_IRQ_HANDLER(id)
317-/** @} */
318-
319-/**
320- * @name Time conversion utilities
321- * @{
322- */
323-/**
324- * @brief Seconds to system ticks.
325- * @details Converts from seconds to system ticks number.
326- * @note The result is rounded upward to the next tick boundary.
327- *
328- * @param[in] secs number of seconds
329- * @return The number of ticks.
330- *
331- * @api
332- */
333-#define OSAL_S2I(secs) TIME_S2I(secs)
334-
335-/**
336- * @brief Milliseconds to system ticks.
337- * @details Converts from milliseconds to system ticks number.
338- * @note The result is rounded upward to the next tick boundary.
339- *
340- * @param[in] msecs number of milliseconds
341- * @return The number of ticks.
342- *
343- * @api
344- */
345-#define OSAL_MS2I(msecs) TIME_MS2I(msecs)
346-
347-/**
348- * @brief Microseconds to system ticks.
349- * @details Converts from microseconds to system ticks number.
350- * @note The result is rounded upward to the next tick boundary.
351- *
352- * @param[in] usecs number of microseconds
353- * @return The number of ticks.
354- *
355- * @api
356- */
357-#define OSAL_US2I(usecs) TIME_US2I(usecs)
358-/** @} */
359-
360-/**
361- * @name Time conversion utilities for the realtime counter
362- * @{
363- */
364-/**
365- * @brief Seconds to realtime counter.
366- * @details Converts from seconds to realtime counter cycles.
367- * @note The macro assumes that @p freq >= @p 1.
368- *
369- * @param[in] freq clock frequency, in Hz, of the realtime counter
370- * @param[in] sec number of seconds
371- * @return The number of cycles.
372- *
373- * @api
374- */
375-#define OSAL_S2RTC(freq, sec) S2RTC(freq, sec)
376-
377-/**
378- * @brief Milliseconds to realtime counter.
379- * @details Converts from milliseconds to realtime counter cycles.
380- * @note The result is rounded upward to the next millisecond boundary.
381- * @note The macro assumes that @p freq >= @p 1000.
382- *
383- * @param[in] freq clock frequency, in Hz, of the realtime counter
384- * @param[in] msec number of milliseconds
385- * @return The number of cycles.
386- *
387- * @api
388- */
389-#define OSAL_MS2RTC(freq, msec) MS2RTC(freq, msec)
390-
391-/**
392- * @brief Microseconds to realtime counter.
393- * @details Converts from microseconds to realtime counter cycles.
394- * @note The result is rounded upward to the next microsecond boundary.
395- * @note The macro assumes that @p freq >= @p 1000000.
396- *
397- * @param[in] freq clock frequency, in Hz, of the realtime counter
398- * @param[in] usec number of microseconds
399- * @return The number of cycles.
400- *
401- * @api
402- */
403-#define OSAL_US2RTC(freq, usec) US2RTC(freq, usec)
404-/** @} */
405-
406-/**
407- * @name Sleep macros using absolute time
408- * @{
409- */
410-/**
411- * @brief Delays the invoking thread for the specified number of seconds.
412- * @note The specified time is rounded up to a value allowed by the real
413- * system tick clock.
414- * @note The maximum specifiable value is implementation dependent.
415- *
416- * @param[in] secs time in seconds, must be different from zero
417- *
418- * @api
419- */
420-#define osalThreadSleepSeconds(secs) osalThreadSleep(OSAL_S2I(secs))
421-
422-/**
423- * @brief Delays the invoking thread for the specified number of
424- * milliseconds.
425- * @note The specified time is rounded up to a value allowed by the real
426- * system tick clock.
427- * @note The maximum specifiable value is implementation dependent.
428- *
429- * @param[in] msecs time in milliseconds, must be different from zero
430- *
431- * @api
432- */
433-#define osalThreadSleepMilliseconds(msecs) osalThreadSleep(OSAL_MS2I(msecs))
434-
435-/**
436- * @brief Delays the invoking thread for the specified number of
437- * microseconds.
438- * @note The specified time is rounded up to a value allowed by the real
439- * system tick clock.
440- * @note The maximum specifiable value is implementation dependent.
441- *
442- * @param[in] usecs time in microseconds, must be different from zero
443- *
444- * @api
445- */
446-#define osalThreadSleepMicroseconds(usecs) osalThreadSleep(OSAL_US2I(usecs))
447-/** @} */
448-
449-/*===========================================================================*/
450-/* External declarations. */
451-/*===========================================================================*/
452-
453-#ifdef __cplusplus
454-extern "C" {
455-#endif
456-
457-#ifdef __cplusplus
458-}
459-#endif
460-
461-/*===========================================================================*/
462-/* Module inline functions. */
463-/*===========================================================================*/
464-
465-/**
466- * @brief OSAL module initialization.
467- *
468- * @api
469- */
470-static inline void osalInit(void) {
471-
472-}
473-
474-/**
475- * @brief System halt with error message.
476- *
477- * @param[in] reason the halt message pointer
478- *
479- * @api
480- */
481-static inline void osalSysHalt(const char *reason) {
482-
483- chSysHalt(reason);
484-}
485-
486-/**
487- * @brief Disables interrupts globally.
488- *
489- * @special
490- */
491-static inline void osalSysDisable(void) {
492-
493- chSysDisable();
494-}
495-
496-/**
497- * @brief Enables interrupts globally.
498- *
499- * @special
500- */
501-static inline void osalSysEnable(void) {
502-
503- chSysEnable();
504-}
505-
506-/**
507- * @brief Enters a critical zone from thread context.
508- * @note This function cannot be used for reentrant critical zones.
509- *
510- * @special
511- */
512-static inline void osalSysLock(void) {
513-
514- chSysLock();
515-}
516-
517-/**
518- * @brief Leaves a critical zone from thread context.
519- * @note This function cannot be used for reentrant critical zones.
520- *
521- * @special
522- */
523-static inline void osalSysUnlock(void) {
524-
525- chSysUnlock();
526-}
527-
528-/**
529- * @brief Enters a critical zone from ISR context.
530- * @note This function cannot be used for reentrant critical zones.
531- *
532- * @special
533- */
534-static inline void osalSysLockFromISR(void) {
535-
536- chSysLockFromISR();
537-}
538-
539-/**
540- * @brief Leaves a critical zone from ISR context.
541- * @note This function cannot be used for reentrant critical zones.
542- *
543- * @special
544- */
545-static inline void osalSysUnlockFromISR(void) {
546-
547- chSysUnlockFromISR();
548-}
549-
550-/**
551- * @brief Returns the execution status and enters a critical zone.
552- * @details This functions enters into a critical zone and can be called
553- * from any context. Because its flexibility it is less efficient
554- * than @p chSysLock() which is preferable when the calling context
555- * is known.
556- * @post The system is in a critical zone.
557- *
558- * @return The previous system status, the encoding of this
559- * status word is architecture-dependent and opaque.
560- *
561- * @xclass
562- */
563-static inline syssts_t osalSysGetStatusAndLockX(void) {
564-
565- return chSysGetStatusAndLockX();
566-}
567-
568-/**
569- * @brief Restores the specified execution status and leaves a critical zone.
570- * @note A call to @p chSchRescheduleS() is automatically performed
571- * if exiting the critical zone and if not in ISR context.
572- *
573- * @param[in] sts the system status to be restored.
574- *
575- * @xclass
576- */
577-static inline void osalSysRestoreStatusX(syssts_t sts) {
578-
579- chSysRestoreStatusX(sts);
580-}
581-
582-/**
583- * @brief Polled delay.
584- * @note The real delay is always few cycles in excess of the specified
585- * value.
586- *
587- * @param[in] cycles number of cycles
588- *
589- * @xclass
590- */
591-#if (PORT_SUPPORTS_RT == TRUE) || defined(__DOXYGEN__)
592-static inline void osalSysPolledDelayX(rtcnt_t cycles) {
593-
594- chSysPolledDelayX(cycles);
595-}
596-#endif
597-
598-/**
599- * @brief Systick callback for the underlying OS.
600- * @note This callback is only defined if the OSAL requires such a
601- * service from the HAL.
602- */
603-#if (OSAL_ST_MODE != OSAL_ST_MODE_NONE) || defined(__DOXYGEN__)
604-static inline void osalOsTimerHandlerI(void) {
605-
606- chSysTimerHandlerI();
607-}
608-#endif
609-
610-/**
611- * @brief Checks if a reschedule is required and performs it.
612- * @note I-Class functions invoked from thread context must not reschedule
613- * by themselves, an explicit reschedule using this function is
614- * required in this scenario.
615- * @note Not implemented in this simplified OSAL.
616- *
617- * @sclass
618- */
619-static inline void osalOsRescheduleS(void) {
620-
621- chSchRescheduleS();
622-}
623-
624-/**
625- * @brief Current system time.
626- * @details Returns the number of system ticks since the @p osalInit()
627- * invocation.
628- * @note The counter can reach its maximum and then restart from zero.
629- * @note This function can be called from any context but its atomicity
630- * is not guaranteed on architectures whose word size is less than
631- * @p systime_t size.
632- *
633- * @return The system time in ticks.
634- *
635- * @xclass
636- */
637-static inline systime_t osalOsGetSystemTimeX(void) {
638-
639- return chVTGetSystemTimeX();
640-}
641-
642-/**
643- * @brief Adds an interval to a system time returning a system time.
644- *
645- * @param[in] systime base system time
646- * @param[in] interval interval to be added
647- * @return The new system time.
648- *
649- * @xclass
650- */
651-static inline systime_t osalTimeAddX(systime_t systime,
652- sysinterval_t interval) {
653-
654- return chTimeAddX(systime, interval);
655-}
656-
657-/**
658- * @brief Subtracts two system times returning an interval.
659- *
660- * @param[in] start first system time
661- * @param[in] end second system time
662- * @return The interval representing the time difference.
663- *
664- * @xclass
665- */
666-static inline sysinterval_t osalTimeDiffX(systime_t start, systime_t end) {
667-
668- return chTimeDiffX(start, end);
669-}
670-
671-/**
672- * @brief Checks if the specified time is within the specified time window.
673- * @note When start==end then the function returns always true because the
674- * whole time range is specified.
675- * @note This function can be called from any context.
676- *
677- * @param[in] time the time to be verified
678- * @param[in] start the start of the time window (inclusive)
679- * @param[in] end the end of the time window (non inclusive)
680- * @retval true current time within the specified time window.
681- * @retval false current time not within the specified time window.
682- *
683- * @xclass
684- */
685-static inline bool osalTimeIsInRangeX(systime_t time,
686- systime_t start,
687- systime_t end) {
688-
689- return chTimeIsInRangeX(time, start, end);
690-}
691-
692-/**
693- * @brief Suspends the invoking thread for the specified time.
694- *
695- * @param[in] time the delay in system ticks, the special values are
696- * handled as follow:
697- * - @a TIME_INFINITE is allowed but interpreted as a
698- * normal time specification.
699- * - @a TIME_IMMEDIATE this value is not allowed.
700- * .
701- *
702- * @sclass
703- */
704-static inline void osalThreadSleepS(sysinterval_t time) {
705-
706- chThdSleepS(time);
707-}
708-
709-/**
710- * @brief Suspends the invoking thread for the specified time.
711- *
712- * @param[in] time the delay in system ticks, the special values are
713- * handled as follow:
714- * - @a TIME_INFINITE is allowed but interpreted as a
715- * normal time specification.
716- * - @a TIME_IMMEDIATE this value is not allowed.
717- * .
718- *
719- * @api
720- */
721-static inline void osalThreadSleep(sysinterval_t time) {
722-
723- chThdSleep(time);
724-}
725-
726-/**
727- * @brief Sends the current thread sleeping and sets a reference variable.
728- * @note This function must reschedule, it can only be called from thread
729- * context.
730- *
731- * @param[in] trp a pointer to a thread reference object
732- * @return The wake up message.
733- *
734- * @sclass
735- */
736-static inline msg_t osalThreadSuspendS(thread_reference_t *trp) {
737-
738- return chThdSuspendTimeoutS(trp, TIME_INFINITE);
739-}
740-
741-/**
742- * @brief Sends the current thread sleeping and sets a reference variable.
743- * @note This function must reschedule, it can only be called from thread
744- * context.
745- *
746- * @param[in] trp a pointer to a thread reference object
747- * @param[in] timeout the timeout in system ticks, the special values are
748- * handled as follow:
749- * - @a TIME_INFINITE the thread enters an infinite sleep
750- * state.
751- * - @a TIME_IMMEDIATE the thread is not enqueued and
752- * the function returns @p MSG_TIMEOUT as if a timeout
753- * occurred.
754- * .
755- * @return The wake up message.
756- * @retval MSG_TIMEOUT if the operation timed out.
757- *
758- * @sclass
759- */
760-static inline msg_t osalThreadSuspendTimeoutS(thread_reference_t *trp,
761- sysinterval_t timeout) {
762-
763- return chThdSuspendTimeoutS(trp, timeout);
764-}
765-
766-/**
767- * @brief Wakes up a thread waiting on a thread reference object.
768- * @note This function must not reschedule because it can be called from
769- * ISR context.
770- *
771- * @param[in] trp a pointer to a thread reference object
772- * @param[in] msg the message code
773- *
774- * @iclass
775- */
776-static inline void osalThreadResumeI(thread_reference_t *trp, msg_t msg) {
777-
778- chThdResumeI(trp, msg);
779-}
780-
781-/**
782- * @brief Wakes up a thread waiting on a thread reference object.
783- * @note This function must reschedule, it can only be called from thread
784- * context.
785- *
786- * @param[in] trp a pointer to a thread reference object
787- * @param[in] msg the message code
788- *
789- * @iclass
790- */
791-static inline void osalThreadResumeS(thread_reference_t *trp, msg_t msg) {
792-
793- chThdResumeI(trp, msg);
794- chSchRescheduleS();
795-}
796-
797-/**
798- * @brief Initializes a threads queue object.
799- *
800- * @param[out] tqp pointer to the threads queue object
801- *
802- * @init
803- */
804-static inline void osalThreadQueueObjectInit(threads_queue_t *tqp) {
805-
806- chThdQueueObjectInit(tqp);
807-}
808-
809-/**
810- * @brief Enqueues the caller thread.
811- * @details The caller thread is enqueued and put to sleep until it is
812- * dequeued or the specified timeouts expires.
813- *
814- * @param[in] tqp pointer to the threads queue object
815- * @param[in] time the timeout in system ticks, the special values are
816- * handled as follow:
817- * - @a TIME_INFINITE the thread enters an infinite sleep
818- * state.
819- * - @a TIME_IMMEDIATE the thread is not enqueued and
820- * the function returns @p MSG_TIMEOUT as if a timeout
821- * occurred.
822- * .
823- * @return The message from @p osalQueueWakeupOneI() or
824- * @p osalQueueWakeupAllI() functions.
825- * @retval MSG_TIMEOUT if the thread has not been dequeued within the
826- * specified timeout or if the function has been
827- * invoked with @p TIME_IMMEDIATE as timeout
828- * specification.
829- *
830- * @sclass
831- */
832-static inline msg_t osalThreadEnqueueTimeoutS(threads_queue_t *tqp,
833- sysinterval_t time) {
834-
835- return chThdEnqueueTimeoutS(tqp, time);
836-}
837-
838-/**
839- * @brief Dequeues and wakes up one thread from the queue, if any.
840- *
841- * @param[in] tqp pointer to the threads queue object
842- * @param[in] msg the message code
843- *
844- * @iclass
845- */
846-static inline void osalThreadDequeueNextI(threads_queue_t *tqp, msg_t msg) {
847-
848- chThdDequeueNextI(tqp, msg);
849-}
850-
851-/**
852- * @brief Dequeues and wakes up all threads from the queue.
853- *
854- * @param[in] tqp pointer to the threads queue object
855- * @param[in] msg the message code
856- *
857- * @iclass
858- */
859-static inline void osalThreadDequeueAllI(threads_queue_t *tqp, msg_t msg) {
860-
861- chThdDequeueAllI(tqp, msg);
862-}
863-
864-/**
865- * @brief Initializes an event source object.
866- *
867- * @param[out] esp pointer to the event source object
868- *
869- * @init
870- */
871-static inline void osalEventObjectInit(event_source_t *esp) {
872-
873- osalDbgCheck(esp != NULL);
874-
875- esp->flags = (eventflags_t)0;
876- esp->cb = NULL;
877- esp->param = NULL;
878-}
879-
880-/**
881- * @brief Add flags to an event source object.
882- *
883- * @param[in] esp pointer to the event flags object
884- * @param[in] flags flags to be ORed to the flags mask
885- *
886- * @iclass
887- */
888-static inline void osalEventBroadcastFlagsI(event_source_t *esp,
889- eventflags_t flags) {
890-
891- osalDbgCheck(esp != NULL);
892-
893- esp->flags |= flags;
894- if (esp->cb != NULL) {
895- esp->cb(esp);
896- }
897-}
898-
899-/**
900- * @brief Add flags to an event source object.
901- *
902- * @param[in] esp pointer to the event flags object
903- * @param[in] flags flags to be ORed to the flags mask
904- *
905- * @iclass
906- */
907-static inline void osalEventBroadcastFlags(event_source_t *esp,
908- eventflags_t flags) {
909-
910- osalDbgCheck(esp != NULL);
911-
912- chSysLock();
913- esp->flags |= flags;
914- if (esp->cb != NULL) {
915- esp->cb(esp);
916- }
917- chSysUnlock();
918-}
919-
920-/**
921- * @brief Event callback setup.
922- * @note The callback is invoked from ISR context and can
923- * only invoke I-Class functions. The callback is meant
924- * to wakeup the task that will handle the event by
925- * calling @p osalEventGetAndClearFlagsI().
926- *
927- * @param[in] esp pointer to the event flags object
928- * @param[in] cb pointer to the callback function
929- * @param[in] param parameter to be passed to the callback function
930- *
931- * @api
932- */
933-static inline void osalEventSetCallback(event_source_t *esp,
934- eventcallback_t cb,
935- void *param) {
936-
937- osalDbgCheck(esp != NULL);
938-
939- esp->cb = cb;
940- esp->param = param;
941-}
942-
943-/**
944- * @brief Initializes s @p mutex_t object.
945- *
946- * @param[out] mp pointer to the @p mutex_t object
947- *
948- * @init
949- */
950-static inline void osalMutexObjectInit(mutex_t *mp) {
951-
952- chSemObjectInit((semaphore_t *)mp, (cnt_t)1);
953-}
954-
955-/**
956- * @brief Locks the specified mutex.
957- * @post The mutex is locked and inserted in the per-thread stack of owned
958- * mutexes.
959- *
960- * @param[in,out] mp pointer to the @p mutex_t object
961- *
962- * @api
963- */
964-static inline void osalMutexLock(mutex_t *mp) {
965-
966- (void) chSemWait((semaphore_t *)mp);
967-}
968-
969-/**
970- * @brief Unlocks the specified mutex.
971- * @note The HAL guarantees to release mutex in reverse lock order. The
972- * mutex being unlocked is guaranteed to be the last locked mutex
973- * by the invoking thread.
974- * The implementation can rely on this behavior and eventually
975- * ignore the @p mp parameter which is supplied in order to support
976- * those OSes not supporting a stack of the owned mutexes.
977- *
978- * @param[in,out] mp pointer to the @p mutex_t object
979- *
980- * @api
981- */
982-static inline void osalMutexUnlock(mutex_t *mp) {
983-
984- chSemSignal((semaphore_t *)mp);
985-}
986-
987-#endif /* OSAL_H */
988-
989-/** @} */
--- trunk/os/hal/osal/rt/osal.c (revision 12948)
+++ trunk/os/hal/osal/rt/osal.c (nonexistent)
@@ -1,51 +0,0 @@
1-/*
2- ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3-
4- Licensed under the Apache License, Version 2.0 (the "License");
5- you may not use this file except in compliance with the License.
6- You may obtain a copy of the License at
7-
8- http://www.apache.org/licenses/LICENSE-2.0
9-
10- Unless required by applicable law or agreed to in writing, software
11- distributed under the License is distributed on an "AS IS" BASIS,
12- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- See the License for the specific language governing permissions and
14- limitations under the License.
15-*/
16-
17-/**
18- * @file osal.c
19- * @brief OSAL module code.
20- *
21- * @addtogroup OSAL
22- * @{
23- */
24-
25-#include "osal.h"
26-
27-/*===========================================================================*/
28-/* Module local definitions. */
29-/*===========================================================================*/
30-
31-/*===========================================================================*/
32-/* Module exported variables. */
33-/*===========================================================================*/
34-
35-/*===========================================================================*/
36-/* Module local types. */
37-/*===========================================================================*/
38-
39-/*===========================================================================*/
40-/* Module local variables. */
41-/*===========================================================================*/
42-
43-/*===========================================================================*/
44-/* Module local functions. */
45-/*===========================================================================*/
46-
47-/*===========================================================================*/
48-/* Module exported functions. */
49-/*===========================================================================*/
50-
51-/** @} */
--- trunk/os/hal/osal/rt/osal.h (revision 12948)
+++ trunk/os/hal/osal/rt/osal.h (nonexistent)
@@ -1,1028 +0,0 @@
1-/*
2- ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3-
4- Licensed under the Apache License, Version 2.0 (the "License");
5- you may not use this file except in compliance with the License.
6- You may obtain a copy of the License at
7-
8- http://www.apache.org/licenses/LICENSE-2.0
9-
10- Unless required by applicable law or agreed to in writing, software
11- distributed under the License is distributed on an "AS IS" BASIS,
12- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- See the License for the specific language governing permissions and
14- limitations under the License.
15-*/
16-
17-/**
18- * @file osal.h
19- * @brief OSAL module header.
20- *
21- * @addtogroup OSAL
22- * @{
23- */
24-
25-#ifndef OSAL_H
26-#define OSAL_H
27-
28-#include <stddef.h>
29-#include <stdint.h>
30-#include <stdbool.h>
31-
32-#include "ch.h"
33-
34-/*===========================================================================*/
35-/* Module constants. */
36-/*===========================================================================*/
37-
38-/**
39- * @name Common constants
40- * @{
41- */
42-#if !defined(FALSE) || defined(__DOXYGEN__)
43-#define FALSE 0
44-#endif
45-
46-#if !defined(TRUE) || defined(__DOXYGEN__)
47-#define TRUE 1
48-#endif
49-
50-#define OSAL_SUCCESS false
51-#define OSAL_FAILED true
52-/** @} */
53-
54-#if 0
55-/**
56- * @name Messages
57- * @{
58- */
59-#define MSG_OK (msg_t)0
60-#define MSG_TIMEOUT (msg_t)-1
61-#define MSG_RESET (msg_t)-2
62-/** @} */
63-#endif
64-
65-#if 0
66-/**
67- * @name Special time constants
68- * @{
69- */
70-#define TIME_IMMEDIATE ((sysinterval_t)0)
71-#define TIME_INFINITE ((sysinterval_t)-1)
72-/** @} */
73-#endif
74-
75-/**
76- * @name Systick modes.
77- * @{
78- */
79-#define OSAL_ST_MODE_NONE 0
80-#define OSAL_ST_MODE_PERIODIC 1
81-#define OSAL_ST_MODE_FREERUNNING 2
82-/** @} */
83-
84-/**
85- * @name Systick parameters.
86- * @{
87- */
88-/**
89- * @brief Size in bits of the @p systick_t type.
90- */
91-#define OSAL_ST_RESOLUTION CH_CFG_ST_RESOLUTION
92-
93-/**
94- * @brief Required systick frequency or resolution.
95- */
96-#define OSAL_ST_FREQUENCY CH_CFG_ST_FREQUENCY
97-
98-/**
99- * @brief Systick mode required by the underlying OS.
100- */
101-#if (CH_CFG_ST_TIMEDELTA == 0) || defined(__DOXYGEN__)
102-#define OSAL_ST_MODE OSAL_ST_MODE_PERIODIC
103-#else
104-#define OSAL_ST_MODE OSAL_ST_MODE_FREERUNNING
105-#endif
106-/** @} */
107-
108-/*===========================================================================*/
109-/* Module pre-compile time settings. */
110-/*===========================================================================*/
111-
112-/*===========================================================================*/
113-/* Derived constants and error checks. */
114-/*===========================================================================*/
115-
116-#if !(OSAL_ST_MODE == OSAL_ST_MODE_NONE) && \
117- !(OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC) && \
118- !(OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING)
119-#error "invalid OSAL_ST_MODE setting in osal.h"
120-#endif
121-
122-#if (OSAL_ST_RESOLUTION != 16) && (OSAL_ST_RESOLUTION != 32)
123-#error "invalid OSAL_ST_RESOLUTION, must be 16 or 32"
124-#endif
125-
126-/*===========================================================================*/
127-/* Module data structures and types. */
128-/*===========================================================================*/
129-
130-#if 0
131-/**
132- * @brief Type of a system status word.
133- */
134-typedef uint32_t syssts_t;
135-#endif
136-
137-#if 0
138-/**
139- * @brief Type of a message.
140- */
141-typedef int32_t msg_t;
142-#endif
143-
144-#if 0
145-/**
146- * @brief Type of system time counter.
147- */
148-typedef uint32_t systime_t;
149-#endif
150-
151-#if 0
152-/**
153- * @brief Type of system time interval.
154- */
155-typedef uint32_t sysinterval_t;
156-#endif
157-
158-#if 0
159-/**
160- * @brief Type of realtime counter.
161- */
162-typedef uint32_t rtcnt_t;
163-#endif
164-
165-#if 0
166-/**
167- * @brief Type of a thread reference.
168- */
169-typedef thread_t * thread_reference_t;
170-#endif
171-
172-#if 0
173-/**
174- * @brief Type of an event flags mask.
175- */
176-typedef uint32_t eventflags_t;
177-#endif
178-
179-#if (CH_CFG_USE_EVENTS == FALSE) || defined(__DOXYGEN__)
180-/**
181- * @brief Type of an event flags object.
182- * @note The content of this structure is not part of the API and should
183- * not be relied upon. Implementers may define this structure in
184- * an entirely different way.
185- * @note Retrieval and clearing of the flags are not defined in this
186- * API and are implementation-dependent.
187- */
188-typedef struct event_source event_source_t;
189-
190-/**
191- * @brief Type of an event source callback.
192- * @note This type is not part of the OSAL API and is provided
193- * exclusively as an example and for convenience.
194- */
195-typedef void (*eventcallback_t)(event_source_t *esp);
196-
197-/**
198- * @brief Events source object.
199- * @note The content of this structure is not part of the API and should
200- * not be relied upon. Implementers may define this structure in
201- * an entirely different way.
202- * @note Retrieval and clearing of the flags are not defined in this
203- * API and are implementation-dependent.
204- */
205-struct event_source {
206- volatile eventflags_t flags; /**< @brief Stored event flags. */
207- eventcallback_t cb; /**< @brief Event source callback. */
208- void *param; /**< @brief User defined field. */
209-};
210-#endif /* CH_CFG_USE_EVENTS == FALSE */
211-
212-/**
213- * @brief Type of a mutex.
214- * @note If the OS does not support mutexes or there is no OS then the
215- * mechanism can be simulated.
216- */
217-#if CH_CFG_USE_MUTEXES || defined(__DOXYGEN__)
218-#elif CH_CFG_USE_SEMAPHORES
219-typedef semaphore_t mutex_t;
220-#else
221-typedef uint32_t mutex_t;
222-#endif
223-
224-#if 0
225-/**
226- * @brief Type of a thread queue.
227- * @details A thread queue is a queue of sleeping threads, queued threads
228- * can be dequeued one at time or all together.
229- * @note In this implementation it is implemented as a single reference
230- * because there are no real threads.
231- */
232-typedef struct {
233- thread_reference_t tr;
234-} threads_queue_t;
235-#endif
236-
237-/*===========================================================================*/
238-/* Module macros. */
239-/*===========================================================================*/
240-
241-/**
242- * @name Debug related macros
243- * @{
244- */
245-/**
246- * @brief Condition assertion.
247- * @details If the condition check fails then the OSAL panics with a
248- * message and halts.
249- * @note The condition is tested only if the @p OSAL_ENABLE_ASSERTIONS
250- * switch is enabled.
251- * @note The remark string is not currently used except for putting a
252- * comment in the code about the assertion.
253- *
254- * @param[in] c the condition to be verified to be true
255- * @param[in] remark a remark string
256- *
257- * @api
258- */
259-#define osalDbgAssert(c, remark) chDbgAssert(c, remark)
260-
261-/**
262- * @brief Function parameters check.
263- * @details If the condition check fails then the OSAL panics and halts.
264- * @note The condition is tested only if the @p OSAL_ENABLE_CHECKS switch
265- * is enabled.
266- *
267- * @param[in] c the condition to be verified to be true
268- *
269- * @api
270- */
271-#define osalDbgCheck(c) chDbgCheck(c)
272-
273-/**
274- * @brief I-Class state check.
275- * @note Not implemented in this simplified OSAL.
276- */
277-#define osalDbgCheckClassI() chDbgCheckClassI()
278-
279-/**
280- * @brief S-Class state check.
281- * @note Not implemented in this simplified OSAL.
282- */
283-#define osalDbgCheckClassS() chDbgCheckClassS()
284-/** @} */
285-
286-/**
287- * @name IRQ service routines wrappers
288- * @{
289- */
290-/**
291- * @brief Priority level verification macro.
292- */
293-#define OSAL_IRQ_IS_VALID_PRIORITY(n) CH_IRQ_IS_VALID_KERNEL_PRIORITY(n)
294-
295-/**
296- * @brief IRQ prologue code.
297- * @details This macro must be inserted at the start of all IRQ handlers.
298- */
299-#define OSAL_IRQ_PROLOGUE() CH_IRQ_PROLOGUE()
300-
301-/**
302- * @brief IRQ epilogue code.
303- * @details This macro must be inserted at the end of all IRQ handlers.
304- */
305-#define OSAL_IRQ_EPILOGUE() CH_IRQ_EPILOGUE()
306-
307-/**
308- * @brief IRQ handler function declaration.
309- * @details This macro hides the details of an ISR function declaration.
310- *
311- * @param[in] id a vector name as defined in @p vectors.s
312- */
313-#define OSAL_IRQ_HANDLER(id) CH_IRQ_HANDLER(id)
314-/** @} */
315-
316-/**
317- * @name Time conversion utilities
318- * @{
319- */
320-/**
321- * @brief Seconds to system ticks.
322- * @details Converts from seconds to system ticks number.
323- * @note The result is rounded upward to the next tick boundary.
324- *
325- * @param[in] secs number of seconds
326- * @return The number of ticks.
327- *
328- * @api
329- */
330-#define OSAL_S2I(secs) TIME_S2I(secs)
331-
332-/**
333- * @brief Milliseconds to system ticks.
334- * @details Converts from milliseconds to system ticks number.
335- * @note The result is rounded upward to the next tick boundary.
336- *
337- * @param[in] msecs number of milliseconds
338- * @return The number of ticks.
339- *
340- * @api
341- */
342-#define OSAL_MS2I(msecs) TIME_MS2I(msecs)
343-
344-/**
345- * @brief Microseconds to system ticks.
346- * @details Converts from microseconds to system ticks number.
347- * @note The result is rounded upward to the next tick boundary.
348- *
349- * @param[in] usecs number of microseconds
350- * @return The number of ticks.
351- *
352- * @api
353- */
354-#define OSAL_US2I(usecs) TIME_US2I(usecs)
355-/** @} */
356-
357-/**
358- * @name Time conversion utilities for the realtime counter
359- * @{
360- */
361-/**
362- * @brief Seconds to realtime counter.
363- * @details Converts from seconds to realtime counter cycles.
364- * @note The macro assumes that @p freq >= @p 1.
365- *
366- * @param[in] freq clock frequency, in Hz, of the realtime counter
367- * @param[in] sec number of seconds
368- * @return The number of cycles.
369- *
370- * @api
371- */
372-#define OSAL_S2RTC(freq, sec) S2RTC(freq, sec)
373-
374-/**
375- * @brief Milliseconds to realtime counter.
376- * @details Converts from milliseconds to realtime counter cycles.
377- * @note The result is rounded upward to the next millisecond boundary.
378- * @note The macro assumes that @p freq >= @p 1000.
379- *
380- * @param[in] freq clock frequency, in Hz, of the realtime counter
381- * @param[in] msec number of milliseconds
382- * @return The number of cycles.
383- *
384- * @api
385- */
386-#define OSAL_MS2RTC(freq, msec) MS2RTC(freq, msec)
387-
388-/**
389- * @brief Microseconds to realtime counter.
390- * @details Converts from microseconds to realtime counter cycles.
391- * @note The result is rounded upward to the next microsecond boundary.
392- * @note The macro assumes that @p freq >= @p 1000000.
393- *
394- * @param[in] freq clock frequency, in Hz, of the realtime counter
395- * @param[in] usec number of microseconds
396- * @return The number of cycles.
397- *
398- * @api
399- */
400-#define OSAL_US2RTC(freq, usec) US2RTC(freq, usec)
401-/** @} */
402-
403-/**
404- * @name Sleep macros using absolute time
405- * @{
406- */
407-/**
408- * @brief Delays the invoking thread for the specified number of seconds.
409- * @note The specified time is rounded up to a value allowed by the real
410- * system tick clock.
411- * @note The maximum specifiable value is implementation dependent.
412- *
413- * @param[in] secs time in seconds, must be different from zero
414- *
415- * @api
416- */
417-#define osalThreadSleepSeconds(secs) osalThreadSleep(OSAL_S2I(secs))
418-
419-/**
420- * @brief Delays the invoking thread for the specified number of
421- * milliseconds.
422- * @note The specified time is rounded up to a value allowed by the real
423- * system tick clock.
424- * @note The maximum specifiable value is implementation dependent.
425- *
426- * @param[in] msecs time in milliseconds, must be different from zero
427- *
428- * @api
429- */
430-#define osalThreadSleepMilliseconds(msecs) osalThreadSleep(OSAL_MS2I(msecs))
431-
432-/**
433- * @brief Delays the invoking thread for the specified number of
434- * microseconds.
435- * @note The specified time is rounded up to a value allowed by the real
436- * system tick clock.
437- * @note The maximum specifiable value is implementation dependent.
438- *
439- * @param[in] usecs time in microseconds, must be different from zero
440- *
441- * @api
442- */
443-#define osalThreadSleepMicroseconds(usecs) osalThreadSleep(OSAL_US2I(usecs))
444-/** @} */
445-
446-/*===========================================================================*/
447-/* External declarations. */
448-/*===========================================================================*/
449-
450-#ifdef __cplusplus
451-extern "C" {
452-#endif
453-
454-#ifdef __cplusplus
455-}
456-#endif
457-
458-/*===========================================================================*/
459-/* Module inline functions. */
460-/*===========================================================================*/
461-
462-/**
463- * @brief OSAL module initialization.
464- *
465- * @api
466- */
467-static inline void osalInit(void) {
468-
469-}
470-
471-/**
472- * @brief System halt with error message.
473- *
474- * @param[in] reason the halt message pointer
475- *
476- * @api
477- */
478-static inline void osalSysHalt(const char *reason) {
479-
480- chSysHalt(reason);
481-}
482-
483-/**
484- * @brief Disables interrupts globally.
485- *
486- * @special
487- */
488-static inline void osalSysDisable(void) {
489-
490- chSysDisable();
491-}
492-
493-/**
494- * @brief Enables interrupts globally.
495- *
496- * @special
497- */
498-static inline void osalSysEnable(void) {
499-
500- chSysEnable();
501-}
502-
503-/**
504- * @brief Enters a critical zone from thread context.
505- * @note This function cannot be used for reentrant critical zones.
506- *
507- * @special
508- */
509-static inline void osalSysLock(void) {
510-
511- chSysLock();
512-}
513-
514-/**
515- * @brief Leaves a critical zone from thread context.
516- * @note This function cannot be used for reentrant critical zones.
517- *
518- * @special
519- */
520-static inline void osalSysUnlock(void) {
521-
522- chSysUnlock();
523-}
524-
525-/**
526- * @brief Enters a critical zone from ISR context.
527- * @note This function cannot be used for reentrant critical zones.
528- *
529- * @special
530- */
531-static inline void osalSysLockFromISR(void) {
532-
533- chSysLockFromISR();
534-}
535-
536-/**
537- * @brief Leaves a critical zone from ISR context.
538- * @note This function cannot be used for reentrant critical zones.
539- *
540- * @special
541- */
542-static inline void osalSysUnlockFromISR(void) {
543-
544- chSysUnlockFromISR();
545-}
546-
547-/**
548- * @brief Returns the execution status and enters a critical zone.
549- * @details This functions enters into a critical zone and can be called
550- * from any context. Because its flexibility it is less efficient
551- * than @p chSysLock() which is preferable when the calling context
552- * is known.
553- * @post The system is in a critical zone.
554- *
555- * @return The previous system status, the encoding of this
556- * status word is architecture-dependent and opaque.
557- *
558- * @xclass
559- */
560-static inline syssts_t osalSysGetStatusAndLockX(void) {
561-
562- return chSysGetStatusAndLockX();
563-}
564-
565-/**
566- * @brief Restores the specified execution status and leaves a critical zone.
567- * @note A call to @p chSchRescheduleS() is automatically performed
568- * if exiting the critical zone and if not in ISR context.
569- *
570- * @param[in] sts the system status to be restored.
571- *
572- * @xclass
573- */
574-static inline void osalSysRestoreStatusX(syssts_t sts) {
575-
576- chSysRestoreStatusX(sts);
577-}
578-
579-/**
580- * @brief Polled delay.
581- * @note The real delay is always few cycles in excess of the specified
582- * value.
583- *
584- * @param[in] cycles number of cycles
585- *
586- * @xclass
587- */
588-#if (PORT_SUPPORTS_RT == TRUE) || defined(__DOXYGEN__)
589-static inline void osalSysPolledDelayX(rtcnt_t cycles) {
590-
591- chSysPolledDelayX(cycles);
592-}
593-#endif
594-
595-/**
596- * @brief Systick callback for the underlying OS.
597- * @note This callback is only defined if the OSAL requires such a
598- * service from the HAL.
599- */
600-#if (OSAL_ST_MODE != OSAL_ST_MODE_NONE) || defined(__DOXYGEN__)
601-static inline void osalOsTimerHandlerI(void) {
602-
603- chSysTimerHandlerI();
604-}
605-#endif
606-
607-/**
608- * @brief Checks if a reschedule is required and performs it.
609- * @note I-Class functions invoked from thread context must not reschedule
610- * by themselves, an explicit reschedule using this function is
611- * required in this scenario.
612- * @note Not implemented in this simplified OSAL.
613- *
614- * @sclass
615- */
616-static inline void osalOsRescheduleS(void) {
617-
618- chSchRescheduleS();
619-}
620-
621-/**
622- * @brief Current system time.
623- * @details Returns the number of system ticks since the @p osalInit()
624- * invocation.
625- * @note The counter can reach its maximum and then restart from zero.
626- * @note This function can be called from any context but its atomicity
627- * is not guaranteed on architectures whose word size is less than
628- * @p systime_t size.
629- *
630- * @return The system time in ticks.
631- *
632- * @xclass
633- */
634-static inline systime_t osalOsGetSystemTimeX(void) {
635-
636- return chVTGetSystemTimeX();
637-}
638-
639-/**
640- * @brief Adds an interval to a system time returning a system time.
641- *
642- * @param[in] systime base system time
643- * @param[in] interval interval to be added
644- * @return The new system time.
645- *
646- * @xclass
647- */
648-static inline systime_t osalTimeAddX(systime_t systime,
649- sysinterval_t interval) {
650-
651- return chTimeAddX(systime, interval);
652-}
653-
654-/**
655- * @brief Subtracts two system times returning an interval.
656- *
657- * @param[in] start first system time
658- * @param[in] end second system time
659- * @return The interval representing the time difference.
660- *
661- * @xclass
662- */
663-static inline sysinterval_t osalTimeDiffX(systime_t start, systime_t end) {
664-
665- return chTimeDiffX(start, end);
666-}
667-
668-/**
669- * @brief Checks if the specified time is within the specified time window.
670- * @note When start==end then the function returns always true because the
671- * whole time range is specified.
672- * @note This function can be called from any context.
673- *
674- * @param[in] time the time to be verified
675- * @param[in] start the start of the time window (inclusive)
676- * @param[in] end the end of the time window (non inclusive)
677- * @retval true current time within the specified time window.
678- * @retval false current time not within the specified time window.
679- *
680- * @xclass
681- */
682-static inline bool osalTimeIsInRangeX(systime_t time,
683- systime_t start,
684- systime_t end) {
685-
686- return chTimeIsInRangeX(time, start, end);
687-}
688-
689-/**
690- * @brief Suspends the invoking thread for the specified time.
691- *
692- * @param[in] delay the delay in system ticks, the special values are
693- * handled as follow:
694- * - @a TIME_INFINITE is allowed but interpreted as a
695- * normal time specification.
696- * - @a TIME_IMMEDIATE this value is not allowed.
697- * .
698- *
699- * @sclass
700- */
701-static inline void osalThreadSleepS(sysinterval_t delay) {
702-
703- chThdSleepS(delay);
704-}
705-
706-/**
707- * @brief Suspends the invoking thread for the specified time.
708- *
709- * @param[in] delay the delay in system ticks, the special values are
710- * handled as follow:
711- * - @a TIME_INFINITE is allowed but interpreted as a
712- * normal time specification.
713- * - @a TIME_IMMEDIATE this value is not allowed.
714- * .
715- *
716- * @api
717- */
718-static inline void osalThreadSleep(sysinterval_t delay) {
719-
720- chThdSleep(delay);
721-}
722-
723-/**
724- * @brief Sends the current thread sleeping and sets a reference variable.
725- * @note This function must reschedule, it can only be called from thread
726- * context.
727- *
728- * @param[in] trp a pointer to a thread reference object
729- * @return The wake up message.
730- *
731- * @sclass
732- */
733-static inline msg_t osalThreadSuspendS(thread_reference_t *trp) {
734-
735- return chThdSuspendTimeoutS(trp, TIME_INFINITE);
736-}
737-
738-/**
739- * @brief Sends the current thread sleeping and sets a reference variable.
740- * @note This function must reschedule, it can only be called from thread
741- * context.
742- *
743- * @param[in] trp a pointer to a thread reference object
744- * @param[in] timeout the timeout in system ticks, the special values are
745- * handled as follow:
746- * - @a TIME_INFINITE the thread enters an infinite sleep
747- * state.
748- * - @a TIME_IMMEDIATE the thread is not enqueued and
749- * the function returns @p MSG_TIMEOUT as if a timeout
750- * occurred.
751- * .
752- * @return The wake up message.
753- * @retval MSG_TIMEOUT if the operation timed out.
754- *
755- * @sclass
756- */
757-static inline msg_t osalThreadSuspendTimeoutS(thread_reference_t *trp,
758- sysinterval_t timeout) {
759-
760- return chThdSuspendTimeoutS(trp, timeout);
761-}
762-
763-/**
764- * @brief Wakes up a thread waiting on a thread reference object.
765- * @note This function must not reschedule because it can be called from
766- * ISR context.
767- *
768- * @param[in] trp a pointer to a thread reference object
769- * @param[in] msg the message code
770- *
771- * @iclass
772- */
773-static inline void osalThreadResumeI(thread_reference_t *trp, msg_t msg) {
774-
775- chThdResumeI(trp, msg);
776-}
777-
778-/**
779- * @brief Wakes up a thread waiting on a thread reference object.
780- * @note This function must reschedule, it can only be called from thread
781- * context.
782- *
783- * @param[in] trp a pointer to a thread reference object
784- * @param[in] msg the message code
785- *
786- * @iclass
787- */
788-static inline void osalThreadResumeS(thread_reference_t *trp, msg_t msg) {
789-
790- chThdResumeS(trp, msg);
791-}
792-
793-/**
794- * @brief Initializes a threads queue object.
795- *
796- * @param[out] tqp pointer to the threads queue object
797- *
798- * @init
799- */
800-static inline void osalThreadQueueObjectInit(threads_queue_t *tqp) {
801-
802- chThdQueueObjectInit(tqp);
803-}
804-
805-/**
806- * @brief Enqueues the caller thread.
807- * @details The caller thread is enqueued and put to sleep until it is
808- * dequeued or the specified timeouts expires.
809- *
810- * @param[in] tqp pointer to the threads queue object
811- * @param[in] timeout the timeout in system ticks, the special values are
812- * handled as follow:
813- * - @a TIME_INFINITE the thread enters an infinite sleep
814- * state.
815- * - @a TIME_IMMEDIATE the thread is not enqueued and
816- * the function returns @p MSG_TIMEOUT as if a timeout
817- * occurred.
818- * .
819- * @return The message from @p osalQueueWakeupOneI() or
820- * @p osalQueueWakeupAllI() functions.
821- * @retval MSG_TIMEOUT if the thread has not been dequeued within the
822- * specified timeout or if the function has been
823- * invoked with @p TIME_IMMEDIATE as timeout
824- * specification.
825- *
826- * @sclass
827- */
828-static inline msg_t osalThreadEnqueueTimeoutS(threads_queue_t *tqp,
829- sysinterval_t timeout) {
830-
831- return chThdEnqueueTimeoutS(tqp, timeout);
832-}
833-
834-/**
835- * @brief Dequeues and wakes up one thread from the queue, if any.
836- *
837- * @param[in] tqp pointer to the threads queue object
838- * @param[in] msg the message code
839- *
840- * @iclass
841- */
842-static inline void osalThreadDequeueNextI(threads_queue_t *tqp, msg_t msg) {
843-
844- chThdDequeueNextI(tqp, msg);
845-}
846-
847-/**
848- * @brief Dequeues and wakes up all threads from the queue.
849- *
850- * @param[in] tqp pointer to the threads queue object
851- * @param[in] msg the message code
852- *
853- * @iclass
854- */
855-static inline void osalThreadDequeueAllI(threads_queue_t *tqp, msg_t msg) {
856-
857- chThdDequeueAllI(tqp, msg);
858-}
859-
860-#if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__)
861-/**
862- * @brief Initializes an event source object.
863- *
864- * @param[out] esp pointer to the event source object
865- *
866- * @init
867- */
868-static inline void osalEventObjectInit(event_source_t *esp) {
869-
870- chEvtObjectInit(esp);
871-}
872-#else
873-static inline void osalEventObjectInit(event_source_t *esp) {
874-
875- osalDbgCheck(esp != NULL);
876-
877- esp->flags = (eventflags_t)0;
878- esp->cb = NULL;
879- esp->param = NULL;
880-}
881-#endif
882-
883-#if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__)
884-/**
885- * @brief Add flags to an event source object.
886- *
887- * @param[in] esp pointer to the event flags object
888- * @param[in] flags flags to be ORed to the flags mask
889- *
890- * @iclass
891- */
892-static inline void osalEventBroadcastFlagsI(event_source_t *esp,
893- eventflags_t flags) {
894-
895- chEvtBroadcastFlagsI(esp, flags);
896-}
897-#else
898-static inline void osalEventBroadcastFlagsI(event_source_t *esp,
899- eventflags_t flags) {
900-
901- osalDbgCheck(esp != NULL);
902-
903- esp->flags |= flags;
904- if (esp->cb != NULL) {
905- esp->cb(esp);
906- }
907-}
908-#endif
909-
910-#if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__)
911-/**
912- * @brief Add flags to an event source object.
913- *
914- * @param[in] esp pointer to the event flags object
915- * @param[in] flags flags to be ORed to the flags mask
916- *
917- * @iclass
918- */
919-static inline void osalEventBroadcastFlags(event_source_t *esp,
920- eventflags_t flags) {
921-
922- chEvtBroadcastFlags(esp, flags);
923-}
924-#else
925-static inline void osalEventBroadcastFlags(event_source_t *esp,
926- eventflags_t flags) {
927-
928- osalDbgCheck(esp != NULL);
929-
930- osalSysLock();
931- esp->flags |= flags;
932- if (esp->cb != NULL) {
933- esp->cb(esp);
934- }
935- osalSysUnlock();
936-}
937-#endif
938-
939-#if (CH_CFG_USE_EVENTS == FALSE) || defined(__DOXYGEN__)
940-/**
941- * @brief Event callback setup.
942- * @note The callback is invoked from ISR context and can
943- * only invoke I-Class functions. The callback is meant
944- * to wakeup the task that will handle the event by
945- * calling @p osalEventGetAndClearFlagsI().
946- *
947- * @param[in] esp pointer to the event flags object
948- * @param[in] cb pointer to the callback function
949- * @param[in] param parameter to be passed to the callback function
950- *
951- * @api
952- */
953-static inline void osalEventSetCallback(event_source_t *esp,
954- eventcallback_t cb,
955- void *param) {
956-
957- osalDbgCheck(esp != NULL);
958-
959- esp->cb = cb;
960- esp->param = param;
961-}
962-#endif
963-
964-/**
965- * @brief Initializes s @p mutex_t object.
966- *
967- * @param[out] mp pointer to the @p mutex_t object
968- *
969- * @init
970- */
971-static inline void osalMutexObjectInit(mutex_t *mp) {
972-
973-#if CH_CFG_USE_MUTEXES
974- chMtxObjectInit(mp);
975-#elif CH_CFG_USE_SEMAPHORES
976- chSemObjectInit((semaphore_t *)mp, 1);
977-#else
978- *mp = 0;
979-#endif
980-}
981-
982-/**
983- * @brief Locks the specified mutex.
984- * @post The mutex is locked and inserted in the per-thread stack of owned
985- * mutexes.
986- *
987- * @param[in,out] mp pointer to the @p mutex_t object
988- *
989- * @api
990- */
991-static inline void osalMutexLock(mutex_t *mp) {
992-
993-#if CH_CFG_USE_MUTEXES
994- chMtxLock(mp);
995-#elif CH_CFG_USE_SEMAPHORES
996- chSemWait((semaphore_t *)mp);
997-#else
998- *mp = 1;
999-#endif
1000-}
1001-
1002-/**
1003- * @brief Unlocks the specified mutex.
1004- * @note The HAL guarantees to release mutex in reverse lock order. The
1005- * mutex being unlocked is guaranteed to be the last locked mutex
1006- * by the invoking thread.
1007- * The implementation can rely on this behavior and eventually
1008- * ignore the @p mp parameter which is supplied in order to support
1009- * those OSes not supporting a stack of the owned mutexes.
1010- *
1011- * @param[in,out] mp pointer to the @p mutex_t object
1012- *
1013- * @api
1014- */
1015-static inline void osalMutexUnlock(mutex_t *mp) {
1016-
1017-#if CH_CFG_USE_MUTEXES
1018- chMtxUnlock(mp);
1019-#elif CH_CFG_USE_SEMAPHORES
1020- chSemSignal((semaphore_t *)mp);
1021-#else
1022- *mp = 0;
1023-#endif
1024-}
1025-
1026-#endif /* OSAL_H */
1027-
1028-/** @} */
Show on old repository browser