Select Git revision
notification.js
-
Bekerle, Patrizio authoredBekerle, Patrizio authored
btstack_flash_bank.c 6.46 KiB
/*
* Copyright (c) 2023 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "pico/btstack_flash_bank.h"
#include "pico/flash.h"
#include "hardware/sync.h"
#include "hardware/flash.h"
#include <string.h>
// Check sizes
static_assert(PICO_FLASH_BANK_TOTAL_SIZE % (FLASH_SECTOR_SIZE * 2) == 0, "PICO_FLASH_BANK_TOTAL_SIZE invalid");
static_assert(PICO_FLASH_BANK_TOTAL_SIZE <= PICO_FLASH_SIZE_BYTES, "PICO_FLASH_BANK_TOTAL_SIZE too big");
// Size of one bank
#define PICO_FLASH_BANK_SIZE (PICO_FLASH_BANK_TOTAL_SIZE / 2)
#if 0
#define DEBUG_PRINT(format,args...) printf(format, ## args)
#else
#define DEBUG_PRINT(...)
#endif
static uint32_t pico_flash_bank_get_size(void * context) {
(void)(context);
return PICO_FLASH_BANK_SIZE;
}
static uint32_t pico_flash_bank_get_alignment(void * context) {
(void)(context);
return 1;
}
typedef struct {
bool op_is_erase;
uintptr_t p0;
uintptr_t p1;
} mutation_operation_t;
static void pico_flash_bank_perform_flash_mutation_operation(void *param) {
const mutation_operation_t *mop = (const mutation_operation_t *)param;
if (mop->op_is_erase) {
flash_range_erase(mop->p0, PICO_FLASH_BANK_SIZE);
} else {
flash_range_program(mop->p0, (const uint8_t *)mop->p1, FLASH_PAGE_SIZE);
}
}
#ifndef pico_flash_bank_get_storage_offset_func
static inline uint32_t pico_flash_bank_get_fixed_storage_offset(void) {
static_assert(PICO_FLASH_BANK_STORAGE_OFFSET + PICO_FLASH_BANK_TOTAL_SIZE <= PICO_FLASH_SIZE_BYTES, "PICO_FLASH_BANK_TOTAL_SIZE too big");
#ifndef NDEBUG
// Check we're not overlapping the binary in flash
extern char __flash_binary_end;
assert(((uintptr_t)&__flash_binary_end - XIP_BASE <= PICO_FLASH_BANK_STORAGE_OFFSET));
#endif
return PICO_FLASH_BANK_STORAGE_OFFSET;
}
#define pico_flash_bank_get_storage_offset_func pico_flash_bank_get_fixed_storage_offset
#else
extern uint32_t pico_flash_bank_get_storage_offset_func(void);
#endif
static void pico_flash_bank_erase(void * context, int bank) {
(void)(context);
DEBUG_PRINT("erase: bank %d\n", bank);
mutation_operation_t mop = {
.op_is_erase = true,