xref: /btstack/platform/embedded/hal_flash_bank.h (revision 17ae5bc4f48b8b6c46a2a11fb6395ec461fe225d)
1*17ae5bc4SMatthias Ringwald /*
2*17ae5bc4SMatthias Ringwald  * Copyright (C) 2017 BlueKitchen GmbH
3*17ae5bc4SMatthias Ringwald  *
4*17ae5bc4SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
5*17ae5bc4SMatthias Ringwald  * modification, are permitted provided that the following conditions
6*17ae5bc4SMatthias Ringwald  * are met:
7*17ae5bc4SMatthias Ringwald  *
8*17ae5bc4SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
9*17ae5bc4SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
10*17ae5bc4SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11*17ae5bc4SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
12*17ae5bc4SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
13*17ae5bc4SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
14*17ae5bc4SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
15*17ae5bc4SMatthias Ringwald  *    from this software without specific prior written permission.
16*17ae5bc4SMatthias Ringwald  *
17*17ae5bc4SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS
18*17ae5bc4SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19*17ae5bc4SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20*17ae5bc4SMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
21*17ae5bc4SMatthias Ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22*17ae5bc4SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23*17ae5bc4SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24*17ae5bc4SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25*17ae5bc4SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26*17ae5bc4SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27*17ae5bc4SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28*17ae5bc4SMatthias Ringwald  * SUCH DAMAGE.
29*17ae5bc4SMatthias Ringwald  *
30*17ae5bc4SMatthias Ringwald  */
31*17ae5bc4SMatthias Ringwald 
32*17ae5bc4SMatthias Ringwald /*
33*17ae5bc4SMatthias Ringwald  *  hal_flash_bank.h
34*17ae5bc4SMatthias Ringwald  *
35*17ae5bc4SMatthias Ringwald  *  HAL abstraction for Flash memory that can be written anywhere
36*17ae5bc4SMatthias Ringwald  *  after being erased
37*17ae5bc4SMatthias Ringwald  */
38*17ae5bc4SMatthias Ringwald 
39*17ae5bc4SMatthias Ringwald #ifndef __HAL_FLASH_BANK_H
40*17ae5bc4SMatthias Ringwald #define __HAL_FLASH_BANK_H
41*17ae5bc4SMatthias Ringwald 
42*17ae5bc4SMatthias Ringwald #include <stdint.h>
43*17ae5bc4SMatthias Ringwald 
44*17ae5bc4SMatthias Ringwald #if defined __cplusplus
45*17ae5bc4SMatthias Ringwald extern "C" {
46*17ae5bc4SMatthias Ringwald #endif
47*17ae5bc4SMatthias Ringwald 
48*17ae5bc4SMatthias Ringwald typedef struct {
49*17ae5bc4SMatthias Ringwald 
50*17ae5bc4SMatthias Ringwald 	/**
51*17ae5bc4SMatthias Ringwald 	 * Get size of flash banks
52*17ae5bc4SMatthias Ringwald 	 */
53*17ae5bc4SMatthias Ringwald 	uint32_t (*get_size)(void * context);
54*17ae5bc4SMatthias Ringwald 
55*17ae5bc4SMatthias Ringwald 	/**
56*17ae5bc4SMatthias Ringwald 	 * Get flash read/write alignmenent requirements
57*17ae5bc4SMatthias Ringwald 	 */
58*17ae5bc4SMatthias Ringwald 	uint32_t (*get_alignment)(void * context);
59*17ae5bc4SMatthias Ringwald 
60*17ae5bc4SMatthias Ringwald 	/**
61*17ae5bc4SMatthias Ringwald 	 * Erase a bank
62*17ae5bc4SMatthias Ringwald 	 * @param context
63*17ae5bc4SMatthias Ringwald 	 * @param bank
64*17ae5bc4SMatthias Ringwald 	 */
65*17ae5bc4SMatthias Ringwald 	void (*erase)(void * context, int bank);
66*17ae5bc4SMatthias Ringwald 
67*17ae5bc4SMatthias Ringwald 	/**
68*17ae5bc4SMatthias Ringwald 	 * Read from flash into provided buffer
69*17ae5bc4SMatthias Ringwald 	 * @param context
70*17ae5bc4SMatthias Ringwald 	 * @param bank
71*17ae5bc4SMatthias Ringwald 	 * @param offset into flash bank
72*17ae5bc4SMatthias Ringwald 	 * @param buffer to read data
73*17ae5bc4SMatthias Ringwald 	 * @param size of data to read
74*17ae5bc4SMatthias Ringwald 	 */
75*17ae5bc4SMatthias Ringwald 	void (*read)(void * context, int bank, uint32_t offset, uint8_t * buffer, uint32_t size);
76*17ae5bc4SMatthias Ringwald 
77*17ae5bc4SMatthias Ringwald 	/**
78*17ae5bc4SMatthias Ringwald 	 * Write data into flash. Each offset can only be written once after bank was erased
79*17ae5bc4SMatthias Ringwald 	 * @param context
80*17ae5bc4SMatthias Ringwald 	 * @param bank
81*17ae5bc4SMatthias Ringwald 	 * @param offset into flash bank
82*17ae5bc4SMatthias Ringwald 	  to read data
83*17ae5bc4SMatthias Ringwald 	 * @param size of data to store
84*17ae5bc4SMatthias Ringwald 	 */
85*17ae5bc4SMatthias Ringwald 	void (*write)(void * context, int bank, uint32_t offset, const uint8_t * data, uint32_t size);
86*17ae5bc4SMatthias Ringwald 
87*17ae5bc4SMatthias Ringwald } hal_flash_bank_t;
88*17ae5bc4SMatthias Ringwald 
89*17ae5bc4SMatthias Ringwald #if defined __cplusplus
90*17ae5bc4SMatthias Ringwald }
91*17ae5bc4SMatthias Ringwald #endif
92*17ae5bc4SMatthias Ringwald #endif // __HAL_FLASH_BANK_H
93