@@ -552,7 +552,7 @@ uint32_t svcKernelSysTick (void) {
552
552
553
553
/// Initialize the RTOS Kernel for creating objects
554
554
osStatus osKernelInitialize (void ) {
555
- if (__get_IPSR () != 0U ) {
555
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) {
556
556
return osErrorISR ; // Not allowed in ISR
557
557
}
558
558
if ((__get_CONTROL () & 1U ) == 0U ) { // Privileged mode
@@ -566,7 +566,7 @@ osStatus osKernelInitialize (void) {
566
566
osStatus osKernelStart (void ) {
567
567
uint32_t stack [8 ];
568
568
569
- if (__get_IPSR () != 0U ) {
569
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) {
570
570
return osErrorISR ; // Not allowed in ISR
571
571
}
572
572
@@ -607,7 +607,7 @@ osStatus osKernelStart (void) {
607
607
608
608
/// Check if the RTOS kernel is already started
609
609
int32_t osKernelRunning (void ) {
610
- if ((__get_IPSR () != 0U ) || ((__get_CONTROL () & 1U ) == 0U )) {
610
+ if ((__get_PRIMASK () != 0U || __get_IPSR () != 0U ) || ((__get_CONTROL () & 1U ) == 0U )) {
611
611
// in ISR or Privileged
612
612
return (int32_t )os_running ;
613
613
} else {
@@ -617,7 +617,7 @@ int32_t osKernelRunning (void) {
617
617
618
618
/// Get the RTOS kernel system timer counter
619
619
uint32_t osKernelSysTick (void ) {
620
- if (__get_IPSR () != 0U ) { return 0U ; } // Not allowed in ISR
620
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) { return 0U ; } // Not allowed in ISR
621
621
return __svcKernelSysTick ();
622
622
}
623
623
@@ -867,7 +867,7 @@ osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument) {
867
867
return osThreadContextCreate (thread_def , argument , NULL );
868
868
}
869
869
osThreadId osThreadContextCreate (const osThreadDef_t * thread_def , void * argument , void * context ) {
870
- if (__get_IPSR () != 0U ) {
870
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) {
871
871
return NULL ; // Not allowed in ISR
872
872
}
873
873
if (((__get_CONTROL () & 1U ) == 0U ) && (os_running == 0U )) {
@@ -885,7 +885,7 @@ osThreadId osThreadContextCreate (const osThreadDef_t *thread_def, void *argumen
885
885
886
886
/// Return the thread ID of the current running thread
887
887
osThreadId osThreadGetId (void ) {
888
- if (__get_IPSR () != 0U ) {
888
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) {
889
889
return NULL ; // Not allowed in ISR
890
890
}
891
891
return __svcThreadGetId ();
@@ -894,7 +894,7 @@ osThreadId osThreadGetId (void) {
894
894
/// Terminate execution of a thread and remove it from ActiveThreads
895
895
osStatus osThreadTerminate (osThreadId thread_id ) {
896
896
osStatus status ;
897
- if (__get_IPSR () != 0U ) {
897
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) {
898
898
return osErrorISR ; // Not allowed in ISR
899
899
}
900
900
osMutexWait (osMutexId_osThreadMutex , osWaitForever );
@@ -907,23 +907,23 @@ osStatus osThreadTerminate (osThreadId thread_id) {
907
907
908
908
/// Pass control to next thread that is in state READY
909
909
osStatus osThreadYield (void ) {
910
- if (__get_IPSR () != 0U ) {
910
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) {
911
911
return osErrorISR ; // Not allowed in ISR
912
912
}
913
913
return __svcThreadYield ();
914
914
}
915
915
916
916
/// Change priority of an active thread
917
917
osStatus osThreadSetPriority (osThreadId thread_id , osPriority priority ) {
918
- if (__get_IPSR () != 0U ) {
918
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) {
919
919
return osErrorISR ; // Not allowed in ISR
920
920
}
921
921
return __svcThreadSetPriority (thread_id , priority );
922
922
}
923
923
924
924
/// Get current priority of an active thread
925
925
osPriority osThreadGetPriority (osThreadId thread_id ) {
926
- if (__get_IPSR () != 0U ) {
926
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) {
927
927
return osPriorityError ; // Not allowed in ISR
928
928
}
929
929
return __svcThreadGetPriority (thread_id );
@@ -948,7 +948,7 @@ __NO_RETURN void osThreadExit (void) {
948
948
uint8_t osThreadGetState (osThreadId thread_id ) {
949
949
P_TCB ptcb ;
950
950
951
- if (__get_IPSR () != 0U ) return osErrorISR ; // Not allowed in ISR
951
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) return osErrorISR ; // Not allowed in ISR
952
952
953
953
ptcb = rt_tid2ptcb (thread_id ); // Get TCB pointer
954
954
if (ptcb == NULL ) return INACTIVE ;
@@ -1040,7 +1040,7 @@ os_InRegs osEvent_type svcWait (uint32_t millisec) {
1040
1040
1041
1041
/// Wait for Timeout (Time Delay)
1042
1042
osStatus osDelay (uint32_t millisec ) {
1043
- if (__get_IPSR () != 0U ) {
1043
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) {
1044
1044
return osErrorISR ; // Not allowed in ISR
1045
1045
}
1046
1046
return __svcDelay (millisec );
@@ -1054,7 +1054,7 @@ os_InRegs osEvent osWait (uint32_t millisec) {
1054
1054
ret .status = osErrorOS ;
1055
1055
return ret ;
1056
1056
#else
1057
- if (__get_IPSR () != 0U ) { // Not allowed in ISR
1057
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) { // Not allowed in ISR
1058
1058
ret .status = osErrorISR ;
1059
1059
return ret ;
1060
1060
}
@@ -1337,7 +1337,7 @@ void sysUserTimerUpdate (uint32_t sleep_time) {
1337
1337
1338
1338
/// Create timer
1339
1339
osTimerId osTimerCreate (const osTimerDef_t * timer_def , os_timer_type type , void * argument ) {
1340
- if (__get_IPSR () != 0U ) {
1340
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) {
1341
1341
return NULL ; // Not allowed in ISR
1342
1342
}
1343
1343
if (((__get_CONTROL () & 1U ) == 0U ) && (os_running == 0U )) {
@@ -1350,23 +1350,23 @@ osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void
1350
1350
1351
1351
/// Start or restart timer
1352
1352
osStatus osTimerStart (osTimerId timer_id , uint32_t millisec ) {
1353
- if (__get_IPSR () != 0U ) {
1353
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) {
1354
1354
return osErrorISR ; // Not allowed in ISR
1355
1355
}
1356
1356
return __svcTimerStart (timer_id , millisec );
1357
1357
}
1358
1358
1359
1359
/// Stop timer
1360
1360
osStatus osTimerStop (osTimerId timer_id ) {
1361
- if (__get_IPSR () != 0U ) {
1361
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) {
1362
1362
return osErrorISR ; // Not allowed in ISR
1363
1363
}
1364
1364
return __svcTimerStop (timer_id );
1365
1365
}
1366
1366
1367
1367
/// Delete timer
1368
1368
osStatus osTimerDelete (osTimerId timer_id ) {
1369
- if (__get_IPSR () != 0U ) {
1369
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) {
1370
1370
return osErrorISR ; // Not allowed in ISR
1371
1371
}
1372
1372
return __svcTimerDelete (timer_id );
@@ -1503,7 +1503,7 @@ int32_t isrSignalSet (osThreadId thread_id, int32_t signals) {
1503
1503
1504
1504
/// Set the specified Signal Flags of an active thread
1505
1505
int32_t osSignalSet (osThreadId thread_id , int32_t signals ) {
1506
- if (__get_IPSR () != 0U ) { // in ISR
1506
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) { // in ISR
1507
1507
return isrSignalSet (thread_id , signals );
1508
1508
} else { // in Thread
1509
1509
return __svcSignalSet (thread_id , signals );
@@ -1512,7 +1512,7 @@ int32_t osSignalSet (osThreadId thread_id, int32_t signals) {
1512
1512
1513
1513
/// Clear the specified Signal Flags of an active thread
1514
1514
int32_t osSignalClear (osThreadId thread_id , int32_t signals ) {
1515
- if (__get_IPSR () != 0U ) {
1515
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) {
1516
1516
return (int32_t )0x80000000U ; // Not allowed in ISR
1517
1517
}
1518
1518
return __svcSignalClear (thread_id , signals );
@@ -1522,7 +1522,7 @@ int32_t osSignalClear (osThreadId thread_id, int32_t signals) {
1522
1522
os_InRegs osEvent osSignalWait (int32_t signals , uint32_t millisec ) {
1523
1523
osEvent ret ;
1524
1524
1525
- if (__get_IPSR () != 0U ) { // Not allowed in ISR
1525
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) { // Not allowed in ISR
1526
1526
ret .status = osErrorISR ;
1527
1527
return ret ;
1528
1528
}
@@ -1634,7 +1634,7 @@ osStatus svcMutexDelete (osMutexId mutex_id) {
1634
1634
1635
1635
/// Create and Initialize a Mutex object
1636
1636
osMutexId osMutexCreate (const osMutexDef_t * mutex_def ) {
1637
- if (__get_IPSR () != 0U ) {
1637
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) {
1638
1638
return NULL ; // Not allowed in ISR
1639
1639
}
1640
1640
if (((__get_CONTROL () & 1U ) == 0U ) && (os_running == 0U )) {
@@ -1647,23 +1647,23 @@ osMutexId osMutexCreate (const osMutexDef_t *mutex_def) {
1647
1647
1648
1648
/// Wait until a Mutex becomes available
1649
1649
osStatus osMutexWait (osMutexId mutex_id , uint32_t millisec ) {
1650
- if (__get_IPSR () != 0U ) {
1650
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) {
1651
1651
return osErrorISR ; // Not allowed in ISR
1652
1652
}
1653
1653
return __svcMutexWait (mutex_id , millisec );
1654
1654
}
1655
1655
1656
1656
/// Release a Mutex that was obtained with osMutexWait
1657
1657
osStatus osMutexRelease (osMutexId mutex_id ) {
1658
- if (__get_IPSR () != 0U ) {
1658
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) {
1659
1659
return osErrorISR ; // Not allowed in ISR
1660
1660
}
1661
1661
return __svcMutexRelease (mutex_id );
1662
1662
}
1663
1663
1664
1664
/// Delete a Mutex that was created by osMutexCreate
1665
1665
osStatus osMutexDelete (osMutexId mutex_id ) {
1666
- if (__get_IPSR () != 0U ) {
1666
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) {
1667
1667
return osErrorISR ; // Not allowed in ISR
1668
1668
}
1669
1669
return __svcMutexDelete (mutex_id );
@@ -1801,7 +1801,7 @@ osStatus isrSemaphoreRelease (osSemaphoreId semaphore_id) {
1801
1801
1802
1802
/// Create and Initialize a Semaphore object
1803
1803
osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t * semaphore_def , int32_t count ) {
1804
- if (__get_IPSR () != 0U ) {
1804
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) {
1805
1805
return NULL ; // Not allowed in ISR
1806
1806
}
1807
1807
if (((__get_CONTROL () & 1U ) == 0U ) && (os_running == 0U )) {
@@ -1814,24 +1814,24 @@ osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t
1814
1814
1815
1815
/// Wait until a Semaphore becomes available
1816
1816
int32_t osSemaphoreWait (osSemaphoreId semaphore_id , uint32_t millisec ) {
1817
- if (__get_IPSR () != 0U ) {
1817
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) {
1818
1818
return -1 ; // Not allowed in ISR
1819
1819
}
1820
1820
return __svcSemaphoreWait (semaphore_id , millisec );
1821
1821
}
1822
1822
1823
1823
/// Release a Semaphore
1824
1824
osStatus osSemaphoreRelease (osSemaphoreId semaphore_id ) {
1825
- if (__get_IPSR () != 0U ) { // in ISR
1825
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) { // in ISR
1826
1826
return isrSemaphoreRelease (semaphore_id );
1827
- } else { // in Thread
1827
+ } else { // in Thread
1828
1828
return __svcSemaphoreRelease (semaphore_id );
1829
1829
}
1830
1830
}
1831
1831
1832
1832
/// Delete a Semaphore that was created by osSemaphoreCreate
1833
1833
osStatus osSemaphoreDelete (osSemaphoreId semaphore_id ) {
1834
- if (__get_IPSR () != 0U ) {
1834
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) {
1835
1835
return osErrorISR ; // Not allowed in ISR
1836
1836
}
1837
1837
return __svcSemaphoreDelete (semaphore_id );
@@ -1914,7 +1914,7 @@ osStatus sysPoolFree (osPoolId pool_id, void *block) {
1914
1914
1915
1915
/// Create and Initialize memory pool
1916
1916
osPoolId osPoolCreate (const osPoolDef_t * pool_def ) {
1917
- if (__get_IPSR () != 0U ) {
1917
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) {
1918
1918
return NULL ; // Not allowed in ISR
1919
1919
}
1920
1920
if (((__get_CONTROL () & 1U ) == 0U ) && (os_running == 0U )) {
@@ -1927,7 +1927,7 @@ osPoolId osPoolCreate (const osPoolDef_t *pool_def) {
1927
1927
1928
1928
/// Allocate a memory block from a memory pool
1929
1929
void * osPoolAlloc (osPoolId pool_id ) {
1930
- if ((__get_IPSR () != 0U ) || ((__get_CONTROL () & 1U ) == 0U )) { // in ISR or Privileged
1930
+ if ((__get_PRIMASK () != 0U || __get_IPSR () != 0U ) || ((__get_CONTROL () & 1U ) == 0U )) { // in ISR or Privileged
1931
1931
return sysPoolAlloc (pool_id );
1932
1932
} else { // in Thread
1933
1933
return __sysPoolAlloc (pool_id );
@@ -1938,7 +1938,7 @@ void *osPoolAlloc (osPoolId pool_id) {
1938
1938
void * osPoolCAlloc (osPoolId pool_id ) {
1939
1939
void * mem ;
1940
1940
1941
- if ((__get_IPSR () != 0U ) || ((__get_CONTROL () & 1U ) == 0U )) { // in ISR or Privileged
1941
+ if ((__get_PRIMASK () != 0U || __get_IPSR () != 0U ) || ((__get_CONTROL () & 1U ) == 0U )) { // in ISR or Privileged
1942
1942
mem = sysPoolAlloc (pool_id );
1943
1943
} else { // in Thread
1944
1944
mem = __sysPoolAlloc (pool_id );
@@ -1951,7 +1951,7 @@ void *osPoolCAlloc (osPoolId pool_id) {
1951
1951
1952
1952
/// Return an allocated memory block back to a specific memory pool
1953
1953
osStatus osPoolFree (osPoolId pool_id , void * block ) {
1954
- if ((__get_IPSR () != 0U ) || ((__get_CONTROL () & 1U ) == 0U )) { // in ISR or Privileged
1954
+ if ((__get_PRIMASK () != 0U || __get_IPSR () != 0U ) || ((__get_CONTROL () & 1U ) == 0U )) { // in ISR or Privileged
1955
1955
return sysPoolFree (pool_id , block );
1956
1956
} else { // in Thread
1957
1957
return __sysPoolFree (pool_id , block );
@@ -2091,7 +2091,7 @@ os_InRegs osEvent isrMessageGet (osMessageQId queue_id, uint32_t millisec) {
2091
2091
2092
2092
/// Create and Initialize Message Queue
2093
2093
osMessageQId osMessageCreate (const osMessageQDef_t * queue_def , osThreadId thread_id ) {
2094
- if (__get_IPSR () != 0U ) {
2094
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) {
2095
2095
return NULL ; // Not allowed in ISR
2096
2096
}
2097
2097
if (((__get_CONTROL () & 1U ) == 0U ) && (os_running == 0U )) {
@@ -2104,7 +2104,7 @@ osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId threa
2104
2104
2105
2105
/// Put a Message to a Queue
2106
2106
osStatus osMessagePut (osMessageQId queue_id , uint32_t info , uint32_t millisec ) {
2107
- if (__get_IPSR () != 0U ) { // in ISR
2107
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) { // in ISR
2108
2108
return isrMessagePut (queue_id , info , millisec );
2109
2109
} else { // in Thread
2110
2110
return __svcMessagePut (queue_id , info , millisec );
@@ -2113,7 +2113,7 @@ osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec)
2113
2113
2114
2114
/// Get a Message or Wait for a Message from a Queue
2115
2115
os_InRegs osEvent osMessageGet (osMessageQId queue_id , uint32_t millisec ) {
2116
- if (__get_IPSR () != 0U ) { // in ISR
2116
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) { // in ISR
2117
2117
return isrMessageGet (queue_id , millisec );
2118
2118
} else { // in Thread
2119
2119
return __svcMessageGet (queue_id , millisec );
@@ -2250,7 +2250,7 @@ osStatus sysMailFree (osMailQId queue_id, void *mail, uint32_t isr) {
2250
2250
2251
2251
/// Create and Initialize mail queue
2252
2252
osMailQId osMailCreate (const osMailQDef_t * queue_def , osThreadId thread_id ) {
2253
- if (__get_IPSR () != 0U ) {
2253
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) {
2254
2254
return NULL ; // Not allowed in ISR
2255
2255
}
2256
2256
if (((__get_CONTROL () & 1U ) == 0U ) && (os_running == 0U )) {
@@ -2263,7 +2263,7 @@ osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id) {
2263
2263
2264
2264
/// Allocate a memory block from a mail
2265
2265
void * osMailAlloc (osMailQId queue_id , uint32_t millisec ) {
2266
- if (__get_IPSR () != 0U ) { // in ISR
2266
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) { // in ISR
2267
2267
return sysMailAlloc (queue_id , millisec , 1U );
2268
2268
} else { // in Thread
2269
2269
return __sysMailAlloc (queue_id , millisec , 0U );
@@ -2275,7 +2275,7 @@ void *osMailCAlloc (osMailQId queue_id, uint32_t millisec) {
2275
2275
void * pool ;
2276
2276
void * mem ;
2277
2277
2278
- if (__get_IPSR () != 0U ) { // in ISR
2278
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) { // in ISR
2279
2279
mem = sysMailAlloc (queue_id , millisec , 1U );
2280
2280
} else { // in Thread
2281
2281
mem = __sysMailAlloc (queue_id , millisec , 0U );
@@ -2290,7 +2290,7 @@ void *osMailCAlloc (osMailQId queue_id, uint32_t millisec) {
2290
2290
2291
2291
/// Free a memory block from a mail
2292
2292
osStatus osMailFree (osMailQId queue_id , void * mail ) {
2293
- if (__get_IPSR () != 0U ) { // in ISR
2293
+ if (__get_PRIMASK () != 0U || __get_IPSR () != 0U ) { // in ISR
2294
2294
return sysMailFree (queue_id , mail , 1U );
2295
2295
} else { // in Thread
2296
2296
return __sysMailFree (queue_id , mail , 0U );
0 commit comments