X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fflash%2Fat91sam3.c;h=75e8495326ac90869d6fa96c22d810dd5f5c5e49;hp=0f2be3c1b86e4b156ec8e3c592fce51c44b8e8bb;hb=2a4a94b7ac4401802832f37ef07b0500efc92f0e;hpb=1186f7efa72a86a7000dce60b090bd4f822cdceb diff --git a/src/flash/at91sam3.c b/src/flash/at91sam3.c index 0f2be3c1b8..75e8495326 100644 --- a/src/flash/at91sam3.c +++ b/src/flash/at91sam3.c @@ -62,7 +62,6 @@ #include #include "types.h" #include "flash.h" -#include "target.h" #include "membuf.h" #include "at91sam3.h" #include "time_support.h" @@ -2268,7 +2267,7 @@ COMMAND_HANDLER(sam3_handle_info_command) unsigned x; int r; - pChip = get_current_sam3(cmd_ctx); + pChip = get_current_sam3(CMD_CTX); if (!pChip) { return ERROR_OK; } @@ -2279,7 +2278,7 @@ COMMAND_HANDLER(sam3_handle_info_command) if (pChip->details.bank[0].pBank == NULL) { x = 0; need_define: - command_print(cmd_ctx, + command_print(CMD_CTX, "Please define bank %d via command: flash bank %s ... ", x, at91sam3_flash.name); @@ -2330,7 +2329,7 @@ COMMAND_HANDLER(sam3_handle_info_command) // print results cp = membuf_strtok(pChip->mbuf, "\n", &vp); while (cp) { - command_print(cmd_ctx,"%s", cp); + command_print(CMD_CTX,"%s", cp); cp = membuf_strtok(NULL, "\n", &vp); } return ERROR_OK; @@ -2342,7 +2341,7 @@ COMMAND_HANDLER(sam3_handle_gpnvm_command) int r,who; struct sam3_chip *pChip; - pChip = get_current_sam3(cmd_ctx); + pChip = get_current_sam3(CMD_CTX); if (!pChip) { return ERROR_OK; } @@ -2354,7 +2353,7 @@ COMMAND_HANDLER(sam3_handle_gpnvm_command) if (pChip->details.bank[0].pBank == NULL) { - command_print(cmd_ctx, "Bank0 must be defined first via: flash bank %s ...", + command_print(CMD_CTX, "Bank0 must be defined first via: flash bank %s ...", at91sam3_flash.name); return ERROR_FAIL; } @@ -2366,9 +2365,9 @@ COMMAND_HANDLER(sam3_handle_gpnvm_command) } - switch (argc) { + switch (CMD_ARGC) { default: - command_print(cmd_ctx,"Too many parameters\n"); + command_print(CMD_CTX,"Too many parameters\n"); return ERROR_COMMAND_SYNTAX_ERROR; break; case 0: @@ -2379,17 +2378,17 @@ COMMAND_HANDLER(sam3_handle_gpnvm_command) who = -1; break; case 2: - if ((0 == strcmp(args[0], "show")) && (0 == strcmp(args[1], "all"))) { + if ((0 == strcmp(CMD_ARGV[0], "show")) && (0 == strcmp(CMD_ARGV[1], "all"))) { who = -1; } else { uint32_t v32; - COMMAND_PARSE_NUMBER(u32, args[1], v32); + COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], v32); who = v32; } break; } - if (0 == strcmp("show", args[0])) { + if (0 == strcmp("show", CMD_ARGV[0])) { if (who == -1) { showall: r = ERROR_OK; @@ -2398,32 +2397,32 @@ COMMAND_HANDLER(sam3_handle_gpnvm_command) if (r != ERROR_OK) { break; } - command_print(cmd_ctx, "sam3-gpnvm%u: %u", x, v); + command_print(CMD_CTX, "sam3-gpnvm%u: %u", x, v); } return r; } if ((who >= 0) && (((unsigned)(who)) < pChip->details.n_gpnvms)) { r = FLASHD_GetGPNVM(&(pChip->details.bank[0]), who, &v); - command_print(cmd_ctx, "sam3-gpnvm%u: %u", who, v); + command_print(CMD_CTX, "sam3-gpnvm%u: %u", who, v); return r; } else { - command_print(cmd_ctx, "sam3-gpnvm invalid GPNVM: %u", who); + command_print(CMD_CTX, "sam3-gpnvm invalid GPNVM: %u", who); return ERROR_COMMAND_SYNTAX_ERROR; } } if (who == -1) { - command_print(cmd_ctx, "Missing GPNVM number"); + command_print(CMD_CTX, "Missing GPNVM number"); return ERROR_COMMAND_SYNTAX_ERROR; } - if (0 == strcmp("set", args[0])) { + if (0 == strcmp("set", CMD_ARGV[0])) { r = FLASHD_SetGPNVM(&(pChip->details.bank[0]), who); - } else if ((0 == strcmp("clr", args[0])) || - (0 == strcmp("clear", args[0]))) { // quietly accept both + } else if ((0 == strcmp("clr", CMD_ARGV[0])) || + (0 == strcmp("clear", CMD_ARGV[0]))) { // quietly accept both r = FLASHD_ClrGPNVM(&(pChip->details.bank[0]), who); } else { - command_print(cmd_ctx, "Unkown command: %s", args[0]); + command_print(CMD_CTX, "Unkown command: %s", CMD_ARGV[0]); r = ERROR_COMMAND_SYNTAX_ERROR; } return r; @@ -2433,13 +2432,13 @@ COMMAND_HANDLER(sam3_handle_slowclk_command) { struct sam3_chip *pChip; - pChip = get_current_sam3(cmd_ctx); + pChip = get_current_sam3(CMD_CTX); if (!pChip) { return ERROR_OK; } - switch (argc) { + switch (CMD_ARGC) { case 0: // show break; @@ -2447,10 +2446,10 @@ COMMAND_HANDLER(sam3_handle_slowclk_command) { // set uint32_t v; - COMMAND_PARSE_NUMBER(u32, args[0], v); + COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], v); if (v > 200000) { // absurd slow clock of 200Khz? - command_print(cmd_ctx,"Absurd/illegal slow clock freq: %d\n", (int)(v)); + command_print(CMD_CTX,"Absurd/illegal slow clock freq: %d\n", (int)(v)); return ERROR_COMMAND_SYNTAX_ERROR; } pChip->cfg.slow_freq = v; @@ -2458,45 +2457,53 @@ COMMAND_HANDLER(sam3_handle_slowclk_command) } default: // error - command_print(cmd_ctx,"Too many parameters"); + command_print(CMD_CTX,"Too many parameters"); return ERROR_COMMAND_SYNTAX_ERROR; break; } - command_print(cmd_ctx, "Slowclk freq: %d.%03dkhz", + command_print(CMD_CTX, "Slowclk freq: %d.%03dkhz", (int)(pChip->cfg.slow_freq/ 1000), (int)(pChip->cfg.slow_freq% 1000)); return ERROR_OK; } +static const struct command_registration at91sam3_exec_command_handlers[] = { + { + .name = "gpnvm", + .handler = &sam3_handle_gpnvm_command, + .mode = COMMAND_EXEC, + .usage = "[(set|clear) []]", + .help = "Without arguments, shows the gpnvm register; " + "otherwise, sets or clear the specified bit.", + }, + { + .name = "info", + .handler = &sam3_handle_info_command, + .mode = COMMAND_EXEC, + .help = "print information about the current sam3 chip", + }, + { + .name = "slowclk", + .handler = &sam3_handle_slowclk_command, + .mode = COMMAND_EXEC, + .usage = "", + .help = "set the slowclock frequency (default 32768hz)", + }, + COMMAND_REGISTRATION_DONE +}; +static const struct command_registration at91sam3_command_handlers[] = { + { + .name = "at91sam3", + .mode = COMMAND_ANY, + .help = "at91sam3 flash command group", + .chain = at91sam3_exec_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; -static int sam3_registered; -static int -sam3_register_commands(struct command_context *cmd_ctx) +static int sam3_register_commands(struct command_context *cmd_ctx) { - struct command *pCmd; - - // only register once - if (!sam3_registered) { - sam3_registered++; - - pCmd = register_command(cmd_ctx, NULL, "at91sam3", NULL, COMMAND_ANY, NULL); - register_command(cmd_ctx, pCmd, - "gpnvm", - sam3_handle_gpnvm_command, - COMMAND_EXEC, - "at91sam3 gpnvm [action [], by default 'show', otherwise set | clear BIT"); - register_command(cmd_ctx, pCmd, - "info", - sam3_handle_info_command, - COMMAND_EXEC, - "at91sam3 info - print information about the current sam3 chip"); - register_command(cmd_ctx, pCmd, - "slowclk", - sam3_handle_slowclk_command, - COMMAND_EXEC, - "at91sam3 slowclk [VALUE] set the slowclock frequency (default 32768hz)"); - } - return ERROR_OK; + return register_commands(cmd_ctx, NULL, at91sam3_command_handlers); } struct flash_driver at91sam3_flash = {