📄 common.h
字号:
// NAME: commom.h
/*
when who what, where, why
-------- -------- ---------------------------------------------------------------
02/18/05 nony.wu Edit code size and all size
============================================================================ */
#ifndef COMM_H_
#define COMM_H_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
//#define diamond_p0
//#define diamond_p1
//#define sapphire
//#define lucas
//#define flying800_p1
//#define flying800_p2
//--------------------------------------------------------------------------------------------------
// CONSTANTS
//--------------------------------------------------------------------------------------------------
// Async HDLC achieves data transparency at the unsigned char level by using two special values.
// The first is a flag value which begins and ends every packet:
#define ASYNC_HDLC_FLAG 0x7e
// The flag value might appear in the data. If it does, it is sent as a two-byte sequence consisting
// of a special escape value followed by the flag value XORed with 0x20. This gives a special meaning
// to the escape character, so if it appears in the data it is itself escaped in the same way.
#define ASYNC_HDLC_ESC 0x7d
#define ASYNC_HDLC_ESC_MASK 0x20
// Maximum size of a received packet. (8K)
#define MAX_PACKET_LEN 0x2000
// Allow this much room for trailing flag
#define ROOM_FOR_FLAG (1)
#define ROOM_FOR_CRC (4)
// Seed value for CRC calculation. The all ones seed is part of CCITT-16, as well as
// allows detection of an entire data stream of zeroes.
#define CRC_16_L_SEED 0xFFFF
#define CRC_16_L_OK_NEG 0xF0B8
#define CODE_BASE 0x0
#define CODE_SIZE 0x700000
#define ALL_SIZE 0x800000 //for k2
//#define CODE_SIZE 0x380000
//#define ALL_SIZE 0x400000 //for ut
#define TAB_OPR ""
#define TAB_SUB_OPR "."
#define TAB_PROMPT ""
//--------------------------------------------------------------------------------------------------
// STRUCTURES AND OTHER TYPEDEFS
//--------------------------------------------------------------------------------------------------
struct pkt_buffer_type
{
unsigned short length; //Length of packet so far
boolean broken; // Set if the packet can't be built
unsigned char buf[MAX_PACKET_LEN]; // The packet under construction
};
//--------------------------------------------------------------------------------------------------
// FUNCTION PROTOTYPES
//--------------------------------------------------------------------------------------------------
void add_byte_to_packet(pkt_buffer_type *pkt, const unsigned char val);
void finish_building_packet(pkt_buffer_type *pkt);
//--------------------------------------------------------------------------------------------------
// MACROS
//--------------------------------------------------------------------------------------------------
// MACRO B_PTR
// MACRO W_PTR
//
// DESCRIPTION
// Casts the address of a specified variable as a pointer to byte/word,allowing byte/word-wise
// access, e.g. W_PTR ( xyz )[ 2 ] = 0x1234; -or- B_PTR ( xyz )[ 2 ] = 0xFF;
//--------------------------------------------------------------------------------------------------
#define B_PTR( var ) ( (byte *) (void *) &(var) )
#define W_PTR( var ) ( (word *) (void *) &(var) )
//--------------------------------------------------------------------------------------------------
// MACRO START_BUILDING_PACKET
//
// DESCRIPTION
// This macro initializes the process of dynamically building a packet.
// PARAMETERS
// pkt A pkt_buffer_type struct in which the packet will be built.
// DEPENDENCIES
// None.
// RETURN VALUE
// None.
// SIDE EFFECTS
// pkt is evaluated twice within this macro.This macro is not an expression, nor is it a single
// statement. It must be called with a trailing semicolon.
//--------------------------------------------------------------------------------------------------
#define START_BUILDING_PACKET(pkt) \
pkt->length = 0; \
pkt->broken = FALSE
//--------------------------------------------------------------------------------------------------
// MACRO ADD_BYTE_TO_PACKET
//
// DESCRIPTION
// This macro adds a single byte to a packet being built dynamically.
//
// PARAMETERS
// pkt A pkt_buffer_type struct in which the packet will be built.
// val The byte to be added to the packet.
//
// DEPENDENCIES
// START_BUILDING_PACKET must have been called on pkt before calling this macro.
//
// RETURN VALUE
// None.
//
// SIDE EFFECTS
// None.
//--------------------------------------------------------------------------------------------------
#define ADD_BYTE_TO_PACKET(pkt,val) \
add_byte_to_packet(pkt, val)
//--------------------------------------------------------------------------------------------------
// MACRO ADD_CRC_TO_PACKET
//
// DESCRIPTION
// This macro adds a word (LEAST significant byte first) to a packet being built dynamically.
// This should only be used for the CRC,since other words are supposed to be sent most significant
// byte first.
//
// PARAMETERS
// pkt A pkt_buffer_type struct in which the packet will be built.
// val The word to be added to the packet.
//
// DEPENDENCIES
// START_BUILDING_PACKET must have been called on pkt before calling this macro.
//
// RETURN VALUE
// None.
//
// SIDE EFFECTS
// Each argument is evaluated twice within this macro.This macro is not an expression, not is it
// a single statement. It must be called with a trailing semicolon.
//--------------------------------------------------------------------------------------------------
#define ADD_CRC_TO_PACKET(pkt,val) \
add_byte_to_packet(pkt, (const unsigned char)(val & 0xFF)); /* low byte */ \
add_byte_to_packet(pkt, (const unsigned char)((val >> 8) & 0xFF)) /* high byte */
//--------------------------------------------------------------------------------------------------
// MACRO FINISH_BUILDING_PACKET
//
// DESCRIPTION
// This macro completes the process of building a packet dynamically.It just calls a function
// to do the work.
//
// PARAMETERS
// pkt A pkt_buffer_type struct in which the packet has been built.
//
// DEPENDENCIES
// START_BUILDING_PACKET must have been called on pkt before calling this macro.
// RETURN VALUE
// None.
//
// SIDE EFFECTS
// None.
//--------------------------------------------------------------------------------------------------
#define FINISH_BUILDING_PACKET(pkt) \
finish_building_packet(pkt)
//--------------------------------------------------------------------------------------------------
// MACRO CRC_16_L_STEP
//
// DESCRIPTION
// This macro calculates one byte step of an LSB-first 16-bit CRC.It can be used to produce a CRC
// and to check a CRC.
//
// PARAMETERS
// xx_crc Current value of the CRC calculation, 16-bits
// xx_c New byte to figure into the CRC, 8-bits
//
// DEPENDENCIES
// None
//
// RETURN VALUE
// The new CRC value, 16-bits. If this macro is being used to check a CRC, and is run over a range
// of bytes, the return value will be equal to CRC_16_L_OK_NEG if the CRC checks correctly according
// to the DMSS Async Download Protocol Spec.
//
// SIDE EFFECTS
// xx_crc is evaluated twice within this macro.
//--------------------------------------------------------------------------------------------------
extern const unsigned short crc_16_l_table[]; // Extern for macro (global)
#define CRC_16_L_STEP(xx_crc,xx_c) \
(((xx_crc) >> 8) ^ crc_16_l_table[((xx_crc) ^ (xx_c)) & 0x00ff])
//--------------------------------------------------------------------------------------------------
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -