//----初始化命令行设备--------------------------------------------------------- //功能: 如名 //参数: 无 //返回: 无意义 //----------------------------------------------------------------------------- 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; }
/******************************************************************************* 功能:CAN设备的初始化函数,初始化中断控制器,申请内存,初始化器件。 参数:byIndex--CAN控制器编号,0~1. 输出:true--初始化成功,false-初始化失败。 说明: *********************************************************************************/ bool_t CAN_Hard_Init(uint8_t byCanNo,uint32_t baudrate,CanFilterConfPara \ * pFilterConfPara) { tagCanReg *pCan; static uint8_t flag=0; uint32_t i=0; CAN_DevCtrl *CAN_DevCtrlTempptr=NULL; struct RingBuf *rxRingBuf=NULL; if(byCanNo==0) { pCan=(tagCanReg *)CAN1_BASE; } else if(byCanNo==1) { pCan=(tagCanReg *)CAN2_BASE; } else return false; if(!flag) { if(__CAN_MemInit()==false) { printf("CAN Dev Control Block malloc failed.\r\n"); return false; } //初始化接收环形缓冲区 for(i=0;i<CN_CAN_NUM;i++) { CAN_DevCtrlTempptr=CAN_DevCtrlPtr+i; rxRingBuf=CAN_DevCtrlTempptr->RcvRing; Ring_Init(rxRingBuf,rxRingBuf->buf,CN_CAN_RX_BUF_SIZE); } flag++; } CAN_DevCtrlTempptr=CAN_DevCtrlPtr+byCanNo; CAN_DevCtrlTempptr->BaudRate=baudrate; CAN_DevCtrlTempptr->RcvFlag=false; __CAN_GpioConfig(byCanNo); //Exit from sleep mode pCan->MCR&=(~(uint32_t)CAN_MCR_SLEEP); //Request init pCan->MCR|=CAN_MCR_INRQ; //Wait the acknowledge while((pCan->MSR&CAN_MSR_INAK)!=CAN_MSR_INAK) { i++; if(i>1000000) { return false; } } //Disable time triggered communication mode pCan->MCR&=~(uint32_t)CAN_MCR_TTCM; //Set automatic bus-off management // pCan->MCR|=CAN_MCR_ABOM; pCan->MCR&=~(uint32_t)CAN_MCR_ABOM; //Set automatic wake-up mode // pCan->MCR|=CAN_MCR_AWUM; pCan->MCR&=~(uint32_t)CAN_MCR_AWUM; //Set no automatic retransmission pCan->MCR&=~(uint32_t)CAN_MCR_NART; //todo //Set transmit FIFO priority (first in first out) pCan->MCR|=CAN_MCR_TXFP; //Set recv FIFO locked mode pCan->MCR&=~(uint32_t)CAN_MCR_RFLM; //Set the bit timing register APB1上 54MHz __CAN_SetBaudRate(pCan,baudrate); //Set loopback test mode // pCan->BTR|=CAN_BTR_LBKM; //todo debug for test // // if(gs_bLoopBackFlag) // { // pCan->BTR|=CAN_BTR_LBKM; // } //Set filter configuration if(pFilterConfPara!=NULL) { __CAN_ConfigFilter(pFilterConfPara); } //Init int __CAN_IntInit(byCanNo); //Enabel Recv Fifo(FMPIE/FFIE/FOVIE) EPVIE BOFIE LECIE ERRIE interrupt pCan->IER|=CAN_IER_FMPIE0|CAN_IER_FFIE0|CAN_IER_FOVIE0|CAN_IER_FMPIE1\ |CAN_IER_FFIE1|CAN_IER_FOVIE1|CAN_IER_BOFIE|CAN_IER_LECIE|CAN_IER_ERRIE; //Request leave init pCan->MCR&=~(uint32_t)CAN_MCR_INRQ; //Wait the acknowledge i=0; while((pCan->MSR&CAN_MSR_INAK)!=CAN_MSR_INAK) { i++; if(i>1000000) { return false; } } return true; }