Added new app_utils module/lib containing miscellaneous utility functions like blocking delays and such. Still need to fully implement the elapsed_ms function.

This commit is contained in:
anschrammh 2023-04-13 13:31:54 +02:00
parent 4184be2763
commit cfc42779dd
6 changed files with 109 additions and 4 deletions

View File

@ -30,11 +30,12 @@ endif
endif
COMPONENTS_$(TARGET) = \
$(TOP_DIR)/app/libuser$(LIB_EXT) \
$(TOP_DIR)/app/app_drivers/libappdrivers$(LIB_EXT) \
$(TOP_DIR)/app/libuser$(LIB_EXT) \
$(TOP_DIR)/app/app_drivers/libappdrivers$(LIB_EXT) \
$(TOP_DIR)/app/persistency/libpersistency$(LIB_EXT) \
$(TOP_DIR)/app/translation/libtranslation$(LIB_EXT) \
$(TOP_DIR)/app/ble/libble$(LIB_EXT) \
$(TOP_DIR)/app/ble/libble$(LIB_EXT) \
$(TOP_DIR)/app/app_utils/libapputils$(LIB_EXT) \
$(TOP_DIR)/lvgl/liblvgl$(LIB_EXT)
ifeq ($(USE_LIB), 0)

View File

@ -0,0 +1,15 @@
TOP_DIR = ../..
sinclude $(TOP_DIR)/tools/w800/conf.mk
ifndef PDIR
GEN_LIBS = libapputils$(LIB_EXT)
endif
#DEFINES +=
sinclude $(TOP_DIR)/tools/w800/rules.mk
INCLUDES := $(INCLUDES) -I $(PDIR)include
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile

View File

@ -0,0 +1,61 @@
#include "app_utils.h"
#include "app_log.h"
static uint32_t _elapsed_ms = 0;
void us_delay(uint32_t us)
{
struct tls_timer_cfg timer_config =
{
.is_repeat = false,
.unit = TLS_TIMER_UNIT_US,
.timeout = 0xFFFFFFFF,
};
uint8_t timer_id = tls_timer_create(&timer_config);
if(WM_TIMER_ID_INVALID == timer_id)
{
APP_LOG_ERROR("Failed to create timer");
return;
}
tls_timer_start(timer_id);
// Perform a blocking delay
while(tls_timer_read(timer_id) < us);
// Don't forget to free the used timer
tls_timer_destroy(timer_id);
}
void ms_delay(uint32_t ms)
{
struct tls_timer_cfg timer_config =
{
.is_repeat = false,
.unit = TLS_TIMER_UNIT_MS,
.timeout = 0xFFFFFFFF,
};
uint8_t timer_id = tls_timer_create(&timer_config);
if(WM_TIMER_ID_INVALID == timer_id)
{
APP_LOG_ERROR("Failed to create timer");
return;
}
tls_timer_start(timer_id);
// Perform a blocking delay
while(tls_timer_read(timer_id) < ms);
// Don't forget to free the used timer
tls_timer_destroy(timer_id);
}
uint32_t elapsed_ms(void)
{
return _elapsed_ms;
}

View File

@ -0,0 +1,27 @@
#ifndef APP_UTILS_H
#define APP_UTILS_H
#include "wm_include.h"
/**
* @brief Wait for the specified time in micro seconds. This is a blocking function !
*
* @param us the specified time to wait in µs.
*/
void us_delay(uint32_t us);
/**
* @brief Wait for the specified time in milli seconds. This is a blocking function !
*
* @param ms the specified time to wait in ms.
*/
void ms_delay(uint32_t ms);
/**
* @brief Returns the current milli seconds count elapsed since the start of the program.
*
* @return uint32_t the elapsed time in ms
*/
uint32_t elapsed_ms(void);
#endif //APP_UTILS_H

View File

@ -70,7 +70,7 @@
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 1 //ʹ<>ÿ<EFBFBD><C3BF>й<EFBFBD><D0B9><EFBFBD>
#define configUSE_TICK_HOOK 1
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ( ( unsigned long ) 40000000 ) /* =12.0MHz xtal multiplied by 5 using the PLL. *///???????????????

View File

@ -51,6 +51,7 @@ INCLUDES += -I $(TOP_DIR)/app/app_drivers/i2c
INCLUDES += -I $(TOP_DIR)/app/app_drivers/watch_peripherals
INCLUDES += -I $(TOP_DIR)/app/app_include
INCLUDES += -I $(TOP_DIR)/app/ble
INCLUDES += -I $(TOP_DIR)/app/app_utils
INCLUDES += -I $(TOP_DIR)/app/gfx
INCLUDES += -I $(TOP_DIR)/app/persistency
INCLUDES += -I $(TOP_DIR)/app/translation