]> rtime.felk.cvut.cz Git - arc.git/blobdiff - communication/CanIf/CanIf.c
LED Blinker example made running for the RPP Board.
[arc.git] / communication / CanIf / CanIf.c
index 3f83669c1b4b09b44341c48bee8d8ebeff65d91b..7f27d79299b517ec977af4baf2f8abea6c088db7 100644 (file)
 #include "CanTp_Cbk.h"\r
 #endif\r
 \r
+#if defined(USE_J1939TP)\r
+#include "J1939Tp_Cbk.h"\r
+#endif\r
+\r
 #if defined(USE_CANNM)\r
 #include "CanNm.h"\r
 #endif\r
@@ -72,7 +76,7 @@
 \r
 // Helper to get the Can Controller refered to by a CanIf Channel\r
 #define ARC_GET_CHANNEL_CONTROLLER(_channel) \\r
-       CanIf_ConfigPtr->Arc_ChannelToControllerMap[channel]\r
+       CanIf_ConfigPtr->Arc_ChannelToControllerMap[_channel]\r
 \r
 /* Global configure */\r
 static const CanIf_ConfigType *CanIf_ConfigPtr;\r
@@ -117,7 +121,7 @@ static CanIf_Arc_ChannelIdType CanIf_Arc_FindHrhChannel( Can_Arc_HRHType hrh )
 \r
   DET_REPORTERROR(MODULE_ID_CANIF, 0, CANIF_RXINDICATION_ID, CANIF_E_PARAM_HRH);\r
 \r
-  return -1;\r
+  return (CanIf_Arc_ChannelIdType) -1;\r
 }\r
 \r
 // Global config\r
@@ -151,7 +155,7 @@ void CanIf_Init(const CanIf_ConfigType *ConfigPtr)
 void CanIf_InitController(uint8 Controller, uint8 ConfigurationIndex)\r
 {\r
   // We call this a CanIf channel. Hopefully makes it easier to follow.\r
-  CanIf_Arc_ChannelIdType channel = Controller;\r
+  CanIf_Arc_ChannelIdType channel = (CanIf_Arc_ChannelIdType) Controller;\r
   CanIf_ControllerModeType mode;\r
 \r
   VALIDATE_NO_RV(CanIf_Global.initRun, CANIF_INIT_CONTROLLER_ID, CANIF_E_UNINIT );\r
@@ -200,7 +204,7 @@ void CanIf_InitController(uint8 Controller, uint8 ConfigurationIndex)
 \r
 void CanIf_PreInit_InitController(uint8 Controller, uint8 ConfigurationIndex){\r
        // We call this a CanIf channel. Hopefully makes it easier to follow.\r
-       CanIf_Arc_ChannelIdType channel = Controller;\r
+       CanIf_Arc_ChannelIdType channel = (CanIf_Arc_ChannelIdType) Controller;\r
 \r
        VALIDATE_NO_RV(channel < CANIF_CHANNEL_CNT, CANIF_INIT_ID, CANIF_E_PARAM_CONTROLLER);\r
        VALIDATE_NO_RV(ConfigurationIndex < CANIF_CHANNEL_CONFIGURATION_CNT, CANIF_INIT_ID, CANIF_E_PARAM_POINTER);\r
@@ -222,7 +226,7 @@ Std_ReturnType CanIf_SetControllerMode(uint8 Controller,
     CanIf_ControllerModeType ControllerMode)\r
 {\r
   // We call this a CanIf channel. Hopefully makes it easier to follow.\r
-  CanIf_Arc_ChannelIdType channel = Controller;\r
+  CanIf_Arc_ChannelIdType channel = (CanIf_Arc_ChannelIdType) Controller;\r
 \r
 \r
   CanIf_ControllerModeType oldMode;\r
@@ -318,7 +322,7 @@ Std_ReturnType CanIf_GetControllerMode(uint8 Controller,
     CanIf_ControllerModeType *ControllerModePtr)\r
 {\r
   // We call this a CanIf channel. Hopefully makes it easier to follow.\r
-  CanIf_Arc_ChannelIdType channel = Controller;\r
+  CanIf_Arc_ChannelIdType channel = (CanIf_Arc_ChannelIdType) Controller;\r
 \r
   VALIDATE(CanIf_Global.initRun, CANIF_GET_CONTROLLER_MODE_ID, CANIF_E_UNINIT );\r
   VALIDATE(channel < CANIF_CHANNEL_CNT, CANIF_GET_CONTROLLER_MODE_ID, CANIF_E_PARAM_CONTROLLER );\r
@@ -346,22 +350,18 @@ static const CanIf_TxPduConfigType * CanIf_FindTxPduEntry(PduIdType id)
        } else {\r
                return &CanIf_ConfigPtr->InitConfig->CanIfTxPduConfigPtr[id];\r
        }\r
-  }\r
+}\r
 \r
+
 #if ( CANIF_ARC_RUNTIME_PDU_CONFIGURATION == STD_ON )\r
-CanIf_RxPduConfigType * CanIf_FindRxPduEntry(PduIdType id)\r
-#else\r
-static const CanIf_RxPduConfigType * CanIf_FindRxPduEntry(PduIdType id)
-#endif\r
-{
-       if (id >= CanIf_ConfigPtr->InitConfig->CanIfNumberOfCanRxPduIds) {
-               return NULL;
-       } else {
-               return &CanIf_ConfigPtr->InitConfig->CanIfRxPduConfigPtr[id];
-       }
-}
+CanIf_RxPduConfigType * CanIf_FindRxPduEntry(PduIdType id) {\r
+       if (id >= CanIf_ConfigPtr->InitConfig->CanIfNumberOfCanRxPduIds) {\r
+               return NULL;\r
+       } else {\r
+               return &CanIf_ConfigPtr->InitConfig->CanIfRxPduConfigPtr[id];\r
+       }\r
+}\r
 
-#if ( CANIF_ARC_RUNTIME_PDU_CONFIGURATION == STD_ON )
 const CanIf_HrhConfigType* CanIf_Arc_GetReceiveHandler(CanIf_Arc_ChannelIdType Channel) {
   const CanIf_InitHohConfigType *hohConfig;
   const CanIf_HrhConfigType *hrhConfig;
@@ -463,7 +463,7 @@ Std_ReturnType CanIf_Transmit(PduIdType CanTxPduId,
 \r
   canPdu.length = PduInfoPtr->SduLength;\r
   canPdu.sdu = PduInfoPtr->SduDataPtr;\r
-  canPdu.swPduHandle = CanTxPduId;\r
+  canPdu.swPduHandle = CanTxPduId;             // e.g. ARC_PDUR_CANIF\r
 \r
   Can_ReturnType rVal = Can_Write(txEntry->CanIfCanTxPduHthRef->CanIfHthIdSymRef, &canPdu);\r
 \r
@@ -544,7 +544,7 @@ Std_ReturnType CanIf_SetPduMode(uint8 Controller,
     CanIf_ChannelSetModeType PduModeRequest)\r
 {\r
   // We call this a CanIf channel. Hopefully makes it easier to follow.\r
-  CanIf_Arc_ChannelIdType channel = Controller;\r
+  CanIf_Arc_ChannelIdType channel = (CanIf_Arc_ChannelIdType) Controller;\r
 \r
   VALIDATE( CanIf_Global.initRun, CANIF_SETPDUMODE_ID, CANIF_E_UNINIT );\r
   VALIDATE( channel < CANIF_CHANNEL_CNT, CANIF_SETPDUMODE_ID, CANIF_E_PARAM_CONTROLLER );\r
@@ -632,7 +632,7 @@ Std_ReturnType CanIf_GetPduMode(uint8 Controller,
     CanIf_ChannelGetModeType *PduModePtr)\r
 {\r
   // We call this a CanIf channel. Hopefully makes it easier to follow.\r
-  CanIf_Arc_ChannelIdType channel = Controller;\r
+  CanIf_Arc_ChannelIdType channel = (CanIf_Arc_ChannelIdType) Controller;\r
 \r
   VALIDATE( CanIf_Global.initRun, CANIF_GETPDUMODE_ID, CANIF_E_UNINIT );\r
   VALIDATE( channel < CANIF_CHANNEL_CNT, CANIF_GETPDUMODE_ID, CANIF_E_PARAM_CONTROLLER );\r
@@ -769,7 +769,7 @@ void CanIf_RxIndication(uint8 Hrh, Can_IdType CanId, uint8 CanDlc,
 \r
   /* Check PDU mode before continue processing */\r
   CanIf_ChannelGetModeType mode;\r
-  CanIf_Arc_ChannelIdType channel = CanIf_Arc_FindHrhChannel(Hrh);\r
+  CanIf_Arc_ChannelIdType channel = CanIf_Arc_FindHrhChannel( (Can_Arc_HRHType) Hrh);\r
   if (channel == -1)  // Invalid HRH\r
   {\r
     return;\r
@@ -855,7 +855,12 @@ void CanIf_RxIndication(uint8 Hrh, Can_IdType CanId, uint8 CanDlc,
         case CANIF_USER_TYPE_CAN_PDUR:\r
             // Send Can frame to PDU router\r
 #if defined(USE_PDUR)\r
-            PduR_CanIfRxIndication(entry->CanIfCanRxPduId,CanSduPtr);\r
+               {\r
+                       PduInfoType pduInfo;\r
+                       pduInfo.SduLength = CanDlc;\r
+                       pduInfo.SduDataPtr = (uint8 *)CanSduPtr;\r
+               PduR_CanIfRxIndication(entry->CanIfCanRxPduId,&pduInfo);\r
+               }\r
             return;\r
 #endif\r
             break;\r
@@ -872,6 +877,18 @@ void CanIf_RxIndication(uint8 Hrh, Can_IdType CanId, uint8 CanDlc,
             return;\r
 #endif\r
             break;\r
+        case CANIF_USER_TYPE_J1939TP:\r
+          // Send Can frame to CAN TP\r
+#if defined(USE_J1939TP)\r
+            {\r
+                   PduInfoType J1939TpRxPdu;\r
+                   J1939TpRxPdu.SduLength = CanDlc;\r
+                   J1939TpRxPdu.SduDataPtr = (uint8 *)CanSduPtr;\r
+                   J1939Tp_RxIndication(entry->CanIfCanRxPduId, &J1939TpRxPdu);\r
+            }\r
+            return;\r
+#endif\r
+            break;            \r
       }\r
     }\r
 \r
@@ -901,10 +918,18 @@ void CanIf_CancelTxConfirmation(const Can_PduType *PduInfoPtr)
 \r
 void CanIf_ControllerBusOff(uint8 Controller)\r
 {\r
-  // We call this a CanIf channel. Hopefully makes it easier to follow.\r
-  CanIf_Arc_ChannelIdType channel = Controller;\r
+  CanIf_Arc_ChannelIdType channel = 0xff;\r
 \r
   VALIDATE_NO_RV( CanIf_Global.initRun, CANIF_CONTROLLER_BUSOFF_ID, CANIF_E_UNINIT );\r
+\r
+  for(int i = 0; i < CANIF_CHANNEL_CNT; i++)\r
+  {\r
+         if(CanIf_ConfigPtr->Arc_ChannelToControllerMap[i] == Controller)\r
+         {\r
+                 channel = i;\r
+         }\r
+  }\r
+\r
   VALIDATE_NO_RV( Controller < CANIF_CHANNEL_CNT, CANIF_CONTROLLER_BUSOFF_ID, CANIF_E_PARAM_CONTROLLER );\r
 \r
   // According to figure 35 in canif spec this should be done in\r
@@ -919,35 +944,54 @@ void CanIf_ControllerBusOff(uint8 Controller)
 \r
 void CanIf_SetWakeupEvent(uint8 Controller)\r
 {\r
-#if  ( CANIF_DEV_ERROR_DETECT == STD_ON )\r
-  // We call this a CanIf channel. Hopefully makes it easier to follow.\r
-  CanIf_Arc_ChannelIdType channel = Controller;\r
-#endif\r
+       CanIf_Arc_ChannelIdType channel = 0xff;\r
 \r
-  VALIDATE_NO_RV(FALSE, CANIF_SETWAKEUPEVENT_ID, CANIF_E_NOK_NOSUPPORT);\r
-  VALIDATE_NO_RV( CanIf_Global.initRun, CANIF_SETWAKEUPEVENT_ID, CANIF_E_UNINIT );\r
-  VALIDATE_NO_RV( channel < CANIF_CHANNEL_CNT, CANIF_SETWAKEUPEVENT_ID, CANIF_E_PARAM_CONTROLLER );\r
+       VALIDATE_NO_RV( CanIf_Global.initRun, CANIF_SETWAKEUPEVENT_ID, CANIF_E_UNINIT );\r
 \r
-  // Not supported\r
+       for(int i = 0; i < CANIF_CHANNEL_CNT; i++)\r
+       {\r
+         if(CanIf_ConfigPtr->Arc_ChannelToControllerMap[i] == Controller)\r
+         {\r
+                 channel = i;\r
+         }\r
+       }\r
+\r
+       VALIDATE_NO_RV(FALSE, CANIF_SETWAKEUPEVENT_ID, CANIF_E_NOK_NOSUPPORT);\r
+       VALIDATE_NO_RV( channel < CANIF_CHANNEL_CNT, CANIF_SETWAKEUPEVENT_ID, CANIF_E_PARAM_CONTROLLER );\r
+\r
+       // Not supported\r
 }\r
 \r
 void CanIf_Arc_Error(uint8 Controller, Can_Arc_ErrorType Error)\r
 {\r
-#if  ( CANIF_DEV_ERROR_DETECT == STD_ON )\r
-  // We call this a CanIf channel. Hopefully makes it easier to follow.\r
-  CanIf_Arc_ChannelIdType channel = Controller;\r
-#endif\r
+  CanIf_Arc_ChannelIdType channel = 0xff;\r
 \r
   VALIDATE_NO_RV( CanIf_Global.initRun, CANIF_ARCERROR_ID, CANIF_E_UNINIT );\r
+\r
+  for(int i = 0; i < CANIF_CHANNEL_CNT; i++)\r
+  {\r
+         if(CanIf_ConfigPtr->Arc_ChannelToControllerMap[i] == Controller)\r
+         {\r
+                 channel = i;\r
+         }\r
+  }\r
+\r
   VALIDATE_NO_RV( channel < CANIF_CHANNEL_CNT, CANIF_ARCERROR_ID, CANIF_E_PARAM_CONTROLLER );\r
 \r
   if (CanIf_ConfigPtr->DispatchConfig->CanIfErrorNotificaton != NULL)\r
   {\r
     CanIf_ConfigPtr->DispatchConfig->CanIfErrorNotificaton(Controller, Error);\r
   }\r
+\r
+  // Special fix for restart of bus incase of general can error i.e. connection to CanSM\r
+  if (CanIf_ConfigPtr->DispatchConfig->CanIfBusOffNotification != NULL)\r
+  {\r
+    CanIf_ConfigPtr->DispatchConfig->CanIfBusOffNotification(channel);\r
+  }\r
 }\r
+\r
 uint8 CanIf_Arc_GetChannelDefaultConfIndex(CanIf_Arc_ChannelIdType Channel)
 {
        return CanIf_Config.Arc_ChannelDefaultConfIndex[Channel];
-};
+}