#include "target.h" less wildly
[fw/openocd] / src / flash / at91sam3.c
index aff4d984539e9f6bb1c112d693929052775e9806..4507888fcbe797d3306fc05dd7cb6333dd83cc9f 100644 (file)
 #include <stdio.h>
 #include <string.h>
 #include <stddef.h>
-#include "log.h"
 #include "types.h"
 #include "flash.h"
-#include "target.h"
 #include "membuf.h"
 #include "at91sam3.h"
 #include "time_support.h"
@@ -175,7 +173,7 @@ struct sam3_bank_private {
        // so we can find the chip we belong to
        struct sam3_chip *pChip;
        // so we can find the orginal bank pointer
-       flash_bank_t *pBank;
+       struct flash_bank *pBank;
        unsigned bank_number;
        uint32_t controller_address;
        uint32_t base_address;
@@ -215,7 +213,7 @@ struct sam3_chip {
 
        // this is "initialized" from the global const structure
        struct sam3_chip_details details;
-       target_t *target;
+       struct target *target;
        struct sam3_cfg cfg;
 
        struct membuf *mbuf;
@@ -231,9 +229,9 @@ struct sam3_reg_list {
 static struct sam3_chip *all_sam3_chips;
 
 static struct sam3_chip *
-get_current_sam3(struct command_context_s *cmd_ctx)
+get_current_sam3(struct command_context *cmd_ctx)
 {
-       target_t *t;
+       struct target *t;
        static struct sam3_chip *p;
 
        t = get_current_target(cmd_ctx);
@@ -1393,7 +1391,7 @@ sam3_explain_mckr(struct sam3_chip *pChip)
 
 #if 0
 static struct sam3_chip *
-target2sam3(target_t *pTarget)
+target2sam3(struct target *pTarget)
 {
        struct sam3_chip *pChip;
 
@@ -1456,7 +1454,7 @@ static const struct sam3_reg_list sam3_all_regs[] = {
 
 
 static struct sam3_bank_private *
-get_sam3_bank_private(flash_bank_t *bank)
+get_sam3_bank_private(struct flash_bank *bank)
 {
        return (struct sam3_bank_private *)(bank->driver_priv);
 }
@@ -1582,7 +1580,7 @@ sam3_GetInfo(struct sam3_chip *pChip)
 
 
 static int
-sam3_erase_check(struct flash_bank_s *bank)
+sam3_erase_check(struct flash_bank *bank)
 {
        int x;
 
@@ -1606,7 +1604,7 @@ sam3_erase_check(struct flash_bank_s *bank)
 }
 
 static int
-sam3_protect_check(struct flash_bank_s *bank)
+sam3_protect_check(struct flash_bank *bank)
 {
        int r;
        uint32_t v=0;
@@ -1641,12 +1639,7 @@ sam3_protect_check(struct flash_bank_s *bank)
        return ERROR_OK;
 }
 
-static int
-sam3_flash_bank_command(struct command_context_s *cmd_ctx,
-                           char *cmd,
-                           char **args,
-                           int argc,
-                           struct flash_bank_s *bank)
+FLASH_BANK_COMMAND_HANDLER(sam3_flash_bank_command)
 {
        struct sam3_chip *pChip;
 
@@ -1714,7 +1707,7 @@ sam3_GetDetails(struct sam3_bank_private *pPrivate)
        const struct sam3_chip_details *pDetails;
        struct sam3_chip *pChip;
        void *vp;
-       flash_bank_t *saved_banks[SAM3_MAX_FLASH_BANKS];
+       struct flash_bank *saved_banks[SAM3_MAX_FLASH_BANKS];
 
        unsigned x;
        const char *cp;
@@ -1782,7 +1775,7 @@ sam3_GetDetails(struct sam3_bank_private *pPrivate)
 
 
 static int
-_sam3_probe(struct flash_bank_s *bank, int noise)
+_sam3_probe(struct flash_bank *bank, int noise)
 {
        unsigned x;
        int r;
@@ -1866,13 +1859,13 @@ _sam3_probe(struct flash_bank_s *bank, int noise)
 }
 
 static int
-sam3_probe(struct flash_bank_s *bank)
+sam3_probe(struct flash_bank *bank)
 {
        return _sam3_probe(bank, 1);
 }
 
 static int
-sam3_auto_probe(struct flash_bank_s *bank)
+sam3_auto_probe(struct flash_bank *bank)
 {
        return _sam3_probe(bank, 0);
 }
@@ -1880,7 +1873,7 @@ sam3_auto_probe(struct flash_bank_s *bank)
 
 
 static int
-sam3_erase(struct flash_bank_s *bank, int first, int last)
+sam3_erase(struct flash_bank *bank, int first, int last)
 {
        struct sam3_bank_private *pPrivate;
        int r;
@@ -1912,7 +1905,7 @@ sam3_erase(struct flash_bank_s *bank, int first, int last)
 }
 
 static int
-sam3_protect(struct flash_bank_s *bank, int set, int first, int last)
+sam3_protect(struct flash_bank *bank, int set, int first, int last)
 {
        struct sam3_bank_private *pPrivate;
        int r;
@@ -1941,7 +1934,7 @@ sam3_protect(struct flash_bank_s *bank, int set, int first, int last)
 
 
 static int
-sam3_info(flash_bank_t *bank, char *buf, int buf_size)
+sam3_info(struct flash_bank *bank, char *buf, int buf_size)
 {
        if (bank->target->state != TARGET_HALTED) {
                LOG_ERROR("Target not halted");
@@ -2109,7 +2102,7 @@ sam3_page_write(struct sam3_bank_private *pPrivate, unsigned pagenum, uint8_t *b
 
 
 static int
-sam3_write(struct flash_bank_s *bank,
+sam3_write(struct flash_bank *bank,
                   uint8_t *buffer,
                   uint32_t offset,
                   uint32_t count)
@@ -2266,8 +2259,7 @@ sam3_write(struct flash_bank_s *bank,
        return r;
 }
 
-static int
-sam3_handle_info_command(struct command_context_s *cmd_ctx, char *cmd, char **argv, int argc)
+COMMAND_HANDLER(sam3_handle_info_command)
 {
        struct sam3_chip *pChip;
        void *vp;
@@ -2343,8 +2335,7 @@ sam3_handle_info_command(struct command_context_s *cmd_ctx, char *cmd, char **ar
        return ERROR_OK;
 }
 
-static int
-sam3_handle_gpnvm_command(struct command_context_s *cmd_ctx, char *cmd, char **argv, int argc)
+COMMAND_HANDLER(sam3_handle_gpnvm_command)
 {
        unsigned x,v;
        int r,who;
@@ -2387,17 +2378,17 @@ sam3_handle_gpnvm_command(struct command_context_s *cmd_ctx, char *cmd, char **a
                who = -1;
                break;
        case 2:
-               if ((0 == strcmp(argv[0], "show")) && (0 == strcmp(argv[1], "all"))) {
+               if ((0 == strcmp(args[0], "show")) && (0 == strcmp(args[1], "all"))) {
                        who = -1;
                } else {
                        uint32_t v32;
-                       COMMAND_PARSE_NUMBER(u32, argv[1], v32);
+                       COMMAND_PARSE_NUMBER(u32, args[1], v32);
                        who = v32;
                }
                break;
        }
 
-       if (0 == strcmp("show", argv[0])) {
+       if (0 == strcmp("show", args[0])) {
                if (who == -1) {
                showall:
                        r = ERROR_OK;
@@ -2425,20 +2416,19 @@ sam3_handle_gpnvm_command(struct command_context_s *cmd_ctx, char *cmd, char **a
                return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
-       if (0 == strcmp("set", argv[0])) {
+       if (0 == strcmp("set", args[0])) {
                r = FLASHD_SetGPNVM(&(pChip->details.bank[0]), who);
-       } else if ((0 == strcmp("clr", argv[0])) ||
-                          (0 == strcmp("clear", argv[0]))) { // quietly accept both
+       } else if ((0 == strcmp("clr", args[0])) ||
+                          (0 == strcmp("clear", args[0]))) { // quietly accept both
                r = FLASHD_ClrGPNVM(&(pChip->details.bank[0]), who);
        } else {
-               command_print(cmd_ctx, "Unkown command: %s", argv[0]);
+               command_print(cmd_ctx, "Unkown command: %s", args[0]);
                r = ERROR_COMMAND_SYNTAX_ERROR;
        }
        return r;
 }
 
-static int
-sam3_handle_slowclk_command(struct command_context_s *cmd_ctx, char *cmd, char **argv, int argc)
+COMMAND_HANDLER(sam3_handle_slowclk_command)
 {
        struct sam3_chip *pChip;
 
@@ -2456,7 +2446,7 @@ sam3_handle_slowclk_command(struct command_context_s *cmd_ctx, char *cmd, char *
        {
                // set
                uint32_t v;
-               COMMAND_PARSE_NUMBER(u32, argv[0], v);
+               COMMAND_PARSE_NUMBER(u32, args[0], v);
                if (v > 200000) {
                        // absurd slow clock of 200Khz?
                        command_print(cmd_ctx,"Absurd/illegal slow clock freq: %d\n", (int)(v));
@@ -2480,9 +2470,9 @@ sam3_handle_slowclk_command(struct command_context_s *cmd_ctx, char *cmd, char *
 
 static int sam3_registered;
 static int
-sam3_register_commands(struct command_context_s *cmd_ctx)
+sam3_register_commands(struct command_context *cmd_ctx)
 {
-       command_t *pCmd;
+       struct command *pCmd;
 
        // only register once
        if (!sam3_registered) {
@@ -2508,19 +2498,16 @@ sam3_register_commands(struct command_context_s *cmd_ctx)
        return ERROR_OK;
 }
 
-
-flash_driver_t at91sam3_flash =
-{
-       .name                                           = "at91sam3",
-       .register_commands                      = sam3_register_commands,
-
-       .flash_bank_command                     = sam3_flash_bank_command,
-       .erase                                          = sam3_erase,
-       .protect                                        = sam3_protect,
-       .write                                          = sam3_write,
-       .probe                                          = sam3_probe,
-       .auto_probe                                     = sam3_auto_probe,
-       .erase_check                            = sam3_erase_check,
-       .protect_check                          = sam3_protect_check,
-       .info                                           = sam3_info
-};
+struct flash_driver at91sam3_flash = {
+               .name = "at91sam3",
+               .register_commands = &sam3_register_commands,
+               .flash_bank_command = &sam3_flash_bank_command,
+               .erase = &sam3_erase,
+               .protect = &sam3_protect,
+               .write = &sam3_write,
+               .probe = &sam3_probe,
+               .auto_probe = &sam3_auto_probe,
+               .erase_check = &sam3_erase_check,
+               .protect_check = &sam3_protect_check,
+               .info = &sam3_info,
+       };