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[])
36 printf("ADC: %ld %ld %ld %ld %ld\n",(LPC_ADC->DR[0] & 0xFFF0)>>4,
37 (LPC_ADC->DR[1] & 0xFFF0)>>4,
38 (LPC_ADC->DR[2] & 0xFFF0)>>4,
39 (LPC_ADC->DR[3] & 0xFFF0)>>4,
40 (LPC_ADC->DR[7] & 0xFFF0)>>4);
44 #ifdef APPL_WITH_DISTORE_EEPROM_USER
45 int cmd_do_test_distore(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
47 appl_distore_user_set_check4change();
51 int cmd_do_test_diload(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
53 appl_distore_user_restore();
56 #endif /*APPL_WITH_DISTORE_EEPROM_USER*/
58 int cmd_do_test_loglevel_cb(ul_log_domain_t *domain, void *context)
61 cmd_io_t *cmd_io = (cmd_io_t *)context;
64 snprintf(s,sizeof(s)-1,"%s (%d)\n\r",domain->name, domain->level);
65 cmd_io_puts(cmd_io, s);
69 int cmd_do_test_loglevel(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
75 if(!line||(si_skspace(&line),!*line)) {
76 ul_logreg_for_each_domain(cmd_do_test_loglevel_cb, cmd_io);
78 res=ul_log_domain_arg2levels(line);
81 return res>=0?0:CMDERR_BADPAR;
84 int cmd_do_spimst_blocking(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
89 int spi_chan = (int)(intptr_t)des->info[0];
90 uint8_t *tx_buff = NULL;
91 uint8_t *rx_buff = NULL;
96 if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
98 return -CMDERR_OPCHAR;
101 spi_chan=*param[1]-'0';
103 spi_drv = spi_find_drv(NULL, spi_chan);
105 return -CMDERR_BADSUF;
110 if(isdigit((int)*p)){
111 if(si_long(&p,&addr,16)<0) return -CMDERR_BADPAR;
113 if(si_fndsep(&p,"({")<0) return -CMDERR_BADSEP;
115 if((res=si_add_to_arr(&p, (void**)&tx_buff, &len, 16, 1, "})"))<0)
116 return -CMDERR_BADPAR;
122 res = spi_transfer_with_mode(spi_drv, addr, len, tx_buff, rx_buff, SPI_MODE_3);
125 printf("SPI! %02lX ERROR\n",addr);
128 printf("SPI! %02lX ",addr);
130 for(i=0;i<len;i++) printf("%s%02X",i?",":"",tx_buff[i]);
132 for(i=0;i<len;i++) printf("%s%02X",i?",":"",rx_buff[i]);
146 int sdram_access_test(void)
149 unsigned int pattern;
150 size_t ramsz = SDRAM_SIZE;
158 pattern = 0x12abcdef;
159 for (cnt = ramsz/sizeof(*ptr), ptr = (typeof(ptr))SDRAM_BASE; cnt--;) {
161 pattern = pattern + 0x87654321;
165 printf("SDRAM write %d ms\n", (int)(lt_msdiff_t)(actual_msec - tic));
170 pattern = 0x12abcdef;
171 for (cnt = ramsz/sizeof(*ptr), ptr = (typeof(ptr))SDRAM_BASE; cnt--;) {
172 if(*ptr != pattern) {
173 printf("SDRAM error modify at %p (%08x)\n", ptr, *ptr ^ pattern);
177 pattern = pattern + 0x87654321;
181 printf("SDRAM modify %d ms\n", (int)(lt_msdiff_t)(actual_msec - tic));
186 pattern = 0x12abcdef;
187 for (cnt = ramsz/sizeof(*ptr), ptr = (typeof(ptr))SDRAM_BASE; cnt--;) {
188 if(*(ptr++) != ~pattern) {
189 printf("SDRAM error read at %p (%08x)\n", ptr, *ptr ^ pattern);
192 pattern = pattern + 0x87654321;
196 printf("SDRAM read %d ms\n", (int)(lt_msdiff_t)(actual_msec - tic));
202 for (cnt = ramsz/sizeof(*ptr), ptr = (typeof(ptr))SDRAM_BASE; cnt--;) {
207 printf("SDRAM sum %d ms res 0x%08x\n", (int)(lt_msdiff_t)(actual_msec - tic), pattern);
209 for (blksz=1; blksz < 256 ; blksz *= 2) {
214 for (cnt = ramsz/sizeof(*ptr); cnt; cnt -= blksz) {
215 ptr = (typeof(ptr))SDRAM_BASE;
216 //ptr = (typeof(ptr))cmd_do_test_memusage;
217 //ptr = (typeof(ptr))&ptr;
218 for (i = blksz; i--; )
222 printf("SDRAM sum %d blksz %d ms res 0x%08x\n", (int)(lt_msdiff_t)(actual_msec - tic), (int)blksz, pattern);
228 int cmd_do_testsdram(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
234 int cmd_do_testmpu(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
237 int reg_cnt = hal_mpu_region_count();
240 for (i = 0; i < reg_cnt; i++) {
242 ra = MPU->RBAR & MPU_RBAR_ADDR_Msk;
243 rsz = (1 << (__mfld2val(MPU_RASR_SIZE_Msk, MPU->RASR) + 1)) - 1;
244 printf("R%d %08lX..%08lX %08lX %08lX\n", i, ra, ra + rsz, MPU->RBAR, MPU->RASR);
247 /*printf("IAP version %08X\n", lpcisp_read_partid());*/
252 int cmd_do_goaddr(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
260 if(si_ulong(&p,&addr,16)<0) return -CMDERR_BADPAR;
262 printf("Jump to address %08lX\n\n", addr);
264 ((void(*)(void))addr)();
269 int cmd_do_mujtest(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
271 volatile uint32_t *testaddr = (volatile uint32_t *)0x80004000;
274 printf("read %d\n", p);
276 printf("read %d\n", p);
278 printf("read %d\n", p);
280 printf("read %d\n", p);
282 printf("read %d\n", p);
284 printf("read %d\n", p);
286 printf("read %d\n", p);
288 printf("read %d\n", p);
290 printf("read %d\n", p);
294 int cmd_do_zmer(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
296 volatile uint32_t *testaddr = (volatile uint32_t *)0x80004000;
297 int32_t values[2048];
298 uint32_t status, status_old, bank,i;
300 status_old = *testaddr;
301 //while((status_old & (1<<2))==(status & (1<<2))) status=*testaddr;
302 //while (*testaddr &(1<<6));
304 while (!(*testaddr & (1<<6))) printf("\ncekam\n");
306 testaddr = (volatile uint32_t *)0x80008000;
308 // printf("bank1\n");
309 testaddr = (volatile uint32_t *)0x80009000;
314 // values[i]=*testaddr++;
323 //testaddr = (volatile uint32_t *)0x80008000;
327 for (i=0;i<1024;i++){
331 printf("%d\n",values[i]);
339 int cmd_do_runnung_meas(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]){
340 volatile uint32_t *testaddr = (volatile uint32_t *)0x80004000;
341 int32_t values[1024];
342 uint32_t status, status_old, bank,i;
344 status_old = *testaddr;
346 while((status_old & (1<<2))==(status & (1<<2))) {status=*testaddr; printf("dely %i %i",status_old & (1<<2),status & (1<<2));}
348 testaddr = (volatile uint32_t *)0x80009000;
350 testaddr = (volatile uint32_t *)0x80008000;
353 // values[i]=*testaddr++;
355 val = (val>> 17) == 0 ? val : -1 ^ 0x7FFFF | val;
360 //testaddr = (volatile uint32_t *)0x80008000;
364 //printf("zacatek\n");
365 for (i=0;i<1024;i++){
366 printf("%d\n",values[i]);
373 int cmd_do_init(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
376 volatile uint32_t *testaddr = (volatile uint32_t *)0x80004000;
386 //*testaddr++ = 4879;
387 *testaddr++ = 5023999;
394 int cmd_do_send(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
397 volatile uint32_t *testaddr = (volatile uint32_t *)0x80004000;
399 int p=(int) strtol(param[1], &end, 10);
401 p=(int) strtol(end, &end, 10);
404 printf("sent %d & read %d\n", p, read);
408 cmd_des_t const cmd_des_test_memusage={0, 0,
409 "memusage","report memory usage",cmd_do_test_memusage,
413 cmd_des_t const cmd_des_test_adc={0, 0,
414 "testadc","adc test",cmd_do_test_adc,
418 #ifdef APPL_WITH_DISTORE_EEPROM_USER
419 cmd_des_t const cmd_des_test_distore={0, 0,
420 "testdistore","test DINFO store",cmd_do_test_distore,
424 cmd_des_t const cmd_des_test_diload={0, 0,
425 "testdiload","test DINFO load",cmd_do_test_diload,
428 #endif /*APPL_WITH_DISTORE_EEPROM_USER*/
430 cmd_des_t const cmd_des_test_loglevel={0, 0,
431 "loglevel","select logging level",
432 cmd_do_test_loglevel,{}};
434 cmd_des_t const cmd_des_spimst={0, CDESM_OPCHR|CDESM_WR,
435 "SPIMST","SPI master communication request",
436 cmd_do_spimst_blocking,{(void*)0}};
438 cmd_des_t const cmd_des_spimstx={0, CDESM_OPCHR|CDESM_WR,
439 "SPIMST#","SPI# master communication request",
440 cmd_do_spimst_blocking,{(void*)-1}};
442 cmd_des_t const cmd_des_testsdram={0, 0,
443 "testsdram","test SDRAM",
444 cmd_do_testsdram,{(void*)0}};
446 cmd_des_t const cmd_des_testmpu={0, 0,
447 "testmpu","test MPU",
448 cmd_do_testmpu,{(void*)0}};
450 cmd_des_t const cmd_des_goaddr={0, 0,
451 "goaddr","run from address",
452 cmd_do_goaddr,{(void*)0}};
454 cmd_des_t const cmd_des_mujtest={0,0,"mujtest","run my simple test", cmd_do_mujtest,{(void*)0}};
456 cmd_des_t const cmd_des_zmer={0,0,"zmer","read values from spectrometer (2 readouts)", cmd_do_zmer,{(void*)0x12}};
458 cmd_des_t const cmd_des_scan={0,0,"scan","read values from spectrometer (2 readouts)", cmd_do_zmer,{(void*)0x10}};
461 cmd_des_t const cmd_des_init={0,0,"init", "inicializacni vypis pro zacatek komunikace", cmd_do_init,{(void*)0}};
463 cmd_des_t const cmd_des_sendvalue={0,0,"send", "send value to given address", cmd_do_send,{(void*)0}};
465 cmd_des_t const cmd_des_runnung_meas = {0,0,"run","read values from spectrometer (running)", cmd_do_runnung_meas,{(void*)0x10}};
467 cmd_des_t const *const cmd_appl_tests[]={
468 &cmd_des_test_memusage,
470 #ifdef APPL_WITH_DISTORE_EEPROM_USER
471 &cmd_des_test_distore,
472 &cmd_des_test_diload,
473 #endif /*APPL_WITH_DISTORE_EEPROM_USER*/
474 &cmd_des_test_loglevel,
485 & cmd_des_runnung_meas,