Debian Codegraph @

ports/renesas-ra/ra/ra_flash.h

raw
1 /*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2021 Renesas Electronics Corporation
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25 #ifndef RA_FLASH_H_
26 #define RA_FLASH_H_
27
28 #include <stdio.h>
29 #include <stdint.h>
30 #include <stdbool.h>
31
32 #if MICROPY_HW_HAS_QSPI_FLASH
33 #define SELECT(ic, attr) ic##_##attr
34 #define FLASH(ic, attr) SELECT(ic, attr)
35 #define CHIP AT25SF128A
36 // #define CHIP W25Q128JV
37
38 #define W25Q128JV_SECTOR_SIZE 4096ul
39 #define W25Q128JV_NUM_BLOCKS 4096ul
40 #define W25Q128JV_PAGE_SIZE 256ul
41
42 #define AT25SF128A_SECTOR_SIZE 4096ul
43 #define AT25SF128A_NUM_BLOCKS 4096ul
44 #define AT25SF128A_PAGE_SIZE 256ul
45
46 #define FLASH_SECTOR_SIZE FLASH(CHIP, SECTOR_SIZE)
47 #define FLASH_NUM_BLOCKS FLASH(CHIP, NUM_BLOCKS)
48 #define FLASH_PAGE_SIZE FLASH(CHIP, PAGE_SIZE)
49 #else
50 #define FLASH_SECTOR_SIZE ((uint32_t)2048)
51 #define FLASH_NUM_BLOCKS ((uint32_t)128)
52 #endif
53 #define FLASH_BUF_OFF_MASK (FLASH_SECTOR_SIZE - 1)
54 #define FLASH_BUF_ADDR_MASK (~FLASH_BUF_OFF_MASK)
55 #define FLASH_BUF_SIZE FLASH_SECTOR_SIZE
56
57 #define FLASH_SECTION __attribute__((section("FLASH_OP")))
58
59 typedef uint8_t CHIP_WORD;
60
61 void FLASH_SECTION *lmemset(void *dst, int c, size_t len);
62 void FLASH_SECTION *lmemcpy(void *dst, const void *src, size_t len);
63 int FLASH_SECTION lmemcmp(const void *p1, const void *p2, size_t len);
64
65 uint32_t FLASH_SECTION sector_size(uint32_t addr);
66 uint32_t FLASH_SECTION sector_start(uint32_t addr);
67 uint32_t FLASH_SECTION sector_index(uint32_t addr);
68 bool FLASH_SECTION internal_flash_read(uint8_t *addr, uint32_t NumBytes, uint8_t *pSectorBuff);
69 bool FLASH_SECTION internal_flash_write(uint8_t *addr, uint32_t NumBytes, uint8_t *pSectorBuff, bool ReadModifyWrite);
70 bool FLASH_SECTION internal_flash_writex(uint8_t *addr, uint32_t NumBytes, uint8_t *pSectorBuff, bool ReadModifyWrite, bool fIncrementDataPtr);
71 bool FLASH_SECTION internal_flash_memset(uint8_t *addr, uint8_t Data, uint32_t NumBytes);
72 bool FLASH_SECTION internal_flash_isblockerased(uint8_t *addr, uint32_t BlockLength);
73 bool FLASH_SECTION internal_flash_eraseblock(uint8_t *addr);
74 bool FLASH_SECTION internal_flash_init(void);
75
76 #endif /* RA_FLASH_H_ */