mirror of
https://github.com/blackmagic-debug/blackmagic.git
synced 2025-10-14 02:58:36 +08:00
msp432p4: Normalised the code organisation a bit
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* This file is part of the Black Magic Debug project.
|
||||
*
|
||||
* Copyright (C) 2017 newbrain <federico.zuccardimerli@gmail.com>
|
||||
* Copyright (C) 2022-2023 1BitSquared <info@1bitsquared.com>
|
||||
* Copyright (C) 2022-2025 1BitSquared <info@1bitsquared.com>
|
||||
* Modified by Rachel Mant <git@dragonmux.network>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@@ -108,26 +108,6 @@ typedef struct msp432_flash {
|
||||
target_addr_t flash_program_fn; /* Flash programming routine in ROM */
|
||||
} msp432_flash_s;
|
||||
|
||||
static bool msp432_sector_erase(const target_flash_s *target_flash, target_addr_t addr);
|
||||
static bool msp432_flash_erase(target_flash_s *flash, target_addr_t addr, size_t len);
|
||||
static bool msp432_flash_write(target_flash_s *flash, target_addr_t dest, const void *src, size_t len);
|
||||
|
||||
/* Call a function in the MSP432 ROM (or anywhere else...)*/
|
||||
static void msp432_call_rom(target_s *target, uint32_t address, uint32_t *regs);
|
||||
|
||||
/* Protect or unprotect the sector containing address */
|
||||
static inline uint32_t msp432_sector_unprotect(const msp432_flash_s *const flash, target_addr_t addr)
|
||||
{
|
||||
/* Read the old protection register */
|
||||
uint32_t old_mask = target_mem32_read32(flash->f.t, flash->flash_protect_register);
|
||||
/* Find the bit representing the sector and set it to 0 */
|
||||
uint32_t sec_mask = ~(1U << ((addr - flash->f.start) / SECTOR_SIZE));
|
||||
/* Clear the potection bit */
|
||||
sec_mask &= old_mask;
|
||||
target_mem32_write32(flash->f.t, flash->flash_protect_register, sec_mask);
|
||||
return old_mask;
|
||||
}
|
||||
|
||||
/* Optional commands handlers */
|
||||
/* Erase all of main flash */
|
||||
static bool msp432_cmd_erase_main(target_s *target, int argc, const char **argv);
|
||||
@@ -141,6 +121,13 @@ const command_s msp432_cmd_list[] = {
|
||||
{NULL, NULL, NULL},
|
||||
};
|
||||
|
||||
static bool msp432_sector_erase(const target_flash_s *target_flash, target_addr_t addr);
|
||||
static bool msp432_flash_erase(target_flash_s *flash, target_addr_t addr, size_t len);
|
||||
static bool msp432_flash_write(target_flash_s *flash, target_addr_t dest, const void *src, size_t len);
|
||||
|
||||
/* Call a function in the MSP432 ROM (or anywhere else...)*/
|
||||
static void msp432_call_rom(target_s *target, uint32_t address, uint32_t *regs);
|
||||
|
||||
static void msp432_add_flash(target_s *target, uint32_t addr, size_t length, target_addr_t prot_reg)
|
||||
{
|
||||
msp432_flash_s *flash = calloc(1, sizeof(*flash));
|
||||
@@ -222,6 +209,19 @@ bool msp432p4_probe(target_s *target)
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Protect or unprotect the sector containing address */
|
||||
static inline uint32_t msp432_sector_unprotect(const msp432_flash_s *const flash, const target_addr_t addr)
|
||||
{
|
||||
/* Read the old protection register */
|
||||
uint32_t old_mask = target_mem32_read32(flash->f.t, flash->flash_protect_register);
|
||||
/* Find the bit representing the sector and set it to 0 */
|
||||
uint32_t sec_mask = ~(1U << ((addr - flash->f.start) / SECTOR_SIZE));
|
||||
/* Clear the potection bit */
|
||||
sec_mask &= old_mask;
|
||||
target_mem32_write32(flash->f.t, flash->flash_protect_register, sec_mask);
|
||||
return old_mask;
|
||||
}
|
||||
|
||||
/* Flash operations */
|
||||
/* Erase a single sector at addr calling the ROM routine*/
|
||||
static bool msp432_sector_erase(const target_flash_s *const target_flash, const target_addr_t addr)
|
||||
|
Reference in New Issue
Block a user