@@ -49,8 +49,104 @@ static bool reg_test(gpio_t gpio)
4949 return true;
5050}
5151
52+ // Drive a pattern (val)
53+ static void drive (gpio_t gpio , uint32_t masked_reg , uint32_t val ) {
54+ gpio_write (gpio , masked_reg , 0XFFFF0000 | val );
55+ }
56+
57+ // Wait for an expected pattern (compare_val).
58+ static void wait (gpio_t gpio , uint32_t compare_val ) {
59+ while (DEV_READ (gpio + GPIO_REG_DATA_IN ) != compare_val ){
60+ }
61+ }
62+
63+ // Verifies GPIOs in partially output and input direction. The test distributes GPIOs as four equal
64+ // quaters. The idea is to drive first quater of GPIOs as outputs and wait for a pattern to appear
65+ // on the second quater of pins as inputs. Next, drive a pattern on the third quater and waits for a
66+ // pattern to appear on the fourth quater as inputs. Repeat the same process second time but with a
67+ // different pattern.
68+ //
69+ // The pattern driven on the outputs is going to be walking 1's (1, 10, 0100, 1000, ...) first and
70+ // then walking 0's (1110, 1101, 1011, 0111, ...) whereas it is a temperature 1's (1, 11, 111, 1111,
71+ // ...) then a temperature 0's (1110, 1100, 1000, 0000, ...) sequence for the inputs.
72+ //
73+ // 1- First, drive 0's on the first and third quater of GPIOs.
74+ // 2- Walk 1's on the first quater of GPIOs in output mode.
75+ // 3- top_chip_dv_gpio_base_vseq will wait for walking 1's pattern to appear on the pads. Once it
76+ // sees that pattern, it will drive 1's in temperature sequence on to the second quater.
77+ // 4- gpio_test waits for the pattern 0x0000T1W1 on the GPIO pads by reading DATA_IN register. Then
78+ // it will walk 1's on the third quater of pins and waits for pattern 0xT1W1T1W1.
79+ // 5- On the other side, the vseq waits for the walking 1's pattern on the third quater of pins and
80+ // drive 1's in temperature sequence on the fourth quater.
81+ // 6- After all that, gpio_test start to write 1's to the first and third quater of pins in order to
82+ // drive walking 0's. Everything beyond that is similar but the expected driven sequence is going
83+ // to be temperature 0's and walking 0's.
84+ static bool gpio_test (gpio_t gpio )
85+ {
86+ // Enable the first and third quater of pins in output mode
87+ gpio_set_all_oe (gpio , 0x00FF00FF );
88+
89+ // Set the gpios to all 0's in order to walk 1's on first and third quater,
90+ gpio_write (gpio , GPIO_REG_DIRECT_OUT , 0x0 );
91+
92+ // Current GPIOs pads state : 0x00000000
93+ //
94+ // Walk 1's on the first quater. vseq drives the second quater as temperature 1's. Hence, the
95+ // expected value to wait for is 0xFF80,
96+ for (int i = 0 ; i < GPIO_NUM_PINS / 4 ; i ++ ) {
97+ drive (gpio , GPIO_REG_MASKED_OUT_LOWER , 1 << i );
98+ if (i == ((GPIO_NUM_PINS / 4 ) - 1 )) {
99+ wait (gpio , 0xFF80 );
100+ }
101+ }
102+
103+ // Current GPIOs pads state : 0x0000FF80
104+ //
105+ // Walk 1's on the third quater. vseq drives the fourth quater as temperature 1's. Additionally,
106+ // the pads contains 0xFF80 by now on the first two quaters. Hence, the expected value to wait
107+ // for is 0xFF80FF80,
108+ for (int i = 0 ; i < GPIO_NUM_PINS / 4 ; i ++ ) {
109+ drive (gpio , GPIO_REG_MASKED_OUT_UPPER , 1 << i );
110+ if (i == ((GPIO_NUM_PINS / 4 ) - 1 )) {
111+ wait (gpio , 0xFF80FF80 );
112+ }
113+ }
114+
115+ // Current GPIOs pads state : 0xFF80FF80
116+ //
117+ // Now, set the first and third quater (which are enabled as outputs) to all 1's in order to
118+ // walk 0's on them.
119+ gpio_write (gpio , GPIO_REG_DIRECT_OUT , 0x00FF00FF );
120+
121+ // Current GPIOs pads state : 0xFFFFFFFF
122+ //
123+ // Walk 0's on the first quater of pins. vseq drives the second quater as temperature 0's.
124+ // Hence, the expected value to wait for is 0xFFFF007F.
125+ for (int i = 0 ; i < GPIO_NUM_PINS / 4 ; i ++ ) {
126+ drive (gpio , GPIO_REG_MASKED_OUT_LOWER , ~(1 << i ));
127+ if (i == ((GPIO_NUM_PINS / 4 ) - 1 )) {
128+ wait (gpio , 0xFFFF007F );
129+ }
130+ }
131+
132+ // Current GPIOs pads state : 0xFFFF007F
133+ //
134+ // Walk 0's on the third quater of pins. vseq drives the fourth quater as temperature 0's.
135+ // Hence, the expected value to wait for is 0x007F007F.
136+ for (int i = 0 ; i < GPIO_NUM_PINS / 4 ; i ++ ) {
137+ drive (gpio , GPIO_REG_MASKED_OUT_UPPER , ~(1 << i ));
138+ if (i == ((GPIO_NUM_PINS / 4 ) - 1 )) {
139+ wait (gpio , 0x007F007F );
140+ }
141+ }
142+
143+ // Current GPIOs pads state : 0x007F007F
144+
145+ return true;
146+ }
147+
52148bool test_main ()
53149{
54150 gpio_t gpio = mocha_system_gpio ();
55- return reg_test (gpio );
151+ return gpio_test (gpio );
56152}
0 commit comments