117ae5bc4SMatthias Ringwald /* 217ae5bc4SMatthias Ringwald * Copyright (C) 2017 BlueKitchen GmbH 317ae5bc4SMatthias Ringwald * 417ae5bc4SMatthias Ringwald * Redistribution and use in source and binary forms, with or without 517ae5bc4SMatthias Ringwald * modification, are permitted provided that the following conditions 617ae5bc4SMatthias Ringwald * are met: 717ae5bc4SMatthias Ringwald * 817ae5bc4SMatthias Ringwald * 1. Redistributions of source code must retain the above copyright 917ae5bc4SMatthias Ringwald * notice, this list of conditions and the following disclaimer. 1017ae5bc4SMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright 1117ae5bc4SMatthias Ringwald * notice, this list of conditions and the following disclaimer in the 1217ae5bc4SMatthias Ringwald * documentation and/or other materials provided with the distribution. 1317ae5bc4SMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of 1417ae5bc4SMatthias Ringwald * contributors may be used to endorse or promote products derived 1517ae5bc4SMatthias Ringwald * from this software without specific prior written permission. 1617ae5bc4SMatthias Ringwald * 17*2fca4dadSMilanka Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 1817ae5bc4SMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1917ae5bc4SMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 20*2fca4dadSMilanka Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN 21*2fca4dadSMilanka Ringwald * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 2217ae5bc4SMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 2317ae5bc4SMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 2417ae5bc4SMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 2517ae5bc4SMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 2617ae5bc4SMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 2717ae5bc4SMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2817ae5bc4SMatthias Ringwald * SUCH DAMAGE. 2917ae5bc4SMatthias Ringwald * 3017ae5bc4SMatthias Ringwald */ 3117ae5bc4SMatthias Ringwald 3217ae5bc4SMatthias Ringwald /* 3317ae5bc4SMatthias Ringwald * hal_flash_bank.h 3417ae5bc4SMatthias Ringwald * 3517ae5bc4SMatthias Ringwald * HAL abstraction for Flash memory that can be written anywhere 3617ae5bc4SMatthias Ringwald * after being erased 3717ae5bc4SMatthias Ringwald */ 3817ae5bc4SMatthias Ringwald 3980e33422SMatthias Ringwald #ifndef HAL_FLASH_BANK_H 4080e33422SMatthias Ringwald #define HAL_FLASH_BANK_H 4117ae5bc4SMatthias Ringwald 4217ae5bc4SMatthias Ringwald #include <stdint.h> 4317ae5bc4SMatthias Ringwald 4417ae5bc4SMatthias Ringwald #if defined __cplusplus 4517ae5bc4SMatthias Ringwald extern "C" { 4617ae5bc4SMatthias Ringwald #endif 4717ae5bc4SMatthias Ringwald 4817ae5bc4SMatthias Ringwald typedef struct { 4917ae5bc4SMatthias Ringwald 5017ae5bc4SMatthias Ringwald /** 5117ae5bc4SMatthias Ringwald * Get size of flash banks 5217ae5bc4SMatthias Ringwald */ 5317ae5bc4SMatthias Ringwald uint32_t (*get_size)(void * context); 5417ae5bc4SMatthias Ringwald 5517ae5bc4SMatthias Ringwald /** 5617ae5bc4SMatthias Ringwald * Get flash read/write alignmenent requirements 5717ae5bc4SMatthias Ringwald */ 5817ae5bc4SMatthias Ringwald uint32_t (*get_alignment)(void * context); 5917ae5bc4SMatthias Ringwald 6017ae5bc4SMatthias Ringwald /** 6117ae5bc4SMatthias Ringwald * Erase a bank 6217ae5bc4SMatthias Ringwald * @param context 6317ae5bc4SMatthias Ringwald * @param bank 6417ae5bc4SMatthias Ringwald */ 6517ae5bc4SMatthias Ringwald void (*erase)(void * context, int bank); 6617ae5bc4SMatthias Ringwald 6717ae5bc4SMatthias Ringwald /** 6817ae5bc4SMatthias Ringwald * Read from flash into provided buffer 6917ae5bc4SMatthias Ringwald * @param context 7017ae5bc4SMatthias Ringwald * @param bank 7117ae5bc4SMatthias Ringwald * @param offset into flash bank 7217ae5bc4SMatthias Ringwald * @param buffer to read data 7317ae5bc4SMatthias Ringwald * @param size of data to read 7417ae5bc4SMatthias Ringwald */ 7517ae5bc4SMatthias Ringwald void (*read)(void * context, int bank, uint32_t offset, uint8_t * buffer, uint32_t size); 7617ae5bc4SMatthias Ringwald 7717ae5bc4SMatthias Ringwald /** 7817ae5bc4SMatthias Ringwald * Write data into flash. Each offset can only be written once after bank was erased 7917ae5bc4SMatthias Ringwald * @param context 8017ae5bc4SMatthias Ringwald * @param bank 8117ae5bc4SMatthias Ringwald * @param offset into flash bank 8217ae5bc4SMatthias Ringwald to read data 8317ae5bc4SMatthias Ringwald * @param size of data to store 8417ae5bc4SMatthias Ringwald */ 8517ae5bc4SMatthias Ringwald void (*write)(void * context, int bank, uint32_t offset, const uint8_t * data, uint32_t size); 8617ae5bc4SMatthias Ringwald 8717ae5bc4SMatthias Ringwald } hal_flash_bank_t; 8817ae5bc4SMatthias Ringwald 8917ae5bc4SMatthias Ringwald #if defined __cplusplus 9017ae5bc4SMatthias Ringwald } 9117ae5bc4SMatthias Ringwald #endif 9280e33422SMatthias Ringwald #endif // HAL_FLASH_BANK_H 93