/** ****************************************************************************** ** \brief Init DTIF callback function ** ** \return none ******************************************************************************/ static void DtifIntCallback(void) { if(GetKeyInput() == PdlHigh) { Mft_Wfg_Nzcl_ClrDigitalFilterIrqFlag(&USER_WFG); //Clear Flag m_u8Ocu0IntFlag = 0; m_u8Ocu1IntFlag = 0; // De-initialize FRT, OCU DeInitFrt(); DeInitOcu(); //re-initialize FRT, OCU InitFrt(); InitOcu(); //re-start FRT, OCU Mft_Ocu_EnableOperation(&USER_OCU,USER_OCU_CH0); Mft_Ocu_EnableOperation(&USER_OCU,USER_OCU_CH1); Mft_Frt_Start(&USER_FRT,USER_MFT_FRT_CH); } return; }
/******************************************************************** 函数名称: TransmitSja 函数功能: CAN总线发送测试 参数名称 类型 输入/输出 含义 返回值 : 0代表成功 非0代表失败 函数说明: 循环发送需要加延时 修改记录: 2012-12-06 王鹤翔 创建 2013-01-09 王鹤翔 修改 根据新版驱动重新编写 2016-04-14 王 明 修改 根据修改后的驱动修改部分函数名称,添加标准帧发送 ********************************************************************/ int TransmitSja(void) { int RunTimes = 0; int i = 0; int ret = 0; sja1000_frame_t frame; int fd = 0; int FrameFormat = 0; /* 清零发送数据 */ memset(frame, 0, sizeof(sja1000_frame_t)); /* 指定发送CAN口 */ printf("Input Transmit CAN Number(0-%d: CAN1-can%d):\n", MAX_SJA_NUM - 1, MAX_SJA_NUM); fd = GetKeyInput(10) % MAX_SJA_NUM; /* 输入发送次数 */ printf("CAN Test, Input Transmit Count(1-10000):\n"); RunTimes = GetKeyInput(10) % 10000; printf("CAN Test, Input Transmit frame format (0:Standard frame 1:Extended frame):\n"); FrameFormat = GetKeyInput(10) % 2; if(FrameFormat == 0) /* 标准帧,注意标准帧最长11字节,ID一共11位 */ { /* header */ frame.header = 0x08; /* ID */ frame.buffer[0] = 0x00; /* ID */ frame.buffer[1] = 0x00; /* ID 高3位有效 */ /* DATA */ frame.buffer[2] = 0x33; frame.buffer[3] = 0x40; frame.buffer[4] = 0x55; frame.buffer[5] = 0x66; frame.buffer[6] = 0x77; } else if(FrameFormat == 1) /* 扩展帧,注意扩展帧最长13字节,ID一共29位*/ { /* header */ frame.header = 0x88; /* ID */ frame.buffer[0] = 0x11; /* ID */ frame.buffer[1] = 0x22; /* ID */ frame.buffer[2] = 0x33; /* ID */ frame.buffer[3] = 0x40; /* ID 高5位有效 */ /* DATA */ frame.buffer[4] = 0x55; frame.buffer[5] = 0x66; frame.buffer[6] = 0x77; frame.buffer[7] = 0x88; frame.buffer[8] = 0x99; } for (i = 0; i < RunTimes; i++) { if(FrameFormat == 0) { frame.buffer[7] = i; } else { frame.buffer[9] = i; } ret |= WriteIsaCan(fd, &frame); if(ret != SUCCESS) { printf("can%d send failed! ret = %d, i = %d\n", fd, ret, i); return ret; } g_transmit_counts[fd] += 1; taskDelay(sysClkRateGet() / 2); /* 这里需要加延时,否则芯片会一直产生接收中断 */ } return ret; }
/******************************************************************** 函数名称: TestSja 函数功能: 测试程序主函数 参数名称 类型 输入/输出 含义 返回值 : 根据实际情况自行定义 函数说明: 主函数先打开驱动程序,然后提供用户人机交互界面 并根据用户选择进行不同的功能测试,具体的测试功能由单独的函数实现 修改记录: 2012-12-06 王鹤翔 创建 2016-04-14 王 明 修改 根据修改后的驱动修改部分函数名称 ********************************************************************/ int TestSja(void) { int input = 0; int ret = 0; int i = 0; int recv_tid[CURRENT_SJA_NUM] = {0}; memset(g_received_counts, 0, sizeof(g_received_counts)); memset(g_transmit_counts, 0, sizeof(g_transmit_counts)); /* 初始化SJA1000芯片 */ for (i = 0; i < CURRENT_SJA_NUM; i++) { ret = InitSja(i, BAUDRATE_500K); if (ret != 0) { printf("InitSja failed!%d\n", ret); continue ; } } /* 创建接收任务 */ for(i = 0; i < CURRENT_SJA_NUM; i++) { recv_tid[i] = taskSpawn("tCanRecv", 98, 0, 8192, tCanRecv, i, 0, 0, 0, 0, 0, 0, 0, 0, 0); } printf("\nISA Sja1000 Test Program\n"); /* 打印菜单 */ for(input = 100;;) { switch(input) { case 98: g_csd_debug = !g_csd_debug; break; case 99: printf("Exit Program, exit code = %d\n", CloseSja()); goto Exit; case 1: printf("return = %d\n", TransmitSja()); break; case 2: /* 显示接收计数 */ for (i = 0; i < MAX_SJA_NUM; i++) { printf("R%d=%11d ", i, g_received_counts[i]); } printf("\n"); for (i = 0; i < MAX_SJA_NUM; i++) { printf("T%d=%11d ", i, g_transmit_counts[i]); } printf("\n"); break; case 3: /* 清除计数 */ for (i = 0; i < MAX_SJA_NUM; i++) { g_received_counts[i] = 0; g_transmit_counts[i] = 0; /* 清除FIFO */ ret = FlushIsaCan(i); if (ret != 0) { printf("channel %d FlushIsaCan failed!%d\n", i, ret); } } printf("Counts are clean.\n"); break; default: printf("1. Transmit data\n" "2. Dispaly Counts\n" "3. Clear counts\n" "98. Swtich debug onoff (debug = %d 0:off 1:on)\n" "99. Quit\n", g_csd_debug); } /* end switch */ printf("%d\n", input = GetKeyInput(10)); } /* end for */ Exit: /* 删除接收任务 */ for(i = 0; i < CURRENT_SJA_NUM; i++) { CloseSja(i); taskDelete(recv_tid[i]); } return 0; }