]> rtime.felk.cvut.cz Git - fpga/zynq/canbench-sw.git/blob - system/ip/servo_led_ps2_1.0/drivers/servo_led_ps2_v1_0/src/servo_led_ps2_selftest.c
microzed_apo: IP skeleton of servo with alternative direct LEDs.
[fpga/zynq/canbench-sw.git] / system / ip / servo_led_ps2_1.0 / drivers / servo_led_ps2_v1_0 / src / servo_led_ps2_selftest.c
1
2 /***************************** Include Files *******************************/
3 #include "servo_led_ps2.h"
4 #include "xparameters.h"
5 #include "stdio.h"
6 #include "xil_io.h"
7
8 /************************** Constant Definitions ***************************/
9 #define READ_WRITE_MUL_FACTOR 0x10
10
11 /************************** Function Definitions ***************************/
12 /**
13  *
14  * Run a self-test on the driver/device. Note this may be a destructive test if
15  * resets of the device are performed.
16  *
17  * If the hardware system is not built correctly, this function may never
18  * return to the caller.
19  *
20  * @param   baseaddr_p is the base address of the SERVO_LED_PS2instance to be worked on.
21  *
22  * @return
23  *
24  *    - XST_SUCCESS   if all self-test code passed
25  *    - XST_FAILURE   if any self-test code failed
26  *
27  * @note    Caching must be turned off for this function to work.
28  * @note    Self test may fail if data memory and device are not on the same bus.
29  *
30  */
31 XStatus SERVO_LED_PS2_Reg_SelfTest(void * baseaddr_p)
32 {
33         u32 baseaddr;
34         int write_loop_index;
35         int read_loop_index;
36         int Index;
37
38         baseaddr = (u32) baseaddr_p;
39
40         xil_printf("******************************\n\r");
41         xil_printf("* User Peripheral Self Test\n\r");
42         xil_printf("******************************\n\n\r");
43
44         /*
45          * Write to user logic slave module register(s) and read back
46          */
47         xil_printf("User logic slave module test...\n\r");
48
49         for (write_loop_index = 0 ; write_loop_index < 4; write_loop_index++)
50           SERVO_LED_PS2_mWriteReg (baseaddr, write_loop_index*4, (write_loop_index+1)*READ_WRITE_MUL_FACTOR);
51         for (read_loop_index = 0 ; read_loop_index < 4; read_loop_index++)
52           if ( SERVO_LED_PS2_mReadReg (baseaddr, read_loop_index*4) != (read_loop_index+1)*READ_WRITE_MUL_FACTOR){
53             xil_printf ("Error reading register value at address %x\n", (int)baseaddr + read_loop_index*4);
54             return XST_FAILURE;
55           }
56
57         xil_printf("   - slave register write/read passed\n\n\r");
58
59         return XST_SUCCESS;
60 }