/
xscuwdt_polled_example.c
182 lines (155 loc) · 5.14 KB
/
xscuwdt_polled_example.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/******************************************************************************
* Copyright (C) 2010 - 2022 Xilinx, Inc. All rights reserved.
* Copyright (C) 2022 - 2023 Advanced Micro Devices, Inc. All rights reserved.
* SPDX-License-Identifier: MIT
******************************************************************************/
/*****************************************************************************/
/**
* @file xscuwdt_polled_example.c
*
* This file contains a design example using the Xilinx SCU Private Watchdog
* Timer driver (XScuWdt) and hardware device in watchdog mode. This test
* illustrates how to initialize the watchdog device and restart it periodially
* to avoid the assertion of the WDRESETREQ pin.
*
* @note None.
*
* MODIFICATION HISTORY:
*
*<pre>
* Ver Who Date Changes
* ----- ---- -------- ---------------------------------------------
* 1.00a sdm 01/15/10 First release
* 2.5 asa 07/18/23 Added support for workflow decouplig flow.
* Interrupt wrapper support has also been added.
* 2.5 dp 09/08/23 Update example to stop wdt at end of the test
*</pre>
******************************************************************************/
/***************************** Include Files *********************************/
#include "xparameters.h"
#include "xscuwdt.h"
#include "xil_printf.h"
#include "sleep.h"
/************************** Constant Definitions *****************************/
/*
* The following constants map to the XPAR parameters created in the
* xparameters.h file. They are only defined here such that a user can easily
* change all the needed parameters in one place.
*/
#ifndef SDT
#define WDT_DEVICE_ID XPAR_SCUWDT_0_DEVICE_ID
#else
#define SCUWDT_BASEADDRESS XPAR_XSCUWDT_0_BASEADDR
#endif
#define WDT_LOAD_VALUE 0xFFFF0000
/**************************** Type Definitions *******************************/
/***************** Macros (Inline Functions) Definitions *********************/
/************************** Function Prototypes ******************************/
#ifndef SDT
int ScuWdtPolledExample(XScuWdt *WdtInstancePtr, u16 DeviceId);
#else
int ScuWdtPolledExample(XScuWdt *WdtInstancePtr, UINTPTR BaseAddress);
#endif
/************************** Variable Definitions *****************************/
XScuWdt Watchdog; /* Cortex SCU Private WatchDog Timer Instance */
/*****************************************************************************/
/**
*
* Main function to call the Scu Priver Wdt polled mode example.
*
*
* @return XST_SUCCESS if successful, XST_FAILURE if unsuccessful.
*
* @note None.
*
******************************************************************************/
#ifndef TESTAPP_GEN
int main(void)
{
int Status;
xil_printf("SCU WDT Polled Mode Example Test \r\n");
/*
* Call the example , specify the device ID that is generated in
* xparameters.h.
*/
#ifndef SDT
Status = ScuWdtPolledExample(&Watchdog, WDT_DEVICE_ID);
#else
Status = ScuWdtPolledExample(&Watchdog, SCUWDT_BASEADDRESS);
#endif
if (Status != XST_SUCCESS) {
xil_printf("SCU WDT Polled Mode Example Test Failed\r\n");
return XST_FAILURE;
}
xil_printf("Successfully ran SCU WDT Polled Mode Example Test\r\n");
return XST_SUCCESS;
}
#endif
/*****************************************************************************/
/**
* This function does a minimal test on the watchdog timer device and driver.
* The purpose of this function is to illustrate how to use the XScuWdt driver.
*
* @param WdtInstancePtr is a pointer to the instance of XScuWdt driver.
* @param DeviceId is the unique device id of the device.
*
* @return XST_SUCCESS if successful, otherwise XST_FAILURE.
*
* @note None.
*
****************************************************************************/
#ifndef SDT
int ScuWdtPolledExample(XScuWdt *WdtInstancePtr, u16 DeviceId)
#else
int ScuWdtPolledExample(XScuWdt *WdtInstancePtr, UINTPTR BaseAddress)
#endif
{
int Status;
XScuWdt_Config *ConfigPtr;
int Count = 0;
/*
* Initialize the SCU Private Wdt driver so that it is ready to use.
*/
#ifndef SDT
ConfigPtr = XScuWdt_LookupConfig(DeviceId);
#else
ConfigPtr = XScuWdt_LookupConfig(BaseAddress);
#endif
/*
* This is where the virtual address would be used, this example
* uses physical address.
*/
Status = XScuWdt_CfgInitialize(WdtInstancePtr, ConfigPtr,
ConfigPtr->BaseAddr);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
}
/*
* Put the watchdog timer in watchdog mode.
*/
XScuWdt_SetWdMode(WdtInstancePtr);
/*
* Load the watchdog counter register.
*/
XScuWdt_LoadWdt(WdtInstancePtr, WDT_LOAD_VALUE);
/*
* Start the ScuWdt device.
*/
XScuWdt_Start(WdtInstancePtr);
while (Count < 20) {
/*
* We have nothing to do here. Sleep for some time and then
* restart the watchdog such that the WDRESETREQ pin is not
* asserted. If the WDRESETREQ pin is asserted and the system
* is reset, then the watchdog device/driver is not working as
* expected.
* The user application needs to call the XScuWdt_RestartWdt
* periodially to avoid the watchdog from being timed-out.
*/
sleep(1);
Count++;
XScuWdt_RestartWdt(WdtInstancePtr);
}
XScuWdt_Stop(WdtInstancePtr);
return XST_SUCCESS;
}