新增:首次提交
首次提交,上传Launcher工程
This commit is contained in:
1149
MCU_Driver/bootload_fun.c
Normal file
1149
MCU_Driver/bootload_fun.c
Normal file
File diff suppressed because it is too large
Load Diff
368
MCU_Driver/debug.c
Normal file
368
MCU_Driver/debug.c
Normal file
@@ -0,0 +1,368 @@
|
||||
/*
|
||||
* debug.c
|
||||
*
|
||||
* Created on: May 14, 2025
|
||||
* Author: cc
|
||||
*/
|
||||
#include "debug.h"
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
volatile uint32_t SysTick_100us = 0;
|
||||
volatile uint32_t SysTick_1ms = 0;
|
||||
volatile uint32_t SysTick_1s = 0;
|
||||
|
||||
void Systick_Init(void)
|
||||
{
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ȼ<EFBFBD>*/
|
||||
NVIC_SetPriority(SysTick_IRQn, 0x00);
|
||||
NVIC_EnableIRQ(SysTick_IRQn);
|
||||
|
||||
/*<2A><><EFBFBD>ö<EFBFBD>ʱ<EFBFBD><CAB1>*/
|
||||
SysTick->CTLR= 0;
|
||||
SysTick->SR = 0;
|
||||
SysTick->CNT = 0;
|
||||
SysTick->CMP = SystemCoreClock/10000; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1000<30><30><EFBFBD><EFBFBD>1000HZ(<28>Ǿ<EFBFBD><C7BE><EFBFBD>1ms<6D><73>һ<EFBFBD><D2BB><EFBFBD>ж<EFBFBD>)
|
||||
SysTick->CTLR= 0xf;
|
||||
}
|
||||
|
||||
void SysTick_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
static uint8_t NUM = 0;
|
||||
static uint16_t NUM_S = 0;
|
||||
|
||||
SysTick->SR = 0; //<2F><><EFBFBD><EFBFBD><EFBFBD>жϱ<D0B6>־
|
||||
|
||||
SysTick_100us++;
|
||||
NUM++;
|
||||
|
||||
if(NUM >= 10){
|
||||
NUM = 0;
|
||||
SysTick_1ms++;
|
||||
NUM_S++;
|
||||
|
||||
if(NUM_S >= 1000)
|
||||
{
|
||||
NUM_S = 0;
|
||||
SysTick_1s++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Delay_Us
|
||||
*
|
||||
* @brief Microsecond Delay Time.
|
||||
*
|
||||
* @param n - Microsecond number.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void Delay_Us(uint32_t n)
|
||||
{
|
||||
for(uint32_t i=0;i<n;i++){
|
||||
for(uint32_t j=0;j<30;j++){
|
||||
__NOP();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Delay_Ms
|
||||
*
|
||||
* @brief Millisecond Delay Time.
|
||||
*
|
||||
* @param n - Millisecond number.
|
||||
*
|
||||
* @return None
|
||||
*/
|
||||
void Delay_Ms(uint32_t n)
|
||||
{
|
||||
for(uint32_t i=0;i<n;i++){
|
||||
Delay_Us(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* @fn _write
|
||||
*
|
||||
* @brief Support Printf Function
|
||||
*
|
||||
* @param *buf - UART send Data.
|
||||
* size - Data length.
|
||||
*
|
||||
* @return size - Data length
|
||||
*/
|
||||
__attribute__((used)) int _write(int fd, char *buf, int size)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
#if (DEBUG) == DEBUG_UART0
|
||||
while ((R8_UART0_LSR & RB_LSR_TX_FIFO_EMP) == 0);
|
||||
R8_UART0_THR = *(buf++);
|
||||
#elif (DEBUG) == DEBUG_UART1
|
||||
while ((R8_UART1_LSR & RB_LSR_TX_FIFO_EMP) == 0);
|
||||
R8_UART1_THR = *(buf++);
|
||||
#elif (DEBUG) == DEBUG_UART2
|
||||
while ((R8_UART2_LSR & RB_LSR_TX_FIFO_EMP) == 0);
|
||||
R8_UART2_THR = *(buf++);
|
||||
#elif (DEBUG) == DEBUG_UART3
|
||||
while ((R8_UART3_LSR & RB_LSR_TX_FIFO_EMP) == 0);
|
||||
R8_UART3_THR = *(buf++);
|
||||
#endif
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn _sbrk
|
||||
*
|
||||
* @brief Change the spatial position of data segment.
|
||||
*
|
||||
* @return size: Data length
|
||||
*/
|
||||
void *_sbrk(ptrdiff_t incr)
|
||||
{
|
||||
extern char _end[];
|
||||
extern char _heap_end[];
|
||||
static char *curbrk = _end;
|
||||
|
||||
if ((curbrk + incr < _end) || (curbrk + incr > _heap_end))
|
||||
return NULL - 1;
|
||||
|
||||
curbrk += incr;
|
||||
return curbrk - incr;
|
||||
}
|
||||
|
||||
|
||||
uint32_t SysTick_Now = 0, SysTick_Last = 0, SysTick_Diff = 0;
|
||||
char Dbg_Buffer[100];
|
||||
|
||||
uint32_t Dbg_Switch = (DBG_OPT_ActCond_STATUS << DBG_BIT_ActCond_STATUS_bit) + \
|
||||
(DBG_OPT_MQTT_STATUS << DBG_BIT_MQTT_STATUS_bit) + \
|
||||
(DBG_OPT_Debug_STATUS << DBG_BIT_Debug_STATUS_bit) + \
|
||||
(DBG_OPT_LOGIC_STATUS << DBG_BIT_LOGIC_STATUS_bit) + \
|
||||
(DBG_OPT_DEVICE_STATUS << DBG_BIT_DEVICE_STATUS_bit) + \
|
||||
(DBG_OPT_NET_STATUS << DBG_BIT_NET_STATUS_bit) + \
|
||||
(DBG_OPT_SYS_STATUS << DBG_BIT_SYS_STATUS_bit);
|
||||
|
||||
//<2F>÷<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD>ٴ<EFBFBD><D9B4><EFBFBD><EFBFBD>ռ䣬<D5BC><E4A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void __putchar__ (char ch)
|
||||
{
|
||||
#if 1
|
||||
|
||||
#if (DEBUG) == DEBUG_UART0
|
||||
while ((R8_UART0_LSR & RB_LSR_TX_FIFO_EMP) == 0);
|
||||
R8_UART0_THR = ch;
|
||||
#elif (DEBUG) == DEBUG_UART1
|
||||
while ((R8_UART1_LSR & RB_LSR_TX_FIFO_EMP) == 0);
|
||||
R8_UART1_THR = ch;
|
||||
#elif (DEBUG) == DEBUG_UART2
|
||||
while ((R8_UART2_LSR & RB_LSR_TX_FIFO_EMP) == 0);
|
||||
R8_UART2_THR = ch;
|
||||
#elif (DEBUG) == DEBUG_UART3
|
||||
while ((R8_UART3_LSR & RB_LSR_TX_FIFO_EMP) == 0);
|
||||
R8_UART3_THR = ch;
|
||||
#endif
|
||||
|
||||
#else
|
||||
//select debug serial Pane
|
||||
volatile unsigned int *pdata = (unsigned int *)LDCC_DATA_P;
|
||||
while (*pdata & LDCC_BIT_STATUS); //Waiting for data read.
|
||||
*pdata = ch;
|
||||
#endif
|
||||
}
|
||||
|
||||
int *myitoa(int value, int* string, int radix)
|
||||
{
|
||||
int tmp[33];
|
||||
int* tp = tmp;
|
||||
int i;
|
||||
unsigned v;
|
||||
int sign;
|
||||
int* sp;
|
||||
|
||||
if (radix > 36 || radix <= 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
sign = (radix == 10 && value < 0);
|
||||
if (sign)
|
||||
v = -value;
|
||||
else
|
||||
v = (unsigned)value;
|
||||
while (v || tp == tmp)
|
||||
{
|
||||
i = v % radix;
|
||||
v = v / radix;
|
||||
if (i < 10) {
|
||||
*tp++ = i+'0';
|
||||
|
||||
} else {
|
||||
*tp++ = i + 'a' - 10;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sp = string;
|
||||
|
||||
if (sign)
|
||||
*sp++ = '-';
|
||||
while (tp > tmp)
|
||||
*sp++ = *--tp;
|
||||
*sp = 0;
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
void my_printf(const char *fmt, ...)
|
||||
{
|
||||
const int *s;
|
||||
int d;
|
||||
|
||||
char ch, *pbuf;
|
||||
int buf[16];
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
while (*fmt) {
|
||||
if (*fmt != '%') {
|
||||
__putchar__(*fmt++);
|
||||
continue;
|
||||
}
|
||||
switch (*++fmt) {
|
||||
case 's':
|
||||
s = va_arg(ap, const int *);
|
||||
for ( ; *s; s++) {
|
||||
__putchar__(*s);
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
d = va_arg(ap, int);
|
||||
myitoa(d, buf, 10);
|
||||
for (s = buf; *s; s++) {
|
||||
__putchar__(*s);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
case 'X':
|
||||
d = va_arg(ap, int);
|
||||
myitoa(d, buf, 16);
|
||||
for (s = buf; *s; s++) {
|
||||
__putchar__(*s);
|
||||
}
|
||||
break;
|
||||
// Add other specifiers here...
|
||||
case 'c':
|
||||
case 'C':
|
||||
ch = (unsigned char)va_arg(ap, int);
|
||||
pbuf = &ch;
|
||||
__putchar__(*pbuf);
|
||||
break;
|
||||
default:
|
||||
__putchar__(*fmt);
|
||||
break;
|
||||
}
|
||||
fmt++;
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void Dbg_Println(int DbgOptBit ,const char *fmt, ...)
|
||||
{
|
||||
|
||||
char ch;
|
||||
|
||||
va_list ap;
|
||||
|
||||
if ( (DBG_LOG_EN & DBG_BIT_SYS_STATUS) != 0x00 )
|
||||
{
|
||||
SysTick_Now = SysTick_1ms;
|
||||
SysTick_Diff = SysTick_Now - SysTick_Last; //<2F><>һ<EFBFBD>δ<EFBFBD>ӡʱ<D3A1><CAB1><EFBFBD><EFBFBD>
|
||||
SysTick_Last = SysTick_Now;
|
||||
|
||||
printf("%8d [%6d]: ",SysTick_Now,SysTick_Diff);
|
||||
|
||||
va_start(ap, fmt);
|
||||
while (*fmt) {
|
||||
if (*fmt != '%') {
|
||||
__putchar__(*fmt++);
|
||||
continue;
|
||||
}
|
||||
switch (*++fmt) {
|
||||
case 's':
|
||||
{
|
||||
char *str = va_arg(ap, char *);
|
||||
printf("%s",str);
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
{
|
||||
int num = va_arg(ap, int);
|
||||
printf("%d", num);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
case 'X':
|
||||
{
|
||||
int num = va_arg(ap, unsigned int);
|
||||
printf("%x", num);
|
||||
}
|
||||
break;
|
||||
// Add other specifiers here...
|
||||
case 'c':
|
||||
case 'C':
|
||||
ch = (unsigned char)va_arg(ap, int);
|
||||
printf("%c", ch);
|
||||
break;
|
||||
default:
|
||||
__putchar__(*fmt);
|
||||
break;
|
||||
}
|
||||
fmt++;
|
||||
}
|
||||
va_end(ap);
|
||||
printf("\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Dbg_Print_Buff
|
||||
* Description : DEBUG<55><47><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD> - <20><><EFBFBD><EFBFBD>Buff<66>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* Input :
|
||||
* Return :
|
||||
*******************************************************************************/
|
||||
void Dbg_Print_Buff(int DbgOptBit ,const char *cmd ,uint8_t *buff,uint32_t len)
|
||||
{
|
||||
#if DBG_LOG_EN
|
||||
if ( (Dbg_Switch & DbgOptBit ) != 0x00 )
|
||||
{
|
||||
SysTick_Now = SysTick_1ms;
|
||||
SysTick_Diff = SysTick_Now - SysTick_Last; //<2F><>һ<EFBFBD>δ<EFBFBD>ӡʱ<D3A1><CAB1><EFBFBD><EFBFBD>
|
||||
SysTick_Last = SysTick_Now;
|
||||
|
||||
printf("%8d [%6d]: %s",SysTick_Now,SysTick_Diff,cmd);
|
||||
for(uint32_t i=0;i<len;i++)
|
||||
{
|
||||
printf("%02X ",buff[i]);
|
||||
}
|
||||
printf("\n\r");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
84
MCU_Driver/inc/bootload_fun.h
Normal file
84
MCU_Driver/inc/bootload_fun.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* launcher_fun.h
|
||||
*
|
||||
* Created on: Jul 28, 2025
|
||||
* Author: cc
|
||||
*/
|
||||
|
||||
#ifndef _BOOTLOAD_FUN_H_
|
||||
#define _BOOTLOAD_FUN_H_
|
||||
|
||||
#include "ch564.h"
|
||||
#include "uart.h"
|
||||
#include "mcu_flash.h"
|
||||
|
||||
|
||||
|
||||
#define BCOMM_CMD_Handshake 0xC0
|
||||
#define BCOMM_CMD_Jump 0xC1
|
||||
#define BCOMM_CMD_SetInfo 0xC2
|
||||
#define BCOMM_CMD_WriteFlash 0xC3
|
||||
#define BCOMM_CMD_ReadFlash 0xC4
|
||||
#define BCOMM_CMD_EraseFlash 0xC5
|
||||
#define BCOMM_CMD_WriteEEPROM 0xC6
|
||||
#define BCOMM_CMD_ReadEEPROM 0xC7
|
||||
#define BCOMM_CMD_EraseEEPROM 0xC8
|
||||
#define BCOMM_CMD_CheckData 0xC9
|
||||
|
||||
#define BCOMM_CMD_ReplySUCC 0x00
|
||||
#define BCOMM_CMD_ReplyFAIL 0x01
|
||||
|
||||
#define BCOMM_ParaSize 4096
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BCOMM_FMT_TXAddr,
|
||||
BCOMM_FMT_SN,
|
||||
BCOMM_FMT_TYPE,
|
||||
BCOMM_FMT_RXAddr,
|
||||
BCOMM_FMT_LEN_L,
|
||||
BCOMM_FMT_LEN_H,
|
||||
BCOMM_FMT_CKS,
|
||||
BCOMM_FMT_CMD,
|
||||
BCOMM_FMT_PARAM,
|
||||
}BOOTLOAD_COMM_FMT_e;
|
||||
|
||||
#define UPDATE_RECORD_INFO_Size 0x28
|
||||
|
||||
typedef struct {
|
||||
|
||||
uint32_t spiflash_fw_count; //<2F>ⲿflash <20>̼<EFBFBD>д<EFBFBD><D0B4><EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD>
|
||||
uint32_t spiflash_fw_succ; //<2F>ⲿflash <20>̼<EFBFBD>д<EFBFBD><D0B4><EFBFBD>ɹ<EFBFBD><C9B9>ܴ<EFBFBD><DCB4><EFBFBD>
|
||||
uint32_t spiflash_fw_fail; //<2F>ⲿflash <20>̼<EFBFBD>д<EFBFBD><D0B4>ʧ<EFBFBD><CAA7><EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD>
|
||||
|
||||
uint32_t spiflash_logic_count; //<2F>ⲿflash <20><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD>
|
||||
uint32_t spiflash_logic_succ; //<2F>ⲿflash <20><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>ɹ<EFBFBD><C9B9>ܴ<EFBFBD><DCB4><EFBFBD>
|
||||
uint32_t spiflash_logic_fail; //<2F>ⲿflash <20><><EFBFBD><EFBFBD>д<EFBFBD><D0B4>ʧ<EFBFBD><CAA7><EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD>
|
||||
|
||||
uint32_t mcuflash_fw_count; //MCU flash <20>̼<EFBFBD>д<EFBFBD><D0B4><EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD>
|
||||
uint32_t mcuflash_fw_succ; //MCU flash <20>̼<EFBFBD>д<EFBFBD><D0B4><EFBFBD>ɹ<EFBFBD><C9B9>ܴ<EFBFBD><DCB4><EFBFBD>
|
||||
uint32_t mcuflash_fw_fail; //MCU flash <20>̼<EFBFBD>д<EFBFBD><D0B4>ʧ<EFBFBD><CAA7><EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD>
|
||||
uint32_t mcuflash_fw_failcount; //MCU flash <20>̼<EFBFBD><CCBC><EFBFBD>ǰд<C7B0><D0B4>ʧ<EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD>θ<EFBFBD><CEB8>¹̼<C2B9><CCBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD><C3BC><EFBFBD>
|
||||
|
||||
}UPDATE_RECORD_T;
|
||||
|
||||
extern G_SYS_FEATURE_T g_app_feature;
|
||||
extern G_SYS_FEATURE_T g_mcu_app_feature;
|
||||
extern UPDATE_RECORD_T g_update_recode; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
|
||||
extern uint8_t g_jump_flag; //<2F><>ת<EFBFBD><D7AA>־λ
|
||||
extern uint32_t g_Boot_Tick; //Bootʱ<74><CAB1><EFBFBD><EFBFBD> <20><>λ<EFBFBD><CEBB>ms
|
||||
extern uint32_t g_Boot_Time; //Bootʱ<74><CAB1> <20><>λ<EFBFBD><CEBB>ms
|
||||
|
||||
uint16_t CRC16_Check(uint8_t * aStr, uint16_t len);
|
||||
uint8_t Launcher_Uart_Upgrade_Process(UART_t *g_rev);
|
||||
|
||||
uint8_t Read_APP_Feature(void);
|
||||
uint8_t MCU_APP_Write(void);
|
||||
uint8_t SPIFLASH_Read_Update_Recode(UPDATE_RECORD_T *info);
|
||||
uint8_t SPIFLASH_Write_Update_Recode(UPDATE_RECORD_T *info);
|
||||
|
||||
void Jump_APP(uint32_t addr);
|
||||
|
||||
#endif /* MCU_DRIVER_INC_LAUNCHER_FUN_H_ */
|
||||
107
MCU_Driver/inc/debug.h
Normal file
107
MCU_Driver/inc/debug.h
Normal file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* debug.h
|
||||
*
|
||||
* Created on: May 14, 2025
|
||||
* Author: cc
|
||||
*/
|
||||
|
||||
#ifndef MCU_DRIVER_DEBUG_H_
|
||||
#define MCU_DRIVER_DEBUG_H_
|
||||
|
||||
#include "ch564.h"
|
||||
#include <stdio.h>
|
||||
|
||||
/* UART Printf Definition */
|
||||
#define DEBUG_UART0 1
|
||||
#define DEBUG_UART1 2
|
||||
#define DEBUG_UART2 3
|
||||
#define DEBUG_UART3 4
|
||||
|
||||
/* DEBUG log function. DEBUG printf() <20><><EFBFBD>ض<EFBFBD><D8B6><EFBFBD>*/
|
||||
#ifndef DBG_LOG_EN
|
||||
#define DBG_LOG_EN 1 //DEBUG LOG <20><><EFBFBD><EFBFBD><EFBFBD>ܿ<EFBFBD><DCBF><EFBFBD>
|
||||
#endif
|
||||
|
||||
#define DBG_Particular_EN 1 //<2F><>ϸ<EFBFBD><CFB8>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD> -- <20><><EFBFBD>嵽<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD>
|
||||
#define DBG_NET_LOG_EN 1 //<2F><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>ʼ״̬*/
|
||||
#define DBG_OPT_ActCond_STATUS 1 //<2F><><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>
|
||||
#define DBG_OPT_MQTT_STATUS 1 //MQTT<54><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>
|
||||
#define DBG_OPT_Debug_STATUS 1 //<2F><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>
|
||||
#define DBG_OPT_LOGIC_STATUS 1 //<2F><EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>
|
||||
#define DBG_OPT_DEVICE_STATUS 1 //<2F>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>
|
||||
#define DBG_OPT_NET_STATUS 1 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>
|
||||
#define DBG_OPT_SYS_STATUS 1 //ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD>
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ*/
|
||||
#define DBG_BIT_ActCond_STATUS_bit 6
|
||||
#define DBG_BIT_MQTT_STATUS_bit 5
|
||||
#define DBG_BIT_Debug_STATUS_bit 4
|
||||
#define DBG_BIT_LOGIC_STATUS_bit 3
|
||||
#define DBG_BIT_DEVICE_STATUS_bit 2
|
||||
#define DBG_BIT_NET_STATUS_bit 1
|
||||
#define DBG_BIT_SYS_STATUS_bit 0
|
||||
|
||||
#define DBG_BIT_ActCond_STATUS 0x00000040
|
||||
#define DBG_BIT_MQTT_STATUS 0x00000020
|
||||
#define DBG_BIT_Debug_STATUS 0x00000010
|
||||
#define DBG_BIT_LOGIC_STATUS 0x00000008
|
||||
#define DBG_BIT_DEVICE_STATUS 0x00000004
|
||||
#define DBG_BIT_NET_STATUS 0x00000002
|
||||
#define DBG_BIT_SYS_STATUS 0x00000001
|
||||
|
||||
extern uint32_t Dbg_Switch;
|
||||
extern uint32_t SysTick_Now, SysTick_Last, SysTick_Diff;
|
||||
|
||||
void Dbg_Println(int DbgOptBit ,const char *fmt, ...);
|
||||
|
||||
#if DBG_LOG_EN
|
||||
|
||||
#define DBG_Printf(...) printf(__VA_ARGS__)
|
||||
|
||||
#define DBG_SYS_Printf(...) Dbg_Println(DBG_BIT_SYS_STATUS,__VA_ARGS__)
|
||||
|
||||
//#define DBG_SYS_Printf(...) { \
|
||||
// if(Dbg_Switch & DBG_BIT_SYS_STATUS){ \
|
||||
// SysTick_Now = SysTick_1ms; \
|
||||
// SysTick_Diff = SysTick_Now - SysTick_Last; \
|
||||
// SysTick_Last = SysTick_Now; \
|
||||
// printf("%8d [%6d]:",SysTick_Now,SysTick_Diff); \
|
||||
// printf(__VA_ARGS__);printf("\r\n");}}
|
||||
|
||||
#define DBG_Debug_Printf(...) { \
|
||||
if(Dbg_Switch & DBG_BIT_Debug_STATUS){ \
|
||||
SysTick_Now = SysTick_1ms; \
|
||||
SysTick_Diff = SysTick_Now - SysTick_Last; \
|
||||
SysTick_Last = SysTick_Now; \
|
||||
printf("%8d [%6d]:",SysTick_Now,SysTick_Diff); \
|
||||
printf(__VA_ARGS__);printf("\r\n");}}
|
||||
|
||||
#define DBG_log(...) {DBG_Printf("%s %s-%d :",__FILE__,__func__,__LINE__);DBG_Printf(__VA_ARGS__);}
|
||||
|
||||
#else
|
||||
|
||||
#define DBG_Printf(...)
|
||||
#define DBG_SYS_Printf(...)
|
||||
#define DBG_Debug_Printf(...)
|
||||
|
||||
#define DBG_log(...)
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
extern volatile uint32_t SysTick_100us;
|
||||
extern volatile uint32_t SysTick_1ms;
|
||||
extern volatile uint32_t SysTick_1s;
|
||||
|
||||
void Systick_Init(void);
|
||||
void Delay_Us(uint32_t n);
|
||||
void Delay_Ms(uint32_t n);
|
||||
|
||||
void my_printf(const char *fmt, ...);
|
||||
void Dbg_Print_Buff(int DbgOptBit ,const char *cmd ,uint8_t *buff,uint32_t len);
|
||||
|
||||
#endif /* MCU_DRIVER_DEBUG_H_ */
|
||||
34
MCU_Driver/inc/flash_mem_addr.h
Normal file
34
MCU_Driver/inc/flash_mem_addr.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* flash_mem_addr.h
|
||||
* Description : <20><><EFBFBD>ļ<EFBFBD>Ϊ<EFBFBD>ⲿFlash <20><>ַӳ<D6B7><D3B3><EFBFBD><EFBFBD> Size: 0x00200000
|
||||
*
|
||||
* Created on: Jul 31, 2025
|
||||
* Author: cc
|
||||
*/
|
||||
|
||||
#ifndef _FLASH_MEM_ADDR_H_
|
||||
#define _FLASH_MEM_ADDR_H_
|
||||
|
||||
/*APP<50><50><EFBFBD>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
#define SPIFLASH_APP_Start_Addr 0x00000000
|
||||
|
||||
#define SPIFLASH_APP_FEATURE_Addr 0x00000000 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - 512Byte
|
||||
|
||||
|
||||
#define SPIFLASH_UPDATE_RECORD_Addr 0x00000200 //д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳ<EFBFBD>Ʊ<EFBFBD><C6B1><EFBFBD><EFBFBD><EFBFBD>ַ - 512Byte
|
||||
|
||||
#define SPIFLASH_APP_Data_Start_Addr 0x00004000
|
||||
#define SPIFLASH_APP_Data_End_Addr 0x0006FFFF
|
||||
|
||||
#define SPIFLASH_APP_End_Addr 0x0006FFFF
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
#define SPIFLASH_LOGIC_FILE_Start_Addr 0x00070000
|
||||
#define SPIFLASH_LOGIC_DataFlag_ADDRESS 0x00070000 //<2F>ļ<EFBFBD><C4BC><EFBFBD>־λ - 4Byte
|
||||
#define SPIFLASH_LOGIC_DataSize_ADDRESS 0x00070004 //<2F>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD> - 4Byte
|
||||
#define SPIFLASH_LOGIC_DataMD5_ADDRESS 0x00070008 //<2F>ļ<EFBFBD>MD5У<35><D0A3>ֵ - 16Byte
|
||||
#define SPIFLASH_LOGIC_DataStart_ADDRESS 0x00070200 //<2F>ļ<EFBFBD><C4BC><EFBFBD>ʼ<EFBFBD><CABC>ַ
|
||||
#define SPIFLASH_LOGIC_FILE_End_Addr 0x000FFFFF
|
||||
|
||||
|
||||
#endif /* MCU_DRIVER_INC_FLASH_MEM_ADDR_H_ */
|
||||
20
MCU_Driver/inc/led.h
Normal file
20
MCU_Driver/inc/led.h
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* led.h
|
||||
*
|
||||
* Created on: May 15, 2025
|
||||
* Author: cc
|
||||
*/
|
||||
|
||||
#ifndef MCU_DRIVER_INC_LED_H_
|
||||
#define MCU_DRIVER_INC_LED_H_
|
||||
|
||||
#include "ch564.h"
|
||||
|
||||
#define SYS_LED_ON GPIOB_ResetBits(GPIO_Pin_12)
|
||||
#define SYS_LED_OFF GPIOA_SetBits(GPIO_Pin_12)
|
||||
#define SYS_LED_FLIP GPIOA_InverseBits(GPIO_Pin_12)
|
||||
|
||||
void SYS_LED_Init(void);
|
||||
void SYS_LED_Task(void);
|
||||
|
||||
#endif /* MCU_DRIVER_INC_LED_H_ */
|
||||
86
MCU_Driver/inc/log_api.h
Normal file
86
MCU_Driver/inc/log_api.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* log_api.h
|
||||
*
|
||||
* Created on: Jul 29, 2025
|
||||
* Author: cc
|
||||
*/
|
||||
|
||||
#ifndef _LOG_API_H_
|
||||
#define _LOG_API_H_
|
||||
|
||||
#include "ch564.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define LogType_Enable 1 //LOGʹ<47><CAB9>
|
||||
|
||||
/*<2A><>־<EFBFBD>洢<EFBFBD><E6B4A2><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD>*/
|
||||
#define LogType_Launcher 0x01 //Launcher<65><72>Ϣ<EFBFBD><CFA2>¼
|
||||
#define LogType_SYS_Record 0x02 //ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>¼
|
||||
#define LogType_Device_COMM 0x03 //<2F>豸ͨѶ<CDA8><D1B6>¼
|
||||
#define LogType_Device_Online 0x04 //<2F>豸ͨѶ״̬<D7B4><CCAC>¼
|
||||
#define LogType_Global_Parameters 0x05 //<2F><><EFBFBD><EFBFBD><EFBFBD>豸״̬<D7B4><CCAC><EFBFBD>ڼ<EFBFBD>¼
|
||||
#define LogType_Net_COMM 0x06 //<2F><><EFBFBD><EFBFBD>ͨѶ<CDA8><D1B6>¼
|
||||
#define LogType_Logic_Record 0x07 //<2F><EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼
|
||||
|
||||
/*<2A><>־<EFBFBD>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD> - <20><>ʼ״̬*/
|
||||
#define LogType_Launcher_SWITCH 1
|
||||
#define LogType_SYS_Record_SWITCH 1
|
||||
#define LogType_Device_COMM_SWITCH 1
|
||||
#define LogType_Device_Online_SWITCH 1
|
||||
#define LogType_Global_Parameters_SWITCH 1
|
||||
#define LogType_Net_COMM_SWITCH 1
|
||||
#define LogType_Logic_Record_SWITCH 1
|
||||
|
||||
/*<2A><>־<EFBFBD>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD>λ*/
|
||||
#define LogType_Launcher_bit 0
|
||||
#define LogType_SYS_Record_bit 1
|
||||
#define LogType_Device_COMM_bit 2
|
||||
#define LogType_Device_Online_bit 3
|
||||
#define LogType_Global_Parameters_bit 4
|
||||
#define LogType_Net_COMM_bit 5
|
||||
#define LogType_Logic_Record_bit 6
|
||||
|
||||
/*<2A><>־<EFBFBD><D6BE><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>*/
|
||||
#define LogInfo_Device_Online 0x01 //<2F>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||
#define LogInfo_Device_Offline 0x02 //<2F>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||
|
||||
typedef enum{
|
||||
LLauncher_App_Check = 0x01, //У<><D0A3>APP
|
||||
LLauncher_Read_App, //<2F><>ȡAPP<50><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD>APP<50><50><EFBFBD><EFBFBD>д<EFBFBD>뵽MCU FLash<73><68>
|
||||
LLauncher_Write_Flash, //дFlash
|
||||
LLauncher_Factory_Reset, //<2F>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
LLauncher_Reset_Source, //<2F><>λԴ
|
||||
LLauncher_RCUKey_State, //RCU<43><55><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>¼
|
||||
}LOGTYPE_Launcher_E;
|
||||
|
||||
typedef enum {
|
||||
LSYS_PHY_Change = 0x01, //PHY״̬<D7B4>仯<EFBFBD><E4BBAF>¼
|
||||
LSYS_DevInfo_Error, //<2F>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
||||
LSYS_API_State, //<2F><><EFBFBD><EFBFBD>״̬
|
||||
LSYS_NET_ARGC, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
LSYS_MQTT_ARGC, //MQTT<54><54><EFBFBD><EFBFBD>
|
||||
LSYS_Server_Comm_State, //<2F>ƶ<EFBFBD>ͨѶ״̬<D7B4><CCAC>¼
|
||||
LSYS_NET_DefaultARGC, //<2F><><EFBFBD><EFBFBD>Ĭ<EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD>
|
||||
LSYS_RCUKey_State, //RCU<43><55><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>¼
|
||||
}LOGTYPR_SYSRecord;
|
||||
|
||||
typedef enum{
|
||||
LCOMM_ASK_TO_Reply = 0x01, //<2F><>ѯ<EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD>
|
||||
LCOMM_Send_Control, //RCU<43>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
LCOMM_Control_Reply, //RCU<43><55><EFBFBD>ƻظ<C6BB><D8B8><EFBFBD><EFBFBD><EFBFBD>
|
||||
LCOMM_Adjust_Baud, //<2F>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}LOGTYPE_DEV_COMM;
|
||||
|
||||
typedef enum{
|
||||
LGlobal_Para = 0x01, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
LGlobal_Dev, //<2F>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||
}LOGTYPE_Global_E;
|
||||
|
||||
void LOG_Launcher_APP_Check_Record(uint8_t state);
|
||||
void LOG_Launcher_Read_App_Record(uint8_t state);
|
||||
void LOG_Launcher_Write_Flash_Record(uint32_t addr,uint16_t len);
|
||||
void LOG_Launcher_Factory_Reset_Record(uint8_t state);
|
||||
void LOG_Launcher_Reset_Source_Record(uint8_t sour);
|
||||
void LOG_Launcher_RCU_Key_State_Record(uint8_t state);
|
||||
|
||||
#endif /* MCU_DRIVER_INC_LOG_API_H_ */
|
||||
123
MCU_Driver/inc/mcu_flash.h
Normal file
123
MCU_Driver/inc/mcu_flash.h
Normal file
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* mcu_flash.h
|
||||
*
|
||||
* Created on: Aug 2, 2025
|
||||
* Author: cc
|
||||
*/
|
||||
|
||||
#ifndef MCU_DRIVER_INC_MCU_FLASH_H_
|
||||
#define MCU_DRIVER_INC_MCU_FLASH_H_
|
||||
|
||||
#include "ch564.h"
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#define MCU_APP_Flash_PageSize 0x00001000 //MCU FlashҳΪ4096Byte
|
||||
#define APP_Flash_WriteNum 0x05 //APPд<50><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
#define App_Procedure_Ready 0x66 //APP<50><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ
|
||||
#define App_Procedure_Not_Ready 0x44 //Appδ<CEB4><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ
|
||||
|
||||
//MCU Flash Address range(0x0 -- 0x6FFFF) Size(448K)
|
||||
#define MCU_APP_Flash_Start_Addr 0x00007000 //MCU Flash<73><68>APP<50><50><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ
|
||||
#define MCU_APP_Data_Start_Addr 0x00007000 //MCU Flash APP<50><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ
|
||||
#define MCU_APP_Data_End_Addr 0x00027DFF //MCU Flash APP<50><50><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
||||
#define MCU_APP_Feature_Addr 0x00027E00 //MCU Flash <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD><EFBFBD>ַ
|
||||
#define MCU_APP_Flash_End_Addr 0x00027FFF //MCU Flash<73><68>APP<50>Ľ<EFBFBD><C4BD><EFBFBD><EFBFBD><EFBFBD>ַ
|
||||
|
||||
#define MCU_APP_Feature_PageAddr 0x00027000 //MCU APP<50><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>ҳ<EFBFBD>ĵ<EFBFBD>ַ
|
||||
#define MCU_APP_Feature_PageOffset 0x00000E00 //MCU APP<50><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>
|
||||
#define APP_FEATURE_SIZE 0x0200 //512Byte
|
||||
|
||||
//EEPROM Address range(0x70000 -- 0x77FFF) Size(32K)
|
||||
#define MCU_EEPROM_Start_Addr 0x00070000
|
||||
#define MCU_EEPROM_MCUDevInfo_Address 0x00070000 //MCU <20>豸<EFBFBD><E8B1B8>Ϣ<EFBFBD><CFA2>ַ<EFBFBD>̶<EFBFBD>Ϊ0x00070000<30><30><EFBFBD><EFBFBD>СΪ4096 <20><><EFBFBD><EFBFBD><EFBFBD>ɸĶ<C9B8>
|
||||
#define MCU_EEPROM_End_Addr 0x00078000
|
||||
|
||||
|
||||
|
||||
/* EEPROM <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD>ʽ<EFBFBD><CABD>
|
||||
* FLAG - 1Byte <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ
|
||||
* LEN - 2Byte <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
||||
* CHECK - 1Byte <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3>
|
||||
* DATA - nByte <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*
|
||||
* */
|
||||
#define EEPROM_SVAE_FLAG 0xAE
|
||||
#define EEPROM_DATA_Size_Max 0x40 //Ŀǰ<C4BF><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ100Byte
|
||||
#define EEPROM_PARA_Size 50
|
||||
#define EEPROM_DEV_NAME_Size 32
|
||||
|
||||
#define EEPROM_Offset_SaveFlag 0x00
|
||||
#define EEPROM_Offset_Datalen 0x01
|
||||
#define EEPROM_Offset_Check 0x03
|
||||
#define EEPROM_Offset_Data 0x04
|
||||
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽṹ<DDBD><E1B9B9>
|
||||
* ע<>⣺<EFBFBD><E2A3BA><EFBFBD><EFBFBD>risc-v<><76><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>ֽڶ<D6BD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* <20><><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD>Flash/MCU Flash<73>е<EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD>ṹ<EFBFBD>嶨<EFBFBD><E5B6A8>˳<EFBFBD><CBB3><EFBFBD><EFBFBD>һ<EFBFBD>£<EFBFBD>ʹ<EFBFBD><CAB9>ʱ<EFBFBD><CAB1>ע<EFBFBD><D7A2>
|
||||
* */
|
||||
typedef enum{
|
||||
Feature_Check = 0x00, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 512Byte <20><>CRCУ<43><D0A3> - 2Byte
|
||||
Feature_AppFlag = 0x02, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - APP<50><50>־λ - 1Byte
|
||||
Feature_AppStart = 0x03, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - APP<50><50>ʼ<EFBFBD><CABC>ַ - 4Byte
|
||||
Feature_AppEnd = 0x07, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - APP<50><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ - 4Byte
|
||||
Feature_AppCrcSize = 0x0B, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - APP CRC<52>ij<EFBFBD><C4B3><EFBFBD> - 2Byte
|
||||
Feature_AppCrcLen = 0x0D, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - APP CRCУ<43><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD>С - 2Byte
|
||||
Feature_AppFlashCrc = 0x0F, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - APP CRC
|
||||
}FEATURE_E;
|
||||
|
||||
#define APP_Feature_CRC_Size 497
|
||||
|
||||
typedef struct{
|
||||
uint8_t app_flag; //APP <20><>־λ
|
||||
uint8_t app_crc[APP_Feature_CRC_Size]; //APP CRCУ<43><D0A3>ֵ
|
||||
|
||||
uint16_t app_crc_size; //APP CRCУ<43><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD>С
|
||||
uint16_t app_crc_len; //APP CRCУ<43><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
||||
uint16_t crc_check; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CRCֵ - <20><><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>Ϸ<EFBFBD>
|
||||
|
||||
uint32_t app_start_addr; //APP<50><50>ʼ<EFBFBD><CABC>ַ
|
||||
uint32_t app_end_addr; //APP<50><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
||||
}G_SYS_FEATURE_T;
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>MCU EEPROM<4F><4D><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
typedef struct{
|
||||
|
||||
uint8_t dev_addr; //<2F>豸<EFBFBD><E8B1B8>ַ
|
||||
uint8_t dev_type; //<2F>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||
uint8_t dev_boot_ver; //<2F>豸Boot<6F><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>汾<EFBFBD><E6B1BE>
|
||||
uint8_t dev_app_ver; //<2F>豸APP<50><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>汾<EFBFBD><E6B1BE>
|
||||
uint8_t dev_name_len; //<2F>豸<EFBFBD><E8B1B8><EFBFBD>Ƶij<C6B5><C4B3><EFBFBD>
|
||||
uint8_t dev_name[EEPROM_DEV_NAME_Size]; //<2F>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||
|
||||
}E_MCU_DEV_INFO;
|
||||
|
||||
|
||||
|
||||
extern E_MCU_DEV_INFO g_mcu_dev;
|
||||
extern uint8_t g_read_buff[4100];
|
||||
extern uint8_t g_flash_buff[4100];
|
||||
|
||||
void EEPROM_Init(void);
|
||||
uint8_t MCU_APP_Flash_Write(uint8_t* pBuffer,uint16_t NumByteToWrite,uint32_t writeAddr);
|
||||
uint8_t MCU_APP_Flash_Read(uint8_t* pBuffer,uint16_t NumByteToWrite,uint32_t readAddr);
|
||||
uint8_t MCU_APP_Flash_Erase(uint32_t readAddr,uint16_t NumByteToWrite);
|
||||
uint8_t MCU_APP_Flash_ALLErase(void);
|
||||
uint8_t MCU_EEPROM_Write(uint8_t* pBuffer,uint16_t NumByteToWrite,uint32_t writeAddr);
|
||||
uint8_t MCU_EEPROM_Read(uint8_t* pBuffer,uint16_t NumByteToWrite,uint32_t readAddr);
|
||||
uint8_t MCU_EEPROM_Erase(uint32_t readAddr,uint16_t NumByteToWrite);
|
||||
uint8_t MCU_EEPROM_ALLErase(void);
|
||||
|
||||
uint8_t EEPROM_CheckSum(uint8_t *data,uint16_t len);
|
||||
uint8_t EEPROM_ReadMCUDevInfo(E_MCU_DEV_INFO *info);
|
||||
uint8_t EEPROM_WriteMCUDevInfo(E_MCU_DEV_INFO *info);
|
||||
void EEPROM_Default_MCUDevInfo(E_MCU_DEV_INFO *info);
|
||||
void EEPROM_Validate_MCUDevInfo(E_MCU_DEV_INFO *info);
|
||||
|
||||
uint8_t Read_APP_Feature_Info(uint8_t option,G_SYS_FEATURE_T *feature_info);
|
||||
uint8_t Write_APP_Feature_Info(uint8_t option,G_SYS_FEATURE_T *feature_info);
|
||||
void APP_Feature_Info_Printf(G_SYS_FEATURE_T *feature_info);
|
||||
|
||||
#endif /* MCU_DRIVER_INC_MCU_FLASH_H_ */
|
||||
42
MCU_Driver/inc/rtc.h
Normal file
42
MCU_Driver/inc/rtc.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* rtc.h
|
||||
*
|
||||
* Created on: Jul 29, 2025
|
||||
* Author: cc
|
||||
*/
|
||||
|
||||
#ifndef MCU_DRIVER_INC_RTC_H_
|
||||
#define MCU_DRIVER_INC_RTC_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "ch564.h"
|
||||
|
||||
typedef struct{
|
||||
uint8_t second;
|
||||
uint8_t minute;
|
||||
uint8_t hour;
|
||||
uint8_t week;
|
||||
uint8_t day;
|
||||
uint8_t month;
|
||||
uint8_t year;
|
||||
}S_RTC;
|
||||
|
||||
typedef struct{
|
||||
uint32_t hour;
|
||||
uint16_t minute;
|
||||
uint16_t second;
|
||||
}G_CORE_RTC;
|
||||
|
||||
extern S_RTC RTC_Raw_Data;
|
||||
extern uint32_t Log_Time_ms;
|
||||
|
||||
void RTC_Init(void);
|
||||
uint8_t HEX_Conversion_To_DEC(uint8_t c_num);
|
||||
uint8_t DEV_Conversion_To_HEX(uint8_t c_num);
|
||||
uint32_t RTC_Conversion_To_Unix(S_RTC *rtc_time);
|
||||
void Unix_Conversion_To_RTC(S_RTC *rtc_time,uint32_t utc_tick);
|
||||
uint8_t RTC_ReadDate(S_RTC *psRTC);
|
||||
uint8_t RTC_WriteDate(S_RTC SetRTC);
|
||||
void RTC_TASK(void);
|
||||
|
||||
#endif /* MCU_DRIVER_INC_RTC_H_ */
|
||||
41
MCU_Driver/inc/rw_logging.h
Normal file
41
MCU_Driver/inc/rw_logging.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* rw_logging.h
|
||||
*
|
||||
* Created on: Jul 29, 2025
|
||||
* Author: cc
|
||||
*/
|
||||
|
||||
#ifndef MCU_DRIVER_INC_RW_LOGGING_H_
|
||||
#define MCU_DRIVER_INC_RW_LOGGING_H_
|
||||
|
||||
#include "ch564.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define APPFlag_UartUpgrade_Reset 0xBBC1 //APP<50><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ
|
||||
|
||||
//<2F><>־<EFBFBD><D6BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD><D8B6><EFBFBD>
|
||||
#define LOG_Data_Hand 0xA5 //LOG<4F><47><EFBFBD><EFBFBD>ͷ
|
||||
#define Log_Data_End 0x5A //LOG<4F><47><EFBFBD><EFBFBD>β
|
||||
#define Log_Data_Len_MAX 512 //<2F><>־<EFBFBD><D6BE><EFBFBD><EFBFBD><EFBFBD>512Byte
|
||||
|
||||
/*<2A><>־<EFBFBD><D6BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD>ʽ*/
|
||||
typedef enum{
|
||||
S_Log_Hand,
|
||||
S_Log_SN, //<2F><>־ÿ<D6BE><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD>
|
||||
S_Log_Len,
|
||||
S_Log_Len_8,
|
||||
S_Log_Check,
|
||||
S_Log_Date_H, //<2F>꣺5bit <20>£<EFBFBD>5bit <20>գ<EFBFBD>5bit
|
||||
S_Log_Date_L,
|
||||
S_Log_Type,
|
||||
S_Log_Time8B, //Сʱʱ<CAB1><CAB1><EFBFBD><EFBFBD>
|
||||
S_Log_Time16B,
|
||||
S_Log_Time24B,
|
||||
S_Log_Time32B,
|
||||
S_Log_Data,
|
||||
}Sram_Log_Data_Format;
|
||||
|
||||
uint8_t Data_CheckSum(uint8_t* data,uint16_t len);
|
||||
uint8_t Log_write_sram(uint8_t data_type,uint8_t *buff,uint16_t len);
|
||||
|
||||
#endif /* MCU_DRIVER_INC_RW_LOGGING_H_ */
|
||||
65
MCU_Driver/inc/spi_flash.h
Normal file
65
MCU_Driver/inc/spi_flash.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* spi_flash.h
|
||||
*
|
||||
* Created on: May 20, 2025
|
||||
* Author: cc
|
||||
*/
|
||||
|
||||
#ifndef MCU_DRIVER_INC_SPI_FLASH_H_
|
||||
#define MCU_DRIVER_INC_SPI_FLASH_H_
|
||||
|
||||
#include "ch564.h"
|
||||
|
||||
#define Flash_CS_H GPIOA_SetBits(GPIO_Pin_11)
|
||||
#define Flash_CS_L GPIOA_ResetBits(GPIO_Pin_11)
|
||||
|
||||
#define Flash_ADDRESS_MAX 0x00200000
|
||||
|
||||
/***********ָ<><D6B8><EFBFBD><EFBFBD>**********/
|
||||
//Read
|
||||
#define P24Q40H_ReadData 0x03
|
||||
#define P24Q40H_FastReadData 0x0B
|
||||
#define P24Q40H_FastReadDual 0x3B
|
||||
//Program and Erase
|
||||
#define P24Q40H_PageErase 0x81
|
||||
#define P24Q40H_SectorErase 0x20
|
||||
#define P24Q40H_BlockErase 0xD8
|
||||
#define P24Q40H_ChipErase 0xC7
|
||||
#define P24Q40H_PageProgram 0x02
|
||||
//Protection
|
||||
#define P24Q40H_WriteEnable 0x06
|
||||
#define P24Q40H_WriteDisable 0x04
|
||||
//Status Register
|
||||
#define P24Q40H_ReadStatusReg 0x05
|
||||
#define P24Q40H_WriteStatusReg 0x01
|
||||
//Other Commands
|
||||
#define P24Q40H_PowerDown 0xB9
|
||||
#define P24Q40H_ReleasePowerDown 0xAB
|
||||
#define P24Q40H_ReadManufactureID 0x90
|
||||
#define P24Q40H_ReadDeviceID 0x9F
|
||||
#define P24Q40H_ResetEnable 0x66
|
||||
#define P24Q40H_Reset 0x99
|
||||
|
||||
extern uint8_t Flash_Buffer[4150];
|
||||
|
||||
void SPI_FLASH_Init(void);
|
||||
uint8_t Flash_ReadSR(void);
|
||||
void Flash_WriteSR(uint8_t sr_val);
|
||||
void Flash_Write_Enable(void);
|
||||
void Flash_Write_Disable(void);
|
||||
uint16_t Flash_ReadID(void);
|
||||
uint8_t Flash_Wait_Busy(void);
|
||||
void Flash_PowerDown(void);
|
||||
void Flash_Wakeup(void);
|
||||
void Flash_Erase_Chip(void);
|
||||
void Flash_Erase_Block(uint32_t BLK_ID);
|
||||
void Flash_Erase_Sector(uint32_t DST_ID);
|
||||
void Flash_Erase_Page(uint32_t Page_ID);
|
||||
void Flash_Erase_Pageaddr(uint32_t Page_addr);
|
||||
void Flash_Read(uint8_t* pBuffer,uint16_t NumByteToRead,uint32_t ReadAddr);
|
||||
void Flash_Write_Page(uint8_t* pBuffer,uint16_t NumByteToWrite,uint32_t writeAddr);
|
||||
void Flash_Write_NoCheck(uint8_t* pBuffer,uint16_t NumByteToWrite,uint32_t writeAddr);
|
||||
void Flash_Write(uint8_t* pBuffer,uint16_t NumByteToWrite,uint32_t WriteAddr);
|
||||
|
||||
|
||||
#endif /* MCU_DRIVER_INC_SPI_FLASH_H_ */
|
||||
46
MCU_Driver/inc/spi_sram.h
Normal file
46
MCU_Driver/inc/spi_sram.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* spi_sram.h
|
||||
*
|
||||
* Created on: May 16, 2025
|
||||
* Author: cc
|
||||
*/
|
||||
|
||||
#ifndef MCU_DRIVER_INC_SPI_SRAM_H_
|
||||
#define MCU_DRIVER_INC_SPI_SRAM_H_
|
||||
|
||||
#include "ch564.h"
|
||||
|
||||
#define SRAM_CE_H GPIOA_ResetBits(GPIO_Pin_11)
|
||||
#define SRAM_CE_L GPIOA_SetBits(GPIO_Pin_11)
|
||||
|
||||
#define SRAM_CMD_Read 0x03
|
||||
#define SRAM_CMD_Fast_Read 0x0B
|
||||
#define SRAM_CMD_Fast_Read_Quad 0xEB
|
||||
#define SRAM_CMD_Write 0x02
|
||||
#define SRAM_CMD_Quad_Write 0x38
|
||||
#define SRAM_CMD_Enter_Quad_Mode 0x35
|
||||
#define SRAM_CMD_Exit_Quad_Mode 0xF5
|
||||
#define SRAM_CMD_Reset_Enable 0x66
|
||||
#define SRAM_CMD_Reset 0x99
|
||||
#define SRAM_CMD_Wrap_Boundary_Toggle 0xC0
|
||||
#define SRAM_CMD_Read_ID 0x9F
|
||||
|
||||
#define SRAM_ADDRESS_MAX 0x00800000
|
||||
|
||||
|
||||
void SPI_SRAM_Init(void);
|
||||
void SRAM_Write_Byte(uint8_t wdate,uint32_t add);
|
||||
uint8_t SRAM_Read_Byte(uint32_t add);
|
||||
void SRAM_Write_Word(uint16_t wdate,uint32_t add);
|
||||
uint16_t SRAM_Read_Word(uint32_t add);
|
||||
void SRAM_Write_DW(uint32_t wdate,uint32_t add);
|
||||
uint32_t SRAM_Read_DW(uint32_t add);
|
||||
uint8_t SRAM_Read_ID_Opeartion(void);
|
||||
void SRAM_Reset_Operation(void);
|
||||
|
||||
void SRAM_DMA_Write_Buff(uint8_t* wbuff,uint16_t len,uint32_t add);
|
||||
void SRAM_DMA_Read_Buff(uint8_t* rbuff,uint16_t len,uint32_t add);
|
||||
|
||||
|
||||
|
||||
#endif /* MCU_DRIVER_INC_SPI_SRAM_H_ */
|
||||
33
MCU_Driver/inc/sram_mem_addr.h
Normal file
33
MCU_Driver/inc/sram_mem_addr.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* sram_virt_mem_addr.h
|
||||
* <20>ⲿSRAM<41><4D>ַ<EFBFBD>ռ<EFBFBD><D5BC>滮 0x00000000 ~ 0x00800000
|
||||
*
|
||||
* Created on: Jul 29, 2025
|
||||
* Author: cc
|
||||
*/
|
||||
|
||||
#ifndef _SRAM_MEM_ADDR_H_
|
||||
#define _SRAM_MEM_ADDR_H_
|
||||
|
||||
|
||||
/*
|
||||
* 2025-07-29 <20><EFBFBD>SRAM<41>洢<EFBFBD><E6B4A2>ַ 0x00400000 ~ 0x007FFFFF SIZE:4MByte
|
||||
* 1<><31><EFBFBD>ĶԿռ<D4BF><D5BC><EFBFBD>ַУ<D6B7>飬<EFBFBD><E9A3AC>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD>쳣
|
||||
* 2<><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD><D6BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȥ<EFBFBD><C8A5>û<EFBFBD><C3BB>ʹ<EFBFBD>õı<C3B5><C4B1><EFBFBD>
|
||||
*
|
||||
* */
|
||||
#define SRAM_LOG_WRITE_Address 0x00400000 //<2F><>־<EFBFBD>ռ<EFBFBD><D5BC><EFBFBD>ʼ<EFBFBD><CABC>ַ - <20><>ǰSRAM<41><4D><EFBFBD><EFBFBD>־<EFBFBD><D6BE><EFBFBD>ݵ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>ַ - 4Byte
|
||||
#define SRAM_LOG_READ_Address 0x00400004 //<2F><>־<EFBFBD>ϱ<EFBFBD><CFB1><EFBFBD>ȡ<EFBFBD><C8A1>ַ - 4Byte
|
||||
#define SRAM_LOG_Serial_Number 0x00400008 //<2F><>־<EFBFBD><D6BE><EFBFBD>ű<EFBFBD><C5B1><EFBFBD><EFBFBD><EFBFBD>ַ - 2Byte Ŀǰֻʹ<D6BB><CAB9>1Byte
|
||||
#define SRAM_LOGFlag_Reset_Source 0x0040000A //Launcher<65><72><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD> - <20><>APPʹ<50><CAB9> - 1Byte
|
||||
#define SRAM_LOGFlag_Addr_INIT 0x0040000B //Launcher<65><72>¼<EFBFBD><C2BC>ַ<EFBFBD><D6B7>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>־λ - <20><>APPʹ<50><CAB9> - 1Byte
|
||||
#define SRAM_LOGFlag_Debug_Switch 0x0040000C //Launcher<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ 4Byte - <20><>APPʹ<50><CAB9>
|
||||
#define SRAM_APPFlag_Reset_Source 0x00400010 //App<70><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ 2Byte - <20><>Launcher<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣʹ<CFA2><CAB9> 0xBBC1
|
||||
#define SRAM_LOG_DATA_Address 0x00400100 //<2F><>־<EFBFBD><D6BE><EFBFBD>ݵ<EFBFBD>ַ
|
||||
#define SRAM_LOG_End_Address 0x007FFFFF //<2F><>־<EFBFBD>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ - 0x007FFFFF
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* MCU_DRIVER_INC_SRAM_MEM_ADDR_H_ */
|
||||
20
MCU_Driver/inc/timer.h
Normal file
20
MCU_Driver/inc/timer.h
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* timer.h
|
||||
*
|
||||
* Created on: May 16, 2025
|
||||
* Author: cc
|
||||
*/
|
||||
|
||||
#ifndef MCU_DRIVER_INC_TIMER_H_
|
||||
#define MCU_DRIVER_INC_TIMER_H_
|
||||
|
||||
#include "ch564.h"
|
||||
|
||||
|
||||
extern volatile uint32_t Time0_100us;
|
||||
extern volatile uint32_t Time0_1ms;
|
||||
|
||||
void TIMER0_Init(void);
|
||||
void Timer0_Task(void);
|
||||
|
||||
#endif /* MCU_DRIVER_INC_TIMER_H_ */
|
||||
100
MCU_Driver/inc/uart.h
Normal file
100
MCU_Driver/inc/uart.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* uart.h
|
||||
*
|
||||
* Created on: May 14, 2025
|
||||
* Author: cc
|
||||
*/
|
||||
|
||||
#ifndef MCU_DRIVER_INC_UART_H_
|
||||
#define MCU_DRIVER_INC_UART_H_
|
||||
|
||||
#include "ch564.h"
|
||||
|
||||
|
||||
#define MCU485_EN1_H GPIOD_SetBits(GPIO_Pin_21)
|
||||
#define MCU485_EN1_L GPIOD_ResetBits(GPIO_Pin_21)
|
||||
#define MCU485_EN2_H GPIOB_SetBits(GPIO_Pin_15)
|
||||
#define MCU485_EN2_L GPIOB_ResetBits(GPIO_Pin_15)
|
||||
|
||||
#define UART_COMMBUSY_IDLE_Flag 0x00
|
||||
#define UART_COMMBUSY_RECV_Flag 0x01
|
||||
#define UART_COMMBUSY_SEND_Flag 0x02
|
||||
|
||||
#define Recv_2400_TimeOut 10 //ms
|
||||
#define Recv_9600_TimeOut 5 //ms
|
||||
#define Recv_115200_TimeOut 3 //ms
|
||||
#define Recv_512000_TimeOut 3 //ms
|
||||
|
||||
#define USART_BUFFER_SIZE 512
|
||||
|
||||
|
||||
typedef void (*Uart_prt)(uint8_t * ,uint16_t );
|
||||
typedef uint8_t (*Uart_set_prt)(uint32_t );
|
||||
|
||||
typedef enum
|
||||
{
|
||||
UART_0,
|
||||
UART_1,
|
||||
UART_2,
|
||||
UART_3,
|
||||
UART_MAX,
|
||||
}UART_IDX;
|
||||
|
||||
typedef struct{
|
||||
|
||||
uint8_t RecvBuffer[USART_BUFFER_SIZE];
|
||||
uint8_t deal_buff[USART_BUFFER_SIZE];
|
||||
uint8_t ackBuffer[USART_BUFFER_SIZE];
|
||||
uint8_t SendBuffer[USART_BUFFER_SIZE];
|
||||
|
||||
uint8_t SendCount; //<2F>ܷ<EFBFBD><DCB7>ʹ<EFBFBD><CDB4><EFBFBD>
|
||||
uint8_t SendCnt; //<2F><>ǰ<EFBFBD><C7B0><EFBFBD>ʹ<EFBFBD><CDB4><EFBFBD>
|
||||
uint8_t CommBusy; //ͨѶ<CDA8><D1B6>æ״̬
|
||||
|
||||
uint8_t Receiving;
|
||||
uint8_t sn;
|
||||
uint8_t pc_addr;
|
||||
uint8_t cmd;
|
||||
|
||||
uint8_t appFlag;
|
||||
uint8_t writeFlag;
|
||||
uint8_t ChangeBaudFlag; //<2F>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>־λ
|
||||
|
||||
uint16_t RecvLen;
|
||||
uint16_t deal_len;
|
||||
uint16_t ackLen;
|
||||
uint16_t SendLen; //<2F><><EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD>
|
||||
|
||||
uint32_t CommBaud; //ͨѶ<CDA8><D1B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱʹ<CAB1><CAB9>
|
||||
uint32_t ackValidity; //<2F><><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD>Ч<EFBFBD><D0A7>
|
||||
uint32_t SendValidDuration; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чʱ<D0A7><CAB1>
|
||||
uint32_t SendValidTick; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чʱ<D0A7><CAB1><EFBFBD><EFBFBD>
|
||||
uint32_t SendInterval; //<2F><><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>
|
||||
uint32_t SendTick; //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
||||
|
||||
uint32_t RecvTimeout;
|
||||
uint32_t RecvIdleTiming;
|
||||
uint32_t SendIdleTick; //<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
||||
|
||||
Uart_prt send_data_cf;
|
||||
Uart_set_prt set_baud_cf;
|
||||
}UART_t;
|
||||
|
||||
extern UART_t g_uart[UART_MAX];
|
||||
|
||||
void UARTx_Init(UART_IDX uart_id, uint32_t buad);
|
||||
void Set_Uart_recvTimeout(UART_t *set_uart,uint32_t baud);
|
||||
|
||||
void UART0_RECEIVE(void);
|
||||
void UART1_RECEIVE(void);
|
||||
void UART2_RECEIVE(void);
|
||||
void UART3_RECEIVE(void);
|
||||
|
||||
uint8_t UART0_ChangeBaud(uint32_t baudrate);
|
||||
uint8_t UART1_ChangeBaud(uint32_t baudrate);
|
||||
uint8_t UART2_ChangeBaud(uint32_t baudrate);
|
||||
uint8_t UART3_ChangeBaud(uint32_t baudrate);
|
||||
|
||||
void Uart0_Task(void);
|
||||
|
||||
#endif /* MCU_DRIVER_INC_UART_H_ */
|
||||
33
MCU_Driver/led.c
Normal file
33
MCU_Driver/led.c
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* led.c
|
||||
*
|
||||
* Created on: 2025<32><35>5<EFBFBD><35>15<31><35>
|
||||
* Author: cc
|
||||
*/
|
||||
|
||||
#include "led.h"
|
||||
#include "debug.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void SYS_LED_Init(void)
|
||||
{
|
||||
GPIOA_ModeCfg(GPIO_Pin_12,GPIO_ModeOut_PP); //LED
|
||||
|
||||
SYS_LED_ON;
|
||||
}
|
||||
|
||||
void SYS_LED_Task(void)
|
||||
{
|
||||
static uint32_t led_tick = 0;
|
||||
|
||||
if(SysTick_1ms - led_tick >= 1000 ){
|
||||
led_tick = SysTick_1ms;
|
||||
|
||||
SYS_LED_FLIP;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
175
MCU_Driver/log_api.c
Normal file
175
MCU_Driver/log_api.c
Normal file
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
* log_api.c
|
||||
*
|
||||
* Created on: Jul 29, 2025
|
||||
* Author: cc
|
||||
*/
|
||||
|
||||
#include "rw_logging.h"
|
||||
#include "SPI_SRAM.h"
|
||||
#include "Log_api.h"
|
||||
#include "string.h"
|
||||
|
||||
uint32_t SYS_Log_Switch = (LogType_Launcher_SWITCH << LogType_Launcher_bit) + \
|
||||
(LogType_SYS_Record_SWITCH << LogType_SYS_Record_bit) + \
|
||||
(LogType_Device_COMM_SWITCH << LogType_Device_COMM_bit) + \
|
||||
(LogType_Device_Online_SWITCH << LogType_Device_Online_bit) + \
|
||||
(LogType_Global_Parameters_SWITCH << LogType_Global_Parameters_bit) + \
|
||||
(LogType_Net_COMM_SWITCH << LogType_Net_COMM_bit) + \
|
||||
(LogType_Logic_Record_SWITCH << LogType_Logic_Record_bit);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : LOG_Launcher_APP_Check_Record
|
||||
* Description : Launcher<65><72><EFBFBD><EFBFBD> - У<><D0A3>APP
|
||||
* Input :
|
||||
state :״̬
|
||||
0x00:<3A><>ͬ<EFBFBD><CDAC>
|
||||
0x01:<3A>汾<EFBFBD>Ų<EFBFBD>ͬ<EFBFBD><CDAC>
|
||||
0x02:CRCУ<43>鲻ͬ<E9B2BB><CDAC>
|
||||
0x03:Flash<73><68>APP<50><50>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
0x04:Flash APP<50><50><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
0x05:Flash<73><68>APP<50><50>־δ<D6BE><CEB4>λ<EFBFBD><CEBB>
|
||||
0x06:Flash <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CRCУ<43><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
0x07:MCU Flash<73><68><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
0x08:MCU Flash<73><68>APP<50><50>־δ<D6BE><CEB4>λ<EFBFBD><CEBB>
|
||||
0x09:MCU Flash<73><68><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CRCУ<43><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void LOG_Launcher_APP_Check_Record(uint8_t state)
|
||||
{
|
||||
if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_Launcher_bit )) )
|
||||
{
|
||||
uint8_t temp_buff[3] = {0};
|
||||
|
||||
temp_buff[0] = LLauncher_App_Check;
|
||||
temp_buff[1] = state;
|
||||
|
||||
Log_write_sram(LogType_Launcher,temp_buff,2);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : LOG_Launcher_APP_Check_Record
|
||||
* Description : Launcher<65><72><EFBFBD><EFBFBD> - У<><D0A3>APP
|
||||
* Input :
|
||||
state :״̬
|
||||
0x00:<3A>ɹ<EFBFBD>
|
||||
0x01:ʧ<><CAA7>
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void LOG_Launcher_Read_App_Record(uint8_t state)
|
||||
{
|
||||
if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_Launcher_bit )) )
|
||||
{
|
||||
uint8_t temp_buff[3] = {0};
|
||||
|
||||
temp_buff[0] = LLauncher_Read_App;
|
||||
temp_buff[1] = state;
|
||||
|
||||
Log_write_sram(LogType_Launcher,temp_buff,2);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : LOG_Launcher_Write_Flash_Record
|
||||
* Description : Launcher<65><72><EFBFBD><EFBFBD> - Flashд<68><D0B4>
|
||||
* Input :
|
||||
addr :д<><D0B4><EFBFBD><EFBFBD>ַ
|
||||
len :д<>볤<EFBFBD><EBB3A4>
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void LOG_Launcher_Write_Flash_Record(uint32_t addr,uint16_t len)
|
||||
{
|
||||
if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_Launcher_bit )) )
|
||||
{
|
||||
uint8_t temp_buff[7] = {0};
|
||||
|
||||
temp_buff[0] = LLauncher_Write_Flash;
|
||||
temp_buff[1] = addr & 0xFF;
|
||||
temp_buff[2] = (addr >> 8) & 0xFF;
|
||||
temp_buff[3] = (addr >> 16) & 0xFF;
|
||||
temp_buff[4] = (addr >> 24) & 0xFF;
|
||||
temp_buff[5] = len & 0xFF;
|
||||
temp_buff[6] = (len >> 8) & 0xFF;
|
||||
|
||||
Log_write_sram(LogType_Launcher,temp_buff,7);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : LOG_Launcher_Factory_Reset_Record
|
||||
* Description : Launcher<65><72><EFBFBD><EFBFBD> - <20>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* Input :
|
||||
state<74><65>
|
||||
0x01:д<><D0B4><EFBFBD>ɹ<EFBFBD>
|
||||
0x02:д<><D0B4>ʧ<EFBFBD><CAA7> - û<>г<EFBFBD><D0B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
0x03:д<><D0B4>ʧ<EFBFBD><CAA7> - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4>ʧ<EFBFBD><CAA7>
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void LOG_Launcher_Factory_Reset_Record(uint8_t state)
|
||||
{
|
||||
if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_Launcher_bit )) )
|
||||
{
|
||||
uint8_t temp_buff[3] = {0};
|
||||
|
||||
temp_buff[0] = LLauncher_Factory_Reset;
|
||||
temp_buff[1] = state;
|
||||
|
||||
Log_write_sram(LogType_Launcher,temp_buff,2);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : LOG_Launcher_Factory_Reset_Record
|
||||
* Description : Launcher<65><72><EFBFBD><EFBFBD> - <20><>λԴ
|
||||
* Input :
|
||||
sour<75><72><EFBFBD><EFBFBD>λ<EFBFBD>ź<EFBFBD>ֵ
|
||||
0x00<30><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ
|
||||
0x01<30><31><EFBFBD>ϵ縴λ
|
||||
0x02<30><32><EFBFBD><EFBFBD><EFBFBD>Ź<EFBFBD><C5B9><EFBFBD>λ
|
||||
0x03<30><33><EFBFBD>ⲿ<EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>λ
|
||||
0x05<30><35><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD>ʱ<EFBFBD>ĸ<EFBFBD>λ - ͨ<><CDA8>WCHISPTool<6F><6C>¼<EFBFBD><C2BC><EFBFBD>ĸ<EFBFBD>λ
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void LOG_Launcher_Reset_Source_Record(uint8_t sour)
|
||||
{
|
||||
if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_Launcher_bit )) )
|
||||
{
|
||||
uint8_t temp_buff[3] = {0};
|
||||
|
||||
temp_buff[0] = LLauncher_Reset_Source;
|
||||
temp_buff[1] = sour;
|
||||
|
||||
Log_write_sram(LogType_Launcher,temp_buff,2);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : LOG_Launcher_Factory_Reset_Record
|
||||
* Description : Launcher<65><72><EFBFBD><EFBFBD> - RCU<43><55><EFBFBD>ذ<EFBFBD><D8B0><EFBFBD>
|
||||
* Input :
|
||||
state<74><65>״̬
|
||||
0x01<30><31><EFBFBD>㰴
|
||||
0x02<30><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
0x03<30><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɿ<EFBFBD>
|
||||
0x04<30><34><EFBFBD>ﵽ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void LOG_Launcher_RCU_Key_State_Record(uint8_t state)
|
||||
{
|
||||
if(LogType_Enable && (SYS_Log_Switch & (1 << LogType_Launcher_bit )) )
|
||||
{
|
||||
uint8_t temp_buff[3] = {0};
|
||||
|
||||
temp_buff[0] = LLauncher_RCUKey_State;
|
||||
temp_buff[1] = state;
|
||||
|
||||
Log_write_sram(LogType_Launcher,temp_buff,2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
638
MCU_Driver/mcu_flash.c
Normal file
638
MCU_Driver/mcu_flash.c
Normal file
@@ -0,0 +1,638 @@
|
||||
/*
|
||||
* mcu_flash.c
|
||||
*
|
||||
* Created on: Aug 2, 2025
|
||||
* Author: cc
|
||||
*/
|
||||
#include "includes.h"
|
||||
#include <string.h>
|
||||
|
||||
E_MCU_DEV_INFO g_mcu_dev;
|
||||
|
||||
uint8_t g_read_buff[4100] = {0};
|
||||
uint8_t g_flash_buff[4100] = {0};
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : EEPROM_Init
|
||||
* Description : EEPROM <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*******************************************************************************/
|
||||
void EEPROM_Init(void)
|
||||
{
|
||||
uint8_t rev = 0;
|
||||
|
||||
rev = EEPROM_ReadMCUDevInfo(&g_mcu_dev);
|
||||
if(rev == 0x00){
|
||||
//<2F><>ȡ<EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD>ʼУ<CABC><D0A3><EFBFBD><EFBFBD><EFBFBD>²<EFBFBD><C2B2><EFBFBD>
|
||||
EEPROM_Validate_MCUDevInfo(&g_mcu_dev);
|
||||
}else{
|
||||
//<2F><>ȡʧ<C8A1>ܣ<EFBFBD><DCA3>ָ<EFBFBD>Ĭ<EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD>
|
||||
DBG_SYS_Printf("EE Use Defalut Para");
|
||||
EEPROM_Default_MCUDevInfo(&g_mcu_dev);
|
||||
|
||||
//DBG_SYS_Printf("EE Use Defalut Para");
|
||||
DBG_SYS_Printf("EE DevBootVer:%d",g_mcu_dev.dev_boot_ver);
|
||||
DBG_SYS_Printf("EE DevNameLen:%d",g_mcu_dev.dev_name_len);
|
||||
DBG_SYS_Printf("EE DevName:%s",g_mcu_dev.dev_name);
|
||||
}
|
||||
|
||||
//EEPROM_Default_MCUDevInfo(&g_mcu_dev);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : MCU_Flash_Write
|
||||
* Description : MCU Flash<73><68><EFBFBD><EFBFBD>д<EFBFBD>뺯<EFBFBD><EBBAAF>
|
||||
* Input :
|
||||
pBuffer<65><72>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
NumByteToWrite<74><65>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD> -- д<>볤<EFBFBD>ȱ<EFBFBD><C8B1><EFBFBD>Ϊ4<CEAA>ı<EFBFBD><C4B1><EFBFBD>
|
||||
writeAddr<64><72>д<EFBFBD><D0B4><EFBFBD><EFBFBD>ַ 0x00004000 ~ 0x0006FFFF 432KB
|
||||
*******************************************************************************/
|
||||
uint8_t MCU_APP_Flash_Write(uint8_t* pBuffer,uint16_t NumByteToWrite,uint32_t writeAddr)
|
||||
{
|
||||
FLASH_Status sta;
|
||||
|
||||
/* У<><D0A3>д<EFBFBD><D0B4><EFBFBD><EFBFBD>ַ<EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - д<><D0B4><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>APP Flash<73><68>Χ<EFBFBD><CEA7><EFBFBD>Լ<EFBFBD>д<EFBFBD>볤<EFBFBD><EBB3A4><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>4Byte<74><65><EFBFBD><EFBFBD>*/
|
||||
if( ( writeAddr < MCU_APP_Flash_Start_Addr ) || ( ( writeAddr + NumByteToWrite ) > MCU_EEPROM_Start_Addr ) || ((NumByteToWrite % 4) != 0x00) ) {
|
||||
DBG_SYS_Printf("MCU APP Flash Addr Error:%x - %x\r\n", writeAddr, NumByteToWrite);
|
||||
return 0x01;
|
||||
}
|
||||
|
||||
FLASH_Unlock();
|
||||
sta = FLASH_ROMA_WRITE(writeAddr, pBuffer, NumByteToWrite);
|
||||
FLASH_Lock();
|
||||
if (sta != FLASH_COMPLETE){
|
||||
DBG_SYS_Printf("Operation FLASH_ROMA_WRITE failed %#x!! Err Code %x\r\n", writeAddr, sta);
|
||||
return 0x01;
|
||||
}
|
||||
|
||||
sta = FLASH_ROMA_VERIFY(writeAddr, pBuffer, NumByteToWrite);
|
||||
if (sta != FLASH_COMPLETE){
|
||||
DBG_SYS_Printf("Operation FLASH_ROMA_VERIFY failed %#x!! Err Code %x\r\n", writeAddr, sta);
|
||||
return 0x01;
|
||||
}
|
||||
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : MCU_Flash_Read
|
||||
* Description : MCU Flash<73><68><EFBFBD>ݶ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||||
* Input :
|
||||
pBuffer<65><72>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
NumByteToWrite<74><65>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD> -- д<>볤<EFBFBD>ȱ<EFBFBD><C8B1><EFBFBD>Ϊ4<CEAA>ı<EFBFBD><C4B1><EFBFBD>
|
||||
readAddr<64><72><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>ַ 0x00004000 ~ 0x0006FFFF 432KB
|
||||
*******************************************************************************/
|
||||
uint8_t MCU_APP_Flash_Read(uint8_t* pBuffer,uint16_t NumByteToWrite,uint32_t readAddr)
|
||||
{
|
||||
FLASH_Status sta;
|
||||
|
||||
/* У<><D0A3><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>ַ<EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><>ȡ<EFBFBD><C8A1>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>APP Flash<73><68>Χ<EFBFBD><CEA7>*/
|
||||
if( ( readAddr < MCU_APP_Flash_Start_Addr ) || ( ( readAddr + NumByteToWrite ) > MCU_EEPROM_Start_Addr ) ) {
|
||||
DBG_SYS_Printf("MCU APP Flash Addr Error:%x - %x\r\n", readAddr, NumByteToWrite);
|
||||
return 0x01;
|
||||
}
|
||||
|
||||
sta = FLASH_ROMA_READ(readAddr, pBuffer, NumByteToWrite);
|
||||
|
||||
if (sta != FLASH_COMPLETE){
|
||||
DBG_Printf("Operation FLASH_ROMA_READ failed %x!! Err Code %x\r\n", readAddr, sta);
|
||||
return 0x01;
|
||||
}
|
||||
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : MCU_APP_Flash_Erase
|
||||
* Description : MCU Flash<73><68><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* Input :
|
||||
pBuffer<65><72>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
NumByteToWrite<74><65>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD> -- д<>볤<EFBFBD>ȱ<EFBFBD><C8B1><EFBFBD>Ϊ4<CEAA>ı<EFBFBD><C4B1><EFBFBD>
|
||||
readAddr<64><72><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>ַ 0x00004000 ~ 0x0006FFFF 432KB
|
||||
*******************************************************************************/
|
||||
uint8_t MCU_APP_Flash_Erase(uint32_t readAddr,uint16_t NumByteToWrite)
|
||||
{
|
||||
FLASH_Status sta;
|
||||
|
||||
/* У<><D0A3><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>ַ<EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><>ȡ<EFBFBD><C8A1>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>APP Flash<73><68>Χ<EFBFBD><CEA7>*/
|
||||
if( ( readAddr < MCU_APP_Flash_Start_Addr ) || ( ( readAddr + NumByteToWrite ) > MCU_EEPROM_Start_Addr ) ) {
|
||||
DBG_SYS_Printf("MCU EEPROM Addr Error:%x - %x\r\n", readAddr, NumByteToWrite);
|
||||
return 0x01;
|
||||
}
|
||||
|
||||
FLASH_Unlock();
|
||||
sta = FLASH_ROMA_ERASE(readAddr, NumByteToWrite);
|
||||
FLASH_Lock();
|
||||
|
||||
if (sta != FLASH_COMPLETE){
|
||||
DBG_Printf("Operation FLASH_ROMA_ERASE failed %x!! Err Code %x\r\n", readAddr, sta);
|
||||
return 0x01;
|
||||
}
|
||||
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : MCU_APP_Flash_ALLErase
|
||||
* Description : MCU Flash<73><68><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - APP<50><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD>APP<50><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
||||
*******************************************************************************/
|
||||
uint8_t MCU_APP_Flash_ALLErase(void)
|
||||
{
|
||||
FLASH_Status sta;
|
||||
|
||||
for(uint32_t i=MCU_APP_Flash_Start_Addr;i<MCU_APP_Flash_End_Addr;i+=MCU_APP_Flash_PageSize)
|
||||
{
|
||||
DBG_Printf("Operation FLASH_ROMA_ERASE - %x!! \r\n", i);
|
||||
FLASH_Unlock();
|
||||
sta = FLASH_ROMA_ERASE(i, MCU_APP_Flash_PageSize);
|
||||
FLASH_Lock();
|
||||
|
||||
if (sta != FLASH_COMPLETE){
|
||||
DBG_Printf("Operation FLASH_ROMA_ERASE failed %x!! Err Code %x\r\n", i, sta);
|
||||
return 0x01;
|
||||
}
|
||||
}
|
||||
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : MCU_EEPROM_Write
|
||||
* Description : MCU EEPROM<4F><4D><EFBFBD><EFBFBD>д<EFBFBD>뺯<EFBFBD><EBBAAF>
|
||||
* Input :
|
||||
pBuffer<65><72>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
NumByteToWrite<74><65>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD> -- д<>볤<EFBFBD>ȱ<EFBFBD><C8B1><EFBFBD>Ϊ4<CEAA>ı<EFBFBD><C4B1><EFBFBD>
|
||||
writeAddr<64><72>д<EFBFBD><D0B4><EFBFBD><EFBFBD>ַ 0x00004000 ~ 0x0006FFFF 432KB
|
||||
*******************************************************************************/
|
||||
uint8_t MCU_EEPROM_Write(uint8_t* pBuffer,uint16_t NumByteToWrite,uint32_t writeAddr)
|
||||
{
|
||||
FLASH_Status sta;
|
||||
|
||||
/* У<><D0A3>д<EFBFBD><D0B4><EFBFBD><EFBFBD>ַ<EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - д<><D0B4><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>APP Flash<73><68>Χ<EFBFBD><CEA7><EFBFBD>Լ<EFBFBD>д<EFBFBD>볤<EFBFBD><EBB3A4><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>4Byte<74><65><EFBFBD><EFBFBD>*/
|
||||
if( ( writeAddr < MCU_EEPROM_Start_Addr ) || ( ( writeAddr + NumByteToWrite ) > MCU_EEPROM_End_Addr ) || ((NumByteToWrite % 4) != 0x00)) {
|
||||
DBG_SYS_Printf("MCU EEPROM Addr Error:%x - %x\r\n", writeAddr, NumByteToWrite);
|
||||
return 0x01;
|
||||
}
|
||||
|
||||
FLASH_Unlock();
|
||||
sta = EEPROM_WRITE(writeAddr, pBuffer, NumByteToWrite);
|
||||
FLASH_Lock();
|
||||
|
||||
if (sta != FLASH_COMPLETE){
|
||||
DBG_SYS_Printf("Operation FLASH_ROMA_WRITE failed %x!! Err Code %x\r\n", writeAddr, sta);
|
||||
|
||||
return 0x01;
|
||||
}
|
||||
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : MCU_EEPROM_Read
|
||||
* Description : MCU EEPROM<4F><4D><EFBFBD>ݶ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||||
* Input :
|
||||
pBuffer<65><72>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
NumByteToWrite<74><65>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD> -- д<>볤<EFBFBD>ȱ<EFBFBD><C8B1><EFBFBD>Ϊ4<CEAA>ı<EFBFBD><C4B1><EFBFBD>
|
||||
readAddr<64><72><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>ַ 0x00004000 ~ 0x0006FFFF 432KB
|
||||
*******************************************************************************/
|
||||
uint8_t MCU_EEPROM_Read(uint8_t* pBuffer,uint16_t NumByteToWrite,uint32_t readAddr)
|
||||
{
|
||||
FLASH_Status sta;
|
||||
|
||||
/* У<><D0A3><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>ַ<EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><>ȡ<EFBFBD><C8A1>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>APP Flash<73><68>Χ<EFBFBD><CEA7>*/
|
||||
if( ( readAddr < MCU_EEPROM_Start_Addr ) || ( ( readAddr + NumByteToWrite ) > MCU_EEPROM_End_Addr ) ) {
|
||||
DBG_SYS_Printf("MCU EEPROM Addr Error:%x - %x\r\n", readAddr, NumByteToWrite);
|
||||
return 0x01;
|
||||
}
|
||||
|
||||
sta = EEPROM_READ(readAddr, pBuffer, NumByteToWrite);
|
||||
|
||||
if (sta != FLASH_COMPLETE){
|
||||
DBG_Printf("Operation FLASH_ROMA_READ failed %x!! Err Code %x\r\n", readAddr, sta);
|
||||
return 0x01;
|
||||
}
|
||||
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : MCU_EEPROM_Erase
|
||||
* Description : MCU EEPROM<4F><4D><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* Input :
|
||||
eraseAddr<64><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ 0x70000 -- 0x77FFF
|
||||
length<74><68>ֻ<EFBFBD>ܰ<EFBFBD><DCB0>տ<EFBFBD><D5BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>СΪ4096
|
||||
*******************************************************************************/
|
||||
uint8_t MCU_EEPROM_Erase(uint32_t eraseAddr,uint16_t length)
|
||||
{
|
||||
FLASH_Status sta;
|
||||
|
||||
/* У<><D0A3><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>ַ<EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20><>ȡ<EFBFBD><C8A1>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>APP Flash<73><68>Χ<EFBFBD><CEA7> */
|
||||
if( ( eraseAddr < MCU_EEPROM_Start_Addr ) || ( ( eraseAddr + length ) > MCU_EEPROM_End_Addr ) ) {
|
||||
DBG_SYS_Printf("MCU EEPROM Addr Error:%x - %x\r\n", eraseAddr, length);
|
||||
return 0x01;
|
||||
}
|
||||
|
||||
FLASH_Unlock();
|
||||
sta = EEPROM_ERASE(eraseAddr, length);
|
||||
FLASH_Lock();
|
||||
|
||||
if (sta != FLASH_COMPLETE){
|
||||
DBG_Printf("Operation MCU_EEPROM_Erase failed %x!! Err Code %x\r\n", eraseAddr, sta);
|
||||
return 0x01;
|
||||
}
|
||||
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : MCU_EEPROM_ALLErase
|
||||
* Description : MCU Flash<73><68><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - EEPROM<4F><4D><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*******************************************************************************/
|
||||
uint8_t MCU_EEPROM_ALLErase(void)
|
||||
{
|
||||
FLASH_Status sta;
|
||||
|
||||
for(uint32_t i=MCU_EEPROM_Start_Addr;i<MCU_EEPROM_End_Addr;i+=MCU_APP_Flash_PageSize)
|
||||
{
|
||||
FLASH_Unlock();
|
||||
sta = EEPROM_ERASE(i, MCU_APP_Flash_PageSize);
|
||||
FLASH_Lock();
|
||||
|
||||
if (sta != FLASH_COMPLETE){
|
||||
DBG_Printf("Operation FLASH_ROMA_ERASE failed %x!! Err Code %x\r\n", i, sta);
|
||||
return 0x01;
|
||||
}
|
||||
}
|
||||
|
||||
return 0x01;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : EEPROM_CheckSum
|
||||
* Description : EEPROM У<>麯<EFBFBD><E9BAAF>
|
||||
*******************************************************************************/
|
||||
uint8_t EEPROM_CheckSum(uint8_t *data,uint16_t len)
|
||||
{
|
||||
uint8_t data_sum = 0;
|
||||
|
||||
for(uint16_t i = 0;i<len;i++)
|
||||
{
|
||||
data_sum += data[i];
|
||||
}
|
||||
return data_sum;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : EEPROM_ReadMCUDevInfo
|
||||
* Description : <20><>EEPROM<4F>ж<EFBFBD>ȡ<EFBFBD>豸<EFBFBD><E8B1B8>Ϣ
|
||||
*******************************************************************************/
|
||||
uint8_t EEPROM_ReadMCUDevInfo(E_MCU_DEV_INFO *info)
|
||||
{
|
||||
uint16_t read_len = 0;
|
||||
uint32_t read_addr = MCU_EEPROM_MCUDevInfo_Address;
|
||||
|
||||
memset(g_read_buff,0,sizeof(g_read_buff));
|
||||
|
||||
DBG_SYS_Printf("EEPROM_READ : %x ",read_addr);
|
||||
|
||||
DBG_Printf("EEPROM_READ 1\r\n");
|
||||
|
||||
FLASH_Unlock();
|
||||
EEPROM_ERASE(read_addr , 0x1000);
|
||||
FLASH_Lock();
|
||||
|
||||
DBG_Printf("EEPROM_READ 2\r\n");
|
||||
|
||||
EEPROM_READ(read_addr,g_read_buff,1024);
|
||||
|
||||
Dbg_Print_Buff(DBG_BIT_SYS_STATUS,"Dev Info:",g_read_buff,4);
|
||||
|
||||
if(g_read_buff[0] == EEPROM_SVAE_FLAG){
|
||||
read_len = g_read_buff[2];
|
||||
read_len <<= 8;
|
||||
read_len |= g_read_buff[1];
|
||||
|
||||
DBG_SYS_Printf("read_len : %d ",read_len);
|
||||
|
||||
if(read_len <= EEPROM_DATA_Size_Max){
|
||||
DBG_SYS_Printf("read_para %0x%x\r\n",MCU_EEPROM_MCUDevInfo_Address);
|
||||
|
||||
//EEPROM_READ(MCU_EEPROM_MCUDevInfo_Address,g_read_buff,1024);
|
||||
|
||||
Dbg_Print_Buff(DBG_BIT_SYS_STATUS,"Dev Info Para:",&g_read_buff[4],read_len);
|
||||
|
||||
if(EEPROM_CheckSum(&g_read_buff[4],sizeof(E_MCU_DEV_INFO)) == g_read_buff[3]){
|
||||
//У<><D0A3><EFBFBD>ɹ<EFBFBD>
|
||||
memcpy((uint8_t *)info,g_read_buff,sizeof(E_MCU_DEV_INFO));
|
||||
|
||||
DBG_SYS_Printf("EE DevAddr:%d",info->dev_addr);
|
||||
DBG_SYS_Printf("EE DevType:%d",info->dev_type);
|
||||
DBG_SYS_Printf("EE DevBootVer:%d",info->dev_boot_ver);
|
||||
DBG_SYS_Printf("EE DevAppVer:%d",info->dev_app_ver);
|
||||
DBG_SYS_Printf("EE DevNameLen:%d",info->dev_name_len);
|
||||
DBG_SYS_Printf("EE DevName:%s",info->dev_name);
|
||||
|
||||
return 0x00;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0x01;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : EEPROM_WriteMCUDevInfo
|
||||
* Description : <20><><EFBFBD>豸<EFBFBD><E8B1B8>Ϣд<CFA2>뵽EEPROM<4F><4D>
|
||||
*******************************************************************************/
|
||||
uint8_t EEPROM_WriteMCUDevInfo(E_MCU_DEV_INFO *info)
|
||||
{
|
||||
uint8_t save_data[EEPROM_DATA_Size_Max + 6];
|
||||
uint16_t save_len = sizeof(E_MCU_DEV_INFO);
|
||||
|
||||
if(save_len >= EEPROM_DATA_Size_Max) save_len = EEPROM_DATA_Size_Max;
|
||||
|
||||
save_data[0] = EEPROM_SVAE_FLAG;
|
||||
save_data[1] = save_len & 0xFF;
|
||||
save_data[2] = (save_len >> 8) & 0xFF;
|
||||
|
||||
memcpy(&save_data[4],(uint8_t *)info,save_len);
|
||||
|
||||
save_data[3] = EEPROM_CheckSum(&save_data[4],save_len);
|
||||
|
||||
save_len+=4;
|
||||
|
||||
MCU_EEPROM_Write(save_data,save_len,MCU_EEPROM_MCUDevInfo_Address);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : EEPROM_Default_MCUDevInfo
|
||||
* Description : EEPROM<4F>в<EFBFBD><D0B2><EFBFBD><EFBFBD>ָ<EFBFBD>Ĭ<EFBFBD><C4AC>ֵ<EFBFBD><D6B5><EFBFBD>ҽ<EFBFBD>Ĭ<EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>EEPROM<4F><4D>
|
||||
*******************************************************************************/
|
||||
void EEPROM_Default_MCUDevInfo(E_MCU_DEV_INFO *info)
|
||||
{
|
||||
#if (Project_Area == 0x01)
|
||||
/*Boot <20><><EFBFBD><EFBFBD>*/
|
||||
info->dev_addr = 0x00;
|
||||
info->dev_type = 0x00;
|
||||
info->dev_app_ver = 0x00;
|
||||
info->dev_boot_ver = Project_FW_Version;
|
||||
info->dev_name_len = sizeof(Peoject_Name);
|
||||
|
||||
memset((char *)info->dev_name,0,EEPROM_DEV_NAME_Size);
|
||||
memcpy((char *)info->dev_name,(char *)Peoject_Name,info->dev_name_len);
|
||||
|
||||
//EEPROM_WriteMCUDevInfo(info);
|
||||
#elif (Project_Area == 0x02)
|
||||
/*APP <20><><EFBFBD><EFBFBD>*/
|
||||
info->dev_addr = 0x00;
|
||||
info->dev_type = Project_Type;
|
||||
info->dev_app_ver = Project_FW_Version;
|
||||
info->dev_name_len = sizeof(Peoject_Name);
|
||||
|
||||
memset((char *)info->dev_name,0,EEPROM_DEV_NAME_Size);
|
||||
memcpy((char *)info->dev_name,(char *)Peoject_Name,info->dev_name_len);
|
||||
|
||||
EEPROM_WriteMCUDevInfo(info);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : EEPROM_Validate_MCUDevInfo
|
||||
* Description : У<><D0A3><EFBFBD><EFBFBD>EEPROM <20>ж<EFBFBD>ȡ<EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD>㽫<EFBFBD><E3BDAB>ǰ<EFBFBD><C7B0>ȷ<EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>д<EFBFBD><D0B4>
|
||||
APP<50><50><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3>ж<EFBFBD>APP<50><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD>EEPROM<4F>м<EFBFBD>¼<EFBFBD><C2BC><EFBFBD>Ƿ<EFBFBD>һ<EFBFBD><D2BB>
|
||||
Boot<6F><74><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3>ж<EFBFBD>Boot<6F><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>EEPROM<4F>м<EFBFBD>¼<EFBFBD><C2BC><EFBFBD>Ƿ<EFBFBD>һ<EFBFBD><D2BB>
|
||||
*******************************************************************************/
|
||||
void EEPROM_Validate_MCUDevInfo(E_MCU_DEV_INFO *info)
|
||||
{
|
||||
#if (Project_Area == 0x01)
|
||||
/*Boot <20><><EFBFBD><EFBFBD>*/
|
||||
uint8_t save_flag = 0;
|
||||
|
||||
if(info->dev_boot_ver != Project_FW_Version)
|
||||
{
|
||||
info->dev_boot_ver = Project_FW_Version;
|
||||
save_flag = 0x01;
|
||||
}
|
||||
|
||||
if(save_flag == 0x01)
|
||||
{
|
||||
EEPROM_WriteMCUDevInfo(info);
|
||||
}
|
||||
#elif (Project_Area == 0x02)
|
||||
/*APP <20><><EFBFBD><EFBFBD>*/
|
||||
U8_T save_flag = 0;
|
||||
|
||||
if(info->dev_app_ver != Project_FW_Version)
|
||||
{
|
||||
info->dev_app_ver = Project_FW_Version;
|
||||
save_flag = 0x01;
|
||||
}
|
||||
|
||||
if(info->dev_type != Project_Type)
|
||||
{
|
||||
info->dev_type = Project_Type;
|
||||
save_flag = 0x01;
|
||||
}
|
||||
|
||||
if(info->dev_name_len != sizeof(Peoject_Name))
|
||||
{
|
||||
info->dev_name_len = sizeof(Peoject_Name);
|
||||
save_flag = 0x01;
|
||||
}
|
||||
|
||||
if(strncmp((char *)info->dev_name,(char *)Peoject_Name,sizeof(Peoject_Name)))
|
||||
{
|
||||
memcpy((char *)info->dev_name,(char *)Peoject_Name,info->dev_name_len);
|
||||
save_flag = 0x01;
|
||||
}
|
||||
|
||||
if(save_flag == 0x01)
|
||||
{
|
||||
EEPROM_WriteMCUDevInfo(info);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Read_APP_Feature_Info
|
||||
* Description : <20><>ȡAPP<50><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*******************************************************************************/
|
||||
uint8_t Read_APP_Feature_Info(uint8_t option,G_SYS_FEATURE_T *feature_info)
|
||||
{
|
||||
uint16_t crc_val = 0,crc_val2 = 0;
|
||||
uint32_t temp_val = 0;
|
||||
memset(g_read_buff,0,sizeof(g_read_buff));
|
||||
|
||||
if(option == 0x01){
|
||||
//<2F><>ȡMCU Flash APP<50><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
MCU_APP_Flash_Read(g_read_buff,APP_FEATURE_SIZE,MCU_APP_Feature_Addr);
|
||||
}else if(option == 0x02){
|
||||
//<2F><>ȡ<EFBFBD>ⲿ Flash APP<50><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Flash_Read(g_read_buff,APP_FEATURE_SIZE,SPIFLASH_APP_FEATURE_Addr);
|
||||
}
|
||||
|
||||
Dbg_Print_Buff(DBG_BIT_SYS_STATUS,"APP Feature :",g_read_buff,APP_FEATURE_SIZE);
|
||||
|
||||
crc_val = g_read_buff[1];
|
||||
crc_val <<= 0x08;
|
||||
crc_val |= g_read_buff[0];
|
||||
|
||||
crc_val2 = CRC16_Check(&g_read_buff[2],510);
|
||||
DBG_SYS_Printf("%s CRC: %x - %x",__func__,crc_val,crc_val2);
|
||||
|
||||
if(crc_val == crc_val2)
|
||||
{
|
||||
/*<2A><><EFBFBD><EFBFBD>У<EFBFBD><D0A3>ͨ<EFBFBD><CDA8>*/
|
||||
feature_info->app_flag = g_read_buff[Feature_AppFlag];
|
||||
|
||||
temp_val = g_read_buff[Feature_AppStart + 3];
|
||||
temp_val <<= 8;
|
||||
temp_val |= g_read_buff[Feature_AppStart + 2];
|
||||
temp_val <<= 8;
|
||||
temp_val |= g_read_buff[Feature_AppStart + 1];
|
||||
temp_val <<= 8;
|
||||
temp_val |= g_read_buff[Feature_AppStart];
|
||||
feature_info->app_start_addr = temp_val;
|
||||
|
||||
temp_val = g_read_buff[Feature_AppEnd + 3];
|
||||
temp_val <<= 8;
|
||||
temp_val |= g_read_buff[Feature_AppEnd + 2];
|
||||
temp_val <<= 8;
|
||||
temp_val |= g_read_buff[Feature_AppEnd + 1];
|
||||
temp_val <<= 8;
|
||||
temp_val |= g_read_buff[Feature_AppEnd];
|
||||
feature_info->app_end_addr = temp_val;
|
||||
|
||||
temp_val = g_read_buff[Feature_AppCrcSize + 1];
|
||||
temp_val <<= 8;
|
||||
temp_val |= g_read_buff[Feature_AppCrcSize];
|
||||
feature_info->app_crc_size = temp_val;
|
||||
|
||||
temp_val = g_read_buff[Feature_AppCrcLen + 1];
|
||||
temp_val <<= 8;
|
||||
temp_val |= g_read_buff[Feature_AppCrcLen];
|
||||
feature_info->app_crc_len = temp_val;
|
||||
|
||||
memcpy(feature_info->app_crc,&g_read_buff[Feature_AppFlashCrc],APP_Feature_CRC_Size);
|
||||
|
||||
/*У<><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Χ*/
|
||||
if( ( feature_info->app_start_addr < MCU_APP_Flash_Start_Addr ) || ( feature_info->app_start_addr > MCU_APP_Data_End_Addr ) ){
|
||||
DBG_SYS_Printf("%s app_start_addr:0x%x Error",__func__, feature_info->app_start_addr);
|
||||
return 0x02;
|
||||
}
|
||||
|
||||
if( ( feature_info->app_end_addr > MCU_APP_Data_End_Addr ) || ( feature_info->app_start_addr > feature_info->app_end_addr ) ){
|
||||
DBG_SYS_Printf("%s app_end_addr:0x%x - 0x%x Error",__func__,feature_info->app_start_addr,feature_info->app_end_addr);
|
||||
return 0x02;
|
||||
}
|
||||
|
||||
if( feature_info->app_crc_size != MCU_APP_Flash_PageSize ){
|
||||
DBG_SYS_Printf("%s app_crc_size:%#x Error",__func__,feature_info->app_crc_size);
|
||||
return 0x02;
|
||||
}
|
||||
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
return 0x01;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Write_APP_Feature_Info
|
||||
* Description : д<><D0B4>APP<50><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*******************************************************************************/
|
||||
uint8_t Write_APP_Feature_Info(uint8_t option,G_SYS_FEATURE_T *feature_info)
|
||||
{
|
||||
uint8_t rev = 0;
|
||||
|
||||
memset(g_read_buff,0,sizeof(g_read_buff));
|
||||
memset(g_flash_buff,0,sizeof(g_flash_buff));
|
||||
|
||||
g_flash_buff[Feature_AppFlag] = feature_info->app_flag;
|
||||
|
||||
g_flash_buff[Feature_AppStart] = feature_info->app_start_addr & 0xFF;
|
||||
g_flash_buff[Feature_AppStart + 1] = ( feature_info->app_start_addr >> 8 ) & 0xFF;
|
||||
g_flash_buff[Feature_AppStart + 2] = ( feature_info->app_start_addr >> 16 ) & 0xFF;
|
||||
g_flash_buff[Feature_AppStart + 3] = ( feature_info->app_start_addr >> 24 ) & 0xFF;
|
||||
|
||||
g_flash_buff[Feature_AppEnd] = feature_info->app_end_addr & 0xFF;
|
||||
g_flash_buff[Feature_AppEnd + 1] = ( feature_info->app_end_addr >> 8 ) & 0xFF;
|
||||
g_flash_buff[Feature_AppEnd + 2] = ( feature_info->app_end_addr >> 16 ) & 0xFF;
|
||||
g_flash_buff[Feature_AppEnd + 3] = ( feature_info->app_end_addr >> 24 ) & 0xFF;
|
||||
|
||||
g_flash_buff[Feature_AppCrcSize] = feature_info->app_crc_size & 0xFF;
|
||||
g_flash_buff[Feature_AppCrcSize + 1] = ( feature_info->app_crc_size >> 8 ) & 0xFF;
|
||||
|
||||
g_flash_buff[Feature_AppCrcLen] = feature_info->app_crc_len & 0xFF;
|
||||
g_flash_buff[Feature_AppCrcLen + 1] = ( feature_info->app_crc_len >> 8 ) & 0xFF;
|
||||
|
||||
memcpy(&g_flash_buff[Feature_AppFlashCrc],feature_info->app_crc,APP_Feature_CRC_Size);
|
||||
|
||||
feature_info->crc_check = CRC16_Check(&g_flash_buff[2], 510);
|
||||
|
||||
g_flash_buff[Feature_Check] = feature_info->crc_check & 0xFF;
|
||||
g_flash_buff[Feature_Check + 1] = ( feature_info->crc_check >> 8 ) & 0xFF;
|
||||
|
||||
if(option == 0x01){
|
||||
//<2F><>ȡMCU Flash APP<50><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>СΪ512Byte<74><65>mcu flash ÿ<><C3BF>д<EFBFBD>붼<EFBFBD><EBB6BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 4096byte
|
||||
/*д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - 1<><31><EFBFBD>ȶ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
|
||||
MCU_APP_Flash_Read(g_read_buff,MCU_APP_Flash_PageSize,MCU_APP_Feature_PageAddr);
|
||||
|
||||
memcpy(&g_read_buff[MCU_APP_Feature_PageOffset],g_flash_buff,512);
|
||||
|
||||
/*д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - 2<><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
rev = MCU_APP_Flash_Erase(MCU_APP_Feature_PageAddr,MCU_APP_Flash_PageSize);
|
||||
|
||||
if(rev != 0x00) {
|
||||
DBG_SYS_Printf("MCU_APP_Flash_Erase Fail:%d %x - %x",rev,MCU_APP_Feature_PageAddr,MCU_APP_Flash_PageSize);
|
||||
return 0x01;
|
||||
}
|
||||
|
||||
/*д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - 3<><33>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
rev = MCU_APP_Flash_Write(g_read_buff,MCU_APP_Flash_PageSize,MCU_APP_Feature_PageAddr);
|
||||
|
||||
if(rev != 0x00) {
|
||||
DBG_SYS_Printf("MCU_APP_Flash_Write Fail:%d %#x - %#x",rev,MCU_APP_Feature_PageAddr,MCU_APP_Flash_PageSize);
|
||||
return 0x02;
|
||||
}
|
||||
|
||||
/*д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - 4<><34>У<EFBFBD><D0A3>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
rev = FLASH_ROMA_VERIFY(MCU_APP_Feature_PageAddr,g_read_buff,MCU_APP_Flash_PageSize);
|
||||
if(rev != 0x00) {
|
||||
DBG_SYS_Printf("FLASH_ROMA_VERIFY Fail:%d %#x - %#x",rev,MCU_APP_Feature_PageAddr,MCU_APP_Flash_PageSize);
|
||||
return 0x03;
|
||||
}
|
||||
|
||||
}else if(option == 0x02){
|
||||
//<2F><>ȡ<EFBFBD>ⲿ Flash APP<50><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Dbg_Print_Buff(DBG_BIT_SYS_STATUS,"SPI Flash Para:",g_flash_buff,APP_FEATURE_SIZE);
|
||||
|
||||
Flash_Write(g_flash_buff,APP_FEATURE_SIZE,SPIFLASH_APP_FEATURE_Addr);
|
||||
}
|
||||
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : APP_Feature_Info_Printf
|
||||
* Description : APP<50><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD>ӡ
|
||||
*******************************************************************************/
|
||||
void APP_Feature_Info_Printf(G_SYS_FEATURE_T *feature_info)
|
||||
{
|
||||
DBG_SYS_Printf("Feature crc_check: %x \r\n",feature_info->crc_check);
|
||||
DBG_SYS_Printf("Feature app_flag: %x \r\n",feature_info->app_flag);
|
||||
|
||||
|
||||
DBG_SYS_Printf("Feature app_start_addr: %x \r\n",feature_info->app_start_addr);
|
||||
DBG_SYS_Printf("Feature app_end_addr: %x \r\n",feature_info->app_end_addr);
|
||||
DBG_SYS_Printf("Feature app_crc_len: %d \r\n",feature_info->app_crc_len);
|
||||
Dbg_Print_Buff(DBG_BIT_SYS_STATUS,"Feature app_crc:",feature_info->app_crc,471);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
221
MCU_Driver/rtc.c
Normal file
221
MCU_Driver/rtc.c
Normal file
@@ -0,0 +1,221 @@
|
||||
/*
|
||||
* rtc.c
|
||||
*
|
||||
* Created on: Jul 29, 2025
|
||||
* Author: cc
|
||||
*/
|
||||
#include "includes.h"
|
||||
#include <string.h>
|
||||
|
||||
S_RTC RTC_Raw_Data = {
|
||||
.year = 0,
|
||||
.month = 1,
|
||||
.day = 1,
|
||||
.week = 0,
|
||||
.hour = 0,
|
||||
.minute = 0,
|
||||
.second = 0,
|
||||
};
|
||||
|
||||
S_RTC MCU_RTC_Data = {
|
||||
.year = 0,
|
||||
.month = 1,
|
||||
.day = 1,
|
||||
.week = 0,
|
||||
.hour = 0,
|
||||
.minute = 0,
|
||||
.second = 0,
|
||||
};
|
||||
|
||||
uint32_t Mcu_GetTime_tick = 0;
|
||||
uint32_t Log_Time_ms = 0;
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_Init
|
||||
* Description : RTC<54><43>ʼ<EFBFBD><CABC> - ע<><D7A2>BLV-C1Pû<50><C3BB>RTC<54><43><EFBFBD>ܣ<EFBFBD>ֻ<EFBFBD><D6BB>ʹ<EFBFBD><CAB9>ϵͳ<CFB5><CDB3>ʱ<EFBFBD><CAB1>ģ<EFBFBD><C4A3>RTC<54><43>ʱ
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void RTC_Init(void)
|
||||
{
|
||||
memset(&RTC_Raw_Data,0,sizeof(S_RTC));
|
||||
memset(&MCU_RTC_Data,0,sizeof(S_RTC));
|
||||
|
||||
RTC_Raw_Data.year = 0x00;
|
||||
RTC_Raw_Data.month = 0x01;
|
||||
RTC_Raw_Data.day = 0x01;
|
||||
RTC_Raw_Data.week = 0x00;
|
||||
RTC_Raw_Data.hour = 0x00;
|
||||
RTC_Raw_Data.minute = 0x00;
|
||||
RTC_Raw_Data.second = 0x00;
|
||||
|
||||
MCU_RTC_Data.year = 0x00;
|
||||
MCU_RTC_Data.month = 0x01;
|
||||
MCU_RTC_Data.day = 0x01;
|
||||
MCU_RTC_Data.week = 0x00;
|
||||
MCU_RTC_Data.hour = 0x00;
|
||||
MCU_RTC_Data.minute = 0x00;
|
||||
MCU_RTC_Data.second = 0x00;
|
||||
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : HEX_data_conversion_to_DEC
|
||||
* Description : <20><>ʮ<EFBFBD><CAAE><EFBFBD><EFBFBD><EFBFBD>Ʊ<EFBFBD><C6B1><EFBFBD><EFBFBD><EFBFBD>ʮ<EFBFBD><CAAE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊʵ<CEAA>ʵ<EFBFBD>ʮ<EFBFBD><CAAE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0x20 -> 20
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
uint8_t HEX_Conversion_To_DEC(uint8_t c_num)
|
||||
{
|
||||
uint8_t rev_num = 0;
|
||||
|
||||
rev_num = (c_num/16)*10 + (c_num%16);
|
||||
|
||||
return rev_num;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : HEX_data_conversion_to_DEC
|
||||
* Description : <20><>ʮ<EFBFBD><CAAE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊʮ<CEAA><CAAE><EFBFBD><EFBFBD><EFBFBD>Ʒ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 20 -> 0x20
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
uint8_t DEV_Conversion_To_HEX(uint8_t c_num)
|
||||
{
|
||||
uint8_t rev_num = 0;
|
||||
|
||||
rev_num = (c_num/10)*16 + (c_num%10);
|
||||
|
||||
return rev_num;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_Conversion_To_UTC
|
||||
* Description : <20><>RTCʱ<43><CAB1>ת<EFBFBD><D7AA>ΪUTCʱ<43><CAB1>
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
uint32_t RTC_Conversion_To_Unix(S_RTC *rtc_time)
|
||||
{
|
||||
// uint32_t timestamp = 0;
|
||||
// struct tm test_time;
|
||||
//
|
||||
// test_time.tm_year = HEX_Conversion_To_DEC(rtc_time->year) + 2000 - 1900;
|
||||
// if(rtc_time->month != 0x00)
|
||||
// {
|
||||
// test_time.tm_mon = HEX_Conversion_To_DEC(rtc_time->month) - 1;
|
||||
// }else {
|
||||
// test_time.tm_mon = 1;
|
||||
// }
|
||||
//
|
||||
// test_time.tm_mday = HEX_Conversion_To_DEC(rtc_time->day);
|
||||
// test_time.tm_hour = HEX_Conversion_To_DEC(rtc_time->hour);
|
||||
// test_time.tm_min = HEX_Conversion_To_DEC(rtc_time->minute);
|
||||
// test_time.tm_sec = HEX_Conversion_To_DEC(rtc_time->second);
|
||||
// test_time.tm_isdst = -1;
|
||||
//
|
||||
// timestamp = mktime(&test_time); //<2F><>ת<EFBFBD><D7AA><EFBFBD>ı<EFBFBD>־<EFBFBD><D6BE>UTCʱ<43><CAB1><EFBFBD><EFBFBD>
|
||||
//
|
||||
// /*<2A><><EFBFBD><EFBFBD>ʱ<EFBFBD>仹<EFBFBD><E4BBB9>Ҫ<EFBFBD><D2AA>ȥ8Сʱ*/
|
||||
// timestamp -= 8*3600;
|
||||
//
|
||||
// return timestamp;
|
||||
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : UTC_Conversion_To_RTC
|
||||
* Description : <20><>UTCʱ<43><CAB1>ת<EFBFBD><D7AA>ΪRTCʱ<43><CAB1>
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void Unix_Conversion_To_RTC(S_RTC *rtc_time,uint32_t utc_tick)
|
||||
{
|
||||
// uint8_t temp = 0;
|
||||
// time_t temp_tick = utc_tick + 8*3600; /*<2A><><EFBFBD><EFBFBD>ʱ<EFBFBD>任<EFBFBD><E4BBBB><EFBFBD>ɱ<EFBFBD><EFBFBD><D7BC><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>8Сʱ*/
|
||||
// struct tm *test_time;
|
||||
//
|
||||
// test_time = localtime(&temp_tick);
|
||||
//
|
||||
// temp = ( 1900 + test_time->tm_year ) - 2000;
|
||||
// rtc_time->year = DEV_Conversion_To_HEX(temp);
|
||||
// temp = 1 + test_time->tm_mon;
|
||||
// rtc_time->month = DEV_Conversion_To_HEX(temp);
|
||||
// temp = test_time->tm_mday;
|
||||
// rtc_time->day = DEV_Conversion_To_HEX(temp);
|
||||
//
|
||||
// temp = test_time->tm_hour;
|
||||
// rtc_time->hour = DEV_Conversion_To_HEX(temp);
|
||||
// temp = test_time->tm_min;
|
||||
// rtc_time->minute = DEV_Conversion_To_HEX(temp);
|
||||
// temp = test_time->tm_sec;
|
||||
// rtc_time->second = DEV_Conversion_To_HEX(temp);
|
||||
//
|
||||
// temp = test_time->tm_wday;
|
||||
// rtc_time->week = DEV_Conversion_To_HEX(temp);
|
||||
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_ReadDate
|
||||
* Description : RTCʱ<43><CAB1><EFBFBD><EFBFBD>ȡ - BLV_C1P<31><50>û<EFBFBD><C3BB>RTC<54><43><EFBFBD>ܣ<EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
uint8_t RTC_ReadDate(S_RTC *psRTC)
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ǰʱ<C7B0><CAB1>+<2B><><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD>
|
||||
uint32_t rtc_tick = 0;
|
||||
|
||||
rtc_tick = RTC_Conversion_To_Unix(&MCU_RTC_Data);
|
||||
//rtc_tick += rtc_hour*3600+rtc_min*60+rtc_sec;
|
||||
rtc_tick += SysTick_1s - Mcu_GetTime_tick;
|
||||
Unix_Conversion_To_RTC(psRTC,rtc_tick);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_WriteDate
|
||||
* Description : RTCʱ<43><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - BLV_C1P<31><50>û<EFBFBD><C3BB>RTC<54><43><EFBFBD>ܣ<EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
uint8_t RTC_WriteDate(S_RTC SetRTC)
|
||||
{
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32>Сʱ<D0A1><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD>ʵĵ<CAB5>ǰʱ<C7B0>䣬<EFBFBD><E4A3AC><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
MCU_RTC_Data.year = SetRTC.year;
|
||||
MCU_RTC_Data.month = SetRTC.month;
|
||||
MCU_RTC_Data.day = SetRTC.day;
|
||||
MCU_RTC_Data.hour = SetRTC.hour;
|
||||
MCU_RTC_Data.minute = SetRTC.minute;
|
||||
MCU_RTC_Data.second = SetRTC.second;
|
||||
|
||||
Mcu_GetTime_tick = SysTick_1s; //<2F><>¼<EFBFBD><C2BC>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_TASK
|
||||
* Description : RTC<54><43><EFBFBD><EFBFBD> - BLV_C1P<31><50>û<EFBFBD><C3BB>RTC<54><43><EFBFBD>ܣ<EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void RTC_TASK(void)
|
||||
{
|
||||
static uint32_t RTC_Tick = 0;
|
||||
uint8_t r_minute = 0;
|
||||
if(SysTick_1ms - RTC_Tick >= 1000)
|
||||
{
|
||||
r_minute = RTC_Raw_Data.minute;
|
||||
RTC_Tick = SysTick_1ms;
|
||||
RTC_ReadDate(&RTC_Raw_Data);
|
||||
|
||||
if(r_minute != RTC_Raw_Data.minute)
|
||||
{
|
||||
Log_Time_ms = SysTick_1ms; //ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
202
MCU_Driver/rw_logging.c
Normal file
202
MCU_Driver/rw_logging.c
Normal file
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* rw_logging.c
|
||||
*
|
||||
* Created on: Jul 29, 2025
|
||||
* Author: cc
|
||||
*/
|
||||
#include "includes.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Log_CheckSum
|
||||
* Description : <20><>У<EFBFBD><D0A3>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD>SRAM<41>ж<EFBFBD>ȡ
|
||||
*******************************************************************************/
|
||||
uint8_t Log_CheckSum(uint32_t addr,uint8_t len)
|
||||
{
|
||||
uint8_t data_sum = 0;
|
||||
for(uint8_t i = 0;i<len;i++)
|
||||
{
|
||||
data_sum += SRAM_Read_Byte(addr+i);
|
||||
}
|
||||
return ~data_sum;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Data_CheckSum
|
||||
* Description : <20><>У<EFBFBD><D0A3>ȡ<EFBFBD><C8A1>
|
||||
*******************************************************************************/
|
||||
uint8_t Data_CheckSum(uint8_t* data,uint16_t len)
|
||||
{
|
||||
uint8_t data_sum = 0;
|
||||
for(uint16_t i = 0;i<len;i++)
|
||||
{
|
||||
data_sum += data[i];
|
||||
}
|
||||
return ~data_sum;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Get_Log_Current_Address
|
||||
* Description : <20><>ȡSRAM<41><4D><EFBFBD><EFBFBD>־<EFBFBD><D6BE>ǰд<C7B0><D0B4><EFBFBD><EFBFBD>ַ
|
||||
*******************************************************************************/
|
||||
uint32_t Get_Log_Current_Address(void)
|
||||
{
|
||||
uint32_t rev = 0;
|
||||
uint8_t read_buff[4] = {0};
|
||||
|
||||
SRAM_DMA_Read_Buff(read_buff,0x04,SRAM_LOG_WRITE_Address);
|
||||
|
||||
rev = read_buff[3];
|
||||
rev <<= 8;
|
||||
rev |= read_buff[2];
|
||||
rev <<= 8;
|
||||
rev |= read_buff[1];
|
||||
rev <<= 8;
|
||||
rev |= read_buff[0];
|
||||
|
||||
if((rev < SRAM_LOG_DATA_Address) || (rev > SRAM_LOG_End_Address)) rev = SRAM_LOG_DATA_Address;
|
||||
|
||||
return rev;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Set_Log_Current_Address
|
||||
* Description : <20><><EFBFBD><EFBFBD>SRAM<41><4D><EFBFBD><EFBFBD>־<EFBFBD><D6BE>ǰд<C7B0><D0B4><EFBFBD><EFBFBD>ַ
|
||||
*******************************************************************************/
|
||||
void Set_Log_Current_Address(uint32_t W_addr)
|
||||
{
|
||||
uint32_t Last_addr = W_addr;
|
||||
uint8_t write_buff[4] = {0};
|
||||
|
||||
if((Last_addr < SRAM_LOG_DATA_Address) || (Last_addr > SRAM_LOG_End_Address)) Last_addr = SRAM_LOG_DATA_Address;
|
||||
|
||||
write_buff[0] = (uint8_t)(Last_addr & 0xFF);
|
||||
write_buff[1] = (uint8_t)((Last_addr >> 8) & 0xFF);
|
||||
write_buff[2] = (uint8_t)((Last_addr >> 16) & 0xFF);
|
||||
write_buff[3] = (uint8_t)((Last_addr >> 24) & 0xFF);
|
||||
|
||||
SRAM_DMA_Write_Buff(write_buff,0x04,SRAM_LOG_WRITE_Address);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SRAM_Get_READ_Log_Address
|
||||
* Description : <20><>ȡSRAM<41>е<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>־<EFBFBD><D6BE>ַ
|
||||
*******************************************************************************/
|
||||
uint32_t SRAM_Get_READ_Log_Address(void)
|
||||
{
|
||||
uint32_t rev = 0;
|
||||
uint8_t read_buff[4] = {0};
|
||||
|
||||
SRAM_DMA_Read_Buff(read_buff,0x04,SRAM_LOG_READ_Address);
|
||||
|
||||
rev = read_buff[3];
|
||||
rev <<= 8;
|
||||
rev |= read_buff[2];
|
||||
rev <<= 8;
|
||||
rev |= read_buff[1];
|
||||
rev <<= 8;
|
||||
rev |= read_buff[0];
|
||||
|
||||
if((rev < SRAM_LOG_DATA_Address) || (rev > SRAM_LOG_End_Address)) rev = SRAM_LOG_DATA_Address;
|
||||
|
||||
return rev;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SRAM_Set_READ_LOG_Address
|
||||
* Description : <20><><EFBFBD><EFBFBD>SRAM<41>е<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>־<EFBFBD><D6BE>ַ
|
||||
*******************************************************************************/
|
||||
void SRAM_Set_READ_LOG_Address(uint32_t r_addr)
|
||||
{
|
||||
uint32_t Last_addr = r_addr;
|
||||
uint8_t write_buff[4] = {0};
|
||||
|
||||
if((Last_addr < SRAM_LOG_DATA_Address) || (Last_addr > SRAM_LOG_End_Address)) Last_addr = SRAM_LOG_DATA_Address;
|
||||
|
||||
write_buff[0] = (uint8_t)(Last_addr & 0xFF);
|
||||
write_buff[1] = (uint8_t)((Last_addr >> 8) & 0xFF);
|
||||
write_buff[2] = (uint8_t)((Last_addr >> 16) & 0xFF);
|
||||
write_buff[3] = (uint8_t)((Last_addr >> 24) & 0xFF);
|
||||
|
||||
SRAM_DMA_Write_Buff(write_buff,0x04,SRAM_LOG_READ_Address);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : <20><>־<EFBFBD><D6BE><EFBFBD>湦<EFBFBD><E6B9A6>
|
||||
* Description : <20><>־ÿһ<C3BF><D2BB>Сʱ<D0A1><CAB1>SRAM<41>е<EFBFBD><D0B5><EFBFBD>־<EFBFBD><D6BE><EFBFBD>ݽ<EFBFBD><DDBD>з<EFBFBD>װ<EFBFBD><D7B0>
|
||||
<20><>װ<EFBFBD><D7B0>ֻ<EFBFBD>Ǽ<EFBFBD><C7BC>ϰ<EFBFBD>ͷ<EFBFBD><CDB7>β<EFBFBD><CEB2><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
*******************************************************************************/
|
||||
uint8_t Log_write_sram(uint8_t data_type,uint8_t *buff,uint16_t len)
|
||||
{
|
||||
uint32_t Last_add = 0;
|
||||
uint8_t temp = 0,temp_len = 0,temp_number = 0;
|
||||
uint8_t temp_buff[20] = {0};
|
||||
uint16_t data_len = len,temp_date = 0,write_len = 0;
|
||||
uint32_t Log_Hour_Tick = SysTick_1ms - Log_Time_ms; //2021-09-23 Log_Time_ms<6D>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>н<EFBFBD><D0BD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹȫ<D6B9>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD>while<6C><65>ͬʱ<CDAC><CAB1>д
|
||||
|
||||
Log_Hour_Tick += (uint32_t)HEX_Conversion_To_DEC(RTC_Raw_Data.minute)*60000;
|
||||
Log_Hour_Tick += (uint32_t)HEX_Conversion_To_DEC(RTC_Raw_Data.hour)*3600000;
|
||||
|
||||
if(data_len >= Log_Data_Len_MAX) data_len = Log_Data_Len_MAX; //<2F><EFBFBD><DEB6><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
||||
write_len = S_Log_Data + data_len + 1;
|
||||
|
||||
/*<2A><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>־д<D6BE><D0B4><EFBFBD><EFBFBD>ַ <20><> <20><>־<EFBFBD><D6BE><EFBFBD><EFBFBD>*/
|
||||
SRAM_DMA_Read_Buff(temp_buff,0x0A,SRAM_LOG_WRITE_Address);
|
||||
|
||||
Last_add = temp_buff[3]; //<2F><>ȡ<EFBFBD><C8A1>־д<D6BE><D0B4><EFBFBD><EFBFBD>ַ
|
||||
Last_add <<= 8;
|
||||
Last_add |= temp_buff[2];
|
||||
Last_add <<= 8;
|
||||
Last_add |= temp_buff[1];
|
||||
Last_add <<= 8;
|
||||
Last_add |= temp_buff[0];
|
||||
|
||||
temp_number = temp_buff[8]; //<2F><>ȡ<EFBFBD><C8A1>־<EFBFBD><D6BE><EFBFBD><EFBFBD>
|
||||
|
||||
//<2F><>ǰ<EFBFBD><C7B0>ַ<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD>ҿ<EFBFBD><D2BF>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD><D6BE><EFBFBD><EFBFBD>
|
||||
if((Last_add + write_len) >= SRAM_LOG_End_Address)
|
||||
{
|
||||
Last_add = SRAM_LOG_DATA_Address;
|
||||
}
|
||||
|
||||
/*<2A>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־*/
|
||||
temp_buff[temp_len++] = LOG_Data_Hand; //<2F><><EFBFBD><EFBFBD>ͷ
|
||||
temp_buff[temp_len++] = temp_buff[8]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>к<EFBFBD>
|
||||
temp_buff[temp_len++] = write_len; //<2F><><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD> 2Byte
|
||||
temp_buff[temp_len++] = (write_len >> 8) & 0xFF;
|
||||
temp_buff[temp_len++] = 0x00;
|
||||
temp_date = (HEX_Conversion_To_DEC(RTC_Raw_Data.year) << 10) + (HEX_Conversion_To_DEC(RTC_Raw_Data.month) << 5) + HEX_Conversion_To_DEC(RTC_Raw_Data.day);
|
||||
temp_buff[temp_len++] = (temp_date >> 8) & 0xFF;
|
||||
temp_buff[temp_len++] = temp_date & 0xFF;
|
||||
temp_buff[temp_len++] = data_type;
|
||||
temp_buff[temp_len++] = Log_Hour_Tick & 0xFF;
|
||||
temp_buff[temp_len++] = (Log_Hour_Tick >> 8) & 0xFF;
|
||||
temp_buff[temp_len++] = (Log_Hour_Tick >> 16) & 0xFF;
|
||||
temp_buff[temp_len++] = (Log_Hour_Tick >> 24) & 0xFF;
|
||||
|
||||
SRAM_DMA_Write_Buff(temp_buff,S_Log_Data,Last_add); //<2F><><EFBFBD><EFBFBD>
|
||||
SRAM_DMA_Write_Buff(buff,data_len,Last_add + S_Log_Data); //<2F><><EFBFBD><EFBFBD>
|
||||
SRAM_Write_Byte(Log_Data_End,Last_add + S_Log_Data + data_len); //<2F><><EFBFBD><EFBFBD>β
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3>*/
|
||||
temp = Log_CheckSum(Last_add,write_len);
|
||||
SRAM_Write_Byte(temp,Last_add + S_Log_Check); //У<><D0A3>ֵ
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˢ<EFBFBD><CBA2><EFBFBD><EFBFBD>־д<D6BE><D0B4><EFBFBD><EFBFBD>ַ <20>Լ<EFBFBD><D4BC><EFBFBD>־<EFBFBD><D6BE><EFBFBD><EFBFBD>*/
|
||||
Last_add = Last_add + write_len;
|
||||
Set_Log_Current_Address(Last_add);
|
||||
if(temp_number >= 0xFF)
|
||||
{
|
||||
temp_number = 0x00;
|
||||
}else {
|
||||
temp_number++;
|
||||
}
|
||||
SRAM_Write_Byte(temp_number,SRAM_LOG_Serial_Number); //<2F><><EFBFBD><EFBFBD>β
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
495
MCU_Driver/spi_flash.c
Normal file
495
MCU_Driver/spi_flash.c
Normal file
@@ -0,0 +1,495 @@
|
||||
/*
|
||||
* spi_flash.c
|
||||
*
|
||||
* Created on: May 20, 2025
|
||||
* Author: cc
|
||||
*/
|
||||
|
||||
#include "spi_flash.h"
|
||||
#include "debug.h"
|
||||
|
||||
uint8_t Flash_Buffer[4150]; //FLash д<>뻺<EFBFBD><EBBBBA>BUFF
|
||||
|
||||
void SPI_FLASH_Init(void)
|
||||
{
|
||||
/* SPI Flash <20><> SPI SRAM <20><><EFBFBD><EFBFBD>SPI<50><49><EFBFBD><EFBFBD>
|
||||
* <20><><EFBFBD><EFBFBD> SPI Flash <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ų<EFBFBD>ʼ<EFBFBD><CABC>
|
||||
* */
|
||||
|
||||
DBG_SYS_Printf("SPI Flash ID:0x%x\r\n",Flash_ReadID());
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Flash_ReadSR
|
||||
* Description : P25Q40H Flash<73><68>ȡ״̬<D7B4>Ĵ<EFBFBD><C4B4><EFBFBD>
|
||||
* Input : None
|
||||
* Return : P25Q40H Flash״̬<D7B4>Ĵ<EFBFBD><C4B4><EFBFBD>ֵ
|
||||
BIT7 6 5 4 3 2 1 0
|
||||
SPR0 BP4 BP3 BP2 BP1 BP0 WEL WIP
|
||||
SPR:Ĭ<><C4AC>0,״̬<D7B4>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ,<2C><><EFBFBD><EFBFBD>WPʹ<50><CAB9>
|
||||
BP4,BP3,BP2,BP1,BP0:FLASH<53><48><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
WEL:дʹ<D0B4><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
BUSY:æ<><C3A6><EFBFBD><EFBFBD>λ(1,æ;0,<2C><><EFBFBD><EFBFBD>)
|
||||
Ĭ<><C4AC>:0x00
|
||||
*******************************************************************************/
|
||||
uint8_t Flash_ReadSR(void)
|
||||
{
|
||||
uint8_t byte = 0;
|
||||
Flash_CS_L;
|
||||
SPI0_MasterSendByte(P24Q40H_ReadStatusReg); //<2F><><EFBFBD>Ͷ<EFBFBD>ȡ״̬<D7B4>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
byte = SPI0_MasterRecvByte();
|
||||
Flash_CS_H;
|
||||
return byte;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Flash_WriteSR
|
||||
* Description : P25Q40H Flashд״̬<D7B4>Ĵ<EFBFBD><C4B4><EFBFBD>
|
||||
* Input :
|
||||
sr_val:д<><D0B4>״̬<D7B4>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
BIT7 6 5 4 3 2 1 0
|
||||
SPR0 BP4 BP3 BP2 BP1 BP0 WEL WIP
|
||||
|
||||
ֻ<><D6BB>SPR0,BP3,BP2,BP1,BP0(bit 7,5,4,3,2)<29><><EFBFBD><EFBFBD>д!!!
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void Flash_WriteSR(uint8_t sr_val)
|
||||
{
|
||||
Flash_CS_L;
|
||||
SPI0_MasterSendByte(P24Q40H_WriteStatusReg);
|
||||
SPI0_MasterSendByte(sr_val);
|
||||
Flash_CS_H;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Flash_Write_Enable
|
||||
* Description : P25Q40H дʹ<D0B4><CAB9> -- <20><>WEL<45><4C>λ
|
||||
* Input : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void Flash_Write_Enable(void)
|
||||
{
|
||||
Flash_CS_L;
|
||||
SPI0_MasterSendByte(P24Q40H_WriteEnable);
|
||||
Flash_CS_H;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Flash_Write_Disable
|
||||
* Description : P25Q40H д<><D0B4>ֹ -- <20><>WEL<45><4C><EFBFBD><EFBFBD>
|
||||
* Input : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void Flash_Write_Disable(void)
|
||||
{
|
||||
Flash_CS_L;
|
||||
SPI0_MasterSendByte(P24Q40H_WriteDisable);
|
||||
Flash_CS_H;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Flash_ReadID
|
||||
* Description : P25Q40H Flash <20><>ȡоƬID
|
||||
* Input : None
|
||||
* Return : <20><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>£<EFBFBD>
|
||||
0x8512:<3A><>ʾоƬ<D0BE>ͺ<EFBFBD>ΪP25Q40H
|
||||
0x8511:<3A><>ʾоƬ<D0BE>ͺ<EFBFBD>ΪP25Q20H
|
||||
0x8510:<3A><>ʾоƬ<D0BE>ͺ<EFBFBD>ΪP25Q10H
|
||||
0x8509:<3A><>ʾоƬ<D0BE>ͺ<EFBFBD>ΪP25Q05H
|
||||
*******************************************************************************/
|
||||
uint16_t Flash_ReadID(void)
|
||||
{
|
||||
uint16_t temp=0;
|
||||
Flash_CS_L;
|
||||
SPI0_MasterSendByte(P24Q40H_ReadManufactureID);
|
||||
SPI0_MasterRecvByte();
|
||||
SPI0_MasterRecvByte();
|
||||
SPI0_MasterRecvByte();
|
||||
temp |= SPI0_MasterRecvByte()<<8;
|
||||
temp |= SPI0_MasterRecvByte();
|
||||
Flash_CS_H;
|
||||
return temp;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Flash_Wait_Busy
|
||||
* Description : <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>
|
||||
* Input : None
|
||||
* Return : 1<><31><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD>æ״̬
|
||||
0<><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
||||
*******************************************************************************/
|
||||
uint8_t Flash_Wait_Busy(void)
|
||||
{
|
||||
uint8_t temp=0;
|
||||
uint16_t i=0;
|
||||
temp = Flash_ReadSR();
|
||||
while((temp&0x01)==0x01)
|
||||
{
|
||||
FEED_DOG(); //ι<><CEB9>
|
||||
Delay_Us(100);
|
||||
temp = Flash_ReadSR();
|
||||
i++;
|
||||
if(i>3000) return 1;
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Flash_PowerDown
|
||||
* Description : Flash <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
||||
* Input : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void Flash_PowerDown(void)
|
||||
{
|
||||
Flash_CS_L;
|
||||
SPI0_MasterSendByte(P24Q40H_PowerDown);
|
||||
Delay_Us(3);
|
||||
Flash_CS_H;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Flash_PowerDown
|
||||
* Description : Flash <20><><EFBFBD>ѵ<EFBFBD><D1B5><EFBFBD>ģʽ
|
||||
* Input : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void Flash_Wakeup(void)
|
||||
{
|
||||
Flash_CS_L;
|
||||
SPI0_MasterSendByte(P24Q40H_ReleasePowerDown);
|
||||
Delay_Us(3);
|
||||
Flash_CS_H;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Flash_Erase_Chip
|
||||
* Description : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>оƬ
|
||||
* Input : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void Flash_Erase_Chip(void)
|
||||
{
|
||||
Flash_Write_Enable();
|
||||
Flash_Wait_Busy();
|
||||
Flash_CS_L;
|
||||
SPI0_MasterSendByte(P24Q40H_ChipErase);
|
||||
Flash_CS_H;
|
||||
Flash_Wait_Busy();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Flash_Erase_Block
|
||||
* Description : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* Input : BLK_ID<49><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(0~31) 2M
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void Flash_Erase_Block(uint32_t BLK_ID)
|
||||
{
|
||||
uint8_t flash_buff[5];
|
||||
|
||||
BLK_ID*=0x10000; //64K
|
||||
flash_buff[0] = P24Q40H_BlockErase;
|
||||
flash_buff[1] = (uint8_t)((BLK_ID >> 16) & 0xFF);
|
||||
flash_buff[2] = (uint8_t)((BLK_ID >> 8) & 0xFF);
|
||||
flash_buff[3] = (uint8_t)((BLK_ID) & 0xFF);
|
||||
flash_buff[4] = 0x00;
|
||||
|
||||
Flash_Write_Enable();
|
||||
Flash_Wait_Busy();
|
||||
Flash_CS_L;
|
||||
SPI0_DMATrans(flash_buff,0x04);
|
||||
Flash_CS_H;
|
||||
|
||||
Flash_Wait_Busy();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Flash_Erase_Sector
|
||||
* Description : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* Input : DST_Addr<64><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(0~511) 2M
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void Flash_Erase_Sector(uint32_t DST_ID)
|
||||
{
|
||||
uint8_t flash_buff[5];
|
||||
|
||||
DST_ID*=4096;
|
||||
flash_buff[0] = P24Q40H_SectorErase;
|
||||
flash_buff[1] = (uint8_t)((DST_ID >> 16) & 0xFF);
|
||||
flash_buff[2] = (uint8_t)((DST_ID >> 8) & 0xFF);
|
||||
flash_buff[3] = (uint8_t)((DST_ID) & 0xFF);
|
||||
flash_buff[4] = 0x00;
|
||||
|
||||
Flash_Write_Enable();
|
||||
Flash_Wait_Busy();
|
||||
Flash_CS_L;
|
||||
SPI0_DMATrans(flash_buff,0x04);
|
||||
Flash_CS_H;
|
||||
|
||||
Flash_Wait_Busy();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Flash_Erase_Page
|
||||
* Description : <20><><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3>
|
||||
* Input : Page_ID<49><44>ҳ<EFBFBD><D2B3>(0~8191)
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void Flash_Erase_Page(uint32_t Page_ID)
|
||||
{
|
||||
uint8_t flash_buff[5];
|
||||
|
||||
Page_ID*=256;
|
||||
flash_buff[0] = P24Q40H_PageErase;
|
||||
flash_buff[1] = (uint8_t)((Page_ID >> 16) & 0xFF);
|
||||
flash_buff[2] = (uint8_t)((Page_ID >> 8) & 0xFF);
|
||||
flash_buff[3] = (uint8_t)((Page_ID) & 0xFF);
|
||||
flash_buff[4] = 0x00;
|
||||
|
||||
Flash_Write_Enable();
|
||||
Flash_Wait_Busy();
|
||||
Flash_CS_L;
|
||||
SPI0_DMATrans(flash_buff,0x04);
|
||||
Flash_CS_H;
|
||||
Flash_Wait_Busy();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Flash_Erase_Page
|
||||
* Description : <20><><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3>
|
||||
* Input : Page_addr:<3A><>ַ
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void Flash_Erase_Pageaddr(uint32_t Page_addr)
|
||||
{
|
||||
uint8_t flash_buff[5];
|
||||
|
||||
flash_buff[0] = P24Q40H_PageErase;
|
||||
flash_buff[1] = (uint8_t)((Page_addr >> 16) & 0xFF);
|
||||
flash_buff[2] = (uint8_t)((Page_addr >> 8) & 0xFF);
|
||||
flash_buff[3] = (uint8_t)((Page_addr) & 0xFF);
|
||||
flash_buff[4] = 0x00;
|
||||
|
||||
Flash_Write_Enable();
|
||||
Flash_Wait_Busy();
|
||||
Flash_CS_L;
|
||||
SPI0_DMATrans(flash_buff,0x04);
|
||||
Flash_CS_H;
|
||||
Flash_Wait_Busy();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Flash_Read
|
||||
* Description : P25Q40H Flash ָ<><D6B8><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>ʼ<EFBFBD><CABC>ȡָ<C8A1><D6B8><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
* Input :
|
||||
pBuffer<65><72><EFBFBD><EFBFBD><EFBFBD>ݴ洢<DDB4><E6B4A2>
|
||||
NumByteToRead<61><64>Ҫ<EFBFBD><D2AA>ȡ<EFBFBD><C8A1><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>(<28><><EFBFBD><EFBFBD>65535)
|
||||
ReadAddr<64><72><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>ʼ<EFBFBD><CABC>ַ(24bit)
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void Flash_Read(uint8_t* pBuffer,uint16_t NumByteToRead,uint32_t ReadAddr)
|
||||
{
|
||||
uint8_t flash_buff[5];
|
||||
|
||||
flash_buff[0] = P24Q40H_ReadData;
|
||||
flash_buff[1] = (uint8_t)((ReadAddr >> 16) & 0xFF);
|
||||
flash_buff[2] = (uint8_t)((ReadAddr >> 8) & 0xFF);
|
||||
flash_buff[3] = (uint8_t)((ReadAddr) & 0xFF);
|
||||
flash_buff[4] = 0x00;
|
||||
|
||||
Flash_CS_L;
|
||||
SPI0_DMATrans(flash_buff,0x04);
|
||||
SPI0_DMARecv(pBuffer,NumByteToRead);
|
||||
Flash_CS_H;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Flash_Write_Page
|
||||
* Description : P25Q40H Flash ָ<><D6B8><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>ʼдָ<D0B4><D6B8><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
* Input :
|
||||
pBuffer<65><72><EFBFBD><EFBFBD><EFBFBD>ݴ洢<DDB4><E6B4A2>
|
||||
NumByteToRead<61><64>Ҫд<D2AA><D0B4><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>(<28><><EFBFBD><EFBFBD>256),<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3>ʣ<EFBFBD><CAA3><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>!!!
|
||||
ReadAddr<64><72><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>ʼ<EFBFBD><CABC>ַ(24bit)
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void Flash_Write_Page(uint8_t* pBuffer,uint16_t NumByteToWrite,uint32_t writeAddr)
|
||||
{
|
||||
uint8_t flash_buff[5];
|
||||
|
||||
flash_buff[0] = P24Q40H_PageProgram;
|
||||
flash_buff[1] = (uint8_t)((writeAddr >> 16) & 0xFF);
|
||||
flash_buff[2] = (uint8_t)((writeAddr >> 8) & 0xFF);
|
||||
flash_buff[3] = (uint8_t)((writeAddr) & 0xFF);
|
||||
flash_buff[4] = 0x00;
|
||||
|
||||
Flash_Write_Enable();
|
||||
Flash_CS_L;
|
||||
SPI0_DMATrans(flash_buff,0x04);
|
||||
SPI0_DMATrans(pBuffer,NumByteToWrite);
|
||||
Flash_CS_H;
|
||||
Flash_Wait_Busy();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Flash_Write_NoCheck
|
||||
* Description : <20><EFBFBD><DEBC><EFBFBD>дP25Q40H FLASH
|
||||
ע<EFBFBD>⣺<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD>ĵ<EFBFBD>ַ<EFBFBD><EFBFBD>Χ<EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><EFBFBD>Ϊ0XFF,<2C><><EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD>0XFF<46><46>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD>ʧ<EFBFBD><CAA7>!
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD>
|
||||
<20><>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>ʼд<CABC><D0B4>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>Ҫȷ<D2AA><C8B7><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>Խ<EFBFBD><D4BD>!
|
||||
* Input :
|
||||
pBuffer<65><72><EFBFBD><EFBFBD><EFBFBD>ݴ洢<DDB4><E6B4A2>
|
||||
NumByteToRead<61><64>Ҫд<D2AA><D0B4><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>(<28><><EFBFBD><EFBFBD>65535)
|
||||
ReadAddr<64><72><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>ʼ<EFBFBD><CABC>ַ(24bit)
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void Flash_Write_NoCheck(uint8_t* pBuffer,uint16_t NumByteToWrite,uint32_t writeAddr)
|
||||
{
|
||||
uint16_t pageremain;
|
||||
pageremain=256-writeAddr%256; //<2F><>ҳʣ<D2B3><CAA3><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>
|
||||
if(NumByteToWrite<=pageremain) pageremain=NumByteToWrite;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>256<35><36><EFBFBD>ֽ<EFBFBD>
|
||||
while(1)
|
||||
{
|
||||
FEED_DOG(); //ι<><CEB9>
|
||||
|
||||
Flash_Write_Page(pBuffer,pageremain,writeAddr);
|
||||
if(pageremain == NumByteToWrite) break; //д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
else {
|
||||
pBuffer+=pageremain;
|
||||
writeAddr+=pageremain;
|
||||
|
||||
NumByteToWrite-=pageremain;
|
||||
if(NumByteToWrite>256) pageremain=256;
|
||||
else pageremain=NumByteToWrite;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Flash_Write
|
||||
* Description : <20><EFBFBD><DEBC><EFBFBD>дP25Q40H FLASH
|
||||
ע<EFBFBD>⣺<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD>ĵ<EFBFBD>ַ<EFBFBD><EFBFBD>Χ<EFBFBD>ڵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><EFBFBD>Ϊ0XFF,<2C><><EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD>0XFF<46><46>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD>ʧ<EFBFBD><CAA7>!
|
||||
<20><><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD>
|
||||
<20><>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>ʼд<CABC><D0B4>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>Ҫȷ<D2AA><C8B7><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>Խ<EFBFBD><D4BD>!
|
||||
* Input :
|
||||
pBuffer<65><72><EFBFBD><EFBFBD><EFBFBD>ݴ洢<DDB4><E6B4A2>
|
||||
NumByteToRead<61><64>Ҫд<D2AA><D0B4><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>(<28><><EFBFBD><EFBFBD>65535)
|
||||
ReadAddr<64><72><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>ʼ<EFBFBD><CABC>ַ(24bit)
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void Flash_Write(uint8_t* pBuffer,uint16_t NumByteToWrite,uint32_t WriteAddr)
|
||||
{
|
||||
uint32_t secpos;
|
||||
uint16_t secoff,secremain,i;
|
||||
uint8_t* Write_Buff;
|
||||
|
||||
if(NumByteToWrite <= 256*2)
|
||||
{
|
||||
Write_Buff = Flash_Buffer;
|
||||
|
||||
secpos = WriteAddr/256; //ҳ<><D2B3><EFBFBD><EFBFBD>ַ
|
||||
secoff = WriteAddr%256; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>ƫ<EFBFBD><C6AB>
|
||||
secremain = 256 - secoff; //<2F><><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD>ռ<EFBFBD>
|
||||
|
||||
if(NumByteToWrite<=secremain) secremain = NumByteToWrite; //<2F><>ǰҳ<C7B0><D2B3>ʣ<EFBFBD><CAA3><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>
|
||||
|
||||
while(1)
|
||||
{
|
||||
FEED_DOG(); //ι<><CEB9>
|
||||
|
||||
Flash_Read(Write_Buff,256,secpos*256); //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
for(i=0;i<secremain;i++) //У<><D0A3><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
if(Write_Buff[secoff+i]!=0xFF) break;
|
||||
}
|
||||
|
||||
if(i<secremain) //<2F><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3>
|
||||
{
|
||||
Flash_Erase_Page(secpos); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3>
|
||||
for(i=0;i<secremain;i++) //<2F><><EFBFBD><EFBFBD>
|
||||
{
|
||||
Write_Buff[i+secoff]=pBuffer[i];
|
||||
}
|
||||
Flash_Write_NoCheck(Write_Buff,256,secpos*256); //д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3>
|
||||
}else {
|
||||
if(secremain == 256)
|
||||
{
|
||||
Flash_Write_NoCheck(pBuffer,256,secpos*256); //д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3>
|
||||
|
||||
}else if(secremain < 256){
|
||||
Flash_Write_NoCheck(pBuffer,secremain,WriteAddr); //<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>ӣ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3>
|
||||
}
|
||||
}
|
||||
if(NumByteToWrite == secremain) break; //д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
else //д<><D0B4>δ<EFBFBD><CEB4><EFBFBD><EFBFBD>
|
||||
{
|
||||
secpos++; //ҳ<><D2B3><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>1
|
||||
secoff = 0; //ҳ<><D2B3>ƫ<EFBFBD><C6AB>λ<EFBFBD>ù<EFBFBD><C3B9><EFBFBD>
|
||||
pBuffer += secremain; //<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>ƫ<EFBFBD><C6AB>
|
||||
WriteAddr += secremain; //<2F><><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD><EFBFBD>ַƫ<D6B7><C6AB>
|
||||
NumByteToWrite -= secremain; //ʣ<><CAA3>д<EFBFBD><D0B4><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD>ݼ<EFBFBD>
|
||||
if(NumByteToWrite > 256) secremain = 256; //<2F><>һ<EFBFBD><D2BB>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
|
||||
else secremain = NumByteToWrite; //<2F><>һ<EFBFBD><D2BB>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4>
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Write_Buff = Flash_Buffer;
|
||||
|
||||
secpos = WriteAddr/4096; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
||||
secoff = WriteAddr%4096; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>ƫ<EFBFBD><C6AB>
|
||||
secremain = 4096 - secoff; //<2F><><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD>ռ<EFBFBD>
|
||||
|
||||
if(NumByteToWrite<=secremain) secremain = NumByteToWrite; //<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>
|
||||
|
||||
while(1)
|
||||
{
|
||||
FEED_DOG(); //ι<><CEB9>
|
||||
|
||||
Flash_Read(Write_Buff,2048,secpos*4096); //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Flash_Read(Write_Buff+2048,2048,secpos*4096+2048); //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
for(i=0;i<secremain;i++) //У<><D0A3><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
if(Write_Buff[secoff+i]!=0xFF)break;
|
||||
}
|
||||
|
||||
if(i<secremain) //<2F><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
Flash_Erase_Sector(secpos); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
for(i=0;i<secremain;i++) //<2F><><EFBFBD><EFBFBD>
|
||||
{
|
||||
Write_Buff[i+secoff]=pBuffer[i];
|
||||
}
|
||||
Flash_Write_NoCheck(Write_Buff,2048,secpos*4096); //д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Flash_Write_NoCheck(Write_Buff+2048,2048,secpos*4096+2048); //д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}else {
|
||||
if(secremain == 4096)
|
||||
{
|
||||
Flash_Write_NoCheck(pBuffer,2048,secpos*4096); //д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Flash_Write_NoCheck(pBuffer+2048,2048,secpos*4096+2048); //д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}else if(secremain < 4096){
|
||||
Flash_Write_NoCheck(pBuffer,secremain,WriteAddr); //<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>ӣ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
}
|
||||
if(NumByteToWrite == secremain) break; //д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
else //д<><D0B4>δ<EFBFBD><CEB4><EFBFBD><EFBFBD>
|
||||
{
|
||||
secpos++; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>1
|
||||
secoff = 0; //<2F><><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB>λ<EFBFBD>ù<EFBFBD><C3B9><EFBFBD>
|
||||
pBuffer += secremain; //<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>ƫ<EFBFBD><C6AB>
|
||||
WriteAddr += secremain; //<2F><><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD><EFBFBD>ַƫ<D6B7><C6AB>
|
||||
NumByteToWrite -= secremain; //ʣ<><CAA3>д<EFBFBD><D0B4><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD>ݼ<EFBFBD>
|
||||
if(NumByteToWrite > 4096) secremain = 4096; //<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
|
||||
else secremain = NumByteToWrite; //<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
266
MCU_Driver/spi_sram.c
Normal file
266
MCU_Driver/spi_sram.c
Normal file
@@ -0,0 +1,266 @@
|
||||
/*
|
||||
* spi.c
|
||||
*
|
||||
* Created on: May 16, 2025
|
||||
* Author: cc
|
||||
*/
|
||||
#include "spi_sram.h"
|
||||
#include "debug.h"
|
||||
#include <string.h>
|
||||
|
||||
void SPI_SRAM_Init(void)
|
||||
{
|
||||
GPIOA_ModeCfg(GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_11, GPIO_ModeOut_PP);
|
||||
GPIOA_ModeCfg(GPIO_Pin_5, GPIO_ModeIN_Floating);
|
||||
|
||||
GPIO_PinRemapConfig(GPIO_PartialRemap2_SPI0,ENABLE);
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD>Եó<D4B5><C3B3><EFBFBD><EFBFBD><EFBFBD> SPI<50><49><EFBFBD>߲<EFBFBD><DFB2><EFBFBD><EFBFBD><EFBFBD>30MHZ <20>ֲ<EFBFBD><D6B2><EFBFBD>д<EFBFBD><D0B4>SPI<50><49><EFBFBD><EFBFBD>ͨѶΪ50MHZ 24MHZ*/
|
||||
SPI0_MasterInit(24000000);
|
||||
SPI0_DataMode(Mode0_HighBitINFront);
|
||||
|
||||
SRAM_CE_H;
|
||||
|
||||
/*<2A><>ȡSRAMоƬID*/
|
||||
//SRAM_Read_ID_Opeartion();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SRAM_Write_Byte
|
||||
* Description : SRAMд<4D>ֽ<EFBFBD>
|
||||
* Input :
|
||||
wdate : <20><>Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
||||
add <20><><EFBFBD>ֽ<EFBFBD>д<EFBFBD><D0B4><EFBFBD>ĵ<EFBFBD>ַ
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SRAM_Write_Byte(uint8_t wdate,uint32_t add)
|
||||
{
|
||||
uint8_t Hadd16=0x00,Hadd8=0x00,Ladd=0x00;
|
||||
Ladd=add;
|
||||
Hadd8=add>>8;
|
||||
Hadd16=add>>16;
|
||||
|
||||
if(add >= SRAM_ADDRESS_MAX) return ;
|
||||
|
||||
SRAM_CE_L;
|
||||
SPI0_MasterSendByte(SRAM_CMD_Write);
|
||||
SPI0_MasterSendByte(Hadd16);
|
||||
SPI0_MasterSendByte(Hadd8);
|
||||
SPI0_MasterSendByte(Ladd);
|
||||
SPI0_MasterSendByte(wdate);
|
||||
|
||||
SRAM_CE_H;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SRAM_Read_Byte
|
||||
* Description : SRAM<41><4D><EFBFBD>ֽ<EFBFBD>
|
||||
* Input :
|
||||
add <20><><EFBFBD><EFBFBD>ȡ<EFBFBD>ֽڵĵ<DAB5>ַ
|
||||
* Return : <20><><EFBFBD>ض<EFBFBD>ȡ<EFBFBD>ֽ<EFBFBD>
|
||||
*******************************************************************************/
|
||||
uint8_t SRAM_Read_Byte(uint32_t add)
|
||||
{
|
||||
uint8_t Hadd8=0x00,Hadd16=0x00,Ladd=0x00,rdate=0x00;
|
||||
Ladd=add;
|
||||
Hadd8=add>>8;
|
||||
Hadd16=add>>16;
|
||||
|
||||
if(add >= SRAM_ADDRESS_MAX) return 0x00;
|
||||
|
||||
SRAM_CE_L;
|
||||
SPI0_MasterSendByte(SRAM_CMD_Read);
|
||||
SPI0_MasterSendByte(Hadd16);
|
||||
SPI0_MasterSendByte(Hadd8);
|
||||
SPI0_MasterSendByte(Ladd);
|
||||
rdate = SPI0_MasterRecvByte();
|
||||
SRAM_CE_H;
|
||||
|
||||
return rdate;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SRAM_Write_Word
|
||||
* Description : SRAMдuint16_t<5F><74><EFBFBD><EFBFBD> -- <20><><EFBFBD><EFBFBD>С<EFBFBD><D0A1>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* Input :
|
||||
wdate : <20><>Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
||||
add <20><><EFBFBD>ֽ<EFBFBD>д<EFBFBD><D0B4><EFBFBD>ĵ<EFBFBD>ַ
|
||||
* Return : <20><><EFBFBD>ض<EFBFBD>ȡ<EFBFBD>ֽ<EFBFBD>
|
||||
*******************************************************************************/
|
||||
void SRAM_Write_Word(uint16_t wdate,uint32_t add)
|
||||
{
|
||||
SRAM_Write_Byte((uint8_t)(wdate & 0xFF),add);
|
||||
SRAM_Write_Byte((uint8_t)((wdate >> 8) & 0xFF),add + 1);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SRAM_Read_Word
|
||||
* Description : SRAMдuint16_t<5F><74><EFBFBD><EFBFBD> -- <20><><EFBFBD><EFBFBD>С<EFBFBD><D0A1>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* Input :
|
||||
add <20><><EFBFBD><EFBFBD>ȡ<EFBFBD>ֵĵ<D6B5>ַ
|
||||
* Return : <20><><EFBFBD>ض<EFBFBD>ȡ<EFBFBD><C8A1>
|
||||
*******************************************************************************/
|
||||
uint16_t SRAM_Read_Word(uint32_t add)
|
||||
{
|
||||
uint16_t rev = 0;
|
||||
rev = SRAM_Read_Byte(add + 1);
|
||||
rev <<= 8;
|
||||
rev |= SRAM_Read_Byte(add);
|
||||
return rev;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SRAM_Write_DW
|
||||
* Description : SRAMдuint32_t<5F><74><EFBFBD><EFBFBD> -- <20><><EFBFBD><EFBFBD>С<EFBFBD><D0A1>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* Input :
|
||||
wdate : <20><>Ҫд<D2AA><D0B4><EFBFBD><EFBFBD>˫<EFBFBD><CBAB>
|
||||
add <20><>˫<EFBFBD><CBAB>д<EFBFBD><D0B4><EFBFBD>ĵ<EFBFBD>ַ
|
||||
* Return : <20><><EFBFBD>ض<EFBFBD>ȡ˫<C8A1><CBAB>
|
||||
*******************************************************************************/
|
||||
void SRAM_Write_DW(uint32_t wdate,uint32_t add)
|
||||
{
|
||||
uint8_t write_buff[4] = {0};
|
||||
|
||||
write_buff[0] = (uint8_t)(wdate & 0xFF);
|
||||
write_buff[1] = (uint8_t)((wdate >> 8) & 0xFF);
|
||||
write_buff[2] = (uint8_t)((wdate >> 16) & 0xFF);
|
||||
write_buff[3] = (uint8_t)((wdate >> 24) & 0xFF);
|
||||
|
||||
SRAM_DMA_Write_Buff(write_buff,0x04,add);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SRAM_Read_DW
|
||||
* Description : SRAMдuint32_t<5F><74><EFBFBD><EFBFBD> -- <20><><EFBFBD><EFBFBD>С<EFBFBD><D0A1>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* Input :
|
||||
add <20><><EFBFBD><EFBFBD>ȡ˫<C8A1>ֵĵ<D6B5>ַ
|
||||
* Return : <20><><EFBFBD>ض<EFBFBD>ȡ˫<C8A1><CBAB>
|
||||
*******************************************************************************/
|
||||
uint32_t SRAM_Read_DW(uint32_t add)
|
||||
{
|
||||
uint32_t rev = 0;
|
||||
uint8_t read_buff[4] = {0};
|
||||
|
||||
SRAM_DMA_Read_Buff(read_buff,0x04,add);
|
||||
|
||||
rev = read_buff[3];
|
||||
rev <<= 8;
|
||||
rev |= read_buff[2];
|
||||
rev <<= 8;
|
||||
rev |= read_buff[1];
|
||||
rev <<= 8;
|
||||
rev |= read_buff[0];
|
||||
|
||||
return rev;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SRAM_Read_ID_Opeartion
|
||||
* Description : SRAM <20><>ȡоƬID
|
||||
* Input : NULL
|
||||
* Return : <20><><EFBFBD>ض<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||||
*******************************************************************************/
|
||||
uint8_t SRAM_Read_ID_Opeartion(void)
|
||||
{
|
||||
uint8_t spi_addr[5];
|
||||
uint8_t read_id[9];
|
||||
|
||||
memset(spi_addr,0,0x05);
|
||||
memset(read_id,0,0x04);
|
||||
|
||||
spi_addr[0] = SRAM_CMD_Read_ID;
|
||||
spi_addr[1] = 0x00 ;
|
||||
spi_addr[2] = 0x00 ;
|
||||
spi_addr[3] = 0x00 ;
|
||||
|
||||
SRAM_CE_L;
|
||||
SPI0_DMATrans(spi_addr,0x04);
|
||||
SPI0_DMARecv(read_id,0x08);
|
||||
SRAM_CE_H;
|
||||
|
||||
// Dbg_Println(DBG_BIT_SYS_STATUS_bit, "SRAM MFID:%X",read_id[0]);
|
||||
// if(read_id[1] == 0x5D)
|
||||
// {
|
||||
// Dbg_Println(DBG_BIT_SYS_STATUS_bit, "SRAM KGD:%X - Known Good Die PASS",read_id[1]);
|
||||
// }else {
|
||||
// Dbg_Println(DBG_BIT_SYS_STATUS_bit, "SRAM KGD:%X - Known Good Die FAIL",read_id[1]);
|
||||
// }
|
||||
// Dbg_Print_Buff(DBG_BIT_SYS_STATUS_bit, "SRAM EID:",&read_id[2],0x06);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SRAM_Reset_Operation
|
||||
* Description : SRAM <20><>λ - ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD>λ
|
||||
* Input : NULL
|
||||
* Return : NULL
|
||||
*******************************************************************************/
|
||||
void SRAM_Reset_Operation(void)
|
||||
{
|
||||
SRAM_CE_L;
|
||||
SPI0_MasterSendByte(SRAM_CMD_Reset_Enable);
|
||||
SRAM_CE_H;
|
||||
//Delay_Ms(2);
|
||||
SRAM_CE_L;
|
||||
SPI0_MasterSendByte(SRAM_CMD_Reset);
|
||||
SRAM_CE_H;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SRAM_DMA_Write_Buff
|
||||
* Description : SRAM DMA<4D><41>ʽд<CABD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* Input :
|
||||
wbuff : <20><>Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
len : д<><D0B4><EFBFBD><EFBFBD><EFBFBD>ݵij<DDB5><C4B3><EFBFBD> -- <20><><EFBFBD><EFBFBD>4095<39>ֽڳ<D6BD><DAB3><EFBFBD>
|
||||
add <20><><EFBFBD>ֽ<EFBFBD>д<EFBFBD><D0B4><EFBFBD>ĵ<EFBFBD>ַ
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SRAM_DMA_Write_Buff(uint8_t* wbuff,uint16_t len,uint32_t add)
|
||||
{
|
||||
uint8_t spi_addr[5];
|
||||
|
||||
if(add + len >= SRAM_ADDRESS_MAX) return ;
|
||||
|
||||
memset(spi_addr,0,0x05);
|
||||
|
||||
spi_addr[0] = SRAM_CMD_Write;
|
||||
spi_addr[1] = (add >> 16) & 0xFF ;
|
||||
spi_addr[2] = (add >> 8) & 0xFF ;
|
||||
spi_addr[3] = (add) & 0xFF ;
|
||||
|
||||
SRAM_CE_L;
|
||||
SPI0_DMATrans(spi_addr,0x04);
|
||||
SPI0_DMATrans(wbuff,len);
|
||||
SRAM_CE_H;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : SRAM_DMA_Read_Buff
|
||||
* Description : SRAM DMA<4D><41>ʽ<EFBFBD><CABD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
||||
* Input :
|
||||
rbuff : <20><>Ҫ<EFBFBD><D2AA>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
len : <20><>ȡ<EFBFBD><C8A1><EFBFBD>ݵij<DDB5><C4B3><EFBFBD> -- <20><><EFBFBD><EFBFBD>4095<39>ֽڳ<D6BD><DAB3><EFBFBD>
|
||||
add <20><><EFBFBD>ֽ<EFBFBD>д<EFBFBD><D0B4><EFBFBD>ĵ<EFBFBD>ַ
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void SRAM_DMA_Read_Buff(uint8_t* rbuff,uint16_t len,uint32_t add)
|
||||
{
|
||||
uint8_t spi_addr[5];
|
||||
|
||||
if(add + len >= SRAM_ADDRESS_MAX) return ;
|
||||
|
||||
memset(spi_addr,0,0x05);
|
||||
|
||||
spi_addr[0] = SRAM_CMD_Read;
|
||||
spi_addr[1] = (add >> 16) & 0xFF ;
|
||||
spi_addr[2] = (add >> 8) & 0xFF ;
|
||||
spi_addr[3] = (add) & 0xFF ;
|
||||
|
||||
SRAM_CE_L;
|
||||
SPI0_DMATrans(spi_addr,0x04);
|
||||
SPI0_DMARecv(rbuff,len);
|
||||
SRAM_CE_H;
|
||||
}
|
||||
|
||||
|
||||
51
MCU_Driver/timer.c
Normal file
51
MCU_Driver/timer.c
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* timer.c
|
||||
*
|
||||
* Created on: May 16, 2025
|
||||
* Author: cc
|
||||
*/
|
||||
#include "timer.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
|
||||
void TIMER0_Init(void)
|
||||
{
|
||||
TMR0_DeInit();
|
||||
TMR0_TimerInit(SystemCoreClock / 10000);
|
||||
TMR0_ITCfg(RB_TMR_IF_CYC_END, ENABLE);
|
||||
NVIC_EnableIRQ(TIM0_IRQn);
|
||||
TMR0_Enable();
|
||||
}
|
||||
|
||||
volatile uint32_t Time0_100us = 0;
|
||||
volatile uint32_t Time0_1ms = 0;
|
||||
|
||||
void __attribute__((interrupt("WCH-Interrupt-fast"))) TIM0_IRQHandler()
|
||||
{
|
||||
static uint8_t NUM_1 = 0;
|
||||
|
||||
TMR0_ClearITFlag(RB_TMR_IF_CYC_END);
|
||||
|
||||
Time0_100us++;
|
||||
NUM_1++;
|
||||
|
||||
if(NUM_1 >= 10){
|
||||
NUM_1 = 0;
|
||||
Time0_1ms++;
|
||||
}
|
||||
}
|
||||
|
||||
void Timer0_Task(void)
|
||||
{
|
||||
static uint32_t timer0_tick = 0;
|
||||
|
||||
if(Time0_1ms - timer0_tick >= 1000 ){
|
||||
timer0_tick = Time0_1ms;
|
||||
|
||||
printf("Run:%d ..",timer0_tick);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
732
MCU_Driver/uart.c
Normal file
732
MCU_Driver/uart.c
Normal file
@@ -0,0 +1,732 @@
|
||||
/*
|
||||
* uart.c
|
||||
*
|
||||
* Created on: May 14, 2025
|
||||
* Author: cc
|
||||
*
|
||||
* Ŀǰ<C4BF><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD> RS485<38><35>
|
||||
*
|
||||
* Uart1 -> <20><><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>
|
||||
* Uart0 -> U1 -> RS485 1
|
||||
* UART2 -> U2 -> RS485 2
|
||||
* Uart3 -> U3 -> BUS
|
||||
*
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
UART_t g_uart[UART_MAX];
|
||||
|
||||
void UART0_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
void UART1_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
void UART2_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
void UART3_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
|
||||
/*********************************************************************
|
||||
* @fn UARTx_Init
|
||||
* @brief UART<52><54>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><E2B4AE>2ͨѶ<CDA8><D1B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>PB22,PB23 - Boot,RST<53><54><EFBFBD><EFBFBD>
|
||||
* @param uart_id - <20><><EFBFBD><EFBFBD>ID
|
||||
* @param buad - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param prt_cf - <20><><EFBFBD>ڽ<EFBFBD><DABD>ջص<D5BB><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @return none
|
||||
*/
|
||||
void UARTx_Init(UART_IDX uart_id, uint32_t buad) {
|
||||
|
||||
switch (uart_id) {
|
||||
case UART_0:
|
||||
//RS485ͨѶ<CDA8><D1B6><EFBFBD><EFBFBD>
|
||||
GPIOD_ModeCfg(GPIO_Pin_21, GPIO_ModeOut_PP);
|
||||
MCU485_EN1_L;
|
||||
|
||||
UART0_Reset();
|
||||
|
||||
GPIO_PinRemapConfig(GPIO_NoRemap_UART0,ENABLE);
|
||||
GPIOB_ModeCfg(GPIO_Pin_9, GPIO_ModeOut_PP);
|
||||
GPIOB_ModeCfg(GPIO_Pin_8, GPIO_ModeIN_Floating);
|
||||
|
||||
UART0_BaudRateCfg(buad);
|
||||
R8_UART0_FCR = RB_FCR_FIFO_TRIG | RB_FCR_TX_FIFO_CLR | RB_FCR_RX_FIFO_CLR | RB_FCR_FIFO_EN;
|
||||
// FIFO open, trigger point 14 bytes
|
||||
R8_UART0_LCR = RB_LCR_WORD_SZ;
|
||||
R8_UART0_IER = RB_IER_TXD_EN;
|
||||
|
||||
UART0_CLR_RXFIFO();
|
||||
UART0_CLR_TXFIFO();
|
||||
|
||||
UART0_INTCfg(ENABLE, RB_IER_RECV_RDY | RB_IER_THR_EMPTY);
|
||||
NVIC_EnableIRQ(UART0_IRQn);
|
||||
|
||||
memset(&g_uart[UART_0],0,sizeof(UART_t));
|
||||
Set_Uart_recvTimeout(&g_uart[UART_0],buad);
|
||||
|
||||
g_uart[UART_0].send_data_cf = UART0_SendString;
|
||||
g_uart[UART_0].set_baud_cf = UART0_ChangeBaud;
|
||||
break;
|
||||
case UART_1:
|
||||
UART1_Reset();
|
||||
|
||||
GPIO_PinRemapConfig(GPIO_NoRemap_UART1,ENABLE);
|
||||
GPIOB_ModeCfg(GPIO_Pin_11, GPIO_ModeOut_PP);
|
||||
GPIOB_ModeCfg(GPIO_Pin_10, GPIO_ModeIN_Floating);
|
||||
|
||||
UART1_BaudRateCfg(buad);
|
||||
R8_UART1_FCR = RB_FCR_FIFO_TRIG | RB_FCR_TX_FIFO_CLR | RB_FCR_RX_FIFO_CLR | RB_FCR_FIFO_EN;
|
||||
// FIFO open, trigger point 14 bytes
|
||||
R8_UART1_LCR = RB_LCR_WORD_SZ;
|
||||
R8_UART1_IER = RB_IER_TXD_EN;
|
||||
|
||||
UART1_INTCfg(ENABLE, RB_IER_RECV_RDY | RB_IER_THR_EMPTY);
|
||||
NVIC_EnableIRQ(UART1_IRQn);
|
||||
|
||||
memset(&g_uart[UART_1],0,sizeof(UART_t));
|
||||
Set_Uart_recvTimeout(&g_uart[UART_1],buad);
|
||||
|
||||
g_uart[UART_1].send_data_cf = UART1_SendString;
|
||||
g_uart[UART_1].set_baud_cf = UART1_ChangeBaud;
|
||||
break;
|
||||
case UART_2:
|
||||
//RS485ͨѶ<CDA8><D1B6><EFBFBD><EFBFBD>
|
||||
GPIOB_ModeCfg(GPIO_Pin_15, GPIO_ModeOut_PP);
|
||||
MCU485_EN2_L;
|
||||
|
||||
UART2_Reset();
|
||||
|
||||
GPIO_PinRemapConfig(GPIO_PartialRemap1_UART2,ENABLE);
|
||||
GPIOB_ModeCfg(GPIO_Pin_14, GPIO_ModeOut_PP);
|
||||
GPIOB_ModeCfg(GPIO_Pin_12, GPIO_ModeIN_Floating);
|
||||
|
||||
UART2_BaudRateCfg(buad);
|
||||
R8_UART2_FCR = RB_FCR_FIFO_TRIG | RB_FCR_TX_FIFO_CLR | RB_FCR_RX_FIFO_CLR | RB_FCR_FIFO_EN;
|
||||
// FIFO open, trigger point 14 bytes
|
||||
R8_UART2_LCR = RB_LCR_WORD_SZ;
|
||||
R8_UART2_IER = RB_IER_TXD_EN;
|
||||
|
||||
UART2_INTCfg(ENABLE, RB_IER_RECV_RDY | RB_IER_THR_EMPTY);
|
||||
NVIC_EnableIRQ(UART2_IRQn);
|
||||
|
||||
memset(&g_uart[UART_2],0,sizeof(UART_t));
|
||||
Set_Uart_recvTimeout(&g_uart[UART_2],buad);
|
||||
|
||||
g_uart[UART_2].send_data_cf = UART2_SendString;
|
||||
g_uart[UART_2].set_baud_cf = UART2_ChangeBaud;
|
||||
break;
|
||||
case UART_3:
|
||||
UART3_Reset();
|
||||
|
||||
GPIO_PinRemapConfig(GPIO_PartialRemap1_UART3,ENABLE);
|
||||
GPIOB_ModeCfg(GPIO_Pin_19, GPIO_ModeOut_PP);
|
||||
GPIOB_ModeCfg(GPIO_Pin_18, GPIO_ModeIN_Floating);
|
||||
|
||||
UART3_BaudRateCfg(buad);
|
||||
R8_UART3_FCR = RB_FCR_FIFO_TRIG | RB_FCR_TX_FIFO_CLR | RB_FCR_RX_FIFO_CLR | RB_FCR_FIFO_EN;
|
||||
// FIFO open, trigger point 14 bytes
|
||||
R8_UART3_LCR = RB_LCR_WORD_SZ;
|
||||
R8_UART3_IER = RB_IER_TXD_EN;
|
||||
|
||||
UART3_INTCfg(ENABLE, RB_IER_RECV_RDY | RB_IER_THR_EMPTY);
|
||||
NVIC_EnableIRQ(UART3_IRQn);
|
||||
|
||||
memset(&g_uart[UART_3],0,sizeof(UART_t));
|
||||
Set_Uart_recvTimeout(&g_uart[UART_3],buad);
|
||||
|
||||
g_uart[UART_3].send_data_cf = UART3_SendString;
|
||||
g_uart[UART_3].set_baud_cf = UART3_ChangeBaud;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Set_Uart_recvTimeout(UART_t *set_uart,uint32_t baud)
|
||||
{
|
||||
if(baud == 115200)
|
||||
{
|
||||
set_uart->RecvTimeout = Recv_115200_TimeOut;
|
||||
}else if(baud == 9600)
|
||||
{
|
||||
set_uart->RecvTimeout = Recv_9600_TimeOut;
|
||||
}else if(baud == 2400)
|
||||
{
|
||||
set_uart->RecvTimeout = Recv_2400_TimeOut;
|
||||
}else if(baud == 512000)
|
||||
{
|
||||
set_uart->RecvTimeout = Recv_512000_TimeOut;
|
||||
}else
|
||||
{
|
||||
set_uart->RecvTimeout = 20;
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USART1_IRQHandler
|
||||
*
|
||||
* @brief USART1<54>жϺ<D0B6><CFBA><EFBFBD>
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void UART0_IRQHandler(void)
|
||||
{
|
||||
switch( UART0_GetITFlag() )
|
||||
{
|
||||
case UART_II_THR_EMPTY:
|
||||
|
||||
break;
|
||||
case UART_II_RECV_RDY:
|
||||
case UART_II_RECV_TOUT:
|
||||
if( (g_uart[UART_0].RecvLen + 1) >= USART_BUFFER_SIZE ) g_uart[UART_0].RecvLen = 0x00;
|
||||
g_uart[UART_0].RecvBuffer[g_uart[UART_0].RecvLen] = UART0_RecvByte();
|
||||
g_uart[UART_0].RecvLen += 1;
|
||||
g_uart[UART_0].Receiving = 0x01;
|
||||
g_uart[UART_0].RecvIdleTiming = SysTick_1ms;
|
||||
|
||||
//<2F><>ǰ<EFBFBD><C7B0><EFBFBD>ڷ<EFBFBD>æ״̬
|
||||
g_uart[UART_0].CommBusy |= UART_COMMBUSY_RECV_Flag;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USART1_IRQHandler
|
||||
*
|
||||
* @brief USART1<54>жϺ<D0B6><CFBA><EFBFBD>
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void UART1_IRQHandler(void)
|
||||
{
|
||||
switch( UART1_GetITFlag() )
|
||||
{
|
||||
case UART_II_THR_EMPTY:
|
||||
|
||||
break;
|
||||
case UART_II_RECV_RDY:
|
||||
case UART_II_RECV_TOUT:
|
||||
if( (g_uart[UART_1].RecvLen + 1) >= USART_BUFFER_SIZE ) g_uart[UART_1].RecvLen = 0x00;
|
||||
g_uart[UART_1].RecvBuffer[g_uart[UART_1].RecvLen] = UART1_RecvByte();
|
||||
g_uart[UART_1].RecvLen += 1;
|
||||
g_uart[UART_1].Receiving = 0x01;
|
||||
g_uart[UART_1].RecvIdleTiming = SysTick_1ms;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn UART2_IRQHandler
|
||||
*
|
||||
* @brief USART2<54>жϺ<D0B6><CFBA><EFBFBD>
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void UART2_IRQHandler(void)
|
||||
{
|
||||
switch( UART2_GetITFlag() )
|
||||
{
|
||||
case UART_II_THR_EMPTY:
|
||||
|
||||
break;
|
||||
case UART_II_RECV_RDY:
|
||||
case UART_II_RECV_TOUT:
|
||||
if( (g_uart[UART_2].RecvLen + 1) >= USART_BUFFER_SIZE ) g_uart[UART_2].RecvLen = 0x00;
|
||||
g_uart[UART_2].RecvBuffer[g_uart[UART_2].RecvLen] = UART2_RecvByte();
|
||||
g_uart[UART_2].RecvLen += 1;
|
||||
g_uart[UART_2].Receiving = 0x01;
|
||||
g_uart[UART_2].RecvIdleTiming = SysTick_1ms;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USART3_IRQHandler
|
||||
*
|
||||
* @brief USART3<54>жϺ<D0B6><CFBA><EFBFBD>
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void UART3_IRQHandler(void)
|
||||
{
|
||||
switch( UART3_GetITFlag() )
|
||||
{
|
||||
case UART_II_THR_EMPTY:
|
||||
|
||||
break;
|
||||
case UART_II_RECV_RDY:
|
||||
case UART_II_RECV_TOUT:
|
||||
if( (g_uart[UART_3].RecvLen + 1) >= USART_BUFFER_SIZE ) g_uart[UART_3].RecvLen = 0x00;
|
||||
g_uart[UART_3].RecvBuffer[g_uart[UART_3].RecvLen] = UART3_RecvByte();
|
||||
g_uart[UART_3].RecvLen += 1;
|
||||
g_uart[UART_3].Receiving = 0x01;
|
||||
g_uart[UART_3].RecvIdleTiming = SysTick_1ms;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USART1_RECEIVE
|
||||
*
|
||||
* @brief USART1
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void UART0_RECEIVE(void)
|
||||
{
|
||||
if(g_uart[UART_0].Receiving == 0x01)
|
||||
{
|
||||
if(SysTick_1ms - g_uart[UART_0].RecvIdleTiming >= g_uart[UART_0].RecvTimeout)
|
||||
{
|
||||
g_uart[UART_0].RecvIdleTiming = SysTick_1ms;
|
||||
|
||||
DBG_SYS_Printf("--UART0_RECEIVE--\r\n");
|
||||
Launcher_Uart_Upgrade_Process(&g_uart[UART_0]);
|
||||
|
||||
g_uart[UART_0].RecvLen = 0;
|
||||
g_uart[UART_0].Receiving = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USART1_RECEIVE
|
||||
*
|
||||
* @brief USART1
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void UART1_RECEIVE(void)
|
||||
{
|
||||
if(g_uart[UART_1].Receiving == 0x01)
|
||||
{
|
||||
if(SysTick_1ms - g_uart[UART_1].RecvIdleTiming >= g_uart[UART_1].RecvTimeout)
|
||||
{
|
||||
g_uart[UART_1].RecvIdleTiming = SysTick_1ms;
|
||||
|
||||
DBG_SYS_Printf("--UART1_RECEIVE--\r\n");
|
||||
Launcher_Uart_Upgrade_Process(&g_uart[UART_1]);
|
||||
|
||||
g_uart[UART_1].RecvLen = 0;
|
||||
g_uart[UART_1].Receiving = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* @fn UART2_RECEIVE
|
||||
*
|
||||
* @brief USART2
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void UART2_RECEIVE(void)
|
||||
{
|
||||
if(g_uart[UART_2].Receiving == 1)
|
||||
{
|
||||
if(SysTick_1ms - g_uart[UART_2].RecvIdleTiming > g_uart[UART_2].RecvTimeout)
|
||||
{
|
||||
g_uart[UART_2].RecvIdleTiming = SysTick_1ms;
|
||||
|
||||
DBG_SYS_Printf("--UART2_RECEIVE--\r\n");
|
||||
Launcher_Uart_Upgrade_Process(&g_uart[UART_2]);
|
||||
|
||||
g_uart[UART_2].RecvLen = 0;
|
||||
g_uart[UART_2].Receiving = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* @fn USART3_RECEIVE
|
||||
*
|
||||
* @brief UART3
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void UART3_RECEIVE(void)
|
||||
{
|
||||
if(g_uart[UART_3].Receiving == 1)
|
||||
{
|
||||
if(SysTick_1ms - g_uart[UART_3].RecvIdleTiming > g_uart[UART_3].RecvTimeout)
|
||||
{
|
||||
g_uart[UART_3].RecvIdleTiming = SysTick_1ms;
|
||||
|
||||
DBG_SYS_Printf("--UART3_RECEIVE--\r\n");
|
||||
Launcher_Uart_Upgrade_Process(&g_uart[UART_3]);
|
||||
|
||||
g_uart[UART_3].RecvLen = 0;
|
||||
g_uart[UART_3].Receiving = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn UART0_ChangeBaud
|
||||
*
|
||||
* @brief UART0<54>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
uint8_t UART0_ChangeBaud(uint32_t baudrate)
|
||||
{
|
||||
uint16_t delay_num = 0;
|
||||
|
||||
while(1)
|
||||
{
|
||||
if( UART0_GetLinSTA() & RB_LSR_TX_ALL_EMP )
|
||||
{
|
||||
/*<2A><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>*/
|
||||
__disable_irq();
|
||||
|
||||
UART0_Reset();
|
||||
|
||||
GPIO_PinRemapConfig(GPIO_NoRemap_UART0,ENABLE);
|
||||
GPIOB_ModeCfg(GPIO_Pin_9, GPIO_ModeOut_PP);
|
||||
GPIOB_ModeCfg(GPIO_Pin_8, GPIO_ModeIN_Floating);
|
||||
|
||||
UART0_BaudRateCfg(baudrate);
|
||||
R8_UART0_FCR = RB_FCR_FIFO_TRIG | RB_FCR_TX_FIFO_CLR | RB_FCR_RX_FIFO_CLR | RB_FCR_FIFO_EN;
|
||||
// FIFO open, trigger point 14 bytes
|
||||
R8_UART0_LCR = RB_LCR_WORD_SZ;
|
||||
R8_UART0_IER = RB_IER_TXD_EN;
|
||||
|
||||
UART0_CLR_RXFIFO();
|
||||
UART0_CLR_TXFIFO();
|
||||
|
||||
UART0_INTCfg(ENABLE, RB_IER_RECV_RDY | RB_IER_THR_EMPTY);
|
||||
NVIC_EnableIRQ(UART0_IRQn);
|
||||
|
||||
Set_Uart_recvTimeout(&g_uart[UART_0],baudrate);
|
||||
|
||||
__enable_irq();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Delay_Us(100);
|
||||
delay_num++;
|
||||
if(delay_num > 500) break;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn UART1_ChangeBaud
|
||||
*
|
||||
* @brief UART1<54>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
uint8_t UART1_ChangeBaud(uint32_t baudrate)
|
||||
{
|
||||
uint16_t delay_num = 0;
|
||||
|
||||
while(1)
|
||||
{
|
||||
if( UART0_GetLinSTA() & RB_LSR_TX_ALL_EMP )
|
||||
{
|
||||
/*<2A><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>*/
|
||||
__disable_irq();
|
||||
|
||||
UART1_Reset();
|
||||
|
||||
GPIO_PinRemapConfig(GPIO_NoRemap_UART1,ENABLE);
|
||||
GPIOB_ModeCfg(GPIO_Pin_11, GPIO_ModeOut_PP);
|
||||
GPIOB_ModeCfg(GPIO_Pin_10, GPIO_ModeIN_Floating);
|
||||
|
||||
UART1_BaudRateCfg(baudrate);
|
||||
R8_UART1_FCR = RB_FCR_FIFO_TRIG | RB_FCR_TX_FIFO_CLR | RB_FCR_RX_FIFO_CLR | RB_FCR_FIFO_EN;
|
||||
// FIFO open, trigger point 14 bytes
|
||||
R8_UART1_LCR = RB_LCR_WORD_SZ;
|
||||
R8_UART1_IER = RB_IER_TXD_EN;
|
||||
|
||||
UART1_INTCfg(ENABLE, RB_IER_RECV_RDY | RB_IER_THR_EMPTY);
|
||||
NVIC_EnableIRQ(UART1_IRQn);
|
||||
|
||||
Set_Uart_recvTimeout(&g_uart[UART_1],baudrate);
|
||||
|
||||
__enable_irq();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Delay_Us(100);
|
||||
delay_num++;
|
||||
if(delay_num > 500) break;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn UART2_ChangeBaud
|
||||
*
|
||||
* @brief UART2<54>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
uint8_t UART2_ChangeBaud(uint32_t baudrate)
|
||||
{
|
||||
uint16_t delay_num = 0;
|
||||
|
||||
while(1)
|
||||
{
|
||||
if( UART0_GetLinSTA() & RB_LSR_TX_ALL_EMP )
|
||||
{
|
||||
/*<2A><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>*/
|
||||
__disable_irq();
|
||||
|
||||
UART2_Reset();
|
||||
|
||||
GPIO_PinRemapConfig(GPIO_PartialRemap1_UART2,ENABLE);
|
||||
GPIOB_ModeCfg(GPIO_Pin_14, GPIO_ModeOut_PP);
|
||||
GPIOB_ModeCfg(GPIO_Pin_12, GPIO_ModeIN_Floating);
|
||||
|
||||
UART2_BaudRateCfg(baudrate);
|
||||
R8_UART2_FCR = RB_FCR_FIFO_TRIG | RB_FCR_TX_FIFO_CLR | RB_FCR_RX_FIFO_CLR | RB_FCR_FIFO_EN;
|
||||
// FIFO open, trigger point 14 bytes
|
||||
R8_UART2_LCR = RB_LCR_WORD_SZ;
|
||||
R8_UART2_IER = RB_IER_TXD_EN;
|
||||
|
||||
UART2_INTCfg(ENABLE, RB_IER_RECV_RDY | RB_IER_THR_EMPTY);
|
||||
NVIC_EnableIRQ(UART2_IRQn);
|
||||
|
||||
Set_Uart_recvTimeout(&g_uart[UART_2],baudrate);
|
||||
|
||||
__enable_irq();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Delay_Us(100);
|
||||
delay_num++;
|
||||
if(delay_num > 500) break;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn UART3_ChangeBaud
|
||||
*
|
||||
* @brief UART3<54>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
uint8_t UART3_ChangeBaud(uint32_t baudrate)
|
||||
{
|
||||
uint16_t delay_num = 0;
|
||||
|
||||
while(1)
|
||||
{
|
||||
if( UART0_GetLinSTA() & RB_LSR_TX_ALL_EMP )
|
||||
{
|
||||
/*<2A><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>*/
|
||||
__disable_irq();
|
||||
|
||||
UART3_Reset();
|
||||
|
||||
GPIO_PinRemapConfig(GPIO_PartialRemap1_UART3,ENABLE);
|
||||
GPIOB_ModeCfg(GPIO_Pin_19, GPIO_ModeOut_PP);
|
||||
GPIOB_ModeCfg(GPIO_Pin_18, GPIO_ModeIN_Floating);
|
||||
|
||||
UART3_BaudRateCfg(baudrate);
|
||||
R8_UART3_FCR = RB_FCR_FIFO_TRIG | RB_FCR_TX_FIFO_CLR | RB_FCR_RX_FIFO_CLR | RB_FCR_FIFO_EN;
|
||||
// FIFO open, trigger point 14 bytes
|
||||
R8_UART3_LCR = RB_LCR_WORD_SZ;
|
||||
R8_UART3_IER = RB_IER_TXD_EN;
|
||||
|
||||
UART3_INTCfg(ENABLE, RB_IER_RECV_RDY | RB_IER_THR_EMPTY);
|
||||
NVIC_EnableIRQ(UART3_IRQn);
|
||||
|
||||
Set_Uart_recvTimeout(&g_uart[UART_3],baudrate);
|
||||
|
||||
__enable_irq();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Delay_Us(100);
|
||||
delay_num++;
|
||||
if(delay_num > 500) break;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* RS485ͨѶ<CDA8><D1B6><EFBFBD>ϼ<EFBFBD><CFBC><EFBFBD>
|
||||
* 1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݺȴ<F3A3ACB5><C8B4><EFBFBD><EFBFBD>߿<EFBFBD><DFBF><EFBFBD>(<28><><EFBFBD>ݲ<EFBFBD>ͬ<EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3>ȴ<EFBFBD>ʱ<EFBFBD>䲻ͬ),<2C>ȴ<EFBFBD><C8B4><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߿<EFBFBD><DFBF><EFBFBD>
|
||||
* 2<><32><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ݺȴ<F3A3ACB5><C8B4><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><CFA3><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>״̬
|
||||
* 3<><33><EFBFBD><EFBFBD><EFBFBD>߿<EFBFBD><DFBF>пɽ<D0BF><C9BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><DDB7>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD>߷<EFBFBD>æ<EFBFBD><C3A6><EFBFBD><EFBFBD><EFBFBD>ɷ<EFBFBD><C9B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* 4<><34><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><DDB7><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD>ڷ<EFBFBD><DAB7>ͣ<EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>¼<EFBFBD><C2BC>ǰʱ<C7B0>䣬<EFBFBD><E4A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>ں<DABA><F3A3ACB8><EFBFBD><EFBFBD>ݱ㲻<DDB1>ڷ<EFBFBD><DAB7><EFBFBD>
|
||||
* 5<><35><EFBFBD><EFBFBD>ͨѶ<CDA8><D1B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD><C9BA><EFBFBD><EFBFBD>л<EFBFBD>ͨѶ<CDA8><D1B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*
|
||||
* - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* - 1<><31><EFBFBD><EFBFBD>æ״̬
|
||||
* - 2<><32><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
||||
* - 3<><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чʱ<D0A7><CAB1>
|
||||
*
|
||||
* */
|
||||
|
||||
uint8_t MCU485_SendString_1(uint8_t *buff, uint16_t len)
|
||||
{
|
||||
uint32_t delay_num = 0;
|
||||
MCU485_EN1_H;
|
||||
|
||||
UART0_SendString(buff,len);
|
||||
|
||||
//<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - 50ms
|
||||
while(1)
|
||||
{
|
||||
if((R8_UART0_LSR & RB_LSR_TX_ALL_EMP)) break;
|
||||
Delay_Us(1);
|
||||
delay_num++;
|
||||
if(delay_num > 50000) break;
|
||||
}
|
||||
|
||||
MCU485_EN1_L;
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
uint8_t MCU485_SendString_2(uint8_t *buff, uint16_t len)
|
||||
{
|
||||
uint32_t delay_num = 0;
|
||||
MCU485_EN2_H;
|
||||
|
||||
UART2_SendString(buff,len);
|
||||
|
||||
//<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - 50ms
|
||||
while(1)
|
||||
{
|
||||
if((R8_UART2_LSR & RB_LSR_TX_ALL_EMP)) break;
|
||||
Delay_Us(1);
|
||||
delay_num++;
|
||||
if(delay_num > 50000) break;
|
||||
}
|
||||
|
||||
MCU485_EN2_L;
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Uart0_Add_Data_To_SendBuff
|
||||
* Description : Uart0 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뷢<EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD>
|
||||
* Input :
|
||||
buff<66><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
len<65><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
||||
sendCount <20><><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CDB4><EFBFBD>
|
||||
ValidDuration <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чʱ<D0A7>䣬<EFBFBD><E4A3AC>λ<EFBFBD><CEBB>ms
|
||||
sendInterval <20><><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>ʱ<EFBFBD>䣬<EFBFBD><E4A3AC>λ<EFBFBD><CEBB>ms
|
||||
*******************************************************************************/
|
||||
uint8_t Uart0_Add_Data_To_SendBuff(uint8_t *buff,uint16_t len,uint8_t sendCount,uint32_t ValidDuration,uint32_t sendInterval)
|
||||
{
|
||||
if( buff == NULL) return 0x01;
|
||||
if( len > USART_BUFFER_SIZE ) return 0x02;
|
||||
|
||||
memset(g_uart[UART_0].SendBuffer,0,USART_BUFFER_SIZE);
|
||||
memcpy(g_uart[UART_0].SendBuffer,buff,len);
|
||||
g_uart[UART_0].SendLen = len;
|
||||
g_uart[UART_0].SendCount = sendCount;
|
||||
g_uart[UART_0].SendCnt = 0;
|
||||
g_uart[UART_0].SendValidDuration = ValidDuration;
|
||||
g_uart[UART_0].SendInterval = sendInterval;
|
||||
g_uart[UART_0].SendValidTick = SysTick_1ms;
|
||||
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Uart0_Clear_SendBuff
|
||||
* Description : Uart0 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬʱȡ<CAB1><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*******************************************************************************/
|
||||
uint8_t Uart0_Clear_SendBuff(void)
|
||||
{
|
||||
memset(g_uart[UART_0].SendBuffer,0,USART_BUFFER_SIZE);
|
||||
g_uart[UART_0].SendLen = 0x00;
|
||||
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : Uart0_Avoid_Conflict_Send_Task
|
||||
* Description : Uart0 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*******************************************************************************/
|
||||
uint8_t Uart0_Avoid_Conflict_Send_Task(void)
|
||||
{
|
||||
if( (g_uart[UART_0].SendLen == 0x00) || (g_uart[UART_0].SendLen > USART_BUFFER_SIZE) ) return 0x01;
|
||||
|
||||
if( g_uart[UART_0].SendCnt >= g_uart[UART_0].SendCount ) {
|
||||
//<2F><><EFBFBD>ʹ<EFBFBD><CDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ﵽ<EFBFBD><EFB5BD><EFBFBD>ޣ<EFBFBD><DEA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><DDB7><EFBFBD>
|
||||
g_uart[UART_0].SendLen = 0x00;
|
||||
return 0x02;
|
||||
}
|
||||
|
||||
if( SysTick_1ms - g_uart[UART_0].SendValidTick >= g_uart[UART_0].SendInterval ){
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD>Ч<EFBFBD>ڣ<EFBFBD><DAA3>㲻<EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><DDB7><EFBFBD>
|
||||
g_uart[UART_0].SendLen = 0x00;
|
||||
return 0x03;
|
||||
}
|
||||
|
||||
if( g_uart[UART_0].CommBusy != UART_COMMBUSY_IDLE_Flag ) return 0x04; //ͨѶ<CDA8><D1B6><EFBFBD>ڷ<EFBFBD>æ״̬
|
||||
|
||||
//<2F><><EFBFBD>ݷ<EFBFBD><DDB7><EFBFBD>
|
||||
if( ( g_uart[UART_0].SendCnt == 0x00 ) || ( SysTick_1ms - g_uart[UART_0].SendTick >= g_uart[UART_0].SendInterval ) )
|
||||
{
|
||||
__disable_irq(); //<2F>ر<EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD>ж<EFBFBD>
|
||||
g_uart[UART_0].CommBusy |= UART_COMMBUSY_SEND_Flag;
|
||||
g_uart[UART_0].SendIdleTick = SysTick_1ms;
|
||||
__enable_irq(); //<2F><><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD>ж<EFBFBD>
|
||||
|
||||
UART0_SendString(g_uart[UART_0].SendBuffer, g_uart[UART_0].SendLen);
|
||||
g_uart[UART_0].SendTick = SysTick_1ms;
|
||||
g_uart[UART_0].SendCnt++;
|
||||
|
||||
if( g_uart[UART_0].SendCnt >= g_uart[UART_0].SendCount )
|
||||
{
|
||||
memset(g_uart[UART_0].SendBuffer,0,USART_BUFFER_SIZE);
|
||||
g_uart[UART_0].SendLen = 0x00;
|
||||
|
||||
return 0x05; //ͨѶ<CDA8><D1B6><EFBFBD><EFBFBD>
|
||||
}
|
||||
}
|
||||
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
void Uart0_Task(void)
|
||||
{
|
||||
UART0_RECEIVE();
|
||||
|
||||
Uart0_Avoid_Conflict_Send_Task();
|
||||
|
||||
if( g_uart[UART_0].CommBusy == UART_COMMBUSY_IDLE_Flag )
|
||||
{
|
||||
/*<2A><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߿<EFBFBD><DFBF><EFBFBD>״̬ - <20><><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʲ<EFBFBD><CAB2><EFBFBD>*/
|
||||
if( g_uart[UART_0].ChangeBaudFlag == 0x01 )
|
||||
{
|
||||
g_uart[UART_0].set_baud_cf(g_uart[UART_0].CommBaud);
|
||||
g_uart[UART_0].ChangeBaudFlag = 0x00;
|
||||
}
|
||||
|
||||
}else {
|
||||
/*<2A><>ǰ<EFBFBD><C7B0><EFBFBD>ڷ<EFBFBD><DAB7>ͷ<EFBFBD>æ״̬<D7B4><CCAC><EFBFBD>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>߿<EFBFBD><DFBF><EFBFBD>״̬ - <20>ж<EFBFBD>ʹ<EFBFBD>ó<EFBFBD>ʱʱ<CAB1><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ճ<EFBFBD>ʱʱ<CAB1><CAB1>һ<EFBFBD><D2BB>*/
|
||||
if( ((g_uart[UART_0].CommBusy & UART_COMMBUSY_SEND_Flag) != 0x00 ) && ( SysTick_1ms - g_uart[UART_0].SendIdleTick >= g_uart[UART_0].RecvTimeout ) )
|
||||
{
|
||||
g_uart[UART_0].SendIdleTick = SysTick_1ms;
|
||||
|
||||
__disable_irq(); //<2F>ر<EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD>ж<EFBFBD>
|
||||
g_uart[UART_0].CommBusy &= ~(UART_COMMBUSY_SEND_Flag);
|
||||
g_uart[UART_0].SendIdleTick = SysTick_1ms;
|
||||
__enable_irq(); //<2F><><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD>ж<EFBFBD>
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user