PS GPIO Control LED (Baremetal)

Problem 
   Using a PS side GPIO, repeatedly turn-off and turn-on the DS23 on the ZC702 evaluation board

Solution
According to the  UG850 (v1.3) June 4, 2014 page 45 the LED with reference DS23 on the board with the net name PS\_LED1 is connected to the pin G7 of the XC7Z020.
In addition, according to the pin configuration in the ZC702 evaluation board shown in Fig.~\ref{fig:g7pinconnectionandconfiguration}, GPIO\_MIO[10] is connected to G7. Therefore, to control the DS23 LED the PS GPIO number 11 should be programmed. This pin is located in GPIO bank 0.


Control LED Flowchart
The following C code will turn on/off the LED.

example-01_code01.c

typedef unsigned long u32;

#define GPIO_BASE        0xE000A000

#define MASK_DATA_0_LSW (GPIO_BASE+0x00000000)
#define DIRM_0 (GPIO_BASE+0x00000204)
#define OEN_0 (GPIO_BASE+0x00000208)




int main()
{
    u32 dirm_value = *(volatile u32 *)DIRM_0;
    dirm_value = dirm_value | 0x00000400;
    *(volatile u32 *)DIRM_0 = dirm_value;

    u32 oen_value = *(volatile u32 *)OEN_0;
    oen_value = oen_value | 0x00000400;
    *(volatile u32 *)OEN_0  = drim_value;


    int volatile i, j=0;
    while (j++ < 1000) {
    *(volatile u32 *) MASK_DATA_0_LSW = 0xFBFF0000;

for (i = 0; i < 10000000; i++);

*(volatile u32 *) MASK_DATA_0_LSW = 0xFBFF0400;

for (i = 0; i < 10000000; i++);
    }

    return 0;
}