use COMMAND_REGISTER macro
[fw/openocd] / src / flash / stellaris.c
index cdeccbe102bf7d70afd02ddaeda467752c2d7b8d..2d653eca1cdbc4048e34d892b15fbefde25f08c2 100644 (file)
 #include "stellaris.h"
 #include "armv7m.h"
 #include "binarybuffer.h"
+#include "algorithm.h"
 
 
 #define DID0_VER(did0) ((did0 >> 28)&0x07)
 
-static int stellaris_read_part_info(struct flash_bank_s *bank);
-static uint32_t stellaris_get_flash_status(flash_bank_t *bank);
-static void stellaris_set_flash_mode(flash_bank_t *bank,int mode);
-//static uint32_t stellaris_wait_status_busy(flash_bank_t *bank, uint32_t waitbits, int timeout);
+static int stellaris_read_part_info(struct flash_bank *bank);
+static uint32_t stellaris_get_flash_status(struct flash_bank *bank);
+static void stellaris_set_flash_mode(struct flash_bank *bank,int mode);
+//static uint32_t stellaris_wait_status_busy(struct flash_bank *bank, uint32_t waitbits, int timeout);
 
-static int stellaris_mass_erase(struct flash_bank_s *bank);
+static int stellaris_mass_erase(struct flash_bank *bank);
 
 static struct {
        uint32_t partno;
@@ -217,7 +218,7 @@ FLASH_BANK_COMMAND_HANDLER(stellaris_flash_bank_command)
 {
        struct stellaris_flash_bank *stellaris_info;
 
-       if (argc < 6)
+       if (CMD_ARGC < 6)
        {
                LOG_WARNING("incomplete flash_bank stellaris configuration");
                return ERROR_FLASH_BANK_INVALID;
@@ -239,7 +240,7 @@ FLASH_BANK_COMMAND_HANDLER(stellaris_flash_bank_command)
        return ERROR_OK;
 }
 
-static int stellaris_info(struct flash_bank_s *bank, char *buf, int buf_size)
+static int stellaris_info(struct flash_bank *bank, char *buf, int buf_size)
 {
        int printed, device_class;
        struct stellaris_flash_bank *stellaris_info = bank->driver_priv;
@@ -316,9 +317,9 @@ static int stellaris_info(struct flash_bank_s *bank, char *buf, int buf_size)
 *      chip identification and status                                         *
 ***************************************************************************/
 
-static uint32_t stellaris_get_flash_status(flash_bank_t *bank)
+static uint32_t stellaris_get_flash_status(struct flash_bank *bank)
 {
-       target_t *target = bank->target;
+       struct target *target = bank->target;
        uint32_t fmc;
 
        target_read_u32(target, FLASH_CONTROL_BASE | FLASH_FMC, &fmc);
@@ -361,10 +362,10 @@ static const unsigned rcc_xtal[32] = {
        [0x16] = 16384000,
 };
 
-static void stellaris_read_clock_info(flash_bank_t *bank)
+static void stellaris_read_clock_info(struct flash_bank *bank)
 {
        struct stellaris_flash_bank *stellaris_info = bank->driver_priv;
-       target_t *target = bank->target;
+       struct target *target = bank->target;
        uint32_t rcc, rcc2, pllcfg, sysdiv, usesysdiv, bypass, oscsrc;
        unsigned xtal;
        unsigned long mainfreq;
@@ -448,10 +449,10 @@ static void stellaris_read_clock_info(flash_bank_t *bank)
 }
 
 /* Setup the timimg registers */
-static void stellaris_set_flash_mode(flash_bank_t *bank,int mode)
+static void stellaris_set_flash_mode(struct flash_bank *bank,int mode)
 {
        struct stellaris_flash_bank *stellaris_info = bank->driver_priv;
-       target_t *target = bank->target;
+       struct target *target = bank->target;
 
        uint32_t usecrl = (stellaris_info->mck_freq/1000000ul-1);
        LOG_DEBUG("usecrl = %i",(int)(usecrl));
@@ -459,7 +460,7 @@ static void stellaris_set_flash_mode(flash_bank_t *bank,int mode)
 }
 
 #if 0
-static uint32_t stellaris_wait_status_busy(flash_bank_t *bank, uint32_t waitbits, int timeout)
+static uint32_t stellaris_wait_status_busy(struct flash_bank *bank, uint32_t waitbits, int timeout)
 {
        uint32_t status;
 
@@ -476,10 +477,10 @@ static uint32_t stellaris_wait_status_busy(flash_bank_t *bank, uint32_t waitbits
 }
 
 /* Send one command to the flash controller */
-static int stellaris_flash_command(struct flash_bank_s *bank,uint8_t cmd,uint16_t pagen)
+static int stellaris_flash_command(struct flash_bank *bank,uint8_t cmd,uint16_t pagen)
 {
        uint32_t fmc;
-       target_t *target = bank->target;
+       struct target *target = bank->target;
 
        fmc = FMC_WRKEY | cmd;
        target_write_u32(target, FLASH_CONTROL_BASE | FLASH_FMC, fmc);
@@ -495,10 +496,10 @@ static int stellaris_flash_command(struct flash_bank_s *bank,uint8_t cmd,uint16_
 #endif
 
 /* Read device id register, main clock frequency register and fill in driver info structure */
-static int stellaris_read_part_info(struct flash_bank_s *bank)
+static int stellaris_read_part_info(struct flash_bank *bank)
 {
        struct stellaris_flash_bank *stellaris_info = bank->driver_priv;
-       target_t *target = bank->target;
+       struct target *target = bank->target;
        uint32_t did0, did1, ver, fam, status;
        int i;
 
@@ -613,7 +614,7 @@ static int stellaris_read_part_info(struct flash_bank_s *bank)
 *      flash operations                                                       *
 ***************************************************************************/
 
-static int stellaris_protect_check(struct flash_bank_s *bank)
+static int stellaris_protect_check(struct flash_bank *bank)
 {
        uint32_t status;
 
@@ -642,12 +643,12 @@ static int stellaris_protect_check(struct flash_bank_s *bank)
        return ERROR_OK;
 }
 
-static int stellaris_erase(struct flash_bank_s *bank, int first, int last)
+static int stellaris_erase(struct flash_bank *bank, int first, int last)
 {
        int banknr;
        uint32_t flash_fmc, flash_cris;
        struct stellaris_flash_bank *stellaris_info = bank->driver_priv;
-       target_t *target = bank->target;
+       struct target *target = bank->target;
 
        if (bank->target->state != TARGET_HALTED)
        {
@@ -712,13 +713,13 @@ static int stellaris_erase(struct flash_bank_s *bank, int first, int last)
        return ERROR_OK;
 }
 
-static int stellaris_protect(struct flash_bank_s *bank, int set, int first, int last)
+static int stellaris_protect(struct flash_bank *bank, int set, int first, int last)
 {
        uint32_t fmppe, flash_fmc, flash_cris;
        int lockregion;
 
        struct stellaris_flash_bank *stellaris_info = bank->driver_priv;
-       target_t *target = bank->target;
+       struct target *target = bank->target;
 
        if (bank->target->state != TARGET_HALTED)
        {
@@ -828,12 +829,12 @@ static uint8_t stellaris_write_code[] =
        0x01,0x00,0x42,0xA4     /* .word        0xA4420001 */
 };
 
-static int stellaris_write_block(struct flash_bank_s *bank, uint8_t *buffer, uint32_t offset, uint32_t wcount)
+static int stellaris_write_block(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t wcount)
 {
-       target_t *target = bank->target;
+       struct target *target = bank->target;
        uint32_t buffer_size = 8192;
-       working_area_t *source;
-       working_area_t *write_algorithm;
+       struct working_area *source;
+       struct working_area *write_algorithm;
        uint32_t address = bank->base + offset;
        struct reg_param reg_params[3];
        struct armv7m_algorithm armv7m_info;
@@ -908,10 +909,10 @@ static int stellaris_write_block(struct flash_bank_s *bank, uint8_t *buffer, uin
        return retval;
 }
 
-static int stellaris_write(struct flash_bank_s *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
+static int stellaris_write(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, uint32_t count)
 {
        struct stellaris_flash_bank *stellaris_info = bank->driver_priv;
-       target_t *target = bank->target;
+       struct target *target = bank->target;
        uint32_t address = offset;
        uint32_t flash_cris, flash_fmc;
        uint32_t words_remaining = (count / 4);
@@ -1043,7 +1044,7 @@ static int stellaris_write(struct flash_bank_s *bank, uint8_t *buffer, uint32_t
        return ERROR_OK;
 }
 
-static int stellaris_probe(struct flash_bank_s *bank)
+static int stellaris_probe(struct flash_bank *bank)
 {
        /* we can't probe on an stellaris
         * if this is an stellaris, it has the configured flash
@@ -1059,7 +1060,7 @@ static int stellaris_probe(struct flash_bank_s *bank)
        return stellaris_read_part_info(bank);
 }
 
-static int stellaris_auto_probe(struct flash_bank_s *bank)
+static int stellaris_auto_probe(struct flash_bank *bank)
 {
        struct stellaris_flash_bank *stellaris_info = bank->driver_priv;
        if (stellaris_info->did1)
@@ -1067,9 +1068,9 @@ static int stellaris_auto_probe(struct flash_bank_s *bank)
        return stellaris_probe(bank);
 }
 
-static int stellaris_mass_erase(struct flash_bank_s *bank)
+static int stellaris_mass_erase(struct flash_bank *bank)
 {
-       target_t *target = NULL;
+       struct target *target = NULL;
        struct stellaris_flash_bank *stellaris_info = NULL;
        uint32_t flash_fmc;
 
@@ -1131,14 +1132,14 @@ COMMAND_HANDLER(stellaris_handle_mass_erase_command)
 {
        int i;
 
-       if (argc < 1)
+       if (CMD_ARGC < 1)
        {
-               command_print(cmd_ctx, "stellaris mass_erase <bank>");
+               command_print(CMD_CTX, "stellaris mass_erase <bank>");
                return ERROR_OK;
        }
 
-       flash_bank_t *bank;
-       int retval = flash_command_get_bank_by_num(cmd_ctx, args[0], &bank);
+       struct flash_bank *bank;
+       int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
        if (ERROR_OK != retval)
                return retval;
 
@@ -1150,22 +1151,22 @@ COMMAND_HANDLER(stellaris_handle_mass_erase_command)
                        bank->sectors[i].is_erased = 1;
                }
 
-               command_print(cmd_ctx, "stellaris mass erase complete");
+               command_print(CMD_CTX, "stellaris mass erase complete");
        }
        else
        {
-               command_print(cmd_ctx, "stellaris mass erase failed");
+               command_print(CMD_CTX, "stellaris mass erase failed");
        }
 
        return ERROR_OK;
 }
 
-static int stellaris_register_commands(struct command_context_s *cmd_ctx)
+static int stellaris_register_commands(struct command_context *cmd_ctx)
 {
-       command_t *stm32x_cmd = register_command(cmd_ctx, NULL, "stellaris",
+       struct command *stm32x_cmd = COMMAND_REGISTER(cmd_ctx, NULL, "stellaris",
                        NULL, COMMAND_ANY, "stellaris flash specific commands");
 
-       register_command(cmd_ctx, stm32x_cmd, "mass_erase",
+       COMMAND_REGISTER(cmd_ctx, stm32x_cmd, "mass_erase",
                        stellaris_handle_mass_erase_command, COMMAND_EXEC,
                        "mass erase device");
        return ERROR_OK;