ChibiOS  21.6.0
hal_efl.c
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
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 /**
18  * @file hal_efl.c
19  * @brief Embedded Flash Driver code.
20  *
21  * @addtogroup HAL_EFL
22  * @{
23  */
24 
25 #include "hal.h"
26 
27 #if (HAL_USE_EFL == TRUE) || defined(__DOXYGEN__)
28 
29 /*===========================================================================*/
30 /* Driver local definitions. */
31 /*===========================================================================*/
32 
33 /*===========================================================================*/
34 /* Driver exported variables. */
35 /*===========================================================================*/
36 
37 /*===========================================================================*/
38 /* Driver local variables and types. */
39 /*===========================================================================*/
40 
41 /*===========================================================================*/
42 /* Driver local functions. */
43 /*===========================================================================*/
44 
45 static const struct EFlashDriverVMT vmt = {
46  (size_t)0,
54 };
55 
56 /*===========================================================================*/
57 /* Driver exported functions. */
58 /*===========================================================================*/
59 
60 /**
61  * @brief Embedded Flash Driver initialization.
62  * @note This function is implicitly invoked by @p halInit(), there is
63  * no need to explicitly initialize the driver.
64  *
65  * @init
66  */
67 void eflInit(void) {
68 
69  efl_lld_init();
70 }
71 
72 /**
73  * @brief Initializes a generic @p EFlashDriver object.
74  *
75  * @param[out] eflp pointer to a @p EFlashDriver structure
76  *
77  * @init
78  */
80 
81  eflp->vmt = &vmt;
82  eflp->state = FLASH_STOP;
83 }
84 
85 /**
86  * @brief Configures and starts the driver.
87  *
88  * @param[in] eflp pointer to a @p EFlashDriver structure
89  * @param[in] config pointer to a configuration structure.
90  * If this parameter is set to @p NULL then a default
91  * configuration is used.
92  *
93  * @api
94  */
95 void eflStart(EFlashDriver *eflp, const EFlashConfig *config) {
96 
97  osalDbgCheck(eflp != NULL);
98 
99  osalSysLock();
100 
101  osalDbgAssert((eflp->state == FLASH_STOP) || (eflp->state == FLASH_READY),
102  "invalid state");
103  eflp->config = config;
104  efl_lld_start(eflp);
105  eflp->state = FLASH_READY;
106 
107  osalSysUnlock();
108 }
109 
110 /**
111  * @brief Stops the driver.
112  *
113  * @param[in] eflp pointer to a @p EFlashDriver structure
114  *
115  * @api
116  */
117 void eflStop(EFlashDriver *eflp) {
118 
119  osalDbgCheck(eflp != NULL);
120 
121  osalSysLock();
122 
123  osalDbgAssert((eflp->state == FLASH_STOP) || (eflp->state == FLASH_READY),
124  "invalid state");
125 
126  efl_lld_stop(eflp);
127  eflp->state = FLASH_STOP;
128 
129  osalSysUnlock();
130 }
131 
132 #endif /* HAL_USE_EFL == TRUE */
133 
134 /** @} */
hal_efl_config
Type of a structure representing a flash driver configuration.
Definition: hal_efl.h:87
hal.h
HAL subsystem header.
efl_lld_query_erase
flash_error_t efl_lld_query_erase(void *instance, uint32_t *msec)
Queries the driver for erase operation progress.
Definition: hal_efl_lld.c:312
eflInit
void eflInit(void)
Embedded Flash Driver initialization.
Definition: hal_efl.c:67
osalSysUnlock
static void osalSysUnlock(void)
Leaves a critical zone from thread context.
Definition: osal.h:611
efl_lld_verify_erase
flash_error_t efl_lld_verify_erase(void *instance, flash_sector_t sector)
Returns the erase state of a sector.
Definition: hal_efl_lld.c:341
hal_efl_driver
Structure representing an embedded flash driver.
Definition: hal_efl.h:97
efl_lld_init
void efl_lld_init(void)
Low level Embedded Flash driver initialization.
Definition: hal_efl_lld.c:78
efl_lld_start_erase_sector
flash_error_t efl_lld_start_erase_sector(void *instance, flash_sector_t sector)
Starts an sector erase operation.
Definition: hal_efl_lld.c:275
hal_efl_driver::vmt
const struct EFlashDriverVMT * vmt
SNORDriver Virtual Methods Table.
Definition: hal_efl.h:101
efl_lld_stop
void efl_lld_stop(EFlashDriver *eflp)
Deactivates the Embedded Flash peripheral.
Definition: hal_efl_lld.c:114
efl_lld_program
flash_error_t efl_lld_program(void *instance, flash_offset_t offset, size_t n, const uint8_t *pp)
Program operation.
Definition: hal_efl_lld.c:202
efl_lld_read
flash_error_t efl_lld_read(void *instance, flash_offset_t offset, size_t n, uint8_t *rp)
Read operation.
Definition: hal_efl_lld.c:158
osalDbgCheck
#define osalDbgCheck(c)
Function parameters check.
Definition: osal.h:284
efl_lld_start
void efl_lld_start(EFlashDriver *eflp)
Configures and activates the Embedded Flash peripheral.
Definition: hal_efl_lld.c:93
EFlashDriverVMT
EFlash virtual methods table.
Definition: hal_efl.h:80
osalSysLock
static void osalSysLock(void)
Enters a critical zone from thread context.
Definition: osal.h:601
eflStop
void eflStop(EFlashDriver *eflp)
Stops the driver.
Definition: hal_efl.c:117
osalDbgAssert
#define osalDbgAssert(c, remark)
Condition assertion.
Definition: osal.h:264
efl_lld_get_descriptor
const flash_descriptor_t * efl_lld_get_descriptor(void *instance)
Gets the flash descriptor structure.
Definition: hal_efl_lld.c:136
eflStart
void eflStart(EFlashDriver *eflp, const EFlashConfig *config)
Configures and starts the driver.
Definition: hal_efl.c:95
eflObjectInit
void eflObjectInit(EFlashDriver *eflp)
Initializes a generic EFlashDriver object.
Definition: hal_efl.c:79
efl_lld_start_erase_all
flash_error_t efl_lld_start_erase_all(void *instance)
Starts a whole-device erase operation.
Definition: hal_efl_lld.c:243