for easylogger

master
ThinkPad-T460P 2021-03-09 18:17:28 +08:00
parent ac3cdef938
commit 2aa2151c95
19 changed files with 362 additions and 267 deletions

View File

@ -29,6 +29,7 @@
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.runtimelibrary_c.1187387752" name="Runtime library" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.runtimelibrary_c" useByScannerDiscovery="true" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.runtimelibrary_c.value.standard_c" valueType="enumerated"/> <option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.runtimelibrary_c.1187387752" name="Runtime library" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.runtimelibrary_c" useByScannerDiscovery="true" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.runtimelibrary_c.value.standard_c" valueType="enumerated"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.converthex.1986680919" name="Convert to Intel Hex file (-O ihex)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.converthex" useByScannerDiscovery="false" value="true" valueType="boolean"/> <option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.converthex.1986680919" name="Convert to Intel Hex file (-O ihex)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.converthex" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.convertbinary.1096157515" name="Convert to binary file (-O binary)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.convertbinary" useByScannerDiscovery="false" value="false" valueType="boolean"/> <option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.convertbinary.1096157515" name="Convert to binary file (-O binary)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.convertbinary" useByScannerDiscovery="false" value="false" valueType="boolean"/>
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.listfile.466232204" name="Generate list file" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.listfile" useByScannerDiscovery="false" value="true" valueType="boolean"/>
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform.1735301810" isAbstract="false" osList="all" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform"/> <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform.1735301810" isAbstract="false" osList="all" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform"/>
<builder buildPath="${workspace_loc:/NaviKit_stm32}/Debug" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder.901379162" keepEnvironmentInBuildfile="false" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="unlimited" stopOnErr="false" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder"/> <builder buildPath="${workspace_loc:/NaviKit_stm32}/Debug" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder.901379162" keepEnvironmentInBuildfile="false" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="unlimited" stopOnErr="false" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder"/>
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.451303658" name="MCU GCC Assembler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler"> <tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.451303658" name="MCU GCC Assembler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler">
@ -44,13 +45,14 @@
<listOptionValue builtIn="false" value="DEBUG"/> <listOptionValue builtIn="false" value="DEBUG"/>
</option> </option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.includepaths.186388616" name="Include paths (-I)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.includepaths" useByScannerDiscovery="false" valueType="includePath"> <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.includepaths.186388616" name="Include paths (-I)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.includepaths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="../App/Inc"/>
<listOptionValue builtIn="false" value="../Core/Inc"/> <listOptionValue builtIn="false" value="../Core/Inc"/>
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Device/ST/STM32F1xx/Include"/> <listOptionValue builtIn="false" value="../Drivers/CMSIS/Device/ST/STM32F1xx/Include"/>
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Include"/> <listOptionValue builtIn="false" value="../Drivers/CMSIS/Include"/>
<listOptionValue builtIn="false" value="../Drivers/STM32F1xx_HAL_Driver/Inc"/> <listOptionValue builtIn="false" value="../Drivers/STM32F1xx_HAL_Driver/Inc"/>
<listOptionValue builtIn="false" value="../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy"/> <listOptionValue builtIn="false" value="../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy"/>
<listOptionValue builtIn="false" value="../Middlewares/Coulomb"/> <listOptionValue builtIn="false" value="../Middlewares/Coulomb"/>
<listOptionValue builtIn="false" value="../Middlewares/Log"/> <listOptionValue builtIn="false" value="../Middlewares/EasyLogger/easylogger/inc"/>
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc"/> <listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc"/>
<listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USB_Device_Library/Core/Inc"/> <listOptionValue builtIn="false" value="../Middlewares/ST/STM32_USB_Device_Library/Core/Inc"/>
<listOptionValue builtIn="false" value="../Middlewares/Third_Party/FreeRTOS/Source/include"/> <listOptionValue builtIn="false" value="../Middlewares/Third_Party/FreeRTOS/Source/include"/>
@ -85,19 +87,13 @@
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objcopy.symbolsrec.1182938463" name="MCU Output Converter Motorola S-rec with symbols" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objcopy.symbolsrec"/> <tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objcopy.symbolsrec.1182938463" name="MCU Output Converter Motorola S-rec with symbols" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.objcopy.symbolsrec"/>
</toolChain> </toolChain>
</folderInfo> </folderInfo>
<fileInfo id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.502298629.1109380639" name="log.h" rcbsApplicability="disable" resourcePath="Middlewares/Log/log.h" toolsToInvoke=""> <fileInfo id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.502298629.1450340378" name="elog_cfg.h" rcbsApplicability="disable" resourcePath="Middlewares/EasyLogger/easylogger/inc/elog_cfg.h" toolsToInvoke=""/>
<tool customBuildStep="true" id="org.eclipse.cdt.managedbuilder.ui.rcbs.429610301" name="Resource Custom Build Step">
<inputType id="org.eclipse.cdt.managedbuilder.ui.rcbs.inputtype.835196452" name="Resource Custom Build Step Input Type">
<additionalInput kind="additionalinputdependency" paths=""/>
</inputType>
<outputType id="org.eclipse.cdt.managedbuilder.ui.rcbs.outputtype.145240003" name="Resource Custom Build Step Output Type"/>
</tool>
</fileInfo>
<sourceEntries> <sourceEntries>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="App"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="CMSIS"/> <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="CMSIS"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Core"/> <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Core"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Drivers"/> <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Drivers"/>
<entry excluding="Log/printf.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Middlewares"/> <entry excluding="Third_Party/FreeRTOS-Plus/Source/Utilities/logging|EasyLogger/easylogger/plugins|EasyLogger/docs" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Middlewares"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="USB_DEVICE"/> <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="USB_DEVICE"/>
</sourceEntries> </sourceEntries>
</configuration> </configuration>

View File

@ -6,7 +6,7 @@
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/> <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1017288726492030834" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true"> <provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1757187311709498749" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/> <language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/> <language-scope id="org.eclipse.cdt.core.g++"/>
</provider> </provider>
@ -18,7 +18,7 @@
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/> <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1060366468373618296" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true"> <provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1800265053591086211" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/> <language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/> <language-scope id="org.eclipse.cdt.core.g++"/>
</provider> </provider>

View File

@ -5,6 +5,8 @@
"*.tcu": "cpp", "*.tcu": "cpp",
"*.json": "json", "*.json": "json",
"*.txt": "txt", "*.txt": "txt",
"navikit.h": "c" "navikit.h": "c",
"isp.h": "c",
"cdc.h": "c"
} }
} }

View File

@ -1,6 +1,17 @@
/*
* @Description:
* @Date: 2021-03-09 10:22:15
* @LastEditors: CK.Zh
* @LastEditTime: 2021-03-09 10:26:05
* @FilePath: \NaviKit_EC_stm32\App\Inc\isp.h
*/
#ifndef __ISP_H__
#define __ISP_H__
#include "main.h" #include "main.h"
#define ISP_ADDRESS 0x1fffb000 //In-System-Program address in flash #define ISP_ADDRESS 0x1fffb000 //In-System-Program address in flash
#define MAGIC_VALUE_ADDRESS RTC_BKP_DR1 #define MAGIC_VALUE_ADDRESS RTC_BKP_DR1
#define MAGIC_VALUE 0xa5a5 //jump to isp while ISP_BKP_DR's value equal this #define MAGIC_VALUE 0xa5a5 //jump to isp while ISP_BKP_DR's value equal this
@ -9,3 +20,5 @@
void ISP_Jump(); void ISP_Jump();
void ISP_Judge(); void ISP_Judge();
bool ISP_Prepare(); bool ISP_Prepare();
#endif

18
App/Inc/th_cdc.h Normal file
View File

@ -0,0 +1,18 @@
/*
* @Description:
* @Date: 2021-03-09 10:37:34
* @LastEditors: CK.Zh
* @LastEditTime: 2021-03-09 10:42:05
* @FilePath: \NaviKit_EC_stm32\App\Inc\cdc.h
*/
#ifndef __TH_CDC_H__
#define __TH_CDC_H__
#include "cmsis_os2.h"
osThreadId_t cdcMonitorTaskHandle;
const osThreadAttr_t cdcMonitorTask_attributes;
void StartCdcMonitorTask(void *argument);
#endif

15
App/Inc/th_demo.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef __TH_DEMO_H__
#define __TH_DEMO_H__
#include "cmsis_os2.h"
osThreadId_t DemoTask2Handle;
osThreadId_t DemoTask1Handle;
const osThreadAttr_t DemoTask1_attributes;
const osThreadAttr_t DemoTask2_attributes;
void StartDemoTask1(void *argument);
void StartDemoTask2(void *argument);
#endif

10
App/Inc/th_elog.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef __TH_ELOG_H__
#define __TH_ELOG_H__
#include "cmsis_os2.h"
osThreadId_t ElogInitTaskHandle;
const osThreadAttr_t ElogInitTask_attributes;
void StartElogInitTask(void *argument);
void my_elog_init();
#endif

View File

@ -1,4 +1,11 @@
#include "isp.h" /*
* @Description:
* @Date: 2021-03-09 10:21:58
* @LastEditors: CK.Zh
* @LastEditTime: 2021-03-09 17:42:16
* @FilePath: \NaviKit_EC_stm32\App\Src\isp.c
*/
#include <isp.h>
#include "cmsis_os2.h" // ::CMSIS:RTOS2 #include "cmsis_os2.h" // ::CMSIS:RTOS2
void ISP_Jump(){ void ISP_Jump(){
@ -33,6 +40,8 @@ void ISP_Judge()
ISP_Jump(); ISP_Jump();
} }
} }
bool ISP_Prepare(){ bool ISP_Prepare(){
RTC_HandleTypeDef hrtc; RTC_HandleTypeDef hrtc;
@ -50,11 +59,12 @@ bool ISP_Prepare(){
if(HAL_RTCEx_BKUPRead(&hrtc,MAGIC_VALUE_ADDRESS) == MAGIC_VALUE) if(HAL_RTCEx_BKUPRead(&hrtc,MAGIC_VALUE_ADDRESS) == MAGIC_VALUE)
{//write successful {//write successful
TaskBeep(400,5); TaskBeep(400,5);
Log(trace,sys,"Enter to EC update state."); log_v("Enter to EC update state.");
Log(info,sys,"EC will reboot ,then run ISP automatic."); log_i("EC will reboot ,then run ISP automatic.");
HAL_NVIC_SystemReset(); HAL_NVIC_SystemReset();
} }
else{ else{
Log(error,sys,"Backup register writen error, can not enter EC update state."); log_e("Backup register writen error, can not enter EC update state.");
return false;
} }
} }

57
App/Src/th_cdc.c Normal file
View File

@ -0,0 +1,57 @@
#define LOG_TAG "TH-CDC"
#include <th_cdc.h>
#include "main.h"
#include "usbd_cdc_if.h"
#include "navikit.h"
//global variable
extern uint8_t port_restart[];
extern uint32_t number_restart;
//task attributes
const osThreadAttr_t cdcMonitorTask_attributes = {
.name = "cdcMonitorTask",
.priority = (osPriority_t) osPriorityNormal,
.stack_size = 128 * 4
};
//task instance
void StartCdcMonitorTask(void *argument){
uint8_t port_restart_temp[64]={0};
uint32_t number_restart_temp =0;
bool beep_flag = false;
for(;;){
if(number_restart){
number_restart_temp = number_restart;
memcpy(port_restart_temp,&port_restart,number_restart_temp<=12 ? number_restart_temp : 12);
number_restart = 0;
// turn off usb port device
for(uint8_t i=0;i<number_restart_temp;i++){
if(port_restart_temp[i]<12){
PWR_Enable(port_restart_temp[i], false,200);
log_i("USB Port%d power off",port_restart_temp[i]);
CDC_Transmit_FS(&port_restart_temp[i],1);
}
}
//turn on usb port device
beep_flag = false;
for(uint8_t i=0;i<number_restart_temp;i++){
if(port_restart_temp[i]<12){
PWR_Enable(port_restart_temp[i], true,200);
log_i("USB Port%d power on",port_restart_temp[i]);
CDC_Transmit_FS(&port_restart_temp[i],1);
beep_flag = true;
}
}
if(beep_flag){
beep_flag = false;
TaskBeep(50, 1);
}
}
osDelay(100);
}
}

30
App/Src/th_demo.c Normal file
View File

@ -0,0 +1,30 @@
#define LOG_TAG "TH-Demo"
#include <th_demo.h>
#include "main.h"
const osThreadAttr_t DemoTask1_attributes = {
.name = "DemoTask1",
.priority = (osPriority_t) osPriorityNormal,
.stack_size = 128 * 4
};
const osThreadAttr_t DemoTask2_attributes = {
.name = "DemoTask2",
.priority = (osPriority_t) osPriorityBelowNormal,
.stack_size = 128 * 4
};
void StartDemoTask1(void *argument){
uint8_t i=0;
for(;;){
log_v("demo task 1 [%d].",i++);
osDelay(1000);
}
}
void StartDemoTask2(void *argument){
uint8_t i=0;
for(;;){
log_v("demo task 2 [%d].",i++);
osDelay(1000);
}
}

86
App/Src/th_elog.c Normal file
View File

@ -0,0 +1,86 @@
/*
* @Description:
* @Date: 2021-03-09 11:30:52
* @LastEditors: CK.Zh
* @LastEditTime: 2021-03-09 17:50:24
* @FilePath: \NaviKit_EC_stm32\App\Src\th_elog.c
*/
#define LOG_TAG "TH-Elog"
#include <th_elog.h>
#include "main.h"
const osThreadAttr_t ElogInitTask_attributes = {
.name = "ElogInitTask",
.priority = (osPriority_t) osPriorityLow,
.stack_size = 128 * 4
};
void StartElogInitTask(void *argument){
elog_init();
/* close printf buffer */
setbuf(stdout, NULL);
#ifndef DEBUG //release mode :only output level、tag、time information
ElogFmtIndex ELOG_FMT_SETTING = ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME;
#else //debug mode:output all information
ElogFmtIndex ELOG_FMT_SETTING = ELOG_FMT_ALL ;
#endif
/* set EasyLogger log format */
/* 断言:输出所有内容 */
elog_set_fmt(ELOG_LVL_ASSERT, ELOG_FMT_SETTING);
/* 错误:输出级别、标签和时间 */
elog_set_fmt(ELOG_LVL_ERROR, ELOG_FMT_SETTING);
/* 警告:输出级别、标签和时间 */
elog_set_fmt(ELOG_LVL_WARN, ELOG_FMT_SETTING);
/* 信息:输出级别、标签和时间 */
elog_set_fmt(ELOG_LVL_INFO, ELOG_FMT_SETTING);
/* 调试:输出除了方法名之外的所有内容 */
elog_set_fmt(ELOG_LVL_DEBUG, ELOG_FMT_SETTING);
/* 详细:输出除了方法名之外的所有内容 */
elog_set_fmt(ELOG_LVL_VERBOSE, ELOG_FMT_SETTING);
/* start EasyLogger */
elog_start();
// log_a("Hello EasyLogger!");
// log_e("Hello EasyLogger!");
// log_w("Hello EasyLogger!");
// log_i("Hello EasyLogger!");
// log_d("Hello EasyLogger!");
// log_v("Hello EasyLogger!");
//
// osDelay(10000);
// log_d("Hello EasyLogger!");
// osThreadExit();//exit this thread,execute this code only once
}
void my_elog_init(){
elog_init();
/* close printf buffer */
setbuf(stdout, NULL);
#ifndef DEBUG //release mode :only output level、tag、time information
ElogFmtIndex ELOG_FMT_SETTING = ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME;
#else //debug mode:output all information
ElogFmtIndex ELOG_FMT_SETTING = ELOG_FMT_ALL ;
#endif
/* set EasyLogger log format */
/* 断言:输出所有内容 */
elog_set_fmt(ELOG_LVL_ASSERT, ELOG_FMT_SETTING);
/* 错误:输出级别、标签和时间 */
elog_set_fmt(ELOG_LVL_ERROR, ELOG_FMT_SETTING);
/* 警告:输出级别、标签和时间 */
elog_set_fmt(ELOG_LVL_WARN, ELOG_FMT_SETTING);
/* 信息:输出级别、标签和时间 */
elog_set_fmt(ELOG_LVL_INFO, ELOG_FMT_SETTING);
/* 调试:输出除了方法名之外的所有内容 */
elog_set_fmt(ELOG_LVL_DEBUG, ELOG_FMT_SETTING);
/* 详细:输出除了方法名之外的所有内容 */
elog_set_fmt(ELOG_LVL_VERBOSE, ELOG_FMT_SETTING);
/* start EasyLogger */
elog_start();
}

View File

@ -34,6 +34,8 @@ extern "C" {
/* USER CODE BEGIN Includes */ /* USER CODE BEGIN Includes */
#include "stdbool.h" #include "stdbool.h"
#include "log.h" #include "log.h"
#include "elog.h"
#include <isp.h>
/* USER CODE END Includes */ /* USER CODE END Includes */
/* Exported types ------------------------------------------------------------*/ /* Exported types ------------------------------------------------------------*/

View File

@ -1,3 +1,10 @@
/*
* @Description:
* @Date: 2020-04-02 21:44:31
* @LastEditors: CK.Zh
* @LastEditTime: 2021-03-09 18:11:08
* @FilePath: \NaviKit_EC_stm32\Core\Src\freertos.c
*/
/* USER CODE BEGIN Header */ /* USER CODE BEGIN Header */
/** /**
****************************************************************************** ******************************************************************************
@ -16,9 +23,13 @@
* *
****************************************************************************** ******************************************************************************
*/ */
//TODO:拆分该文件中的功能到不同的文件中,按照任务进行模块化拆分
/* USER CODE END Header */ /* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "FreeRTOS.h" #include "FreeRTOS.h"
#include "task.h" #include "task.h"
#include "main.h" #include "main.h"
@ -29,7 +40,10 @@
#include "timers.h" #include "timers.h"
#include "navikit.h" #include "navikit.h"
#include "coulomb.h" #include "coulomb.h"
#include "usbd_cdc_if.h" #include <th_cdc.h>
#include <th_demo.h>
#include <th_elog.h>
/* USER CODE END Includes */ /* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/ /* Private typedef -----------------------------------------------------------*/
@ -49,8 +63,7 @@
/* Private variables ---------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */ /* USER CODE BEGIN Variables */
extern uint8_t port_restart;
extern uint8_t number_restart;
//Timer //Timer
osTimerId_t PwrBtnLongPressTimerHandle; osTimerId_t PwrBtnLongPressTimerHandle;
const osTimerAttr_t PwrBtnLongPressTimer_attributes = { const osTimerAttr_t PwrBtnLongPressTimer_attributes = {
@ -75,13 +88,6 @@ const osTimerAttr_t IdleStateHoldTimer_attributes = {
//Thread //Thread
osThreadId_t cdcMonitorTaskHandle;
const osThreadAttr_t cdcMonitorTask_attributes = {
.name = "cdcMonitorTask",
.priority = (osPriority_t) osPriorityNormal,
.stack_size = 128 * 4
};
osThreadId_t LogtoUartTaskHandle; osThreadId_t LogtoUartTaskHandle;
const osThreadAttr_t LogtoUartTask_attributes = { const osThreadAttr_t LogtoUartTask_attributes = {
.name = "LogtoUartTask", .name = "LogtoUartTask",
@ -89,18 +95,7 @@ const osThreadAttr_t LogtoUartTask_attributes = {
.stack_size = 128 * 4 .stack_size = 128 * 4
}; };
osThreadId_t TestTask1Handle;
const osThreadAttr_t TestTask1_attributes = {
.name = "TestTask1",
.priority = (osPriority_t) osPriorityNormal,
.stack_size = 128 * 4
};
osThreadId_t TestTask2Handle;
const osThreadAttr_t TestTask2_attributes = {
.name = "TestTask2",
.priority = (osPriority_t) osPriorityBelowNormal,
.stack_size = 128 * 4
};
//Queue //Queue
//osMessageQueueId_t LogMessageQueueHandle; //osMessageQueueId_t LogMessageQueueHandle;
@ -159,10 +154,7 @@ void IdleStateHoldTimerCallback(void *argument);
//task //task
void StartLogtoUartTask(void *argument); void StartLogtoUartTask(void *argument);
void StartCdcMonitorTask(void *argument);
void StartTestTask1(void *argument);
void StartTestTask2(void *argument);
/* USER CODE END FunctionPrototypes */ /* USER CODE END FunctionPrototypes */
@ -251,7 +243,9 @@ __weak void PostSleepProcessing(uint32_t *ulExpectedIdleTime)
*/ */
void MX_FREERTOS_Init(void) { void MX_FREERTOS_Init(void) {
/* USER CODE BEGIN Init */ /* USER CODE BEGIN Init */
// elog_init();
my_elog_init();
NaviKit_var_init();
/* USER CODE END Init */ /* USER CODE END Init */
/* USER CODE BEGIN RTOS_MUTEX */ /* USER CODE BEGIN RTOS_MUTEX */
@ -297,10 +291,12 @@ void MX_FREERTOS_Init(void) {
/* USER CODE BEGIN RTOS_THREADS */ /* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */ /* add threads, ... */
// LogtoUartTaskHandle = osThreadNew(StartLogtoUartTask, NULL, &LogtoUartTask_attributes); // LogtoUartTaskHandle = osThreadNew(StartLogtoUartTask, NULL, &LogtoUartTask_attributes);
// TestTask1Handle = osThreadNew(StartTestTask1, NULL, &TestTask1_attributes); // DemoTask1Handle = osThreadNew(StartDemoTask1, NULL, &DemoTask1_attributes);
// TestTask2Handle = osThreadNew(StartTestTask2, NULL, &TestTask2_attributes); // DemoTask2Handle = osThreadNew(StartDemoTask2, NULL, &DemoTask2_attributes);
cdcMonitorTaskHandle = osThreadNew(StartCdcMonitorTask, NULL, &cdcMonitorTask_attributes); cdcMonitorTaskHandle = osThreadNew(StartCdcMonitorTask, NULL, &cdcMonitorTask_attributes);
// ElogInitTaskHandle = osThreadNew(StartElogInitTask, NULL, &ElogInitTask_attributes);
// ElogOutputMutexHandle = osMutexNew(&ElogOutputMutex_attributes);
/* USER CODE END RTOS_THREADS */ /* USER CODE END RTOS_THREADS */
@ -338,38 +334,43 @@ void StartDefaultTask(void *argument)
else{ else{
NaviKit.sys.power_btn = true; NaviKit.sys.power_btn = true;
} }
Log(info,sys,"EC Reset source :Power Button WakeUP"); log_i("EC Reset source :Power Button WakeUP");
}else{ }else{
NaviKit.sys.next_sta = idle; NaviKit.sys.next_sta = idle;
Log(info,sys,"EC Reset source :RTC WakeUP"); log_i("EC Reset source :RTC WakeUP");
enter_standby_state(); enter_standby_state();
} }
}else{//judge reset source "power on" }else{//judge reset source "power on"
Log(info,sys,"EC Reset source :PowerON"); log_i("EC Reset source :PowerON");
if(HAL_GPIO_ReadPin(SYS_CUSTOM_BTN_GPIO_Port, SYS_CUSTOM_BTN_Pin)==GPIO_PIN_RESET){ if(HAL_GPIO_ReadPin(SYS_CUSTOM_BTN_GPIO_Port, SYS_CUSTOM_BTN_Pin)==GPIO_PIN_RESET){
Log(debug,sys,"EC next state isp"); log_d("EC next state isp");
NaviKit.sys.next_sta = isp; NaviKit.sys.next_sta = isp;
}else{ }else{
NaviKit.sys.next_sta = idle; NaviKit.sys.next_sta = idle;
} }
TaskBeep(50,1); // TaskBeep(50,1);
} }
Log(info,sys,"----------------------------------------------"); log_i("----------------------------------------------");
Log(info,sys,"Copyright (c) Powered by www.autolabor.com.cn"); log_i("Copyright (c) Powered by www.autolabor.com.cn");
Log(info,sys,"EC Firmware: %s[%s], build: %s, %s, by STD:%u",APP_VERSION,DEPLOY_MODE,__DATE__ ,__TIME__,__STDC_VERSION__ ); log_i("EC Firmware: %s[%s], build: %s, %s, by STD:%u",APP_VERSION,DEPLOY_MODE,__DATE__ ,__TIME__,__STDC_VERSION__ );
Log(info,sys,"HAL Version: %u ", HAL_GetHalVersion()); log_i("HAL Version: 0x%X ", HAL_GetHalVersion());
Log(info,sys,"Revision ID: %u ", HAL_GetREVID()); log_i("Revision ID: 0x%X ", HAL_GetREVID());
Log(info,sys,"Device ID: %u ", HAL_GetDEVID()); log_i("Device ID: 0x%X ", HAL_GetDEVID());
Log(info,sys,"Chip UID: %u%u%u ", HAL_GetUIDw0(),HAL_GetUIDw1(),HAL_GetUIDw2()); log_i("Chip UID: 0x%X%X%X ", HAL_GetUIDw0(),HAL_GetUIDw1(),HAL_GetUIDw2());
if(osOK == osKernelGetInfo(&osVersion,id_buf,id_size)){ if(osOK == osKernelGetInfo(&osVersion,id_buf,id_size)){
Log(info,sys,"OS Kernel Version: %u ", osVersion.kernel); log_i("OS Kernel Version: %u ", osVersion.kernel);
Log(info,sys,"OS Kernel ID: %s ",id_buf); log_i("OS Kernel ID: %s ",id_buf);
} }
Log(info,sys,"Core initial successfully"); log_i("OS Kernel Tick Frequence: %d ",osKernelGetTickFreq());
Log(info,sys,"----------------------------------------------"); log_i("OS Kernel System Timer Frequence: %d ",osKernelGetSysTimerFreq());
log_i("Log Library Version: V%s",ELOG_SW_VERSION);
log_i("Core initial successfully");
// log_i("EasyLogger V%s is initialize success.", ELOG_SW_VERSION);
log_i("----------------------------------------------");
/* Infinite loop */ /* Infinite loop */
for(;;) for(;;)
@ -392,8 +393,8 @@ void StartDefaultTask(void *argument)
// }else{ // }else{
// NaviKit.sys.next_sta = NaviKit.sys.sta; // NaviKit.sys.next_sta = NaviKit.sys.sta;
// TaskBeep(500,2); // TaskBeep(500,2);
// Log(error,pmb,"Main power not exist, retry after plug in it."); // log_e(,"Main power not exist, retry after plug in it.");
// Log(fatal,pmb,"Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000)); // log_e("Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
// } // }
}break; }break;
case sleep:{ case sleep:{
@ -407,8 +408,8 @@ void StartDefaultTask(void *argument)
// }else{ // }else{
// NaviKit.sys.next_sta = NaviKit.sys.sta; // NaviKit.sys.next_sta = NaviKit.sys.sta;
// TaskBeep(500,2); // TaskBeep(500,2);
// Log(error,pmb,"Main power not exist, retry after plug in it."); // log_e(,"Main power not exist, retry after plug in it.");
// Log(fatal,pmb,"Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000)); // log_e("Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
// } // }
}break; }break;
case isp:{ case isp:{
@ -444,7 +445,7 @@ void StartLedBlinkTask(void *argument)
{ {
/* USER CODE BEGIN StartLedBlinkTask */ /* USER CODE BEGIN StartLedBlinkTask */
/* Infinite loop */ /* Infinite loop */
// Log(trace,"Start LED Blink"); // log_v("Start LED Blink");
for(;;) for(;;)
{ {
@ -504,7 +505,7 @@ void StartLedBlinkTask(void *argument)
void StartCoulombRead(void *argument) void StartCoulombRead(void *argument)
{ {
/* USER CODE BEGIN StartCoulombRead */ /* USER CODE BEGIN StartCoulombRead */
// Log(trace,"Start Coulomb Read Task"); // log_v("Start Coulomb Read Task");
//写寄存器方法 //写寄存器方法
coulomb_write_config_load(); coulomb_write_config_load();
coulomb_write_config_actual_to_raw(); coulomb_write_config_actual_to_raw();
@ -523,6 +524,7 @@ void StartCoulombRead(void *argument)
osDelay(500); osDelay(500);
else else
osDelay(5000); osDelay(5000);
} }
/* USER CODE END StartCoulombRead */ /* USER CODE END StartCoulombRead */
} }
@ -537,7 +539,7 @@ void StartCoulombRead(void *argument)
void StartPowerMonitTask(void *argument) void StartPowerMonitTask(void *argument)
{ {
/* USER CODE BEGIN StartPowerMonitTask */ /* USER CODE BEGIN StartPowerMonitTask */
// Log(trace,"Start Power Monitor Task"); // log_v("Start Power Monitor Task");
HAL_ADCEx_Calibration_Start(&hadc1); HAL_ADCEx_Calibration_Start(&hadc1);
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&(NaviKit.pmb.rails.adc), ADC_CH_COUNT); HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&(NaviKit.pmb.rails.adc), ADC_CH_COUNT);
osDelay(100); osDelay(100);
@ -547,10 +549,10 @@ void StartPowerMonitTask(void *argument)
if(NaviKit.pmb.rails.main_pwr > 30){ if(NaviKit.pmb.rails.main_pwr > 30){
TaskBeep(200,1); TaskBeep(200,1);
Log(fatal,pmb,"Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000)); log_e("Main power is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
} }
if(NaviKit.pmb.rails.bkp_bat > 15){ if(NaviKit.pmb.rails.bkp_bat > 15){
Log(fatal,pmb,"Backup battery is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); log_e("Backup battery is exception:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
TaskBeep(200,1); TaskBeep(200,1);
} }
//stat1 stat2 lead-acid //stat1 stat2 lead-acid
@ -562,40 +564,40 @@ void StartPowerMonitTask(void *argument)
NaviKit.pmb.sta.chrg_stat2 = (bool)HAL_GPIO_ReadPin(PMB_CHRG_STAT2_GPIO_Port, PMB_CHRG_STAT2_Pin); NaviKit.pmb.sta.chrg_stat2 = (bool)HAL_GPIO_ReadPin(PMB_CHRG_STAT2_GPIO_Port, PMB_CHRG_STAT2_Pin);
if(!NaviKit.pmb.sta.chrg_stat1 && !NaviKit.pmb.sta.chrg_stat2) if(!NaviKit.pmb.sta.chrg_stat1 && !NaviKit.pmb.sta.chrg_stat2)
Log(trace,pmb,"Backup battery status:%dmV Bulk Charge(Vth=12.6V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); log_v("Backup battery status:%dmV Bulk Charge(Vth=12.6V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
if(!NaviKit.pmb.sta.chrg_stat1 && NaviKit.pmb.sta.chrg_stat2) if(!NaviKit.pmb.sta.chrg_stat1 && NaviKit.pmb.sta.chrg_stat2)
Log(trace,pmb,"Backup battery status:%dmV Absorption Charge(Vth=14.4V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); log_v("Backup battery status:%dmV Absorption Charge(Vth=14.4V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
if(NaviKit.pmb.sta.chrg_stat1 && !NaviKit.pmb.sta.chrg_stat2) if(NaviKit.pmb.sta.chrg_stat1 && !NaviKit.pmb.sta.chrg_stat2)
Log(trace,pmb,"Backup battery status:%dmV Float Charge(Vth=13.3V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); log_v("Backup battery status:%dmV Float Charge(Vth=13.3V)",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
if(NaviKit.pmb.sta.chrg_stat1 && NaviKit.pmb.sta.chrg_stat2) if(NaviKit.pmb.sta.chrg_stat1 && NaviKit.pmb.sta.chrg_stat2)
Log(trace,pmb,"Backup battery status:%dmV Not Charge",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); log_v("Backup battery status:%dmV Not Charge",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
if(NaviKit.sys.sta == run || NaviKit.sys.sta == dfu ){ if(NaviKit.sys.sta == run || NaviKit.sys.sta == dfu ){
if(NaviKit.pmb.rails.main_pwr < 19){ if(NaviKit.pmb.rails.main_pwr < 19){
TaskBeep(200,1); TaskBeep(200,1);
Log(warning,pmb,"Main power has been lost, please shutdown computer as soon as possible:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000)); log_w("Main power has been lost, please shutdown computer as soon as possible:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
}else }else
Log(trace,pmb,"Main power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000)); log_v("Main power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.main_pwr*1000));
if(NaviKit.pmb.rails.out_24v > 26.4 || NaviKit.pmb.rails.out_24v < 21.6) if(NaviKit.pmb.rails.out_24v > 26.4 || NaviKit.pmb.rails.out_24v < 21.6)
Log(fatal,pmb,"24V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000)); log_e("24V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000));
else else
Log(trace,pmb,"24V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000)); log_v("24V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_24v*1000));
if(NaviKit.pmb.rails.out_5v > 5.5 || NaviKit.pmb.rails.out_5v < 4.5) if(NaviKit.pmb.rails.out_5v > 5.5 || NaviKit.pmb.rails.out_5v < 4.5)
Log(fatal,pmb,"5V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000)); log_e("5V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000));
else else
Log(trace,pmb,"5V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000)); log_v("5V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_5v*1000));
if(NaviKit.pmb.rails.out_12v > 13.2 || NaviKit.pmb.rails.out_12v < 10.8) if(NaviKit.pmb.rails.out_12v > 13.2 || NaviKit.pmb.rails.out_12v < 10.8)
Log(fatal ,pmb,"12V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000)); log_e("12V(±10%%) power rail exception:%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000));
else else
Log(trace,pmb,"12V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000)); log_v("12V(±10%%) power rail regular:%dmV",(uint32_t)(NaviKit.pmb.rails.out_12v*1000));
if(NaviKit.pmb.rails.bkp_bat < 9.5) if(NaviKit.pmb.rails.bkp_bat < 9.5)
Log(warning,pmb,"Backup battery exception:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); log_w("Backup battery exception:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
else else
Log(trace,pmb,"Backup battery is regular:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000)); log_v("Backup battery is regular:%dmV",(uint32_t)(NaviKit.pmb.rails.bkp_bat*1000));
osDelay(2000); osDelay(2000);
@ -603,8 +605,8 @@ void StartPowerMonitTask(void *argument)
osDelay(5000); osDelay(5000);
} }
// Log(debug,sys,"state :%d",NaviKit.sys.sta); // log_d("state :%d",NaviKit.sys.sta);
// Log(debug,sys,"next_state :%d",NaviKit.sys.next_sta); // log_d("next_state :%d",NaviKit.sys.next_sta);
} }
/* USER CODE END StartPowerMonitTask */ /* USER CODE END StartPowerMonitTask */
@ -621,7 +623,7 @@ void StartEventDetect(void *argument)
{ {
/* USER CODE BEGIN StartEventDetect */ /* USER CODE BEGIN StartEventDetect */
/* Infinite loop */ /* Infinite loop */
// Log(trace,"Start Event Detect Task."); // log_v("Start Event Detect Task.");
for(;;) for(;;)
{ {
//power button //power button
@ -646,6 +648,8 @@ void StartEventDetect(void *argument)
osTimerStart(CustBtnShortPressTimerHandle,100); osTimerStart(CustBtnShortPressTimerHandle,100);
} }
osDelay(2); osDelay(2);
} }
/* USER CODE END StartEventDetect */ /* USER CODE END StartEventDetect */
} }
@ -653,75 +657,27 @@ void StartEventDetect(void *argument)
/* Private application code --------------------------------------------------*/ /* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */ /* USER CODE BEGIN Application */
void StartCdcMonitorTask(void *argument){
uint8_t port_restart_temp[64]={0};
uint32_t number_restart_temp =0;
bool beep_flag = false;
for(;;){
if(number_restart){
number_restart_temp = number_restart;
memcpy(port_restart_temp,&port_restart,number_restart_temp<=12 ? number_restart_temp : 12);
number_restart = 0;
// turn off usb port device
for(uint8_t i=0;i<number_restart_temp;i++){
if(port_restart_temp[i]<12){
PWR_Enable(port_restart_temp[i], false,200);
Log(info,sys,"USB Port%d power off",port_restart_temp[i]);
CDC_Transmit_FS(&port_restart_temp[i],1);
}
}
//turn on usb port device
beep_flag = false;
for(uint8_t i=0;i<number_restart_temp;i++){
if(port_restart_temp[i]<12){
PWR_Enable(port_restart_temp[i], true,200);
Log(info,sys,"USB Port%d power on",port_restart_temp[i]);
CDC_Transmit_FS(&port_restart_temp[i],1);
beep_flag = true;
}
}
if(beep_flag){
beep_flag = false;
TaskBeep(50, 1);
}
}
osDelay(100);
}
}
void StartLogtoUartTask(void *argument){ void StartLogtoUartTask(void *argument){
// HAL_UART_Transmit(&huart1,(uint8_t *)&ch,1,2); // HAL_UART_Transmit(&huart1,(uint8_t *)&ch,1,2);
} }
void StartTestTask1(void *argument){
uint8_t i=0;
for(;;){
Log(debug,sys,"test task 1 [%d].",i++);
osDelay(1000);
}
}
void StartTestTask2(void *argument){
uint8_t i=0;
for(;;){
Log(debug,sys,"test task 2 [%d].",i++);
osDelay(1000);
}
}
void PwrBtnLongPressTimerCallback(void *argument) void PwrBtnLongPressTimerCallback(void *argument)
{ {
Log(trace,sys,"power btn long pressed."); log_v("power btn long pressed.");
switch(NaviKit.sys.sta){ switch(NaviKit.sys.sta){
case run: {NaviKit.sys.next_sta = idle;Log(trace,sys,"change to idle"); }break;//system is run now, user request to idle case run: {NaviKit.sys.next_sta = idle;log_v("change to idle"); }break;//system is run now, user request to idle
case idle: {NaviKit.sys.next_sta = run;Log(trace,sys,"change to run"); }break;//system is idle now , user request to power on case idle: {NaviKit.sys.next_sta = run;log_v("change to run"); }break;//system is idle now , user request to power on
case dfu: {NaviKit.sys.next_sta = idle;Log(trace,sys,"change to idle"); }break; case dfu: {NaviKit.sys.next_sta = idle;log_v("change to idle"); }break;
case sleep:{NaviKit.sys.next_sta = run;Log(trace,sys,"change to run"); }break; case sleep:{NaviKit.sys.next_sta = run;log_v("change to run"); }break;
case isp: {NaviKit.sys.next_sta = idle;Log(trace,sys,"change to idle"); }break; case isp: {NaviKit.sys.next_sta = idle;log_v("change to idle"); }break;
default : break; default : break;
} }
} }
void CustBtnLongPressTimerCallback(void *argument) void CustBtnLongPressTimerCallback(void *argument)
{ {
Log(trace,sys,"custom btn long pressed."); log_v("custom btn long pressed.");
switch(NaviKit.sys.sta){ switch(NaviKit.sys.sta){
case run:{//system is run now, user request to reboot SOM case run:{//system is run now, user request to reboot SOM
som_reboot(100); som_reboot(100);
@ -738,10 +694,10 @@ void CustBtnLongPressTimerCallback(void *argument)
} }
void PwrBtnShortPressTimerCallback(void *argument) void PwrBtnShortPressTimerCallback(void *argument)
{ {
Log(trace,sys,"power btn short pressed."); log_v("power btn short pressed.");
switch(NaviKit.sys.sta){ switch(NaviKit.sys.sta){
case run: {//som is running, send sleep requeset to operate system case run: {//som is running, send sleep requeset to operate system
Log(trace,som,"Request operate system pop up the shutdown dialog."); log_v("Request operate system pop up the shutdown dialog.");
PWR_Enable(SOM_SLEEP,true,100); PWR_Enable(SOM_SLEEP,true,100);
PWR_Enable(SOM_SLEEP,false,0); PWR_Enable(SOM_SLEEP,false,0);
}break; }break;
@ -754,7 +710,7 @@ void PwrBtnShortPressTimerCallback(void *argument)
} }
void CustBtnShortPressTimerCallback(void *argument) void CustBtnShortPressTimerCallback(void *argument)
{ {
Log(trace,sys,"custom btn short pressed."); log_v("custom btn short pressed.");
switch(NaviKit.sys.sta){ switch(NaviKit.sys.sta){
case run:{ case run:{
}break; }break;
@ -769,7 +725,7 @@ void CustBtnShortPressTimerCallback(void *argument)
} }
void IdleStateHoldTimerCallback(void *argument){ void IdleStateHoldTimerCallback(void *argument){
if(NaviKit.sys.sta == idle && NaviKit.sys.next_sta == idle){ if(NaviKit.sys.sta == idle && NaviKit.sys.next_sta == idle){
Log(trace,sys,"Idle state duration more than 5000ms."); log_v("Idle state duration more than 5000ms.");
NaviKit.sys.next_sta = standby; NaviKit.sys.next_sta = standby;
} }
} }

View File

@ -107,7 +107,6 @@ int main(void)
MX_NVIC_Init(); MX_NVIC_Init();
/* USER CODE BEGIN 2 */ /* USER CODE BEGIN 2 */
NaviKit_var_init();
/* USER CODE END 2 */ /* USER CODE END 2 */
/* Init scheduler */ /* Init scheduler */

View File

@ -65,7 +65,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
if(NaviKit.sys.sta == run){//if jetson nano shutdown output low,the power_en should be set low less than 10us if(NaviKit.sys.sta == run){//if jetson nano shutdown output low,the power_en should be set low less than 10us
PWR_Enable(SOM_PWR_EN,false,0); PWR_Enable(SOM_PWR_EN,false,0);
NaviKit.sys.next_sta = idle; NaviKit.sys.next_sta = idle;
Log(info,som,"SOM's shutdown_req pin falling edge, SOM request to shutdown."); log_i("SOM's shutdown_req pin falling edge, SOM request to shutdown.");
} }
}else{//Rising edge trigger }else{//Rising edge trigger
} }
@ -73,26 +73,26 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
case SOM_MOD_SLEEP_Pin:{ case SOM_MOD_SLEEP_Pin:{
if(HAL_GPIO_ReadPin(SOM_MOD_SLEEP_GPIO_Port, SOM_MOD_SLEEP_Pin)==GPIO_PIN_SET){//Rising edge trigger if(HAL_GPIO_ReadPin(SOM_MOD_SLEEP_GPIO_Port, SOM_MOD_SLEEP_Pin)==GPIO_PIN_SET){//Rising edge trigger
Log(info,som,"SOM's sleep pin rising edge."); log_i("SOM's sleep pin rising edge.");
}else{//falling edge trigger }else{//falling edge trigger
Log(trace,som,"SOM's sleep pin falling edge."); log_v("SOM's sleep pin falling edge.");
} }
}break; }break;
case SYS_POWER_BTN_Pin:{ case SYS_POWER_BTN_Pin:{
if(HAL_GPIO_ReadPin(SYS_POWER_BTN_GPIO_Port, SYS_POWER_BTN_Pin)==GPIO_PIN_SET){//Rising edge trigger if(HAL_GPIO_ReadPin(SYS_POWER_BTN_GPIO_Port, SYS_POWER_BTN_Pin)==GPIO_PIN_SET){//Rising edge trigger
NaviKit.sys.power_btn = true; NaviKit.sys.power_btn = true;
Log(debug,sys,"power_btn status: pressed."); log_v("power_btn status: pressed.");
}else{//falling edge trigger }else{//falling edge trigger
NaviKit.sys.power_btn = false; NaviKit.sys.power_btn = false;
Log(debug,sys,"power_btn status: released."); log_v("power_btn status: released.");
} }
}break; }break;
case SYS_CUSTOM_BTN_Pin:{ case SYS_CUSTOM_BTN_Pin:{
if(HAL_GPIO_ReadPin(SYS_CUSTOM_BTN_GPIO_Port, SYS_CUSTOM_BTN_Pin)==GPIO_PIN_RESET){//falling edge trigger if(HAL_GPIO_ReadPin(SYS_CUSTOM_BTN_GPIO_Port, SYS_CUSTOM_BTN_Pin)==GPIO_PIN_RESET){//falling edge trigger
Log(debug,sys,"custom_btn status: pressed."); log_v("custom_btn status: pressed.");
NaviKit.sys.custom_btn = true; NaviKit.sys.custom_btn = true;
}else{//Rising edge trigger }else{//Rising edge trigger
Log(debug,sys,"custom_btn status: released."); log_v("custom_btn status: released.");
NaviKit.sys.custom_btn = false; NaviKit.sys.custom_btn = false;
} }
}break; }break;
@ -102,7 +102,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
void enter_standby_state(){ void enter_standby_state(){
Log(info,sys,"Enter to STANDBY Mode to save power, see you!"); log_i("Enter to STANDBY Mode to save power, see you!");
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);//Enable PA0 wakeup function HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);//Enable PA0 wakeup function
__HAL_RCC_RTC_DISABLE(); __HAL_RCC_RTC_DISABLE();
HAL_PWR_EnterSTANDBYMode(); HAL_PWR_EnterSTANDBYMode();
@ -116,7 +116,7 @@ void enter_isp_state()
//timeout:the time of wait //timeout:the time of wait
void enter_idle_state(uint16_t delay) void enter_idle_state(uint16_t delay)
{ {
Log(info,sys,"Enter to idle state."); log_i("Enter to idle state.");
TaskBeep(50,1); TaskBeep(50,1);
PWR_Enable(SOM_SLEEP,true,delay); PWR_Enable(SOM_SLEEP,true,delay);
@ -154,7 +154,7 @@ void enter_idle_state(uint16_t delay)
void enter_run_state(uint16_t delay) void enter_run_state(uint16_t delay)
{ {
Log(info,sys,"Enter to run state"); log_i("Enter to run state");
TaskBeep(200,1); TaskBeep(200,1);
PWR_Enable(PMB_PS_ON ,true, delay); PWR_Enable(PMB_PS_ON ,true, delay);
@ -191,13 +191,13 @@ void enter_run_state(uint16_t delay)
} }
void enter_sleep_state(uint16_t delay) void enter_sleep_state(uint16_t delay)
{ {
Log(info,sys,"Enter to sleep state."); log_i("Enter to sleep state.");
TaskBeep(50,1); TaskBeep(50,1);
} }
void enter_dfu_state(uint16_t delay) void enter_dfu_state(uint16_t delay)
{ {
Log(info,sys,"Enter to DFU state."); log_i("Enter to DFU state.");
TaskBeep(500,3); TaskBeep(500,3);
PWR_Enable(PMB_PS_ON , true , delay); PWR_Enable(PMB_PS_ON , true , delay);
@ -214,7 +214,7 @@ void enter_dfu_state(uint16_t delay)
} }
//para, delayreset low level signal duration (ms) //para, delayreset low level signal duration (ms)
void som_reboot(uint16_t delay){ void som_reboot(uint16_t delay){
Log(info,som,"Jetson Nano rebooting..."); log_i("Jetson Nano rebooting...");
PWR_Enable(SOM_RESET,true,0); PWR_Enable(SOM_RESET,true,0);
TaskBeep(100,1); TaskBeep(100,1);
PWR_Enable(SOM_RESET,false,0); PWR_Enable(SOM_RESET,false,0);
@ -252,7 +252,7 @@ void PWR_Enable(enum Device_t device,bool en,uint16_t delay){
case SOM_RESET: {HAL_GPIO_WritePin(SOM_SYS_RESET_GPIO_Port, SOM_SYS_RESET_Pin, !en); }break; case SOM_RESET: {HAL_GPIO_WritePin(SOM_SYS_RESET_GPIO_Port, SOM_SYS_RESET_Pin, !en); }break;
case SOM_SLEEP: {HAL_GPIO_WritePin(SOM_SLEEP_WAKE_GPIO_Port, SOM_SLEEP_WAKE_Pin, !en); }break; case SOM_SLEEP: {HAL_GPIO_WritePin(SOM_SLEEP_WAKE_GPIO_Port, SOM_SLEEP_WAKE_Pin, !en); }break;
case PMB_PS_ON: {HAL_GPIO_WritePin(PMB_PS_ON_GPIO_Port, PMB_PS_ON_Pin, en); }break; case PMB_PS_ON: {HAL_GPIO_WritePin(PMB_PS_ON_GPIO_Port, PMB_PS_ON_Pin, en); }break;
default: {Log(error,sys,"PWR_Enable device parameter is invalid."); }break; default: {log_e("PWR_Enable device parameter is invalid."); }break;
} }
osDelay(delay); osDelay(delay);
} }
@ -288,7 +288,7 @@ bool PWR_Status(enum Device_t device){
case SOM_RESET: {sta = !HAL_GPIO_ReadPin(SOM_SYS_RESET_GPIO_Port,SOM_SYS_RESET_Pin); }break; case SOM_RESET: {sta = !HAL_GPIO_ReadPin(SOM_SYS_RESET_GPIO_Port,SOM_SYS_RESET_Pin); }break;
case SOM_SLEEP: {sta = !HAL_GPIO_ReadPin(SOM_SLEEP_WAKE_GPIO_Port,SOM_SLEEP_WAKE_Pin); }break; case SOM_SLEEP: {sta = !HAL_GPIO_ReadPin(SOM_SLEEP_WAKE_GPIO_Port,SOM_SLEEP_WAKE_Pin); }break;
case PMB_PS_ON: {sta = HAL_GPIO_ReadPin(PMB_PS_ON_GPIO_Port,PMB_PS_ON_Pin); }break; case PMB_PS_ON: {sta = HAL_GPIO_ReadPin(PMB_PS_ON_GPIO_Port,PMB_PS_ON_Pin); }break;
default: {Log(error,sys,"PWR_Status device parameter is invalid."); }break; default: {log_e("PWR_Status device parameter is invalid."); }break;
} }
return sta; return sta;
} }

View File

@ -91,7 +91,7 @@ void NMI_Handler(void)
void HardFault_Handler(void) void HardFault_Handler(void)
{ {
/* USER CODE BEGIN HardFault_IRQn 0 */ /* USER CODE BEGIN HardFault_IRQn 0 */
Log(fatal,sys,"HardFault_Handler"); log_e("HardFault_Handler");
/* USER CODE END HardFault_IRQn 0 */ /* USER CODE END HardFault_IRQn 0 */
while (1) while (1)
{ {
@ -106,7 +106,7 @@ void HardFault_Handler(void)
void MemManage_Handler(void) void MemManage_Handler(void)
{ {
/* USER CODE BEGIN MemoryManagement_IRQn 0 */ /* USER CODE BEGIN MemoryManagement_IRQn 0 */
Log(fatal,sys,"MemManage_Handler"); log_e("MemManage_Handler");
/* USER CODE END MemoryManagement_IRQn 0 */ /* USER CODE END MemoryManagement_IRQn 0 */
while (1) while (1)
{ {
@ -121,7 +121,7 @@ void MemManage_Handler(void)
void BusFault_Handler(void) void BusFault_Handler(void)
{ {
/* USER CODE BEGIN BusFault_IRQn 0 */ /* USER CODE BEGIN BusFault_IRQn 0 */
Log(fatal,sys,"BusFault_Handler"); log_e("BusFault_Handler");
/* USER CODE END BusFault_IRQn 0 */ /* USER CODE END BusFault_IRQn 0 */
while (1) while (1)
{ {
@ -136,7 +136,7 @@ void BusFault_Handler(void)
void UsageFault_Handler(void) void UsageFault_Handler(void)
{ {
/* USER CODE BEGIN UsageFault_IRQn 0 */ /* USER CODE BEGIN UsageFault_IRQn 0 */
Log(fatal,sys,"UsageFault_Handler"); log_e("UsageFault_Handler");
/* USER CODE END UsageFault_IRQn 0 */ /* USER CODE END UsageFault_IRQn 0 */
while (1) while (1)
{ {

@ -1 +1 @@
Subproject commit 12a12fe37d47d26f7c7f1d00dfea8a3dc04162f4 Subproject commit 056e521b20f62af5a009c4c154248199b4588941

View File

@ -1,61 +0,0 @@
/*
* @Description:
* @Date: 2020-12-22 18:27:24
* @LastEditors: CK.Zh
* @LastEditTime: 2021-01-07 17:54:00
* @FilePath: \NaviKit_stm32\Middlewares\Log\log.c
*/
/*
* log.c
*
* Created on: Dec 16, 2020
* Author: bookshiyi
*/
#include "log.h"
static bool mutex =false;
void Log(LogLevel_t level,LogPositon_t positon,char *format,...)
{
if(mutex){
unsigned char time_out = 100;
while(mutex && time_out--){//100ms timout for multi-thread use log function
osDelay(1);
}
}
if(!mutex){
mutex = true;
switch(level){
case trace: { printf("[Trace] ") ; }break;
case debug: { printf("[Debug] ") ; }break;
case info: { printf("[Info ] ") ; }break;
case warning:{ printf("[Warn ] ") ; }break;
case error: { printf("[Error] ") ; }break;
case fatal: { printf("[Fatal] ") ; }break;
default: { printf("[Undefined Level] ") ; }break;
}
printf("%10.3f | ",osKernelGetTickCount()/1000.0);
switch (positon)
{
case sys:{ printf("SYS: ") ; }break;
case som:{ printf("SOM: ") ; }break;
case pmb:{ printf("PMB: ") ; }break;
default: { printf("Undefined Position: ") ;}break;
}
// va_list args;
// va_start( args, format );
// print(0, format, args );
va_list ap;
va_start(ap, format);
vprintf(format, ap);
va_end(ap);
printf("\n") ;
mutex = false;
}
}

View File

@ -1,38 +0,0 @@
/*
* @Description:
* @Date: 2020-12-22 18:27:24
* @LastEditors: CK.Zh
* @LastEditTime: 2021-01-07 17:50:39
* @FilePath: \NaviKit_stm32\Middlewares\Log\log.h
*/
/*
* log.h
*
* Created on: Dec 16, 2020
* Author: bookshiyi
*/
#ifndef LOG_LOG_H_
#define LOG_LOG_H_
#include <stdarg.h>
#include <stdio.h>
#include <stdbool.h>
typedef enum {
trace = 0,
debug = 1,
info = 2,
warning = 3,
error = 4,
fatal =5
}LogLevel_t;
typedef enum {
sys = 0,//system:board device and ec device
som = 1,//system on module: jetson nano
pmb = 2,//power manage board
}LogPositon_t;
void Log(LogLevel_t level,LogPositon_t positon,char *format, ...);
#endif /* LOG_LOG_H_ */