/////////////////////////////////////////////////////////////// // I-87120 firmware demo2 -- Use interrupt function // /////////////////////////////////////////////////////////////// #include "..\..\c87s110.h" #include #include #include unsigned char InterruptFlag=0; void UserIrqFunc(char INTT) { int ret; unsigned char Mode,RTR,DataLen,Data[8]; unsigned long ID; // If CPU is interrupted by the CAN controller, the function will be excuted if (INTT & 0x01){ ret = GetCANMsg(&Mode,&ID,&RTR,&DataLen,Data); if(!ret){ if((!Mode)&&(ID == 0x123)){ if(Data[0]&0x01) InterruptFlag = 1; } } } } void UserInitFunc(void) { int ret; // The function will be excuted first after I-87120 is power on ret = SetCANBaud(1000000UL, 0, 0); // Set CAN Baud to 1M bps if(ret) ToCom1Str(">SetCANBaudFaile\r"); ret = SetCANMask(0x00000000, 0xFFFFFFFF); // Set CAN Mask if(ret) ToCom1Str(">SetCANMaskFaile\r"); } void UserDefCmdFunc(unsigned int CmdLength, char * UserCmd) { // Process user-defined command, the UserCmd[0] must be '_' if (CmdLength); switch (UserCmd[1]){ } } void UserDefBinaryFunc(unsigned int CmdLength, char * UserCmd) { // Process user-defined command for binary code, the UserCmd[0] must be '|' if (CmdLength); switch (UserCmd[1]){ } } void UserLoopFunc(void) { int ret; unsigned char data[8]; unsigned char Mode,RTR,DataLen,Data[8]; unsigned long ID; // The function will be excuted in while loop after the I-87120 has be configured if(InterruptFlag){ InterruptFlag = 0; data[0]=0x11; data[1]=0x22; data[2]=0x33; data[3]=0x44; data[4]=0x55; data[5]=0x66; data[6]=0x77; data[7]=0x88; ret=SendCANMsg(0,0x321,0,8,data); if(ret) ToCom1Str(">SendFaile\r"); } }