• hu's avatar
    debug · 27886e59
    hu authored
    27886e59
UART.c 24.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 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 179 180 181 182 183 184 185 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 237 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 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 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 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 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 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 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 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925
//#include "r_typedefs.h"
#include "dr7f701441.dvf.h"
#include "UART.h"
//#include "rh850_macros.h"
#include "GPIO.h"
#include "r_dev_api.h"

#include "kwp2000_tp.h"

/*-----------------use for RH850_D1M1A --------------------*/
/*******************************************************************/

#define UART_BASE_ADDRESS 0xFFCE0000UL
#define UART_CKSCLK_ILIN 48000000UL
#define UART_TIME_OUT 10000UL

/*******************************************************************/

uint32_t UART_Init(UART_Channel_en_t enUARTCh, UART_Channel_Config_st_t *penUARTCfg);
void UART_Sleep_Init(void);
/*******************************************************************/
/*******************************************************************/
/*******************************************************************/
#define UART_LSB_FIRST (0U << 1U)
#define UART_MSB_FIRST (1U << 1U)

#define UART_INT_AT_START (0U << 3U)
#define UART_INT_AT_FINISH (1U << 3U)
/*******************************************************/
typedef struct
{
    uint8_t u8UARTCount;      /*发送计数*/
    uint8_t u8UARTLEN;        /*发送数据总长*/
    uint8_t u8UARTTXBusyFlag; /*发送是否忙标志  0:idle  1:busy */
    uint8_t *pu8UARTDataBuf;  /*要发送数据的指针*/
} UART_Ctr_st_t;
/*******************************************************/

static UART_Ctr_st_t stUARTCtr0;
static UART_Ctr_st_t stUARTCtr1;
static UART_Ctr_st_t stUARTCtr2;
static UART_Ctr_st_t stUARTCtr3;

static UART_Channel_Config_st_t stUARTCh0Cfg;
static UART_Channel_Config_st_t stUARTCh1Cfg;
static UART_Channel_Config_st_t stUARTCh2Cfg;
static UART_Channel_Config_st_t stUARTCh3Cfg;

/*******************************************************/
static void UART_Variate_Init(UART_Channel_en_t enUARTCh)
{
    switch (enUARTCh)
    {
    case UART_RLIN30:
    {
        stUARTCtr0.u8UARTCount = 0U;
        stUARTCtr0.u8UARTLEN = 0U;
        stUARTCtr0.u8UARTTXBusyFlag = 0U;
        stUARTCtr0.pu8UARTDataBuf = 0U;

        stUARTCh0Cfg.u32UARTChEn = 0U;
        stUARTCh0Cfg.u32UARTbps = 0U;
        stUARTCh0Cfg.pfnUARTConfirmCallBack = 0U;
        stUARTCh0Cfg.pfnUARTReadMsgCallBack = 0U;
        break;
    }
    case UART_RLIN31:
    {
        stUARTCtr1.u8UARTCount = 0U;
        stUARTCtr1.u8UARTLEN = 0U;
        stUARTCtr1.u8UARTTXBusyFlag = 0U;
        stUARTCtr1.pu8UARTDataBuf = 0U;

        stUARTCh1Cfg.u32UARTChEn = 0U;
        stUARTCh1Cfg.u32UARTbps = 0U;
        stUARTCh1Cfg.pfnUARTConfirmCallBack = 0U;
        stUARTCh1Cfg.pfnUARTReadMsgCallBack = 0U;
        break;
    }
    case UART_RLIN32:
    {
        stUARTCtr2.u8UARTCount = 0U;
        stUARTCtr2.u8UARTLEN = 0U;
        stUARTCtr2.u8UARTTXBusyFlag = 0U;
        stUARTCtr2.pu8UARTDataBuf = 0U;

        stUARTCh2Cfg.u32UARTChEn = 0U;
        stUARTCh2Cfg.u32UARTbps = 0U;
        stUARTCh2Cfg.pfnUARTConfirmCallBack = 0U;
        stUARTCh2Cfg.pfnUARTReadMsgCallBack = 0U;

        break;
    }
    case UART_RLIN33:
    {
        stUARTCtr3.u8UARTCount = 0U;
        stUARTCtr3.u8UARTLEN = 0U;
        stUARTCtr3.u8UARTTXBusyFlag = 0U;
        stUARTCtr3.pu8UARTDataBuf = 0U;

        stUARTCh3Cfg.u32UARTChEn = 0U;
        stUARTCh3Cfg.u32UARTbps = 0U;
        stUARTCh3Cfg.pfnUARTConfirmCallBack = 0U;
        stUARTCh3Cfg.pfnUARTReadMsgCallBack = 0U;
        break;
    }

    default:
        break;
    }
}

/*
返回设置成功的波特率,返回0xFFFFFFFF表示设置失败。
*/
uint32_t UART_Init(UART_Channel_en_t enUARTCh, UART_Channel_Config_st_t *penUARTCfg)
{
    uint32_t u32UARTAddressBase = 0UL;
    uint32_t u32UARTAddress = 0UL;
    uint32_t u32UARTCalBuf = 0UL;
    uint32_t u32UARTCount = 0UL;

    if ((enUARTCh < UART_RLIN_MAX) && (penUARTCfg->u32UARTChEn) && (penUARTCfg->u32UARTbps))
    {
        u32UARTAddressBase = UART_BASE_ADDRESS + 0x1000UL * enUARTCh;

        u32UARTAddress = u32UARTAddressBase + 0x20U;
        (*((uint8_t *)(u32UARTAddress))) = 0X00U;
        //  RLN31LUOER = 0X00U;

        u32UARTAddress = u32UARTAddressBase + 0x08U;
        (*((uint8_t *)(u32UARTAddress))) = 0X00U;
        // RLN31LMD = 0X0U;
        /*****LIN reset mode*/
        u32UARTAddress = u32UARTAddressBase + 0x0EU;
        (*((uint8_t *)(u32UARTAddress))) = 0X00U;
        //  RLN31LCUC = 0X0U;
        u32UARTCount = 0UL;
        u32UARTAddress = u32UARTAddressBase + 0x11U;
        while (((*((uint8_t *)(u32UARTAddress))) != 0U) && (u32UARTCount < UART_TIME_OUT))
            //  while (RLN31LMST != 0U)
        {
            u32UARTCount++;
        }

        UART_Variate_Init(enUARTCh);

        /** baud rate**/
        u32UARTAddress = u32UARTAddressBase + 0x01U;
        (*((uint8_t *)(u32UARTAddress))) = 0X50U;
        /*6 samplings  Prescaler Clock Select1/1*/
        // RLN31LWBR = 0X50U;

        u32UARTCalBuf = UART_CKSCLK_ILIN / 6UL / penUARTCfg->u32UARTbps;
        if (u32UARTCalBuf <= 65536U)
        {
            u32UARTAddress = u32UARTAddressBase + 0x02U;
            (*((uint16_t *)(u32UARTAddress))) = u32UARTCalBuf - 1U;
            // RLN31LBRP01 = u32UARTCalBuf - 1U;
            penUARTCfg->u32UARTbps = UART_CKSCLK_ILIN / 6UL / u32UARTCalBuf;
        }
        else
        {
            penUARTCfg->u32UARTbps = 0xFFFFFFFFUL;
        }

        /**The noise filter is enabled**/
        u32UARTAddress = u32UARTAddressBase + 0x08U;
        (*((uint8_t *)(u32UARTAddress))) = 0X01U;
        // RLN31LMD = 0X01U;

        /**disable error detection.**/
        u32UARTAddress = u32UARTAddressBase + 0x0DU;
        (*((uint8_t *)(u32UARTAddress))) = 0X00U;
        //  RLN31LEDE = 0U;
        /*** data format   N81*/
        u32UARTAddress = u32UARTAddressBase + 0x09U;
        (*((uint8_t *)(u32UARTAddress))) = UART_LSB_FIRST;
        // RLN31LBFC = UART_MSB_FIRST;
        /*Transmission interrupt is generated at.*/
        u32UARTAddress = u32UARTAddressBase + 0x21U;
        (*((uint8_t *)(u32UARTAddress))) = UART_INT_AT_FINISH;
        // RLN31LUOR1 = UART_INT_AT_FINISH;
        /******Exits from LIN reset mode***/
        u32UARTAddress = u32UARTAddressBase + 0x0EU;
        (*((uint8_t *)(u32UARTAddress))) = 0X01U;
        // RLN31LCUC = 0X01U;

        u32UARTCount = 0UL;
        u32UARTAddress = u32UARTAddressBase + 0x11U;
        while (((*((uint8_t *)(u32UARTAddress))) != 0X01U) && (u32UARTCount < UART_TIME_OUT))
            //  while (RLN31LMST != 0X01U)
        {
            u32UARTCount++;
        }

        u32UARTAddress = u32UARTAddressBase + 0x13U;
        (*((uint8_t *)(u32UARTAddress))) = 0X0U;
        // RLN31LEST = 0X0U; /*clear Error Flag , it doesn't matter*/

        u32UARTAddress = u32UARTAddressBase + 0x20U;
        (*((uint8_t *)(u32UARTAddress))) = 0X03U;
        //  RLN31LUOER = 0X03U; /*TX RX EN*/

        /***************************/
        /**********NO USE*****************/

        /***************************/

        if (enUARTCh == UART_RLIN30)
        {
            stUARTCh0Cfg = *penUARTCfg;
            R_DEV_IntEnable(R_DEV_INT_RLIN30R, 1U);
            R_DEV_IntEnable(R_DEV_INT_RLIN30T, 1U);
        }
        else if (enUARTCh == UART_RLIN31)
        {
            stUARTCh1Cfg = *penUARTCfg;
            R_DEV_IntEnable(R_DEV_INT_RLIN31R, 1U);
            R_DEV_IntEnable(R_DEV_INT_RLIN31T, 1U);
        }
        else if (enUARTCh == UART_RLIN32)
        {
            stUARTCh2Cfg = *penUARTCfg;
            R_DEV_IntEnable(R_DEV_INT_RLIN32R, 1U);
            R_DEV_IntEnable(R_DEV_INT_RLIN32T, 1U);
        }
        else if (enUARTCh == UART_RLIN33)
        {
            stUARTCh3Cfg = *penUARTCfg;
            R_DEV_IntEnable(R_DEV_INT_RLIN33R, 1U);
            R_DEV_IntEnable(R_DEV_INT_RLIN33T, 1U);
        }

        /***************************/
    }
    return penUARTCfg->u32UARTbps;
}

void UART_Sleep_Init(void)
{
    uint32_t u32UARTCount = 0UL;
    uint32_t u32UARTAddressBase = 0UL;
    uint32_t u32UARTAddress = 0UL;
    UART_Channel_en_t enUARTCh;

    enUARTCh = UART_RLIN32;

    if ((enUARTCh < UART_RLIN_MAX))
    {
        u32UARTAddressBase = UART_BASE_ADDRESS + 0x1000UL * enUARTCh;

        u32UARTAddress = u32UARTAddressBase + 0x20U;
        (*((uint8_t *)(u32UARTAddress))) = 0X00U;
        //  RLN31LUOER = 0X00U;

        u32UARTAddress = u32UARTAddressBase + 0x08U;
        (*((uint8_t *)(u32UARTAddress))) = 0X00U;
        // RLN31LMD = 0X0U;
        /*****LIN reset mode*/
        u32UARTAddress = u32UARTAddressBase + 0x0EU;
        (*((uint8_t *)(u32UARTAddress))) = 0X00U;
        //  RLN31LCUC = 0X0U;
        u32UARTCount = 0UL;
        u32UARTAddress = u32UARTAddressBase + 0x11U;
        while (((*((uint8_t *)(u32UARTAddress))) != 0U) && (u32UARTCount < UART_TIME_OUT))
            //  while (RLN31LMST != 0U)
        {
            u32UARTCount++;
        }
    }
    UART_Variate_Init(enUARTCh);
}
/*
0:idle
1:busy
*/
uint8_t UART_Ch0_Get_TX_Busy_Flag(void)
{
    uint8_t u8Status = 0U;
    if ((RLN30LST & 0x10U) || (stUARTCtr0.u8UARTTXBusyFlag))
    {
        u8Status = 1U;
    }
    return u8Status;
}
uint8_t UART_Ch1_Get_TX_Busy_Flag(void)
{
    uint8_t u8Status = 0U;
    if ((RLN31LST & 0x10U) || (stUARTCtr1.u8UARTTXBusyFlag))
    {
        u8Status = 1U;
    }
    return u8Status;
}
uint8_t UART_Ch2_Get_TX_Busy_Flag(void)
{
    uint8_t u8Status = 0U;
    if ((RLN32LST & 0x10U) || (stUARTCtr2.u8UARTTXBusyFlag))
    {
        u8Status = 1U;
    }
    return u8Status;
}
uint8_t UART_Ch3_Get_TX_Busy_Flag(void)
{
    uint8_t u8Status = 0U;
    if ((RLN33LST & 0x10U) || (stUARTCtr3.u8UARTTXBusyFlag))
    {
        u8Status = 1U;
    }
    return u8Status;
}
/*
Data:要发送数据的指针,
请确认是全局变量的指针,且指向的数据在发送完成之前不会被改变。
*/
void UART_Ch0_Send_Multiple_Byte(uint8_t *Data, uint8_t Len)
{
    if (UART_Ch0_Get_TX_Busy_Flag() == 0U)
    {
        stUARTCtr0.u8UARTCount = 1U;
        stUARTCtr0.u8UARTLEN = Len;
        stUARTCtr0.u8UARTTXBusyFlag = 1U;
        stUARTCtr0.pu8UARTDataBuf = Data;
        RLN30LUTDR = stUARTCtr0.pu8UARTDataBuf[0U];
    }
}
void UART_Ch1_Send_Multiple_Byte(uint8_t *Data, uint8_t Len)
{
    if (UART_Ch1_Get_TX_Busy_Flag() == 0U)
    {
        stUARTCtr1.u8UARTCount = 1U;
        stUARTCtr1.u8UARTLEN = Len;
        stUARTCtr1.u8UARTTXBusyFlag = 1U;
        stUARTCtr1.pu8UARTDataBuf = Data;
        RLN31LUTDR = stUARTCtr1.pu8UARTDataBuf[0U];
    }
}
void UART_Ch2_Send_Multiple_Byte(uint8_t *Data, uint8_t Len)
{
    if (UART_Ch2_Get_TX_Busy_Flag() == 0U)
    {
        stUARTCtr2.u8UARTCount = 1U;
        stUARTCtr2.u8UARTLEN = Len;
        stUARTCtr2.u8UARTTXBusyFlag = 1U;
        stUARTCtr2.pu8UARTDataBuf = Data;
        RLN32LUTDR = stUARTCtr2.pu8UARTDataBuf[0U];
    }
}
void UART_Ch3_Send_Multiple_Byte(uint8_t *Data, uint8_t Len)
{
    if (UART_Ch3_Get_TX_Busy_Flag() == 0U)
    {
        stUARTCtr3.u8UARTCount = 1U;
        stUARTCtr3.u8UARTLEN = Len;
        stUARTCtr3.u8UARTTXBusyFlag = 1U;
        stUARTCtr3.pu8UARTDataBuf = Data;
        RLN33LUTDR = stUARTCtr3.pu8UARTDataBuf[0U];
    }
}

void UART_CH0_RX_ISR(void)
{
    /*If no error is detected*/
    if (stUARTCh0Cfg.pfnUARTReadMsgCallBack)
    {
        stUARTCh0Cfg.pfnUARTReadMsgCallBack(RLN30LURDR);
    }
}
void UART_CH1_RX_ISR(void)
{
    /*If no error is detected*/
    if (stUARTCh1Cfg.pfnUARTReadMsgCallBack)
    {
        stUARTCh1Cfg.pfnUARTReadMsgCallBack(RLN31LURDR);
    }
}
void UART_CH2_RX_ISR(void)
{
    /*If no error is detected*/
    if (stUARTCh2Cfg.pfnUARTReadMsgCallBack)
    {
        stUARTCh2Cfg.pfnUARTReadMsgCallBack(RLN32LURDR);
    }
}
void UART_CH3_RX_ISR(void)
{
    /*If no error is detected*/
    if (stUARTCh3Cfg.pfnUARTReadMsgCallBack)
    {
        stUARTCh3Cfg.pfnUARTReadMsgCallBack(RLN33LURDR);
    }
}

void UART_CH0_TX_ISR(void)
{
    if (stUARTCtr0.u8UARTCount < stUARTCtr0.u8UARTLEN)
    {
        RLN30LUTDR = stUARTCtr0.pu8UARTDataBuf[stUARTCtr0.u8UARTCount++];
    }
    else
    {
        stUARTCtr0.u8UARTTXBusyFlag = 0U;
        if (stUARTCh0Cfg.pfnUARTConfirmCallBack)
        {
            stUARTCh0Cfg.pfnUARTConfirmCallBack();
        }
    }
}
void UART_CH1_TX_ISR(void)
{
    if (stUARTCtr1.u8UARTCount < stUARTCtr1.u8UARTLEN)
    {
        RLN31LUTDR = stUARTCtr1.pu8UARTDataBuf[stUARTCtr1.u8UARTCount++];
    }
    else
    {
        stUARTCtr1.u8UARTTXBusyFlag = 0U;
        if (stUARTCh1Cfg.pfnUARTConfirmCallBack)
        {
            stUARTCh1Cfg.pfnUARTConfirmCallBack();
        }
    }
}
void UART_CH2_TX_ISR(void)
{
    if (stUARTCtr2.u8UARTCount < stUARTCtr2.u8UARTLEN)
    {
        RLN32LUTDR = stUARTCtr2.pu8UARTDataBuf[stUARTCtr2.u8UARTCount++];
    }
    else
    {
        stUARTCtr2.u8UARTTXBusyFlag = 0U;
        if (stUARTCh2Cfg.pfnUARTConfirmCallBack)
        {
            stUARTCh2Cfg.pfnUARTConfirmCallBack();
        }
    }
}
void UART_CH3_TX_ISR(void)
{
    if (stUARTCtr3.u8UARTCount < stUARTCtr3.u8UARTLEN)
    {
        RLN33LUTDR = stUARTCtr3.pu8UARTDataBuf[stUARTCtr3.u8UARTCount++];
    }
    else
    {
        stUARTCtr3.u8UARTTXBusyFlag = 0U;
        if (stUARTCh3Cfg.pfnUARTConfirmCallBack)
        {
            stUARTCh3Cfg.pfnUARTConfirmCallBack();
        }
    }
}
/***********************************************************************/
/***********************************************************************/
/***********************************************************************/
#define UART_CH_SEL UART_RLIN32

/*****所有引脚相关根据实际引脚自行添加****/
/*****所有引脚相关根据实际引脚自行添加****/
/*****所有引脚相关根据实际引脚自行添加****/

/*-------------------------------------------------------------------------
* Function Name  : Uart_ConfigOperationMode
* Description    : 配置串口工作模式
* Input          :
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void Uart_ConfigOperationMode(void)
{
}

/*-------------------------------------------------------------------------
* Function Name  : Uart_GetRxLevel
* Description    : 提取RX 管脚电平
* Input          :
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
unsigned char Uart_GetRxLevel(void)
{
    return GPIO_IN_PORT00_PIN03;
}

/*-------------------------------------------------------------------------
* Function Name  : Uart_ClearRxFullFlag
* Description    : 清除串口接收完成标志位
* Input          :
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void Uart_ClearRxFullFlag(void)
{
    switch (UART_CH_SEL)
    {
    case UART_RLIN30:
    {
        R_DEV_IntClearFlag(R_DEV_INT_RLIN30R);
        break;
    }
    case UART_RLIN31:
    {
        R_DEV_IntClearFlag(R_DEV_INT_RLIN31R);
        break;
    }
    case UART_RLIN32:
    {
        R_DEV_IntClearFlag(R_DEV_INT_RLIN32R);
        break;
    }
    case UART_RLIN33:
    {
        R_DEV_IntClearFlag(R_DEV_INT_RLIN33R);
        break;
    }
    default:
        break;
    }
}

/*-------------------------------------------------------------------------
* Function Name  : Uart_SetBaudrate
* Description    : 设置串口波特率
* Input          :
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void UART_Read_ISR(uint16_t u16UARTData)
{
    Kwp2000_AscRxInterrupt(); //包含一下,然后打开即可
}

void Uart_SetBaudrate(unsigned long xBaudrate_u32)
{
    UART_Channel_Config_st_t stUARTConfig;

    stUARTConfig.u32UARTChEn = 1U;
    stUARTConfig.u32UARTbps = xBaudrate_u32;
    stUARTConfig.pfnUARTConfirmCallBack = 0U;
    stUARTConfig.pfnUARTReadMsgCallBack = UART_Read_ISR;

    UART_Init(UART_CH_SEL, &stUARTConfig);
}

/*-------------------------------------------------------------------------
* Function Name  : Uart_SetRxGpio
* Description    : 设置接收的GPIO
* Input          :
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void Uart_SetRxGpio(void)
{
}

/*-------------------------------------------------------------------------
* Function Name  : Uart_SetTxGpio
* Description    : 设置发送的GPIO
* Input          :
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void Uart_SetTxGpio(void)
{
}

/*-------------------------------------------------------------------------
* Function Name  : Uart_EnableRx
* Description    : 使能接收
* Input          :
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void Uart_EnableRx(void)
{
    switch (UART_CH_SEL)
    {
    case UART_RLIN30:
    {
        RLN30LUOER |= 0X02U;
        break;
    }
    case UART_RLIN31:
    {
        RLN31LUOER |= 0X02U;
        break;
    }
    case UART_RLIN32:
    {
        RLN32LUOER |= 0X02U;
        break;
    }
    case UART_RLIN33:
    {
        RLN33LUOER |= 0X02U;
        break;
    }
    default:
        break;
    }
}

/*-------------------------------------------------------------------------
* Function Name  : Uart_DisableRx
* Description    : 禁止接收
* Input          :
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void Uart_DisableRx(void)
{
    switch (UART_CH_SEL)
    {
    case UART_RLIN30:
    {
        RLN30LUOER &= 0XFDU;
        break;
    }
    case UART_RLIN31:
    {
        RLN31LUOER &= 0XFDU;
        break;
    }
    case UART_RLIN32:
    {
        RLN32LUOER &= 0XFDU;
        break;
    }
    case UART_RLIN33:
    {
        RLN33LUOER &= 0XFDU;
        break;
    }
    default:
        break;
    }
}

/*-------------------------------------------------------------------------
* Function Name  : TJA1021_Enable
* Description    : 使能收发器
* Input          :
* Output         : None
* Return         : None
* onther         : 1 使能 ; 0 关闭
--------------------------------------------------------------------------*/
void TJA1021_Enable(unsigned char state)
{
    LIN_SLP_N_MCU = state;
}

/*-------------------------------------------------------------------------
* Function Name  : Uart_EnableTx
* Description    : 使能发
* Input          :
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void Uart_EnableTx(void)
{
    switch (UART_CH_SEL)
    {
    case UART_RLIN30:
    {
        RLN30LUOER |= 0X01U;
        break;
    }
    case UART_RLIN31:
    {
        RLN31LUOER |= 0X01U;
        break;
    }
    case UART_RLIN32:
    {
        RLN32LUOER |= 0X01U;
        break;
    }
    case UART_RLIN33:
    {
        RLN33LUOER |= 0X01U;
        break;
    }
    default:
        break;
    }
}

/*-------------------------------------------------------------------------
* Function Name  : Uart_ClearAllErrorFlag
* Description    : 清除所有的错误标志位
* Input          :
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void Uart_ClearAllErrorFlag(void)
{
    switch (UART_CH_SEL)
    {
    case UART_RLIN30:
    {
        RLN30LEST = 0X0U;
        break;
    }
    case UART_RLIN31:
    {
        RLN31LEST = 0X0U;
        break;
    }
    case UART_RLIN32:
    {
        RLN32LEST = 0X0U;
        break;
    }
    case UART_RLIN33:
    {
        RLN33LEST = 0X0U;
        break;
    }
    default:
        break;
    }
}

/*-------------------------------------------------------------------------
* Function Name  : Uart_SetData
* Description    : 写串口数据
* Input          :
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void Uart_SetData(unsigned char xBuffer_pu8)
{

    switch (UART_CH_SEL)
    {
    case UART_RLIN30:
    {
        RLN30LUTDR = xBuffer_pu8;
        break;
    }
    case UART_RLIN31:
    {
        RLN31LUTDR = xBuffer_pu8;
        break;
    }
    case UART_RLIN32:
    {
        RLN32LUTDR = xBuffer_pu8;
        break;
    }
    case UART_RLIN33:
    {
        RLN33LUTDR = xBuffer_pu8;
        break;
    }
    default:
        break;
    }
}

/*-------------------------------------------------------------------------
* Function Name  : Uart_GetData
* Description    : 读取串口数据
* Input          :
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
unsigned short Uart_GetData(void)
{
    unsigned short wTemp_u08 = 0;

    switch (UART_CH_SEL)
    {
    case UART_RLIN30:
    {
        wTemp_u08 = RLN30LURDR;
        break;
    }
    case UART_RLIN31:
    {
        wTemp_u08 = RLN31LURDR;
        break;
    }
    case UART_RLIN32:
    {
        wTemp_u08 = RLN32LURDR;
        break;
    }
    case UART_RLIN33:
    {
        wTemp_u08 = RLN33LURDR;
        break;
    }
    default:
        break;
    }
    return wTemp_u08;
}

/*-------------------------------------------------------------------------
* Function Name  : Uart_DisableReceiveIsrReq
* Description    : 禁止接收中断
* Input          :
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void Uart_DisableReceiveIsrReq(void)
{
    switch (UART_CH_SEL)
    {
    case UART_RLIN30:
    {
        R_DEV_IntEnable(R_DEV_INT_RLIN30R, 0U);
        break;
    }
    case UART_RLIN31:
    {
        R_DEV_IntEnable(R_DEV_INT_RLIN31R, 0U);
        break;
    }
    case UART_RLIN32:
    {
        R_DEV_IntEnable(R_DEV_INT_RLIN32R, 0U);
        break;
    }
    case UART_RLIN33:
    {
        R_DEV_IntEnable(R_DEV_INT_RLIN33R, 0U);
        break;
    }
    default:
        break;
    }
}

/*-------------------------------------------------------------------------
* Function Name  : Uart_EnableReceiveIsrReq
* Description    : 使能接收中断
* Input          :
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void Uart_EnableReceiveIsrReq(void)
{
    switch (UART_CH_SEL)
    {
    case UART_RLIN30:
    {
        R_DEV_IntEnable(R_DEV_INT_RLIN30R, 1U);
        break;
    }
    case UART_RLIN31:
    {
        R_DEV_IntEnable(R_DEV_INT_RLIN31R, 1U);
        break;
    }
    case UART_RLIN32:
    {
        R_DEV_IntEnable(R_DEV_INT_RLIN32R, 1U);
        break;
    }
    case UART_RLIN33:
    {
        R_DEV_IntEnable(R_DEV_INT_RLIN33R, 1U);
        break;
    }
    default:
        break;
    }
}

/*-------------------------------------------------------------------------
* Function Name  : Uart_DisableTxInterrupt
* Description    : 禁止发送中断
* Input          :
* Output         : None
* Return         : None
* onther         :
--------------------------------------------------------------------------*/
void Uart_DisableTxInterrupt(void)
{

    switch (UART_CH_SEL)
    {
    case UART_RLIN30:
    {
        R_DEV_IntEnable(R_DEV_INT_RLIN30T, 0U);
        break;
    }
    case UART_RLIN31:
    {
        R_DEV_IntEnable(R_DEV_INT_RLIN31T, 0U);
        break;
    }
    case UART_RLIN32:
    {
        R_DEV_IntEnable(R_DEV_INT_RLIN32T, 0U);
        break;
    }
    case UART_RLIN33:
    {
        R_DEV_IntEnable(R_DEV_INT_RLIN33T, 0U);
        break;
    }
    default:
        break;
    }
}