libpynq (release 5EWC0-2023 version 0.1.0 of 2023-08-14 14:01)
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;
27 char *state;
28 uint8_t channel;
29 char *level;
30} pin_t;
31
32void sleep_msec(int msec) {
33 if (msec > 0)
34 usleep(msec * 1000);
35}
36
37void mapping_info(void) {
38 const uint8_t NR_PINS = 64;
39 pin_t pin_array[NR_PINS];
40 printf("Pin\tName\tI/O\tLevel\tChannel\tCh_Name\n");
41 for (int i = 0; i < NR_PINS; i++) {
42 pin_array[i].name = pin_names[i];
43 pin_array[i].state = gpio_get_direction(i) ? "o" : "i";
45 pin_array[i].level = "high";
46 } else if (gpio_get_level(i) == GPIO_LEVEL_LOW) {
47 pin_array[i].level = "low";
48 } else {
49 pin_array[i].level = "undef";
50 }
51 // get the index of the channel the pin is mapped to, 0 for none
52 pin_array[i].channel = switchbox_get_pin(i);
53
54 printf("%i\t%s\t%s\t%s\t%u\t", i, pin_array[i].name, pin_array[i].state,
55 pin_array[i].level, pin_array[i].channel);
56
57 printf("%s\n", switchbox_names[pin_array[i].channel]);
58 }
59}
gpio_direction_t gpio_get_direction(const gpio_t pin)
Returns the direction the set pin is initialized in.
Definition gpio.c:89
gpio_level_t gpio_get_level(const gpio_t pin)
Return the level of the GPIO pin.
Definition gpio.c:118
@ GPIO_LEVEL_LOW
Definition gpio.h:91
@ GPIO_LEVEL_HIGH
Definition gpio.h:93
char *const pin_names[]
Pin names.
Definition pinmap.c:24
uint8_t switchbox_get_pin(const int32_t pin_number)
Sets the mode of a specified pin.
Definition switchbox.c:149
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
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
Definition util.c:25
char * level
Definition util.c:29
char * state
Definition util.c:27
uint8_t channel
Definition util.c:28
char * name
Definition util.c:26