refactor ada_callback, detect isr using cortex ICSR
remove ada_callback_FromISR()
This commit is contained in:
1 parent
4f5a143475
commit
577b2039b2
5 files changed
+15
-13
No files matched your search
@@ -151,7 +151,7 @@ void GPIOTE_IRQHandler()
|
||||
if (channelMap[ch] != -1 && callbacksInt[ch]) {
|
||||
if ( callbackDeferred[ch] ) {
|
||||
// Adafruit defer callback to non-isr if configured so
|
||||
ada_callback_fromISR(NULL, 0, callbacksInt[ch]);
|
||||
ada_callback(NULL, 0, callbacksInt[ch]);
|
||||
}else{
|
||||
callbacksInt[ch]();
|
||||
}
|
||||
|
||||
@@ -72,9 +72,15 @@ void adafruit_callback_task(void* arg)
|
||||
}
|
||||
}
|
||||
|
||||
void ada_callback_queue(ada_callback_t* cb_data, bool from_isr)
|
||||
//! Test if in interrupt mode
|
||||
static inline bool is_isr(void)
|
||||
{
|
||||
if ( from_isr )
|
||||
return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0 ;
|
||||
}
|
||||
|
||||
void ada_callback_queue(ada_callback_t* cb_data)
|
||||
{
|
||||
if ( is_isr() )
|
||||
{
|
||||
xQueueSendFromISR(_cb_queue, (void*) &cb_data, NULL);
|
||||
}else
|
||||
|
||||
@@ -94,7 +94,7 @@ typedef void (*adacb_5arg_t) (uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
|
||||
/**
|
||||
* Macro function is called by other module with all intended parameters.
|
||||
*/
|
||||
#define _cb_setup(_from_isr, _mdata, _mlen, _func, ... ) \
|
||||
#define _cb_setup(_mdata, _mlen, _func, ... ) \
|
||||
do { \
|
||||
uint8_t const _count = VA_ARGS_NUM(__VA_ARGS__); \
|
||||
ada_callback_t* cb_data = (ada_callback_t*) rtos_malloc( sizeof(ada_callback_t) + (_count ? (_count-1)*4 : 0) );\
|
||||
@@ -115,7 +115,7 @@ typedef void (*adacb_5arg_t) (uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
|
||||
}\
|
||||
memcpy(cb_data->arguments, arguments, 4*_count); \
|
||||
} \
|
||||
ada_callback_queue(cb_data, _from_isr); \
|
||||
ada_callback_queue(cb_data); \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
@@ -127,15 +127,11 @@ typedef void (*adacb_5arg_t) (uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
|
||||
* - 3rd arg : function to be invoked
|
||||
* - 3rd-7th arg : function argument, will be cast to uint32_t
|
||||
*/
|
||||
#define ada_callback(... ) _cb_setup(false, __VA_ARGS__)
|
||||
#define ada_callback(...) _cb_setup(__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* Similar to ada_callback() but invoke in ISR-context
|
||||
*/
|
||||
#define ada_callback_fromISR(... ) _cb_setup(true, __VA_ARGS__)
|
||||
|
||||
void ada_callback_init(void);
|
||||
void ada_callback_queue(ada_callback_t* cb_data, bool from_isr);
|
||||
void ada_callback_queue(ada_callback_t* cb_data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ void HwRotaryEncoder::_irq_handler(void)
|
||||
if ( _cb )
|
||||
{
|
||||
int32_t step = read();
|
||||
if ( step ) ada_callback_fromISR(NULL, 0, _cb, step);
|
||||
if ( step ) ada_callback(NULL, 0, _cb, step);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ void SwRotaryEncoder::_irq_handler(void)
|
||||
_abs += step;
|
||||
_a_last = bita;
|
||||
|
||||
if (_cb) ada_callback_fromISR(NULL, 0, _cb, step);
|
||||
if (_cb) ada_callback(NULL, 0, _cb, step);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user