kwp2000_tp.c 19.2 KB
Newer Older
hu's avatar
hu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

/*
*********************************************************************
* Includes
*********************************************************************
*/

#include "kwp2000_interface.h"
#include "kwp2000_tp.h"

/*
*********************************************************************
* defines
*********************************************************************
*/
/* Possible initialization formats */
hu's avatar
hu committed
17 18 19 20
#define KWP2000_FORMAT_NOADDRESS 0u            /* 00 */
#define KWP2000_FORMAT_CARB 1u                 /* 01 Exception mode */
#define KWP2000_FORMAT_PHYSICALADDRESSING 2u   /* 10 */
#define KWP2000_FORMAT_FUNCTIONALADDRESSING 3u /* 11 */
hu's avatar
hu committed
21

hu's avatar
hu committed
22
#define KWP2000_WUP_TI_IDLE_DU 5ul /* idle time of RX pins [us] */
hu's avatar
hu committed
23

hu's avatar
hu committed
24 25
#define KWP2000_WUP_TI_MIN_DU 24ul /* duration of WUP, min value (low time/hi time) [ms]  */
#define KWP2000_WUP_TI_MAX_DU 26ul /* duration of WUP, max value (low time/hi time) [ms]  */
hu's avatar
hu committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39

/*
*********************************************************************
* structure
*********************************************************************
*/

typedef enum
{
    KWP2000_WUP_WAIT4IDLE_E = 0x00,
    KWP2000_WUP_WAIT4SCANLO_E = 0x10,
    KWP2000_WUP_SCANLO_E,
    KWP2000_WUP_WAIT4SCANHI_E = 0x20,
    KWP2000_WUP_SCANHI_E,
hu's avatar
hu committed
40
    KWP2000_WUP_SCANASC_E = 0x30,
hu's avatar
hu committed
41 42 43 44 45
    KWP2000_WUP_DETECTED_E = 0x80,
} Kwp2000_ScanStates_t;

typedef struct
{
hu's avatar
hu committed
46 47 48
    unsigned long xPortIn_pu32;
    unsigned long xPortInMsk_u32;
    unsigned long tiStartSample_u32;
hu's avatar
hu committed
49
    Kwp2000_ScanStates_t xScanState_u32;
hu's avatar
hu committed
50 51
    unsigned char xBusType_u32;
    unsigned long tiCom_u32;
hu's avatar
hu committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
} Kwp2000_ScanWup_t;

/*
*********************************************************************
* variable
*********************************************************************
*/

/* Carb address and format */
unsigned char kwp2000_CARB_Address;
unsigned char kwp2000_CARB_TgtRequest;
unsigned char kwp2000_CARB_TgtResponse;
unsigned char kwp2000_CARB_Fmt;

unsigned long Kwp2000_TimeCounter;
unsigned long Kwp2000_P2_TimeCounter;
unsigned long Kwp2000_ComMode;
hu's avatar
hu committed
69 70
Kwp2000_ScanWup_t Kwp2000_ScanWup;
Kwp2000_Modify_t Kwp2000_Modify;
hu's avatar
hu committed
71 72 73 74 75 76 77 78
Kwp2000_ComState_t Kwp2000_ComState;

/*
*********************************************************************
* function
*********************************************************************
*/

hu's avatar
hu committed
79
void Kwp2000_ProtocolInit(void);
hu's avatar
hu committed
80 81 82

/*-------------------------------------------------------------------------
* Function Name  : Kwp2000_Init
hu's avatar
hu committed
83
* Description    : Kwp2000初始化
hu's avatar
hu committed
84 85 86 87 88 89 90 91 92 93 94 95 96
* Input          :
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void Kwp2000_Init(void)
{
    Kwp2000_AscInit();
    Kwp2000_ProtocolInit();
}

/*-------------------------------------------------------------------------
* Function Name  : Kwp2000_ProtocolInit
hu's avatar
hu committed
97
* Description    : KWP2000协议初始化
hu's avatar
hu committed
98 99 100 101 102
* Input          :
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
hu's avatar
hu committed
103
void Kwp2000_ProtocolInit(void)
hu's avatar
hu committed
104 105 106 107 108 109 110 111
{
    /* Initial time base */
    Kwp2000_TimeCounter = 0;
    Kwp2000_P2_TimeCounter = 0;

    /* Prepare Wup scan */
    Kwp2000_ComMode = COM_INIT;

hu's avatar
hu committed
112
    Kwp2000_ScanWup.xScanState_u32 = KWP2000_WUP_WAIT4IDLE_E;
hu's avatar
hu committed
113 114
    Kwp2000_ScanWup.tiStartSample_u32 = Kwp2000_TimeCounter;

hu's avatar
hu committed
115
    //Uart_DisableReceiveIsrReq(); /*----20220309----*/
hu's avatar
hu committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178

    /*Set RX as GPIO-IN*/
    Uart_SetRxGpio();

    Kwp2000_Modify.typeOfModif = KWP2000_MODIFY_NULL;

    Kwp2000_ComState.Rx_len = 0;

    Kwp2000_SetAddress();
    Kwp2000_SetTiming();

    kwp2000_CARB_TgtRequest = 0x6A;
    kwp2000_CARB_TgtResponse = 0x6B;

    Kwp2000_ComState.ResponsePending = 0;
}

/*-------------------------------------------------------------------------
* Function Name  : Kwp2000_Timeout
* Description    :
* Input          :
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void Kwp2000_Timeout(void)
{
    unsigned long tiSample_u32;

    if ((Kwp2000_ComMode & PROTOCOL) == KWP2000)
    {
        tiSample_u32 = Kwp2000_TimeCounter;

        /**/
        if (Kwp2000_ComMode == KWP2000_FAST_INIT)
        {

            if ((tiSample_u32 - Kwp2000_ComState.tiCom_u32) >= 20u)
            {
                Kwp2000_ProtocolInit();
            }
        }
        else
        {

            if ((tiSample_u32 - Kwp2000_ComState.tiCom_u32) >= kwp2000_P3_MAX_LIMIT)
            {
                Kwp2000_ProtocolInit();
            }
        }
        /*
        tiSample_u32 = Kwp2000_TimeCounter;

        if((tiSample_u32 - Kwp2000_ComState.tiCom_u32) >= kwp2000_P3_MAX_LIMIT)
        {
            Kwp2000_ProtocolInit();
        }
        */
    }
}

/*-------------------------------------------------------------------------
* Function Name  : Kwp2000_CommuniationDown
hu's avatar
hu committed
179
* Description    : 通讯底层与协议层初始化
hu's avatar
hu committed
180 181 182 183 184
* Input          :
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
hu's avatar
hu committed
185
void Kwp2000_CommuniationDown(void)
hu's avatar
hu committed
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
{
    Kwp2000_AscInit();
    Kwp2000_ProtocolInit();
}

/*-------------------------------------------------------------------------
* Function Name  : Kwp2000_VerifyChecksum
* Description    : Verify the message checksum
* Input          :
* Output         : None
* Return         : TRUE or FALSE
* onther         :
--------------------------------------------------------------------------*/
unsigned char Kwp2000_VerifyChecksum(void)
{
    unsigned char answer;
    unsigned char CS;

    /* Calculates the message Checksum */
    CS = Kwp2000_ChecksumCalculate((unsigned char *) & (Kwp2000_ComState.RxBuffer[0]), (unsigned short)(Kwp2000_ComState.headerSize + Kwp2000_ComState.kwp2000_Len));
    /* Verifies it with the one that was in the message */
    if (CS == Kwp2000_ComState.kwp2000_Checksum)
    {
        /* it is ok */
        answer = 1;
    }
    else
    {
        /* it is not the same */
        answer = 0;
    }

    return (answer);
}

/*-------------------------------------------------------------------------
* Function Name  : Kwp2000_ChecksumCalculate
* Description    : calculates the checksum
* Input          : dataBuffer, numberOfBytes
* Output         : None
* Return         : sum
* onther         :
--------------------------------------------------------------------------*/
unsigned char Kwp2000_ChecksumCalculate(unsigned char *dataBuffer, unsigned short numberOfBytes)
{
    unsigned char sum;
    unsigned short i;

    /* Resets the sum */
    sum = 0;

hu's avatar
hu committed
237
    for (i = 0; i < numberOfBytes; i++)
hu's avatar
hu committed
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
    {
        /* add each byte to the sum */
        sum += dataBuffer[i];
    }

    return (sum);
}

/*-------------------------------------------------------------------------
* Function Name  : Kwp2000_PrepareHeader
* Description    : constructs the message header
* Input          : headerSize
* Output         : dataSize
* Return         : sum
* onther         :
--------------------------------------------------------------------------*/
unsigned char Kwp2000_PrepareHeader(unsigned char dataSize)
{
    unsigned char headerSize;
    unsigned char fmt;

    /* Resets the header size */
    headerSize = 1;
    /* Tests the data size */
    if (dataSize > 63)
    {
        /* Too big to be written in the format byte, needs additional length byte */
        fmt = Kwp2000_ComState.Format << 6;
        Kwp2000_ComState.TxBuffer[4 - (headerSize++)] = dataSize;
    }
    else
    {
        /* Format and size in the same byte */
        fmt = (Kwp2000_ComState.Format << 6) | dataSize;
    }
    /* Test the format used */
    switch (Kwp2000_ComState.Format)
    {
hu's avatar
hu committed
276
    case KWP2000_FORMAT_NOADDRESS:
hu's avatar
hu committed
277 278
        /* if no address then nothing to be added to the header */
        break;
hu's avatar
hu committed
279
    case KWP2000_FORMAT_CARB:
hu's avatar
hu committed
280 281 282 283 284
        //   /* CARB mode */
        //   fmt = kwp2000_CARB_Fmt;
        //   asc0_CommunicationBuf.b[4-(headerSize++)]= kwp2000_CARB_Address;
        //   asc0_CommunicationBuf.b[4-(headerSize++)]= kwp2000_CARB_TgtResponse;
        break;
hu's avatar
hu committed
285 286
    case KWP2000_FORMAT_FUNCTIONALADDRESSING:
    case KWP2000_FORMAT_PHYSICALADDRESSING:
hu's avatar
hu committed
287 288
        /* Physical addressing */
        Kwp2000_ComState.TxBuffer[4 - (headerSize++)] = kwp2000_PhysicalAddress;
hu's avatar
hu committed
289
        Kwp2000_ComState.TxBuffer[4 - (headerSize++)] = Kwp2000_ComState.SrcAddr; // kwp2000_ServerAddress;
hu's avatar
hu committed
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
        break;
    }
    Kwp2000_ComState.TxBuffer[4 - headerSize] = fmt;

    Kwp2000_ComState.Response_Datas = (unsigned char *)&Kwp2000_ComState.TxBuffer[4 - headerSize];

    return (headerSize);
}

/*-------------------------------------------------------------------------
* Function Name  : Kwp2000_FormatAnalyse
* Description    : Copies the datas from the buffer to the variables related to the header information
* Input          :
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void Kwp2000_HeaderAnalyse(void)
{
    /* Tests the header size */
    switch (Kwp2000_ComState.headerSize)
    {
hu's avatar
hu committed
312
    case 1:
hu's avatar
hu committed
313 314
        /* 1 byte  -> FMT */
        break;
hu's avatar
hu committed
315
    case 2:
hu's avatar
hu committed
316 317 318
        /* 2 bytes -> FMT LEN */
        Kwp2000_ComState.kwp2000_Len = Kwp2000_ComState.RxBuffer[1];
        break;
hu's avatar
hu committed
319
    case 3:
hu's avatar
hu committed
320 321 322 323
        /* 3 bytes -> FMT TGT SRC */
        Kwp2000_ComState.TgtAddr = Kwp2000_ComState.RxBuffer[1];
        Kwp2000_ComState.SrcAddr = Kwp2000_ComState.RxBuffer[2];
        break;
hu's avatar
hu committed
324
    case 4:
hu's avatar
hu committed
325 326 327 328 329 330 331 332 333 334
        /* 4 bytes -> FMT TGT SRC LEN */
        Kwp2000_ComState.TgtAddr = Kwp2000_ComState.RxBuffer[1];
        Kwp2000_ComState.SrcAddr = Kwp2000_ComState.RxBuffer[2];
        Kwp2000_ComState.kwp2000_Len = Kwp2000_ComState.RxBuffer[3];
        break;
    }
}

/*-------------------------------------------------------------------------
* Function Name  : Kwp2000_FormatAnalyse
hu's avatar
hu committed
335
* Description    : ����֡����
hu's avatar
hu committed
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
* Input          :
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
unsigned char Kwp2000_FormatAnalyse(void)
{
    unsigned char headerSize;

    /* Extracts the format information */
    Kwp2000_ComState.Format = (Kwp2000_ComState.RxBuffer[0] & 0xC0) >> 6;
    /* Extracts the message length */
    Kwp2000_ComState.kwp2000_Len = Kwp2000_ComState.RxBuffer[0] & 0x3F;
    /* Resets the headerSize */
    headerSize = 1;
    /* Tests the format */
    switch (Kwp2000_ComState.Format)
    {
hu's avatar
hu committed
354
    case KWP2000_FORMAT_NOADDRESS:
hu's avatar
hu committed
355 356
        /* There is no address */
        break;
hu's avatar
hu committed
357
    case KWP2000_FORMAT_CARB:
hu's avatar
hu committed
358 359
        /* There are source and target addresses */
        Kwp2000_ComState.kwp2000_Len = 0;
hu's avatar
hu committed
360 361
    case KWP2000_FORMAT_PHYSICALADDRESSING:
    case KWP2000_FORMAT_FUNCTIONALADDRESSING:
hu's avatar
hu committed
362 363 364 365 366 367 368 369 370 371 372 373 374 375
        /* There are source and target addresses */
        headerSize += 2;
        break;
    }
    /* Tests the message length */
    if (Kwp2000_ComState.kwp2000_Len == 0)
    {
        /* it was 0 so there is an additional length byte */
        headerSize++;
    }
    else
    {
    }
    /* Sets the pointer at the beginning of the datas */
hu's avatar
hu committed
376
    Kwp2000_ComState.Request_Datas = (unsigned char *) & (Kwp2000_ComState.RxBuffer[headerSize]);
hu's avatar
hu committed
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403

    return (headerSize);
}

/*-------------------------------------------------------------------------
* Function Name  : kwp2000_AddressTest
* Description    : verifies the target address to know if this ECU is the target
* Input          :
* Output         : None
* Return         : TRUE or FALSE
* onther         :
--------------------------------------------------------------------------*/
unsigned char kwp2000_AddressTest(void)
{
    unsigned char answer = 0;

    /* Tests the format */
    if (Kwp2000_ComState.Format == KWP2000_FORMAT_NOADDRESS)
    {
        /* No addressing bytes */
        /* The message is for this ECU */
        answer = 1;
    }
    else
    {
        switch (Kwp2000_ComState.Format)
        {
hu's avatar
hu committed
404
        case KWP2000_FORMAT_CARB:
hu's avatar
hu committed
405 406 407 408 409 410 411 412 413 414 415 416
            /* CARB addressing mode */
            if (Kwp2000_ComState.TgtAddr == kwp2000_CARB_TgtRequest)
            {
                /* it is the correct address */
                answer = 1;
            }
            else
            {
                /* it is the false address */
                answer = 0;
            }
            break;
hu's avatar
hu committed
417
        case KWP2000_FORMAT_PHYSICALADDRESSING:
hu's avatar
hu committed
418 419 420 421 422 423 424 425 426 427 428 429
            /* Physical addressing mode */
            if (Kwp2000_ComState.TgtAddr == kwp2000_PhysicalAddress)
            {
                /* it is the correct address */
                answer = 1;
            }
            else
            {
                /* it is the false address */
                answer = 0;
            }
            break;
hu's avatar
hu committed
430
        case KWP2000_FORMAT_FUNCTIONALADDRESSING:
hu's avatar
hu committed
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
            /* Functional addressing mode */
            if ((Kwp2000_ComState.TgtAddr == kwp2000_FunctionalAddress) || (Kwp2000_ComState.TgtAddr == kwp2000_PhysicalAddress))
            {
                /* it is the correct address */
                answer = 1;
            }
            else
            {
                /* it is the false address */
                answer = 0;
            }
            break;
        default:
            break;
        }
    }

    return (answer);
}

/*-------------------------------------------------------------------------
* Function Name  : Kwp2000_ComInit_Handle
hu's avatar
hu committed
453
* Description    : 测量Twup
hu's avatar
hu committed
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
* Input          :
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void Kwp2000_ComInit_Handle(void)
{
    unsigned char RxPortState;

    /* scan all RX-pins, which are configured, for WUP */
    RxPortState = Uart_GetRxLevel();

    /* scan WUP (100ms) for each ASC available */

    /* wait Tidle */
    if (Kwp2000_ScanWup.xScanState_u32 == KWP2000_WUP_WAIT4IDLE_E)
    {
        if (RxPortState != 0)
        {
            if ((Kwp2000_TimeCounter - Kwp2000_ScanWup.tiStartSample_u32) >= KWP2000_WUP_TI_IDLE_DU)
            {
                Kwp2000_ScanWup.xScanState_u32 = KWP2000_WUP_WAIT4SCANLO_E;
            }
        }
        else
        {
            Kwp2000_ScanWup.tiStartSample_u32 = Kwp2000_TimeCounter;
        }
    }

    /* wait for low level on RX-pin and start time measurement */
    if (Kwp2000_ScanWup.xScanState_u32 == KWP2000_WUP_WAIT4SCANLO_E)
    {
        if (RxPortState == 0)
        {
            Kwp2000_ScanWup.xScanState_u32 = KWP2000_WUP_SCANLO_E;
            Kwp2000_ScanWup.tiStartSample_u32 = Kwp2000_TimeCounter;
        }
    }
    // measure low level time on RX-pin, if level changes to high during the first 25ms
    // abort measurement
    if (Kwp2000_ScanWup.xScanState_u32 == KWP2000_WUP_SCANLO_E)
    {
        if (RxPortState != 0)
        {
hu's avatar
hu committed
499
            if (((Kwp2000_TimeCounter - Kwp2000_ScanWup.tiStartSample_u32) >= KWP2000_WUP_TI_MIN_DU) && ((Kwp2000_TimeCounter - Kwp2000_ScanWup.tiStartSample_u32) <= KWP2000_WUP_TI_MAX_DU))
hu's avatar
hu committed
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
            {
                Kwp2000_ScanWup.tiStartSample_u32 = Kwp2000_TimeCounter;
                Kwp2000_ScanWup.xScanState_u32 = KWP2000_WUP_WAIT4SCANHI_E;
            }
            else
            {
                Kwp2000_ScanWup.tiStartSample_u32 = Kwp2000_TimeCounter;
                Kwp2000_ScanWup.xScanState_u32 = KWP2000_WUP_WAIT4IDLE_E;
            }
        }
    }
    // After 25ms - 4%, wait until RX-pin level goes hi
    // If level stays low, abort measurement
    if (Kwp2000_ScanWup.xScanState_u32 == KWP2000_WUP_WAIT4SCANHI_E)
    {
        if (RxPortState != 0)
        {
            if ((Kwp2000_TimeCounter - Kwp2000_ScanWup.tiStartSample_u32) >= KWP2000_WUP_TI_MIN_DU)
            {
                Kwp2000_ScanWup.xScanState_u32 = KWP2000_WUP_DETECTED_E;

hu's avatar
hu committed
521
                Uart_SetRxGpio(); // RX
hu's avatar
hu committed
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
                Kwp2000_AscEnableRx();

                /* reset variables, which are used by the receive interrupt function */
                Kwp2000_ComState.Rx_len = 0;

                /* enable irq */
                Uart_EnableReceiveIsrReq();

                Kwp2000_ComMode = KWP2000_FAST_INIT;

                Kwp2000_ComState.tiCom_u32 = Kwp2000_TimeCounter;
            }
        }
        else
        {
            if (RxPortState == 0)
            {
                Kwp2000_ScanWup.tiStartSample_u32 = Kwp2000_TimeCounter;
                Kwp2000_ScanWup.xScanState_u32 = KWP2000_WUP_WAIT4IDLE_E;
            }
        }
    }

    Kwp2000_TimeCounter += 1;
    Kwp2000_P2_TimeCounter += 1;
}

/*-------------------------------------------------------------------------
* Function Name  : Kwp2000_AscRxInterrupt
hu's avatar
hu committed
551
* Description    : 串口接收中断
hu's avatar
hu committed
552 553 554 555 556
* Input          :
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
hu's avatar
hu committed
557
void Kwp2000_AscRxInterrupt(void)
hu's avatar
hu committed
558
{
hu's avatar
hu committed
559
    unsigned short rxUartData;
hu's avatar
hu committed
560

hu's avatar
hu committed
561
    Uart_ClearRxFullFlag(); /* clear service request flags */
hu's avatar
hu committed
562 563 564 565 566 567 568 569 570 571 572 573 574

    if ((Kwp2000_ComMode & PROTOCOL) == KWP2000)
    {
        if (Kwp2000_ComMode < KWP2000_BUILD_RESPONSE)
        {
            /* if receve on going */
            if (Kwp2000_ComMode == KWP2000_FAST_INIT)
            {
                Kwp2000_ComMode = KWP2000_WAIT_RECEPTION;
            }

            if (Kwp2000_ComState.Rx_len < KWP2000_RX_BUFFER_SIZE)
            {
hu's avatar
hu committed
575
                rxUartData = Uart_GetData(); /*读取串口数据 ----20220303----*/
hu's avatar
hu committed
576 577 578 579 580

                Kwp2000_ComState.RxBuffer[Kwp2000_ComState.Rx_len] = (unsigned char)rxUartData;

                Kwp2000_ComState.tiCom_u32 = Kwp2000_TimeCounter;

hu's avatar
hu committed
581
                Kwp2000_ComState.Rx_len++;
hu's avatar
hu committed
582 583 584 585 586
            }
        }
        else
        {
            /* if transmit on going, do nothing */
hu's avatar
hu committed
587
            rxUartData = Uart_GetData(); /* 读取串口数据----20220303----*/
hu's avatar
hu committed
588 589 590 591 592 593 594 595 596 597 598 599

            if (Kwp2000_ComState.Tx_len)
            {
                Kwp2000_ComState.Tx_len--;
            }

            if (Kwp2000_ComState.Tx_len > 0)
            {
                if (rxUartData == (*Kwp2000_ComState.Response_Datas))
                {
                    Kwp2000_P2_TimeCounter = 0;
                    Kwp2000_ComState.Response_Datas++;
hu's avatar
hu committed
600
                    Kwp2000_AscTx(Kwp2000_ComState.Response_Datas); /* 数据发送----20220303----*/
hu's avatar
hu committed
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
                }
                else
                {
                    Kwp2000_ComState.Tx_len = 0;
                    Kwp2000_ComMode = KWP2000_WAIT_RECEPTION;
                }
            }
            else
            {
                if (Kwp2000_ComState.ResponsePending)
                {
                    Kwp2000_ComMode = KWP2000_BUILD_RESPONSE;

                    /* Start a new timeout counter */
                    Kwp2000_ComState.tiCom_u32 = Kwp2000_TimeCounter;
                }
                else
                {
                    Kwp2000_ComMode = KWP2000_MODIFY_CONFIG;
                }
            }
        }
    }
}