2024-07-11 06:58:55 +00:00
|
|
|
|
/*
|
|
|
|
|
* task.c
|
|
|
|
|
*
|
|
|
|
|
* Created on: 2024<EFBFBD><EFBFBD>6<EFBFBD><EFBFBD>24<EFBFBD><EFBFBD>
|
|
|
|
|
* Author: psx
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "task.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "tim.h"
|
|
|
|
|
#include "pwm.h"
|
|
|
|
|
#include "adc.h"
|
|
|
|
|
#include "rs485.h"
|
|
|
|
|
#include "gpio.h"
|
|
|
|
|
#include "flash.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "sl_protocol.h"
|
|
|
|
|
#include "mppt_control.h"
|
|
|
|
|
#include "inflash.h"
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָʾ<EFBFBD><EFBFBD>
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
STR_TimeSliceOffset m_runled;
|
|
|
|
|
void Task_RunLED(void)
|
|
|
|
|
{
|
|
|
|
|
static uint8_t flag = RESET;
|
|
|
|
|
flag = !flag;
|
|
|
|
|
GPIO_WriteBit(RUN_LED_GPIO, RUN_LED_PIN, flag);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief mppt<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
STR_TimeSliceOffset m_mpptControl;
|
|
|
|
|
void Task_mpptControl(void)
|
|
|
|
|
{
|
|
|
|
|
// uart_dev_write(g_gw485_uart4_handle, "hello world \n", sizeof("hello world \n"));
|
|
|
|
|
test();
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
STR_TimeSliceOffset m_usart;
|
2024-07-12 02:00:47 +00:00
|
|
|
|
uint8_t RegistrationRequestFlag = 0;
|
2024-07-11 06:58:55 +00:00
|
|
|
|
void Task_usart(void)
|
|
|
|
|
{
|
|
|
|
|
// printf(" task3******** \n");
|
|
|
|
|
read_and_process_uart_data(g_gw485_uart4_handle);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD>Ź<EFBFBD>
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
STR_TimeSliceOffset m_wdi;
|
|
|
|
|
void Task_wdi(void)
|
|
|
|
|
{
|
|
|
|
|
static uint32_t temp = 0;
|
|
|
|
|
if (wdi_RESET == temp++) {
|
|
|
|
|
NVIC_SystemReset();
|
|
|
|
|
}
|
|
|
|
|
GPIO_WriteBit(WDI_INPUT_GPIO, WDI_INPUT_PIN, SET);
|
|
|
|
|
GPIO_WriteBit(WDI_INPUT_GPIO, WDI_INPUT_PIN, RESET);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD>㲥ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>ٴη<EFBFBD><EFBFBD>ͣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Σ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>3s
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
uint8_t recvbroadcast_flag = 0;
|
|
|
|
|
device_handle g_recvBroadcastDevice;
|
|
|
|
|
uint8_t g_recvBroadcastRegisterNumber;
|
|
|
|
|
STR_TimeSliceOffset m_recvbroadcast;
|
|
|
|
|
void Task_recvbroadcast(void)
|
|
|
|
|
{
|
|
|
|
|
m_recvbroadcast.count = recvbroadcast_reloadVal;
|
|
|
|
|
static uint8_t run_number = 0;
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Σ<EFBFBD><CEA3><EFBFBD><EFBFBD>ٷ<EFBFBD><D9B7><EFBFBD> */
|
|
|
|
|
if (run_number++ == 3 || run_number > 3) {
|
2024-07-12 02:00:47 +00:00
|
|
|
|
RegistrationRequestFlag = 0;
|
2024-07-11 06:58:55 +00:00
|
|
|
|
run_number = 0;
|
|
|
|
|
TimeSliceOffset_Unregister(&m_recvbroadcast);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// if (g_Mppt_Para.Registration_Status == REGISTER_SUCCESS) {
|
|
|
|
|
// TimeSliceOffset_Unregister(&m_recvbroadcast);
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
SL_Mppt_RegistrationRequest_pack recvpack = {0};
|
|
|
|
|
|
|
|
|
|
/* <20><>ʼ<EFBFBD><CABC>־ */
|
|
|
|
|
recvpack.start_Flag[0] = g_slConfigInfo.start_Flag[0];
|
|
|
|
|
recvpack.start_Flag[1] = g_slConfigInfo.start_Flag[1];
|
|
|
|
|
|
|
|
|
|
/* ID */
|
|
|
|
|
recvpack.address[0] = 0xFF;
|
|
|
|
|
recvpack.address[1] = 0xFF;
|
|
|
|
|
recvpack.address[2] = 0xFF;
|
|
|
|
|
recvpack.address[3] = 0xFF;
|
|
|
|
|
recvpack.address[4] = 0xFF;
|
|
|
|
|
recvpack.address[5] = 0xFF;
|
|
|
|
|
recvpack.address[6] = 0xFF;
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
recvpack.function_Code = SL_Function_Code_Registration_request;
|
|
|
|
|
|
|
|
|
|
/* <20>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
recvpack.register_Length_H = g_recvBroadcastRegisterNumber >> 8;
|
|
|
|
|
recvpack.register_Length_L = g_recvBroadcastRegisterNumber;
|
|
|
|
|
|
|
|
|
|
/* ע<><D7A2>״̬ */
|
|
|
|
|
recvpack.registration_Status_H = g_Mppt_Para.Registration_Status >> 8;
|
|
|
|
|
recvpack.registration_Status_L = g_Mppt_Para.Registration_Status;
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>ID */
|
|
|
|
|
recvpack.access_Node_ID[0] = g_slConfigInfo.address[0];
|
|
|
|
|
recvpack.access_Node_ID[1] = g_slConfigInfo.address[1];
|
|
|
|
|
recvpack.access_Node_ID[2] = g_slConfigInfo.address[2];
|
|
|
|
|
recvpack.access_Node_ID[3] = g_slConfigInfo.address[3];
|
|
|
|
|
recvpack.access_Node_ID[4] = g_slConfigInfo.address[4];
|
|
|
|
|
recvpack.access_Node_ID[5] = g_slConfigInfo.address[5];
|
|
|
|
|
recvpack.access_Node_ID[6] = g_slConfigInfo.address[6];
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
recvpack.access_Node_Type_H = g_Mppt_Para.Access_Node_Type >> 8;
|
|
|
|
|
recvpack.access_Node_Type_L = g_Mppt_Para.Access_Node_Type;
|
|
|
|
|
|
|
|
|
|
/* У<><D0A3>λ */
|
|
|
|
|
// uint8_t *rpack_buf = (uint8_t *)&recvpack;
|
|
|
|
|
uint16_t crc = CheckFunc((uint8_t *)&recvpack, SL_MPPT_REGISTRATIONREQUEST_PACK_SIZE - 3);
|
|
|
|
|
|
|
|
|
|
recvpack.check_Bit_H = crc >> 8;
|
|
|
|
|
recvpack.check_Bit_L = crc;
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ */
|
|
|
|
|
recvpack.end_Flag = g_slConfigInfo.end_Flag;
|
|
|
|
|
/* У<><D0A3>λ */
|
|
|
|
|
for (uint8_t var = 0; var < 10; ++var) {
|
|
|
|
|
Delay_Ms(randomDelay());
|
|
|
|
|
if (!Check_485_bus_busy(g_recvBroadcastDevice)) {
|
|
|
|
|
if (recvbroadcast_flag == 1) {
|
|
|
|
|
recvbroadcast_flag = 0;
|
|
|
|
|
run_number = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
uart_dev_write(g_recvBroadcastDevice, (uint8_t *)&recvpack, SL_MPPT_REGISTRATIONREQUEST_PACK_SIZE + 1);
|
|
|
|
|
|
|
|
|
|
if (g_recvBroadcastDevice == g_bat485_uart3_handle) {
|
|
|
|
|
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
|
|
|
|
|
} else {
|
|
|
|
|
USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void g_Mppt_Para_Init(void)
|
|
|
|
|
{
|
|
|
|
|
g_Mppt_Para.Registration_Status = UNREGISTER;
|
|
|
|
|
g_Mppt_Para.address[0] = g_slConfigInfo.address[0];
|
|
|
|
|
g_Mppt_Para.address[1] = g_slConfigInfo.address[1];
|
|
|
|
|
g_Mppt_Para.address[2] = g_slConfigInfo.address[2];
|
|
|
|
|
g_Mppt_Para.address[3] = g_slConfigInfo.address[3];
|
|
|
|
|
g_Mppt_Para.address[4] = g_slConfigInfo.address[4];
|
|
|
|
|
g_Mppt_Para.address[5] = g_slConfigInfo.address[5];
|
|
|
|
|
g_Mppt_Para.address[6] = g_slConfigInfo.address[6];
|
|
|
|
|
g_Mppt_Para.Access_Node_Type = g_slConfigInfo.Access_Node_Type;
|
|
|
|
|
g_Mppt_Para.Communication_Methods = g_slConfigInfo.Communication_Methods;
|
|
|
|
|
g_Mppt_Para.Battery_Voltage = 0;
|
|
|
|
|
g_Mppt_Para.Battery_temperature = 0;
|
|
|
|
|
g_Mppt_Para.Remaining_Battery_Bower = 0;
|
|
|
|
|
g_Mppt_Para.Solar_Open_Circuit_Voltage1 = 0;
|
|
|
|
|
g_Mppt_Para.Solar_Open_Circuit_Voltage2 = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void task_Init(void)
|
|
|
|
|
{
|
|
|
|
|
read_config_info();
|
|
|
|
|
g_Mppt_Para_Init();
|
|
|
|
|
|
|
|
|
|
TimeSliceOffset_Register(&m_runled, Task_RunLED, runled_reloadVal, runled_offset);
|
|
|
|
|
TimeSliceOffset_Register(&m_mpptControl, Task_mpptControl, mpptControl_reloadVal, mpptControl_offset);
|
|
|
|
|
TimeSliceOffset_Register(&m_usart, Task_usart, usart_reloadVal, usart_offset);
|
|
|
|
|
TimeSliceOffset_Register(&m_wdi, Task_wdi, wdi_reloadVal, wdi_offset);
|
|
|
|
|
|
|
|
|
|
TimeSliceOffset_Start(); /* <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>Ƭ<EFBFBD><C6AC>ѯ */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼĴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>еı<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void hardware_Init(void)
|
|
|
|
|
{
|
|
|
|
|
TIM3_Init();
|
|
|
|
|
uart_dev_init();
|
|
|
|
|
PWM_TIM_Configuration();
|
|
|
|
|
ADC_all_Init();
|
|
|
|
|
RUN_LED_Init();
|
|
|
|
|
G_FFMOS_CON_Init();
|
|
|
|
|
WDI_INPUT_Init();
|
2024-07-13 02:12:30 +00:00
|
|
|
|
BEEP_Init();
|
|
|
|
|
POW_OUT_CON_Init();
|
|
|
|
|
DSG_PROT_Init();
|
2024-07-11 06:58:55 +00:00
|
|
|
|
SPI_Flash_Init();
|
|
|
|
|
|
|
|
|
|
Set_duty_ratio(0.5);
|
|
|
|
|
}
|
|
|
|
|
|