1 /**
2 * @file test.c
3 *
4 * @brief
5 * Test Code to test the Watchdog Timer Module
6 *
7 * \par
8 * NOTE:
9 * (C) Copyright 2012 Texas Instruments, Inc.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 *
15 * Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 *
18 * Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the
21 * distribution.
22 *
23 * Neither the name of Texas Instruments Incorporated nor the names of
24 * its contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *
39 */
40 #include <c6x.h>
41 #include <stdint.h>
42 #include <string.h>
44 /* BIOS/XDC Include Files. */
45 #include <xdc/std.h>
46 #include <xdc/runtime/System.h>
47 #include <ti/sysbios/BIOS.h>
48 #include <ti/sysbios/knl/Task.h>
50 /* WatchdogTimer module includes */
51 #include <ti/instrumentation/wdtimer/WatchdogTimer.h>
53 /* API test result */
54 Bool apiTestPassed = FALSE;
56 /**********************************************************************
57 ************************* Unit Test Functions ************************
58 **********************************************************************/
60 /* Exception function that is plugged into exception module */
61 void wdExceptionFunction (void)
62 {
63 System_printf ("Core %d: wdExceptionFunction - The watchdog timer has expired.\n", DNUM);
65 if (apiTestPassed)
66 {
67 System_printf ("Core %d: Watchdog Timer Test PASSED.\n", DNUM);
68 }
69 else
70 {
71 System_printf ("Core %d: Watchdog Timer Test FAILED.\n", DNUM);
72 }
73 }
75 /* Test task which configures the watchdog timer API tests */
76 void testTask (void)
77 {
78 WatchdogTimer_InitCfg wdCfg;
80 /* Initialize the watchdog timer configuration structure to all zeros */
81 memset ((void *)&wdCfg, 0, sizeof(WatchdogTimer_InitCfg));
83 System_printf ("Core %d: Configuring Watchdog Timer for API tests.\n", DNUM);
85 /* Configure the watchdog timer with a low period and no output event
86 * This scenario is used to test the different watchdog reset APIs. After
87 * testing all reset APIs the watchdog will be forcefully timed out. The period
88 * is configured to be low enough so that if none of the reset APIs work the
89 * reset will occur prior to the forced timeout. */
90 wdCfg.wdPeriodLo = 0x00001000;
91 wdCfg.wdPeriodHi = 0x00000000;
92 wdCfg.wdResetType = WatchdogTimer_RstcfgResetType_SOFT_RESET;
93 wdCfg.wdRegisterTimeoutExc = TRUE;
94 wdCfg.rstOmode = WatchdogTimer_RstmuxOmode_DEFAULT_NO_OUTPUT_EVENT;
95 wdCfg.rstDelay = WatchdogTimer_RstmuxDelay_4096CPU_DIV_6_CYCLES_DEFAULT;
97 /* Initialize and start the timer */
98 WatchdogTimer_Init(&wdCfg);
100 /* Test ResetTimer API */
101 System_printf ("Core %d: Servicing Watchdog Timer via ResetTimer API.\n", DNUM);
102 WatchdogTimer_ResetTimer();
104 /* Test individual service state APIs */
105 System_printf ("Core %d: Servicing Watchdog Timer via MoveTo APIs.\n", DNUM);
106 WatchdogTimer_MoveToServiceState();
107 WatchdogTimer_MoveToActiveState();
109 /* If reached here the API tests passed. Force the watchdog timeout */
110 apiTestPassed = TRUE;
111 System_printf ("Core %d: Forcing Timeout.\n", DNUM);
112 WatchdogTimer_ForceTimeout();
114 /* If the force timeout API doesn't work the exception will not execute and this
115 * code will be reached. */
116 System_printf ("\nCore %d: ForceTimeout API Test FAILED.", DNUM);
117 }
119 int32_t main(int32_t argc, char* argv[])
120 {
121 Task_Params taskParams;
123 System_printf ("**********************************************\n");
124 System_printf ("********** Watchdog Timer Unit Test **********\n");
125 System_printf ("**********************************************\n");
127 /* Initialize the Task Parameters. */
128 Task_Params_init(&taskParams);
130 /* Create a task that causes an exception */
131 Task_create((Task_FuncPtr)testTask, &taskParams, NULL);
133 BIOS_start();
134 return 0;
135 }