1 #include <system_def.h>
11 #include <hal_machperiph.h>
17 #include <ul_logreg.h>
19 #include "appl_defs.h"
21 int cmd_do_test_memusage(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
28 snprintf(str,sizeof(str),"memusage maxaddr 0x%08lx\n",(unsigned long)maxaddr);
29 cmd_io_write(cmd_io,str,strlen(str));
34 int cmd_do_test_adc(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
38 if (cmd_io->priv.ed_line.io_stack)
39 cmd_io = cmd_io->priv.ed_line.io_stack;
41 F = cmd_io_as_file(cmd_io, "r+");
45 fprintf(F, "ADC: %ld %ld %ld %ld %ld\n", (LPC_ADC->DR[0] & 0xFFF0) >> 4,
46 (LPC_ADC->DR[1] & 0xFFF0) >> 4,
47 (LPC_ADC->DR[2] & 0xFFF0) >> 4,
48 (LPC_ADC->DR[3] & 0xFFF0) >> 4,
49 (LPC_ADC->DR[7] & 0xFFF0) >> 4);
54 #ifdef APPL_WITH_DISTORE_EEPROM_USER
55 int cmd_do_test_distore(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
57 appl_distore_user_set_check4change();
61 int cmd_do_test_diload(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
63 appl_distore_user_restore();
66 #endif /*APPL_WITH_DISTORE_EEPROM_USER*/
68 int cmd_do_test_loglevel_cb(ul_log_domain_t *domain, void *context)
71 cmd_io_t *cmd_io = (cmd_io_t *)context;
74 snprintf(s,sizeof(s)-1,"%s (%d)\n\r",domain->name, domain->level);
75 cmd_io_puts(cmd_io, s);
79 int cmd_do_test_loglevel(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
85 if(!line||(si_skspace(&line),!*line)) {
86 ul_logreg_for_each_domain(cmd_do_test_loglevel_cb, cmd_io);
88 res=ul_log_domain_arg2levels(line);
91 return res>=0?0:CMDERR_BADPAR;
94 int cmd_do_spimst_blocking(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
99 int spi_chan = (int)(intptr_t)des->info[0];
100 uint8_t *tx_buff = NULL;
101 uint8_t *rx_buff = NULL;
106 if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
108 return -CMDERR_OPCHAR;
111 spi_chan=*param[1]-'0';
113 spi_drv = spi_find_drv(NULL, spi_chan);
115 return -CMDERR_BADSUF;
120 if(isdigit((int)*p)){
121 if(si_long(&p,&addr,16)<0) return -CMDERR_BADPAR;
123 if(si_fndsep(&p,"({")<0) return -CMDERR_BADSEP;
125 if((res=si_add_to_arr(&p, (void**)&tx_buff, &len, 16, 1, "})"))<0)
126 return -CMDERR_BADPAR;
132 res = spi_transfer_with_mode(spi_drv, addr, len, tx_buff, rx_buff, SPI_MODE_3);
135 printf("SPI! %02lX ERROR\n",addr);
138 printf("SPI! %02lX ",addr);
140 for(i=0;i<len;i++) printf("%s%02X",i?",":"",tx_buff[i]);
142 for(i=0;i<len;i++) printf("%s%02X",i?",":"",rx_buff[i]);
156 int sdram_access_test(void)
159 unsigned int pattern;
160 size_t ramsz = SDRAM_SIZE;
168 pattern = 0x12abcdef;
169 for (cnt = ramsz/sizeof(*ptr), ptr = (typeof(ptr))SDRAM_BASE; cnt--;) {
171 pattern = pattern + 0x87654321;
175 printf("SDRAM write %d ms\n", (int)(lt_msdiff_t)(actual_msec - tic));
180 pattern = 0x12abcdef;
181 for (cnt = ramsz/sizeof(*ptr), ptr = (typeof(ptr))SDRAM_BASE; cnt--;) {
182 if(*ptr != pattern) {
183 printf("SDRAM error modify at %p (%08x)\n", ptr, *ptr ^ pattern);
187 pattern = pattern + 0x87654321;
191 printf("SDRAM modify %d ms\n", (int)(lt_msdiff_t)(actual_msec - tic));
196 pattern = 0x12abcdef;
197 for (cnt = ramsz/sizeof(*ptr), ptr = (typeof(ptr))SDRAM_BASE; cnt--;) {
198 if(*(ptr++) != ~pattern) {
199 printf("SDRAM error read at %p (%08x)\n", ptr, *ptr ^ pattern);
202 pattern = pattern + 0x87654321;
206 printf("SDRAM read %d ms\n", (int)(lt_msdiff_t)(actual_msec - tic));
212 for (cnt = ramsz/sizeof(*ptr), ptr = (typeof(ptr))SDRAM_BASE; cnt--;) {
217 printf("SDRAM sum %d ms res 0x%08x\n", (int)(lt_msdiff_t)(actual_msec - tic), pattern);
219 for (blksz=1; blksz < 256 ; blksz *= 2) {
224 for (cnt = ramsz/sizeof(*ptr); cnt; cnt -= blksz) {
225 ptr = (typeof(ptr))SDRAM_BASE;
226 //ptr = (typeof(ptr))cmd_do_test_memusage;
227 //ptr = (typeof(ptr))&ptr;
228 for (i = blksz; i--; )
232 printf("SDRAM sum %d blksz %d ms res 0x%08x\n", (int)(lt_msdiff_t)(actual_msec - tic), (int)blksz, pattern);
238 int cmd_do_testsdram(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
244 int cmd_do_testmpu(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
247 int reg_cnt = hal_mpu_region_count();
250 for (i = 0; i < reg_cnt; i++) {
252 ra = MPU->RBAR & MPU_RBAR_ADDR_Msk;
253 rsz = (1 << (__mfld2val(MPU_RASR_SIZE_Msk, MPU->RASR) + 1)) - 1;
254 printf("R%d %08lX..%08lX %08lX %08lX\n", i, ra, ra + rsz, MPU->RBAR, MPU->RASR);
257 /*printf("IAP version %08X\n", lpcisp_read_partid());*/
262 int cmd_do_goaddr(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
270 if(si_ulong(&p,&addr,16)<0) return -CMDERR_BADPAR;
272 printf("Jump to address %08lX\n\n", addr);
274 ((void(*)(void))addr)();
279 int cmd_do_mujtest(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
281 volatile uint32_t *testaddr = (volatile uint32_t *)0x80004000;
284 printf("read %d\n", p);
286 printf("read %d\n", p);
288 printf("read %d\n", p);
290 printf("read %d\n", p);
292 printf("read %d\n", p);
294 printf("read %d\n", p);
296 printf("read %d\n", p);
298 printf("read %d\n", p);
300 printf("read %d\n", p);
304 int cmd_do_zmer(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
306 volatile uint32_t *testaddr = (volatile uint32_t *)0x80004000;
307 int32_t values[2048];
308 uint32_t status, status_old, bank,i;
310 status_old = *testaddr;
311 //while((status_old & (1<<2))==(status & (1<<2))) status=*testaddr;
312 //while (*testaddr &(1<<6));
314 while (!(*testaddr & (1<<6))) printf("\ncekam\n");
316 testaddr = (volatile uint32_t *)0x80008000;
318 // printf("bank1\n");
319 testaddr = (volatile uint32_t *)0x80009000;
324 // values[i]=*testaddr++;
333 //testaddr = (volatile uint32_t *)0x80008000;
337 for (i=0;i<1024;i++){
341 printf("%d\n",values[i]);
349 int cmd_do_runnung_meas(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]){
350 volatile uint32_t *testaddr = (volatile uint32_t *)0x80004000;
351 int32_t values[1024];
352 uint32_t status, status_old, bank,i;
354 status_old = *testaddr;
356 while((status_old & (1<<2))==(status & (1<<2))) {status=*testaddr; printf("dely %i %i",status_old & (1<<2),status & (1<<2));}
358 testaddr = (volatile uint32_t *)0x80009000;
360 testaddr = (volatile uint32_t *)0x80008000;
363 // values[i]=*testaddr++;
372 //testaddr = (volatile uint32_t *)0x80008000;
376 //printf("zacatek\n");
377 for (i=0;i<1024;i++){
378 printf("%d\n",values[i]);
385 int cmd_do_init(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
388 volatile uint32_t *testaddr = (volatile uint32_t *)0x80004000;
398 //*testaddr++ = 4879;
399 *testaddr++ = 5023999;
406 int cmd_do_send(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
409 volatile uint32_t *testaddr = (volatile uint32_t *)0x80004000;
411 int p=(int) strtol(param[1], &end, 10);
413 p=(int) strtol(end, &end, 10);
416 printf("sent %d & read %d\n", p, read);
420 cmd_des_t const cmd_des_test_memusage={0, 0,
421 "memusage","report memory usage",cmd_do_test_memusage,
425 cmd_des_t const cmd_des_test_adc={0, 0,
426 "testadc","adc test",cmd_do_test_adc,
430 #ifdef APPL_WITH_DISTORE_EEPROM_USER
431 cmd_des_t const cmd_des_test_distore={0, 0,
432 "testdistore","test DINFO store",cmd_do_test_distore,
436 cmd_des_t const cmd_des_test_diload={0, 0,
437 "testdiload","test DINFO load",cmd_do_test_diload,
440 #endif /*APPL_WITH_DISTORE_EEPROM_USER*/
442 cmd_des_t const cmd_des_test_loglevel={0, 0,
443 "loglevel","select logging level",
444 cmd_do_test_loglevel,{}};
446 cmd_des_t const cmd_des_spimst={0, CDESM_OPCHR|CDESM_WR,
447 "SPIMST","SPI master communication request",
448 cmd_do_spimst_blocking,{(void*)0}};
450 cmd_des_t const cmd_des_spimstx={0, CDESM_OPCHR|CDESM_WR,
451 "SPIMST#","SPI# master communication request",
452 cmd_do_spimst_blocking,{(void*)-1}};
454 cmd_des_t const cmd_des_testsdram={0, 0,
455 "testsdram","test SDRAM",
456 cmd_do_testsdram,{(void*)0}};
458 cmd_des_t const cmd_des_testmpu={0, 0,
459 "testmpu","test MPU",
460 cmd_do_testmpu,{(void*)0}};
462 cmd_des_t const cmd_des_goaddr={0, 0,
463 "goaddr","run from address",
464 cmd_do_goaddr,{(void*)0}};
466 cmd_des_t const cmd_des_mujtest={0,0,"mujtest","run my simple test", cmd_do_mujtest,{(void*)0}};
468 cmd_des_t const cmd_des_zmer={0,0,"zmer","read values from spectrometer (2 readouts)", cmd_do_zmer,{(void*)0x12}};
470 cmd_des_t const cmd_des_scan={0,0,"scan","read values from spectrometer (2 readouts)", cmd_do_zmer,{(void*)0x10}};
473 cmd_des_t const cmd_des_init={0,0,"init", "inicializacni vypis pro zacatek komunikace", cmd_do_init,{(void*)0}};
475 cmd_des_t const cmd_des_sendvalue={0,0,"send", "send value to given address", cmd_do_send,{(void*)0}};
477 cmd_des_t const cmd_des_runnung_meas = {0,0,"run","read values from spectrometer (running)", cmd_do_runnung_meas,{(void*)0x10}};
479 cmd_des_t const *const cmd_appl_tests[]={
480 &cmd_des_test_memusage,
482 #ifdef APPL_WITH_DISTORE_EEPROM_USER
483 &cmd_des_test_distore,
484 &cmd_des_test_diload,
485 #endif /*APPL_WITH_DISTORE_EEPROM_USER*/
486 &cmd_des_test_loglevel,
497 & cmd_des_runnung_meas,