1 #include <system_def.h>
11 #include <hal_machperiph.h>
17 #include <ul_logreg.h>
19 #include "appl_defs.h"
20 #include "appl_fpga.h"
22 int cmd_do_test_memusage(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
29 snprintf(str, sizeof(str), "memusage maxaddr 0x%08lx\n", (unsigned long)maxaddr);
30 cmd_io_write(cmd_io, str, strlen(str));
35 int cmd_do_test_adc(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
37 printf("ADC: %ld %ld %ld %ld %ld\n", (LPC_ADC->DR[0] & 0xFFF0) >> 4,
38 (LPC_ADC->DR[1] & 0xFFF0) >> 4,
39 (LPC_ADC->DR[2] & 0xFFF0) >> 4,
40 (LPC_ADC->DR[3] & 0xFFF0) >> 4,
41 (LPC_ADC->DR[7] & 0xFFF0) >> 4);
45 #ifdef APPL_WITH_DISTORE_EEPROM_USER
46 int cmd_do_test_distore(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
48 appl_distore_user_set_check4change();
52 int cmd_do_test_diload(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
54 appl_distore_user_restore();
57 #endif /*APPL_WITH_DISTORE_EEPROM_USER*/
59 int cmd_do_test_loglevel_cb(ul_log_domain_t *domain, void *context)
62 cmd_io_t *cmd_io = (cmd_io_t *)context;
65 snprintf(s, sizeof(s) - 1, "%s (%d)\n\r", domain->name, domain->level);
66 cmd_io_puts(cmd_io, s);
70 int cmd_do_test_loglevel(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
76 if (!line || (si_skspace(&line), !*line))
78 ul_logreg_for_each_domain(cmd_do_test_loglevel_cb, cmd_io);
82 res = ul_log_domain_arg2levels(line);
85 return res >= 0 ? 0 : CMDERR_BADPAR;
88 int cmd_do_spimst_blocking(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
93 int spi_chan = (int)(intptr_t)des->info[0];
94 uint8_t *tx_buff = NULL;
95 uint8_t *rx_buff = NULL;
100 if ((opchar = cmd_opchar_check(cmd_io, des, param)) < 0)
104 return -CMDERR_OPCHAR;
107 spi_chan = *param[1] - '0';
109 spi_drv = spi_find_drv(NULL, spi_chan);
112 return -CMDERR_BADSUF;
118 if (isdigit((int)*p))
120 if (si_long(&p, &addr, 16) < 0)
121 return -CMDERR_BADPAR;
124 if (si_fndsep(&p, "({") < 0)
125 return -CMDERR_BADSEP;
127 if ((res = si_add_to_arr(&p, (void **)&tx_buff, &len, 16, 1, "})")) < 0)
128 return -CMDERR_BADPAR;
130 rx_buff = malloc(len);
135 res = spi_transfer(spi_drv, addr, len, tx_buff, rx_buff);
139 printf("SPI! %02lX ERROR\n", addr);
144 printf("SPI! %02lX ", addr);
147 for (i = 0; i < len; i++)
148 printf("%s%02X", i ? "," : "", tx_buff[i]);
152 for (i = 0; i < len; i++)
153 printf("%s%02X", i ? "," : "", rx_buff[i]);
170 int sdram_access_test(void)
173 unsigned int pattern;
174 size_t ramsz = SDRAM_SIZE;
182 pattern = 0x12abcdef;
184 for (cnt = ramsz / sizeof(*ptr), ptr = (typeof(ptr))SDRAM_BASE; cnt--;)
187 pattern = pattern + 0x87654321;
191 printf("SDRAM write %d ms\n", (int)(lt_msdiff_t)(actual_msec - tic));
196 pattern = 0x12abcdef;
198 for (cnt = ramsz / sizeof(*ptr), ptr = (typeof(ptr))SDRAM_BASE; cnt--;)
202 printf("SDRAM error modify at %p (%08x)\n", ptr, *ptr ^ pattern);
207 pattern = pattern + 0x87654321;
211 printf("SDRAM modify %d ms\n", (int)(lt_msdiff_t)(actual_msec - tic));
216 pattern = 0x12abcdef;
218 for (cnt = ramsz / sizeof(*ptr), ptr = (typeof(ptr))SDRAM_BASE; cnt--;)
220 if (*(ptr++) != ~pattern)
222 printf("SDRAM error read at %p (%08x)\n", ptr, *ptr ^ pattern);
226 pattern = pattern + 0x87654321;
230 printf("SDRAM read %d ms\n", (int)(lt_msdiff_t)(actual_msec - tic));
237 for (cnt = ramsz / sizeof(*ptr), ptr = (typeof(ptr))SDRAM_BASE; cnt--;)
243 printf("SDRAM sum %d ms res 0x%08x\n", (int)(lt_msdiff_t)(actual_msec - tic), pattern);
245 for (blksz = 1; blksz < 256 ; blksz *= 2)
252 for (cnt = ramsz / sizeof(*ptr); cnt; cnt -= blksz)
254 ptr = (typeof(ptr))SDRAM_BASE;
256 //ptr = (typeof(ptr))cmd_do_test_memusage;
257 //ptr = (typeof(ptr))&ptr;
258 for (i = blksz; i--;)
263 printf("SDRAM sum %d blksz %d ms res 0x%08x\n", (int)(lt_msdiff_t)(actual_msec - tic), (int)blksz, pattern);
269 int cmd_do_testsdram(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
274 #endif /*SDRAM_BASE*/
276 int cmd_do_testlxpwrrx(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
278 pxmc_rocon_rx_data_hist_buff = NULL;
279 #ifndef PXMC_ROCON_TIMED_BY_RX_DONE
280 pxmc_rocon_rx_done_isr_setup(pxmc_rocon_rx_done_isr);
281 #endif /*PXMC_ROCON_TIMED_BY_RX_DONE*/
282 pxmc_rocon_rx_data_hist_buff_end = (void *)(FPGA_CONFIGURATION_FILE_ADDRESS +
284 pxmc_rocon_rx_data_hist_buff = (void *)FPGA_CONFIGURATION_FILE_ADDRESS;
288 int cmd_do_testlxpwrstat(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
290 printf("lxpwrrx period %ld latency %ld max %ld\n",
291 (long)pxmc_rocon_rx_cycle_time, (long)pxmc_rocon_rx_irq_latency,
292 (long)pxmc_rocon_rx_irq_latency_max);
296 int cmd_do_testfncapprox(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
308 if (si_ulong(&ps, &val, 0) < 0)
309 return -CMDERR_BADPAR;
312 xb = __builtin_clz(x);
315 *fpga_fncapprox_base = xl;
317 res = *fpga_fncapprox_base;
319 yl = (1LL << 62) / xl;
323 printf("val=0x%08lx res=0x%08lx ref=0x%08lx diff=%ld\n",
324 val, res, (unsigned long)yl, diff);
329 cmd_des_t const cmd_des_test_memusage = {0, 0,
330 "memusage", "report memory usage", cmd_do_test_memusage,
337 cmd_des_t const cmd_des_test_adc = {0, 0,
338 "testadc", "adc test", cmd_do_test_adc,
345 #ifdef APPL_WITH_DISTORE_EEPROM_USER
346 cmd_des_t const cmd_des_test_distore = {0, 0,
347 "testdistore", "test DINFO store", cmd_do_test_distore,
354 cmd_des_t const cmd_des_test_diload = {0, 0,
355 "testdiload", "test DINFO load", cmd_do_test_diload,
361 #endif /*APPL_WITH_DISTORE_EEPROM_USER*/
363 cmd_des_t const cmd_des_test_loglevel = {0, 0,
364 "loglevel", "select logging level",
365 cmd_do_test_loglevel, {}
368 cmd_des_t const cmd_des_spimst = {0, CDESM_OPCHR | CDESM_WR,
369 "SPIMST", "SPI master communication request",
370 cmd_do_spimst_blocking, {(void *)0}
373 cmd_des_t const cmd_des_spimstx = {0, CDESM_OPCHR | CDESM_WR,
374 "SPIMST#", "SPI# master communication request",
375 cmd_do_spimst_blocking, {(void *) - 1}
379 cmd_des_t const cmd_des_testsdram = {0, 0,
380 "testsdram", "test SDRAM",
381 cmd_do_testsdram, {(void *)0}
383 #endif /*SDRAM_BASE*/
386 cmd_des_t const cmd_des_testlxpwrrx = {0, 0,
387 "testlxpwrrx", "capture data stream from lxpwr",
388 cmd_do_testlxpwrrx, {(void *)0}
391 cmd_des_t const cmd_des_testlxpwrstat = {0, 0,
392 "testlxpwrstat", "lxpwr interrupt statistic",
393 cmd_do_testlxpwrstat, {(void *)0}
396 cmd_des_t const cmd_des_testfncapprox = {0, 0,
397 "testfncapprox", "test of function approximator",
398 cmd_do_testfncapprox, {(void *)0}
401 cmd_des_t const *const cmd_appl_tests[] =
403 &cmd_des_test_memusage,
405 #ifdef APPL_WITH_DISTORE_EEPROM_USER
406 &cmd_des_test_distore,
407 &cmd_des_test_diload,
408 #endif /*APPL_WITH_DISTORE_EEPROM_USER*/
409 &cmd_des_test_loglevel,
414 #endif /*SDRAM_BASE*/
415 &cmd_des_testlxpwrrx,
416 &cmd_des_testlxpwrstat,
417 &cmd_des_testfncapprox,