Zephyr API Documentation 4.0.0
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
7#ifndef ZEPHYR_INCLUDE_DRIVERS_FPGA_H_
8#define ZEPHYR_INCLUDE_DRIVERS_FPGA_H_
9
10#include <errno.h>
11
12#include <zephyr/types.h>
13#include <zephyr/sys/util.h>
14#include <zephyr/device.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
21 /* Inactive is when the FPGA cannot accept the bitstream
22 * and will not be programmed correctly
23 */
25 /* Active is when the FPGA can accept the bitstream and
26 * can be programmed correctly
27 */
29};
30
31typedef enum FPGA_status (*fpga_api_get_status)(const struct device *dev);
32typedef int (*fpga_api_load)(const struct device *dev, uint32_t *image_ptr,
33 uint32_t img_size);
34typedef int (*fpga_api_reset)(const struct device *dev);
35typedef int (*fpga_api_on)(const struct device *dev);
36typedef int (*fpga_api_off)(const struct device *dev);
37typedef const char *(*fpga_api_get_info)(const struct device *dev);
38
47
56static inline enum FPGA_status fpga_get_status(const struct device *dev)
57{
58 const struct fpga_driver_api *api =
59 (const struct fpga_driver_api *)dev->api;
60
61 if (api->get_status == NULL) {
62 /* assume it can never be reprogrammed if it
63 * doesn't support the get_status callback
64 */
66 }
67
68 return api->get_status(dev);
69}
70
79static inline int fpga_reset(const struct device *dev)
80{
81 const struct fpga_driver_api *api =
82 (const struct fpga_driver_api *)dev->api;
83
84 if (api->reset == NULL) {
85 return -ENOTSUP;
86 }
87
88 return api->reset(dev);
89}
90
101static inline int fpga_load(const struct device *dev, uint32_t *image_ptr,
102 uint32_t img_size)
103{
104 const struct fpga_driver_api *api =
105 (const struct fpga_driver_api *)dev->api;
106
107 if (api->load == NULL) {
108 return -ENOTSUP;
109 }
110
111 return api->load(dev, image_ptr, img_size);
112}
113
122static inline int fpga_on(const struct device *dev)
123{
124 const struct fpga_driver_api *api =
125 (const struct fpga_driver_api *)dev->api;
126
127 if (api->on == NULL) {
128 return -ENOTSUP;
129 }
130
131 return api->on(dev);
132}
133
134#define FPGA_GET_INFO_DEFAULT "n/a"
135
143static inline const char *fpga_get_info(const struct device *dev)
144{
145 const struct fpga_driver_api *api =
146 (const struct fpga_driver_api *)dev->api;
147
148 if (api->get_info == NULL) {
150 }
151
152 return api->get_info(dev);
153}
154
163static inline int fpga_off(const struct device *dev)
164{
165 const struct fpga_driver_api *api =
166 (const struct fpga_driver_api *)dev->api;
167
168 if (api->off == NULL) {
169 return -ENOTSUP;
170 }
171
172 return api->off(dev);
173}
174
175#ifdef __cplusplus
176}
177#endif
178
179#endif /* ZEPHYR_INCLUDE_DRIVERS_FPGA_H_ */
System error numbers.
enum FPGA_status(* fpga_api_get_status)(const struct device *dev)
Definition fpga.h:31
FPGA_status
Definition fpga.h:20
@ FPGA_STATUS_INACTIVE
Definition fpga.h:24
@ FPGA_STATUS_ACTIVE
Definition fpga.h:28
static enum FPGA_status fpga_get_status(const struct device *dev)
Read the status of FPGA.
Definition fpga.h:56
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:101
const char *(* fpga_api_get_info)(const struct device *dev)
Definition fpga.h:37
int(* fpga_api_reset)(const struct device *dev)
Definition fpga.h:34
int(* fpga_api_off)(const struct device *dev)
Definition fpga.h:36
int(* fpga_api_load)(const struct device *dev, uint32_t *image_ptr, uint32_t img_size)
Definition fpga.h:32
static int fpga_off(const struct device *dev)
Turns off the FPGA.
Definition fpga.h:163
#define FPGA_GET_INFO_DEFAULT
Definition fpga.h:134
static const char * fpga_get_info(const struct device *dev)
Returns information about the FPGA.
Definition fpga.h:143
static int fpga_on(const struct device *dev)
Turns on the FPGA.
Definition fpga.h:122
static int fpga_reset(const struct device *dev)
Reset the FPGA.
Definition fpga.h:79
int(* fpga_api_on)(const struct device *dev)
Definition fpga.h:35
#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:412
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:418
Definition fpga.h:39
fpga_api_on on
Definition fpga.h:43
fpga_api_load load
Definition fpga.h:42
fpga_api_off off
Definition fpga.h:44
fpga_api_get_info get_info
Definition fpga.h:45
fpga_api_reset reset
Definition fpga.h:41
fpga_api_get_status get_status
Definition fpga.h:40
Misc utilities.