2 * Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
4 * Created on: 28.2.2013
8 * - Carlos Jenkins <carlos@jenkins.co.cr>
10 * This document contains proprietary information belonging to Czech
11 * Technical University in Prague. Passing on and copying of this
12 * document, and communication of its contents is not permitted
13 * without prior written authorization.
18 * This file contains commands for testing external SDRAM of RPP board.
22 #include "cmd_sdram.h"
29 #define BASE_FREQ_MILLIS 1000
30 #define FREQ_VARIABILITY 100
31 #define TEST_TASK_PRIORITY 0
32 #define TEST_TASK_STACK 512
37 extern xSemaphoreHandle rpp_sdr_cmdproc_semaphore;
38 static boolean_t stop_tasks = FALSE; /**< Flag for stopping all related tasks. */
39 static uint8_t tasks_running = 0; /**< Task counter - incremented each time task is spawn, decremented when task is deleted */
42 * @brief Set flag for tasks to finish.
44 * All tasks are reading the flag during their work and when
45 * they detect this flag is up, they stop the routine, decrement
46 * task counter and delete themselves.
48 static void wait_tasks_to_finish()
51 while (tasks_running > 0)
57 * @brief Wait for user input "q" to quit the loop.
61 while (rpp_sci_getc() < 0)
62 vTaskDelay(INPUT_IDLE / portTICK_RATE_MS);
67 * FreeRTOS Task that send some noise to the log from time to time.
69 void sdr_test_task(void *par)
71 // Calculate wait time in OS ticks
72 static const portTickType freq_ticks = BASE_FREQ_MILLIS / portTICK_RATE_MS;
73 portTickType last_wake_time = xTaskGetTickCount();
76 srand(2097925); // They are random, I swear xD
79 uint32_t variation = 0;
80 int8_t plus_minus = 1;
83 // Put something in the log
84 rpp_sdr_printf((const char *)
85 "This is the noise generator at iteration %d "
86 "putting some noise value %d.", i, rand()
91 variation = freq_ticks +
92 (plus_minus * ((rand() % FREQ_VARIABILITY) + 1));
93 plus_minus = plus_minus * -1;
94 vTaskDelayUntil(&last_wake_time, variation);
104 * SDR Test entry point.
113 xTaskHandle test_task_handle;
115 // Spawn noise task first, and later enable logging. Depending on the time
116 // required the first logs might not be registered, but that's ok, is better
117 // to check if logging could be enabled after data is being sent that enable
118 // command processor (which output messages to the SCI), and that inmediatly
119 // after the noise task could not be created, forcing to close the just
120 // opened command processor.
121 portBASE_TYPE task_created = xTaskCreate(sdr_test_task,
123 TEST_TASK_STACK, NULL, TEST_TASK_PRIORITY,
127 if (task_created != pdPASS) {
129 rpp_sci_printf((const char *)
130 "ERROR: Problem spawning the test task. "
131 "Error code: %d\r\n", (uint32_t)task_created
139 if (rpp_sdr_setup(TRUE) != SUCCESS) {
140 rpp_sci_printf((const char *)
141 "ERROR: Problem enabling the logging module. "
144 wait_tasks_to_finish();
148 // Wait for the SDR included command processor to finish
149 xSemaphoreTake(rpp_sdr_cmdproc_semaphore, portMAX_DELAY);
150 wait_tasks_to_finish();
152 /// Reset module configuration
153 if (rpp_sdr_setup(FALSE) != SUCCESS) {
154 rpp_sci_printf((const char *)
155 "ERROR: Could not stop logging module.\r\n"
160 rpp_sci_printf((const char *)"\r\n");
167 * @brief Start SDR test routine
169 * @param[in] cmd_io Pointer to IO stack
170 * @param[in] des Pointer to command descriptor
171 * @param[in] param Parameters of command
174 int cmd_do_test_log(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
181 * @brief Tests the capacity and fitness of connected SDRAM
183 * @param[in] cmd_io Pointer to IO stack
184 * @param[in] des Pointer to command descriptor
185 * @param[in] param Parameters of command
186 * @return 0 when OK or error code
188 int cmd_do_test_ram(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
190 volatile uint32_t *addrPtr = (uint32_t *)0x80000000U;
191 volatile uint32_t *endAddr = (uint32_t *)0x83FFFFFFU;
192 uint32_t pattern = 0x55555555U;
195 uint32_t readVal = 0;
197 while (addrPtr <= endAddr) {
199 pattern += 0x55555555U;
203 addrPtr = (uint32_t *)0x80000000U;
204 pattern = 0x55555555U;
205 while (addrPtr <= endAddr) {
207 if (pattern == readVal) cnt++;
208 else if (errCnt++ <= 10)
209 rpp_sci_printf("Error at %h\r\n",addrPtr);
211 pattern += 0x55555555U;
215 cnt = cnt * sizeof(uint32_t) / 1024 / 1024;
217 rpp_sci_printf("SDRAM not connected.");
219 rpp_sci_printf("SDRAM installed: %d MB", cnt);
226 /** Command descriptor for test SDRAM */
227 cmd_des_t const cmd_des_test_sdram = {
229 "sdramtest","Test if the SDRAM module is connected and if so, measures its capacity",
230 "### Command syntax ###\n"
234 "### Description ###\n"
236 "This command tests SDRAM address space by writing and reading a\n"
237 "pattern to/from it. It detects the SDRAM capacity.\n"
242 " SDRAM installed: 64 MB\n",
243 CMD_HANDLER(cmd_do_test_ram), (void *)&cmd_list_sdram
246 /** Command descriptor for test log to SDRAM */
247 cmd_des_t const cmd_des_test_log = {
249 "sdramlogtest","Open a command subprocessor for managing SDRAM logging",
250 "### Command syntax ###\n"
254 "### Description ###\n"
256 "The command opens a subcommand processor, which contains testing\n"
257 "commands for logging into SDRAM.\n",
258 CMD_HANDLER(cmd_do_test_log), (void *)&cmd_list_sdram
261 /** List of commands for sdram, defined as external */
262 cmd_des_t const *cmd_list_sdram[] = {