dbg: remove db_dump_memory
[open-ath9k-htc-firmware.git] / target_firmware / magpie_fw_dev / target / cmnos / dbg_api.c
index 0662a829a9a62eb29992b7f54601885e213ebb2f..65c30d31a658a918d4a6aac78251ffe0abd1e6c3 100755 (executable)
@@ -1,3 +1,37 @@
+/*
+ * Copyright (c) 2013 Qualcomm Atheros, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted (subject to the limitations in the
+ * disclaimer below) provided that the following conditions are met:
+ *
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the
+ *    distribution.
+ *
+ *  * Neither the name of Qualcomm Atheros nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
+ * GRANTED BY THIS LICENSE.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
+ * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
 #include "sys_cfg.h"
 #include "athos_api.h"
 
@@ -13,7 +47,6 @@
 int db_help_cmd(char *, char*, char*, char*);
 int db_ldr_cmd(char*, char*, char*, char*);
 int db_str_cmd(char*, char*, char*, char*);
-int db_dump_memory(char* cmd, char* param1, char* param2, char* param3);
 int db_info_cmd(char*, char*, char*, char*);
 int db_cmd_dbg(char*, char*, char*, char*);
 int db_usb_cmd(char*, char*, char*, char*);
@@ -64,7 +97,6 @@ const struct DB_COMMAND_STRUCT command_table[] =
        {"STR",    "<Hex addr> <Hex value>, Store word", db_str_cmd},
        {"STRH",   "<Hex addr> <Hex value>, Store half word", db_str_cmd},
        {"STRB",   "<Hex addr> <Hex value>, Store byte", db_str_cmd},
-       {"DUMP",   "<Hex addr>, Dump memory", db_dump_memory},
        {"INFO",   ", Print debug information", db_info_cmd},
        {"USB",   ", usb releated command", db_usb_cmd},
        {"INTR",   ", intr releated command", db_intr_cmd},
@@ -163,12 +195,12 @@ void zfDebugTask(void)
                }
                if (cmd_not_found)
                {
-                       zm_uart_send("Error, HELP for command list.\n\r", 31);
+                       A_PRINTF("Error, HELP for command list.\n\r");
                }
 
        }
 
-       zm_uart_send(">", 1);
+       A_PRINTF(">");
        return;
 }
 
@@ -197,24 +229,24 @@ uint16_t db_get_cmd_line(uint8_t ch, char *cmd_line, uint16_t* i)
                        }
                }
 
-               if(strlen(cmd_buffer[cmd_buf_loc]) != 0)
+               if (A_STRLEN(cmd_buffer[cmd_buf_loc]) != 0)
                {
-                       strcpy(cmd_line, cmd_buffer[cmd_buf_loc]);
-                       *i = strlen(cmd_buffer[cmd_buf_loc]);
-                       zm_uart_send("\r>", 2);
-                       zm_uart_send(cmd_line, *i);
+                       A_STRCPY(cmd_line, cmd_buffer[cmd_buf_loc]);
+                       *i = A_STRLEN(cmd_buffer[cmd_buf_loc]);
+                       A_PRINTF("\r>");
+                       A_PRINTF("%s", cmd_line);
                }
                break;
        case 13 : /* Return */
                pressed_time = 0;
                cmd_line[*i] = 0;
-               zm_uart_send("\n\r", 2);
+               A_PRINTF("\n\r");
                if (*i != 0)
                {
                        //Filter duplicated string in command history
                        if (strcmp(cmd_buffer[(cmd_buf_ptr==0)?(COMMAND_BUFFER_SIZE-1):(cmd_buf_ptr-1)], cmd_line) != 0)
                        {
-                               strcpy(cmd_buffer[cmd_buf_ptr++], cmd_line);
+                               A_STRCPY(cmd_buffer[cmd_buf_ptr++], cmd_line);
                        }
                }
                if (cmd_buf_ptr >= COMMAND_BUFFER_SIZE)
@@ -228,7 +260,7 @@ uint16_t db_get_cmd_line(uint8_t ch, char *cmd_line, uint16_t* i)
                if (*i > 0)
                {
                        *i = *i-1;
-                       zm_uart_send("\b \b", 3);
+                       A_PRINTF("\b \b");
                }
                break;
        case 0 : //None
@@ -247,14 +279,14 @@ uint16_t db_get_cmd_line(uint8_t ch, char *cmd_line, uint16_t* i)
                                        //}
                                        cmd_line[*i] = ch;
                                        *i = *i + 1;
-                                       zm_uart_send(&ch, 1);
+                                       A_PRINTF("%c", ch);
                                }
                        }
                }
                else
                {
                        ch = 7; /* Beep */
-                       zm_uart_send(&ch, 1);
+                       A_PRINTF("%c", ch);
                }
                break;
        } /* end of switch */
@@ -295,7 +327,7 @@ int db_formalize_command(char* raw_str,  char* cmd_str)
                }
                cmd_str[k*DB_MAX_COMMAND_LENGTH + j] = 0;
        }
-       return (int)strlen(cmd_str);
+       return (int)A_STRLEN(cmd_str);
 }
 
 int db_ascii_to_hex(char* num_str, unsigned long* hex_num)
@@ -377,15 +409,12 @@ int db_help_cmd(char* cmd, char* param1, char* param2, char* param3)
 
        i = 0;
 
-       zm_uart_send(ATH_DEBUGGER_VERSION_STR, strlen(ATH_DEBUGGER_VERSION_STR));
-       zm_uart_send(ATH_COMMAND_LIST_STR, strlen(ATH_COMMAND_LIST_STR));
+       A_PRINTF("%s %s\n", ATH_DEBUGGER_VERSION_STR, ATH_COMMAND_LIST_STR);
 
        while (command_table[i].cmd_func)
        {
-               zm_uart_send(command_table[i].cmd_str, strlen(command_table[i].cmd_str));
-               zm_uart_send("\t", 1);
-               zm_uart_send(command_table[i].help_str, strlen(command_table[i].help_str));
-               zm_uart_send("\n\r", 2);
+               A_PRINTF("%s\t%s\n\r", command_table[i].cmd_str,
+                                      command_table[i].help_str);
                i++;
        }
        return i;
@@ -402,7 +431,8 @@ int db_ldr_cmd(char* cmd, char* param1, char* param2, char* param3)
        {
                if( addr == 0 )
                {
-                       zm_uart_send("Error! bad address 0x%08x.\n\r", (unsigned long)addr);
+                       A_PRINTF("Error! bad address 0x%08x.\n\r",
+                                (unsigned long)addr);
                        return -1;
                }
                if (strcmp(cmd, "LDR") == 0)
@@ -424,16 +454,12 @@ int db_ldr_cmd(char* cmd, char* param1, char* param2, char* param3)
                db_hex_to_ascii(val, val_str);
                db_hex_to_ascii(addr, addr_str);
 
-               zm_uart_send(addr_str, strlen(addr_str));
-               zm_uart_send(" : ", 3);
-               zm_uart_send(val_str, strlen(val_str));
-               zm_uart_send("\n\r", 2);
-
+               A_PRINTF("%s : %s\n\r", addr_str, val_str);
                return 0;
        }
        else
        {
-               zm_uart_send("Error! Incorrect format.\n\r", 26);
+               A_PRINTF("Error! Incorrect format.\n\r");
 
                return -1;
        }
@@ -446,7 +472,7 @@ int db_str_cmd(char* cmd, char* param1, char* param2, char* param3)
        char val_str[20];
        char addr_str[20];
 
-       if ((strlen(param2) > 0) &&
+       if ((A_STRLEN(param2) > 0) &&
            (db_ascii_to_hex(param1, &addr) != -1) &&
            (db_ascii_to_hex(param2, &val) != -1))
        {
@@ -476,92 +502,17 @@ int db_str_cmd(char* cmd, char* param1, char* param2, char* param3)
                db_hex_to_ascii(val, val_str);
                db_hex_to_ascii(addr, addr_str);
 
-               zm_uart_send(addr_str, strlen(addr_str));
-               zm_uart_send(" : ", 3);
-               zm_uart_send(val_str, strlen(val_str));
-               zm_uart_send("\n\r", 2);
-
+               A_PRINTF("%s : %s\n\r", addr_str, val_str);
                return 0;
        }
        else
        {
-               zm_uart_send("Error! Incorrect format.\n\r", 26);
+               A_PRINTF("Error! Incorrect format.\n\r");
 
                return -1;
        }
 }
 
-// macro extension the address to dump the memory
-#define FOUR_BYTE_HEX_DUMP(addr) (" %02x %02x %02x %02x",              \
-                                 *(uint8_t*)((addr)+3), *(uint8_t*)((addr)+2), \
-                                 *(uint8_t*)((addr)+1), *(uint8_t*)((addr)))
-
-
-int db_dump_memory(char* cmd, char* param1, char* param2, char* param3)
-{
-       unsigned long addr;
-       unsigned long length;
-       unsigned long ptrAddr;
-       int i;
-
-       if (db_ascii_to_hex(param1, &addr) != -1 &&
-           (db_ascii_to_int(param2, &length) != -1))
-       {
-               // if no length, default is 128 bytes to dump
-               if( length == 0 )
-                       length = 128;
-               addr &= 0xfffffffc;
-
-               A_PRINTF("length: %d\n\r", length);
-
-               //zm_uart_send("                     7 6 5 4  3 2 1 0\n\r", 28);
-               A_PRINTF("           15 14 13 12 11 10 09 08   07 06 05 04 03 02 01 00\n\r");
-               A_PRINTF("------------------------------------------------------------\n\r");
-               for (i=0; i<length/16; i++)
-               {
-                       //zfUartSendHex((unsigned long)addr);
-                       A_PRINTF("%08x: ", (unsigned long)addr);
-
-                       ptrAddr = (unsigned long *)addr;
-
-                       // dump from MSB to LSB
-                       A_PRINTF FOUR_BYTE_HEX_DUMP(ptrAddr+12);
-                       A_PRINTF FOUR_BYTE_HEX_DUMP(ptrAddr+8);
-                       A_PRINTF(" -");
-                       A_PRINTF FOUR_BYTE_HEX_DUMP(ptrAddr+4);
-                       A_PRINTF FOUR_BYTE_HEX_DUMP(ptrAddr);
-                       A_PRINTF("\n\r");
-                       addr+=16;
-               }
-
-               // the rest of the byte to dump
-               if( (length %16)!=0 )
-               {
-                       A_PRINTF("%08x: ", (unsigned long)addr);
-
-                       // make the space, since we dump MSB first
-                       for(i=0; i<(16-(length %16)); i++)
-                               A_PRINTF("   ");
-
-                       // if less than 8 bytes, add 2 more space for " -"
-                       if( (length%16) < 8 )
-                               A_PRINTF("  ");
-
-                       for(i=0; i<length%16; i++)
-                       {
-                               // MSB first,
-                               A_PRINTF(" %02x", *(uint8_t*)((addr+(length%16)-1)-i));
-
-                               if((16-(length%16))+i==7)
-                                       A_PRINTF(" -");
-                       }
-               }
-               A_PRINTF("\n\r");
-               return 0;
-       }
-       return -1;
-}
-
 LOCAL void dbg_timer_func(A_HANDLE alarm, void *data)
 {
        A_PRINTF("this is a timer alarm function 0x%08x\n\r", xthal_get_ccount());
@@ -575,12 +526,6 @@ int db_patch_cmd(char* cmd, char* param1, char* param2, char* param3)
 
 uint32_t delay = 0;
 
-LOCAL void cb_tick()
-{
-       ;    
-}
-
-
 int db_intr_cmd(char* cmd, char* param1, char* param2, char* param3)
 {
 #if SYSTEM_MODULE_INTR
@@ -603,8 +548,7 @@ int db_intr_cmd(char* cmd, char* param1, char* param2, char* param3)
 
                if (strcmp(param2, "on") == 0 )
                {
-                       A_ATTACH_ISR(A_INUM_XTTIMER, cb_tick, NULL);
-
+                       /* TODO: this part is probably dead. */
                        pending_intrs = A_INTR_GET_INTRENABLE()|CMNOS_IMASK_XTTIMER;
                        A_INTR_SET_INTRENABLE(pending_intrs);
                        A_PRINTF("- intr [0x%08x]\n\r", pending_intrs);
@@ -708,7 +652,8 @@ int db_info_cmd(char* cmd, char* param1, char* param2, char* param3)
        {
                A_ALLOCRAM_DEBUG();
        }
-#if SYSTEM_MODULE_SYS_MONITOR
+#if 0  /* TODO: SYSTEM_MODULE_SYS_MONITOR depends on _ROM_ or _RAM_ which
+       * is dead too */
        else if(strcmp(param1, "cpu") == 0)
                zfPrintCpuUtilization();
 #endif