2 * Copyright (c) 2013 Qualcomm Atheros, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted (subject to the limitations in the
7 * disclaimer below) provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
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
17 * * Neither the name of Qualcomm Atheros nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
22 * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
23 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
33 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include "athos_api.h"
38 #if defined(PROJECT_K2)
39 #if SYSTEM_MODULE_SFLASH
40 #include "sflash_api.h"
42 #endif /* #if defined(PROJECT_K2) */
44 #if defined(SYSTEM_MODULE_DBG)
46 /* Function prototypes */
47 static int db_help_cmd(char *, char *, char *, char *);
48 static int db_ldr_cmd(char *, char *, char *, char *);
49 static int db_str_cmd(char *, char *, char *, char *);
50 static int db_info_cmd(char *, char *, char *, char *);
51 static int db_usb_cmd(char *, char *, char *, char *);
52 static int db_intr_cmd(char *, char *, char *, char *);
54 static int db_cmd_starthtc(char *cmd, char *param1, char *param2, char *param3);
56 static int db_wdt_cmd(char *cmd, char *param1, char *param2, char *param3);
58 #if defined(PROJECT_K2)
59 #if SYSTEM_MODULE_SFLASH
60 static int db_cmd_sferase(char *cmd, char *param1, char *param2, char *param3);
61 static int db_cmd_sfpg(char *cmd, char *param1, char *param2, char *param3);
62 static int db_cmd_sfru(char *cmd, char *param1, char *param2, char *param3);
63 static int db_cmd_sfrm(char *cmd, char *param1, char *param2, char *param3);
64 static int db_cmd_sfrdsr(char *cmd, char *param1, char *param2, char *param3);
66 #endif /* #if defined(PROJECT_K2) */
67 static int db_cmd_memcmp(char *cmd, char *param1, char *param2, char *param3);
68 static int db_cmd_memdump(char *cmd, char *param1, char *param2, char *param3);
70 static int db_clock_cmd(char *cmd, char *param1, char *param2, char *param3);
72 static uint16_t db_get_cmd_line(uint8_t ch, char *cmd_line, uint16_t *i);
73 static int db_formalize_command(char *, char *);
74 static int db_ascii_to_hex(char *, unsigned long *);
75 static int db_hex_to_ascii(unsigned long, char *);
76 static void zf_debug_task(void);
78 /* Console debug command table */
79 const struct DB_COMMAND_STRUCT command_table[] =
81 {"HELP", ", List all debug commands", db_help_cmd},
82 {"?", ", Equal to HELP comamnd", db_help_cmd},
84 /* Basic load/store/dump command */
85 {"LDR", "<Hex addr>, Load word", db_ldr_cmd},
86 {"LDRH", "<Hex addr>, Load half word", db_ldr_cmd},
87 {"LDRB", "<Hex addr>, Load byte", db_ldr_cmd},
88 {"STR", "<Hex addr> <Hex value>, Store word", db_str_cmd},
89 {"STRH", "<Hex addr> <Hex value>, Store half word", db_str_cmd},
90 {"STRB", "<Hex addr> <Hex value>, Store byte", db_str_cmd},
91 {"INFO", ", Print debug information", db_info_cmd},
92 {"USB", ", usb releated command", db_usb_cmd},
93 {"INTR", ", intr releated command", db_intr_cmd},
94 {"CLOCK", ", change the clock...", db_clock_cmd},
95 {"HTCR", "Issue HTC ready to host", db_cmd_starthtc},
96 {"WDT", ", wdt debug command", db_wdt_cmd},
97 #if defined(PROJECT_K2)
98 #if SYSTEM_MODULE_SFLASH
99 {"SFE", ", S<Hex>/B<Hex>/C, SPI Flash chip erase", db_cmd_sferase},
100 {"SFPG", "<Hex addr> <Hex len> <Hex buf>, SPI Flash program", db_cmd_sfpg},
101 {"SFRU", "f/r <Hex addr> <Hex addr>, SPI Flash fast read/read to UART", db_cmd_sfru},
102 {"SFRM", "f/r <Hex addr> <Hex addr>, SPI Flash fast read/read to Memory 0x520000", db_cmd_sfrm},
103 {"SFRDSR", ", SPI Flash status register read", db_cmd_sfrdsr},
105 #endif /* #if defined(PROJECT_K2) */
106 {"MEMCMP", "<Hex addr> <Hex addr> <Hex len>, memory comparison", db_cmd_memcmp},
107 {"MEMDMP", "<Hex addr> <Hex addr>, memory dump", db_cmd_memdump},
109 /* {Command, Help description, function} */
112 char cmd_buffer[COMMAND_BUFFER_SIZE][DB_MAX_COMMAND_LENGTH]; /* Backup previous command */
115 char raw_cmd[DB_MAX_COMMAND_LENGTH];
116 char cmd_str[DB_MAX_COMMAND_LENGTH*4];
121 static void db_incorect_format(void)
123 A_PRINTF("Error! Incorrect format.\n\r");
126 static void zf_debug_init(void)
131 while ((zm_get_char(&ch)) != 0)
136 cmd_buf_full = FALSE;
141 static void zf_debug_task(void)
146 if ((zm_get_char(&ch)) == 0)
151 if (db_get_cmd_line(ch, raw_cmd, &gvLen) == 0)
156 if (db_formalize_command(raw_cmd, cmd_str))
161 cmd_not_found = TRUE;
162 while(command_table[i].cmd_func)
164 if (!strcmp(command_table[i].cmd_str, cmd_str))
166 cmd_not_found = FALSE;
167 command_table[i].cmd_func(cmd_str,
168 cmd_str+DB_MAX_COMMAND_LENGTH,
169 cmd_str+DB_MAX_COMMAND_LENGTH*2,
170 cmd_str+DB_MAX_COMMAND_LENGTH*3);
177 A_PRINTF("Error, HELP for command list.\n\r");
186 static uint16_t db_get_cmd_line(uint8_t ch, char *cmd_line, uint16_t *i)
192 case '\\' : /* Last command */
194 if (pressed_time >= COMMAND_BUFFER_SIZE)
198 cmd_buf_loc = cmd_buf_ptr - pressed_time;
201 if (cmd_buf_full == TRUE)
203 cmd_buf_loc += COMMAND_BUFFER_SIZE;
211 if (A_STRLEN(cmd_buffer[cmd_buf_loc]) != 0)
213 A_STRCPY(cmd_line, cmd_buffer[cmd_buf_loc]);
214 *i = A_STRLEN(cmd_buffer[cmd_buf_loc]);
216 A_PRINTF("%s", cmd_line);
219 case 13 : /* Return */
225 //Filter duplicated string in command history
226 if (strcmp(cmd_buffer[(cmd_buf_ptr==0)?(COMMAND_BUFFER_SIZE-1):(cmd_buf_ptr-1)], cmd_line) != 0)
228 A_STRCPY(cmd_buffer[cmd_buf_ptr++], cmd_line);
231 if (cmd_buf_ptr >= COMMAND_BUFFER_SIZE)
237 case '\b' : /* Backspace */
248 if ((ch >= ' ') && (ch <= '~'))
251 if (*i < DB_MAX_COMMAND_LENGTH-2)
253 if ((ch >= 0x11) && (ch <= 0x7e))
255 //if ((buf <= 'z') && (buf >= 'a'))
271 } /* end of switch */
277 static int db_formalize_command(char *raw_str, char *cmd_str)
286 /* Remove preceeding spaces */
287 while (raw_str[i++] == ' '){}
290 /* Copy command string */
292 while(raw_str[i] && (raw_str[i] != ' '))
296 if ((raw_str[i] <= 'z') && (raw_str[i] >= 'a'))
298 raw_str[i] -= 'a' - 'A';
300 cmd_str[k*DB_MAX_COMMAND_LENGTH + j++] = raw_str[i++];
304 cmd_str[k*DB_MAX_COMMAND_LENGTH + j++] = raw_str[i++];
307 cmd_str[k*DB_MAX_COMMAND_LENGTH + j] = 0;
309 return (int)A_STRLEN(cmd_str);
312 static int db_ascii_to_hex(char *num_str, unsigned long *hex_num)
319 if ((num_str[i] >= '0') && (num_str[i] <= '9'))
322 *hex_num += (num_str[i] - '0');
324 else if ((num_str[i] >= 'A') && (num_str[i] <= 'F'))
327 *hex_num += (num_str[i] - 'A' + 10);
329 else if ((num_str[i] >= 'a') && (num_str[i] <= 'f'))
332 *hex_num += (num_str[i] - 'a' + 10);
343 int db_ascii_to_int(char *num_str, unsigned long *int_num)
350 if ((num_str[i] >= '0') && (num_str[i] <= '9'))
353 *int_num += (num_str[i] - '0');
364 static int db_hex_to_ascii(unsigned long hex_num, char *num_str)
367 unsigned long four_bits;
371 four_bits = (hex_num >> i*4) & 0xf;
374 num_str[7-i] = four_bits + '0';
378 num_str[7-i] = four_bits - 10 + 'A';
385 int db_help_cmd(char *cmd, char *param1, char *param2, char *param3)
391 A_PRINTF("%s %s\n", ATH_DEBUGGER_VERSION_STR, ATH_COMMAND_LIST_STR);
393 while (command_table[i].cmd_func)
395 A_PRINTF("%s\t%s\n\r", command_table[i].cmd_str,
396 command_table[i].help_str);
402 static int db_ldr_cmd(char *cmd, char *param1, char *param2, char *param3)
409 if (db_ascii_to_hex(param1, &addr) != -1)
413 A_PRINTF("Error! bad address 0x%08x.\n\r",
414 (unsigned long)addr);
417 if (strcmp(cmd, "LDR") == 0)
420 //val = *(unsigned long *)addr;
422 val = HAL_WORD_REG_READ(addr);
424 else if (strcmp(cmd, "LDRH") == 0)
427 val = HAL_HALF_WORD_REG_READ(addr);
429 else if (strcmp(cmd, "LDRB") == 0)
433 db_hex_to_ascii(val, val_str);
434 db_hex_to_ascii(addr, addr_str);
436 A_PRINTF("%s : %s\n\r", addr_str, val_str);
440 db_incorect_format();
444 static int db_str_cmd(char *cmd, char *param1, char *param2, char *param3)
451 if ((A_STRLEN(param2) > 0) &&
452 (db_ascii_to_hex(param1, &addr) != -1) &&
453 (db_ascii_to_hex(param2, &val) != -1))
455 if (strcmp(cmd, "STR") == 0)
458 //HAL_WORD_REG_WRITE(addr, val);
459 HAL_WORD_REG_WRITE(addr, val);
460 //*(volatile unsigned long *)(addr & 0xfffffffc) = (unsigned long)val;
463 else if (strcmp(cmd, "STRH") == 0)
466 //*(volatile unsigned short *)(addr & 0xfffffffe) = (unsigned short)val;
467 HAL_HALF_WORD_REG_WRITE(addr, val);
469 else if (strcmp(cmd, "STRB") == 0)
471 if( addr & 0x00f00000 )
472 HAL_BYTE_REG_WRITE(addr, val);
474 HAL_BYTE_REG_WRITE(addr^3, val);
475 //*(volatile unsigned char *)addr = (unsigned char)val;
478 db_hex_to_ascii(val, val_str);
479 db_hex_to_ascii(addr, addr_str);
481 A_PRINTF("%s : %s\n\r", addr_str, val_str);
485 db_incorect_format();
489 LOCAL void dbg_timer_func(A_HANDLE alarm, void *data)
491 A_PRINTF("this is a timer alarm function 0x%08x\n\r", xthal_get_ccount());
496 static int db_intr_cmd(char *cmd, char *param1, char *param2, char *param3)
498 #if SYSTEM_MODULE_INTR
499 uint32_t pending_intrs;
501 if(strcmp(param1, "read") == 0 )
504 /* Update snapshot of pending interrupts */
506 pending_intrs = A_INTR_GET_INTRPENDING();
508 A_PRINTF("intr mask [0x%08x]\n\r", xthal_get_intenable());
509 A_PRINTF("intr on [0x%08x]\n\r", pending_intrs);
512 else if (strcmp(param1, "timer") == 0 )
516 if (strcmp(param2, "on") == 0 )
518 /* TODO: this part is probably dead. */
519 pending_intrs = A_INTR_GET_INTRENABLE()|CMNOS_IMASK_XTTIMER;
520 A_INTR_SET_INTRENABLE(pending_intrs);
521 A_PRINTF("- intr [0x%08x]\n\r", pending_intrs);
523 else if ( strcmp(param2, "off") == 0 )
525 pending_intrs = A_INTR_GET_INTRENABLE()&(~CMNOS_IMASK_XTTIMER);
526 A_INTR_SET_INTRENABLE(pending_intrs);
527 A_PRINTF("- intr [0x%08x]\n\r", pending_intrs);
530 else if( db_ascii_to_hex(param2, &data)==0 )
532 if( data>=0 && data <=10 )
537 A_PRINTF("==>set cb to %d seconds \n\r", delay);
543 A_PRINTF("\tintr read - read the interrenable status\n\r");
544 A_PRINTF("\tintr timer on/off/tick - timer attach on/off/ticks\n\r");
548 #endif //#if SYSTEM_MODULE_INTR
552 static int db_usb_cmd(char *cmd, char *param1, char *param2, char *param3)
554 A_PRINTF("THIS IS USB COMMAND\n\r");
556 if( strcmp(param1, "que") == 0 )
558 HIFusb_DescTraceDump();
562 A_PRINTF("\tusb que - dump descriptor queue\n\r");
563 A_PRINTF("\tusb fw on/off - enable/disable write fw download to ram\n\r");
569 static void clk_change(uint32_t clk, uint32_t ratio, uint32_t baud)
571 uint32_t clk_sel = 0;
594 HAL_WORD_REG_WRITE(0x50040, (0x300|clk_sel|(ratio>>1)<<12));
595 A_UART_HWINIT((clk*1000*1000)/ratio, baud);
599 static int db_clock_cmd(char *cmd, char *param1, char *param2, char *param3)
602 uint32_t baud = 19200;
605 if( db_ascii_to_int(param1, &clk) != -1 )
607 A_PRINTF("changing clock to %d\n", clk);
608 clk_change(clk, ratio, baud);
612 static int db_info_cmd(char *cmd, char *param1, char *param2, char *param3)
616 if(strcmp(param1, "ram") == 0 )
620 #if 0 /* TODO: SYSTEM_MODULE_SYS_MONITOR depends on _ROM_ or _RAM_ which
622 else if(strcmp(param1, "cpu") == 0)
623 zfPrintCpuUtilization();
626 HIFusb_DescTraceDump();
637 register uint32_t data1;
638 if( db_ascii_to_hex(param1, &data1)==0 )
640 __asm__ __volatile__ (
642 : "=a" (ccount1) : : "memory"
644 data = *(volatile uint32_t *)(data1);
645 __asm__ __volatile__ (
647 : "=a" (ccount2) : : "memory"
649 A_PRINTF("\n\rread 0x%08x (0x%08x) use %d clocks\n\r", data1, data, ccount2-ccount1);
652 __asm__ __volatile__ (
654 : "=a" (ccount1) : : "memory"
656 data = *(volatile uint32_t *)(data1);
657 __asm__ __volatile__ (
659 : "=a" (ccount2) : : "memory"
661 A_PRINTF("\n\rread 0x%08x (0x%08x) use %d clocks\n\r", data1, data, ccount2-ccount1);
664 __asm__ __volatile__ (
666 : "=a" (ccount1) : : "memory"
668 data = *(volatile uint32_t *)(data2);
669 __asm__ __volatile__ (
671 : "=a" (ccount2) : : "memory"
673 A_PRINTF("read 0x%08x (0x%08x) use %d clocks\n\r", data2, data, ccount2-ccount1);
676 __asm__ __volatile__ (
678 : "=a" (ccount1) : : "memory"
680 data = *(volatile uint32_t *)(data3);
681 __asm__ __volatile__ (
683 : "=a" (ccount2) : : "memory"
685 A_PRINTF("read 0x%08x (0x%08x) use %d clocks\n\r", data3, data, ccount2-ccount1);
692 static int db_cmd_starthtc(char *cmd, char *param1, char *param2, char *param3)
694 extern htc_handle_t htc_handle;
695 HTC_Ready(htc_handle);
698 static int db_wdt_cmd(char *cmd, char *param1, char *param2, char *param3)
700 if ( strcmp(param1, "rst") == 0 )
702 A_PRINTF(" reseting...\n\n\r");
705 else if( strcmp(param1, "on") == 0 )
709 else if (strcmp(param1, "off") == 0 )
713 else if ( strcmp(param1, "boot") == 0 )
715 A_PRINTF("Last BOOT is ");
716 if (ENUM_WDT_BOOT == A_WDT_LASTBOOT() )
719 A_PRINTF("normal boot");
721 else if (strcmp(param1, "loop") == 0 )
724 uint32_t time_offset;
725 A_PRINTF(" doing the wdt reseting...");
727 if( db_ascii_to_hex(param2, &time_offset)!=0 )
729 if( time_offset < 0 || time_offset >0xffffffff )
730 time_offset = 0xffffff;
732 A_PRINTF(" (wdt tick: 0x%08x...\n\n\r", time_offset);
733 wdt_cmd.cmd = WDT_TIMEOUT;
734 wdt_cmd.timeout = time_offset;
739 else if (strcmp(param1, "noloop") == 0 )
742 uint32_t time_offset;
743 A_PRINTF(" doing the wdt reseting...");
745 if( db_ascii_to_hex(param3, &time_offset)!=0 )
747 if( time_offset < 0 || time_offset >0xffffffff )
748 time_offset = 0xffffff;
750 A_PRINTF(" (wdt tick: 0x%08x...\n\n\r", time_offset);
752 wdt_cmd.cmd = WDT_TIMEOUT;
753 wdt_cmd.timeout = time_offset;
757 else if( strcmp(param1, "event") == 0 )
759 uint32_t event= 0x00123400;
760 #define USB_BYTE_REG_WRITE(addr, val) HAL_BYTE_REG_WRITE(USB_CTRL_BASE_ADDRESS|(uint8_t)(addr^3), (val))
761 #define USB_BYTE_REG_READ(addr) HAL_BYTE_REG_READ(USB_CTRL_BASE_ADDRESS|(uint8_t)(addr^3))
763 #define USB_WORD_REG_WRITE(addr, val) HAL_WORD_REG_WRITE(USB_CTRL_BASE_ADDRESS|(uint32_t)(addr), (val))
764 #define USB_WORD_REG_READ(addr) HAL_WORD_REG_READ(USB_CTRL_BASE_ADDRESS|(uint32_t)(addr))
767 USB_BYTE_REG_WRITE(0x17, USB_BYTE_REG_READ(0x17)|0xc0);
769 //ZM_CBUS_FIFO_SIZE_REG = 0xf;
770 USB_WORD_REG_WRITE(0x100, 0x0f);
772 //ZM_EP3_DATA_REG = event;
773 USB_WORD_REG_WRITE(0xF8, event);
776 USB_BYTE_REG_WRITE(0xAE, USB_BYTE_REG_READ(0xAE)|0x08);
779 USB_BYTE_REG_WRITE(0x17, USB_BYTE_REG_READ(0x17)&0xbf);
783 #if defined(PROJECT_K2)
784 #if SYSTEM_MODULE_SFLASH
785 /* Serial Flash -> Chip Erase, Sector Erase, Block Erase */
786 static int db_cmd_sferase(char *cmd, char *param1, char *param2, char *param3)
790 if (strcmp(param1, "s") == 0)
792 if (db_ascii_to_hex(param2, &addr) != -1 && addr < SPI_FLASH_MAX_SIZE)
794 /* Sector size is 4K (0x1000) */
795 A_PRINTF("Sector addr : 0x%08X\n\r", addr - addr%0x1000);
796 A_SFLASH_ERASE(ZM_SFLASH_SECTOR_ERASE, addr);
801 db_incorect_format();
804 else if (strcmp(param2, "b") == 0)
806 if (db_ascii_to_hex(param2, &addr) != -1 && addr < SPI_FLASH_MAX_SIZE)
808 /* Sector size is 64K (0x10000) */
809 A_PRINTF("Block addr : 0x%08X\n\r", addr - addr%0x10000);
810 A_SFLASH_ERASE(ZM_SFLASH_BLOCK_ERASE, addr);
815 db_incorect_format();
819 else if (strcmp(param1, "c") == 0)
821 A_SFLASH_ERASE(ZM_SFLASH_CHIP_ERASE, addr);
828 A_PRINTF("Error! Unknown command.\n\r");
833 /* Serial Flash -> Program */
834 static int db_cmd_sfpg(char *cmd, char *param1, char *param2, char *param3)
836 unsigned long addr, len, buf;
838 if (db_ascii_to_hex(param1, &addr) != -1 &&
839 db_ascii_to_hex(param2, &len) != -1 &&
840 db_ascii_to_hex(param3, &buf) != -1 &&
841 ((addr+len) <= SPI_FLASH_MAX_SIZE) &&
842 addr%4 == 0 && len%4 == 0 && buf%4 == 0 &&
843 ((buf >=0x500000 && buf < 0x528000) || (buf >=0x4e0000 && buf < 0x4e6000)) )
845 A_SFLASH_PROG(addr, len, (A_UINT8 *)buf);
851 db_incorect_format();
855 /* Serial Flash -> Read, Fast Read to UART */
856 static int db_cmd_sfru(char *cmd, char *param1, char *param2, char *param3)
859 unsigned long addr1, addr2, t_addr;
862 if (strcmp(param1, "r") == 0)
864 else if (strcmp(param1, "f") == 0)
868 A_PRINTF("Error! Unknown command.\n\r");
872 if (db_ascii_to_hex(param2, &addr1) != -1 &&
873 db_ascii_to_hex(param3, &addr2) != -1 &&
874 addr1 < addr2 && addr1 < SPI_FLASH_MAX_SIZE &&
875 addr2 < SPI_FLASH_MAX_SIZE && addr1%4 == 0)
877 A_PRINTF("addr data data data data data data data data\n\r");
878 A_PRINTF("====== ======== ======== ======== ======== ======== ======== ======== ========");
880 for (i = 0, t_addr = addr1; t_addr < addr2; i++, t_addr += 4)
883 A_PRINTF("\n\r%06X ", t_addr);
885 A_SFLASH_READ(fast, t_addr, 4, (A_UINT8 *)&val);
886 A_PRINTF("%08X ", val);
893 db_incorect_format();
897 /* Serial Flash -> Read, Fast Read to Memory */
898 static int db_cmd_sfrm(char *cmd, char *param1, char *param2, char *param3)
901 unsigned long addr1, addr2, t_addr;
903 A_UINT8 *buf = (A_UINT8 *)0x520000;
905 if (strcmp(param1, "r") == 0)
907 else if (strcmp(param1, "f") == 0)
911 A_PRINTF("Error! Unknown command.\n\r");
915 if (db_ascii_to_hex(param2, &addr1) != -1 &&
916 db_ascii_to_hex(param3, &addr2) != -1 &&
917 addr1 < addr2 && addr1 < SPI_FLASH_MAX_SIZE &&
918 addr2 < SPI_FLASH_MAX_SIZE && addr1%4 == 0)
920 for (i = 0, t_addr = addr1; t_addr < addr2; i++, t_addr += 4)
922 A_SFLASH_READ(fast, t_addr, 4, buf + i*4);
929 db_incorect_format();
933 /* Serial Flash -> Read Status Register */
934 static int db_cmd_sfrdsr(char *cmd, char *param1, char *param2, char *param3)
936 A_PRINTF("0x%02X\n\r", A_SFLASH_RDSR());
940 #endif /* #if defined(PROJECT_K2) */
942 /* Memory Comparison */
943 static int db_cmd_memcmp(char *cmd, char *param1, char *param2, char *param3)
945 unsigned long addr1, addr2, len;
946 A_UINT8 *buf1, *buf2;
948 if (db_ascii_to_hex(param1, &addr1) != -1 &&
949 db_ascii_to_hex(param2, &addr2) != -1 &&
950 db_ascii_to_hex(param3, &len) != -1 &&
951 addr1 != addr2 && addr1%4 == 0 && addr2%4 == 0 && len%4 == 0)
953 buf1 = (A_UINT8 *)addr1;
954 buf2 = (A_UINT8 *)addr2; ;
956 A_PRINTF("memcmp(buf1, buf2, len) = %d\n\r", A_MEMCMP(buf1, buf2, len));
960 db_incorect_format();
965 static int db_cmd_memdump(char *cmd, char *param1, char *param2, char *param3)
968 unsigned long addr1, addr2, t_addr;
971 if (db_ascii_to_hex(param1, &addr1) != -1 && db_ascii_to_hex(param2, &addr2) != -1 && addr1 < addr2 && addr1%4 == 0)
973 A_PRINTF("addr data data data data data data data data\n\r");
974 A_PRINTF("====== ======== ======== ======== ======== ======== ======== ======== ========");
976 for (i = 0, t_addr = addr1; t_addr < addr2; i++, t_addr += 4)
979 A_PRINTF("\n\r%06X ", t_addr);
981 val = (A_UINT32 *)t_addr;
982 A_PRINTF("%08X ", *val);
989 db_incorect_format();
992 void cmnos_dbg_module_install(struct dbg_api *apis)
994 apis->_dbg_init = zf_debug_init;
995 apis->_dbg_task = zf_debug_task;
998 #endif /* SYSTEM_MODULE_DBG */