From 24f2105fd6684949784879cf866e0d6fed69ac8e Mon Sep 17 00:00:00 2001 From: ThinkPad Date: Mon, 27 Apr 2020 18:19:02 +0800 Subject: [PATCH] add coulomb task and driver files --- Core/Src/freertos.c | 36 ++++++++++++++++++++++++++++++++--- Middlewares/Coulomb/coulomb.c | 21 ++++++++++++++++++++ Middlewares/Coulomb/coulomb.h | 16 ++++++++++++++++ NaviKit_stm32.ioc | 2 +- 4 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 Middlewares/Coulomb/coulomb.c create mode 100644 Middlewares/Coulomb/coulomb.h diff --git a/Core/Src/freertos.c b/Core/Src/freertos.c index 6844c54..2a7df6c 100644 --- a/Core/Src/freertos.c +++ b/Core/Src/freertos.c @@ -31,7 +31,7 @@ #include "usart.h" #include "stdio.h" #include "navikit.h" - +#include "coulomb.h" #include "stdbool.h" /* USER CODE END Includes */ @@ -82,6 +82,13 @@ const osThreadAttr_t ButtonDetect_attributes = { .priority = (osPriority_t) osPriorityLow, .stack_size = 128 * 4 }; +/* Definitions for CoulombRead */ +osThreadId_t CoulombReadHandle; +const osThreadAttr_t CoulombRead_attributes = { + .name = "CoulombRead", + .priority = (osPriority_t) osPriorityLow, + .stack_size = 128 * 4 +}; /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN FunctionPrototypes */ @@ -91,6 +98,7 @@ void StartDefaultTask(void *argument); void StartLedBlinkTask(void *argument); void StartIWDGRefreshTask(void *argument); void StartButtonDetect(void *argument); +void StartCoulombRead(void *argument); extern void MX_USB_DEVICE_Init(void); void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */ @@ -134,6 +142,9 @@ void MX_FREERTOS_Init(void) { /* creation of ButtonDetect */ ButtonDetectHandle = osThreadNew(StartButtonDetect, NULL, &ButtonDetect_attributes); + /* creation of CoulombRead */ + CoulombReadHandle = osThreadNew(StartCoulombRead, NULL, &CoulombRead_attributes); + /* USER CODE BEGIN RTOS_THREADS */ /* add threads, ... */ @@ -243,7 +254,7 @@ void StartButtonDetect(void *argument) if(NaviKit.pwr_button_pushed == true) {//仍被按下 if(NaviKit.system_runing == true) - {//当前处于开机状态,进行关机操作 + {//当前处于开机状态,进行关机操作 NaviKit.system_runing = false; HAL_GPIO_WritePin(USB2_VBUS_CTL_1_GPIO_Port,USB2_VBUS_CTL_1_Pin, GPIO_PIN_RESET); @@ -262,7 +273,7 @@ void StartButtonDetect(void *argument) } else - {//当前处于关机状态,进行开机操作 + {//当前处于关机状态,进行开机操作 NaviKit.system_runing = true; Beep(40); HAL_GPIO_WritePin(BAT_RELAY_CTL_GPIO_Port ,BAT_RELAY_CTL_Pin, GPIO_PIN_SET); @@ -296,6 +307,25 @@ void StartButtonDetect(void *argument) /* USER CODE END StartButtonDetect */ } +/* USER CODE BEGIN Header_StartCoulombRead */ +/** +* @brief Function implementing the CoulombRead thread. +* @param argument: Not used +* @retval None +*/ +/* USER CODE END Header_StartCoulombRead */ +void StartCoulombRead(void *argument) +{ + /* USER CODE BEGIN StartCoulombRead */ + /* Infinite loop */ + for(;;) + { + IIC + osDelay(10); + } + /* USER CODE END StartCoulombRead */ +} + /* Private application code --------------------------------------------------*/ /* USER CODE BEGIN Application */ diff --git a/Middlewares/Coulomb/coulomb.c b/Middlewares/Coulomb/coulomb.c new file mode 100644 index 0000000..661e626 --- /dev/null +++ b/Middlewares/Coulomb/coulomb.c @@ -0,0 +1,21 @@ +#include "coulomb.h" +#include "i2c.h" + +bool is_coulomb_ready() +{ + HAL_I2C_IsDeviceReady(hi2c1,COULOMB_ADDR); +} +coulomb_write_reg() +{ + HAL_I2C_IsDeviceReady(COULOMB_ADDR); +} +coulomb_read_reg() +{ + +} + + +bool coulomb_read_alcc() +{ + return HAL_GPIO_ReadPin(COULOMB_ALCC_GPIO_Port,COULOMB_ALCC_Pin); +} diff --git a/Middlewares/Coulomb/coulomb.h b/Middlewares/Coulomb/coulomb.h new file mode 100644 index 0000000..f9baea0 --- /dev/null +++ b/Middlewares/Coulomb/coulomb.h @@ -0,0 +1,16 @@ +/* + * coulomb.h + * + * Created on: Apr 27, 2020 + * Author: oarap + */ + +#ifndef _COULOMB_H_ +#define _COULOMB_H_ + +#define COULOMB_ADDR 0x64 //device address +#define COULOMB_WRITE_CMD 0x00 //coulomb write command +#define COULOMB_READ_CMD 0x01 //coulomb read command + + +#endif /* _COULOMB_H_ */ diff --git a/NaviKit_stm32.ioc b/NaviKit_stm32.ioc index 355461a..7aed152 100644 --- a/NaviKit_stm32.ioc +++ b/NaviKit_stm32.ioc @@ -26,7 +26,7 @@ FREERTOS.FootprintOK=true FREERTOS.INCLUDE_xTaskGetCurrentTaskHandle=1 FREERTOS.INCLUDE_xTaskGetHandle=1 FREERTOS.IPParameters=Tasks01,configMAX_TASK_NAME_LEN,configUSE_TICKLESS_IDLE,INCLUDE_xTaskGetCurrentTaskHandle,INCLUDE_xTaskGetHandle,configUSE_APPLICATION_TASK_TAG,FootprintOK,configUSE_IDLE_HOOK,configUSE_TICK_HOOK,configUSE_MALLOC_FAILED_HOOK,configGENERATE_RUN_TIME_STATS,configUSE_STATS_FORMATTING_FUNCTIONS,configUSE_TRACE_FACILITY -FREERTOS.Tasks01=defaultTask,24,128,StartDefaultTask,Default,NULL,Dynamic,NULL,NULL;LedBlinkTask,8,128,StartLedBlinkTask,Default,NULL,Dynamic,NULL,NULL;IWDGRefreshTask,40,128,StartIWDGRefreshTask,Default,NULL,Dynamic,NULL,NULL;ButtonDetect,8,128,StartButtonDetect,Default,NULL,Dynamic,NULL,NULL +FREERTOS.Tasks01=defaultTask,24,128,StartDefaultTask,Default,NULL,Dynamic,NULL,NULL;LedBlinkTask,8,128,StartLedBlinkTask,Default,NULL,Dynamic,NULL,NULL;IWDGRefreshTask,40,128,StartIWDGRefreshTask,Default,NULL,Dynamic,NULL,NULL;ButtonDetect,8,128,StartButtonDetect,Default,NULL,Dynamic,NULL,NULL;CoulombRead,8,128,StartCoulombRead,Default,NULL,Dynamic,NULL,NULL FREERTOS.configGENERATE_RUN_TIME_STATS=0 FREERTOS.configMAX_TASK_NAME_LEN=32 FREERTOS.configUSE_APPLICATION_TASK_TAG=0