Skip to content

Commit 872ce93

Browse files
committed
Minimal C RTOS API
1 parent 8479550 commit 872ce93

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

rtos/rtos_c.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2006-2013 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "rtos/rtos_c.h"
19+
#include "rtos/Kernel.h"
20+
#include "rtos/ThisThread.h"
21+
22+
extern "C" {
23+
24+
uint64_t get_ms_count(void)
25+
{
26+
return rtos::Kernel::get_ms_count();
27+
}
28+
29+
void thread_sleep_for(uint32_t millisec)
30+
{
31+
return rtos::ThisThread::sleep_for(millisec);
32+
}
33+
34+
void thread_sleep_until(uint64_t millisec)
35+
{
36+
return rtos::ThisThread::sleep_until(millisec);
37+
38+
}
39+
40+
}

rtos/rtos_c.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2019 ARM Limited. All rights reserved.
3+
*/
4+
5+
#ifndef MBED_RTOS_C_H_
6+
#define MBED_RTOS_C_H_
7+
8+
#include <stdint.h>
9+
10+
#ifdef __cplusplus
11+
extern "C" {
12+
#endif
13+
14+
/** Generic thread functions.
15+
*
16+
* These are C versions of functions provided in C++ via rtos::Thread and rtos::ThisThread
17+
*/
18+
19+
/** Read the current RTOS kernel millisecond tick count.
20+
The tick count corresponds to the tick count the RTOS uses for timing
21+
purposes. It increments monotonically from 0 at boot, so it effectively
22+
never wraps. If the underlying RTOS only provides a 32-bit tick count,
23+
this method expands it to 64 bits.
24+
@return RTOS kernel current tick count
25+
@note Mbed OS always uses millisecond RTOS ticks, and this could only wrap
26+
after half a billion years.
27+
@note In a non-RTOS build, this computes an equivalent time in milliseconds,
28+
based on a HAL timer. The time may be referenced as 0 on first call.
29+
@note You cannot call this function from ISR context.
30+
@note The equivalent functionality is accessible in C++ via rtos::Kernel::get_ms_count.
31+
*/
32+
uint64_t get_ms_count(void);
33+
34+
/** Sleep for a specified time period in millisec:
35+
@param millisec time delay value
36+
@note You cannot call this function from ISR context.
37+
@note The equivalent functionality is accessible in C++ via rtos::ThisThread::sleep_for.
38+
*/
39+
void thread_sleep_for(uint32_t millisec);
40+
41+
/** Sleep until a specified time in millisec
42+
The specified time is according to Kernel::get_ms_count().
43+
@param millisec absolute time in millisec
44+
@note You cannot call this function from ISR context.
45+
@note if millisec is equal to or lower than the current tick count, this
46+
returns immediately.
47+
@note The equivalent functionality is accessible in C++ via ThisThread::sleep_until.
48+
*/
49+
void thread_sleep_until(uint64_t millisec);
50+
51+
#ifdef __cplusplus
52+
}
53+
#endif
54+
55+
#endif /* MBED_THREAD_API_H_ */

0 commit comments

Comments
 (0)