|
| 1 | +/* |
| 2 | + * Copyright (c) 2017-2018 ARM Limited |
| 3 | + * |
| 4 | + * Licensed under the Apache License Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#include "device.h" |
| 18 | +#include "flash_api.h" |
| 19 | +#include "memory_zones.h" |
| 20 | + |
| 21 | +/* CM3DS is deployed on MPS2 board with an FPGA image (AN511). |
| 22 | + * It doesn't have physical flash memory,the implementation emulates |
| 23 | + * flash over SRAM. |
| 24 | + */ |
| 25 | +#define FLASH_PAGE_SIZE 256 |
| 26 | +#define FLASH_OFS_START ZBT_SSRAM1_START |
| 27 | +#define FLASH_SECTOR_SIZE 0x1000 |
| 28 | +#define FLASH_OFS_END (FLASH_OFS_START + FLASH_SIZE) |
| 29 | + |
| 30 | +int32_t flash_init(flash_t *obj) |
| 31 | +{ |
| 32 | + (void)obj; |
| 33 | + |
| 34 | + return 0; |
| 35 | +} |
| 36 | + |
| 37 | +int32_t flash_free(flash_t *obj) |
| 38 | +{ |
| 39 | + (void)obj; |
| 40 | + |
| 41 | + return 0; |
| 42 | +} |
| 43 | + |
| 44 | +int32_t flash_erase_sector(flash_t *obj, uint32_t address) |
| 45 | +{ |
| 46 | + (void)obj; |
| 47 | + |
| 48 | + memset((void *)address, 0xff, FLASH_SECTOR_SIZE); |
| 49 | + |
| 50 | + return 0; |
| 51 | +} |
| 52 | + |
| 53 | +int32_t flash_read(flash_t *obj, uint32_t address, |
| 54 | + uint8_t *data, uint32_t size) |
| 55 | +{ |
| 56 | + (void)obj; |
| 57 | + |
| 58 | + memcpy(data, (void *)address, size); |
| 59 | + |
| 60 | + return 0; |
| 61 | +} |
| 62 | + |
| 63 | +int32_t flash_program_page(flash_t *obj, uint32_t address, |
| 64 | + const uint8_t *data, uint32_t size) |
| 65 | +{ |
| 66 | + (void)obj; |
| 67 | + |
| 68 | + memcpy((void *)address, data, size); |
| 69 | + |
| 70 | + return 0; |
| 71 | +} |
| 72 | + |
| 73 | +uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address) |
| 74 | +{ |
| 75 | + (void)obj; |
| 76 | + |
| 77 | + if (address < FLASH_OFS_START || address >= FLASH_OFS_END) { |
| 78 | + return MBED_FLASH_INVALID_SIZE; |
| 79 | + } |
| 80 | + |
| 81 | + return FLASH_SECTOR_SIZE; |
| 82 | +} |
| 83 | + |
| 84 | +uint32_t flash_get_page_size(const flash_t *obj) |
| 85 | +{ |
| 86 | + (void)obj; |
| 87 | + |
| 88 | + return FLASH_PAGE_SIZE; |
| 89 | +} |
| 90 | + |
| 91 | +uint32_t flash_get_start_address(const flash_t *obj) |
| 92 | +{ |
| 93 | + (void)obj; |
| 94 | + |
| 95 | + return FLASH_OFS_START; |
| 96 | +} |
| 97 | + |
| 98 | +uint32_t flash_get_size(const flash_t *obj) |
| 99 | +{ |
| 100 | + (void)obj; |
| 101 | + |
| 102 | + return FLASH_SIZE; |
| 103 | +} |
0 commit comments