]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/commitdiff
Reorganize the logic for restarting FlexRay communication to be Autosar compliant
authorMichal Horn <hornmich@fel.cvut.cz>
Wed, 11 Sep 2013 13:59:50 +0000 (15:59 +0200)
committerMichal Horn <hornmich@fel.cvut.cz>
Wed, 11 Sep 2013 13:59:50 +0000 (15:59 +0200)
Autosar specification restricts the Fr_StartCommunication to be use only for starting the communication and no other logic should be there.
The specification orders the Fr_ControllerInit function to be able to switch POC state to Config from any other states. So all the restart logic was moved here.

Commands descriptions and rpp function documentation was modified.

rpp/include/rpp/fr.h
rpp/src/drv/fr_tms570.c
rpp/src/rpp/fr.c

index 7c9af6a14417e6b3d8d319d1b622b36a9aa679dd..0b0c373a7f0f46eb56b43900017cda489e6e6bbb 100644 (file)
@@ -69,8 +69,13 @@ int8_t rpp_fr_init_driver(const Fr_ConfigType* config_ptr, uint32_t* error);
 /**
  * FlexRay controller initialization.
  *
- * This method should be called after rpp_fr_init_driver() and before any
- * other function from this module.
+ * This method should be called after rpp_fr_init_driver() or rpp_fr_halt_communication() and
+ * rpp_fr_abort_communication() and before any other function from this module.
+ *
+ * To restart communication after halt or abort functions were called, this sequence should be used:
+ * - rpp_fr_init_controller
+ * - rpp_fr_start_communication
+ * -rpp_fr_all_slots (optionally)
  *
  * The functions checks configuration parameters and configures FlexRay
  * controller registers.
@@ -101,9 +106,7 @@ int8_t rpp_fr_init_controller(uint8_t ctrl, uint32_t* error);
  * FlexRay start communication
  *
  * This method should be called after rpp_fr_init_controller() and
- * before any attempt to send or receive messages. If the communication
- * has been halted by rpp_fr_halt_communication() or rpp_fr_abort_communication(),
- * this function has to be called to restart the communication.
+ * before any attempt to send or receive messages.
  *
  * For coldstarter node the function tries to listen and join an
  * existing network. If it fails, it tries to initiate the new one.
index a0be67edc533947ce28448700622d1e9e7317bc4..3ce63d80b0cbe86d686b0e6ccfaefa8d28b1808c 100644 (file)
@@ -882,15 +882,18 @@ Std_ReturnType Fr_ControllerInit(uint8_t Fr_CtrlIdx) {
        uint8_t totalBufferCount;
 
 #ifdef DET_ACTIVATED
-       if (Fr_DrvState != FR_ST_DRV_INITIALIZED) {
+       if (Fr_DrvState < FR_ST_DRV_INITIALIZED) {
                return E_NOT_OK;
        }
 #endif
 
        /* Switch CC into ‘POC:config’ (from any other POCState) */
-       if (Fr_POC_go_to_config() == E_NOT_OK) {
-               return E_NOT_OK;
+       while (frayREG->CCSV_UN.CCSV_ST.pocs_B6 != FR_POCS_CONFIG) {
+               if (Fr_POC_go_to_config() == E_NOT_OK) {
+                       return E_NOT_OK;
+               }
        }
+
        /* Check Cluster config parameters */
        if (Fr_check_cluster_parameters(Fr_Config->clusterConfiguration, &errCode) == E_NOT_OK) {
                return E_NOT_OK | errCode | FR_INIT_ERR_CLUSTER_CONFIG;
@@ -925,6 +928,12 @@ Std_ReturnType Fr_ControllerInit(uint8_t Fr_CtrlIdx) {
        totalBufferCount = Fr_config_msgRAM_parameters(Fr_Config->msgRAMConfig);
        Fr_MsgRAMDataStartAddress = totalBufferCount*4U; // First data section after headers sections in message RAM.
        Fr_MsgRAMDataOffset = Fr_MsgRAMDataStartAddress;
+
+       /* Reset configured flags */
+       for (i = 0; i < totalBufferCount; i++) {
+               Fr_BuffersConfigured[i] = FALSE;
+       }
+
        /* Configure all transmit/receive resources */
        for (i = 0; i < totalBufferCount; i++) {
                if (Fr_PrepareLPdu(Fr_CtrlIdx, Fr_buffer_slot_map[i].buffer_ptr->slotId) == E_NOT_OK) {
@@ -1550,7 +1559,7 @@ Std_ReturnType Fr_PrepareLPdu(uint8_t Fr_CtrlIdx, uint16_t Fr_LPduIdx) {
        if (Fr_CtrlIdx != 0) {
                return E_NOT_OK;
        }
-       if (Fr_DrvState != FR_ST_DRV_INITIALIZED) {
+       if (Fr_DrvState < FR_ST_DRV_INITIALIZED) {
                return E_NOT_OK;
        }
        if (Fr_LPduIdx > cSlotIDMax) {
index 53ecf2794bc4a01bce8d7362e419ec74bbd1ed36..4a61abedf526e11990d6671b9370e913520c52a9 100644 (file)
@@ -47,7 +47,9 @@ int8_t rpp_fr_init_driver(const Fr_ConfigType* config_ptr, uint32_t* error) {
 
 int8_t rpp_fr_init_controller(uint8_t ctrl, uint32_t* error) {
        Std_ReturnType retVal = ERR_PARAM_NO_ERROR;
-       if (rpp_fr_state == RPP_FR_DRV_INITIALIZED) {
+       if (rpp_fr_state == RPP_FR_DRV_INITIALIZED ||
+                       rpp_fr_state == RPP_FR_HALTED ||
+                       rpp_fr_state == RPP_FR_ABORTED) {
                retVal = Fr_ControllerInit(ctrl);
                if (retVal & E_OK) {
                        rpp_fr_state = RPP_FR_CTR_INITIALIZED;
@@ -63,7 +65,7 @@ int8_t rpp_fr_init_controller(uint8_t ctrl, uint32_t* error) {
 
 int8_t rpp_fr_start_communication(uint8_t ctrl, uint32_t* error) {
        Std_ReturnType retVal = ERR_PARAM_NO_ERROR;
-       if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED) {
+       if (rpp_fr_state == RPP_FR_CTR_INITIALIZED) {
                retVal = Fr_StartCommunication(ctrl);
                if (retVal & E_OK) {
                        rpp_fr_state = RPP_FR_RUNNING;