[FL-667] Power saving: deep sleep in tickless state (#300)

* SYSTEM: tickless mode with deep sleep.
* Move FreeRTOS ticks to lptim2.
* API: move all sumbodules init routines to one place.
* Timebase: working lptim2 at tick source.
* API Timebase: lp-timer routines, timer access safe zones prediction and synchronization. 
* FreeRTOS: adjust configuration for tickless mode.
* NFC: support for tickless mode.
* API Timebase: improve tick error handling in IRQ. 
* Apploader: use insomnia mode to run applications.
* BLE: prevent sleep while core2 starting.
* HAL: nap while in insomnia mode.

Co-authored-by: coreglitch <mail@s3f.ru>
This commit is contained in:
あく
2021-01-18 18:08:58 +03:00
committed by GitHub
parent c3a8af8448
commit c8aca9ef48
44 changed files with 395 additions and 200 deletions

View File

@@ -26,7 +26,6 @@
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
@@ -48,18 +47,11 @@
/* USER CODE BEGIN Variables */
/* USER CODE END Variables */
/* Definitions for defaultTask */
osThreadId_t defaultTaskHandle;
const osThreadAttr_t defaultTask_attributes = {
.name = "defaultTask",
.priority = (osPriority_t) osPriorityNormal,
.stack_size = 1024 * 4
};
/* Definitions for app_main */
osThreadId_t app_mainHandle;
const osThreadAttr_t app_main_attributes = {
.name = "app_main",
.priority = (osPriority_t) osPriorityLow,
.priority = (osPriority_t) osPriorityNormal,
.stack_size = 1024 * 4
};
@@ -68,8 +60,7 @@ const osThreadAttr_t app_main_attributes = {
/* USER CODE END FunctionPrototypes */
void StartDefaultTask(void *argument);
extern void app(void *argument);
void app(void *argument);
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
@@ -77,7 +68,7 @@ void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
void configureTimerForRunTimeStats(void);
unsigned long getRunTimeCounterValue(void);
void vApplicationIdleHook(void);
void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName);
void vApplicationStackOverflowHook(TaskHandle_t xTask, signed char *pcTaskName);
/* USER CODE BEGIN 1 */
/* Functions needed when configGENERATE_RUN_TIME_STATS is on */
@@ -108,7 +99,7 @@ __weak void vApplicationIdleHook( void )
/* USER CODE END 2 */
/* USER CODE BEGIN 4 */
__weak void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName)
__weak void vApplicationStackOverflowHook(TaskHandle_t xTask, signed char *pcTaskName)
{
/* Run time stack overflow checking is performed if
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook function is
@@ -116,6 +107,9 @@ __weak void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTask
}
/* USER CODE END 4 */
/* USER CODE BEGIN VPORT_SUPPORT_TICKS_AND_SLEEP */
/* USER CODE END VPORT_SUPPORT_TICKS_AND_SLEEP */
/**
* @brief FreeRTOS initialization
* @param None
@@ -143,9 +137,6 @@ void MX_FREERTOS_Init(void) {
/* USER CODE END RTOS_QUEUES */
/* Create the thread(s) */
/* creation of defaultTask */
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);
/* creation of app_main */
app_mainHandle = osThreadNew(app, NULL, &app_main_attributes);
@@ -159,22 +150,22 @@ void MX_FREERTOS_Init(void) {
}
/* USER CODE BEGIN Header_StartDefaultTask */
/* USER CODE BEGIN Header_app */
/**
* @brief Function implementing the defaultTask thread.
* @brief Function implementing the app_main thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartDefaultTask */
void StartDefaultTask(void *argument)
/* USER CODE END Header_app */
__weak void app(void *argument)
{
/* USER CODE BEGIN StartDefaultTask */
/* USER CODE BEGIN app */
/* Infinite loop */
for(;;)
{
osDelay(1);
}
/* USER CODE END StartDefaultTask */
/* USER CODE END app */
}
/* Private application code --------------------------------------------------*/