Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
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 <zephyr/types.h>
11#include <sys/util.h>
12#include <device.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
19 /* Inactive is when the FPGA cannot accept the bitstream
20 * and will not be programmed correctly
21 */
23 /* Active is when the FPGA can accept the bitstream and
24 * can be programmed correctly
25 */
27};
28
29typedef enum FPGA_status (*fpga_api_get_status)(const struct device *dev);
30typedef int (*fpga_api_load)(const struct device *dev, uint32_t *image_ptr,
31 uint32_t img_size);
32typedef int (*fpga_api_reset)(const struct device *dev);
33typedef int (*fpga_api_on)(const struct device *dev);
34typedef int (*fpga_api_off)(const struct device *dev);
35typedef const char *(*fpga_api_get_info)(const struct device *dev);
36
37__subsystem struct fpga_driver_api {
44};
45
54static inline enum FPGA_status fpga_get_status(const struct device *dev)
55{
56 const struct fpga_driver_api *api =
57 (const struct fpga_driver_api *)dev->api;
58
59 return api->get_status(dev);
60}
61
70static inline int fpga_reset(const struct device *dev)
71{
72 const struct fpga_driver_api *api =
73 (const struct fpga_driver_api *)dev->api;
74
75 return api->reset(dev);
76}
77
88static inline int fpga_load(const struct device *dev, uint32_t *image_ptr,
89 uint32_t img_size)
90{
91 const struct fpga_driver_api *api =
92 (const struct fpga_driver_api *)dev->api;
93
94 return api->load(dev, image_ptr, img_size);
95}
96
105static inline int fpga_on(const struct device *dev)
106{
107 const struct fpga_driver_api *api =
108 (const struct fpga_driver_api *)dev->api;
109
110 if (api->on == NULL) {
111 return -ENOTSUP;
112 }
113
114 return api->on(dev);
115}
116
124static inline const char *fpga_get_info(const struct device *dev)
125{
126 const struct fpga_driver_api *api =
127 (const struct fpga_driver_api *)dev->api;
128
129 return api->get_info(dev);
130}
131
140static inline int fpga_off(const struct device *dev)
141{
142 const struct fpga_driver_api *api =
143 (const struct fpga_driver_api *)dev->api;
144
145 if (api->off == NULL) {
146 return -ENOTSUP;
147 }
148
149 return api->off(dev);
150}
151
152#ifdef __cplusplus
153}
154#endif
155
156#endif /* ZEPHYR_INCLUDE_DRIVERS_FPGA_H_ */
enum FPGA_status(* fpga_api_get_status)(const struct device *dev)
Definition: fpga.h:29
FPGA_status
Definition: fpga.h:18
@ FPGA_STATUS_INACTIVE
Definition: fpga.h:22
@ FPGA_STATUS_ACTIVE
Definition: fpga.h:26
static enum FPGA_status fpga_get_status(const struct device *dev)
Read the status of FPGA.
Definition: fpga.h:54
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:88
const char *(* fpga_api_get_info)(const struct device *dev)
Definition: fpga.h:35
int(* fpga_api_reset)(const struct device *dev)
Definition: fpga.h:32
int(* fpga_api_off)(const struct device *dev)
Definition: fpga.h:34
int(* fpga_api_load)(const struct device *dev, uint32_t *image_ptr, uint32_t img_size)
Definition: fpga.h:30
static int fpga_off(const struct device *dev)
Turns off the FPGA.
Definition: fpga.h:140
static const char * fpga_get_info(const struct device *dev)
Returns information about the FPGA.
Definition: fpga.h:124
static int fpga_on(const struct device *dev)
Turns on the FPGA.
Definition: fpga.h:105
static int fpga_reset(const struct device *dev)
Reset the FPGA.
Definition: fpga.h:70
int(* fpga_api_on)(const struct device *dev)
Definition: fpga.h:33
#define ENOTSUP
Definition: errno.h:115
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
Runtime device structure (in ROM) per driver instance.
Definition: device.h:367
const void * api
Definition: device.h:373
Definition: fpga.h:37
fpga_api_on on
Definition: fpga.h:41
fpga_api_load load
Definition: fpga.h:40
fpga_api_off off
Definition: fpga.h:42
fpga_api_get_info get_info
Definition: fpga.h:43
fpga_api_reset reset
Definition: fpga.h:39
fpga_api_get_status get_status
Definition: fpga.h:38
Misc utilities.