2008-08-20 03:35:50 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* examples/nsh/dbg_proccmds.c
|
|
|
|
*
|
2009-12-15 20:00:40 +01:00
|
|
|
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
|
2008-08-20 03:35:50 +02:00
|
|
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. 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.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2009-12-15 20:00:40 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2008-08-20 03:35:50 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "nsh.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct dbgmem_s
|
|
|
|
{
|
2009-12-15 20:00:40 +01:00
|
|
|
bool dm_write; /* true: perfrom write operation */
|
2008-08-20 03:35:50 +02:00
|
|
|
void *dm_addr; /* Address to access */
|
2009-12-15 20:00:40 +01:00
|
|
|
uint32_t dm_value; /* Value to write */
|
2008-08-20 03:35:50 +02:00
|
|
|
unsigned int dm_count; /* The number of bytes to access */
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mem_parse
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int mem_parse(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv,
|
|
|
|
struct dbgmem_s *mem)
|
|
|
|
{
|
|
|
|
char *pcvalue = strchr(argv[1], '=');
|
|
|
|
unsigned long lvalue = 0;
|
|
|
|
|
|
|
|
/* Check if we are writing a value */
|
|
|
|
|
|
|
|
if (pcvalue)
|
|
|
|
{
|
|
|
|
*pcvalue = '\0';
|
|
|
|
pcvalue++;
|
2008-11-07 21:07:27 +01:00
|
|
|
|
2008-08-20 03:35:50 +02:00
|
|
|
lvalue = (unsigned long)strtol(pcvalue, NULL, 16);
|
|
|
|
if (lvalue > 0xffffffff)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-12-15 20:00:40 +01:00
|
|
|
mem->dm_write = true;
|
|
|
|
mem->dm_value = (uint32_t)lvalue;
|
2008-08-20 03:35:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-15 20:00:40 +01:00
|
|
|
mem->dm_write = false;
|
2008-08-20 03:35:50 +02:00
|
|
|
mem->dm_value = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the address to be accessed */
|
|
|
|
|
|
|
|
mem->dm_addr = (void*)strtol(argv[1], NULL, 16);
|
|
|
|
|
|
|
|
/* Get the number of bytes to access */
|
|
|
|
|
|
|
|
if (argc > 2)
|
|
|
|
{
|
|
|
|
mem->dm_count = (unsigned int)strtol(argv[2], NULL, 16);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mem->dm_count = 1;
|
|
|
|
}
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_mb
|
|
|
|
****************************************************************************/
|
|
|
|
|
2008-11-14 16:11:26 +01:00
|
|
|
#ifndef CONFIG_EXAMPLES_NSH_DISABLE_MB
|
2008-08-20 03:35:50 +02:00
|
|
|
int cmd_mb(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct dbgmem_s mem;
|
2009-12-15 20:00:40 +01:00
|
|
|
volatile uint8_t *ptr;
|
2008-08-20 03:35:50 +02:00
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ret = mem_parse(vtbl, argc, argv, &mem);
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
/* Loop for the number of requested bytes */
|
|
|
|
|
2009-12-15 20:00:40 +01:00
|
|
|
for (i = 0, ptr = (volatile uint8_t*)mem.dm_addr; i < mem.dm_count; i++, ptr++)
|
2008-08-20 03:35:50 +02:00
|
|
|
{
|
|
|
|
/* Print the value at the address */
|
|
|
|
|
|
|
|
nsh_output(vtbl, " %p = 0x%02x", ptr, *ptr);
|
|
|
|
|
|
|
|
/* Are we supposed to write a value to this address? */
|
|
|
|
|
|
|
|
if (mem.dm_write)
|
|
|
|
{
|
|
|
|
/* Yes, was the supplied value within range? */
|
|
|
|
|
|
|
|
if (mem.dm_value > 0x000000ff)
|
|
|
|
{
|
|
|
|
nsh_output(vtbl, g_fmtargrange, argv[0]);
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the value and re-read the address so that we print its
|
|
|
|
* current value (if the address is a process address, then the
|
|
|
|
* value read might not necessarily be the value written).
|
|
|
|
*/
|
|
|
|
|
2009-12-15 20:00:40 +01:00
|
|
|
*ptr = (uint8_t)mem.dm_value;
|
2008-08-20 03:35:50 +02:00
|
|
|
nsh_output(vtbl, " -> 0x%02x", *ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure we end it with a newline */
|
|
|
|
|
|
|
|
nsh_output(vtbl, "\n", *ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2008-11-14 16:11:26 +01:00
|
|
|
#endif
|
2008-08-20 03:35:50 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_mh
|
|
|
|
****************************************************************************/
|
|
|
|
|
2008-11-14 16:11:26 +01:00
|
|
|
#ifndef CONFIG_EXAMPLES_NSH_DISABLE_MH
|
2008-08-20 03:35:50 +02:00
|
|
|
int cmd_mh(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct dbgmem_s mem;
|
2009-12-15 20:00:40 +01:00
|
|
|
volatile uint16_t *ptr;
|
2008-08-20 03:35:50 +02:00
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ret = mem_parse(vtbl, argc, argv, &mem);
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
/* Loop for the number of requested bytes */
|
|
|
|
|
2009-12-15 20:00:40 +01:00
|
|
|
for (i = 0, ptr = (volatile uint16_t*)mem.dm_addr; i < mem.dm_count; i += 2, ptr++)
|
2008-08-20 03:35:50 +02:00
|
|
|
{
|
|
|
|
/* Print the value at the address */
|
|
|
|
|
|
|
|
nsh_output(vtbl, " %p = 0x%04x", ptr, *ptr);
|
|
|
|
|
|
|
|
/* Are we supposed to write a value to this address? */
|
|
|
|
|
|
|
|
if (mem.dm_write)
|
|
|
|
{
|
|
|
|
/* Yes, was the supplied value within range? */
|
|
|
|
|
|
|
|
if (mem.dm_value > 0x0000ffff)
|
|
|
|
{
|
|
|
|
nsh_output(vtbl, g_fmtargrange, argv[0]);
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the value and re-read the address so that we print its
|
|
|
|
* current value (if the address is a process address, then the
|
|
|
|
* value read might not necessarily be the value written).
|
|
|
|
*/
|
|
|
|
|
2009-12-15 20:00:40 +01:00
|
|
|
*ptr = (uint16_t)mem.dm_value;
|
2008-08-20 03:35:50 +02:00
|
|
|
nsh_output(vtbl, " -> 0x%04x", *ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure we end it with a newline */
|
|
|
|
|
|
|
|
nsh_output(vtbl, "\n", *ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2008-11-14 16:11:26 +01:00
|
|
|
#endif
|
2008-08-20 03:35:50 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_mw
|
|
|
|
****************************************************************************/
|
|
|
|
|
2008-11-14 16:11:26 +01:00
|
|
|
#ifndef CONFIG_EXAMPLES_NSH_DISABLE_MW
|
2008-08-20 03:35:50 +02:00
|
|
|
int cmd_mw(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct dbgmem_s mem;
|
2009-12-15 20:00:40 +01:00
|
|
|
volatile uint32_t *ptr;
|
2008-08-20 03:35:50 +02:00
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ret = mem_parse(vtbl, argc, argv, &mem);
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
/* Loop for the number of requested bytes */
|
|
|
|
|
2009-12-15 20:00:40 +01:00
|
|
|
for (i = 0, ptr = (volatile uint32_t*)mem.dm_addr; i < mem.dm_count; i += 4, ptr++)
|
2008-08-20 03:35:50 +02:00
|
|
|
{
|
|
|
|
/* Print the value at the address */
|
|
|
|
|
|
|
|
nsh_output(vtbl, " %p = 0x%08x", ptr, *ptr);
|
|
|
|
|
|
|
|
/* Are we supposed to write a value to this address? */
|
|
|
|
|
|
|
|
if (mem.dm_write)
|
|
|
|
{
|
|
|
|
/* Write the value and re-read the address so that we print its
|
|
|
|
* current value (if the address is a process address, then the
|
|
|
|
* value read might not necessarily be the value written).
|
|
|
|
*/
|
|
|
|
|
|
|
|
*ptr = mem.dm_value;
|
|
|
|
nsh_output(vtbl, " -> 0x%08x", *ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure we end it with a newline */
|
|
|
|
|
|
|
|
nsh_output(vtbl, "\n", *ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2008-11-14 16:11:26 +01:00
|
|
|
#endif
|
2008-08-20 03:35:50 +02:00
|
|
|
|
2008-08-29 18:15:00 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_mem
|
|
|
|
****************************************************************************/
|
|
|
|
|
2008-11-14 16:11:26 +01:00
|
|
|
#ifndef CONFIG_EXAMPLES_NSH_DISABLE_MEM
|
2008-08-29 18:15:00 +02:00
|
|
|
int cmd_mem(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct mallinfo mem;
|
|
|
|
|
|
|
|
#ifdef CONFIG_CAN_PASS_STRUCTS
|
|
|
|
mem = mallinfo();
|
|
|
|
#else
|
|
|
|
(void)mallinfo(&mem);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsh_output(vtbl, " arena: %8x\n", mem.arena);
|
|
|
|
nsh_output(vtbl, " ordblks: %8d\n", mem.ordblks);
|
|
|
|
nsh_output(vtbl, " mxordblk: %8x\n", mem.mxordblk);
|
|
|
|
nsh_output(vtbl, " uordblks: %8x\n", mem.uordblks);
|
|
|
|
nsh_output(vtbl, " fordblks: %8x\n", mem.fordblks);
|
|
|
|
return OK;
|
2008-08-29 20:29:42 +02:00
|
|
|
}
|
2008-11-14 16:11:26 +01:00
|
|
|
#endif
|
2008-09-07 15:42:55 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nsh_dumpbuffer
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void nsh_dumpbuffer(FAR struct nsh_vtbl_s *vtbl, const char *msg,
|
2009-12-15 20:00:40 +01:00
|
|
|
const uint8_t *buffer, ssize_t nbytes)
|
2008-09-07 15:42:55 +02:00
|
|
|
{
|
|
|
|
char line[128];
|
|
|
|
int ch;
|
|
|
|
int i;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
nsh_output(vtbl, "%s:\n", msg);
|
|
|
|
for (i = 0; i < nbytes; i += 16)
|
|
|
|
{
|
|
|
|
sprintf(line, "%04x: ", i);
|
|
|
|
|
|
|
|
for ( j = 0; j < 16; j++)
|
|
|
|
{
|
|
|
|
if (i + j < nbytes)
|
|
|
|
{
|
|
|
|
sprintf(&line[strlen(line)], "%02x ", buffer[i+j] );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpy(&line[strlen(line)], " ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( j = 0; j < 16; j++)
|
|
|
|
{
|
|
|
|
if (i + j < nbytes)
|
|
|
|
{
|
|
|
|
ch = buffer[i+j];
|
|
|
|
sprintf(&line[strlen(line)], "%c", ch >= 0x20 && ch <= 0x7e ? ch : '.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nsh_output(vtbl, "%s\n", line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_xd
|
|
|
|
****************************************************************************/
|
|
|
|
|
2008-11-14 16:11:26 +01:00
|
|
|
#ifndef CONFIG_EXAMPLES_NSH_DISABLE_XD
|
2008-09-07 15:42:55 +02:00
|
|
|
int cmd_xd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
|
|
|
{
|
|
|
|
char *addr;
|
|
|
|
char *endptr;
|
|
|
|
int nbytes;
|
|
|
|
|
|
|
|
addr = (char*)strtol(argv[1], &endptr, 16);
|
|
|
|
if (argv[0][0] == '\0' || *endptr != '\0')
|
|
|
|
{
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
nbytes = (int)strtol(argv[2], &endptr, 0);
|
|
|
|
if (argv[0][0] == '\0' || *endptr != '\0' || nbytes < 0)
|
|
|
|
{
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
2009-12-15 20:00:40 +01:00
|
|
|
nsh_dumpbuffer(vtbl, "Hex dump", (uint8_t*)addr, nbytes);
|
2008-09-07 15:42:55 +02:00
|
|
|
return OK;
|
|
|
|
}
|
2008-11-14 16:11:26 +01:00
|
|
|
#endif
|
2008-09-07 15:42:55 +02:00
|
|
|
|