stm32_ota/SYSTEM/SYSLIB/syslib.h

82 lines
3.7 KiB
C
Raw Normal View History

2023-12-15 06:28:06 +00:00
#ifndef __SYSLIB_H
#define __SYSLIB_H
#include <stdint.h>
#include <string.h>
#include "stm32f10x.h"
/********************************************************
*<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*********************************************************/
/*<2A><><EFBFBD><EFBFBD>stringfication,<2C><><EFBFBD><EFBFBD><EAB6A8>תΪ<D7AA>ַ<EFBFBD><D6B7><EFBFBD>*/
#define STR1(R) #R //#<23><><EFBFBD><EFBFBD><EFBFBD>Ѳ<EFBFBD><D1B2><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
#define STR2(R) STR1(R) //<2F><><EFBFBD><EFBFBD>stringfication,<2C><><EFBFBD><EFBFBD><EAB6A8>תΪ<D7AA>ַ<EFBFBD><D6B7><EFBFBD>
#define ENUM_CHIP_TYPE_CASE(x) case x: return(#x) ; //#<23><><EFBFBD><EFBFBD><EFBFBD>Ѳ<EFBFBD><D1B2><EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
typedef enum {InParamErr = 0, OutParamErr = 1, RUNERR = 2, RUNOK=3, TIMEOUT=4} RunResult ; //RunResultö<74><C3B6><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD>ٺ<EFBFBD><D9BA><EFBFBD>ִ<EFBFBD>н<EFBFBD><D0BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/**************************************************************************************************
* <EFBFBD><EFBFBD> <EFBFBD>ƣ<EFBFBD> static inline const char *RunResultToString(RunResult result)
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD>ٳ<EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> RunResult<EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ö<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Ϊö<EFBFBD>ٵij<EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD>
**************************************************************************************************/
static inline const char *RunResultToString(RunResult result)
{
switch (result)
{
ENUM_CHIP_TYPE_CASE(InParamErr)
ENUM_CHIP_TYPE_CASE(OutParamErr)
ENUM_CHIP_TYPE_CASE(RUNERR)
ENUM_CHIP_TYPE_CASE(RUNOK)
ENUM_CHIP_TYPE_CASE(TIMEOUT)
}
return "δ֪<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
}
/*<2A><><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
#define MAX_QUEUE_LEN (1024*2) //֡<><D6A1><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>bytes
#define RW_OK 0 //֡<><D6A1><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳɹ<DDB3>
#define FULL_ERROR 1 //֡<><D6A1><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define EMPTY_ERROR 2 //֡<><D6A1><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>
#define HEAD1 0x12 //֡<><D6A1><EFBFBD><EFBFBD>֡ͷ<D6A1><CDB7>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD>
#define HEAD2 0x34 //֡<><D6A1><EFBFBD><EFBFBD>֡ͷ<D6A1>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD>ֽ<EFBFBD>
#define TAIL1 0x56 //֡<><D6A1><EFBFBD><EFBFBD>֡β<D6A1><CEB2>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD>
#define TAIL2 0x78 //֡<><D6A1><EFBFBD><EFBFBD>֡β<D6A1>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD>ֽ<EFBFBD>
/********************************************************
*<EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*********************************************************/
typedef struct
{
volatile uint16_t getIndex ; //֡<><D6A1><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
volatile uint16_t insertIndex ; //֡<><D6A1><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD>дָ<D0B4><D6B8>
volatile uint16_t hasDataLen ; //֡<><D6A1><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
char dataBuf[MAX_QUEUE_LEN];//֡<><D6A1><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
} FrameQueue_s ; //֡<><D6A1><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E1B9B9>
/*****************************************
*<EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
****************************************/
void kmp_next2(const char* _ptn, char* _next) ;
/*****************************************
*<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿں<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
****************************************/
extern void InitQueueMem(FrameQueue_s *sFrame) ; //<2F><><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
extern uint8_t InsertQueueMemData(FrameQueue_s *sFrame, char *data, uint16_t len) ; //<2F><><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
extern uint8_t GetQueueMemData(FrameQueue_s* sFrame, char* data, uint16_t* pLen); //<2F>ӻ<EFBFBD><D3BB>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>һ֡<D2BB><D6A1><EFBFBD><EFBFBD>
extern void SysStrcat(char *dest, uint16_t destSize, char *src) ; //<2F><>destSize<7A><65><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD>src<72><63><EFBFBD><EFBFBD><EFBFBD><EFBFBD>dest<73><74>
extern void CopyStr(char *dest, char *src, char startLot, char endLot, uint16_t maxLen) ; //<2F><>src<72><63>startLot<6F>ַ<EFBFBD><D6B7><EFBFBD>ʼ<EFBFBD><CABC>endLot<6F>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD>dest<73><74>
extern uint16_t CopyValues(uint8_t *dest, uint8_t *src, uint8_t lot, uint16_t maxLen) ; //<2F><>src<72>е<EFBFBD><D0B5><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD>dest<73>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD>lot<6F><74><EFBFBD>߿<EFBFBD><DFBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD>ԼmaxLen<65><6E>ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
extern void HexConvertToString(uint8_t * dest, uint8_t * src, uint16_t length); //hex<65><78><EFBFBD><EFBFBD>ת<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
extern void ByteToHexStr( uint8_t* dest, const uint8_t* src, uint16_t sourceLen) ; //byteת<65>ַ<EFBFBD><D6B7><EFBFBD>
extern int kmp(const char* _str, const char* _ptn) ; //<2F><><EFBFBD><EFBFBD><EFBFBD>Ӵ<EFBFBD>
//extern uint16_t atoi(const char *nptr) ;
extern char *itoa(int value, char *string, int radix) ;
extern char * uitoa(unsigned int value, char *string) ;
#endif