57 OSThread(
const char *name,
int priority,
size_t stack_size,
58 void *(*start_routine)(
void*),
void *arg)
78 void start(
const char *name,
int priority,
size_t stack_size)
181 HASSERT(0 &&
"forgot to overload OSThread entry point. This thread "
182 "would do nothing.");
194 return thread->
entry();
266#if OPENMRN_FEATURE_RTOS_FROM_ISR
270 void post_from_isr(
int *woken)
272 os_sem_post_from_isr(&
handle, woken);
284#if OPENMRN_FEATURE_SEM_TIMEDWAIT
289 int timedwait(
long long timeout)
291 return os_sem_timedwait(&
handle, timeout);
312 OSMQ(
size_t length,
size_t item_size)
544#define OSMutexLock(l) int error_omitted_mutex_lock_variable[-1]
592#if defined (__FreeRTOS__)
594typedef EventBits_t OSEventType;
611 : event(xEventGroupCreate())
620 vEventGroupDelete(event);
626 static int number_of_bits()
628#if configUSE_16_BIT_TICKS
645 int wait(OSEventType mask, OSEventType *value,
bool clear, Test test)
661 int timedwait(OSEventType mask, OSEventType *value,
bool clear, Test test,
long long timeout)
663 BaseType_t e_clear = clear ? pdTRUE : pdFALSE;
664 BaseType_t e_test = test ? pdTRUE : pdFALSE;
667 OSEventType bits = xEventGroupWaitBits(event, mask, e_clear, e_test, e_timeout);
669 if (((bits & mask) == mask && test == WAIT_ALL) ||
670 ((bits & mask) != 0 && test == WAIT_ANY))
690 void set(OSEventType mask)
692 xEventGroupSetBits(event, mask);
699 void set_from_isr(OSEventType mask,
int *woken)
701 portBASE_TYPE local_woken;
702 xEventGroupSetBitsFromISR(event, mask, &local_woken);
703 *woken |= local_woken;
709 void clear(OSEventType mask)
711 xEventGroupClearBits(event, mask);
717 void clear_from_isr(OSEventType mask)
719 xEventGroupClearBitsFromISR(event, mask);
727 return xEventGroupGetBits(event);
734 EventGroupHandle_t event;
736#elif defined(ARDUINO) && !defined(ESP_PLATFORM)
738typedef uint32_t OSEventType;
741extern unsigned critical_nesting;
742extern uint32_t SystemCoreClock;
745#define cm3_cpu_clock_hz SystemCoreClock
746#define cpu_clock_hz SystemCoreClock
748#define portENTER_CRITICAL() \
752 ++critical_nesting; \
754#define portEXIT_CRITICAL() \
757 if (critical_nesting <= 1) \
759 critical_nesting = 0; \
764 --critical_nesting; \
768#define configKERNEL_INTERRUPT_PRIORITY (0xa0)
long long rtcOffset
Allows for OS abstracted access to time.
This class provides a simple message queue.
int timedreceive(void *data, long long timeout)
Receive a message from a queue.
int num_spaces()
Return the number of spaces available.
int receive_from_isr(void *data, int *woken)
Receive a message from a queue from ISR context.
OSMQ(size_t length, size_t item_size)
Constructor.
void receive(void *data)
Blocking receive a message from a queue.
OSMQ()
Default Constructor.
os_mq_t handle
Private message queue handle.
int is_full_from_isr()
Check if a queue is full from ISR context.
int pending_from_isr()
Return the number of messages pending in the queue from ISR context.
int send_from_isr(const void *data, int *woken)
Send of a message to a queue from ISR context.
void send(const void *data)
Blocking send of a message to a queue.
int num_pending()
Return the number of messages pending in the queue.
int timedsend(const void *data, long long timeout)
Send a message to a queue with a timeout.
Class to allow convenient locking and unlocking of mutexes in a C context.
os_mutex_t * mutex_
Mutex we are having locked.
OSMutexLock(OSMutex *mutex)
Constructor.
OSMutexLock(os_mutex_t *mutex)
Constructor.
This class provides a mutex API.
os_mutex_t handle
Private mutex handle.
OSMutex(bool recursive=false)
Initialize a mutex.
void unlock()
Unlock a mutex.
This class provides a counting semaphore API.
os_sem_t handle
Private semaphore handle.
OSSem(unsigned int value=0)
Initialize a Semaphore.
void post()
Post (increment) a semaphore.
void wait()
Wait on (decrement) a semaphore.
This class provides support for one time initialization.
~OSThreadOnce()
Default Destructor.
int once(void)
call one time intialization routine
OSThreadOnce(void(*routine)(void))
One time intialization constructor.
os_thread_once_t handle
Private once handle.
void(* routine)(void)
One time initialization routine.
This class provides a threading API.
static int get_priority(OSThread *thread)
Return the current thread priority.
static int getpriority(OSThread *thread)
Return the current thread priority.
os_thread_t handle
Private thread handle.
static int get_priority_min()
Get the minimum thread priority.
static void * start(void *arg)
Starting point for a new thread.
void inherit()
Inherits the current thread.
virtual ~OSThread()
Default destructor.
OSThread(const char *name, int priority, size_t stack_size, void *(*start_routine)(void *), void *arg)
Create a thread.
void unlock_from_thread()
Resets the thread handle to none.
void lock_to_thread()
Sets the thread handle to the current calling thread's.
virtual void * entry()
User entry point for the created thread.
static int get_priority_max()
Get the maximum thread priority.
void start(const char *name, int priority, size_t stack_size)
Starts the thread.
OSThread()
Creates a thread via inheritance.
static long long get_realtime()
Get the current RTC time.
static void set_realtime(long long time)
Set the current RTC time.
static long long get_monotonic()
Get the monotonic time since the system started.
~OSTime()
Default destructor.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.
long long os_get_time_monotonic(void)
Get the monotonic time since the system started.
int os_thread_create(os_thread_t *thread, const char *name, int priority, size_t stack_size, void *(*start_routine)(void *), void *arg)
Create a thread.
OS_INLINE void os_mq_receive(os_mq_t queue, void *data)
Blocking receive a message from a queue.
OS_INLINE int os_mq_num_pending_from_isr(os_mq_t queue)
Return the number of messages pending in the queue from ISR context.
OS_INLINE os_mq_t os_mq_create(size_t length, size_t item_size)
Create a new message queue.
OS_INLINE int os_recursive_mutex_init(os_mutex_t *mutex)
Initialize recursive mutex.
OS_INLINE int os_mq_send_from_isr(os_mq_t queue, const void *data, int *woken)
Send of a message to a queue from ISR context.
OS_INLINE int os_mutex_lock(os_mutex_t *mutex)
Lock a mutex.
OS_INLINE int os_mq_is_full_from_isr(os_mq_t queue)
Check if a queue is full from ISR context.
#define OPENMRN_OS_WAIT_FOREVER
maximum timeout period
OS_INLINE int os_thread_once(os_thread_once_t *once, void(*routine)(void))
One time intialization routine.
OS_INLINE int os_thread_get_priority_max(void)
Get the maximum thread priority.
OS_INLINE int os_sem_init(os_sem_t *sem, unsigned int value)
Initialize a semaphore.
OS_INLINE int os_mq_timedsend(os_mq_t queue, const void *data, long long timeout)
Send a message to a queue with a timeout.
OS_INLINE int os_mutex_destroy(os_mutex_t *mutex)
Destroy a mutex.
OS_INLINE int os_thread_get_priority_min(void)
Get the minimum thread priority.
OS_INLINE int os_sem_post(os_sem_t *sem)
Post a semaphore.
OS_INLINE int os_sem_wait(os_sem_t *sem)
Wait on a semaphore.
OS_INLINE int os_mutex_unlock(os_mutex_t *mutex)
Unock a mutex.
OS_INLINE int os_thread_get_priority(os_thread_t thread)
Return the current thread priority.
OS_INLINE os_thread_t os_thread_self(void)
Return a handle to the calling thread.
#define OS_THREAD_ONCE_INIT
initial value for one time intitialization instance
OS_INLINE int os_mq_timedreceive(os_mq_t queue, void *data, long long timeout)
Receive a message from a queue.
OS_INLINE int os_mq_receive_from_isr(os_mq_t queue, void *data, int *woken)
Receive a message from a queue from ISR context.
OS_INLINE int os_mutex_init(os_mutex_t *mutex)
Initialize mutex.
OS_INLINE int os_sem_destroy(os_sem_t *sem)
Destroy a semaphore.
OS_INLINE int os_mq_num_spaces(os_mq_t queue)
Return the number of spaces available in the queue.
OS_INLINE void os_mq_send(os_mq_t queue, const void *data)
Blocking send of a message to a queue.
OS_INLINE int os_mq_num_pending(os_mq_t queue)
Return the number of messages pending in the queue.
Helper class for using lock_to_thread.