#define CAN_NoError 0 #define CAN_ResetError 5 #define CAN_ConfigError 8 #define CAN_SetACRError 9 #define CAN_SetAMRError 10 #define CAN_SetBaudRateError 11 #define CAN_InstallIrqFailure 14 #define CAN_RemoveIrqFailure 15 #define CAN_TransmitIncomplete 16 #define CAN_TransmitBufferLocked 17 #define CAN_ReceiveBufferEmpty 18 #define CAN_DataOverrun 19 #define CAN_ReceiveError 20 #define CAN_SoftBufferIsEmpty 21 #define CAN_SoftBufferIsFull 22 #define CAN_BaudRateNotSupport 30 #define CAN_DataLengthError 31 #define CAN_NotEnoughMemory 32 #define CAN_AIFreqError 40 #define CAN_AICntError 41 //////////////////////////////////// // CAN chip function // //////////////////////////////////// int I87KCANConfig(void); void CAN_Reset(void); int SetCANBaud(unsigned long Baud, unsigned char BT0, unsigned char BT1); void GetCANBaud(unsigned long *Baud, unsigned char *BT0, unsigned char *BT1); // Baud: 5000UL, 10000UL, 20000UL, 25000UL, 50000UL, 100000UL, // 125000UL, 200000UL, 250000UL, 500000UL, 800000UL, 1000000UL int SetCANMask(unsigned long AccCode, unsigned long AccMask); void GetCANMask(unsigned long *AccCode, unsigned long *AccMask); int SendCANMsg(unsigned char Mode,unsigned long ID, unsigned char RTR, unsigned char DataLen, unsigned char *Data); int GetCANMsg(unsigned char *Mode, unsigned long *ID, unsigned char *RTR, unsigned char *DataLen, unsigned char *Data); int GetCANStatus(void); int RxMsgCount(void); void ClearTxSoftBuffer(void); void ClearRxSoftBuffer(void); //////////////////////////////////// // For user define function // //////////////////////////////////// void UserIrqFunc(char INTT); void UserInitFunc(void); void UserDefCmdFunc(unsigned int CmdLength,char * UserCmd); // Header : "_" // Ender : 0x0d void UserDefBinaryFunc(unsigned int CmdLength,char * UserCmd); // Header : "|" + Length1 Length2 + Data , only header is string and the others are binary. // Example: |0800123456789abcdef0 // --> "|" : is header // --> 0800 : is data length, 08 is LSB and 00 is HSB, so 0800 means data length is 8 bytes // --> 12 34 56 78 9a bc de f0 ==> 8 bytes data void UserLoopFunc(void); /////////////////////////////// // LED function // /////////////////////////////// void L1Off(void); //Error LED void L1On(void); //Error LED void L2Off(void); //Tx/Rx LED void L2On(void); //Tx/Rx LED void L3Off(void); //Power LED void L3On(void); //Power LED ////////////////////////////// // System function // ////////////////////////////// void RefreshWDT(void); /////////////////////////////////// // EEPROM function // /////////////////////////////////// //Valid range from (Block 0, address 0) to (Block 6, address 255) int CM100_EEPROMReadByte(unsigned int Block, unsigned int Address, unsigned char *Data); int CM100_EEPROMReadMultiByte(unsigned int Block, unsigned int Address, char *Data, unsigned int DataNum); int CM100_EEPROMWriteByte(unsigned int Block, unsigned int Address, unsigned char Data); int CM100_EEPROMWriteMultiByte(unsigned int Block, unsigned int Address, char *Data, unsigned int DataNum); //////////////////////////////////////////// // RTC and NVRAM function // //////////////////////////////////////////// void GetTime(int *hour,int *minute,int *sec); int SetTime(int hour,int minute,int sec); void GetDate(int *year,int *month,int *day); int SetDate(int year,int month,int day); int GetWeekDay(void); int ReadNVRAM(int Address); int WriteNVRAM(int Address, int data); /////////////////////////////////////////// // Hex/ASCII convertor // /////////////////////////////////////////// extern char hex_to_ascii[16]; int ascii_to_hex(char ascii); //////////////////////////////////////////// // Timer function // //////////////////////////////////////////// #ifndef _T_STOPWATCH_ #define _T_STOPWATCH_ typedef struct { unsigned long ulStart; //record the start time, unit is ms unsigned long ulPauseTime; //record when the timer is pause, unit is ms unsigned int uMode; // 0: pause, 1:run(start) }STOPWATCH; #endif #ifndef _T_COUNTDOWNTIMER_ #define _T_COUNTDOWNTIMER_ typedef struct { unsigned long ulTime; //record the timer period of count down timer, unit is ms unsigned long ulStartTime; //record the start time, unit is ms unsigned long ulPauseTime; //record when the timer is pause unsigned int uMode; // 0: pause, 1:run(start) }COUNTDOWNTIMER; #endif int TimerOpen(void); int TimerClose(void); void InstallUserTimer(void (*fun)(void)); long GetTimeTicks(void); //unit is ms. This function can't be used in ISR void DelayMs(unsigned int DelayTime_ms); //Delay unit is ms void T_StopWatchStart(STOPWATCH *sw); unsigned long T_StopWatchGetTime(STOPWATCH *sw); void T_StopWatchPause(STOPWATCH *sw); void T_StopWatchContinue(STOPWATCH *sw); void T_CountDownTimerStart(COUNTDOWNTIMER *cdt,unsigned long timems); //timems: unit is ms void T_CountDownTimerPause(COUNTDOWNTIMER *cdt); void T_CountDownTimerContinue(COUNTDOWNTIMER *cdt); int T_CountDownTimerIsTimeUp(COUNTDOWNTIMER *cdt); unsigned long T_CountDownTimerGetTimeLeft(COUNTDOWNTIMER *cdt); /////////////////////////////////// // Debug Port function // /////////////////////////////////// int Kbhit(void); int Print(const char *fmt, ...); int ToComStr_1(char *str); #define ToCom1Str ToComStr_1