]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blob - psdk_cust/pdk_k2g_1_0_1_1_eng/packages/ti/board/diag/mem/src/mem_test.c
PASDK-258:Update PDK eng to 1.0.1.1. Using build number to differentiate PDK eng...
[processor-sdk/performance-audio-sr.git] / psdk_cust / pdk_k2g_1_0_1_1_eng / packages / ti / board / diag / mem / src / mem_test.c
1 /*
2  * Copyright (c) 2015, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * *  Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * *  Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the 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 "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
33 #include <ti/drv/uart/UART_stdio.h>
34 #include <stdlib.h>
36 #include "board.h"
37 #include "board_cfg.h"
39 static inline int32_t board_memory_test (uint32_t start_address, uint32_t end_address)
40 {
41         uint32_t index, value;
43         UART_printf("First test started\n");
44         UART_printf("Writing to test area...\n");
45         /* Write a pattern */
46         for (index = start_address; (index >= start_address) && (index < end_address); index += 4) {
47                 *(volatile uint32_t *) index = (uint32_t)index;
48                 if (!(index & 0xFFFFFFc)) UART_printf("\tWrite up to 0x%08x done\n", index);
49         }
51         UART_printf("Write finished!\n");
52         UART_printf("Checking values...\n");
54         /* Read and check the pattern */
55         for (index = start_address;  (index >= start_address) && (index < end_address); index += 4) {
57                 value = *(uint32_t *) index;
59                 if (value  != index) {
60                         UART_printf("board_memory_test: Failed at address index = 0x%x value = 0x%x *(index) = 0x%x\n",
61                                         index, value, *(volatile uint32_t *) index);
62                         return (-1);
63                 }
64                 if (!(index & 0xFFFFFFc))UART_printf("\tRead up to 0x%08x okay\n", index);
65         }
67         UART_printf("Second test started\n");
68         UART_printf("Writing complementary values to test area...\n");
69         /* Write a pattern for complementary values */
70         for (index = start_address; (index >= start_address) && (index < end_address); index += 4) {
71                 *(volatile uint32_t *) index = (uint32_t)~index;
72                 if (!(index & 0xFFFFFFc)) UART_printf("\tWrite up to 0x%08x done\n", index);
73         }
75         UART_printf("Write finished!\n");
76         UART_printf("Checking values...\n");
77         /* Read and check the pattern */
78         for (index = start_address;  (index >= start_address) && (index < end_address); index += 4) {
80                 value = *(uint32_t *) index;
82                 if (value  != ~index) {
83                         UART_printf("board_memory_test: Failed at address index = 0x%x value = 0x%x *(index) = 0x%x\n",
84                                         index, value, *(volatile uint32_t *) index);
85                         return (-1);
86                 }
87                 if (!(index & 0xFFFFFFc)) UART_printf("\tRead up to 0x%08x okay\n", index);
88         }
90         return 0;
91 }
93 int32_t board_external_memory_test()
94 {
95         UART_printf("board_external_memory_test: Start address (0x%08x), end address (0x%08x)\n",
96                 BOARD_DDR3_START_ADDR, BOARD_DDR3_END_ADDR);
97         return board_memory_test(BOARD_DDR3_START_ADDR, BOARD_DDR3_END_ADDR);
98 }
100 int mem_test()
102         int32_t status;
103         int ret;
105         UART_printf("\n*********************************************\n"); 
106         UART_printf  ("*              DDR Memory Test              *\n");
107         UART_printf  ("*********************************************\n");
109         UART_printf("\nTesting writing and reading memory\n");
110         status = board_external_memory_test();
111         if (status < 0)
112         {
113                 UART_printf("Memory test failed!\n");
114                 ret = -1;
115         }
116         else
117         {
118                 UART_printf("Memory test passed!\n");
119                 ret = 0;
120         }
121         return ret;
124 /*
125  *  ======== main ========
126  */
127 int main(void)
129     Board_initCfg boardCfg;
130 #ifdef PDK_RAW_BOOT
131     boardCfg = BOARD_INIT_DEFAULT;
132 #else
133     boardCfg = BOARD_INIT_UART_STDIO;
134 #endif
135     Board_init(boardCfg);
136     return mem_test();