📄 boot_main.c
字号:
#include "hal.h"
#include "uart.h"
#include "code_upgrade.h"
/* mcu power up or reboot
*/
void _mcu_init(void)
{
SCFI0=FN_4;
SCFQCTL|=SCFQ_4M;
// Init WDT
_clr_wdt();
FLL_CTL0|=XCAP14PF; // Configure load caps
BTCTL=BT_ADLY_125+BT_fLCD_DIV128;
// init port 1
P1SEL=P1SEL_VAL;
P1DIR=P1DIR_VAL;
P1OUT=P1OUT_VAL;
P1IES=P1IES_VAL;
// P1IFG=0;
// P1IE=P1IE_VAL;
// init port 2
P2SEL=P2SEL_VAL;
P2DIR=P2DIR_VAL;
P2OUT=P2OUT_VAL;
P2IES=P2IES_VAL;
//P2IFG=0;
// P2IE=P2IE_VAL;
// init port 6
P6DIR=P6DIR_VAL;
P6OUT=P6OUT_VAL;
//init uart
_uart_wait();
}
#define SET_NAK_FLAG(flg) (flg=0x4FFFF)// about 4 seconds
void boot_main(void)
{
_t_frm _frm_buf;
_t_pre_frm pre_frm;
unsigned short time_out;
unsigned long s_nak_flg=0;
_mcu_init();
if(code_sel())
{
pre_frm.resp=0;
_frm_buf.flash_ptr=0;
erase_all_user_code();
time_out=BOOT_CODE_STA;
flash_write_byte((unsigned char *)0xFFFF, (unsigned char)time_out);
time_out=0x0;
flash_write_byte((unsigned char *)0xFFFE, (unsigned char)time_out);
}
while(code_sel())
{
_clr_wdt();
if(IFG1&URXIFG0)
{
check_rx_buffer((unsigned char *)&_frm_buf.soh,(unsigned char *)&pre_frm.blk);
time_out=0xFFFF;
}
if(time_out)
{
time_out--;
SET_NAK_FLAG(s_nak_flg);
}
if(time_out==0)
{
_frm_buf.ptr=0;
}
if(s_nak_flg)
{
s_nak_flg--;
}
if(s_nak_flg==0)
{
_uart_start_to_tx(ASCII_NAK);
_uart_start_to_rx((unsigned char *)&_frm_buf.soh);
SET_NAK_FLAG(s_nak_flg);
}
}
}
void main(void) @ "USERCODE"
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -