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 int db_info_intr(char* cmd, char* param1, char* param2, char* param3);
80 extern u32_t this_is_global_variables;
82 /* Console debug command table */
83 const struct DB_COMMAND_STRUCT command_table[] =
85 {"HELP", ", List all debug commands", db_help_cmd},
86 {"?", ", Equal to HELP comamnd", db_help_cmd},
88 /* Basic load/store/dump command */
89 {"LDR", "<Hex addr>, Load word", db_ldr_cmd},
90 {"LDRH", "<Hex addr>, Load half word", db_ldr_cmd},
91 {"LDRB", "<Hex addr>, Load byte", db_ldr_cmd},
92 {"STR", "<Hex addr> <Hex value>, Store word", db_str_cmd},
93 {"STRH", "<Hex addr> <Hex value>, Store half word", db_str_cmd},
94 {"STRB", "<Hex addr> <Hex value>, Store byte", db_str_cmd},
95 {"INFO", ", Print debug information", db_info_cmd},
96 {"USB", ", usb releated command", db_usb_cmd},
97 {"INTR", ", intr releated command", db_intr_cmd},
98 {"CLOCK", ", change the clock...", db_clock_cmd},
99 {"HTCR", "Issue HTC ready to host", db_cmd_starthtc},
100 {"WDT", ", wdt debug command", db_wdt_cmd},
101 #if defined(PROJECT_K2)
102 #if SYSTEM_MODULE_SFLASH
103 {"SFE", ", S<Hex>/B<Hex>/C, SPI Flash chip erase", db_cmd_sferase},
104 {"SFPG", "<Hex addr> <Hex len> <Hex buf>, SPI Flash program", db_cmd_sfpg},
105 {"SFRU", "f/r <Hex addr> <Hex addr>, SPI Flash fast read/read to UART", db_cmd_sfru},
106 {"SFRM", "f/r <Hex addr> <Hex addr>, SPI Flash fast read/read to Memory 0x520000", db_cmd_sfrm},
107 {"SFRDSR", ", SPI Flash status register read", db_cmd_sfrdsr},
109 #endif /* #if defined(PROJECT_K2) */
110 {"MEMCMP", "<Hex addr> <Hex addr> <Hex len>, memory comparison", db_cmd_memcmp},
111 {"MEMDMP", "<Hex addr> <Hex addr>, memory dump", db_cmd_memdump},
113 /* {Command, Help description, function} */
116 char cmd_buffer[COMMAND_BUFFER_SIZE][DB_MAX_COMMAND_LENGTH]; /* Backup previous command */
119 char raw_cmd[DB_MAX_COMMAND_LENGTH];
120 char cmd_str[DB_MAX_COMMAND_LENGTH*4];
125 //////////////////////////////////////////////////
126 #define MAX_REG_NUM 16
128 typedef struct reg_elem {
130 unsigned char mode; // byte, half-word word
131 unsigned long reg_addr;
134 t_reg_elem reg_buffer[MAX_REG_NUM];
136 //////////////////////////////////////////////////
138 static void zf_debug_init(void)
143 while ((zm_get_char(&ch)) != 0)
148 cmd_buf_full = FALSE;
153 static void zf_debug_task(void)
158 if ((zm_get_char(&ch)) == 0)
163 if (db_get_cmd_line(ch, raw_cmd, &gvLen) == 0)
168 if (db_formalize_command(raw_cmd, cmd_str))
173 cmd_not_found = TRUE;
174 while(command_table[i].cmd_func)
176 if (!strcmp(command_table[i].cmd_str, cmd_str))
178 cmd_not_found = FALSE;
179 command_table[i].cmd_func(cmd_str,
180 cmd_str+DB_MAX_COMMAND_LENGTH,
181 cmd_str+DB_MAX_COMMAND_LENGTH*2,
182 cmd_str+DB_MAX_COMMAND_LENGTH*3);
189 A_PRINTF("Error, HELP for command list.\n\r");
198 static uint16_t db_get_cmd_line(uint8_t ch, char *cmd_line, uint16_t *i)
204 case '\\' : /* Last command */
206 if (pressed_time >= COMMAND_BUFFER_SIZE)
210 cmd_buf_loc = cmd_buf_ptr - pressed_time;
213 if (cmd_buf_full == TRUE)
215 cmd_buf_loc += COMMAND_BUFFER_SIZE;
223 if (A_STRLEN(cmd_buffer[cmd_buf_loc]) != 0)
225 A_STRCPY(cmd_line, cmd_buffer[cmd_buf_loc]);
226 *i = A_STRLEN(cmd_buffer[cmd_buf_loc]);
228 A_PRINTF("%s", cmd_line);
231 case 13 : /* Return */
237 //Filter duplicated string in command history
238 if (strcmp(cmd_buffer[(cmd_buf_ptr==0)?(COMMAND_BUFFER_SIZE-1):(cmd_buf_ptr-1)], cmd_line) != 0)
240 A_STRCPY(cmd_buffer[cmd_buf_ptr++], cmd_line);
243 if (cmd_buf_ptr >= COMMAND_BUFFER_SIZE)
249 case '\b' : /* Backspace */
260 if ((ch >= ' ') && (ch <= '~'))
263 if (*i < DB_MAX_COMMAND_LENGTH-2)
265 if ((ch >= 0x11) && (ch <= 0x7e))
267 //if ((buf <= 'z') && (buf >= 'a'))
283 } /* end of switch */
289 static int db_formalize_command(char *raw_str, char *cmd_str)
298 /* Remove preceeding spaces */
299 while (raw_str[i++] == ' '){}
302 /* Copy command string */
304 while(raw_str[i] && (raw_str[i] != ' '))
308 if ((raw_str[i] <= 'z') && (raw_str[i] >= 'a'))
310 raw_str[i] -= 'a' - 'A';
312 cmd_str[k*DB_MAX_COMMAND_LENGTH + j++] = raw_str[i++];
316 cmd_str[k*DB_MAX_COMMAND_LENGTH + j++] = raw_str[i++];
319 cmd_str[k*DB_MAX_COMMAND_LENGTH + j] = 0;
321 return (int)A_STRLEN(cmd_str);
324 static int db_ascii_to_hex(char *num_str, unsigned long *hex_num)
331 if ((num_str[i] >= '0') && (num_str[i] <= '9'))
334 *hex_num += (num_str[i] - '0');
336 else if ((num_str[i] >= 'A') && (num_str[i] <= 'F'))
339 *hex_num += (num_str[i] - 'A' + 10);
341 else if ((num_str[i] >= 'a') && (num_str[i] <= 'f'))
344 *hex_num += (num_str[i] - 'a' + 10);
355 int db_ascii_to_int(char *num_str, unsigned long *int_num)
362 if ((num_str[i] >= '0') && (num_str[i] <= '9'))
365 *int_num += (num_str[i] - '0');
376 static int db_hex_to_ascii(unsigned long hex_num, char *num_str)
379 unsigned long four_bits;
383 four_bits = (hex_num >> i*4) & 0xf;
386 num_str[7-i] = four_bits + '0';
390 num_str[7-i] = four_bits - 10 + 'A';
397 int db_help_cmd(char *cmd, char *param1, char *param2, char *param3)
403 A_PRINTF("%s %s\n", ATH_DEBUGGER_VERSION_STR, ATH_COMMAND_LIST_STR);
405 while (command_table[i].cmd_func)
407 A_PRINTF("%s\t%s\n\r", command_table[i].cmd_str,
408 command_table[i].help_str);
414 static int db_ldr_cmd(char *cmd, char *param1, char *param2, char *param3)
421 if (db_ascii_to_hex(param1, &addr) != -1)
425 A_PRINTF("Error! bad address 0x%08x.\n\r",
426 (unsigned long)addr);
429 if (strcmp(cmd, "LDR") == 0)
432 //val = *(unsigned long *)addr;
434 val = HAL_WORD_REG_READ(addr);
436 else if (strcmp(cmd, "LDRH") == 0)
439 val = HAL_HALF_WORD_REG_READ(addr);
441 else if (strcmp(cmd, "LDRB") == 0)
445 db_hex_to_ascii(val, val_str);
446 db_hex_to_ascii(addr, addr_str);
448 A_PRINTF("%s : %s\n\r", addr_str, val_str);
453 A_PRINTF("Error! Incorrect format.\n\r");
459 static int db_str_cmd(char *cmd, char *param1, char *param2, char *param3)
466 if ((A_STRLEN(param2) > 0) &&
467 (db_ascii_to_hex(param1, &addr) != -1) &&
468 (db_ascii_to_hex(param2, &val) != -1))
470 if (strcmp(cmd, "STR") == 0)
473 //HAL_WORD_REG_WRITE(addr, val);
474 HAL_WORD_REG_WRITE(addr, val);
475 //*(volatile unsigned long *)(addr & 0xfffffffc) = (unsigned long)val;
478 else if (strcmp(cmd, "STRH") == 0)
481 //*(volatile unsigned short *)(addr & 0xfffffffe) = (unsigned short)val;
482 HAL_HALF_WORD_REG_WRITE(addr, val);
484 else if (strcmp(cmd, "STRB") == 0)
486 if( addr & 0x00f00000 )
487 HAL_BYTE_REG_WRITE(addr, val);
489 HAL_BYTE_REG_WRITE(addr^3, val);
490 //*(volatile unsigned char *)addr = (unsigned char)val;
493 db_hex_to_ascii(val, val_str);
494 db_hex_to_ascii(addr, addr_str);
496 A_PRINTF("%s : %s\n\r", addr_str, val_str);
501 A_PRINTF("Error! Incorrect format.\n\r");
507 LOCAL void dbg_timer_func(A_HANDLE alarm, void *data)
509 A_PRINTF("this is a timer alarm function 0x%08x\n\r", xthal_get_ccount());
514 static int db_intr_cmd(char *cmd, char *param1, char *param2, char *param3)
516 #if SYSTEM_MODULE_INTR
517 uint32_t pending_intrs;
519 if(strcmp(param1, "read") == 0 )
522 /* Update snapshot of pending interrupts */
524 pending_intrs = A_INTR_GET_INTRPENDING();
526 A_PRINTF("intr mask [0x%08x]\n\r", xthal_get_intenable());
527 A_PRINTF("intr on [0x%08x]\n\r", pending_intrs);
530 else if (strcmp(param1, "timer") == 0 )
534 if (strcmp(param2, "on") == 0 )
536 /* TODO: this part is probably dead. */
537 pending_intrs = A_INTR_GET_INTRENABLE()|CMNOS_IMASK_XTTIMER;
538 A_INTR_SET_INTRENABLE(pending_intrs);
539 A_PRINTF("- intr [0x%08x]\n\r", pending_intrs);
541 else if ( strcmp(param2, "off") == 0 )
543 pending_intrs = A_INTR_GET_INTRENABLE()&(~CMNOS_IMASK_XTTIMER);
544 A_INTR_SET_INTRENABLE(pending_intrs);
545 A_PRINTF("- intr [0x%08x]\n\r", pending_intrs);
548 else if( db_ascii_to_hex(param2, &data)==0 )
550 if( data>=0 && data <=10 )
555 A_PRINTF("==>set cb to %d seconds \n\r", delay);
561 A_PRINTF("\tintr read - read the interrenable status\n\r");
562 A_PRINTF("\tintr timer on/off/tick - timer attach on/off/ticks\n\r");
566 #endif //#if SYSTEM_MODULE_INTR
570 uint32_t usb_swap_flag = 0; //default
571 uint32_t usb_swap_flag_changed = 0;
572 static int db_usb_cmd(char *cmd, char *param1, char *param2, char *param3)
574 A_PRINTF("THIS IS USB COMMAND\n\r");
576 if( strcmp(param1, "que") == 0 )
578 HIFusb_DescTraceDump();
582 A_PRINTF("\tusb que - dump descriptor queue\n\r");
583 A_PRINTF("\tusb fw on/off - enable/disable write fw download to ram\n\r");
589 static void clk_change(uint32_t clk, uint32_t ratio, uint32_t baud)
591 uint32_t clk_sel = 0;
614 HAL_WORD_REG_WRITE(0x50040, (0x300|clk_sel|(ratio>>1)<<12));
615 A_UART_HWINIT((clk*1000*1000)/ratio, baud);
619 static int db_clock_cmd(char *cmd, char *param1, char *param2, char *param3)
622 uint32_t baud = 19200;
625 if( db_ascii_to_int(param1, &clk) != -1 )
627 A_PRINTF("changing clock to %d\n", clk);
628 clk_change(clk, ratio, baud);
632 static int db_info_cmd(char *cmd, char *param1, char *param2, char *param3)
636 if(strcmp(param1, "ram") == 0 )
640 #if 0 /* TODO: SYSTEM_MODULE_SYS_MONITOR depends on _ROM_ or _RAM_ which
642 else if(strcmp(param1, "cpu") == 0)
643 zfPrintCpuUtilization();
646 HIFusb_DescTraceDump();
657 register uint32_t data1;
658 if( db_ascii_to_hex(param1, &data1)==0 )
660 __asm__ __volatile__ (
662 : "=a" (ccount1) : : "memory"
664 data = *(volatile uint32_t *)(data1);
665 __asm__ __volatile__ (
667 : "=a" (ccount2) : : "memory"
669 A_PRINTF("\n\rread 0x%08x (0x%08x) use %d clocks\n\r", data1, data, ccount2-ccount1);
672 __asm__ __volatile__ (
674 : "=a" (ccount1) : : "memory"
676 data = *(volatile uint32_t *)(data1);
677 __asm__ __volatile__ (
679 : "=a" (ccount2) : : "memory"
681 A_PRINTF("\n\rread 0x%08x (0x%08x) use %d clocks\n\r", data1, data, ccount2-ccount1);
684 __asm__ __volatile__ (
686 : "=a" (ccount1) : : "memory"
688 data = *(volatile uint32_t *)(data2);
689 __asm__ __volatile__ (
691 : "=a" (ccount2) : : "memory"
693 A_PRINTF("read 0x%08x (0x%08x) use %d clocks\n\r", data2, data, ccount2-ccount1);
696 __asm__ __volatile__ (
698 : "=a" (ccount1) : : "memory"
700 data = *(volatile uint32_t *)(data3);
701 __asm__ __volatile__ (
703 : "=a" (ccount2) : : "memory"
705 A_PRINTF("read 0x%08x (0x%08x) use %d clocks\n\r", data3, data, ccount2-ccount1);
712 static int db_cmd_starthtc(char *cmd, char *param1, char *param2, char *param3)
714 extern htc_handle_t htc_handle;
715 HTC_Ready(htc_handle);
718 #define WRITE_USB_DESC(pDesc, Offset) \
720 uint16_t *pSrc = 0; \
721 uint16_t mSize = 0; \
722 pSrc = (uint16_t *)(pDesc); \
723 mSize = (*pSrc&0xff)/2; \
724 A_PRINTF("0x%04x, 0x%04x, 0x%08x\n", Offset, mSize, pSrc); \
725 A_EEP_WRITE(Offset, mSize, pSrc); \
726 A_DELAY_USECS(500); \
729 #define READ_USB_DESC(pDesc, Offset, Size) \
733 pDst = (uint16_t *)pDesc; \
734 A_EEP_READ(Offset, 1, &mSize); \
735 mSize = mSize &0xff; \
739 A_PRINTF("0x%04x, 0x%04x, 0x%08x\n", Offset, mSize, pDst); \
740 A_EEP_READ(Offset, mSize, pDst); \
741 A_DELAY_USECS(500); \
745 ////////////////////////////////////////////////////////////////////////////////////////////////
747 extern uint16_t UsbDeviceDescriptor[];
748 extern uint16_t String00Descriptor[];
749 extern uint16_t String10Descriptor[];
750 extern uint16_t String20Descriptor[];
751 extern uint16_t String30Descriptor[];
753 static int db_wdt_cmd(char *cmd, char *param1, char *param2, char *param3)
755 if ( strcmp(param1, "rst") == 0 )
757 A_PRINTF(" reseting.....................\n\n\r");
760 else if( strcmp(param1, "on") == 0 )
764 else if (strcmp(param1, "off") == 0 )
768 else if ( strcmp(param1, "boot") == 0 )
770 if (ENUM_WDT_BOOT == A_WDT_LASTBOOT() )
771 A_PRINTF("LAST BOOT IS %s", "wdt");
773 A_PRINTF("LAST BOOT IS %s", "normal boot");
775 else if (strcmp(param1, "loop") == 0 )
778 uint32_t time_offset;
779 A_PRINTF(" doing the wdt reseting................\n\n\r");
781 if( db_ascii_to_hex(param2, &time_offset)!=0 )
783 if( time_offset < 0 || time_offset >0xffffffff )
784 time_offset = 0xffffff;
786 A_PRINTF(" doing the wdt reseting (wdt tick: 0x%08x................\n\n\r", time_offset);
787 wdt_cmd.cmd = WDT_TIMEOUT;
788 wdt_cmd.timeout = time_offset;
793 else if (strcmp(param1, "noloop") == 0 )
796 uint32_t time_offset;
797 A_PRINTF(" doing the wdt reseting................\n\n\r");
799 if( db_ascii_to_hex(param3, &time_offset)!=0 )
801 if( time_offset < 0 || time_offset >0xffffffff )
802 time_offset = 0xffffff;
804 A_PRINTF(" doing the wdt reseting (wdt tick: 0x%08x................\n\n\r", time_offset);
806 wdt_cmd.cmd = WDT_TIMEOUT;
807 wdt_cmd.timeout = time_offset;
811 else if( strcmp(param1, "event") == 0 )
813 uint32_t event= 0x00123400;
814 #define USB_BYTE_REG_WRITE(addr, val) HAL_BYTE_REG_WRITE(USB_CTRL_BASE_ADDRESS|(uint8_t)(addr^3), (val))
815 #define USB_BYTE_REG_READ(addr) HAL_BYTE_REG_READ(USB_CTRL_BASE_ADDRESS|(uint8_t)(addr^3))
817 #define USB_WORD_REG_WRITE(addr, val) HAL_WORD_REG_WRITE(USB_CTRL_BASE_ADDRESS|(uint32_t)(addr), (val))
818 #define USB_WORD_REG_READ(addr) HAL_WORD_REG_READ(USB_CTRL_BASE_ADDRESS|(uint32_t)(addr))
821 USB_BYTE_REG_WRITE(0x17, USB_BYTE_REG_READ(0x17)|0xc0);
823 //ZM_CBUS_FIFO_SIZE_REG = 0xf;
824 USB_WORD_REG_WRITE(0x100, 0x0f);
826 //ZM_EP3_DATA_REG = event;
827 USB_WORD_REG_WRITE(0xF8, event);
830 USB_BYTE_REG_WRITE(0xAE, USB_BYTE_REG_READ(0xAE)|0x08);
833 USB_BYTE_REG_WRITE(0x17, USB_BYTE_REG_READ(0x17)&0xbf);
837 #if defined(PROJECT_K2)
838 #if SYSTEM_MODULE_SFLASH
839 /* Serial Flash -> Chip Erase, Sector Erase, Block Erase */
840 static int db_cmd_sferase(char *cmd, char *param1, char *param2, char *param3)
844 if (strcmp(param1, "s") == 0)
846 if (db_ascii_to_hex(param2, &addr) != -1 && addr < SPI_FLASH_MAX_SIZE)
848 /* Sector size is 4K (0x1000) */
849 A_PRINTF("Sector addr : 0x%08X\n\r", addr - addr%0x1000);
850 A_SFLASH_ERASE(ZM_SFLASH_SECTOR_ERASE, addr);
856 A_PRINTF("Error! Incorrect format.\n\r");
860 else if (strcmp(param2, "b") == 0)
862 if (db_ascii_to_hex(param2, &addr) != -1 && addr < SPI_FLASH_MAX_SIZE)
864 /* Sector size is 64K (0x10000) */
865 A_PRINTF("Block addr : 0x%08X\n\r", addr - addr%0x10000);
866 A_SFLASH_ERASE(ZM_SFLASH_BLOCK_ERASE, addr);
872 A_PRINTF("Error! Incorrect format.\n\r");
876 else if (strcmp(param1, "c") == 0)
878 A_SFLASH_ERASE(ZM_SFLASH_CHIP_ERASE, addr);
885 A_PRINTF("Error! Unknown command.\n\r");
890 /* Serial Flash -> Program */
891 static int db_cmd_sfpg(char *cmd, char *param1, char *param2, char *param3)
893 unsigned long addr, len, buf;
895 if (db_ascii_to_hex(param1, &addr) != -1 &&
896 db_ascii_to_hex(param2, &len) != -1 &&
897 db_ascii_to_hex(param3, &buf) != -1 &&
898 ((addr+len) <= SPI_FLASH_MAX_SIZE) &&
899 addr%4 == 0 && len%4 == 0 && buf%4 == 0 &&
900 ((buf >=0x500000 && buf < 0x528000) || (buf >=0x4e0000 && buf < 0x4e6000)) )
902 A_SFLASH_PROG(addr, len, (A_UINT8 *)buf);
909 A_PRINTF("Error! Incorrect format.\n\r");
914 /* Serial Flash -> Read, Fast Read to UART */
915 static int db_cmd_sfru(char *cmd, char *param1, char *param2, char *param3)
918 unsigned long addr1, addr2, t_addr;
921 if (strcmp(param1, "r") == 0)
923 else if (strcmp(param1, "f") == 0)
927 A_PRINTF("Error! Unknown command.\n\r");
931 if (db_ascii_to_hex(param2, &addr1) != -1 &&
932 db_ascii_to_hex(param3, &addr2) != -1 &&
933 addr1 < addr2 && addr1 < SPI_FLASH_MAX_SIZE &&
934 addr2 < SPI_FLASH_MAX_SIZE && addr1%4 == 0)
936 A_PRINTF("addr data data data data data data data data\n\r");
937 A_PRINTF("====== ======== ======== ======== ======== ======== ======== ======== ========");
939 for (i = 0, t_addr = addr1; t_addr < addr2; i++, t_addr += 4)
942 A_PRINTF("\n\r%06X ", t_addr);
944 A_SFLASH_READ(fast, t_addr, 4, (A_UINT8 *)&val);
945 A_PRINTF("%08X ", val);
953 A_PRINTF("Error! Incorrect format.\n\r");
958 /* Serial Flash -> Read, Fast Read to Memory */
959 static int db_cmd_sfrm(char *cmd, char *param1, char *param2, char *param3)
962 unsigned long addr1, addr2, t_addr;
964 A_UINT8 *buf = (A_UINT8 *)0x520000;
966 if (strcmp(param1, "r") == 0)
968 else if (strcmp(param1, "f") == 0)
972 A_PRINTF("Error! Unknown command.\n\r");
976 if (db_ascii_to_hex(param2, &addr1) != -1 &&
977 db_ascii_to_hex(param3, &addr2) != -1 &&
978 addr1 < addr2 && addr1 < SPI_FLASH_MAX_SIZE &&
979 addr2 < SPI_FLASH_MAX_SIZE && addr1%4 == 0)
981 for (i = 0, t_addr = addr1; t_addr < addr2; i++, t_addr += 4)
983 A_SFLASH_READ(fast, t_addr, 4, buf + i*4);
991 A_PRINTF("Error! Incorrect format.\n\r");
996 /* Serial Flash -> Read Status Register */
997 static int db_cmd_sfrdsr(char *cmd, char *param1, char *param2, char *param3)
999 A_PRINTF("0x%02X\n\r", A_SFLASH_RDSR());
1003 #endif /* #if defined(PROJECT_K2) */
1005 /* Memory Comparison */
1006 static int db_cmd_memcmp(char *cmd, char *param1, char *param2, char *param3)
1008 unsigned long addr1, addr2, len;
1009 A_UINT8 *buf1, *buf2;
1011 if (db_ascii_to_hex(param1, &addr1) != -1 &&
1012 db_ascii_to_hex(param2, &addr2) != -1 &&
1013 db_ascii_to_hex(param3, &len) != -1 &&
1014 addr1 != addr2 && addr1%4 == 0 && addr2%4 == 0 && len%4 == 0)
1016 buf1 = (A_UINT8 *)addr1;
1017 buf2 = (A_UINT8 *)addr2; ;
1019 A_PRINTF("memcmp(buf1, buf2, len) = %d\n\r", A_MEMCMP(buf1, buf2, len));
1024 A_PRINTF("Error! Incorrect format.\n\r");
1030 static int db_cmd_memdump(char *cmd, char *param1, char *param2, char *param3)
1033 unsigned long addr1, addr2, t_addr;
1036 if (db_ascii_to_hex(param1, &addr1) != -1 && db_ascii_to_hex(param2, &addr2) != -1 && addr1 < addr2 && addr1%4 == 0)
1038 A_PRINTF("addr data data data data data data data data\n\r");
1039 A_PRINTF("====== ======== ======== ======== ======== ======== ======== ======== ========");
1041 for (i = 0, t_addr = addr1; t_addr < addr2; i++, t_addr += 4)
1044 A_PRINTF("\n\r%06X ", t_addr);
1046 val = (A_UINT32 *)t_addr;
1047 A_PRINTF("%08X ", *val);
1055 A_PRINTF("Error! Incorrect format.\n\r");
1059 void cmnos_dbg_module_install(struct dbg_api *apis)
1061 apis->_dbg_init = zf_debug_init;
1062 apis->_dbg_task = zf_debug_task;
1065 #endif /* SYSTEM_MODULE_DBG */