tao_z
2022-06-01 0ff91e66071237834a1501c78648729c8c32f67a
Application/source/uds_modules/uds.c
@@ -223,7 +223,7 @@
static UDS_CONTOL_TYPE_e UDS_L_CommunicationControlType_e = EnableRxAndTx;
static uint8_t UDS_L_SecurityFault_cnt;
static uint8_t UDS_L_SecurityStartDelay = 1;
static uint8_t UDS_L_SecurityStartDelay = 0;
static uint8_t UDS_L_SecurityAccessStep_e = SECURITY_ACCESS_STEP_MAX;
/*****************************************************************************/
/*  Local Variables Definition                                               */
@@ -260,6 +260,7 @@
static uint16_t ResponsePendingTimer_u16;
static bool UDS_L_TransferDataInProgressing_b = false;
static bool UDS_L_CRCCheckFail_b = false;
static uint32_t UDS_L_CRCReceived = 0;
static UDS_TRANFER_DATA_STATE_Te UDS_L_TransferDataState_e;
static uint8_t expectedSequenceCnt;        /* Block sequence counter             */
@@ -356,6 +357,9 @@
#define ROUTINE_CONTROL_MIN_LEN (0x04u)
#define TESTER_PRESENT_MIN_LEN (0x02u)
#define CONTROL_DTC_SETTING_MIN_LEN (0x02u)
#define REQUEST_DOWNLOAD_MIN_LEN (0xB)
#define TRANSFER_DATA_MIN_LEN (0XC)
#define REQUEST_TRANSFER_EXIT_MIN_LEN (0X01)
typedef struct
{
@@ -423,12 +427,6 @@
    uint8_t sid;
    sid = msg_buf[0];
    if (msg_dlc < 2)
    {
        result = false;
    }
    else
    {
        subfunction = UDS_GET_SUB_FUNCTION(msg_buf[1]);
        switch (sid)
@@ -566,10 +564,33 @@
            }
        }
        break;
    case REQUEST_DOWNLOAD:
        if (msg_dlc == REQUEST_DOWNLOAD_MIN_LEN)
        {
            result = true;
        }
        else
        {
            result = false;
        }
        break;
    case TRANSFER_DATA:
        if (msg_dlc >= TRANSFER_DATA_MIN_LEN)
        {
            result = true;
        }
        else
        {
            result = false;
        }
        break;
    case REQUEST_TRANSFER_EXIT:
        result = true;
        break;
        default:
            result = false;
            break;
        }
    }
    return result;
}
@@ -700,7 +721,7 @@
    TesterPresentTimer_u16 = 0;
    UDS_NS_SessionTimeout_u16 = 5000;
    UDS_L_SecurityFault_cnt = 0;
    UDS_L_SecurityStartDelay = 1;
    UDS_L_SecurityStartDelay = 0;
    UDS_L_Diag_session_e = DEFAULT;
    UDS_O_SecurityAccessState_e = SECURITY_ACCESS_LOCKED;
    UDS_L_Current_SID = 0;
@@ -759,11 +780,20 @@
static void UDS_RxTask_1ms(void)
{
    static TP_PDU_t msg_rx_temp = {0};
    CAN_PDU_t msg_can_temp = {0};
    uint8_t msg_num = MCAN_GetReceiveMessageCounter(MCAN);
    while (msg_num--)
    {
        MCAN_ReceiveData(MCAN, (MCAN_MsgTypeDef *)(&msg_rx_temp));
        MCAN_ReceiveData(MCAN, (MCAN_MsgTypeDef *)(&msg_can_temp));
        msg_rx_temp.arbId = msg_can_temp.MCAN_ID;
        msg_rx_temp.dlc = msg_can_temp.MCAN_DLC;
        for (TP_uint8_t i = 0; i < msg_can_temp.MCAN_DLC; i++)
        {
            msg_rx_temp.frame[i] = msg_can_temp.MCAN_Data[i];
        }
        if (msg_rx_temp.arbId == UDS_PHY_REQ_RID)
        {
            UDS_RxMessage(&msg_rx_temp);
@@ -1031,12 +1061,12 @@
            if (CDT_HASEXPIRED(TesterPresentTimer_u16) != false)
            {
                UDS_SwitchtoDefaultSession(true);
                UDS_SwitchtoDefaultSession(false);
            }
        }
        else
        {
            UDS_SwitchtoDefaultSession(true);
            UDS_SwitchtoDefaultSession(false);
        }
    }
    else
@@ -1772,7 +1802,7 @@
            {
                if (transferType == DOWNLOAD_FLASH)
                {
                    UDS_L_CRCCheckFail_b = !MEM_PartitionCRCOK((uint8_t)MEM_PARTITION_CODEFLASH);
                    UDS_L_CRCCheckFail_b = !MEM_PartitionCRCOK((uint8_t)MEM_PARTITION_CODEFLASH, UDS_L_CRCReceived);
                    if (UDS_L_CRCCheckFail_b == false)
                    {
                        NVM_ReInitFlashDriveRam(); // CLEAR FLASH DRIVE IN RAM
@@ -1780,14 +1810,12 @@
                }
                else
                {
                    UDS_L_CRCCheckFail_b = !MEM_PartitionCRCOK((uint8_t)MEM_PARTITION_RAM);
                    UDS_L_CRCCheckFail_b = !MEM_PartitionCRCOK((uint8_t)MEM_PARTITION_RAM, UDS_L_CRCReceived);
                    if (UDS_L_CRCCheckFail_b == true)
                    {
                        NVM_ReInitFlashDriveRam(); // CLEAR FLASH DRIVE IN RAM
                    }
                }
                if (UDS_L_CRCCheckFail_b == false)
                {
                    UDS_L_tx_msg_buffer[0] = GET_RESPONSE_SERVICE_ID(ROUTINE_CONTROL);
                    UDS_L_tx_msg_buffer[1] = 0x01;
                    UDS_L_tx_msg_buffer[2] = 0xf0;
@@ -1802,7 +1830,6 @@
                    UDS_L_ResponsePendingRequest_e &= (~CHECK_PROGRAMMING_INTERGRITY_PENDING);
                    UDS_L_ResponsePendingRelease_e &= (~CHECK_PROGRAMMING_INTERGRITY_PENDING);
                }
            }
        }
    }
@@ -1973,7 +2000,7 @@
      FBL_UDS_L_ResponsePendingRelease_e &=(~CHECK_PROGRAMMING_INTERGRITY_PENDING); 
   }
#endif
    UDS_L_CRCReceived = (uint32_t)payload[4] << 24 | (uint32_t)payload[5] << 16 | (uint32_t)payload[6] << 8 | (uint32_t)payload[7];
    UDS_L_ResponsePendingRequest_e |= CHECK_PROGRAMMING_INTERGRITY_PENDING;
    CDT_RESET(ResponsePendingTimer_u16, P2SERVER_PENDING_TIMEROUT);
}