X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fflash%2Flpc288x.c;h=4827c2198886809dc4172f7bca3addf478bc06a8;hb=4cd02c63e9213b7f33ec4ac33d481fb00e00708f;hp=5400339946897eefa164107ed5921c4ac6a7e154;hpb=310be8a838c9db6b67bc4d6d7d3c7ff41b32af4c;p=openocd diff --git a/src/flash/lpc288x.c b/src/flash/lpc288x.c index 54003399..4827c219 100644 --- a/src/flash/lpc288x.c +++ b/src/flash/lpc288x.c @@ -84,52 +84,34 @@ /* F_CLK_TIME */ #define FCT_CLK_DIV_MASK 0x0FFF +#if 0 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, u32 offset, u32 count); +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 u32 lpc288x_wait_status_busy(flash_bank_t *bank, int timeout); +#endif +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 u32 lpc288x_system_ready(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) +static uint32_t lpc288x_wait_status_busy(flash_bank_t *bank, int timeout) { - return ERROR_OK; -} - -static u32 lpc288x_wait_status_busy(flash_bank_t *bank, int timeout) -{ - u32 status; + uint32_t status; target_t *target = bank->target; do { 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; @@ -142,10 +124,10 @@ static int lpc288x_read_part_info(struct flash_bank_s *bank) { lpc288x_flash_bank_t *lpc288x_info = bank->driver_priv; target_t *target = bank->target; - u32 cidr; + uint32_t cidr; int i = 0; - u32 offset; + uint32_t offset; if (lpc288x_info->cidr == 0x0102100A) return ERROR_OK; /* already probed, multiple probes may cause memory leak, not allowed */ @@ -155,7 +137,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; } @@ -209,19 +191,19 @@ 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 ? */ static void lpc288x_set_flash_clk(struct flash_bank_s *bank) { - u32 clk_time; + uint32_t clk_time; lpc288x_flash_bank_t *lpc288x_info = bank->driver_priv; clk_time = (lpc288x_info->cclk / 66000) / 3; target_write_u32(bank->target, F_CTRL, FC_CS | FC_WEN); @@ -246,7 +228,7 @@ static void lpc288x_load_timer(int erase, struct target_s *target) } } -static u32 lpc288x_system_ready(struct flash_bank_s *bank) +static uint32_t lpc288x_system_ready(struct flash_bank_s *bank) { lpc288x_flash_bank_t *lpc288x_info = bank->driver_priv; if (lpc288x_info->cidr == 0) @@ -264,7 +246,7 @@ static u32 lpc288x_system_ready(struct flash_bank_s *bank) static int lpc288x_erase_check(struct flash_bank_s *bank) { - u32 status = lpc288x_system_ready(bank); /* probed? halted? */ + uint32_t status = lpc288x_system_ready(bank); /* probed? halted? */ if (status != ERROR_OK) { LOG_INFO("Processor not halted/not probed"); @@ -276,7 +258,7 @@ static int lpc288x_erase_check(struct flash_bank_s *bank) static int lpc288x_erase(struct flash_bank_s *bank, int first, int last) { - u32 status; + uint32_t status; int sector; target_t *target = bank->target; @@ -315,13 +297,13 @@ static int lpc288x_erase(struct flash_bank_s *bank, int first, int last) return ERROR_OK; } -static int lpc288x_write(struct flash_bank_s *bank, uint8_t *buffer, u32 offset, u32 count) +static int lpc288x_write(struct flash_bank_s *bank, uint8_t *buffer, uint32_t offset, uint32_t count) { uint8_t page_buffer[FLASH_PAGE_SIZE]; - u32 status, source_offset,dest_offset; + uint32_t status, source_offset,dest_offset; target_t *target = bank->target; - u32 bytes_remaining = count; - u32 first_sector, last_sector, sector, page; + uint32_t bytes_remaining = count; + uint32_t first_sector, last_sector, sector, page; int i; /* probed? halted? */ @@ -345,7 +327,7 @@ static int lpc288x_write(struct flash_bank_s *bank, uint8_t *buffer, u32 offset, /* 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 +342,7 @@ static int lpc288x_write(struct flash_bank_s *bank, uint8_t *buffer, u32 offset, /* 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 +390,7 @@ static int lpc288x_write(struct flash_bank_s *bank, uint8_t *buffer, u32 offset, #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 @@ -463,7 +445,7 @@ static int lpc288x_info(struct flash_bank_s *bank, char *buf, int buf_size) static int lpc288x_protect(struct flash_bank_s *bank, int set, int first, int last) { int lockregion, status; - u32 value; + uint32_t value; target_t *target = bank->target; /* probed? halted? */ @@ -499,3 +481,16 @@ static int lpc288x_protect(struct flash_bank_s *bank, int set, int first, int la return ERROR_OK; } + +flash_driver_t 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, + };