//
|
//
|
//
|
//
|
//
|
//
|
|
|
#include <stdio.h>
|
#include <stdio.h>
|
#include "LPC22xx.h"
|
#include "LPC22xx.h"
|
|
|
#include <cyg/error/codes.h>
|
#include <cyg/error/codes.h>
|
#include <cyg/io/io.h>
|
#include <cyg/io/io.h>
|
#include <cyg/io/ttyio.h>
|
#include <cyg/io/ttyio.h>
|
|
|
// #include <redboot.h>
|
// #include <redboot.h>
|
#include "lib_dbg_sh.h"
|
#include "lib_dbg_sh.h"
|
#include "parse.h"
|
#include "parse.h"
|
|
|
|
|
CYG_HAL_TABLE_BEGIN( __RedBoot_CMD_TAB__, RedBoot_commands );
|
CYG_HAL_TABLE_BEGIN( __RedBoot_CMD_TAB__, RedBoot_commands );
|
CYG_HAL_TABLE_END( __RedBoot_CMD_TAB_END__, RedBoot_commands );
|
CYG_HAL_TABLE_END( __RedBoot_CMD_TAB_END__, RedBoot_commands );
|
extern struct cmd __RedBoot_CMD_TAB__[], __RedBoot_CMD_TAB_END__;
|
extern struct cmd __RedBoot_CMD_TAB__[], __RedBoot_CMD_TAB_END__;
|
|
|
|
|
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
//
|
//
|
//
|
//
|
|
|
#include "memtest.h"
|
#include "memtest.h"
|
|
|
extern datum memTestDataBus(volatile datum *address);
|
extern datum memTestDataBus(volatile datum *address);
|
extern datum *memTestAddressBus(volatile datum *baseAddress, unsigned long nBytes);
|
extern datum *memTestAddressBus(volatile datum *baseAddress, unsigned long nBytes);
|
extern datum *memTestDevice(volatile datum *baseAddress, unsigned long nBytes);
|
extern datum *memTestDevice(volatile datum *baseAddress, unsigned long nBytes);
|
|
|
static void do_memtest (int argc, char *argv[]);
|
static void do_memtest (int argc, char *argv[]);
|
RedBoot_cmd ("memtest", "Test Memory", "-b <location> -l <length>", do_memtest);
|
RedBoot_cmd ("memtest", "Test Memory", "-b <location> -l <length>", do_memtest);
|
|
|
|
|
static void
|
static void
|
do_memtest (int argc, char *argv[])
|
do_memtest (int argc, char *argv[])
|
{
|
{
|
struct option_info opts[2];
|
struct option_info opts[2];
|
unsigned long location, length, result;
|
unsigned long location, length, result;
|
bool location_set, length_set;
|
bool location_set, length_set;
|
|
|
init_opts (&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
|
init_opts (&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
|
&location, &location_set, "location");
|
&location, &location_set, "location");
|
init_opts (&opts[1], 'l', true, OPTION_ARG_TYPE_NUM,
|
init_opts (&opts[1], 'l', true, OPTION_ARG_TYPE_NUM,
|
&length, &length_set, "length");
|
&length, &length_set, "length");
|
if (!scan_opts (argc, argv, 1, opts, 2, 0, 0, "")) {
|
if (!scan_opts (argc, argv, 1, opts, 2, 0, 0, "")) {
|
return;
|
return;
|
}
|
}
|
if (!location_set) {
|
if (!location_set) {
|
printf ("memtest: what location?\n");
|
printf ("memtest: what location?\n");
|
return;
|
return;
|
}
|
}
|
|
|
if (!length_set) {
|
if (!length_set) {
|
printf ("memtest: what length?\n");
|
printf ("memtest: what length?\n");
|
return;
|
return;
|
}
|
}
|
|
|
result = memTestDataBus( (volatile datum *)location );
|
result = memTestDataBus( (volatile datum *)location );
|
|
|
if( result == 0 ) {
|
if( result == 0 ) {
|
printf( "memTestDataBus: passes\n" );
|
printf( "memTestDataBus: passes\n" );
|
} else {
|
} else {
|
printf( "memTestDataBus: failed with %x\n", result );
|
printf( "memTestDataBus: failed with %x\n", result );
|
return;
|
return;
|
}
|
}
|
|
|
result = memTestAddressBus( (volatile datum *)location, length );
|
result = memTestAddressBus( (volatile datum *)location, length );
|
|
|
if( result == NULL ) {
|
if( result == NULL ) {
|
printf( "memTestAddressBus: passes\n" );
|
printf( "memTestAddressBus: passes\n" );
|
} else {
|
} else {
|
printf( "memTestAddressBus: failed at address %x\n", result );
|
printf( "memTestAddressBus: failed at address %x\n", result );
|
return;
|
return;
|
}
|
}
|
|
|
result = memTestDevice( (volatile datum *)location, length );
|
result = memTestDevice( (volatile datum *)location, length );
|
|
|
if( result == NULL ) {
|
if( result == NULL ) {
|
printf( "memTestDevice: passes\n" );
|
printf( "memTestDevice: passes\n" );
|
} else {
|
} else {
|
printf( "memTestDevice: failed at address %x\n", result );
|
printf( "memTestDevice: failed at address %x\n", result );
|
return;
|
return;
|
}
|
}
|
|
|
printf( "memtest: done\n" );
|
printf( "memtest: done\n" );
|
|
|
return;
|
return;
|
}
|
}
|
|
|
|
|
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
//
|
//
|
//
|
//
|
RedBoot_cmd("iopeek",
|
RedBoot_cmd("iopeek",
|
"Read I/O location",
|
"Read I/O location",
|
"[-b <location>] [-1|2|4]",
|
"[-b <location>] [-1|2|4]",
|
do_iopeek
|
do_iopeek
|
);
|
);
|
RedBoot_cmd("iopoke",
|
RedBoot_cmd("iopoke",
|
"Write I/O location",
|
"Write I/O location",
|
"[-b <location>] [-1|2|4] -v <value>",
|
"[-b <location>] [-1|2|4] -v <value>",
|
do_iopoke
|
do_iopoke
|
);
|
);
|
|
|
void
|
void
|
do_iopoke(int argc, char *argv[])
|
do_iopoke(int argc, char *argv[])
|
{
|
{
|
struct option_info opts[5];
|
struct option_info opts[5];
|
unsigned long base;
|
unsigned long base;
|
bool base_set, value_set;
|
bool base_set, value_set;
|
bool set_32bit = false;
|
bool set_32bit = false;
|
bool set_16bit = false;
|
bool set_16bit = false;
|
bool set_8bit = false;
|
bool set_8bit = false;
|
cyg_uint32 value;
|
cyg_uint32 value;
|
int size = 1;
|
int size = 1;
|
|
|
init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
|
init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
|
&base, &base_set, "base address");
|
&base, &base_set, "base address");
|
init_opts(&opts[1], 'v', true, OPTION_ARG_TYPE_NUM,
|
init_opts(&opts[1], 'v', true, OPTION_ARG_TYPE_NUM,
|
&value, &value_set, "valuex");
|
&value, &value_set, "valuex");
|
init_opts(&opts[2], '4', false, OPTION_ARG_TYPE_FLG,
|
init_opts(&opts[2], '4', false, OPTION_ARG_TYPE_FLG,
|
&set_32bit, 0, "output 32 bit units");
|
&set_32bit, 0, "output 32 bit units");
|
init_opts(&opts[3], '2', false, OPTION_ARG_TYPE_FLG,
|
init_opts(&opts[3], '2', false, OPTION_ARG_TYPE_FLG,
|
&set_16bit, 0, "output 16 bit units");
|
&set_16bit, 0, "output 16 bit units");
|
init_opts(&opts[4], '1', false, OPTION_ARG_TYPE_FLG,
|
init_opts(&opts[4], '1', false, OPTION_ARG_TYPE_FLG,
|
&set_8bit, 0, "output 8 bit units");
|
&set_8bit, 0, "output 8 bit units");
|
if (!scan_opts(argc, argv, 1, opts, 5, 0, 0, "")) {
|
if (!scan_opts(argc, argv, 1, opts, 5, 0, 0, "")) {
|
return;
|
return;
|
}
|
}
|
if (!base_set) {
|
if (!base_set) {
|
printf("iopoke what <location>?\n");
|
printf("iopoke what <location>?\n");
|
return;
|
return;
|
}
|
}
|
if (!value_set) {
|
if (!value_set) {
|
printf("iopoke what <value>?\n");
|
printf("iopoke what <value>?\n");
|
return;
|
return;
|
}
|
}
|
if (set_32bit) {
|
if (set_32bit) {
|
size = 4;
|
size = 4;
|
} else if (set_16bit) {
|
} else if (set_16bit) {
|
size = 2;
|
size = 2;
|
} else if (set_8bit) {
|
} else if (set_8bit) {
|
size = 1;
|
size = 1;
|
}
|
}
|
|
|
switch (size) {
|
switch (size) {
|
case 4:
|
case 4:
|
HAL_WRITE_UINT32 ( base, value );
|
HAL_WRITE_UINT32 ( base, value );
|
break;
|
break;
|
case 2:
|
case 2:
|
HAL_WRITE_UINT16 ( base, value );
|
HAL_WRITE_UINT16 ( base, value );
|
break;
|
break;
|
case 1:
|
case 1:
|
HAL_WRITE_UINT8 ( base, value );
|
HAL_WRITE_UINT8 ( base, value );
|
break;
|
break;
|
}
|
}
|
}
|
}
|
|
|
void
|
void
|
do_iopeek(int argc, char *argv[])
|
do_iopeek(int argc, char *argv[])
|
{
|
{
|
struct option_info opts[4];
|
struct option_info opts[4];
|
unsigned long base;
|
unsigned long base;
|
bool base_set;
|
bool base_set;
|
bool set_32bit = false;
|
bool set_32bit = false;
|
bool set_16bit = false;
|
bool set_16bit = false;
|
bool set_8bit = false;
|
bool set_8bit = false;
|
int size = 1, value;
|
int size = 1, value;
|
|
|
init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
|
init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
|
&base, &base_set, "base address");
|
&base, &base_set, "base address");
|
init_opts(&opts[1], '4', false, OPTION_ARG_TYPE_FLG,
|
init_opts(&opts[1], '4', false, OPTION_ARG_TYPE_FLG,
|
&set_32bit, 0, "output 32 bit units");
|
&set_32bit, 0, "output 32 bit units");
|
init_opts(&opts[2], '2', false, OPTION_ARG_TYPE_FLG,
|
init_opts(&opts[2], '2', false, OPTION_ARG_TYPE_FLG,
|
&set_16bit, 0, "output 16 bit units");
|
&set_16bit, 0, "output 16 bit units");
|
init_opts(&opts[3], '1', false, OPTION_ARG_TYPE_FLG,
|
init_opts(&opts[3], '1', false, OPTION_ARG_TYPE_FLG,
|
&set_8bit, 0, "output 8 bit units");
|
&set_8bit, 0, "output 8 bit units");
|
if (!scan_opts(argc, argv, 1, opts, 4, 0, 0, "")) {
|
if (!scan_opts(argc, argv, 1, opts, 4, 0, 0, "")) {
|
return;
|
return;
|
}
|
}
|
if (!base_set) {
|
if (!base_set) {
|
printf("iopeek what <location>?\n");
|
printf("iopeek what <location>?\n");
|
return;
|
return;
|
}
|
}
|
if (set_32bit) {
|
if (set_32bit) {
|
size = 4;
|
size = 4;
|
} else if (set_16bit) {
|
} else if (set_16bit) {
|
size = 2;
|
size = 2;
|
} else if (set_8bit) {
|
} else if (set_8bit) {
|
size = 1;
|
size = 1;
|
}
|
}
|
|
|
switch (size) {
|
switch (size) {
|
case 4:
|
case 4:
|
HAL_READ_UINT32 ( base, value );
|
HAL_READ_UINT32 ( base, value );
|
printf("0x%04lx = 0x%08x\n", base, value );
|
printf("0x%04lx = 0x%08x\n", base, value );
|
break;
|
break;
|
case 2:
|
case 2:
|
HAL_READ_UINT16 ( base, value );
|
HAL_READ_UINT16 ( base, value );
|
printf("0x%04lx = 0x%04x\n", base, value );
|
printf("0x%04lx = 0x%04x\n", base, value );
|
break;
|
break;
|
case 1:
|
case 1:
|
HAL_READ_UINT8 ( base, value );
|
HAL_READ_UINT8 ( base, value );
|
printf("0x%04lx = 0x%02x\n", base, value );
|
printf("0x%04lx = 0x%02x\n", base, value );
|
break;
|
break;
|
}
|
}
|
}
|
}
|
|
|
|
|
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
//
|
//
|
//
|
//
|
RedBoot_cmd("help",
|
RedBoot_cmd("help",
|
"Help about help?",
|
"Help about help?",
|
"[<topic>]",
|
"[<topic>]",
|
do_help
|
do_help
|
);
|
);
|
|
|
void
|
void
|
show_help(struct cmd *cmd, struct cmd *cmd_end, char *which, char *pre)
|
show_help(struct cmd *cmd, struct cmd *cmd_end, char *which, char *pre)
|
{
|
{
|
bool show;
|
bool show;
|
int len = 0;
|
int len = 0;
|
|
|
if (which) {
|
if (which) {
|
len = strlen(which);
|
len = strlen(which);
|
}
|
}
|
while (cmd != cmd_end) {
|
while (cmd != cmd_end) {
|
show = true;
|
show = true;
|
if (which && (strncasecmp(which, cmd->str, len) != 0)) {
|
if (which && (strncasecmp(which, cmd->str, len) != 0)) {
|
show = false;
|
show = false;
|
}
|
}
|
if (show) {
|
if (show) {
|
printf("%s\n %s %s %s\n", cmd->help, pre, cmd->str, cmd->usage);
|
printf("%s\n %s %s %s\n", cmd->help, pre, cmd->str, cmd->usage);
|
if ((cmd->sub_cmds != (struct cmd *)0) && (which != (char *)0)) {
|
if ((cmd->sub_cmds != (struct cmd *)0) && (which != (char *)0)) {
|
show_help(cmd->sub_cmds, cmd->sub_cmds_end, 0, cmd->str);
|
show_help(cmd->sub_cmds, cmd->sub_cmds_end, 0, cmd->str);
|
}
|
}
|
}
|
}
|
cmd++;
|
cmd++;
|
}
|
}
|
}
|
}
|
|
|
void
|
void
|
do_help(int argc, char *argv[])
|
do_help(int argc, char *argv[])
|
{
|
{
|
struct cmd *cmd;
|
struct cmd *cmd;
|
char *which = (char *)0;
|
char *which = (char *)0;
|
|
|
if (!scan_opts(argc, argv, 1, 0, 0, (void *)&which, OPTION_ARG_TYPE_STR, "<topic>")) {
|
if (!scan_opts(argc, argv, 1, 0, 0, (void *)&which, OPTION_ARG_TYPE_STR, "<topic>")) {
|
printf("Invalid argument\n");
|
printf("Invalid argument\n");
|
return;
|
return;
|
}
|
}
|
cmd = __RedBoot_CMD_TAB__;
|
cmd = __RedBoot_CMD_TAB__;
|
show_help(cmd, &__RedBoot_CMD_TAB_END__, which, "");
|
show_help(cmd, &__RedBoot_CMD_TAB_END__, which, "");
|
return;
|
return;
|
}
|
}
|
|
|
|
|
void dbg_sh(void)
|
void dbg_sh(void)
|
{
|
{
|
char buffer[256];
|
char buffer[256];
|
|
|
char *command;
|
char *command;
|
struct cmd *cmd;
|
struct cmd *cmd;
|
|
|
int argc;
|
int argc;
|
char *argv[16];
|
char *argv[16];
|
|
|
while(1)
|
while(1)
|
{
|
{
|
printf( "dbg_sh> " );
|
printf( "dbg_sh> " );
|
|
|
gets( buffer );
|
gets( buffer );
|
command = buffer;
|
command = buffer;
|
|
|
if( strlen(command) > 0 )
|
if( strlen(command) > 0 )
|
{
|
{
|
if ((cmd = parse(&command, &argc, &argv[0])) != (struct cmd *)0)
|
if ((cmd = parse(&command, &argc, &argv[0])) != (struct cmd *)0)
|
{
|
{
|
(cmd->fun)(argc, argv);
|
(cmd->fun)(argc, argv);
|
} else
|
} else
|
{
|
{
|
printf("** Error: Illegal command: \"%s\"\n", argv[0]);
|
printf("** Error: Illegal command: \"%s\"\n", argv[0]);
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
|
|
|
|