Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
fpga.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 Antmicro <www.antmicro.com>
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12
13#ifndef ZEPHYR_INCLUDE_DRIVERS_FPGA_H_
14#define ZEPHYR_INCLUDE_DRIVERS_FPGA_H_
15
16#include <errno.h>
17
18#include <zephyr/types.h>
19#include <zephyr/sys/util.h>
20#include <zephyr/device.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
34
36 /* Inactive is when the FPGA cannot accept the bitstream
37 * and will not be programmed correctly
38 */
40 /* Active is when the FPGA can accept the bitstream and
41 * can be programmed correctly
42 */
44};
45
50
55typedef enum FPGA_status (*fpga_api_get_status)(const struct device *dev);
56
61typedef int (*fpga_api_load)(const struct device *dev, uint32_t *image_ptr,
62 uint32_t img_size);
63
68typedef int (*fpga_api_reset)(const struct device *dev);
69
74typedef int (*fpga_api_on)(const struct device *dev);
75
80typedef int (*fpga_api_off)(const struct device *dev);
81
86typedef const char *(*fpga_api_get_info)(const struct device *dev);
87
117
120
129static inline enum FPGA_status fpga_get_status(const struct device *dev)
130{
131 const struct fpga_driver_api *api = DEVICE_API_GET(fpga, dev);
132
133 if (api->get_status == NULL) {
134 /* assume it can never be reprogrammed if it
135 * doesn't support the get_status callback
136 */
138 }
139
140 return api->get_status(dev);
141}
142
151static inline int fpga_reset(const struct device *dev)
152{
153 const struct fpga_driver_api *api = DEVICE_API_GET(fpga, dev);
154
155 if (api->reset == NULL) {
156 return -ENOTSUP;
157 }
158
159 return api->reset(dev);
160}
161
172static inline int fpga_load(const struct device *dev, uint32_t *image_ptr,
173 uint32_t img_size)
174{
175 const struct fpga_driver_api *api = DEVICE_API_GET(fpga, dev);
176
177 if (api->load == NULL) {
178 return -ENOTSUP;
179 }
180
181 return api->load(dev, image_ptr, img_size);
182}
183
192static inline int fpga_on(const struct device *dev)
193{
194 const struct fpga_driver_api *api = DEVICE_API_GET(fpga, dev);
195
196 if (api->on == NULL) {
197 return -ENOTSUP;
198 }
199
200 return api->on(dev);
201}
202
203#define FPGA_GET_INFO_DEFAULT "n/a"
204
212static inline const char *fpga_get_info(const struct device *dev)
213{
214 const struct fpga_driver_api *api = DEVICE_API_GET(fpga, dev);
215
216 if (api->get_info == NULL) {
218 }
219
220 return api->get_info(dev);
221}
222
231static inline int fpga_off(const struct device *dev)
232{
233 const struct fpga_driver_api *api = DEVICE_API_GET(fpga, dev);
234
235 if (api->off == NULL) {
236 return -ENOTSUP;
237 }
238
239 return api->off(dev);
240}
241
243
244#ifdef __cplusplus
245}
246#endif
247
248#endif /* ZEPHYR_INCLUDE_DRIVERS_FPGA_H_ */
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1375
System error numbers.
enum FPGA_status(* fpga_api_get_status)(const struct device *dev)
Callback API to read FPGA status.
Definition fpga.h:55
const char *(* fpga_api_get_info)(const struct device *dev)
Callback API to return information about the FPGA.
Definition fpga.h:86
int(* fpga_api_reset)(const struct device *dev)
Callback API to reset the FPGA.
Definition fpga.h:68
int(* fpga_api_off)(const struct device *dev)
Callback API to turn the FPGA off.
Definition fpga.h:80
int(* fpga_api_load)(const struct device *dev, uint32_t *image_ptr, uint32_t img_size)
Callback API to load a bitstream and program the FPGA.
Definition fpga.h:61
int(* fpga_api_on)(const struct device *dev)
Callback API to turn the FPGA on.
Definition fpga.h:74
FPGA_status
Definition fpga.h:35
static enum FPGA_status fpga_get_status(const struct device *dev)
Read the status of FPGA.
Definition fpga.h:129
static int fpga_load(const struct device *dev, uint32_t *image_ptr, uint32_t img_size)
Load the bitstream and program the FPGA.
Definition fpga.h:172
static int fpga_off(const struct device *dev)
Turns off the FPGA.
Definition fpga.h:231
#define FPGA_GET_INFO_DEFAULT
Definition fpga.h:203
static const char * fpga_get_info(const struct device *dev)
Returns information about the FPGA.
Definition fpga.h:212
static int fpga_on(const struct device *dev)
Turns on the FPGA.
Definition fpga.h:192
static int fpga_reset(const struct device *dev)
Reset the FPGA.
Definition fpga.h:151
@ FPGA_STATUS_INACTIVE
Definition fpga.h:39
@ FPGA_STATUS_ACTIVE
Definition fpga.h:43
#define ENOTSUP
Unsupported value.
Definition errno.h:114
#define NULL
Definition iar_missing_defs.h:20
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
<span class="mlabel">Driver Operations</span> FPGA driver operations
Definition fpga.h:91
fpga_api_on on
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition fpga.h:107
fpga_api_load load
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition fpga.h:103
fpga_api_off off
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition fpga.h:111
fpga_api_get_info get_info
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition fpga.h:115
fpga_api_reset reset
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition fpga.h:99
fpga_api_get_status get_status
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition fpga.h:95
Misc utilities.