Zephyr API Documentation 4.4.0-rc1
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 =
132 (const struct fpga_driver_api *)dev->api;
133
134 if (api->get_status == NULL) {
135 /* assume it can never be reprogrammed if it
136 * doesn't support the get_status callback
137 */
139 }
140
141 return api->get_status(dev);
142}
143
152static inline int fpga_reset(const struct device *dev)
153{
154 const struct fpga_driver_api *api =
155 (const struct fpga_driver_api *)dev->api;
156
157 if (api->reset == NULL) {
158 return -ENOTSUP;
159 }
160
161 return api->reset(dev);
162}
163
174static inline int fpga_load(const struct device *dev, uint32_t *image_ptr,
175 uint32_t img_size)
176{
177 const struct fpga_driver_api *api =
178 (const struct fpga_driver_api *)dev->api;
179
180 if (api->load == NULL) {
181 return -ENOTSUP;
182 }
183
184 return api->load(dev, image_ptr, img_size);
185}
186
195static inline int fpga_on(const struct device *dev)
196{
197 const struct fpga_driver_api *api =
198 (const struct fpga_driver_api *)dev->api;
199
200 if (api->on == NULL) {
201 return -ENOTSUP;
202 }
203
204 return api->on(dev);
205}
206
207#define FPGA_GET_INFO_DEFAULT "n/a"
208
216static inline const char *fpga_get_info(const struct device *dev)
217{
218 const struct fpga_driver_api *api =
219 (const struct fpga_driver_api *)dev->api;
220
221 if (api->get_info == NULL) {
223 }
224
225 return api->get_info(dev);
226}
227
236static inline int fpga_off(const struct device *dev)
237{
238 const struct fpga_driver_api *api =
239 (const struct fpga_driver_api *)dev->api;
240
241 if (api->off == NULL) {
242 return -ENOTSUP;
243 }
244
245 return api->off(dev);
246}
247
249
250#ifdef __cplusplus
251}
252#endif
253
254#endif /* ZEPHYR_INCLUDE_DRIVERS_FPGA_H_ */
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:174
static int fpga_off(const struct device *dev)
Turns off the FPGA.
Definition fpga.h:236
#define FPGA_GET_INFO_DEFAULT
Definition fpga.h:207
static const char * fpga_get_info(const struct device *dev)
Returns information about the FPGA.
Definition fpga.h:216
static int fpga_on(const struct device *dev)
Turns on the FPGA.
Definition fpga.h:195
static int fpga_reset(const struct device *dev)
Reset the FPGA.
Definition fpga.h:152
@ 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
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:519
<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.