Adacallback support fromISR call
- change Prioprity for loop() to LOW - defer interrupt for both hw and sw encoder to ada callback
This commit is contained in:
1 parent
9b71709c13
commit
b2e49f2fc9
8 files changed
+26
-12
No files matched your search
@@ -131,7 +131,7 @@
|
||||
|
||||
/* Software timer definitions. */
|
||||
#define configUSE_TIMERS 1
|
||||
#define configTIMER_TASK_PRIORITY ( 2 )
|
||||
#define configTIMER_TASK_PRIORITY ( 2 ) // Normal
|
||||
#define configTIMER_QUEUE_LENGTH 32
|
||||
#define configTIMER_TASK_STACK_DEPTH ( 100 )
|
||||
|
||||
|
||||
+1
-1
@@ -93,7 +93,7 @@ int main( void )
|
||||
|
||||
// Create a task for loop()
|
||||
TaskHandle_t _loopHandle;
|
||||
xTaskCreate( loop_task, "loop", _loopStacksize, NULL, TASK_PRIO_NORMAL, &_loopHandle);
|
||||
xTaskCreate( loop_task, "loop", _loopStacksize, NULL, TASK_PRIO_LOW, &_loopHandle);
|
||||
|
||||
// Initialize callback task
|
||||
ada_callback_init();
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ bool SchedulerRTOS::startLoop(taskfunc_t task, uint32_t stack_size)
|
||||
bool SchedulerRTOS::startLoop(taskfunc_t task, const char* name, uint32_t stack_size)
|
||||
{
|
||||
TaskHandle_t handle;
|
||||
return pdPASS == xTaskCreate( _redirect_task, name, stack_size, (void*) task, TASK_PRIO_NORMAL, &handle);
|
||||
return pdPASS == xTaskCreate( _redirect_task, name, stack_size, (void*) task, TASK_PRIO_LOW, &handle);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
|
||||
+2
-2
@@ -55,8 +55,8 @@
|
||||
enum
|
||||
{
|
||||
TASK_PRIO_LOWEST = 0, // Idle task, should not be used
|
||||
TASK_PRIO_LOW = 1,
|
||||
TASK_PRIO_NORMAL = 2, // Loop, Timer Task
|
||||
TASK_PRIO_LOW = 1, // Loop
|
||||
TASK_PRIO_NORMAL = 2, // Timer Task, Callback Task
|
||||
TASK_PRIO_HIGH = 3, // Bluefruit Task
|
||||
TASK_PRIO_HIGHEST = 4,
|
||||
};
|
||||
|
||||
@@ -74,7 +74,13 @@ void adafruit_callback_task(void* arg)
|
||||
|
||||
void ada_callback_queue(ada_callback_t* cb_data)
|
||||
{
|
||||
xQueueSend(_cb_queue, (void*) &cb_data, CFG_CALLBACK_TIMEOUT);
|
||||
if ( cb_data->from_isr )
|
||||
{
|
||||
xQueueSendFromISR(_cb_queue, (void*) &cb_data, NULL);
|
||||
}else
|
||||
{
|
||||
xQueueSend(_cb_queue, (void*) &cb_data, CFG_CALLBACK_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
void ada_callback_init(void)
|
||||
|
||||
@@ -52,6 +52,7 @@ typedef struct
|
||||
void* callback_func;
|
||||
|
||||
uint8_t arg_count;
|
||||
bool from_isr;
|
||||
// uint8_t callback_type;
|
||||
// uint8_t _reserved[2];
|
||||
|
||||
@@ -86,12 +87,13 @@ 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.
|
||||
* The first parameter is malloced Pointer (NULL if not), so that callback could know to free memory
|
||||
*/
|
||||
#define ada_callback(_malloced, _func, ... ) \
|
||||
#define _cb_setup(_from_isr, _malloced, _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) ); \
|
||||
cb_data->malloced_data = _malloced;\
|
||||
cb_data->callback_func = (void*)_func;\
|
||||
cb_data->from_isr = _from_isr;\
|
||||
cb_data->arg_count = _count;\
|
||||
if ( _count ) {\
|
||||
uint32_t arguments[] = { _ADA_CB_ARGS(__VA_ARGS__) };\
|
||||
@@ -100,6 +102,9 @@ typedef void (*adacb_5arg_t) (uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
|
||||
ada_callback_queue(cb_data);\
|
||||
} while(0)
|
||||
|
||||
#define ada_callback(... ) _cb_setup(false, __VA_ARGS__)
|
||||
#define ada_callback_fromISR(... ) _cb_setup(true , __VA_ARGS__)
|
||||
|
||||
void ada_callback_init(void);
|
||||
void ada_callback_queue(ada_callback_t* cb_data);
|
||||
|
||||
|
||||
@@ -198,7 +198,7 @@ void HwRotaryEncoder::_irq_handler(void)
|
||||
if ( _cb )
|
||||
{
|
||||
int32_t step = read();
|
||||
if ( step ) ada_callback(NULL, _cb, step);
|
||||
if ( step ) ada_callback_fromISR(NULL, _cb, step);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,17 +124,20 @@ void SwRotaryEncoder::_irq_handler(void)
|
||||
|
||||
if ( val != _a_last )
|
||||
{
|
||||
int32_t step = 0;
|
||||
|
||||
if ( val != digitalRead(_pinb) )
|
||||
{
|
||||
_abs++;
|
||||
if (_cb) _cb(1);
|
||||
step = 1;
|
||||
}else
|
||||
{
|
||||
_abs--;
|
||||
if (_cb) _cb(-1);
|
||||
step = -1;
|
||||
}
|
||||
|
||||
_abs += step;
|
||||
_a_last = val;
|
||||
|
||||
if (_cb) ada_callback_fromISR(NULL, _cb, step);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user