Skip to content

Commit

Permalink
update macros and introduce __IRQ_SAFE
Browse files Browse the repository at this point in the history
  • Loading branch information
GorgonMeducer committed Mar 24, 2021
1 parent c9a0f16 commit ed90b5b
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 35 deletions.
4 changes: 2 additions & 2 deletions example/app_platform/app_platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ volatile static int32_t s_nCycleCounts = 0;
*/
void start_counter(void)
{
SAFE_ATOM_CODE(){
__IRQ_SAFE {
s_nCycleCounts = (int32_t)SysTick->VAL - (int32_t)SysTick->LOAD;
}
}
Expand All @@ -110,7 +110,7 @@ static ALWAYS_INLINE void counter_overflow(void)
*/
int32_t stop_counter(void)
{
SAFE_ATOM_CODE(){
__IRQ_SAFE {
s_nCycleCounts += (int32_t)SysTick->LOAD - (int32_t)SysTick->VAL;
}
return s_nCycleCounts;
Expand Down
4 changes: 2 additions & 2 deletions example/build/mdk/Blinky.uvoptx
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@
<GroupNumber>3</GroupNumber>
<FileNumber>6</FileNumber>
<FileType>1</FileType>
<tvExp>0</tvExp>
<tvExp>1</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\sources\gmsi\utilities\arm\signal.c</PathWithFileName>
Expand All @@ -324,7 +324,7 @@
<GroupNumber>3</GroupNumber>
<FileNumber>7</FileNumber>
<FileType>1</FileType>
<tvExp>1</tvExp>
<tvExp>0</tvExp>
<tvExpOptDlg>0</tvExpOptDlg>
<bDave2>0</bDave2>
<PathWithFileName>..\..\..\sources\gmsi\gmsi.c</PathWithFileName>
Expand Down
2 changes: 1 addition & 1 deletion sources/gmsi/service/memory/stream2block/stream2block.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
BLOCK.Size.Get(ref_obj_as((*ptBlock), block_t)); \
s_t##__NAME##StreamOutService.hwIndex = 0; \
\
SAFE_ATOM_CODE(){ \
__IRQ_SAFE { \
__NAME##_serial_port_enable_tx_cpl_interrupt(); \
\
__NAME##_serial_port_fill_byte( \
Expand Down
14 changes: 7 additions & 7 deletions sources/gmsi/service/scheduler/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ bool scheduler( void )
return false;
}
)*/
SAFE_ATOM_CODE(){
__IRQ_SAFE {
pTask = get_task_from_queue(s_TaskQueuePool);
}
if (NULL == pTask) {
Expand Down Expand Up @@ -519,7 +519,7 @@ bool scheduler( void )
}
)
*/
SAFE_ATOM_CODE(){
__IRQ_SAFE {
if (pTask->ptFlag->bSignal) {
//! signal already set
pTask->bThreadBlocked = false;
Expand Down Expand Up @@ -614,7 +614,7 @@ void set_event(event_t *pEvent)

)
#else
SAFE_ATOM_CODE(){
__IRQ_SAFE {
//! wake up blocked tasks
safe_task_t *pTask = ptEvent->ptHead;
while(NULL != pTask) {
Expand Down Expand Up @@ -683,7 +683,7 @@ void leave_critical_section(critical_section_t *ptCritical)
}
)
#else
SAFE_ATOM_CODE(){
__IRQ_SAFE {
if (!ptEvent->bSignal) {
//! wake up blocked tasks
safe_task_t *ptTask = ptEvent->ptHead;
Expand Down Expand Up @@ -729,7 +729,7 @@ void reset_event(event_t *pEvent)
ptEvent->bSignal = false;
)
#else
SAFE_ATOM_CODE(){
__IRQ_SAFE {
ptEvent->bSignal = false;
}
#endif
Expand Down Expand Up @@ -779,7 +779,7 @@ bool wait_for_single_object(fsm_flag_t *ptFlag, void *ptTask)
}
)
#else
SAFE_ATOM_CODE(){
__IRQ_SAFE {
bResult = ptEvent->bSignal;
if (!ptEvent->bManualReset) {
ptEvent->bSignal = false;
Expand Down Expand Up @@ -854,7 +854,7 @@ static bool _register_task( safe_task_t *pTask )
bResult = false;
}
)*/
SAFE_ATOM_CODE(){
__IRQ_SAFE {
if (!add_task_to_queue(&s_TaskQueuePool[0],pTask)) {
bResult = false;
}
Expand Down
6 changes: 3 additions & 3 deletions sources/gmsi/service/scheduler/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ safe_task_t *new_task( safe_task_func_t *fnRoutine, void *pArg )
}
)
#else
SAFE_ATOM_CODE(){
__IRQ_SAFE {
if (NULL != s_pFreeList) {
pTask = s_pFreeList;
s_pFreeList = s_pFreeList->pNext;
Expand Down Expand Up @@ -260,7 +260,7 @@ void free_task( safe_task_t *pTask )
s_pFreeList = pTask;
)
#else
SAFE_ATOM_CODE(){
__IRQ_SAFE {
pTask->pchKey = NULL; //!< clear task key

//! add task item to freelist
Expand Down Expand Up @@ -297,7 +297,7 @@ bool task_pool_init(void *pHeap, uint16_t hwSize)
s_pFreeList = pTask;
)
#else
SAFE_ATOM_CODE(){
__IRQ_SAFE {
pTask->pchKey = NULL; //!< clear task key

//! add task item to freelist
Expand Down
1 change: 1 addition & 0 deletions sources/gmsi/utilities/arm/arm_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
* Warning Mitigation *
*----------------------------------------------------------------------------*/
#if defined(__clang__) //__IS_COMPILER_LLVM__
#pragma clang diagnostic ignored "-Wcompound-token-split-by-macro"
#pragma clang diagnostic ignored "-Wmissing-declarations"
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#pragma clang diagnostic ignored "-Wmicrosoft-anon-tag"
Expand Down
2 changes: 1 addition & 1 deletion sources/gmsi/utilities/arm/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ bool enter_lock(locker_t *ptLock)
return true;
}
if (UNLOCKED == (*ptLock)) {
SAFE_ATOM_CODE(){
__IRQ_SAFE {
if (UNLOCKED == (*ptLock)) {
(*ptLock) = LOCKED;
bResult = true;
Expand Down
8 changes: 8 additions & 0 deletions sources/gmsi/utilities/arm/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
/*============================ INCLUDES ======================================*/
#include <stdbool.h>
#include <stdint.h>
#include "../preprocessor/preprocessor.h"

/*! \brief How To Define and Use your own CODE_REGION
*! Example:
Expand Down Expand Up @@ -205,6 +206,13 @@
__CODE_REGION_SIMPLE((__REGION_ADDR), __VA_ARGS__)



#ifndef __IRQ_SAFE
# define __IRQ_SAFE \
using( uint32_t CONNECT2(temp,__LINE__) = __disable_irq(), \
__set_PRIMASK(CONNECT2(temp,__LINE__)))
#endif

/*============================ TYPES =========================================*/
typedef volatile bool locker_t;

Expand Down
44 changes: 25 additions & 19 deletions sources/gmsi/utilities/preprocessor/language_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
#define __LANGUAGE_EXTENSION_H__

#include "../3rd-party/PLOOC/plooc.h"
#include "./connect.h"

#undef __using1
#undef __using2
#undef __using3
#undef __using4
#undef using

#define __using1(__declare) \
for (__declare, *CONNECT3(__using_, __LINE__,_ptr) = NULL; \
Expand All @@ -30,57 +36,57 @@
#define __using2(__declare, __on_leave_expr) \
for (__declare, *CONNECT3(__using_, __LINE__,_ptr) = NULL; \
CONNECT3(__using_, __LINE__,_ptr)++ == NULL; \
__on_leave_expr \
(__on_leave_expr) \
)

#define __using3(__declare, __on_enter_expr, __on_leave_expr) \
for (__declare, *CONNECT3(__using_, __LINE__,_ptr) = NULL; \
CONNECT3(__using_, __LINE__,_ptr)++ == NULL ? \
((__on_enter_expr),1) : 0; \
__on_leave_expr \
(__on_leave_expr) \
)

#define __using4(__dcl1, __dcl2, __on_enter_expr, __on_leave_expr) \
for (__dcl1, __dcl2, *CONNECT3(__using_, __LINE__,_ptr) = NULL; \
CONNECT3(__using_, __LINE__,_ptr)++ == NULL ? \
((__on_enter_expr),1) : 0; \
__on_leave_expr \
(__on_leave_expr) \
)

#define using(...) \
CONNECT2(__using, __PLOOC_VA_NUM_ARGS(__VA_ARGS__))(__VA_ARGS__)


#undef __with2
#undef __with3
#undef with

#define __with2(__type, __addr) \
using(__type *_p=(__addr))
using(__type *_=(__addr))
#define __with3(__type, __addr, __item) \
using(__type *_p=(__addr), *__item = _p, _p=_p, )
using(__type *_=(__addr), *__item = _, _=_,_=_ )

#define with(...) \
CONNECT2(__with, __PLOOC_VA_NUM_ARGS(__VA_ARGS__))(__VA_ARGS__)

#ifndef dimof
# define dimof(__array) (sizeof(__array)/sizeof(__array[0]))
#endif
#undef _

#undef foreach2
#undef foreach3
#undef foreach

#define foreach2(__type, __array) \
using(__type *_p = __array) \
using(__type *_ = __array) \
for ( uint_fast32_t CONNECT2(count,__LINE__) = dimof(__array); \
CONNECT2(count,__LINE__) > 0; \
_p++, CONNECT2(count,__LINE__)-- \
_++, CONNECT2(count,__LINE__)-- \
)

#define foreach3(__type, __array, __item) \
using(__type *_p = __array, *__item = _p, _p = _p, ) \
using(__type *_ = __array, *__item = _, _ = _, ) \
for ( uint_fast32_t CONNECT2(count,__LINE__) = dimof(__array); \
CONNECT2(count,__LINE__) > 0; \
_p++, __item = _p, CONNECT2(count,__LINE__)-- \
)

#define foreach4(__type, __array, __count, __item) \
using(__type *_p = __array, *__item = _p, _p = _p, ) \
for ( uint_fast32_t CONNECT2(count,__LINE__) = (__count); \
CONNECT2(count,__LINE__) > 0; \
_p++, __item = _p, CONNECT2(count,__LINE__)-- \
_++, __item = _, CONNECT2(count,__LINE__)-- \
)

#define foreach(...) \
Expand Down

0 comments on commit ed90b5b

Please sign in to comment.