libpynq (release 5EWC0-2023 version 0.2.2 of 2023-09-24 22:22)
Loading...
Searching...
No Matches
util.c
Go to the documentation of this file.
1/*
2Copyright (c) 2023 Eindhoven University of Technology
3
4Permission is hereby granted, free of charge, to any person obtaining a copy
5of this software and associated documentation files (the "Software"), to deal
6in the Software without restriction, including without limitation the rights
7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in all
12copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20SOFTWARE.
21*/
22#include <libpynq.h>
23#include <unistd.h>
24
25typedef struct {
26 char *name;
28 uint8_t channel;
29 char *level;
31
32void sleep_msec(int msec) {
33 if (msec > 0)
34 usleep(msec * 1000);
35}
36
37void mapping_info(void) {
38 const char *const dir[2] = {"Input", "Output"};
39 printf("Pin\tName\tI/O\tLevel\tChannel\tCh_Name\t\tState\n");
40 for (int i = 0; i < SWB_NUM_PINS; i++) {
41 pin_state_t pin_array = {
42 0,
43 };
44 pin_array.name = pin_names[i];
45 pin_array.state = gpio_get_direction(i);
47 pin_array.level = "high";
48 } else if (gpio_get_level(i) == GPIO_LEVEL_LOW) {
49 pin_array.level = "low";
50 } else {
51 pin_array.level = "undef";
52 }
53 // get the index of the channel the pin is mapped to, 0 for none
54 pin_array.channel = switchbox_get_pin(i);
55
56 printf("%i\t%s\t%s\t%s\t%u\t", i, pin_array.name, dir[pin_array.state],
57 pin_array.level, pin_array.channel);
58
59 printf("%s\t", switchbox_names[pin_array.channel]);
60 if (pin_array.channel != SWB_GPIO && pin_array.state != GPIO_DIR_INPUT) {
61 printf("Invalid\n");
62 } else {
63 printf("Valid\n");
64 }
65 }
66}
gpio_direction_t gpio_get_direction(const pin_t pin)
Returns the direction the set pin is initialized in.
Definition gpio.c:95
gpio_direction_t
Definition gpio.h:81
gpio_level_t gpio_get_level(const pin_t pin)
Return the level of the GPIO pin.
Definition gpio.c:118
@ GPIO_DIR_INPUT
Definition gpio.h:83
@ GPIO_LEVEL_LOW
Definition gpio.h:93
@ GPIO_LEVEL_HIGH
Definition gpio.h:95
char *const pin_names[]
Pin names.
Definition pinmap.c:24
@ SWB_NUM_PINS
Definition pinmap.h:144
uint8_t switchbox_get_pin(const pin_t pin_number)
Sets the mode of a specified pin.
Definition switchbox.c:163
char *const switchbox_names[NUM_SWITCHBOX_NAMES]
Taken from scpi_names.h, lookup table for channels in the mapping_info function.
Definition switchbox.c:25
@ SWB_GPIO
Definition switchbox.h:63
void sleep_msec(int msec)
Wait for msec milliseconds.
Definition util.c:32
void mapping_info(void)
Displays a table to see where all pins have been mapped, what channels have been linked where and the...
Definition util.c:37
char * level
Definition util.c:29
char * name
Definition util.c:26
uint8_t channel
Definition util.c:28
gpio_direction_t state
Definition util.c:27