1 /*
2 * Copyright (c) 2023 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 #ifndef __DRIVER_FLASH_COMMON_H__
18 #define __DRIVER_FLASH_COMMON_H__
19
20 #include "Driver_Flash.h"
21
22 #ifndef ARG_UNUSED
23 #define ARG_UNUSED(arg) ((void)arg)
24 #endif
25
26 /* Driver version */
27 #define ARM_FLASH_DRV_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(1, 1)
28 #define ARM_FLASH_DRV_ERASE_VALUE 0xFF
29
30 /**
31 * Data width values for ARM_FLASH_CAPABILITIES::data_width
32 * \ref ARM_FLASH_CAPABILITIES
33 */
34 enum {
35 DATA_WIDTH_8BIT = 0u,
36 DATA_WIDTH_16BIT,
37 DATA_WIDTH_32BIT,
38 DATA_WIDTH_ENUM_SIZE
39 };
40
41 static const uint32_t data_width_byte[DATA_WIDTH_ENUM_SIZE] = {
42 sizeof(uint8_t),
43 sizeof(uint16_t),
44 sizeof(uint32_t),
45 };
46
47 /* Flash Status */
48 static ARM_FLASH_STATUS FlashStatus = {0, 0, 0};
49
50 /* Driver Version */
51 static const ARM_DRIVER_VERSION DriverVersion = {
52 ARM_FLASH_API_VERSION,
53 ARM_FLASH_DRV_VERSION
54 };
55
56 /*
57 * Common interface functions
58 */
59
ARM_Flash_GetVersion(void)60 static inline ARM_DRIVER_VERSION ARM_Flash_GetVersion(void)
61 {
62 return DriverVersion;
63 }
64
ARM_Flash_GetStatus(void)65 static inline ARM_FLASH_STATUS ARM_Flash_GetStatus(void)
66 {
67 return FlashStatus;
68 }
69
ARM_Flash_PowerControl(ARM_POWER_STATE state)70 static inline int32_t ARM_Flash_PowerControl(ARM_POWER_STATE state)
71 {
72 switch (state) {
73 case ARM_POWER_FULL:
74 /* Nothing to be done */
75 return ARM_DRIVER_OK;
76 break;
77
78 case ARM_POWER_OFF:
79 case ARM_POWER_LOW:
80 default:
81 return ARM_DRIVER_ERROR_UNSUPPORTED;
82 }
83 }
84
ARM_Flash_Uninitialize(void)85 static inline int32_t ARM_Flash_Uninitialize(void)
86 {
87 /* Nothing to be done */
88 return ARM_DRIVER_OK;
89 }
90
91 #endif /* __DRIVER_FLASH_COMMON_H__ */
92