⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 canpie_hal.c.svn-base

📁 canpie 一个can bus的协议栈 - CAN interface for embedded control - CAN interface for PC (without local
💻 SVN-BASE
📖 第 1 页 / 共 4 页
字号:
   //----------------------------------------------------------------   // check if a free queue was found   //   if(slQueueIdT < 0)    {      PK_DBG(2, "no free queue found");      return(0L);   }   //----------------------------------------------------------------   // set pointer to the selected message queue   //   ptsQueueT = &(atsCpHalS[slLogIfV].atsMsgQueue[slQueueIdT]);      //----------------------------------------------------------------   // create the message queue, i.e. init FIFOs for receive and   // transmit   //    if( CpFifoInit( &(ptsQueueT->tsRcvFifo), (_U16) slRcvFifoSizeV) != CpErr_OK)   {      goto QueueFail;   }         if( CpFifoInit( &(ptsQueueT->tsTrmFifo), (_U16) slTrmFifoSizeV) != CpErr_OK)   {      CpFifoRelease(&(ptsQueueT->tsRcvFifo));      goto QueueFail;   }   //----------------------------------------------------------------   // mark the message queue as assigned   //   ptsQueueT->tsCanPort.slLogIf = slLogIfV;   ptsQueueT->tsCanPort.slQueue = slQueueIdT;   atsCpHalS[slLogIfV].slUseCount++;         return( &(ptsQueueT->tsCanPort) );   QueueFail:      return(0L);}//----------------------------------------------------------------------------//// can_queue_delete()                                                         ////                                                                            ////----------------------------------------------------------------------------//int can_queue_delete(_TsCpPort * ptsCanPortV){   int               slLogIfT;            // number of logical CAN interface      int               slQueueIdT = -1;     // selected queue ID   _TsCpMsgQueue *   ptsQueueT;           // pointer to CAN message queue         //----------------------------------------------------------------   // test the _TsCpPort pointer   //   if(ptsCanPortV == 0L)   {      return(-EINVAL);     }         //----------------------------------------------------------------   // test the logical interface number   //   slLogIfT = ptsCanPortV->slLogIf;   if( (slLogIfT > CP_CHANNEL_MAX - 1) || (slLogIfT < 0) )   {      PK_DBG(2, "No CAN interface on port %d", slLogIfT);      return(-ENODEV);   }   //----------------------------------------------------------------   // test the queue ID number   //   slQueueIdT = ptsCanPortV->slQueue;   if( (slQueueIdT < 0) || (slQueueIdT > CP_QUEUE_MAX - 1) )   {      PK_DBG(2, "No queue ID %d on CAN interface %d", slQueueIdT, slLogIfT);      return(-EINVAL);     }      //----------------------------------------------------------------   // select the message queue and delete the FIFOs   //   ptsQueueT = &(atsCpHalS[slLogIfT].atsMsgQueue[slQueueIdT]);   CpFifoRelease( &(ptsQueueT->tsRcvFifo) );   CpFifoRelease( &(ptsQueueT->tsTrmFifo) );      //----------------------------------------------------------------   // mark the queue as not assigned   //   ptsCanPortV->slQueue = -1;   atsCpHalS[slLogIfT].slUseCount--;   return(0);}//----------------------------------------------------------------------------//// can_queue_rcv_pop()                                                        //// read CAN messages from specified CAN port (queue)                          ////----------------------------------------------------------------------------//int can_queue_rcv_pop(  _TsCpPort * ptsCanPortV,                         _TsCpCanMsg * ptsCanMsgV, int slMsgNumV){   int               slLogIfT;            // number of logical CAN interface      int               slQueueIdT = -1;     // selected queue ID   int               slMsgCopyT;          // number of messages copied   _U08              ubFifoStatusT;       // status of receive FIFO         _TsCpMsgQueue *   ptsQueueT;           // pointer to CAN message queue         //----------------------------------------------------------------   // test the _TsCpPort pointer   //   if(ptsCanPortV == 0L)   {      return(-EINVAL);     }         //----------------------------------------------------------------   // test the logical interface number   //   slLogIfT = ptsCanPortV->slLogIf;   if( (slLogIfT > CP_CHANNEL_MAX - 1) || (slLogIfT < 0) )   {      PK_DBG(2, "No CAN interface on port %d", slLogIfT);      return(-ENODEV);   }   //----------------------------------------------------------------   // test the queue ID number   //   slQueueIdT = ptsCanPortV->slQueue;   if( (slQueueIdT < 0) || (slQueueIdT > CP_QUEUE_MAX - 1) )   {      PK_DBG(2, "No queue ID %d on CAN interface %d", slQueueIdT, slLogIfT);      return(-EINVAL);     }   //----------------------------------------------------------------   // select the message queue and read 'slMsgNumV' messages   //   ptsQueueT = &(atsCpHalS[slLogIfT].atsMsgQueue[slQueueIdT]);   for(slMsgCopyT = 0; slMsgCopyT < slMsgNumV; slMsgCopyT++)   {      ubFifoStatusT = CpFifoPop(&(ptsQueueT->tsRcvFifo), ptsCanMsgV);      if(ubFifoStatusT == CpErr_FIFO_EMPTY) break;      ptsCanMsgV++;   }      return(slMsgCopyT);  }//----------------------------------------------------------------------------//// can_queue_rcv_push()                                                       //// write CAN messages to specified CAN port ( all open queues)                ////----------------------------------------------------------------------------//int can_queue_rcv_push( _TsCpPort * ptsCanPortV,                         _TsCpCanMsg * ptsCanMsgV, int slMsgNumV){   int               slLogIfT;            // number of logical CAN interface      int               slQueueCntT;         // counter for message queue   int               slMsgCopyT = 0;      // number of messages copied   _U08              ubFifoStatusT;       // status of receive FIFO         _TsCpMsgQueue *   ptsQueueT;           // pointer to CAN message queue   _TsCpCanMsg *     ptsCanMsgT;          // copy of pointer to CAN message         //----------------------------------------------------------------   // test the _TsCpPort pointer   //   if(ptsCanPortV == 0L)   {      return(-EINVAL);     }         //----------------------------------------------------------------   // test the logical interface number   //   slLogIfT = ptsCanPortV->slLogIf;   if( (slLogIfT > CP_CHANNEL_MAX - 1) || (slLogIfT < 0) )   {      PK_DBG(2, "No CAN interface on port %d", slLogIfT);      return(-ENODEV);   }      can_print_frame(ptsCanMsgV, szMsgDbgS);   PK_DBG(eDBG_FUNC, "%s", szMsgDbgS);   //----------------------------------------------------------------   // run through all open message queues and push message into   // the queue   //   for(slQueueCntT = 0; slQueueCntT < CP_QUEUE_MAX; slQueueCntT++)   {      //---------------------------------------------------      // select the next possible open rcv queue      //      ptsQueueT = &(atsCpHalS[slLogIfT].atsMsgQueue[slQueueCntT]);      if(ptsQueueT->tsCanPort.slQueue < 0) continue;      //---------------------------------------------------      // copy data into rcv queue       //      ptsCanMsgT = ptsCanMsgV;      for(slMsgCopyT = 0; slMsgCopyT < slMsgNumV; slMsgCopyT++)      {         ubFifoStatusT = CpFifoPush( &(ptsQueueT->tsRcvFifo), ptsCanMsgV);         if(ubFifoStatusT == CpErr_FIFO_FULL) break;         ptsCanMsgT++; // increase copy of CAN message ptr      }         }      return(slMsgCopyT);  }//----------------------------------------------------------------------------//// can_queue_trm_pop()                                                        //// read CAN messages from Transmit queue ( all open queues)                   ////----------------------------------------------------------------------------//int can_queue_trm_pop(  _TsCpPort * ptsCanPortV,                         _TsCpCanMsg * ptsCanMsgV, int slMsgNumV){   int               slLogIfT;            // number of logical CAN interface      int               slQueueCntT;         // counter for message queue   int               slMsgCopyT = 0;      // number of messages copied   _U08              ubFifoStatusT;       // status of receive FIFO         _TsCpMsgQueue *   ptsQueueT;           // pointer to CAN message queue         //----------------------------------------------------------------   // test the _TsCpPort pointer   //   if(ptsCanPortV == 0L)   {      return(-EINVAL);     }         //----------------------------------------------------------------   // test the logical interface number   //   slLogIfT = ptsCanPortV->slLogIf;   if( (slLogIfT > CP_CHANNEL_MAX - 1) || (slLogIfT < 0) )   {      PK_DBG(2, "No CAN interface on port %d", slLogIfT);      return(-ENODEV);   }   //----------------------------------------------------------------   // run through all open message queues and push message into   // the queue   //   slMsgCopyT = 0;   for(slQueueCntT = 0; slQueueCntT < CP_QUEUE_MAX; slQueueCntT++)   {      //---------------------------------------------------      // select the next possible open trm queue      //      ptsQueueT = &(atsCpHalS[slLogIfT].atsMsgQueue[slQueueCntT]);      if(ptsQueueT->tsCanPort.slQueue < 0) continue;      //---------------------------------------------------      // copy data from trm queue       //      ubFifoStatusT = CpFifoPop( &(ptsQueueT->tsTrmFifo), ptsCanMsgV);      while(ubFifoStatusT != CpErr_FIFO_EMPTY)      {         ptsCanMsgV++;  // increase CAN message ptr         slMsgCopyT++;  // increase message counter         if(slMsgCopyT == slMsgNumV) return(slMsgCopyT);         ubFifoStatusT = CpFifoPop( &(ptsQueueT->tsTrmFifo), ptsCanMsgV);      };   }      return(slMsgCopyT);  }//----------------------------------------------------------------------------//// can_queue_trm_push()                                                       //// write CAN messages to specified CAN port (queue)                           ////----------------------------------------------------------------------------//int can_queue_trm_push( _TsCpPort * ptsCanPortV,                         _TsCpCanMsg * ptsCanMsgV, int slMsgNumV){   int               slLogIfT;            // number of logical CAN interface      int               slQueueIdT = -1;     // selected queue ID   int               slMsgCopyT;          // number of messages copied   _U08              ubFifoStatusT;       // status of receive FIFO         _TsCpMsgQueue *   ptsQueueT;           // pointer to CAN message queue         //----------------------------------------------------------------   // test the _TsCpPort pointer   //   if(ptsCanPortV == 0L)   {      return(-EINVAL);     }         //----------------------------------------------------------------   // test the logical interface number   //   slLogIfT = ptsCanPortV->slLogIf;   if( (slLogIfT > CP_CHANNEL_MAX - 1) || (slLogIfT < 0) )   {      PK_DBG(2, "No CAN interface on port %d", slLogIfT);      return(-ENODEV);   }   //----------------------------------------------------------------   // test the queue ID number   //   slQueueIdT = ptsCanPortV->slQueue;   if( (slQueueIdT < 0) || (slQueueIdT > CP_QUEUE_MAX - 1) )   {      PK_DBG(2, "No queue ID %d on CAN interface %d", slQueueIdT, slLogIfT);      return(-EINVAL);     }      PK_DBG(eDBG_SOCK, "Message: ID=%04X DLC=%1d Data=%02X %02X",              ptsCanMsgV->tuMsgId.ulExt, ptsCanMsgV->ubMsgDLC,              ptsCanMsgV->tuMsgData.aubByte[0],             ptsCanMsgV->tuMsgData.aubByte[1]);      //----------------------------------------------------------------   // select the message queue and write 'slMsgNumV' messages   //   ptsQueueT = &(atsCpHalS[slLogIfT].atsMsgQueue[slQueueIdT]);   for(slMsgCopyT = 0; slMsgCopyT < slMsgNumV; slMsgCopyT++)   {      ubFifoStatusT = CpFifoPush(&(ptsQueueT->tsTrmFifo), ptsCanMsgV);      if(ubFifoStatusT == CpErr_FIFO_FULL) break;      ptsCanMsgV++;   }      return(slMsgCopyT);  }//============================================================================////----------------------------------------------------------------------------//// can_clear_hal_struct()                                                     ////                                                                            ////----------------------------------------------------------------------------//static void can_clear_hal_struct(int slLogIfV){   int   slQueueCntT;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -