Zephyr API Documentation 4.2.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
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
27
29 /* Inactive is when the FPGA cannot accept the bitstream
30 * and will not be programmed correctly
31 */
33 /* Active is when the FPGA can accept the bitstream and
34 * can be programmed correctly
35 */
37};
38
39typedef enum FPGA_status (*fpga_api_get_status)(const struct device *dev);
40typedef int (*fpga_api_load)(const struct device *dev, uint32_t *image_ptr,
41 uint32_t img_size);
42typedef int (*fpga_api_reset)(const struct device *dev);
43typedef int (*fpga_api_on)(const struct device *dev);
44typedef int (*fpga_api_off)(const struct device *dev);
45typedef const char *(*fpga_api_get_info)(const struct device *dev);
46
55
64static inline enum FPGA_status fpga_get_status(const struct device *dev)
65{
66 const struct fpga_driver_api *api =
67 (const struct fpga_driver_api *)dev->api;
68
69 if (api->get_status == NULL) {
70 /* assume it can never be reprogrammed if it
71 * doesn't support the get_status callback
72 */
74 }
75
76 return api->get_status(dev);
77}
78
87static inline int fpga_reset(const struct device *dev)
88{
89 const struct fpga_driver_api *api =
90 (const struct fpga_driver_api *)dev->api;
91
92 if (api->reset == NULL) {
93 return -ENOTSUP;
94 }
95
96 return api->reset(dev);
97}
98
109static inline int fpga_load(const struct device *dev, uint32_t *image_ptr,
110 uint32_t img_size)
111{
112 const struct fpga_driver_api *api =
113 (const struct fpga_driver_api *)dev->api;
114
115 if (api->load == NULL) {
116 return -ENOTSUP;
117 }
118
119 return api->load(dev, image_ptr, img_size);
120}
121
130static inline int fpga_on(const struct device *dev)
131{
132 const struct fpga_driver_api *api =
133 (const struct fpga_driver_api *)dev->api;
134
135 if (api->on == NULL) {
136 return -ENOTSUP;
137 }
138
139 return api->on(dev);
140}
141
142#define FPGA_GET_INFO_DEFAULT "n/a"
143
151static inline const char *fpga_get_info(const struct device *dev)
152{
153 const struct fpga_driver_api *api =
154 (const struct fpga_driver_api *)dev->api;
155
156 if (api->get_info == NULL) {
158 }
159
160 return api->get_info(dev);
161}
162
171static inline int fpga_off(const struct device *dev)
172{
173 const struct fpga_driver_api *api =
174 (const struct fpga_driver_api *)dev->api;
175
176 if (api->off == NULL) {
177 return -ENOTSUP;
178 }
179
180 return api->off(dev);
181}
182
184
185#ifdef __cplusplus
186}
187#endif
188
189#endif /* ZEPHYR_INCLUDE_DRIVERS_FPGA_H_ */
System error numbers.
enum FPGA_status(* fpga_api_get_status)(const struct device *dev)
Definition fpga.h:39
FPGA_status
Definition fpga.h:28
static enum FPGA_status fpga_get_status(const struct device *dev)
Read the status of FPGA.
Definition fpga.h:64
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:109
const char *(* fpga_api_get_info)(const struct device *dev)
Definition fpga.h:45
int(* fpga_api_reset)(const struct device *dev)
Definition fpga.h:42
int(* fpga_api_off)(const struct device *dev)
Definition fpga.h:44
int(* fpga_api_load)(const struct device *dev, uint32_t *image_ptr, uint32_t img_size)
Definition fpga.h:40
static int fpga_off(const struct device *dev)
Turns off the FPGA.
Definition fpga.h:171
#define FPGA_GET_INFO_DEFAULT
Definition fpga.h:142
static const char * fpga_get_info(const struct device *dev)
Returns information about the FPGA.
Definition fpga.h:151
static int fpga_on(const struct device *dev)
Turns on the FPGA.
Definition fpga.h:130
static int fpga_reset(const struct device *dev)
Reset the FPGA.
Definition fpga.h:87
int(* fpga_api_on)(const struct device *dev)
Definition fpga.h:43
@ FPGA_STATUS_INACTIVE
Definition fpga.h:32
@ FPGA_STATUS_ACTIVE
Definition fpga.h:36
#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:510
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:516
Definition fpga.h:47
fpga_api_on on
Definition fpga.h:51
fpga_api_load load
Definition fpga.h:50
fpga_api_off off
Definition fpga.h:52
fpga_api_get_info get_info
Definition fpga.h:53
fpga_api_reset reset
Definition fpga.h:49
fpga_api_get_status get_status
Definition fpga.h:48
Misc utilities.