flash_driver_t -> struct flash_driver
[openocd.git] / src / flash / lpc288x.c
index b3fc2ef3bbcf7ee3a3cac4f8e8dd2e37850f1d5c..d681fbf9ea69ce3e0cf54f385e08506f197fc9f2 100644 (file)
 /* F_CLK_TIME */
 #define FCT_CLK_DIV_MASK    0x0FFF
 
-static int lpc288x_register_commands(struct command_context_s *cmd_ctx);
-static int lpc288x_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank);
-static int lpc288x_erase(struct flash_bank_s *bank, int first, int last);
-static int lpc288x_protect(struct flash_bank_s *bank, int set, int first, int last);
-static int lpc288x_write(struct flash_bank_s *bank, uint8_t *buffer, uint32_t offset, uint32_t count);
-static int lpc288x_probe(struct flash_bank_s *bank);
-static int lpc288x_erase_check(struct flash_bank_s *bank);
-static int lpc288x_protect_check(struct flash_bank_s *bank);
-static int lpc288x_info(struct flash_bank_s *bank, char *buf, int buf_size);
 static uint32_t lpc288x_wait_status_busy(flash_bank_t *bank, int timeout);
 static void lpc288x_load_timer(int erase, struct target_s *target);
 static void lpc288x_set_flash_clk(struct flash_bank_s *bank);
 static uint32_t lpc288x_system_ready(struct flash_bank_s *bank);
 
-flash_driver_t lpc288x_flash =
-{
-       .name = "lpc288x",
-       .register_commands = lpc288x_register_commands,
-       .flash_bank_command = lpc288x_flash_bank_command,
-       .erase = lpc288x_erase,
-       .protect = lpc288x_protect,
-       .write = lpc288x_write,
-       .probe = lpc288x_probe,
-       .auto_probe = lpc288x_probe,
-       .erase_check = lpc288x_erase_check,
-       .protect_check = lpc288x_protect_check,
-       .info = lpc288x_info
-};
-
-static int lpc288x_register_commands(struct command_context_s *cmd_ctx)
-{
-       return ERROR_OK;
-}
-
 static uint32_t lpc288x_wait_status_busy(flash_bank_t *bank, int timeout)
 {
        uint32_t status;
@@ -127,9 +98,9 @@ static uint32_t lpc288x_wait_status_busy(flash_bank_t *bank, int timeout)
                alive_sleep(1);
                timeout--;
                target_read_u32(target, F_STAT, &status);
-       }while (((status & FS_DONE) == 0) && timeout);
+       } while (((status & FS_DONE) == 0) && timeout);
 
-       if(timeout == 0)
+       if (timeout == 0)
        {
                LOG_DEBUG("Timedout!");
                return ERROR_FLASH_OPERATION_FAILED;
@@ -155,7 +126,7 @@ static int lpc288x_read_part_info(struct flash_bank_s *bank)
 
        if (cidr != 0x0102100A)
        {
-               LOG_WARNING("Cannot identify target as an LPC288X (%08X)",cidr);
+               LOG_WARNING("Cannot identify target as an LPC288X (%08" PRIx32 ")",cidr);
                return ERROR_FLASH_OPERATION_FAILED;
        }
 
@@ -166,7 +137,7 @@ static int lpc288x_read_part_info(struct flash_bank_s *bank)
        /* setup the sector info... */
        offset = bank->base;
        bank->num_sectors = 23;
-       bank->sectors = malloc(sizeof(flash_sector_t) * 23);
+       bank->sectors = malloc(sizeof(struct flash_sector) * 23);
 
        for (i = 0; i < 15; i++)
        {
@@ -194,7 +165,7 @@ static int lpc288x_protect_check(struct flash_bank_s *bank)
 }
 
 /* flash_bank LPC288x 0 0 0 0 <target#> <cclk> */
-static int lpc288x_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, struct flash_bank_s *bank)
+FLASH_BANK_COMMAND_HANDLER(lpc288x_flash_bank_command)
 {
        lpc288x_flash_bank_t *lpc288x_info;
 
@@ -209,13 +180,13 @@ static int lpc288x_flash_bank_command(struct command_context_s *cmd_ctx, char *c
 
        /* part wasn't probed for info yet */
        lpc288x_info->cidr = 0;
-       lpc288x_info->cclk = strtoul(args[6], NULL, 0);
+       COMMAND_PARSE_NUMBER(u32, args[6], lpc288x_info->cclk);
 
        return ERROR_OK;
 }
 
-/* The frequency is the AHB clock frequency divided by (CLK_DIV ×3) + 1.
- * This must be programmed such that the Flash Programming clock frequency is 66 kHz ± 20%.
+/* The frequency is the AHB clock frequency divided by (CLK_DIV ×3) + 1.
+ * This must be programmed such that the Flash Programming clock frequency is 66 kHz Â± 20%.
  * AHB = 12 MHz ?
  * 12000000/66000 = 182
  * CLK_DIV = 60 ? */
@@ -345,7 +316,7 @@ static int lpc288x_write(struct flash_bank_s *bank, uint8_t *buffer, uint32_t of
                        /* all writes must start on a sector boundary... */
                        if (offset % bank->sectors[i].size)
                        {
-                               LOG_INFO("offset 0x%x breaks required alignment 0x%x", offset, bank->sectors[i].size);
+                               LOG_INFO("offset 0x%" PRIx32 " breaks required alignment 0x%" PRIx32 "", offset, bank->sectors[i].size);
                                return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
                        }
                }
@@ -360,7 +331,7 @@ static int lpc288x_write(struct flash_bank_s *bank, uint8_t *buffer, uint32_t of
        /* Range check... */
        if (first_sector == 0xffffffff || last_sector == 0xffffffff)
        {
-               LOG_INFO("Range check failed %x %x", offset, count);
+               LOG_INFO("Range check failed %" PRIx32 " %" PRIx32 "", offset, count);
                return ERROR_FLASH_DST_OUT_OF_BANK;
        }
 
@@ -408,7 +379,7 @@ static int lpc288x_write(struct flash_bank_s *bank, uint8_t *buffer, uint32_t of
 #if 1
                        if (target_write_memory(target, offset + dest_offset, 4, 128, page_buffer) != ERROR_OK)
                        {
-                               LOG_ERROR("Write failed s %x p %x", sector, page);
+                               LOG_ERROR("Write failed s %" PRIx32 " p %" PRIx32 "", sector, page);
                                return ERROR_FLASH_OPERATION_FAILED;
                        }
 #else
@@ -499,3 +470,16 @@ static int lpc288x_protect(struct flash_bank_s *bank, int set, int first, int la
 
        return ERROR_OK;
 }
+
+struct flash_driver lpc288x_flash = {
+               .name = "lpc288x",
+               .flash_bank_command = &lpc288x_flash_bank_command,
+               .erase = &lpc288x_erase,
+               .protect = &lpc288x_protect,
+               .write = &lpc288x_write,
+               .probe = &lpc288x_probe,
+               .auto_probe = &lpc288x_probe,
+               .erase_check = &lpc288x_erase_check,
+               .protect_check = &lpc288x_protect_check,
+               .info = &lpc288x_info,
+       };

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)