]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/pdk.git/blob - packages/ti/board/diag/button/src/button_test.c
[OSAL]: Added testcase for task sub module
[processor-sdk/pdk.git] / packages / ti / board / diag / button / src / button_test.c
1 /*
2  * Copyright (C) 2016-2021 Texas Instruments Incorporated - http://www.ti.com/
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * distribution.
15  *
16  * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
34 /**
35  * \file   button_test.c
36  *
37  * \brief  Push button diagnostic test file
38  *
39  *  Targeted Functionality: Verification of basic functionality of
40  *  available push buttons.
41  *
42  *  Operation: This application demonstrates the working of GPIO based button
43  *             keypad. It waits for a key press event from the button keypad.
44  *             On a key press the diagnostic test sequentially moves to the
45  *             other buttons in the keypad.
46  *
47  *  Supported SoCs: AM335x, AM437x, AM65xx, TPR12, AM64x, AWR294x
48  *
49  *  Supported Platforms: skAM335x, skAM437x, evmAM437x am65xx_evm, am65xx_idk,
50  *                       tpr12_evm,am64x_evm, awr294x_evm.
51  *
52  */
54 #include "button_test.h"
56 #if defined(SOC_TPR12) || defined(SOC_AWR294X)
57 extern GPIO_v2_Config GPIO_v2_config;
58 #endif
60 uint32_t buttonOffset[2]={0, 0};
61 uint32_t powerOffset[2]={0, 0};
62 uint32_t buttonStart[2]={0, 0};
64 /* Variable to hold the GPIO key info. */
65 gpioInfo_t KeyScn[4];
67 /**
68  *  \brief   Push Button diagnostic test main function
69  *
70  *  \return  int - Push Button diagnostic test status.
71  *            S_PASS - if the board id matches
72  *            E_FAIL - if the board id fails.
73  *
74  */
75 int main(void)
76 {
77     int status = S_PASS;
78 #if (defined(SOC_AM65XX) || defined(SOC_TPR12) || defined(SOC_AM64X) || defined(SOC_AWR294X))
79     Board_IDInfo_v2 info;
80 #else
81     Board_IDInfo boardInfo;
82 #endif
83     keyPadInfo_t boardKeyPad;
84     Board_initCfg boardCfg;
86 #ifdef SOC_K2G
87     DIAG_IntrInit();
88 #endif
90 #ifdef PDK_RAW_BOOT
91     boardCfg = BOARD_INIT_MODULE_CLOCK |
92                BOARD_INIT_PINMUX_CONFIG |
93                BOARD_INIT_UART_STDIO;
94 #else
95     boardCfg = BOARD_INIT_UART_STDIO;
96 #endif
97     Board_init(boardCfg);
99     UART_printf("\n*********************************************\n"); 
100     UART_printf  ("*                 Button Test               *\n");
101     UART_printf  ("*********************************************\n");
103 #if (defined(SOC_AM65XX) || defined(SOC_TPR12) || defined(SOC_AM64X) || defined(SOC_AWR294X))
104     Board_getIDInfo_v2(&info, BOARD_I2C_EEPROM_ADDR);
105 #else
106     Board_getIDInfo(&boardInfo);
107 #endif
109     /* Update the KeyPad information. */
110 #if (defined(SOC_AM65XX) || defined(SOC_TPR12) || defined(SOC_AM64X) || defined(SOC_AWR294X))
111     status = BoardDiag_GetKeyPadInfo(info.boardInfo.boardName, &boardKeyPad);
112 #else
113     status = BoardDiag_GetKeyPadInfo(boardInfo.boardName, &boardKeyPad);
114 #endif
115     if(S_PASS == status)
116     {
117         status = BoardDiag_ButtonTest(&boardKeyPad);
119         if(S_PASS == status)
120         {
121             UART_printf("Test PASSED! \n");
122         }
123         else
124         {
125             UART_printf("Test Failed!\n");
126         }
127     }
129     return status;
132 /**
133  * \brief   This function is used enable the power key by making the power
134  *          key GPIO line high.
135  *
136  * \param   *pBoardKeyPad     [IN]      Structure pointer consisting of the
137  *                                      Keypad information of the board
138  * \param   num               [IN]      Power key number.
139  *
140  * \retval  S_PASS  if the board id matches
141  * \retval  E_FAIL  if the board id fails.
142  *
143  */
144 void BoardDiag_BtnPwr(keyPadInfo_t *pBoardKeyPad, uint32_t num)
146     uint32_t i = 0U;
148     for(i = 0; i < pBoardKeyPad->pwrKeyNum; i++)
149     {
150         if(i == num)
151         {
152             GPIO_write(pBoardKeyPad->pwrKeyIdx + i, GPIO_PIN_VAL_HIGH);
153         }
154         else
155         {
156             GPIO_write(pBoardKeyPad->pwrKeyIdx + i, GPIO_PIN_VAL_LOW);
157         }
158     }
161 /**
162  * \brief   This function is used to perform the push button diagnostic test.
163  *
164  * \param   *pBoardKeyPad     [IN]      Structure pointer consisting of the
165  *                                      Keypad information of the board.
166  *
167  * \retval  S_PASS  if the board id matches
168  * \retval  E_FAIL  if the board id fails.
169  *
170  */
171 int32_t BoardDiag_ButtonTest(keyPadInfo_t *pBoardKeyPad)
173     uint32_t retVal = S_PASS;
174     uint32_t i, j, k;
176     /* Initialize the GPIO driver. */
177     UART_printf("\nRunning button test...\n");
178 #if defined(SOC_AM65XX)
179     GPIO_v0_HwAttrs gpioCfg;
180     GPIO_socGetInitCfg(0, &gpioCfg);
181     gpioCfg.baseAddr = CSL_WKUP_GPIO0_BASE;
182     GPIO_socSetInitCfg(0, &gpioCfg);
183     GPIO_init();
184 #elif defined(SOC_AM64X)
185     GPIO_init();
186 #else
187 #if (defined(SOC_TPR12) || defined(SOC_AWR294X))
188     GPIO_v2_updateConfig(&GPIO_v2_config);
189 #endif
190     GPIO_init();
191 #endif
193     for(k=0; k < pBoardKeyPad->buttonSet; k++)
194     {
195         for(i=0; i< pBoardKeyPad->pwrKeyNum; i++)
196         {
197             for(j=0; j < pBoardKeyPad->scnKeyNum; j++)
198             {
199                 retVal = BoardDiag_KeyPressCheck(pBoardKeyPad,
200                                                  buttonStart[k] + (i*powerOffset[k]) + (j*buttonOffset[k]),
201                                                  j, i);
202             }
203         }
204     }
206     return retVal;
209 /**
210  * \brief   This is used for keep on checking for a specified button to
211  *          be pressed.
212  *
213  * \param   *pBoardKeyPad     [IN]      Structure pointer consisting of the
214  *                                      Keypad information of the board.
215  * \param   button            [IN]      Push button switch number.
216  * \param   scnKey            [IN]      Push button switch index.
217  * \param   pwrKey            [IN]      Power key number.
218  *
219  * \retval  S_PASS  if the board id matches
220  * \retval  E_FAIL  if the board id fails.
221  *
222  */
223 int32_t BoardDiag_KeyPressCheck(keyPadInfo_t *pBoardKeyPad,
224                                 uint32_t button,
225                                 uint32_t scnKey,
226                                 uint32_t pwrKey)
228     int32_t ret_val=0;
229     uint32_t level = 0U;
230 #if defined (DIAG_COMPLIANCE_TEST)
231     UART_printf(  "Button SW %2d            ", button);
233     level = GPIO_read(scnKey);
235     UART_printf("Button SW %2d Value - %d\n", button, level);
236     ret_val = S_PASS;
238     return ret_val;
239 #else
240     UART_printf(  "Button SW %2d            ", button);
241     UART_printf("WAIT      Waiting for button press");
243 #if (defined(SOC_AM65XX) || defined(SOC_TPR12) || defined(SOC_AM64X) || defined(SOC_AWR294X))
244     do
245     {
246 #if (defined(SOC_TPR12) || defined(SOC_AWR294X))
247         level = GPIO_read(GPIO_v2_config.pinConfigs[scnKey].pinIndex);
248 #else
249         level = GPIO_read(scnKey);
250 #endif
251 #if (defined(SOC_TPR12) || defined(SOC_AWR294X))
252     }while(level == 0);
253 #else
254     }while(level == 1);
255 #endif
256     UART_printf("...   Button %2d Pressed \n", button);
258     UART_printf(  "Button SW %2d            ", button);
259     UART_printf("WAIT      Waiting for button release...");
260     do
261     {
262 #if (defined(SOC_TPR12) || defined(SOC_AWR294X))
263         level = GPIO_read(GPIO_v2_config.pinConfigs[scnKey].pinIndex);
264 #else
265         level = GPIO_read(scnKey);
266 #endif
267 #if (defined(SOC_TPR12) || defined(SOC_AWR294X))
268     }while(level == 1);
269 #else
270     }while(level == 0);
271 #endif
272     UART_printf(" Button %2d released\n", button);
273 #else
274     BoardDiag_BtnPwr(pBoardKeyPad, pwrKey);
275     do
276     {
277         level = (GPIO_read(scnKey));
278     }while(level != 1);
279 #endif
281     UART_printf("Button SW %2d            ", button);
283 #if (!(defined(SOC_AM65XX) || defined(SOC_TPR12) || defined(SOC_AM64X) || defined(SOC_AWR294X)))
284     if(level != 1)
285     {
286         UART_printf("FAIL                                            \n");
287         ret_val = E_FAIL;
288     }
289     else
290     {
291         UART_printf("PASS                                            \n");
292         ret_val = S_PASS;
293     }
294 #else
295     UART_printf("PASS                                            \n");
296     ret_val = S_PASS;
297 #endif
298     return ret_val;
299 #endif
302 /**
303  * \brief   Get the Board keypad information as per the board Id.
304  *
305  * \param   *pBoardName       [IN]      Pointer to hold the board name
306  * \param   *pBoardKeyPad     [OUT]     Structure pointer for holding the
307  *                                      Keypad information of the board.
308  *
309  * \retval  S_PASS  if the board id matches
310  * \retval  E_FAIL  if the board id fails.
311  *
312  */
313 int32_t BoardDiag_GetKeyPadInfo(char *pBoardName, keyPadInfo_t *pBoardKeyPad)
315     int32_t status = S_PASS;
317     /* Check if the board is AM437x GPEVM by comparing the string
318        read from EEPROM. */
319     if (strncmp("AM43__GP", pBoardName, BOARD_NAME_LENGTH) == 0U)
320     {
321         pBoardKeyPad->buttonSet = 1;
322         pBoardKeyPad->scnKeyNum = 3;
323         pBoardKeyPad->pwrKeyNum = 2;
324         pBoardKeyPad->pwrKeyIdx = 3;
325         buttonStart[0]=4;
326         buttonOffset[0]=1;
327         powerOffset[0]=3;
328         /* Update the GPIO data for keypad inputs. */
329         KeyScn[0].instance=3;
330         KeyScn[0].pin=21;
332         KeyScn[1].instance=4;
333         KeyScn[1].pin=3;
335         KeyScn[2].instance=4;
336         KeyScn[2].pin=2;
337     }
338     /* Check if the board is SKAM437x by comparing the string read
339        from EEPROM. */
340     else if (strncmp("AM43__SK", pBoardName, BOARD_NAME_LENGTH) == 0U)
341     {
342         pBoardKeyPad->buttonSet = 1;
343         pBoardKeyPad->scnKeyNum = 2;
344         pBoardKeyPad->pwrKeyNum = 2;
345         pBoardKeyPad->pwrKeyIdx = 2;
346         buttonStart[0]=6;
347         buttonOffset[0]=1;
348         powerOffset[0]=2;
350         /* Update the GPIO data for keypad inputs. */
351         KeyScn[0].instance=5;
352         KeyScn[0].pin=5;
354         KeyScn[1].instance=5;
355         KeyScn[1].pin=6;
356     }
357     /* Check if the board is SKAM335x by comparing the string read
358        from EEPROM. */
359     else if (strncmp("A335X_SK", pBoardName, BOARD_NAME_LENGTH) == 0U)
360     {
361         pBoardKeyPad->buttonSet = 1;
362         pBoardKeyPad->scnKeyNum = 4;
363         pBoardKeyPad->pwrKeyNum = 1;
364         pBoardKeyPad->pwrKeyIdx = 0;
365         buttonStart[0]=1;
366         buttonOffset[0]=1;
367         powerOffset[0]=1;
369         /*
370         ** Note: For skAM335x board the order of key press on the keypad should
371                  be in the following order
372         1: Key1: SW3 corresponding to SW3 switch on board.
373         2: Key2: SW1 corresponding to SW1 switch on board.
374         3: Key3: SW2 corresponding to SW2 switch on board.
375         4: Key4: SW4 corresponding to SW4 switch on board.
376         */
377         KeyScn[0].instance=0;
378         KeyScn[0].pin=30;
380         KeyScn[1].instance=2;
381         KeyScn[1].pin=3;
383         KeyScn[2].instance=2;
384         KeyScn[2].pin=2;
386         KeyScn[3].instance=2;
387         KeyScn[3].pin=5;
388     }
389     /* Check if the board is EVM AM65XX by comparing the string read from
390        EEPROM. */
391     else if (strncmp("AM6-COMP", pBoardName, BOARD_NAME_LENGTH) == 0U)
392     {
394         pBoardKeyPad->buttonSet = 1;
395         pBoardKeyPad->scnKeyNum = 2;
396         pBoardKeyPad->pwrKeyNum = 1;
397         pBoardKeyPad->pwrKeyIdx = 0;
398         buttonStart[0]=5;
399         buttonOffset[0]=1;
400         powerOffset[0]=1;
402         /* Update the GPIO data for keypad inputs. */
403         KeyScn[0].instance=0;
404         KeyScn[0].pin=24;
406         KeyScn[1].instance=0;
407         KeyScn[1].pin=27;
408     }
409 #if (defined(SOC_TPR12) || defined(SOC_AWR294X))
410     /* TODO: Need to update after programming board ID EEPROM
411      * Check if the board is EVM TPR12 by comparing the string read from
412        EEPROM. */
413     else if(status == S_PASS)
414     {
416         pBoardKeyPad->buttonSet = 1;
417         pBoardKeyPad->scnKeyNum = 1;
418         pBoardKeyPad->pwrKeyNum = 1;
419         pBoardKeyPad->pwrKeyIdx = 0;
420         buttonStart[0]=2;
421         buttonOffset[0]=1;
422         powerOffset[0]=1;
424         /* Update the GPIO data for keypad inputs. */
425         KeyScn[0].instance=0;
426         KeyScn[0].pin=28;
428     }
429 #endif
430     /* Check if the board is EVM AM64X by comparing the string read from
431        EEPROM. */
432     else if (strncmp("AM64-GPEVM", pBoardName, BOARD_NAME_LENGTH) == 0U)
433     {
435         pBoardKeyPad->buttonSet = 1;
436         pBoardKeyPad->scnKeyNum = 1;
437         pBoardKeyPad->pwrKeyNum = 1;
438         pBoardKeyPad->pwrKeyIdx = 0;
439         buttonStart[0]=5;
440         buttonOffset[0]=1;
441         powerOffset[0]=1;
443         /* Update the GPIO data for keypad inputs. */
444         KeyScn[0].instance=1;
445         KeyScn[0].pin=43;
446     }
447     else
448     {
449         status = E_FAIL;
450         UART_printf("The test is not supported on this board\n");
451     }
453     return status;