1- #include <stdio.h> // Standard I/O functions
2- #include <stdint.h> // Standard integer types
3- #include "io.h" // I/O functions for memory-mapped I/O
4- #include <unistd.h> // Standard library for usleep function
5- #include <system.h> // System definitions
6- #include "altera_avalon_sysid_qsys_regs.h" // Altera Avalon SysID Qsys register definitions
1+ #include <stdio.h>
2+ #include <stdint.h>
3+ #include "io.h"
4+ #include <unistd.h>
5+ #include <system.h>
6+ #include "altera_avalon_sysid_qsys_regs.h"
77
8- #define OCM_BASE INTEL_ONCHIP_MEMORY_0_BASE // Base address for on-chip memory
8+ #define OCM_BASE INTEL_ONCHIP_MEMORY_0_BASE
99
10- int main () {
11- int p ; // Variable to store memory value
12- int p_updated ; // Variable to store updated memory value
13- int sys_id ; // Variable to store system ID (unused)
14- int i ; // Loop counter
10+ #if 0
11+ // Using usleep as the delay function
12+ int usleep (useconds_t usec );
1513
14+ // Function to test PIO functionality
15+ int pio_test ()
16+ {
17+ int count = 0 ;
18+ int i ;
19+ int pio_err = 0 ;
20+ printf ("Application to toggle the PIOs- [4:0] \n" );
21+
22+ while (count < 64 )
23+ {
24+ i = count & 0xf ;
25+
26+ // Write data to the PIO register at base address PIO_0_BASE
27+ IOWR_ALTERA_AVALON_PIO_DATA (PIO_0_BASE , count & 0xf );
28+
29+ // Introduce a short delay
30+ usleep (100 );
31+
32+ // Read back data from the PIO register
33+ printf ("DATA READBACK FROM PIO_0_BASE is 0x%x \n" , IORD_ALTERA_AVALON_PIO_DATA (PIO_0_BASE ));
34+
35+ // Verify if the written data matches the read data
36+ if (i != IORD_ALTERA_AVALON_PIO_DATA (PIO_0_BASE ))
37+ {
38+ printf ("Data MISMATCH - TEST FAILED \n" );
39+ pio_err = pio_err + 1 ;
40+ }
41+ else
42+ {
43+ printf ("DATA MATCHED - TEST PASSED \n" );
44+ }
45+ count ++ ;
46+ }
47+ return pio_err ;
48+ }
49+ #endif
50+
51+ int main ()
52+ {
53+ int p ;
54+ int p_updated ;
55+ int sys_id ;
56+ int i ;
57+
1658 // Print initial messages
17- printf ("Hello World from Agilex-5 NIOSV/c core! \n" );
59+ printf ("Hello World from Agilex-5 NIOSV/c core! \n" );
1860 printf ("Application will execute Memory Test \n" );
19-
20- // Print starting message for memory test
61+
62+ // Start memory test by reading and writing values to on-chip memory
2163 printf ("Starting Memory test \n" );
2264
23- // Loop to test memory locations
24- for ( i = 0 ; i < 32 ; i = i + 4 ) {
25- // Read value from memory
65+ for ( i = 0 ; i < 32 ; i = i + 4 )
66+ {
67+ // Read value from memory at specified base address and offset
2668 p = IORD_32DIRECT (OCM_BASE , i );
27- printf ("Value at memory location 0x%x with offset %d is 0x%x\n" , OCM_BASE , i , p );
28-
29- // Write a test value to memory
69+ printf ("value at memory location 0x%x with offset %d is 0x%x\n" , OCM_BASE , i , p );
70+
71+ // Write a test pattern to memory
3072 IOWR_32DIRECT (OCM_BASE , i , 0xa5a5a5a5 );
31- // Read the updated value from memory
73+
74+ // Read back the value to verify the write operation
3275 p_updated = IORD_32DIRECT (OCM_BASE , i );
3376 printf ("After write: value at memory location 0x%x with offset %d is 0x%x\n" , OCM_BASE , i , p_updated );
3477
35- // Check if the write was successful
36- if (p_updated == 0xa5a5a5a5 ) {
37- printf ("Memory test passed at offset %d\n" , i );
38- } else {
39- printf ("Memory test failed at offset %d\n" , i );
78+ // Verify if the written value matches expected data
79+ if (p_updated == 0xa5a5a5a5 )
80+ {
81+ printf ("Memory write test PASSED\n" );
82+ }
83+ else
84+ {
85+ printf ("Memory write test FAILED at location 0x%X\n" , (OCM_BASE + i ));
4086 }
4187 }
4288
43- return 0 ; // Exit the application
44- }
89+ printf ("Memory Test Complete \n" );
90+
91+ #if 0
92+ int pio_fail_flag ;
93+
94+ // Run the PIO test function
95+ pio_fail_flag = pio_test ();
96+
97+ // Check the result of the PIO test
98+ if (pio_fail_flag != 0 )
99+ {
100+ printf ("NIOSV-PIO Test failed with PIO_ERR = %d\n" , pio_fail_flag );
101+ }
102+ else
103+ {
104+ printf ("NIOSV-PIO Test PASSED \n" );
105+ }
106+ #endif
107+
108+ // Read and print the System ID from the peripheral core
109+ printf ("Print the value of System ID \n" );
110+ sys_id = IORD_ALTERA_AVALON_SYSID_QSYS_ID (SYSID_QSYS_0_BASE ); // Read System ID from the Qsys system ID peripheral
111+ printf ("System ID from Peripheral core is 0x%X \n" , sys_id );
112+
113+ return 0 ;
114+ }
0 commit comments