GPIO.c 17.6 KB
Newer Older
梁百峰's avatar
梁百峰 committed
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
#include "r_typedefs.h"
#include "dr7f701684.dvf.h"
#include "GPIO.h"

/*-----------------use for RH850_F1KM_S1 --------------------*/

#define GPIO_STB_PROTECTED_WRITE(preg, pstatus, reg, value) \
    do                                                      \
    {                                                       \
        (preg) = 0xA5U;                                     \
        (reg) = (value);                                    \
        (reg) = ~(value);                                   \
        (reg) = (value);                                    \
    } while ((pstatus) == 1U)

#define GPIO_PORTN_BASE_ADDRESS 0xFFC10000UL

typedef enum
{
    GPIO_REG_PMC = 0U,
    GPIO_REG_PIPC,
    GPIO_REG_PM,
    GPIO_REG_PIBC,
    GPIO_REG_PFC,
    GPIO_REG_PFCE,
    GPIO_REG_PFCAE,
    GPIO_REG_PBDC,
    GPIO_REG_P,
    GPIO_REG_PU,
    GPIO_REG_PD,
    GPIO_REG_PDSC,
    GPIO_REG_PODC,
    GPIO_REG_PIS,
    GPIO_REG_PPCMD,
    GPIO_REG_PPROTS,

} GPIO_Register_en_t;

const uint16_t g_u16GPIOConfigArray[56U][2U] =
{
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
梁百峰's avatar
梁百峰 committed
44
    {0x000Cu, 0x0000u},
梁百峰's avatar
梁百峰 committed
45 46 47 48
    {0x0020u, 0x0000u},
    {0x0620u, 0x0600u},
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
梁百峰's avatar
梁百峰 committed
49 50 51 52
    {0x063Cu, 0x0630u},
    {0x1A6Bu, 0x1A6Fu},
    {0x79C3u, 0x79CFu},
    {0x0000u, 0x0000u},
梁百峰's avatar
梁百峰 committed
53 54 55 56 57 58 59 60
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
梁百峰's avatar
梁百峰 committed
61
    {0x1FFFu, 0x1FFFu},
梁百峰's avatar
梁百峰 committed
62 63 64 65 66 67
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
梁百峰's avatar
梁百峰 committed
68 69 70
    {0x0002u, 0x0000u},
    {0x0000u, 0x0000u},
    {0x0001u, 0x0001u},
梁百峰's avatar
梁百峰 committed
71 72 73 74
    {0x007Fu, 0x007Fu},
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
梁百峰's avatar
梁百峰 committed
75 76 77 78 79 80 81 82 83 84 85
    {0x1800u, 0x1000u},
    {0x0000u, 0x0800u},
    {0x0000u, 0x0800u},
    {0x0000u, 0x0000u},
    {0x0002u, 0x0200u},
    {0x1800u, 0x1800u},
    {0x0A60u, 0x0A60u},
    {0xE7FFu, 0xE7FFu},
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
梁百峰's avatar
梁百峰 committed
86 87 88 89 90 91 92
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
    {0x0000u, 0x0000u},
梁百峰's avatar
梁百峰 committed
93 94 95
    {0x00FFu, 0x00FFu},
    {0x0200u, 0x0000u},
    {0xC07Fu, 0xC07Fu},
梁百峰's avatar
梁百峰 committed
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
    {0xFFFFu, 0xFFFFu},
};
static void GPIO_PIN_Init(GPIO_Config_Mode_en_t enGPIOConfigMode)
{

    PORTPIBC0 = 0X0UL;
    PORTPIBC8 = 0X0UL;
    PORTPIBC9 = 0X0UL;
    PORTPIBC10 = 0X0UL;
    PORTPIBC11 = 0X0UL;
    PORTAPIBC0 = 0X0UL;

    PORTPBDC0 = 0X0UL;
    PORTPBDC8 = 0X0UL;
    PORTPBDC9 = 0X0UL;
    PORTPBDC10 = 0X0UL;
    PORTPBDC11 = 0X0UL;
    PORTAPBDC0 = 0X0UL;

    PORTPM0 = 0XFFFFUL;
    PORTPM8 = 0XFFFFUL;
    PORTPM9 = 0XFFFFUL;
    PORTPM10 = 0XFFFFUL;
    PORTPM11 = 0XFFFFUL;
    PORTAPM0 = 0XFFFFUL;

    PORTPMC0 = 0X0UL;
    PORTPMC8 = 0X0UL;
    PORTPMC9 = 0X0UL;
    PORTPMC10 = 0X0UL;
    PORTPMC11 = 0X0UL;

    PORTPIPC0 = 0X0UL;
    PORTPIPC10 = 0X0UL;
    PORTPIPC11 = 0X0UL;

    PORTPODC0 = 0X0UL;
    PORTPODC8 = 0X0UL;
    PORTPODC9 = 0X0UL;
    PORTPODC10 = 0X0UL;
    PORTPODC11 = 0X0UL;

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

    PORTPU0 = g_u16GPIOConfigArray[0U][enGPIOConfigMode];
    PORTPD0 = g_u16GPIOConfigArray[1U][enGPIOConfigMode];
    PORTPIS0 = g_u16GPIOConfigArray[2U][enGPIOConfigMode];
    PORTPFC0 = g_u16GPIOConfigArray[3U][enGPIOConfigMode];
    PORTPFCE0 = g_u16GPIOConfigArray[4U][enGPIOConfigMode];
    PORTPFCAE0 = g_u16GPIOConfigArray[5U][enGPIOConfigMode];
    PORTPIPC0 = g_u16GPIOConfigArray[6U][enGPIOConfigMode];
    PORTP0 = g_u16GPIOConfigArray[7U][enGPIOConfigMode];
    PORTPMC0 = g_u16GPIOConfigArray[8U][enGPIOConfigMode];
    PORTPM0 = g_u16GPIOConfigArray[9U][enGPIOConfigMode];
    PORTPIBC0 = g_u16GPIOConfigArray[10U][enGPIOConfigMode];

    PORTPU8 = g_u16GPIOConfigArray[11U][enGPIOConfigMode];
    PORTPD8 = g_u16GPIOConfigArray[12U][enGPIOConfigMode];
    PORTPIS8 = g_u16GPIOConfigArray[13U][enGPIOConfigMode];
    PORTPFC8 = g_u16GPIOConfigArray[14U][enGPIOConfigMode];
    PORTPFCE8 = g_u16GPIOConfigArray[15U][enGPIOConfigMode];
    PORTPFCAE8 = g_u16GPIOConfigArray[16U][enGPIOConfigMode];
    PORTP8 = g_u16GPIOConfigArray[17U][enGPIOConfigMode];
    PORTPMC8 = g_u16GPIOConfigArray[18U][enGPIOConfigMode];
    PORTPM8 = g_u16GPIOConfigArray[19U][enGPIOConfigMode];
    PORTPIBC8 = g_u16GPIOConfigArray[20U][enGPIOConfigMode];

    PORTPU9 = g_u16GPIOConfigArray[21U][enGPIOConfigMode];
    PORTPD9 = g_u16GPIOConfigArray[22U][enGPIOConfigMode];
    PORTPIS9 = g_u16GPIOConfigArray[23U][enGPIOConfigMode];
    PORTPFC9 = g_u16GPIOConfigArray[24U][enGPIOConfigMode];
    PORTPFCE9 = g_u16GPIOConfigArray[25U][enGPIOConfigMode];
    PORTPFCAE9 = g_u16GPIOConfigArray[26U][enGPIOConfigMode];
    PORTP9 = g_u16GPIOConfigArray[27U][enGPIOConfigMode];
    PORTPMC9 = g_u16GPIOConfigArray[28U][enGPIOConfigMode];
    PORTPM9 = g_u16GPIOConfigArray[29U][enGPIOConfigMode];
    PORTPIBC9 = g_u16GPIOConfigArray[30U][enGPIOConfigMode];

    PORTPU10 = g_u16GPIOConfigArray[31U][enGPIOConfigMode];
    PORTPD10 = g_u16GPIOConfigArray[32U][enGPIOConfigMode];
    PORTPIS10 = g_u16GPIOConfigArray[33U][enGPIOConfigMode];
    PORTPFC10 = g_u16GPIOConfigArray[34U][enGPIOConfigMode];
    PORTPFCE10 = g_u16GPIOConfigArray[35U][enGPIOConfigMode];
    PORTPFCAE10 = g_u16GPIOConfigArray[36U][enGPIOConfigMode];
    PORTPIPC10 = g_u16GPIOConfigArray[37U][enGPIOConfigMode];
    PORTP10 = g_u16GPIOConfigArray[38U][enGPIOConfigMode];
    PORTPMC10 = g_u16GPIOConfigArray[39U][enGPIOConfigMode];
    PORTPM10 = g_u16GPIOConfigArray[40U][enGPIOConfigMode];
    PORTPIBC10 = g_u16GPIOConfigArray[41U][enGPIOConfigMode];

    PORTPU11 = g_u16GPIOConfigArray[42U][enGPIOConfigMode];
    PORTPD11 = g_u16GPIOConfigArray[43U][enGPIOConfigMode];
    PORTPIS11 = g_u16GPIOConfigArray[44U][enGPIOConfigMode];
    PORTPFC11 = g_u16GPIOConfigArray[45U][enGPIOConfigMode];
    PORTPFCE11 = g_u16GPIOConfigArray[46U][enGPIOConfigMode];
    PORTPFCAE11 = g_u16GPIOConfigArray[47U][enGPIOConfigMode];
    PORTPIPC11 = g_u16GPIOConfigArray[48U][enGPIOConfigMode];
    PORTP11 = g_u16GPIOConfigArray[49U][enGPIOConfigMode];
    PORTPMC11 = g_u16GPIOConfigArray[50U][enGPIOConfigMode];
    PORTPM11 = g_u16GPIOConfigArray[51U][enGPIOConfigMode];
    PORTPIBC11 = g_u16GPIOConfigArray[52U][enGPIOConfigMode];

    PORTAP0 = g_u16GPIOConfigArray[53U][enGPIOConfigMode];
    PORTAPM0 = g_u16GPIOConfigArray[54U][enGPIOConfigMode];
    PORTAPIBC0 = g_u16GPIOConfigArray[55U][enGPIOConfigMode];
}

void GPIO_Init(GPIO_Config_Mode_en_t enGPIOConfigMode)
{
    if (enGPIOConfigMode == GPIO_WAKEUP_MODE)
    {
        GPIO_PIN_Init(GPIO_WAKEUP_MODE);
        /*port buffer  exit hold state*/
        GPIO_STB_PROTECTED_WRITE(WPROTRPROTCMD0, WPROTRPROTS0, STBC_IOHOLDIOHOLD, 0x00U);
    }
    else
    {
        GPIO_PIN_Init(GPIO_SLEEP_MODE);
    }
}
static uint32_t GPIO_Get_Wake_Bit(GPIO_Wakeup_PIN_en_t enGPIOWakeupPIN)
{
    uint32_t u32GPIOWakeBit = 0UL;
    switch (enGPIOWakeupPIN)
    {
    case GPIO_WAKEUP_PIN_P0_1:
    {
        u32GPIOWakeBit = 0x20UL;
        break;
    }
    case GPIO_WAKEUP_PIN_P0_2:
    {
        u32GPIOWakeBit = 0x40UL;
        break;
    }
    case GPIO_WAKEUP_PIN_P0_3:
    {
        u32GPIOWakeBit = 0x1000UL;
        break;
    }
    case GPIO_WAKEUP_PIN_P0_4:
    {
        u32GPIOWakeBit = 0x2000UL;
        break;
    }
    /*case GPIO_WAKEUP_PIN_P0_5: */
    case GPIO_WAKEUP_PIN_P0_6:
    {
        u32GPIOWakeBit = 0x80UL;
        break;
    }
    /*case GPIO_WAKEUP_PIN_P0_7: */
    case GPIO_WAKEUP_PIN_P0_10:
    {
        u32GPIOWakeBit = 0x200UL;
        break;
    }
    case GPIO_WAKEUP_PIN_P0_9:
    {
        u32GPIOWakeBit = 0x400UL;
        break;
    }
    case GPIO_WAKEUP_PIN_P0_13:
    {
        u32GPIOWakeBit = 0x800UL;
        break;
    }
    case GPIO_WAKEUP_PIN_P8_2:
    {
        u32GPIOWakeBit = 0x100000UL;
        break;
    }
    case GPIO_WAKEUP_PIN_P8_3:
    {
        u32GPIOWakeBit = 0x200000UL;
        break;
    }
    case GPIO_WAKEUP_PIN_P8_4:
    {
        u32GPIOWakeBit = 0x400000UL;
        break;
    }
    default:
        break;
    }
    return (~u32GPIOWakeBit);
}

void GPIO_Wakeup_PIN_Set(GPIO_Wakeup_PIN_en_t enGPIOWakeupPIN, GPIO_Wakeup_Trigger_Mode_en_t enGPIOTrigger)
{
    uint32_t u32GPIORegisterAddress = 0xFFC34020U + 0X4U * enGPIOWakeupPIN;
    uint32_t u32GPIORegisterValue = GPIO_Get_Wake_Bit(enGPIOWakeupPIN);

    /*trigger type*/
    *(uint8_t *)u32GPIORegisterAddress = enGPIOTrigger;

    /*trigger PIN*/
    STBC_WUF0WUFMSK0 &= u32GPIORegisterValue;
}

static uint32_t GPIO_Register_Address_Cal(GPIO_Port_en_t enGPIOPort, GPIO_Register_en_t enGPIORegister)
{
    uint32_t u32GPIOAddress = 0UL;
    uint32_t u32GPIOAddressBase = GPIO_PORTN_BASE_ADDRESS + enGPIOPort * 4UL;

    switch (enGPIORegister)
    {
    case GPIO_REG_PMC:
    {
        u32GPIOAddress = 0X400UL;
        break;
    }
    case GPIO_REG_PIPC:
    {
        u32GPIOAddress = 0X4200UL;
        break;
    }
    case GPIO_REG_PM:
    {
        u32GPIOAddress = 0x300UL;
        break;
    }
    case GPIO_REG_PIBC:
    {
        u32GPIOAddress = 0x4000UL;
        break;
    }
    case GPIO_REG_PFC:
    {
        u32GPIOAddress = 0X500UL;
        break;
    }
    case GPIO_REG_PFCE:
    {
        u32GPIOAddress = 0X600UL;
        break;
    }
    case GPIO_REG_PFCAE:
    {
        u32GPIOAddress = 0XA00UL;
        break;
    }
    case GPIO_REG_PBDC:
    {
        u32GPIOAddress = 0X4100UL;
        break;
    }
    case GPIO_REG_P:
    {
        u32GPIOAddress = 0X000UL;
        break;
    }
    case GPIO_REG_PU:
    {
        u32GPIOAddress = 0X4300UL;
        break;
    }
    case GPIO_REG_PD:
    {
        u32GPIOAddress = 0X4400UL;
        break;
    }
    case GPIO_REG_PDSC:
    {
        u32GPIOAddress = 0X4600UL;
        break;
    }
    case GPIO_REG_PODC:
    {
        u32GPIOAddress = 0X4500UL;
        break;
    }
    case GPIO_REG_PIS:
    {
        u32GPIOAddress = 0X4700UL;
        break;
    }
    case GPIO_REG_PPCMD:
    {
        u32GPIOAddress = 0X4C00UL;
        break;
    }
    case GPIO_REG_PPROTS:
    {
        u32GPIOAddress = 0X4B00UL;
        break;
    }
    default:
        break;
    }

    u32GPIOAddress += u32GPIOAddressBase;
    return u32GPIOAddress;
}

void GPIO_Config(GPIO_Config_st_t *pstGPIOConfig)
{

    uint32_t u32GPIORegisterAddress = 0UL;
    uint16_t u16GPIORegisterValue = 0U;
    uint32_t u32GPIORegisterAddress2 = 0UL;
    uint16_t u16GPIORegisterValue2 = 0U;
    uint32_t u32GPIORegisterAddress3 = 0UL;
    uint16_t u16GPIORegisterValue3 = 0U;

    uint16_t u16GPIOBitOr = (1U << pstGPIOConfig->enGPIOPIN);
    uint16_t u16GPIOBitAnd = ~u16GPIOBitOr;

    /**********************Port initialization*******************/
    /*******PDSCn**Lower drive strength********/
    /*******PODCn**Push-pull********/
    /*******PBDCn**Bidirectional mode disabled********/
    /*******PDn**PUn**********/
    if (pstGPIOConfig->enGPIOPort != GPIO_PORT_GROUP_AP0)
    {
        u32GPIORegisterAddress = GPIO_Register_Address_Cal(pstGPIOConfig->enGPIOPort, GPIO_REG_PU);
        u16GPIORegisterValue = (*((uint16_t *)(u32GPIORegisterAddress)));
        u32GPIORegisterAddress2 = GPIO_Register_Address_Cal(pstGPIOConfig->enGPIOPort, GPIO_REG_PD);
        u16GPIORegisterValue2 = (*((uint16_t *)(u32GPIORegisterAddress2)));

        if (pstGPIOConfig->enGPIOPull == GPIO_PULL_UP)
        {
            u16GPIORegisterValue2 &= u16GPIOBitAnd;
            u16GPIORegisterValue |= u16GPIOBitOr;
        }
        else if (pstGPIOConfig->enGPIOPull == GPIO_PULL_DOWN)
        {
            u16GPIORegisterValue &= u16GPIOBitAnd;
            u16GPIORegisterValue2 |= u16GPIOBitOr;
        }
        else /*GPIO_PULL_NONE*/
        {
            u16GPIORegisterValue &= u16GPIOBitAnd;
            u16GPIORegisterValue2 &= u16GPIOBitAnd;
        }
        (*((uint16_t *)(u32GPIORegisterAddress))) = u16GPIORegisterValue;
        (*((uint16_t *)(u32GPIORegisterAddress2))) = u16GPIORegisterValue2;
    }
    /********PISn*********/
    if (pstGPIOConfig->enGPIOPort != GPIO_PORT_GROUP_AP0)
    {
        u32GPIORegisterAddress = GPIO_Register_Address_Cal(pstGPIOConfig->enGPIOPort, GPIO_REG_PIS);
        u16GPIORegisterValue = (*((uint16_t *)(u32GPIORegisterAddress)));

        if (pstGPIOConfig->enGPIOCharacter == GPIO_Char_Schmitt1)
        {
            u16GPIORegisterValue &= u16GPIOBitAnd;
        }
        else if (pstGPIOConfig->enGPIOCharacter == GPIO_Char_Schmitt4)
        {
            u16GPIORegisterValue |= u16GPIOBitOr;
        }
        (*((uint16_t *)(u32GPIORegisterAddress))) = u16GPIORegisterValue;
    }
    /******PFCn**PFCEn**PFCAEn*******/
    if (pstGPIOConfig->enGPIOPort != GPIO_PORT_GROUP_AP0)
    {
        u32GPIORegisterAddress = GPIO_Register_Address_Cal(pstGPIOConfig->enGPIOPort, GPIO_REG_PFC);
        u16GPIORegisterValue = (*((uint16_t *)(u32GPIORegisterAddress)));
        u32GPIORegisterAddress2 = GPIO_Register_Address_Cal(pstGPIOConfig->enGPIOPort, GPIO_REG_PFCE);
        u16GPIORegisterValue2 = (*((uint16_t *)(u32GPIORegisterAddress2)));
        u32GPIORegisterAddress3 = GPIO_Register_Address_Cal(pstGPIOConfig->enGPIOPort, GPIO_REG_PFCAE);
        u16GPIORegisterValue3 = (*((uint16_t *)(u32GPIORegisterAddress3)));

        switch (pstGPIOConfig->enGPIOAltFun)
        {
        default:
        case GPIO_ALTER_FUN_1:
        {
            u16GPIORegisterValue &= u16GPIOBitAnd;
            u16GPIORegisterValue2 &= u16GPIOBitAnd;
            u16GPIORegisterValue3 &= u16GPIOBitAnd;
            break;
        }
        case GPIO_ALTER_FUN_2:
        {
            u16GPIORegisterValue |= u16GPIOBitOr;
            u16GPIORegisterValue2 &= u16GPIOBitAnd;
            u16GPIORegisterValue3 &= u16GPIOBitAnd;
            break;
        }
        case GPIO_ALTER_FUN_3:
        {
            u16GPIORegisterValue &= u16GPIOBitAnd;
            u16GPIORegisterValue2 |= u16GPIOBitOr;
            u16GPIORegisterValue3 &= u16GPIOBitAnd;
            break;
        }
        case GPIO_ALTER_FUN_4:
        {
            u16GPIORegisterValue |= u16GPIOBitOr;
            u16GPIORegisterValue2 |= u16GPIOBitOr;
            u16GPIORegisterValue3 &= u16GPIOBitAnd;
            break;
        }
        case GPIO_ALTER_FUN_5:
        {
            u16GPIORegisterValue &= u16GPIOBitAnd;
            u16GPIORegisterValue2 &= u16GPIOBitAnd;
            u16GPIORegisterValue3 |= u16GPIOBitOr;
            break;
        }
        case GPIO_ALTER_FUN_6:
        {
            u16GPIORegisterValue |= u16GPIOBitOr;
            u16GPIORegisterValue2 &= u16GPIOBitAnd;
            u16GPIORegisterValue3 |= u16GPIOBitOr;
            break;
        }
        case GPIO_ALTER_FUN_7:
        {
            u16GPIORegisterValue &= u16GPIOBitAnd;
            u16GPIORegisterValue2 |= u16GPIOBitOr;
            u16GPIORegisterValue3 |= u16GPIOBitOr;
            break;
        }
        }

        (*((uint16_t *)(u32GPIORegisterAddress))) = u16GPIORegisterValue;
        (*((uint16_t *)(u32GPIORegisterAddress2))) = u16GPIORegisterValue2;
        (*((uint16_t *)(u32GPIORegisterAddress3))) = u16GPIORegisterValue3;
    }
    /*******Pn**********/
    u32GPIORegisterAddress = GPIO_Register_Address_Cal(pstGPIOConfig->enGPIOPort, GPIO_REG_P);
    u16GPIORegisterValue = (*((uint16_t *)(u32GPIORegisterAddress)));

    if (pstGPIOConfig->enGPIOOutputValue == GPIO_Level_High)
    {
        u16GPIORegisterValue |= u16GPIOBitOr;
    }
    else
    {
        u16GPIORegisterValue &= u16GPIOBitAnd;
    }

    (*((uint16_t *)(u32GPIORegisterAddress))) = u16GPIORegisterValue;
    /*****PMCn**PIPCn***PIBCn*******/
    u32GPIORegisterAddress = GPIO_Register_Address_Cal(pstGPIOConfig->enGPIOPort, GPIO_REG_PMC);
    u16GPIORegisterValue = (*((uint16_t *)(u32GPIORegisterAddress)));
    u32GPIORegisterAddress2 = GPIO_Register_Address_Cal(pstGPIOConfig->enGPIOPort, GPIO_REG_PIPC);
    u16GPIORegisterValue2 = (*((uint16_t *)(u32GPIORegisterAddress2)));
    u32GPIORegisterAddress3 = GPIO_Register_Address_Cal(pstGPIOConfig->enGPIOPort, GPIO_REG_PIBC);
    u16GPIORegisterValue3 = (*((uint16_t *)(u32GPIORegisterAddress3)));

    if (pstGPIOConfig->enGPIOMode == GPIO_MODE_ALTER_DIRECT)
    {
        u16GPIORegisterValue |= u16GPIOBitOr;
        u16GPIORegisterValue2 |= u16GPIOBitOr;
        u16GPIORegisterValue3 &= u16GPIOBitAnd;
    }
    else if (pstGPIOConfig->enGPIOMode == GPIO_MODE_ALTER_SOFTWARE)
    {
        u16GPIORegisterValue |= u16GPIOBitOr;
        u16GPIORegisterValue2 &= u16GPIOBitAnd;
        u16GPIORegisterValue3 &= u16GPIOBitAnd;
    }
    else /*if (pstGPIOConfig->enGPIOMode==GPIO_MODE_PORT)*/
    {
        u16GPIORegisterValue &= u16GPIOBitAnd;
        u16GPIORegisterValue2 &= u16GPIOBitAnd;
        u16GPIORegisterValue3 |= u16GPIOBitOr;
    }
    if (pstGPIOConfig->enGPIOPort != GPIO_PORT_GROUP_AP0)
    {
        (*((uint16_t *)(u32GPIORegisterAddress))) = u16GPIORegisterValue;
    }
    if ((pstGPIOConfig->enGPIOPort == GPIO_PORT_GROUP_0) ||
        (pstGPIOConfig->enGPIOPort == GPIO_PORT_GROUP_10) ||
        (pstGPIOConfig->enGPIOPort == GPIO_PORT_GROUP_11))
    {
        (*((uint16_t *)(u32GPIORegisterAddress2))) = u16GPIORegisterValue2;
    }
    (*((uint16_t *)(u32GPIORegisterAddress3))) = u16GPIORegisterValue3;
    /***************PMn*****************/
    u32GPIORegisterAddress = GPIO_Register_Address_Cal(pstGPIOConfig->enGPIOPort, GPIO_REG_PM);
    u16GPIORegisterValue = (*((uint16_t *)(u32GPIORegisterAddress)));
    if (pstGPIOConfig->enGPIODir == GPIO_DIR_IN)
    {
        u16GPIORegisterValue |= u16GPIOBitOr;
    }
    else
    {
        u16GPIORegisterValue &= u16GPIOBitAnd;
    }
    (*((uint16_t *)(u32GPIORegisterAddress))) = u16GPIORegisterValue;
}
void GPIO_SET_KEPP(void) 
{
    GPIO_STB_PROTECTED_WRITE(WPROTRPROTCMD0, WPROTRPROTS0, STBC_IOHOLDIOHOLD, 0x00U);
}