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
42
47
52typedef enum FPGA_status (*fpga_api_get_status)(const struct device *dev);
53
58typedef int (*fpga_api_load)(const struct device *dev, uint32_t *image_ptr,
59 uint32_t img_size);
60
65typedef int (*fpga_api_reset)(const struct device *dev);
66
71typedef int (*fpga_api_on)(const struct device *dev);
72
77typedef int (*fpga_api_off)(const struct device *dev);
78
83typedef const char *(*fpga_api_get_info)(const struct device *dev);
84
114
117
126static inline enum FPGA_status fpga_get_status(const struct device *dev)
127{
128 const struct fpga_driver_api *api = DEVICE_API_GET(fpga, dev);
129
130 if (api->get_status == NULL) {
131 /* assume it can never be reprogrammed if it
132 * doesn't support the get_status callback
133 */
135 }
136
137 return api->get_status(dev);
138}
139
148static inline int fpga_reset(const struct device *dev)
149{
150 const struct fpga_driver_api *api = DEVICE_API_GET(fpga, dev);
151
152 if (api->reset == NULL) {
153 return -ENOTSUP;
154 }
155
156 return api->reset(dev);
157}
158
169static inline int fpga_load(const struct device *dev, uint32_t *image_ptr,
170 uint32_t img_size)
171{
172 const struct fpga_driver_api *api = DEVICE_API_GET(fpga, dev);
173
174 if (api->load == NULL) {
175 return -ENOTSUP;
176 }
177
178 return api->load(dev, image_ptr, img_size);
179}
180
189static inline int fpga_on(const struct device *dev)
190{
191 const struct fpga_driver_api *api = DEVICE_API_GET(fpga, dev);
192
193 if (api->on == NULL) {
194 return -ENOTSUP;
195 }
196
197 return api->on(dev);
198}
199
201#define FPGA_GET_INFO_DEFAULT "n/a"
202
210static inline const char *fpga_get_info(const struct device *dev)
211{
212 const struct fpga_driver_api *api = DEVICE_API_GET(fpga, dev);
213
214 if (api->get_info == NULL) {
216 }
217
218 return api->get_info(dev);
219}
220
229static inline int fpga_off(const struct device *dev)
230{
231 const struct fpga_driver_api *api = DEVICE_API_GET(fpga, dev);
232
233 if (api->off == NULL) {
234 return -ENOTSUP;
235 }
236
237 return api->off(dev);
238}
239
241
242#ifdef __cplusplus
243}
244#endif
245
246#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:1425
System error numbers.
enum FPGA_status(* fpga_api_get_status)(const struct device *dev)
Callback API to read FPGA status.
Definition fpga.h:52
const char *(* fpga_api_get_info)(const struct device *dev)
Callback API to return information about the FPGA.
Definition fpga.h:83
int(* fpga_api_reset)(const struct device *dev)
Callback API to reset the FPGA.
Definition fpga.h:65
int(* fpga_api_off)(const struct device *dev)
Callback API to turn the FPGA off.
Definition fpga.h:77
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:58
int(* fpga_api_on)(const struct device *dev)
Callback API to turn the FPGA on.
Definition fpga.h:71
FPGA_status
FPGA programming status.
Definition fpga.h:36
static enum FPGA_status fpga_get_status(const struct device *dev)
Read the status of FPGA.
Definition fpga.h:126
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:169
static int fpga_off(const struct device *dev)
Turns off the FPGA.
Definition fpga.h:229
#define FPGA_GET_INFO_DEFAULT
Default string returned by fpga_get_info() when no info is available.
Definition fpga.h:201
static const char * fpga_get_info(const struct device *dev)
Returns information about the FPGA.
Definition fpga.h:210
static int fpga_on(const struct device *dev)
Turns on the FPGA.
Definition fpga.h:189
static int fpga_reset(const struct device *dev)
Reset the FPGA.
Definition fpga.h:148
@ FPGA_STATUS_INACTIVE
FPGA cannot accept a bitstream and will not be programmed correctly.
Definition fpga.h:38
@ FPGA_STATUS_ACTIVE
FPGA can accept a bitstream and can be programmed correctly.
Definition fpga.h:40
#define ENOTSUP
Unsupported value.
Definition errno.h:114
__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:88
fpga_api_on on
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition fpga.h:104
fpga_api_load load
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition fpga.h:100
fpga_api_off off
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition fpga.h:108
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:112
fpga_api_reset reset
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition fpga.h:96
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:92
Misc utilities.