Files
E3/main.c
2025-10-21 19:14:21 +08:00

143 lines
4.0 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <types.h>
#include "board.h"
#include "debug.h"
#include "regs_base.h"
#include "irq_num.h"
#include "clock_cfg.h"
#include "reset_cfg.h"
#include "pinmux_cfg.h"
#include "eth_cfg.h"
#include "lwip/err.h"
#include "lwip/inet.h"
#include "lwip/tcp.h"
#include "lwip/timeouts.h"
#include <string.h>
#include "lwip/udp.h"
#include "flexcan_cfg.h"
#include "interface_config.h"
#include "irq.h"
//app包含
#include "app/app_config.h"
#include "app/app_param_manage.h"
#include "app/app_power.h"
#include "app/app_brake.h"
#include "app/app_differential_drive.h"
#include <app/app_test.h>
#include <app/app_temp.h>
#include <app/app_light.h>
#include "app/app_request.h"
#include "app/app_ultrasonic.h"
#include "app/app_turntable.h"
void testAppInit(void);
#define IP_ADDR0 10
#define IP_ADDR1 18
#define IP_ADDR2 252
#define IP_ADDR3 34
extern int btm_init(void);
extern struct tcp_pcb *netdemo_connect_server(char *ip, int port);
extern bool netdemo_tcp_connected(void);
extern bool netdemo_tcp_send_done(void);
extern void netdemo_clear_tcp_send_done(void);
uint8_t mainCnt = 0;
uint8_t mainCntarr[8] = {0x56,0x88,0x98,0x79,0x23};
uint8_t test_app[26] = {0};
int main(void)
{
initFramework();
uint8_t BOOT_Arr[2] = {0x01,0x02};//上电发送app帧给上位机用
// 释放MCU各模块reset信号
board_reset_init();
// 配置时钟
int ret = sdrv_ckgen_init(&g_clock_config);
ASSERT(ret == 0);
// VIC初始化
irq_initialize(VIC1_BASE, IRQ_MAX_INTR_NUM);
// 配置pinmux
sdrv_pinctrl_init(NUM_OF_CONFIGURED_PINS, g_pin_init_config);
// Timer初始化用于提供LWIP sys_now接口获取当前时间
btm_init();
// 使能打印
board_debug_console_init();
printf("debug_console_init initial OK %d\n",getCurrentTime());
//初始化所有can
initialization_All_Flexcan();
printf("initialization_All_Flexcan initial OK %d\n",getCurrentTime());
// ETH初始化
board_eth_init();
initSpi();//初始化SPI
//以太网端口初始化
UDP_Echo_Init(UDPCB_1, udp_Callback_1, COMMUNICATION_PORT);
UDP_Echo_Init(UDPCB_2, udp_Callback_2, UPPER_PORT);
UDP_Echo_Init(UDPCB_3, udp_Callback_3, PARAM_PORT);
UDP_Echo_Init(UDPCB_4, udp_Callback_4, DOWNLOAR_PORT);
UDP_Echo_Init(UDPCB_5, udp_Callback_5, WDT_PORT);
printf("board_eth_init initial OK %d\n",getCurrentTime());
//读取重启标志
g_systemDataRecord.canBootloaderUpgrade = rdbyte_24c02(0x00);
printf("rdbyte_24c02 OK %d\n",getCurrentTime());
ethernet_parameter.download_ip[0] = rdbyte_24c02(BOOT_DES_IP);//读取下载的IP
ethernet_parameter.download_ip[1] = rdbyte_24c02(BOOT_DES_IP+1);//读取下载的IP
ethernet_parameter.download_ip[2] = rdbyte_24c02(BOOT_DES_IP+2);//读取下载的IP
ethernet_parameter.download_ip[3] = rdbyte_24c02(BOOT_DES_IP+3);//读取下载的IP
//发送重启后的第一帧给上位机
CAN_Send_Msg(&can_handle_6,OTA_CANTxID, FLEXCAN_STANDARD_FRAME, FLEXCAN_FrameTypeData, BOOT_Arr,2, TX_MB_INDEX);//app 帧
printf("CAN_Send_Msg can_handle_6 OK %d\n",getCurrentTime());
//打印版本号
printf("version: V1.75 \n");
// 初始化框架 放在最前面解决电机can发送信号累积不处理的问题。
testAppInit();
paramAppInit();
diffAppInit();
// brakeAppInit();
powerAppInit(); //电源管理
// tempAppInit(); //温度
lightAppInit(); //灯光
ethernetInterfaceInit(); //以太网先初始化
requestAppInit();
canInterfaceInit();
bootInterfaceInit();
// ultrasonicAppInit();
turnableInit();
printf("All init OK ------ %d\n",getCurrentTime());
for (;;)
{
// 处理信号
processMessages();
}
}