diff --git a/FreeRTOSConfig.h b/FreeRTOSConfig.h index c56a883..51bc917 100644 --- a/FreeRTOSConfig.h +++ b/FreeRTOSConfig.h @@ -109,6 +109,11 @@ #define configCHECK_FOR_STACK_OVERFLOW 2 #define configENABLE_BACKWARD_COMPATIBILITY 0 +#define configUSE_TIMERS 1 +#define configTIMER_TASK_PRIORITY 4 // above normal +#define configTIMER_TASK_STACK_DEPTH 128 +#define configTIMER_QUEUE_LENGTH 4 + #define configTOTAL_HEAP_SIZE 4096 /* Co-routine definitions. */ diff --git a/freertos.c b/freertos.c index b19b04a..045e3e0 100644 --- a/freertos.c +++ b/freertos.c @@ -125,6 +125,21 @@ void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackTy } /* USER CODE END GET_IDLE_TASK_MEMORY */ + +/* USER CODE BEGIN GET_IDLE_TASK_MEMORY */ +static StaticTask_t xTimersTaskTCBBuffer; +static StackType_t xTimersStack[configTIMER_TASK_STACK_DEPTH]; + +void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimersTaskTCBBuffer, StackType_t **ppxTimersTaskStackBuffer, uint32_t *pulTimersTaskStackSize ) +{ + *ppxTimersTaskTCBBuffer = &xTimersTaskTCBBuffer; + *ppxTimersTaskStackBuffer = &xTimersStack[0]; + *pulTimersTaskStackSize = configTIMER_TASK_STACK_DEPTH; + /* place for user code */ +} +/* USER CODE END GET_IDLE_TASK_MEMORY */ + + /* Init FreeRTOS */ void MX_FREERTOS_Init(void) { diff --git a/units/1wire/_ow_internal.h b/units/1wire/_ow_internal.h index 8a5983c..5038ba5 100644 --- a/units/1wire/_ow_internal.h +++ b/units/1wire/_ow_internal.h @@ -19,6 +19,7 @@ struct priv { GPIO_TypeDef *port; uint32_t ll_pin; + TimerHandle_t busyWaitTimer; // timer used to wait for ds1820 measurement completion }; // Prototypes diff --git a/units/1wire/unit_1wire.c b/units/1wire/unit_1wire.c index 602b583..3ed95f7 100644 --- a/units/1wire/unit_1wire.c +++ b/units/1wire/unit_1wire.c @@ -76,12 +76,21 @@ static void U1WIRE_writeIni(Unit *unit, IniWriter *iw) // ------------------------------------------------------------------------ +static void U1WIRE_TimerCb(TimerHandle_t xTimer) +{ + +} + /** Allocate data structure and set defaults */ static error_t U1WIRE_preInit(Unit *unit) { struct priv *priv = unit->data = calloc_ck(1, sizeof(struct priv)); if (priv == NULL) return E_OUT_OF_MEM; + // the timer is not started until needed + priv->busyWaitTimer = xTimerCreate("1w_tim", 750, false, unit, U1WIRE_TimerCb); + if (priv->busyWaitTimer == NULL) return E_OUT_OF_MEM; + // some defaults priv->pin_number = 0; priv->port_name = 'A'; @@ -122,6 +131,9 @@ static void U1WIRE_deInit(Unit *unit) // Release all resources rsc_teardown(unit); + // Delete the software timer + assert_param(pdPASS == xTimerDelete(priv->busyWaitTimer, 1000)); + // Free memory free_ck(unit->data); }