add coulomb task and driver files

master
ThinkPad 2020-04-27 18:19:02 +08:00
parent e5675efb6d
commit 24f2105fd6
4 changed files with 71 additions and 4 deletions

View File

@ -31,7 +31,7 @@
#include "usart.h" #include "usart.h"
#include "stdio.h" #include "stdio.h"
#include "navikit.h" #include "navikit.h"
#include "coulomb.h"
#include "stdbool.h" #include "stdbool.h"
/* USER CODE END Includes */ /* USER CODE END Includes */
@ -82,6 +82,13 @@ const osThreadAttr_t ButtonDetect_attributes = {
.priority = (osPriority_t) osPriorityLow, .priority = (osPriority_t) osPriorityLow,
.stack_size = 128 * 4 .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 -----------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */ /* USER CODE BEGIN FunctionPrototypes */
@ -91,6 +98,7 @@ void StartDefaultTask(void *argument);
void StartLedBlinkTask(void *argument); void StartLedBlinkTask(void *argument);
void StartIWDGRefreshTask(void *argument); void StartIWDGRefreshTask(void *argument);
void StartButtonDetect(void *argument); void StartButtonDetect(void *argument);
void StartCoulombRead(void *argument);
extern void MX_USB_DEVICE_Init(void); extern void MX_USB_DEVICE_Init(void);
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */ void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
@ -134,6 +142,9 @@ void MX_FREERTOS_Init(void) {
/* creation of ButtonDetect */ /* creation of ButtonDetect */
ButtonDetectHandle = osThreadNew(StartButtonDetect, NULL, &ButtonDetect_attributes); ButtonDetectHandle = osThreadNew(StartButtonDetect, NULL, &ButtonDetect_attributes);
/* creation of CoulombRead */
CoulombReadHandle = osThreadNew(StartCoulombRead, NULL, &CoulombRead_attributes);
/* USER CODE BEGIN RTOS_THREADS */ /* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */ /* add threads, ... */
@ -243,7 +254,7 @@ void StartButtonDetect(void *argument)
if(NaviKit.pwr_button_pushed == true) if(NaviKit.pwr_button_pushed == true)
{//仍被按下 {//仍被按下
if(NaviKit.system_runing == true) if(NaviKit.system_runing == true)
{//当前处于开机状态进行关机操作 {//当前处于开机状态,进行关机操作
NaviKit.system_runing = false; NaviKit.system_runing = false;
HAL_GPIO_WritePin(USB2_VBUS_CTL_1_GPIO_Port,USB2_VBUS_CTL_1_Pin, GPIO_PIN_RESET); 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 else
{//当前处于关机状态进行开机操作 {//当前处于关机状态,进行开机操作
NaviKit.system_runing = true; NaviKit.system_runing = true;
Beep(40); Beep(40);
HAL_GPIO_WritePin(BAT_RELAY_CTL_GPIO_Port ,BAT_RELAY_CTL_Pin, GPIO_PIN_SET); 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 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 --------------------------------------------------*/ /* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */ /* USER CODE BEGIN Application */

View File

@ -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);
}

View File

@ -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_ */

View File

@ -26,7 +26,7 @@ FREERTOS.FootprintOK=true
FREERTOS.INCLUDE_xTaskGetCurrentTaskHandle=1 FREERTOS.INCLUDE_xTaskGetCurrentTaskHandle=1
FREERTOS.INCLUDE_xTaskGetHandle=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.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.configGENERATE_RUN_TIME_STATS=0
FREERTOS.configMAX_TASK_NAME_LEN=32 FREERTOS.configMAX_TASK_NAME_LEN=32
FREERTOS.configUSE_APPLICATION_TASK_TAG=0 FREERTOS.configUSE_APPLICATION_TASK_TAG=0