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