static void __CAN_IntInit(uint8_t byCanNo) { //挂中断线 if(byCanNo==0) { //发送中断线 Int_Register(CN_INT_LINE_CAN1_RX0); Int_SetClearType(CN_INT_LINE_CAN1_RX0,CN_INT_CLEAR_AUTO); Int_IsrConnect(CN_INT_LINE_CAN1_RX0,CAN_ISR_Handler); Int_SettoAsynSignal(CN_INT_LINE_CAN1_RX0); Int_ClearLine(CN_INT_LINE_CAN1_RX0); Int_RestoreAsynLine(CN_INT_LINE_CAN1_RX0); //发送中断线 Int_Register(CN_INT_LINE_CAN1_RX1); Int_SetClearType(CN_INT_LINE_CAN1_RX1,CN_INT_CLEAR_AUTO); Int_IsrConnect(CN_INT_LINE_CAN1_RX1,CAN_ISR_Handler); Int_SettoAsynSignal(CN_INT_LINE_CAN1_RX1); Int_ClearLine(CN_INT_LINE_CAN1_RX1); Int_RestoreAsynLine(CN_INT_LINE_CAN1_RX1); //发送中断线 Int_Register(CN_INT_LINE_CAN1_SCE); Int_SetClearType(CN_INT_LINE_CAN1_SCE,CN_INT_CLEAR_AUTO); Int_IsrConnect(CN_INT_LINE_CAN1_SCE,CAN_ISR_Handler); Int_SettoAsynSignal(CN_INT_LINE_CAN1_SCE); Int_ClearLine(CN_INT_LINE_CAN1_SCE); Int_RestoreAsynLine(CN_INT_LINE_CAN1_SCE); } // else // { // //发送中断线 // Int_Register(CN_INT_LINE_CAN2_RX0); // Int_SetClearType(CN_INT_LINE_CAN2_RX0,CN_INT_CLEAR_AUTO); // Int_IsrConnect(CN_INT_LINE_CAN2_RX0,CAN_ISR_Handler); // Int_SettoAsynSignal(CN_INT_LINE_CAN2_RX0); // Int_ClearLine(CN_INT_LINE_CAN2_RX0); // Int_RestoreAsynLine(CN_INT_LINE_CAN2_RX0); // // //发送中断线 // Int_Register(CN_INT_LINE_CAN2_RX1); // Int_SetClearType(CN_INT_LINE_CAN2_RX1,CN_INT_CLEAR_AUTO); // Int_IsrConnect(CN_INT_LINE_CAN2_RX1,CAN_ISR_Handler); // Int_SettoAsynSignal(CN_INT_LINE_CAN2_RX1); // Int_ClearLine(CN_INT_LINE_CAN2_RX1); // Int_RestoreAsynLine(CN_INT_LINE_CAN2_RX1); // // //发送中断线 // Int_Register(CN_INT_LINE_CAN2_SCE); // Int_SetClearType(CN_INT_LINE_CAN2_SCE,CN_INT_CLEAR_AUTO); // Int_IsrConnect(CN_INT_LINE_CAN2_SCE,CAN_ISR_Handler); // Int_SettoAsynSignal(CN_INT_LINE_CAN2_SCE); // Int_ClearLine(CN_INT_LINE_CAN2_SCE); // Int_RestoreAsynLine(CN_INT_LINE_CAN2_SCE); // } }
//----初始化tick--------------------------------------------------------------- //功能: 初始化定时器,并连接tick中断函数,启动定时器. //参数: 无 //返回: 无 //备注: 本函数是移植敏感函数. //----------------------------------------------------------------------------- void __DjyInitTick(void) { Int_IsrConnect(cn_int_line_timer_event,__DjyIsrTick); Int_SettoAsynSignal(cn_int_line_timer_event); //tick中断被设为异步信号 Int_RestoreAsynLine(cn_int_line_timer_event); timeSetEvent(CN_CFG_TICK_US/mS,CN_CFG_TICK_US/mS,&TimerCallBack,0,TIME_PERIODIC); }
void main(int argc, char *argv[]) { MSG msg; LARGE_INTEGER litmp; SetProcessAffinityMask(GetCurrentProcess(), 1); hInstance = GetModuleHandle(NULL); pHeapList.CessionNum = 1; pHeapList.HeapAlign = 0; pHeapList.HeapBottom = DjyosHeap; pHeapList.HeapTop = pHeapList.HeapBottom + sizeof(DjyosHeap); pHeapList.PageSize = 128; strcpy(pHeapList.name,"sys"); pHeapList.name[4] = '\0'; // a = CreateDirectory(_TEXT("djyfs"),NULL); // a = CreateDirectory(_TEXT("djyfs\\sys"),NULL); Heap_StaticModuleInit(0); Int_Init(); QueryPerformanceFrequency(&litmp); s64g_freq = litmp.QuadPart; Int_IsrConnect(cn_int_line_switch_context,switch_context); Int_SettoAsynSignal(cn_int_line_switch_context); //tick中断被设为异步信号 Int_RestoreAsynLine(cn_int_line_switch_context); // printf("VC 编译器版本:%d\n\r",_MSC_VER); Sys_Start(); // 主消息循环: while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return ; }
// ============================================================================= // 功能: 初始化UART对应的中断线,并初始化中断入口函数 // 参数:SerialNo,串口号 // 返回: 无 // ============================================================================= static void __UART_IntInit(u32 SerialNo) { u8 IntLine; if(SerialNo == CN_UART0) IntLine = CN_INT_LINE_UART0_RX_TX; else if(SerialNo == CN_UART1) IntLine = CN_INT_LINE_UART1_RX_TX; else if(SerialNo == CN_UART2) IntLine = CN_INT_LINE_UART2_RX_TX; else if(SerialNo == CN_UART3) IntLine = CN_INT_LINE_UART3_RX_TX; else if(SerialNo == CN_UART4) IntLine = CN_INT_LINE_UART4_RX_TX; else if(SerialNo == CN_UART5) IntLine = CN_INT_LINE_UART5_RX_TX; else return; if(true == Int_Register(IntLine)) { Int_IsrConnect(IntLine,UART_ISR); Int_SetClearType(IntLine,CN_INT_CLEAR_AUTO); Int_SettoAsynSignal(IntLine); Int_ClearLine(IntLine); Int_RestoreAsynLine(IntLine); } }
bool_t debug_dm9000a_write_reg(char *param) { char *word, *next_param; u32 reg = 0; u32 value = 0; // 提取为SOCKET号 if (param) { next_param = param; word = Sh_GetWord(next_param, &next_param); reg = __sh_atol(word); word = Sh_GetWord(next_param, &next_param); value = __sh_atol(word); word = Sh_GetWord(next_param, &next_param); if(word != NULL) { printf("\r\n参数错误\r\n"); return false; } } if (Lock_SempPend(semp_dm9000, 10000*mS) == true) { Int_SaveAsynLine(cn_int_line_enet); // 关闭DM9000A的外部中断 printf("\r\n写入DM9000A的【%4x】寄存器:%4x", reg, value); iow(reg, value); printf("\r\n"); Int_RestoreAsynLine(cn_int_line_enet); // 打开DM9000A的外部中断 Lock_SempPost(semp_dm9000); } return true; }
// ============================================================================= // 功能: IIC中断配置函数 // 参数: IntLine,中断线 // isr,中断服务函数指针 // 返回: 无 // ============================================================================= static void __IIC_IntConfig(u32 IntLine,u32 (*isr)(ufast_t)) { Int_IsrConnect(cn_int_line_TWII,__IIC_ISR); Int_SettoAsynSignal(cn_int_line_TWII); Int_ClearLine(cn_int_line_TWII); //清掉初始化产生的发送fifo空的中断 Int_RestoreAsynLine(cn_int_line_TWII); }
// ============================================================================= // 功能: IIC中断配置函数 // 参数: IntLine,中断线 // isr,中断服务函数指针 // 返回: 无 // ============================================================================= static void __IIC_IntConfig(u32 IntLine,u32 (*isr)(ptu32_t)) { Int_Register(IntLine); Int_IsrConnect(IntLine,isr); Int_SettoAsynSignal(IntLine); Int_ClearLine(IntLine); //清掉初始化产生的发送fifo空的中断 Int_RestoreAsynLine(IntLine); }
// ============================================================================= // 功能: SPI中断配置函数 // 参数: IntLine,中断线 // 返回: 无 // ============================================================================= static void __SPI_IntConfig(u8 IntLine) { //中断线的初始化 Int_Register(IntLine); Int_SetClearType(IntLine,CN_INT_CLEAR_AUTO); Int_IsrConnect(IntLine,SPI_ISR); Int_SettoAsynSignal(IntLine); Int_ClearLine(IntLine); Int_RestoreAsynLine(IntLine); }
// ============================================================================= // 函数功能:module_init_timer // SHARC21469的GP timer初始化 // 输入参数: // 输出参数: // 返回值 : // 说明 : // ============================================================================= void GPTimer_ModuleInit(void) { struct tagTimerChip Sharc21469GPtimer; Int_IsrConnect(cn_int_line_GPTMR0I,__GPTimer0_ISR); Int_SettoAsynSignal(cn_int_line_GPTMR0I); Int_ClearLine(cn_int_line_GPTMR0I); //清掉初始化产生的发送fifo空的中断 Int_RestoreAsynLine(cn_int_line_GPTMR0I); Int_IsrConnect(cn_int_line_GPTMR1I,__GPTimer1_ISR); Int_SettoAsynSignal(cn_int_line_GPTMR1I); Int_ClearLine(cn_int_line_GPTMR1I); //清掉初始化产生的发送fifo空的中断 Int_RestoreAsynLine(cn_int_line_GPTMR1I); *pTM0CTL = TIMODEPWM | PRDCNT | IRQEN; // configure the timer0 *pTM0W = 1; // timer0 width *pTM1CTL = TIMODEPWM | PRDCNT | IRQEN; // configure the timer1 *pTM1W = 1; // timer1 width register Sharc21469GPtimer.chipname = "SHARC21469GPTimer"; Sharc21469GPtimer.timerhardalloc = __GPTimer_Alloc; Sharc21469GPtimer.timerhardfree = __GPTimer_Free; Sharc21469GPtimer.timerhardctrl = __GPTimer_Ctrl; TimerHard_RegisterChip(&Sharc21469GPtimer); // =============下面代码仅做测试使用=================================== /* struct tagGPTimerHandle *testTimer; //step1:分配一个定时器 testTimer=__GPTimer_Alloc(30000000, __GPTimer0_ISR); //step2:设置定时周期 // __GPTimer_SetCycle(testTimer, 30000000); //step3:使能中断 __GPTimer_EnInt(testTimer); //开始计数 __GPTimer_StartCount(testTimer); */ }
// ============================================================================= // 功能: SPI中断配置函数 // 参数: IntLine,中断线 // 返回: 无 // ============================================================================= static void __SPI_IntConfig(void) { u8 IntLine = cn_int_line_espi; //中断线的初始化 Int_Register(IntLine); Int_IsrConnect(IntLine,SPI_ISR); Int_SettoAsynSignal(IntLine); Int_SetLineTrigerType(IntLine,EN_INT_TRIGER_HIGHLEVEL); Int_ClearLine(IntLine); Int_RestoreAsynLine(IntLine); }
//----初始化命令行设备--------------------------------------------------------- //功能: 如名 //参数: 无 //返回: 无意义 //----------------------------------------------------------------------------- ptu32_t ModuleInstall_Cmd(ptu32_t para) { tagDevHandle cmd_dev; pMultiplexCmd = NULL; MplCmdStatus = CN_MULTIPLEX_SENSINGBIT_WRITE;//初始时可写不可读 Ring_Init( &recv_ring_buf, (u8 *)cmd_ptcl_recv_buf, cmd_buf_len); //以下建立windows 终端输入设备 cmd_dev = Driver_DeviceCreate( NULL,"windows_cmd", NULL,NULL, (devWriteFunc) cmd_DriverWrite, (devReadFunc ) cmd_DriverRead, (devCtrlFunc ) cmd_DriverCtrl, cmd_MultiplexAdd, 0 ); if(cmd_dev == NULL) goto exit_from_add_device; // pg_cmd_hdl = Driver_OpenDevice("windows_cmd",O_RDWR,0); //打开右手句柄 Int_IsrConnect(cn_int_line_cmd,cmd_int); Int_SettoAsynSignal(cn_int_line_cmd); Int_RestoreAsynLine(cn_int_line_cmd); win32_scanf = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)win32_scanf_pro, 0, 0, NULL ); SetThreadAffinityMask( win32_scanf, 1 ); hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); hStdIn = GetStdHandle(STD_INPUT_HANDLE); /* hNewScreenBuffer = CreateConsoleScreenBuffer( GENERIC_READ | GENERIC_WRITE, // read/write access FILE_SHARE_READ | FILE_SHARE_WRITE, // shared NULL, // default security attributes CONSOLE_TEXTMODE_BUFFER, // must be TEXTMODE NULL); // reserved; must be NULL SetConsoleActiveScreenBuffer(hNewScreenBuffer); */ return 1; exit_from_add_device: return 0; }
// ============================================================================= // 功能:DM9000中断初始化。DM9000中断引脚接到CPU的GPIO引脚,因此需将该引脚配置为外部 // 中断,并配置触发电平;同时需连接中断线到中断系统 // 参数:无 // 返回值 : // ============================================================================= void DM9000_IntInit(void) { //配置外部引脚EINT7/GPF7 pg_gpio_reg->GPFCON &= ~(3<<14); pg_gpio_reg->GPFCON |= (2<<14); //配置为输入 pg_gpio_reg->EXTINT0 &= ~(7<<28); pg_gpio_reg->EXTINT0 |= (4<<28); //配置上升沿触发 pg_gpio_reg->EINTPEND |= (1<<7); pg_gpio_reg->EINTMASK &= (~(01<<7)); u32 DM9000_ISR_Handler(ufast_t IntLine); //DM9000的中断引脚输出中断信号到CPU的EINT7 Int_IsrConnect(cn_int_line_eint4_7,DM9000_ISR_Handler); Int_SettoAsynSignal(cn_int_line_eint4_7); Int_ClearLine(cn_int_line_eint4_7); Int_RestoreAsynLine(cn_int_line_eint4_7); }
//----初始化uart对应的中断----------------------------------------------------- //功能: 初始化uart对应的中断线,并初始化中断入口函数 //参数:SerialNo,串口号 //返回: 无 //----------------------------------------------------------------------------- void __UART_IntInit(u32 SerialNo) { uint32_t int_line; if(SerialNo == CN_UART0) int_line = CN_INT_LINE_UART0; else if(SerialNo == CN_UART1) int_line = CN_INT_LINE_UART1; else if(SerialNo == CN_USART0) int_line = CN_INT_LINE_USART0; else int_line = CN_INT_LINE_USART1; Int_SetClearType(int_line,CN_INT_CLEAR_PRE); Int_IsrConnect(int_line,UART_ISR); Int_SettoAsynSignal(int_line); Int_ClearLine(int_line); Int_RestoreAsynLine(int_line); }
//----从DM9000A中读出所有数据---------------------------------------------------- //功能:把DM9000A中的所有数据都读取出来,这些数据包会组织在lst链表中。 //参数:lst,数据包的接收链表头指针 //返回:数据包的接收链表头指针(可能与输入的lst不同) //----------------------------------------------------------------------------- struct enet_rcv_packet *__hw_read_in(struct enet_rcv_packet *lst) { u32 tmp; u32 len; u32 totlen = 0; static u32 times = 0; struct enet_rcv_packet *nlst = NULL; // 请求DM9000A硬件操作的信号量,等待5S秒如果没有发出去,则返回 if (Lock_SempPend(semp_dm9000, 0) == true) { // 接收过程中如果有中断发生,中断响应函数读 写DM9000的其他寄存器会打断接收过程。 Int_SaveAsynLine(cn_int_line_enet); // 关闭DM9000A的外部中断 ior(DM9000A_MRCMDX); // dummy read tmp = (u8)DATAR16(); if (tmp == 0x01) // 第一个字节读出为01h { switch (ehi.io) { case ENUM_DM9000A_IO_16BIT: // 16-bit while (tmp == 0x01) { len = dump_data16(lst, &nlst); if (len == -1) { dm9000a_reset_to_new(); totlen = 0; } else { totlen += len; // 试读下一帧数据,若为01h则继续读数,若为0则表示没有有效数据 ADDRW8(DM9000A_MRCMDX); tmp = (u8)DATAR16(); lst = nlst; } } __hw_ctrl(enum_enet_hw_ctrl_clear_rx_int); // 清除接收中断 break; case ENUM_DM9000A_IO_32BIT: // 32-bit break; case ENUM_DM9000A_IO_8BIT: // 8-bit break; default: break; } } else if (tmp != 0) { times++; if (times > 5) { debug_dm9000a_read_reg(NULL); } dm9000a_reset_to_new(); totlen = 0; if (times > 5) { debug_dm9000a_read_reg(NULL); times = 0; } } Int_RestoreAsynLine(cn_int_line_enet); // 打开DM9000A的外部中断 Lock_SempPost(semp_dm9000); } return nlst; }
bool_t debug_dm9000a_read_reg(char *param) { char *word, *next_param; int i; u32 reg = 0xFFFF; // 提取为SOCKET号 if (param) { next_param = param; word = Sh_GetWord(next_param, &next_param); reg = __sh_atol(word); word = Sh_GetWord(next_param, &next_param); if(word != NULL) { printf("\r\n参数错误\r\n"); return false; } } if (Lock_SempPend(semp_dm9000, 10000*mS) == true) { Int_SaveAsynLine(cn_int_line_enet); // 关闭DM9000A的外部中断 if (reg != 0xFFFF) { printf("\r\n读取DM9000A的【%4x】寄存器:", reg); printf("\r\n %4x:%4x", reg, ior(reg)); } else { printf("\r\n读取DM9000A的【所有】寄存器:"); printf("\r\n"); for (i=0; i<=0x1f; i++) { printf("\r\n %4x:%4x", i, ior(i)); } printf("\r\n"); for (i=0x22; i<=0x25; i++) { printf("\r\n %4x:%4x", i, ior(i)); } printf("\r\n"); for (i=0x28; i<=0x34; i++) { printf("\r\n %4x:%4x", i, ior(i)); } printf("\r\n"); i = 0x38; printf("\r\n %4x:%4x", i, ior(i)); i = 0x39; printf("\r\n %4x:%4x", i, ior(i)); printf("\r\n"); i = 0x50; printf("\r\n %4x:%4x", i, ior(i)); i = 0x51; printf("\r\n %4x:%4x", i, ior(i)); printf("\r\n"); i = 0xF0; printf("\r\n %4x:%4x", i, ior(i)); i = 0xF1; printf("\r\n %4x:%4x", i, ior(i)); i = 0xF2; printf("\r\n %4x:%4x", i, ior(i)); i = 0xF4; printf("\r\n %4x:%4x", i, ior(i)); i = 0xF5; printf("\r\n %4x:%4x", i, ior(i)); i = 0xF6; printf("\r\n %4x:%4x", i, ior(i)); i = 0xF8; printf("\r\n %4x:%4x", i, ior(i)); printf("\r\n"); for (i=0xFA; i<=0xFF; i++) { printf("\r\n %4x:%4x", i, ior(i)); } } printf("\r\n"); Int_RestoreAsynLine(cn_int_line_enet); // 打开DM9000A的外部中断 Lock_SempPost(semp_dm9000); } return true; }
int main( void ) { /****************UART SET*******************/ *pPICR2 &= ~(0x1F); //Sets the UART0 receive interrupt to P12 *pPICR2 |= (0x13<<0); initPLL_DDR2(); *pUART0LCR=0; *pUART0IER = UARTRBFIE; // enables UART0 receive interrupt /****************SYS INIT*******************/ initDPI(); initUART(); Init_LEDs(); Init_PushButtons(); sysreg_bit_clr(sysreg_MODE1, IRPTEN ); /* disable global interrupts */ /* unmask individual interrupts */ (*pDAI_IRPTL_PRI) = (SRU_EXTMISCA1_INT | SRU_EXTMISCA2_INT); /* make sure interrupts latch on the rising edge */ (*pDAI_IRPTL_RE) = (SRU_EXTMISCA1_INT | SRU_EXTMISCA2_INT); /* setup the IRQ pins to use the pushbuttons */ (*pSYSCTL) |= (IRQ1EN | IRQ2EN); sysreg_bit_set(sysreg_MODE2, (IRQ1E | IRQ2E) ); /* enable IRQ interrupts and make DAI interrupts high priority */ sysreg_bit_set(sysreg_IMASK, (IRQ1I | IRQ2I | DAIHI) ); sysreg_bit_clr(sysreg_IMASKP, (IRQ1I | IRQ2I | DAIHI) ); sysreg_bit_set(sysreg_LIRPTL, P12IMSK ); sysreg_bit_clr(sysreg_LIRPTL, P12IMSKP ); sysreg_bit_clr(sysreg_IRPTL, (IRQ1I | IRQ2I) ); sysreg_bit_clr(sysreg_LIRPTL, P12I ); /* register the interrut handlers */ Int_Init(); Int_IsrConnect(cn_int_line_IRQ2I,SW9_IRQ2_handler); Int_RestoreRealLine(cn_int_line_IRQ2I); Int_IsrConnect(cn_int_line_IRQ1I,SW8_IRQ1_handler); Int_RestoreAsynLine(cn_int_line_IRQ1I); Int_IsrConnect(cn_int_line_DAII,__int_engine_dai); Int_RestoreAsynLine(cn_int_line_DAII); Int_IsrConnect(cn_int_line_P12I,UARTisr); Int_RestoreAsynLine(cn_int_line_P12I); Int_CutTrunk(); Int_ContactTrunk(); sysreg_bit_clr(sysreg_IRPTL, (IRQ1I | IRQ2I) ); NOP;NOP; sysreg_bit_clr(sysreg_LIRPTL, P12I ); NOP;NOP; sysreg_bit_set(sysreg_MODE1, NESTM ); /* enable interrupts nest */ sysreg_bit_set(sysreg_MODE1, IRPTEN ); /* enable global interrupts */ // 测试通过 // atom_high_test=Int_HighAtomStart(); // Int_HighAtomEnd(atom_high_test); // atom_low_test=Int_LowAtomStart(); // Int_LowAtomEnd(atom_low_test); // 测试通过 Int_TapLine(cn_int_line_IRQ2I); // Int_TapLine(cn_int_line_DAII); // Int_TapLine(cn_int_line_P12I); Int_TapLine(cn_int_line_IRQ1I); // 测试通过 // bool_value=Int_QueryLine(cn_int_line_IRQ2I); // bool_value=Int_QueryLine(cn_int_line_IRQ1I); // bool_value=Int_QueryLine(cn_int_line_DAII); // bool_value=Int_QueryLine(cn_int_line_P12I); // 测试通过 // Int_CutLine(cn_int_line_SFT3I); // Int_CutLine(cn_int_line_P17I); // Int_CutLine(cn_int_line_IRQ2I); /****************UART TEST******************/ xmitUARTmessage(welcomemessage,sizeof(welcomemessage)); xmitUARTmessage("CYG Copyright \n\r",sizeof("CYG Copyright \n\r")); while(1) { Blink_LED(10000000); // Int_TapLine(cn_int_line_IRQ2I); // xmitUARTmessage("CYG Copyright \n\r",sizeof("CYG Copyright \n\r")); // Int_TapLine(cn_int_line_DAII); } /* Begin adding your custom code here */ return 0; }