📄 main.c
字号:
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f10x_xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f10x.c file
*/
if (SysTick_Config(SystemCoreClock / 1000))
{
/* Capture error */
// Do some thing
while (1);
}
/* System clocks configuration ---------------------------------------------*/
RCC_Configuration();
/* Interrupt configuration ---------------------------------------------*/
NVIC_Configuration();
/* GPIO configuration ------------------------------------------------------*/
GPIO_Configuration();
/* Free run TIM configuration ------------------------------------------------------*/
GLB_FreerunTIM_Initial();
memset((uint8_t *)0x20003000, 0x00, 0x200);
/* UART2 configuration ------------------------------------------------------*/
#ifdef DEBUG
COM_Debug_Configuration();
UART2_Debug_Print("Program started. \r\n");
#endif
/* Check if the system has resumed from IWDG reset */
if (RCC_GetFlagStatus(RCC_FLAG_IWDGRST) != RESET)
{
/* Clear reset flags */
RCC_ClearFlag();
LCD_BACKLIGHT_ON;
Occupy_Delay(100);
LCD_BACKLIGHT_OFF;
Occupy_Delay(100);
LCD_BACKLIGHT_ON;
Occupy_Delay(100);
LCD_BACKLIGHT_OFF;
Occupy_Delay(100);
LCD_BACKLIGHT_ON;
Occupy_Delay(100);
#ifdef DEBUG
UART2_Debug_Print("Watchdog reset. \r\n");
#endif
}
else
{
}
IWDG_Configuration();
/* HMI configuration ------------------------------------------------------*/
// HMI_Configuration();
/* Signalling configuration ------------------------------------------------------*/
// SIG_Configuration();
FLAG_HMI_PWRON_RESET = SET;
FLAG_SIG_START_TX = SET;
while (1)
{
IWDG_ReloadCounter();
HMI_Manager();
SIG_Manager();
FishDetected_Manager();
HMI_Depth_Curve_Redraw_Handler();
//COM_Manager();
}
}
void FishDetected_Manager(void)
{
static uint8_t staFishDetectedColorInvertCNT = 0;
static uint32_t staLastFishDetectedColorInvert = 0;
if (SET == FLAG_SIG_FISH_DETECTED)
{
FLAG_SIG_FISH_DETECTED = RESET;
//newBLBlink(FISH_DETECTED_BL_BLINK_ITV, FISH_DETECTED_BL_BLINK_NUM);
//staFishDetectedColorInvertCNT = FISH_DETECTED_COLOR_INVERT_NUM;
//staLastFishDetectedColorInvert = gSystem_1ms_CNT;
//setHMINegativeColor();
}
if (staFishDetectedColorInvertCNT > 0)
{
// Color invert 5 times at interval 400ms
if ((uint32_t)(gSystem_1ms_CNT - staLastFishDetectedColorInvert) > FISH_DETECTED_COLOR_INVERT_ITV)
{
staLastFishDetectedColorInvert = gSystem_1ms_CNT;
staFishDetectedColorInvertCNT--;
((staFishDetectedColorInvertCNT % 2) == 0) ? (*HMI_Set_Color_Type)((char *)const_HMI_NegativeColor_CMD) :
(*HMI_Set_Color_Type)((char *)const_HMI_PositiveColor_CMD);
}
}
}
void Occupy_Delay(uint32_t delayMs)
{
uint32_t entrTime = gSystem_1ms_CNT;
while ((uint32_t)(gSystem_1ms_CNT - entrTime) < delayMs)
{
}
}
//************************************************************//
//************* !! UART Transmission for debug!! **************//
//************************************************************//
#ifdef DEBUG
void COM_Debug_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
USART_Cmd(DEBUG_UART, DISABLE);
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No ;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(DEBUG_UART, &USART_InitStructure);
// Choose USART2's TX as DMA request
USART_DMACmd(DEBUG_UART, USART_DMAReq_Tx, ENABLE);
/* Enable USART3 and disable all it's Interrupt except RXNE */
// USART_ITConfig(DEBUG_UART, USART_IT_TXE, DISABLE);
// USART_ITConfig(DEBUG_UART, USART_IT_TC, DISABLE);
// USART_ITConfig(DEBUG_UART, USART_IT_RXNE, ENABLE);
USART_Cmd(DEBUG_UART, ENABLE);
DMA_DeInit(UART_DEBUG_DMA_CHN);
sta_UART2_DMA_InitStructure.DMA_PeripheralBaseAddr = UART_DEBUG_DR;
sta_UART2_DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)0x20004000; // 20KB RAM => 0x20005000 top address
sta_UART2_DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
sta_UART2_DMA_InitStructure.DMA_BufferSize = 0x10;
sta_UART2_DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
sta_UART2_DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
sta_UART2_DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
sta_UART2_DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
sta_UART2_DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
sta_UART2_DMA_InitStructure.DMA_Priority = DMA_Priority_High;
sta_UART2_DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(UART_DEBUG_DMA_CHN, &sta_UART2_DMA_InitStructure);
DMA_ITConfig(UART_DEBUG_DMA_CHN, DMA_IT_TC, ENABLE);
}
void UART2_Debug_Print(char *printString)
{
static char sta_COM_Print_Buffer[MAX_UART_DEBUG_LEN];
uint32_t temp_trans_CNT = 1000000;
uint16_t temp_StringLen;
while(((RESET == USART_GetFlagStatus (USART2, USART_FLAG_TXE)) ||
(RESET == USART_GetFlagStatus (USART2, USART_FLAG_TC)) ||
(SET == FLAG_UART_DEBUG_DMA_TRANSMITTING)) &&
(temp_trans_CNT != 0)) // Last transmission has not complete
{
temp_trans_CNT--;
}
FLAG_UART_DEBUG_DMA_TRANSMITTING = SET;
temp_StringLen = strlen(printString);
memcpy(sta_COM_Print_Buffer, printString, temp_StringLen + 1);
sta_UART2_DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)sta_COM_Print_Buffer;
sta_UART2_DMA_InitStructure.DMA_BufferSize = temp_StringLen;
DMA_Init(UART_DEBUG_DMA_CHN, &sta_UART2_DMA_InitStructure);
/* Enable SIMUART DMA TX Channel, start to transmit */
DMA_Cmd(UART_DEBUG_DMA_CHN, ENABLE);
}
#endif
void IWDG_Configuration(void)
{
/* Enable the LSI OSC */
RCC_LSICmd(ENABLE);
/* Wait till LSI is ready */
while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
{}
DBGMCU_Config(DBGMCU_IWDG_STOP, ENABLE);
/* IWDG timeout equal to 250 ms (the timeout may varies due to LSI frequency
dispersion) */
/* Enable write access to IWDG_PR and IWDG_RLR registers */
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
/* IWDG counter clock: LSI/32 */
IWDG_SetPrescaler(IWDG_Prescaler_32);
/* Set counter reload value to obtain 250ms IWDG TimeOut.
Counter Reload Value = 250ms/IWDG counter clock period
= 250ms / (1 / (LsiFreq/32))
= LsiFreq/(32 * 4)
= LsiFreq/128
*/
IWDG_SetReload(LSI_FREQUENCY / 128);
/* Reload IWDG counter */
IWDG_ReloadCounter();
/* Enable IWDG (the LSI oscillator will be enabled by hardware) */
IWDG_Enable();
}
/**
* @brief Configures the different system clocks.
* @param None
* @retval None
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -