]> begriffs open source - cmsis/blob - CMSIS/Driver/DriverTemplates/Driver_Flash.c
Possible bugs in MMU_MemorySection(), MMU_MemoryPage() (#219)
[cmsis] / CMSIS / Driver / DriverTemplates / Driver_Flash.c
1 /*
2  * Copyright (c) 2013-2020 Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the License); you may
7  * not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18  
19 #include "Driver_Flash.h"
20
21 #define ARM_FLASH_DRV_VERSION    ARM_DRIVER_VERSION_MAJOR_MINOR(1, 0) /* driver version */
22
23 /* Sector Information */
24 #ifdef FLASH_SECTORS
25 static ARM_FLASH_SECTOR FLASH_SECTOR_INFO[FLASH_SECTOR_COUNT] = {
26     FLASH_SECTORS
27 };
28 #else
29 #define FLASH_SECTOR_INFO    NULL
30 #endif
31
32 /* Flash Information */
33 static ARM_FLASH_INFO FlashInfo = {
34     0, /* FLASH_SECTOR_INFO  */
35     0, /* FLASH_SECTOR_COUNT */
36     0, /* FLASH_SECTOR_SIZE  */
37     0, /* FLASH_PAGE_SIZE    */
38     0, /* FLASH_PROGRAM_UNIT */
39     0, /* FLASH_ERASED_VALUE */
40   { 0, 0, 0 }  /* Reserved (must be zero) */
41 };
42
43 /* Flash Status */
44 static ARM_FLASH_STATUS FlashStatus;
45
46 /* Driver Version */
47 static const ARM_DRIVER_VERSION DriverVersion = {
48     ARM_FLASH_API_VERSION,
49     ARM_FLASH_DRV_VERSION
50 };
51
52 /* Driver Capabilities */
53 static const ARM_FLASH_CAPABILITIES DriverCapabilities = {
54     0, /* event_ready */
55     0, /* data_width = 0:8-bit, 1:16-bit, 2:32-bit */
56     0, /* erase_chip */
57     0  /* reserved (must be zero) */
58 };
59
60 //
61 // Functions
62 //
63
64 static ARM_DRIVER_VERSION ARM_Flash_GetVersion(void)
65 {
66   return DriverVersion;
67 }
68
69 static ARM_FLASH_CAPABILITIES ARM_Flash_GetCapabilities(void)
70 {
71   return DriverCapabilities;
72 }
73
74 static int32_t ARM_Flash_Initialize(ARM_Flash_SignalEvent_t cb_event)
75 {
76 }
77
78 static int32_t ARM_Flash_Uninitialize(void)
79 {
80 }
81
82 static int32_t ARM_Flash_PowerControl(ARM_POWER_STATE state)
83 {
84     switch (state)
85     {
86     case ARM_POWER_OFF:
87         break;
88
89     case ARM_POWER_LOW:
90         break;
91
92     case ARM_POWER_FULL:
93         break;
94     }
95     return ARM_DRIVER_OK;
96 }
97
98 static int32_t ARM_Flash_ReadData(uint32_t addr, void *data, uint32_t cnt)
99 {
100 }
101
102 static int32_t ARM_Flash_ProgramData(uint32_t addr, const void *data, uint32_t cnt)
103 {
104 }
105
106 static int32_t ARM_Flash_EraseSector(uint32_t addr)
107 {
108 }
109
110 static int32_t ARM_Flash_EraseChip(void)
111 {
112 }
113
114 static ARM_FLASH_STATUS ARM_Flash_GetStatus(void)
115 {
116   return FlashStatus;
117 }
118
119 static ARM_FLASH_INFO * ARM_Flash_GetInfo(void)
120 {
121   return &FlashInfo;
122 }
123
124 static void ARM_Flash_SignalEvent(uint32_t event)
125 {
126 }
127
128 // End Flash Interface
129
130 extern \
131 ARM_DRIVER_FLASH Driver_Flash0;
132 ARM_DRIVER_FLASH Driver_Flash0 = {
133     ARM_Flash_GetVersion,
134     ARM_Flash_GetCapabilities,
135     ARM_Flash_Initialize,
136     ARM_Flash_Uninitialize,
137     ARM_Flash_PowerControl,
138     ARM_Flash_ReadData,
139     ARM_Flash_ProgramData,
140     ARM_Flash_EraseSector,
141     ARM_Flash_EraseChip,
142     ARM_Flash_GetStatus,
143     ARM_Flash_GetInfo
144 };