Zephyr Project API 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
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
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
46typedef enum FPGA_status (*fpga_api_get_status)(const struct device *dev);
47typedef int (*fpga_api_load)(const struct device *dev, uint32_t *image_ptr,
48 uint32_t img_size);
49typedef int (*fpga_api_reset)(const struct device *dev);
50typedef int (*fpga_api_on)(const struct device *dev);
51typedef int (*fpga_api_off)(const struct device *dev);
52typedef const char *(*fpga_api_get_info)(const struct device *dev);
53
62
71static inline enum FPGA_status fpga_get_status(const struct device *dev)
72{
73 const struct fpga_driver_api *api =
74 (const struct fpga_driver_api *)dev->api;
75
76 if (api->get_status == NULL) {
77 /* assume it can never be reprogrammed if it
78 * doesn't support the get_status callback
79 */
81 }
82
83 return api->get_status(dev);
84}
85
94static inline int fpga_reset(const struct device *dev)
95{
96 const struct fpga_driver_api *api =
97 (const struct fpga_driver_api *)dev->api;
98
99 if (api->reset == NULL) {
100 return -ENOTSUP;
101 }
102
103 return api->reset(dev);
104}
105
116static inline int fpga_load(const struct device *dev, uint32_t *image_ptr,
117 uint32_t img_size)
118{
119 const struct fpga_driver_api *api =
120 (const struct fpga_driver_api *)dev->api;
121
122 if (api->load == NULL) {
123 return -ENOTSUP;
124 }
125
126 return api->load(dev, image_ptr, img_size);
127}
128
137static inline int fpga_on(const struct device *dev)
138{
139 const struct fpga_driver_api *api =
140 (const struct fpga_driver_api *)dev->api;
141
142 if (api->on == NULL) {
143 return -ENOTSUP;
144 }
145
146 return api->on(dev);
147}
148
149#define FPGA_GET_INFO_DEFAULT "n/a"
150
158static inline const char *fpga_get_info(const struct device *dev)
159{
160 const struct fpga_driver_api *api =
161 (const struct fpga_driver_api *)dev->api;
162
163 if (api->get_info == NULL) {
165 }
166
167 return api->get_info(dev);
168}
169
178static inline int fpga_off(const struct device *dev)
179{
180 const struct fpga_driver_api *api =
181 (const struct fpga_driver_api *)dev->api;
182
183 if (api->off == NULL) {
184 return -ENOTSUP;
185 }
186
187 return api->off(dev);
188}
189
192#ifdef __cplusplus
193}
194#endif
195
196#endif /* ZEPHYR_INCLUDE_DRIVERS_FPGA_H_ */
System error numbers.
enum FPGA_status(* fpga_api_get_status)(const struct device *dev)
Definition fpga.h:46
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:71
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:116
const char *(* fpga_api_get_info)(const struct device *dev)
Definition fpga.h:52
int(* fpga_api_reset)(const struct device *dev)
Definition fpga.h:49
int(* fpga_api_off)(const struct device *dev)
Definition fpga.h:51
int(* fpga_api_load)(const struct device *dev, uint32_t *image_ptr, uint32_t img_size)
Definition fpga.h:47
static int fpga_off(const struct device *dev)
Turns off the FPGA.
Definition fpga.h:178
#define FPGA_GET_INFO_DEFAULT
Definition fpga.h:149
static const char * fpga_get_info(const struct device *dev)
Returns information about the FPGA.
Definition fpga.h:158
static int fpga_on(const struct device *dev)
Turns on the FPGA.
Definition fpga.h:137
static int fpga_reset(const struct device *dev)
Reset the FPGA.
Definition fpga.h:94
int(* fpga_api_on)(const struct device *dev)
Definition fpga.h:50
@ 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:510
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:516
Definition fpga.h:54
fpga_api_on on
Definition fpga.h:58
fpga_api_load load
Definition fpga.h:57
fpga_api_off off
Definition fpga.h:59
fpga_api_get_info get_info
Definition fpga.h:60
fpga_api_reset reset
Definition fpga.h:56
fpga_api_get_status get_status
Definition fpga.h:55
Misc utilities.