]> rtime.felk.cvut.cz Git - arc.git/blobdiff - arch/ppc/mpc55xx/drivers/Can.c
Merged with dem-dev
[arc.git] / arch / ppc / mpc55xx / drivers / Can.c
index ccdb7c932413469379d18db243e53ff71438e752..6037bbc0264c1bc7491045539d41021445034335 100644 (file)
 #include <stdlib.h>\r
 #include <string.h>\r
 #if defined(USE_KERNEL)\r
-#include "Os.h"\r
+#include "Os.h"
+#include "int_ctrl.h"\r
 #endif\r
 \r
 \r
 /* CONFIGURATION NOTES\r
  * ------------------------------------------------------------------\r
- * - CanHandleType must be CAN_ECORE_HANDLE_TYPE_BASIC\r
- *   i.e. CanHandleType=CAN_ECORE_HANDLE_TYPE_FULL NOT supported\r
+ * - CanHandleType must be CAN_ARC_HANDLE_TYPE_BASIC\r
+ *   i.e. CanHandleType=CAN_ARC_HANDLE_TYPE_FULL NOT supported\r
  *   i.e CanIdValue is NOT supported\r
- * - All CanXXXProcessing must be CAN_ECORE_PROCESS_TYPE_INTERRUPT\r
- *   ie CAN_ECORE_PROCESS_TYPE_POLLED not supported\r
- * - To select the Mailboxes to use in the CAN controller use CanEcoreMbMask\r
+ * - All CanXXXProcessing must be CAN_ARC_PROCESS_TYPE_INTERRUPT\r
+ *   ie CAN_ARC_PROCESS_TYPE_POLLED not supported\r
+ * - To select the Mailboxes to use in the CAN controller use Can_Arc_MbMask\r
  * - HOH's for Tx are global and Rx are for each controller\r
  * - CanControllerTimeQuanta is NOT used. The other CanControllerXXX selects\r
  *   the proper time-quanta\r
- * - CanEcoreMbMask for Tx HOH must NOT overlap CanEcoreMbMask for Rx.\r
+ * - Can_Arc_MbMask for Tx HOH must NOT overlap Can_Arc_MbMask for Rx.\r
  * - ONLY global mask is supported( NOT 14,15 and individual )\r
  * - Numbering the CanObjectId for Tx:\r
  *     To do this correctly there are a number of things that are good to know\r
  *     1. HTH's have unique numbers.\r
  *     2. One HTH/HRH is maped to one HOH\r
- *     3. The extension CanEcoreMbMask binds FULL CAN boxes together.\r
+ *     3. The extension Can_Arc_MbMask binds FULL CAN boxes together.\r
  *\r
  *     Example:\r
  *\r
@@ -66,7 +67,7 @@
  *      1    F   0  1\r
  *      ..\r
  *      16   B   0  16  |\r
- *                  17  |    The use of CanEcoreMbMask=0x000f0000 binds these to HTH 16\r
+ *                  17  |    The use of Can_Arc_MbMask=0x000f0000 binds these to HTH 16\r
  *                  18  |    ( bits 16 to 19 set here )\r
  *                  19  |\r
  *           ...\r
@@ -214,12 +215,12 @@ typedef struct FLEXCAN_tag flexcan_t;
 #endif\r
 \r
 // Mapping between HRH and Controller//HOH\r
-typedef struct Can_EcoreObjectHOHMapStruct\r
+typedef struct Can_Arc_ObjectHOHMapStruct\r
 {\r
   uint32 HxHRef;    // Reference to HRH or HTH\r
   CanControllerIdType CanControllerRef;    // Reference to controller\r
   const Can_HardwareObjectType* CanHOHRef;       // Reference to HOH.\r
-} Can_EcoreObjectHOHMapType;\r
+} Can_Arc_ObjectHOHMapType;\r
 \r
 /* Type for holding global information used by the driver */\r
 typedef struct {\r
@@ -238,7 +239,7 @@ typedef struct {
 \r
   // This is a map that maps the HTH:s with the controller and Hoh. It is built\r
   // during Can_Init and is used to make things faster during a transmit.\r
-  Can_EcoreObjectHOHMapType CanHTHMap[NUM_OF_HTHS];\r
+  Can_Arc_ObjectHOHMapType CanHTHMap[NUM_OF_HTHS];\r
 } Can_GlobalType;\r
 \r
 // Global config\r
@@ -253,14 +254,14 @@ typedef struct {
   CanIf_ControllerModeType state;\r
   uint32               lock_cnt;\r
   // Interrupt masks that is for all Mb's in this controller\r
-  uint32               CanEcoreRxMbMask;\r
-  uint32               CanEcoreTxMbMask;\r
+  uint32               Can_Arc_RxMbMask;\r
+  uint32               Can_Arc_TxMbMask;\r
 \r
   // Used at IFLG in controller at startup\r
   uint32               iflagStart;\r
 \r
   // Statistics\r
-  Can_EcoreStatisticsType stats;\r
+  Can_Arc_StatisticsType stats;\r
 \r
   // Data stored for Txconfirmation callbacks to CanIf\r
   PduIdType swPduHandles[MAX_NUM_OF_MAILBOXES];\r
@@ -311,10 +312,10 @@ Can_UnitType CanUnit[CAN_CONTROLLER_CNT] =
  * @param hth The transmit handle\r
  * @returns Ptr to the Hoh\r
  */\r
-static const Can_HardwareObjectType * Can_FindHoh( Can_EcoreHTHType hth , uint32* controller)\r
+static const Can_HardwareObjectType * Can_FindHoh( Can_Arc_HTHType hth , uint32* controller)\r
 {\r
   const Can_HardwareObjectType *hohObj;\r
-  const Can_EcoreObjectHOHMapType *map;\r
+  const Can_Arc_ObjectHOHMapType *map;\r
   const Can_ControllerConfigType *canHwConfig;\r
 \r
   map = &Can_Global.CanHTHMap[hth];\r
@@ -387,7 +388,7 @@ void Can_F_BusOff( void  ) {        Can_BusOff(CAN_CTRL_F); }
 \r
 static void Can_Err( int unit ) {\r
   flexcan_t *canHw = GET_CONTROLLER(unit);\r
-  Can_EcoreErrorType err;\r
+  Can_Arc_ErrorType err;\r
   ESRType esr;\r
   err.R = 0;\r
 \r
@@ -402,9 +403,9 @@ static void Can_Err( int unit ) {
   err.B.RXWRN = esr.B.RXWRN;\r
   err.B.TXWRN = esr.B.TXWRN;\r
 \r
-  if (GET_CALLBACKS()->EcoreError != NULL)\r
+  if (GET_CALLBACKS()->Arc_Error != NULL)\r
   {\r
-    GET_CALLBACKS()->EcoreError(unit, err );\r
+    GET_CALLBACKS()->Arc_Error(unit, err );\r
   }\r
   // Clear ERRINT\r
   canHw->ESR.B.ERRINT = 1;\r
@@ -417,7 +418,7 @@ static void Can_AbortTx( flexcan_t *canHw, Can_UnitType *canUnit ) {
   uint8 mbNr;\r
 \r
        // Find our Tx boxes.\r
-  mbMask = canUnit->CanEcoreTxMbMask;\r
+  mbMask = canUnit->Can_Arc_TxMbMask;\r
 \r
   // Loop over the Mb's set to abort\r
   for (; mbMask; mbMask&=~(1<<mbNr)) {\r
@@ -442,8 +443,8 @@ static void Can_AbortTx( flexcan_t *canHw, Can_UnitType *canUnit ) {
   }\r
 \r
   // Ack tx interrupts\r
-  canHw->IFRL.R = canUnit->CanEcoreTxMbMask;\r
-  canUnit->iflagStart = canUnit->CanEcoreTxMbMask;\r
+  canHw->IFRL.R = canUnit->Can_Arc_TxMbMask;\r
+  canUnit->iflagStart = canUnit->Can_Arc_TxMbMask;\r
 }\r
 \r
 //-------------------------------------------------------------------\r
@@ -456,7 +457,7 @@ static void Can_AbortTx( flexcan_t *canHw, Can_UnitType *canUnit ) {
 static void Can_BusOff( int unit ) {\r
   flexcan_t *canHw = GET_CONTROLLER(unit);\r
   Can_UnitType *canUnit = GET_PRIVATE_DATA(unit);\r
-  Can_EcoreErrorType err;\r
+  Can_Arc_ErrorType err;\r
   err.R = 0;\r
 \r
   if ( canHw->ESR.B.TWRNINT )\r
@@ -475,9 +476,9 @@ static void Can_BusOff( int unit ) {
 \r
   if (err.R != 0)\r
   {\r
-    if (GET_CALLBACKS()->EcoreError != NULL)\r
+    if (GET_CALLBACKS()->Arc_Error != NULL)\r
     {\r
-      GET_CALLBACKS()->EcoreError( unit, err );\r
+      GET_CALLBACKS()->Arc_Error( unit, err );\r
     }\r
   }\r
 \r
@@ -557,12 +558,12 @@ static void Can_Isr(int unit) {
       //\r
 \r
       // Rx\r
-      hohObj= canHwConfig->CanEcoreHoh;\r
+      hohObj= canHwConfig->Can_Arc_Hoh;\r
       --hohObj;\r
       do {\r
         ++hohObj;\r
 \r
-        mbMask = hohObj->CanEcoreMbMask & iFlagLow;\r
+        mbMask = hohObj->Can_Arc_MbMask & iFlagLow;\r
 \r
         if (hohObj->CanObjectType == CAN_OBJECT_TYPE_RECEIVE)\r
         {\r
@@ -596,17 +597,17 @@ static void Can_Isr(int unit) {
             canHw->IFRL.R = (1<<mbNr);\r
           }\r
         }\r
-      } while ( !hohObj->CanEcoreEOL);\r
+      } while ( !hohObj->Can_Arc_EOL);\r
 \r
       // Tx\r
-      hohObj= canHwConfig->CanEcoreHoh;\r
+      hohObj= canHwConfig->Can_Arc_Hoh;\r
       --hohObj;\r
       do {\r
         ++hohObj;\r
 \r
         if (hohObj->CanObjectType == CAN_OBJECT_TYPE_TRANSMIT)\r
         {\r
-          mbMask = hohObj->CanEcoreMbMask & iFlagLow;\r
+          mbMask = hohObj->Can_Arc_MbMask & iFlagLow;\r
 \r
           // Loop over the Mb's for this Hoh\r
           for (; mbMask; mbMask&=~(1<<mbNr)) {\r
@@ -623,7 +624,7 @@ static void Can_Isr(int unit) {
             canHw->IFRL.R = (1<<mbNr);\r
           }\r
         }\r
-      } while ( !hohObj->CanEcoreEOL);\r
+      } while ( !hohObj->Can_Arc_EOL);\r
 #if defined(CFG_MPC5516) || defined(CFG_MPC5517)\r
     } // FIFO code\r
 #endif\r
@@ -633,7 +634,7 @@ static void Can_Isr(int unit) {
     // - Interupt on a masked box\r
   }\r
 \r
-  if (canHwConfig->CanEcoreFifo) {\r
+  if (canHwConfig->Can_Arc_Fifo) {\r
        /* Note\r
         * NOT tested at all\r
         */\r
@@ -693,7 +694,7 @@ void Can_Init( const Can_ConfigType *config ) {
   Can_Global.initRun = CAN_READY;\r
 \r
 \r
-  for (int configId=0; configId < CAN_ECORE_CTRL_CONFIG_CNT; configId++) {\r
+  for (int configId=0; configId < CAN_ARC_CTRL_CONFIG_CNT; configId++) {\r
     canHwConfig = GET_CONTROLLER_CONFIG(configId);\r
     ctlrId = canHwConfig->CanControllerId;\r
 \r
@@ -707,13 +708,13 @@ void Can_Init( const Can_ConfigType *config ) {
     canUnit->lock_cnt = 0;\r
 \r
     // Clear stats\r
-    memset(&canUnit->stats, 0, sizeof(Can_EcoreStatisticsType));\r
+    memset(&canUnit->stats, 0, sizeof(Can_Arc_StatisticsType));\r
 \r
     Can_InitController(ctlrId, canHwConfig);\r
 \r
     // Loop through all Hoh:s and map them into the HTHMap\r
     const Can_HardwareObjectType* hoh;\r
-    hoh = canHwConfig->CanEcoreHoh;\r
+    hoh = canHwConfig->Can_Arc_Hoh;\r
     hoh--;\r
     do\r
     {\r
@@ -725,7 +726,7 @@ void Can_Init( const Can_ConfigType *config ) {
         Can_Global.CanHTHMap[hoh->CanObjectId].CanHOHRef = hoh;\r
         Can_Global.CanHTHMap[hoh->CanObjectId].HxHRef = hoh->CanObjectId;\r
       }\r
-    } while (!hoh->CanEcoreEOL);\r
+    } while (!hoh->Can_Arc_EOL);\r
 \r
     // Note!\r
     // Could install handlers depending on HW objects to trap more errors\r
@@ -774,7 +775,7 @@ void Can_DeInit()
   const Can_ControllerConfigType *canHwConfig;\r
   uint32 ctlrId;\r
 \r
-  for (int configId=0; configId < CAN_ECORE_CTRL_CONFIG_CNT; configId++) {\r
+  for (int configId=0; configId < CAN_ARC_CTRL_CONFIG_CNT; configId++) {\r
     canHwConfig = GET_CONTROLLER_CONFIG(configId);\r
     ctlrId = canHwConfig->CanControllerId;\r
 \r
@@ -786,7 +787,7 @@ void Can_DeInit()
     canUnit->lock_cnt = 0;\r
 \r
     // Clear stats\r
-    memset(&canUnit->stats, 0, sizeof(Can_EcoreStatisticsType));\r
+    memset(&canUnit->stats, 0, sizeof(Can_Arc_StatisticsType));\r
   }\r
 \r
   Can_Global.config = NULL;\r
@@ -835,7 +836,7 @@ void Can_InitController( uint8 controller, const Can_ControllerConfigType *confi
 #if defined(CFG_MPC5516) || defined(CFG_MPC5517)\r
   // Note!\r
   // FIFO implemenation not tested\r
-  if( config->CanEcoreFifo ) {\r
+  if( config->Can_Arc_Fifo ) {\r
     canHw->MCR.B.FEN = 1;      // Enable FIFO\r
     canHw->MCR.B.IDAM = 0;     // We want extended id's to match with\r
   }\r
@@ -846,7 +847,7 @@ void Can_InitController( uint8 controller, const Can_ControllerConfigType *confi
   canHw->MCR.B.MAXMB = MAX_NUM_OF_MAILBOXES - 1;\r
 \r
   /* Disable selfreception */\r
-  canHw->MCR.B.SRXDIS = !config->CanEcoreLoopback;\r
+  canHw->MCR.B.SRXDIS = !config->Can_Arc_Loopback;\r
 \r
   // Clock calucation\r
   // -------------------------------------------------------------------\r
@@ -878,13 +879,13 @@ void Can_InitController( uint8 controller, const Can_ControllerConfigType *confi
   canHw->CR.B.PSEG1 = config->CanControllerSeg1;\r
   canHw->CR.B.PSEG2 = config->CanControllerSeg2;\r
   canHw->CR.B.SMP =    1;      // 3 samples better than 1 ??\r
-  canHw->CR.B.LPB =    config->CanEcoreLoopback;\r
+  canHw->CR.B.LPB =    config->Can_Arc_Loopback;\r
   canHw->CR.B.BOFFREC = 1;  // Disable bus off recovery\r
 \r
 #if defined(CFG_MPC5516) || defined(CFG_MPC5517)\r
   // Check if we use individual masks. If so accept anything(=0) for now\r
   if( canHw->MCR.B.BCC ) {\r
-    i = (config->CanEcoreFifo ? 8 : 0 );\r
+    i = (config->Can_Arc_Fifo ? 8 : 0 );\r
     for(;i<63;i++) {\r
       canHw->RXIMR[i].R = 0;\r
     }\r
@@ -892,7 +893,7 @@ void Can_InitController( uint8 controller, const Can_ControllerConfigType *confi
 #else\r
 #endif\r
   // Set the id's\r
-  if( config->CanEcoreFifo ) {\r
+  if( config->Can_Arc_Fifo ) {\r
     // Clear ID's in FIFO also, MUST set extended bit here\r
     uint32_t *fifoId = (uint32_t*)(((uint8_t *)canHw)+0xe0);\r
     for(int k=0;k<8;k++) {\r
@@ -901,7 +902,7 @@ void Can_InitController( uint8 controller, const Can_ControllerConfigType *confi
   }\r
 \r
   // Mark all slots as inactive( depending on fifo )\r
-  i = (config->CanEcoreFifo ? 8 : 0 );\r
+  i = (config->Can_Arc_Fifo ? 8 : 0 );\r
   for(; i < 63; i++) {\r
     //canHw->BUF[i].CS.B.CODE = 0;\r
     canHw->BUF[i].CS.R = 0;\r
@@ -915,12 +916,12 @@ void Can_InitController( uint8 controller, const Can_ControllerConfigType *confi
     Can_FilterMaskType mask = 0xffffffff;\r
 \r
     // Rx\r
-    hohObj = canHwConfig->CanEcoreHoh;\r
+    hohObj = canHwConfig->Can_Arc_Hoh;\r
     --hohObj;\r
     do {\r
       ++hohObj;\r
 \r
-      mbMask = hohObj->CanEcoreMbMask;\r
+      mbMask = hohObj->Can_Arc_MbMask;\r
       mbNr = 0;\r
 \r
       if (hohObj->CanObjectType == CAN_OBJECT_TYPE_RECEIVE)\r
@@ -941,16 +942,16 @@ void Can_InitController( uint8 controller, const Can_ControllerConfigType *confi
         }\r
 \r
         // Add to global mask\r
-        canUnit->CanEcoreRxMbMask |= hohObj->CanEcoreMbMask;\r
+        canUnit->Can_Arc_RxMbMask |= hohObj->Can_Arc_MbMask;\r
         if( hohObj->CanFilterMaskRef != NULL  ) {\r
           mask &= *hohObj->CanFilterMaskRef;\r
         }\r
       }\r
       else\r
       {\r
-        canUnit->CanEcoreTxMbMask |= hohObj->CanEcoreMbMask;\r
+        canUnit->Can_Arc_TxMbMask |= hohObj->Can_Arc_MbMask;\r
       }\r
-    } while( !hohObj->CanEcoreEOL );\r
+    } while( !hohObj->Can_Arc_EOL );\r
 \r
 \r
     // Set global mask\r
@@ -960,7 +961,7 @@ void Can_InitController( uint8 controller, const Can_ControllerConfigType *confi
     canHw->RX15MASK.R = 0;\r
   }\r
 \r
-  canUnit->iflagStart = canUnit->CanEcoreTxMbMask;\r
+  canUnit->iflagStart = canUnit->Can_Arc_TxMbMask;\r
 \r
   canUnit->state = CANIF_CS_STOPPED;\r
   Can_EnableControllerInterrupts(cId);\r
@@ -1077,18 +1078,18 @@ void Can_EnableControllerInterrupts( uint8 controller ) {
   canHw->IMRH.R = 0;\r
   canHw->IMRL.R = 0;\r
 \r
-  if( canHwConfig->CanRxProcessing == CAN_ECORE_PROCESS_TYPE_INTERRUPT ) {\r
+  if( canHwConfig->CanRxProcessing == CAN_ARC_PROCESS_TYPE_INTERRUPT ) {\r
     /* Turn on the interrupt mailboxes */\r
-    canHw->IMRL.R = canUnit->CanEcoreRxMbMask;\r
+    canHw->IMRL.R = canUnit->Can_Arc_RxMbMask;\r
   }\r
 \r
-  if( canHwConfig->CanTxProcessing == CAN_ECORE_PROCESS_TYPE_INTERRUPT ) {\r
+  if( canHwConfig->CanTxProcessing == CAN_ARC_PROCESS_TYPE_INTERRUPT ) {\r
     /* Turn on the interrupt mailboxes */\r
-    canHw->IMRL.R |= canUnit->CanEcoreTxMbMask;\r
+    canHw->IMRL.R |= canUnit->Can_Arc_TxMbMask;\r
   }\r
 \r
   // BusOff here represents all errors and warnings\r
-  if( canHwConfig->CanBusOffProcessing == CAN_ECORE_PROCESS_TYPE_INTERRUPT ) {\r
+  if( canHwConfig->CanBusOffProcessing == CAN_ARC_PROCESS_TYPE_INTERRUPT ) {\r
     canHw->MCR.B.WRNEN = 1;    /* Turn On warning int */\r
 \r
     canHw->CR.B.ERRMSK = 1;    /* Enable error interrupt */\r
@@ -1100,7 +1101,7 @@ void Can_EnableControllerInterrupts( uint8 controller ) {
   return;\r
 }\r
 \r
-Can_ReturnType Can_Write( Can_EcoreHTHType hth, Can_PduType *pduInfo ) {\r
+Can_ReturnType Can_Write( Can_Arc_HTHType hth, Can_PduType *pduInfo ) {\r
   uint16_t timer;\r
   uint32_t iflag;\r
   Can_ReturnType rv = CAN_OK;\r
@@ -1123,7 +1124,7 @@ Can_ReturnType Can_Write( Can_EcoreHTHType hth, Can_PduType *pduInfo ) {
 \r
   canHw = GET_CONTROLLER(controller);\r
   oldMsr = McuE_EnterCriticalSection();\r
-  iflag = canHw->IFRL.R & canUnit->CanEcoreTxMbMask;\r
+  iflag = canHw->IFRL.R & canUnit->Can_Arc_TxMbMask;\r
 \r
   // check for any free box\r
   // Normally we would just use the iflag to get the free box\r
@@ -1206,7 +1207,7 @@ void Can_MainFunction_Wakeup( void ) {
  * @param stats Pointer to data to copy statistics to\r
  */\r
 \r
-void Can_EcoreGetStatistics( uint8 controller, Can_EcoreStatisticsType *stats)\r
+void Can_Arc_GetStatistics( uint8 controller, Can_Arc_StatisticsType *stats)\r
 {\r
   Can_UnitType *canUnit = GET_PRIVATE_DATA(controller);\r
   *stats = canUnit->stats;\r
@@ -1234,7 +1235,7 @@ Can_ReturnType Can_SetControllerMode( uint8 Controller, Can_StateTransitionType
        return E_OK;\r
 }\r
 \r
-Can_ReturnType Can_Write( Can_EcoreHTHType hth, Can_PduType *pduInfo )\r
+Can_ReturnType Can_Write( Can_Arc_HTHType hth, Can_PduType *pduInfo )\r
 {\r
        // Write to mailbox on controller here.\r
        DEBUG(DEBUG_MEDIUM, "Can_Write(stub): Received data ");\r
@@ -1274,7 +1275,7 @@ void Can_MainFunction_Read( void ){}
 void Can_MainFunction_BusOff( void ){}\r
 void Can_MainFunction_Wakeup( void ){}\r
 \r
-void Can_EcoreGetStatistics( uint8 controller, Can_EcoreStatisticsType * stat){}\r
+void Can_Arc_GetStatistics( uint8 controller, Can_Arc_StatisticsType * stat){}\r
 \r
 #endif\r
 \r