Skip to content

Commit b793a3f

Browse files
bulislaw0xc0170
authored andcommitted
Update codebase for CMSIS5/RTX5
Update all of mbed-os to use RTX5.
1 parent b97ffe8 commit b793a3f

File tree

50 files changed

+1678
-1110
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1678
-1110
lines changed

TESTS/mbedmicro-rtos-mbed/mutex/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ void test_dual_thread_lock_lock_thread(Mutex *mutex)
142142
uint32_t start = us_ticker_read();
143143

144144
osStatus stat = mutex->lock(TEST_HALF_SEC_MS);
145-
TEST_ASSERT_EQUAL(stat, osEventTimeout);
145+
TEST_ASSERT_EQUAL(stat, osErrorTimeout);
146146
TEST_ASSERT_UINT32_WITHIN(TEST_ONE_MS_US, TEST_HALF_SEC_US, us_ticker_read() - start);
147147
}
148148

TESTS/mbedmicro-rtos-mbed/threads/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ void self_terminate(Thread *self) {
6161
// Tests that spawn tasks in different configurations
6262
template <void (*F)(counter_t *)>
6363
void test_single_thread() {
64+
const char tname[] = "Single Thread";
6465
counter_t counter(0);
65-
Thread thread(osPriorityNormal, THREAD_STACK_SIZE, NULL);
66+
Thread thread(osPriorityNormal, THREAD_STACK_SIZE, NULL, tname);
6667
thread.start(callback(F, &counter));
6768
thread.join();
6869
TEST_ASSERT_EQUAL(counter, 1);
70+
TEST_ASSERT_EQUAL(strcmp(tname, thread.get_name()), 0);
6971
}
7072

7173
template <int N, void (*F)(counter_t *)>

events/equeue/equeue_platform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ typedef struct equeue_sema {
112112
bool signal;
113113
} equeue_sema_t;
114114
#elif defined(EQUEUE_PLATFORM_MBED) && defined(MBED_CONF_RTOS_PRESENT)
115-
typedef unsigned equeue_sema_t[8];
115+
typedef unsigned equeue_sema_t[9];
116116
#elif defined(EQUEUE_PLATFORM_MBED)
117117
typedef volatile int equeue_sema_t;
118118
#endif

features/FEATURE_BLE/ble/services/iBeacon.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#ifndef __BLE_IBEACON_H__
1717
#define __BLE_IBEACON_H__
1818

19-
#include "core_cmInstr.h"
19+
#include "cmsis_compiler.h"
2020
#include "ble/BLE.h"
2121

2222
/**

features/FEATURE_COMMON_PAL/nanostack-hal-mbed-cmsis-rtos/arm_hal_interrupt.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,30 @@
44

55
#include "arm_hal_interrupt.h"
66
#include "arm_hal_interrupt_private.h"
7-
#include "cmsis_os.h"
8-
7+
#include "cmsis_os2.h"
8+
#include "mbed_rtos_storage.h"
9+
#include <mbed_assert.h>
910

1011
static uint8_t sys_irq_disable_counter;
1112

12-
static osMutexDef(critical);
13-
static osMutexId critical_mutex_id;
13+
static mbed_rtos_storage_mutex_t critical_mutex;
14+
static const osMutexAttr_t critical_mutex_attr = {
15+
.name = "critical_mutex",
16+
.attr_bits = osMutexRecursive,
17+
.cb_mem = &critical_mutex,
18+
.cb_size = sizeof critical_mutex,
19+
};
20+
static osMutexId_t critical_mutex_id;
1421

1522
void platform_critical_init(void)
1623
{
17-
critical_mutex_id = osMutexCreate(osMutex(critical));
24+
critical_mutex_id = osMutexNew(&critical_mutex_attr);
25+
MBED_ASSERT(critical_mutex_id);
1826
}
1927

2028
void platform_enter_critical(void)
2129
{
22-
osMutexWait(critical_mutex_id, osWaitForever);
30+
osMutexAcquire(critical_mutex_id, osWaitForever);
2331
sys_irq_disable_counter++;
2432
}
2533

features/FEATURE_COMMON_PAL/nanostack-hal-mbed-cmsis-rtos/arm_hal_timer.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,27 @@
44

55
// Include before mbed.h to properly get UINT*_C()
66
#include "ns_types.h"
7-
8-
#include "cmsis_os.h"
97
#include "mbed.h"
10-
8+
#include "cmsis_os2.h"
9+
#include "rtx_os.h"
1110
#include "platform/arm_hal_timer.h"
1211
#include "platform/arm_hal_interrupt.h"
12+
#include <mbed_assert.h>
1313

14-
static osThreadId timer_thread_id;
14+
static osThreadId_t timer_thread_id;
15+
static uint64_t timer_thread_stk[2048];
16+
static osRtxThread_t timer_thread_tcb;
1517

1618
static Timer timer;
1719
static Timeout timeout;
1820
static uint32_t due;
1921
static void (*arm_hal_callback)(void);
2022

21-
static void timer_thread(const void *)
23+
static void timer_thread(void *arg)
2224
{
25+
(void)arg;
2326
for (;;) {
24-
osSignalWait(1, osWaitForever);
27+
osThreadFlagsWait(1, osFlagsWaitAny, osWaitForever);
2528
// !!! We don't do our own enter/exit critical - we rely on callback
2629
// doing it (ns_timer_interrupt_handler does)
2730
//platform_enter_critical();
@@ -33,8 +36,14 @@ static void timer_thread(const void *)
3336
// Called once at boot
3437
void platform_timer_enable(void)
3538
{
36-
static osThreadDef(timer_thread, osPriorityRealtime, /*1,*/ 2*1024);
37-
timer_thread_id = osThreadCreate(osThread(timer_thread), NULL);
39+
static osThreadAttr_t timer_thread_attr = {0};
40+
timer_thread_attr.stack_mem = &timer_thread_stk[0];
41+
timer_thread_attr.cb_mem = &timer_thread_tcb;
42+
timer_thread_attr.stack_size = sizeof(timer_thread_stk);
43+
timer_thread_attr.cb_size = sizeof(timer_thread_tcb);
44+
timer_thread_attr.priority = osPriorityRealtime;
45+
timer_thread_id = osThreadNew(timer_thread, NULL, &timer_thread_attr);
46+
MBED_ASSERT(timer_thread_id != NULL);
3847
timer.start();
3948
}
4049

@@ -53,8 +62,7 @@ void platform_timer_set_cb(void (*new_fp)(void))
5362
static void timer_callback(void)
5463
{
5564
due = 0;
56-
osSignalSet(timer_thread_id, 1);
57-
//callback();
65+
osThreadFlagsSet(timer_thread_id, 1);
5866
}
5967

6068
// This is called from inside platform_enter_critical - IRQs can't happen

features/FEATURE_COMMON_PAL/nanostack-hal-mbed-cmsis-rtos/ns_event_loop.c

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
* Copyright (c) 2016 ARM Limited, All Rights Reserved
33
*/
44

5+
#include <mbed_assert.h>
56
#include "cmsis.h"
6-
#include "cmsis_os.h"
7+
#include "cmsis_os2.h"
8+
#include "mbed_rtos_storage.h"
79
#include "ns_trace.h"
810

911
#include "eventOS_scheduler.h"
@@ -12,21 +14,32 @@
1214

1315
#define TRACE_GROUP "evlp"
1416

15-
static void event_loop_thread(const void *arg);
16-
17-
// 1K should be enough - it's what the SAM4E port uses...
18-
// What happened to the instances parameter?
19-
static osThreadDef(event_loop_thread, osPriorityNormal, /*1,*/ MBED_CONF_NANOSTACK_HAL_EVENT_LOOP_THREAD_STACK_SIZE);
20-
static osMutexDef(event);
21-
22-
static osThreadId event_thread_id;
23-
static osMutexId event_mutex_id;
24-
static osThreadId event_mutex_owner_id = NULL;
17+
static void event_loop_thread(void *arg);
18+
19+
static uint64_t event_thread_stk[MBED_CONF_NANOSTACK_HAL_EVENT_LOOP_THREAD_STACK_SIZE/8];
20+
static mbed_rtos_storage_thread_t event_thread_tcb;
21+
static const osThreadAttr_t event_thread_attr = {
22+
.priority = osPriorityNormal,
23+
.stack_mem = &event_thread_stk[0],
24+
.stack_size = sizeof event_thread_stk,
25+
.cb_mem = &event_thread_tcb,
26+
.cb_size = sizeof event_thread_tcb,
27+
};
28+
static osThreadId_t event_thread_id;
29+
static mbed_rtos_storage_mutex_t event_mutex;
30+
static const osMutexAttr_t event_mutex_attr = {
31+
.name = "event_mutex",
32+
.attr_bits = osMutexRecursive,
33+
.cb_mem = &event_mutex,
34+
.cb_size = sizeof event_mutex,
35+
};
36+
static osMutexId_t event_mutex_id;
37+
static osThreadId_t event_mutex_owner_id = NULL;
2538
static uint32_t owner_count = 0;
2639

2740
void eventOS_scheduler_mutex_wait(void)
2841
{
29-
osMutexWait(event_mutex_id, osWaitForever);
42+
osMutexAcquire(event_mutex_id, osWaitForever);
3043
if (0 == owner_count) {
3144
event_mutex_owner_id = osThreadGetId();
3245
}
@@ -52,37 +65,34 @@ void eventOS_scheduler_signal(void)
5265
// XXX why does signal set lock if called with irqs disabled?
5366
//__enable_irq();
5467
//tr_debug("signal %p", (void*)event_thread_id);
55-
osSignalSet(event_thread_id, 1);
68+
osThreadFlagsSet(event_thread_id, 1);
5669
//tr_debug("signalled %p", (void*)event_thread_id);
5770
}
5871

5972
void eventOS_scheduler_idle(void)
6073
{
6174
//tr_debug("idle");
6275
eventOS_scheduler_mutex_release();
63-
osSignalWait(1, osWaitForever);
76+
osThreadFlagsWait(1, 0, osWaitForever);
6477
eventOS_scheduler_mutex_wait();
6578
}
6679

67-
static void event_loop_thread(const void *arg)
80+
static void event_loop_thread(void *arg)
6881
{
69-
//tr_debug("event_loop_thread create");
70-
osSignalWait(2, osWaitForever);
71-
82+
(void)arg;
7283
eventOS_scheduler_mutex_wait();
73-
tr_debug("event_loop_thread");
74-
75-
// Run does not return - it calls eventOS_scheduler_idle when it's, er, idle
76-
eventOS_scheduler_run();
84+
eventOS_scheduler_run(); //Does not return
7785
}
7886

7987
void ns_event_loop_thread_create(void)
8088
{
81-
event_mutex_id = osMutexCreate(osMutex(event));
82-
event_thread_id = osThreadCreate(osThread(event_loop_thread), NULL);
89+
event_mutex_id = osMutexNew(&event_mutex_attr);
90+
MBED_ASSERT(event_mutex_id != NULL);
91+
92+
event_thread_id = osThreadNew(event_loop_thread, NULL, &event_thread_attr);
93+
MBED_ASSERT(event_thread_id != NULL);
8394
}
8495

8596
void ns_event_loop_thread_start(void)
8697
{
87-
osSignalSet(event_thread_id, 2);
8898
}

features/FEATURE_LWIP/lwip-interface/lwip-eth/arch/TARGET_Freescale/k64f_emac.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,8 @@ static err_t k64f_low_level_output(struct netif *netif, struct pbuf *p)
532532
}
533533

534534
/* Check if a descriptor is available for the transfer. */
535-
int32_t count = osSemaphoreWait(k64f_enet->xTXDCountSem.id, 0);
536-
if (count < 1)
535+
osStatus_t stat = osSemaphoreAcquire(k64f_enet->xTXDCountSem.id, 0);
536+
if (stat != osOK)
537537
return ERR_BUF;
538538

539539
/* Get exclusive access */
@@ -697,11 +697,10 @@ err_t eth_arch_enetif_init(struct netif *netif)
697697
netif->linkoutput = k64f_low_level_output;
698698

699699
/* CMSIS-RTOS, start tasks */
700-
#ifdef CMSIS_OS_RTX
701-
memset(k64f_enetdata.xTXDCountSem.data, 0, sizeof(k64f_enetdata.xTXDCountSem.data));
702-
k64f_enetdata.xTXDCountSem.def.semaphore = k64f_enetdata.xTXDCountSem.data;
703-
#endif
704-
k64f_enetdata.xTXDCountSem.id = osSemaphoreCreate(&k64f_enetdata.xTXDCountSem.def, ENET_TX_RING_LEN);
700+
memset(&k64f_enetdata.xTXDCountSem.data, 0, sizeof(k64f_enetdata.xTXDCountSem.data));
701+
k64f_enetdata.xTXDCountSem.attr.cb_mem = &k64f_enetdata.xTXDCountSem.data;
702+
k64f_enetdata.xTXDCountSem.attr.cb_size = sizeof(k64f_enetdata.xTXDCountSem.data);
703+
k64f_enetdata.xTXDCountSem.id = osSemaphoreNew(ENET_TX_RING_LEN, ENET_TX_RING_LEN, &k64f_enetdata.xTXDCountSem.attr);
705704

706705
LWIP_ASSERT("xTXDCountSem creation error", (k64f_enetdata.xTXDCountSem.id != NULL));
707706

features/FEATURE_LWIP/lwip-interface/lwip-eth/arch/TARGET_NXP/lpc17_emac.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
* the same. */
7171
#define RX_PRIORITY (osPriorityNormal)
7272
#define TX_PRIORITY (osPriorityNormal)
73+
#define PHY_PRIORITY (osPriorityNormal)
7374

7475
/** \brief Debug output formatter lock define
7576
*
@@ -603,7 +604,7 @@ static err_t lpc_low_level_output(struct netif *netif, struct pbuf *p)
603604
/* THIS WILL BLOCK UNTIL THERE ARE ENOUGH DESCRIPTORS AVAILABLE */
604605
while (dn > lpc_tx_ready(netif))
605606
#if NO_SYS == 0
606-
osSemaphoreWait(lpc_enetif->xTXDCountSem.id, osWaitForever);
607+
osSemaphoreAcquire(lpc_enetif->xTXDCountSem.id, osWaitForever);
607608
#else
608609
osDelay(1);
609610
#endif
@@ -685,7 +686,7 @@ void LPC17xxEthernetHandler(void)
685686

686687
if (ints & RXINTGROUP) {
687688
/* RX group interrupt(s): Give signal to wakeup RX receive task.*/
688-
osSignalSet(lpc_enetdata.RxThread->id, RX_SIGNAL);
689+
osThreadFlagsSet(lpc_enetdata.RxThread->id, RX_SIGNAL);
689690
}
690691

691692
if (ints & TXINTGROUP) {
@@ -711,7 +712,7 @@ static void packet_rx(void* pvParameters) {
711712

712713
while (1) {
713714
/* Wait for receive task to wakeup */
714-
osSignalWait(RX_SIGNAL, osWaitForever);
715+
osThreadFlagsWait(RX_SIGNAL, 0, osWaitForever);
715716

716717
/* Process packets until all empty */
717718
while (LPC_EMAC->RxConsumeIndex != LPC_EMAC->RxProduceIndex)
@@ -942,10 +943,13 @@ err_t lpc_etharp_output_ipv6(struct netif *netif, struct pbuf *q,
942943

943944
#if NO_SYS == 0
944945
/* periodic PHY status update */
945-
void phy_update(void const *nif) {
946-
lpc_phy_sts_sm((struct netif*)nif);
946+
void phy_update(void *nif) {
947+
while (true) {
948+
lpc_phy_sts_sm((struct netif*)nif);
949+
osDelay(250);
950+
}
947951
}
948-
osTimerDef(phy_update, phy_update);
952+
949953
#endif
950954

951955
/**
@@ -1017,11 +1021,10 @@ err_t eth_arch_enetif_init(struct netif *netif)
10171021

10181022
/* CMSIS-RTOS, start tasks */
10191023
#if NO_SYS == 0
1020-
#ifdef CMSIS_OS_RTX
1021-
memset(lpc_enetdata.xTXDCountSem.data, 0, sizeof(lpc_enetdata.xTXDCountSem.data));
1022-
lpc_enetdata.xTXDCountSem.def.semaphore = lpc_enetdata.xTXDCountSem.data;
1023-
#endif
1024-
lpc_enetdata.xTXDCountSem.id = osSemaphoreCreate(&lpc_enetdata.xTXDCountSem.def, LPC_NUM_BUFF_TXDESCS);
1024+
memset(&lpc_enetdata.xTXDCountSem.data, 0, sizeof(lpc_enetdata.xTXDCountSem.data));
1025+
lpc_enetdata.xTXDCountSem.attr.cb_mem = &lpc_enetdata.xTXDCountSem.data;
1026+
lpc_enetdata.xTXDCountSem.attr.cb_size = sizeof(lpc_enetdata.xTXDCountSem.data);
1027+
lpc_enetdata.xTXDCountSem.id = osSemaphoreNew(LPC_NUM_BUFF_TXDESCS, LPC_NUM_BUFF_TXDESCS, &lpc_enetdata.xTXDCountSem.attr);
10251028
LWIP_ASSERT("xTXDCountSem creation error", (lpc_enetdata.xTXDCountSem.id != NULL));
10261029

10271030
err = sys_mutex_new(&lpc_enetdata.TXLockMutex);
@@ -1037,8 +1040,7 @@ err_t eth_arch_enetif_init(struct netif *netif)
10371040
sys_thread_new("txclean_thread", packet_tx, netif->state, DEFAULT_THREAD_STACKSIZE, TX_PRIORITY);
10381041

10391042
/* periodic PHY status update */
1040-
osTimerId phy_timer = osTimerCreate(osTimer(phy_update), osTimerPeriodic, (void *)netif);
1041-
osTimerStart(phy_timer, 250);
1043+
sys_thread_new("phy_thread", phy_update, netif, DEFAULT_THREAD_STACKSIZE, TX_PRIORITY);
10421044
#endif
10431045

10441046
return ERR_OK;

features/FEATURE_LWIP/lwip-interface/lwip-eth/arch/TARGET_STM/stm32xx_emac.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "lwip/tcpip.h"
55
#include "lwip/ethip6.h"
66
#include <string.h>
7-
#include "cmsis_os.h"
7+
#include "cmsis_os2.h"
88
#include "mbed_interface.h"
99

1010
#define RECV_TASK_PRI (osPriorityHigh)

0 commit comments

Comments
 (0)