chore: migrate src to solutions
This commit is contained in:
167 files changed
+17
-17
No files matched your search
@@ -0,0 +1,54 @@
|
||||
EXE=gpio
|
||||
SRCS=$(wildcard *.c)
|
||||
|
||||
ifeq ($(target),)
|
||||
target=nano
|
||||
endif
|
||||
|
||||
CFLAGS=-Wall -Wextra -g -c -O1 -MD -std=gnu11 -D_GNU_SOURCE
|
||||
|
||||
ifeq ($(target),nano)
|
||||
TOOLCHAIN_PATH=/buildroot/output/host/usr/bin/
|
||||
TOOLCHAIN=$(TOOLCHAIN_PATH)aarch64-linux-
|
||||
CFLAGS+=-mcpu=cortex-a53 -funwind-tables
|
||||
##CFLAGS+=-O2 -fno-omit-frame-pointer
|
||||
OBJDIR=.obj/nano
|
||||
EXEC=$(EXE)
|
||||
endif
|
||||
|
||||
ifeq ($(target),host)
|
||||
EXEC=$(EXE)_h
|
||||
endif
|
||||
|
||||
CC=$(TOOLCHAIN)gcc
|
||||
LD=$(TOOLCHAIN)gcc
|
||||
AR=$(TOOLCHAIN)ar
|
||||
STRIP=$(TOOLCHAIN)strip
|
||||
OBJDUMP=$(TOOLCHAIN)objdump
|
||||
|
||||
OBJDIR=.obj/$(target)
|
||||
OBJS= $(addprefix $(OBJDIR)/, $(SRCS:.c=.o))
|
||||
|
||||
$(OBJDIR)/%o: %c
|
||||
$(CC) $(CFLAGS) $< -o $@
|
||||
|
||||
all: $(OBJDIR)/ $(EXEC)
|
||||
|
||||
$(EXEC): $(OBJS) $(LINKER_SCRIPT)
|
||||
$(LD) $(OBJS) $(LDFLAGS) -o $@
|
||||
|
||||
$(OBJDIR)/:
|
||||
mkdir -p $(OBJDIR)
|
||||
|
||||
clean:
|
||||
rm -Rf $(OBJDIR) $(EXEC) $(EXEC)_s *~ t.txt
|
||||
|
||||
clean_all: clean
|
||||
rm -Rf .obj $(EXE) $(EXE)_s $(EXE)_a $(EXE)_a_s $(EXE)_h $(EXE)_h_s
|
||||
|
||||
dump: all
|
||||
$(OBJDUMP) -dS $(EXEC) > t.txt
|
||||
|
||||
-include $(OBJS:.o=.d)
|
||||
|
||||
.PHONY: all clean clean_all dump
|
||||
@@ -0,0 +1,87 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
#include <sched.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define GPIO_EXPORT "/sys/class/gpio/export"
|
||||
#define GPIO_UNEXPORT "/sys/class/gpio/unexport"
|
||||
#define GPIO_GPIOG11 "/sys/class/gpio/gpio203"
|
||||
#define GPIOG11 "203"
|
||||
|
||||
static int open_gpio()
|
||||
{
|
||||
// unexport pin out of sysfs (reinitialization)
|
||||
int f = open (GPIO_UNEXPORT, O_WRONLY);
|
||||
write (f, GPIOG11, strlen(GPIOG11));
|
||||
close (f);
|
||||
|
||||
// export pin to sysfs
|
||||
f = open (GPIO_EXPORT, O_WRONLY);
|
||||
write (f, GPIOG11, strlen(GPIOG11));
|
||||
close (f);
|
||||
|
||||
// config pin
|
||||
f = open (GPIO_GPIOG11 "/direction", O_WRONLY);
|
||||
write (f, "out", 3);
|
||||
close (f);
|
||||
|
||||
// open gpio value attribute
|
||||
f = open (GPIO_GPIOG11 "/value", O_RDWR);
|
||||
return f;
|
||||
}
|
||||
|
||||
/**
|
||||
* main program...
|
||||
*/
|
||||
int main()
|
||||
{
|
||||
cpu_set_t my_set;
|
||||
CPU_ZERO(&my_set);
|
||||
CPU_SET(2, &my_set);
|
||||
sched_setaffinity(0, sizeof(cpu_set_t), &my_set);
|
||||
|
||||
int gpio = open_gpio();
|
||||
bool on = false;
|
||||
struct timespec start_time;
|
||||
struct timespec stop_time;
|
||||
clock_gettime (CLOCK_MONOTONIC, &start_time); // setup...
|
||||
|
||||
|
||||
// --> measurement with internal timers
|
||||
clock_gettime (CLOCK_MONOTONIC, &start_time);
|
||||
for (int i=0; i<1000; i++) {
|
||||
if (on) {
|
||||
pwrite (gpio, "1", sizeof("1"), 0);
|
||||
} else {
|
||||
pwrite (gpio, "0", sizeof("0"), 0);
|
||||
}
|
||||
on = !on;
|
||||
}
|
||||
clock_gettime (CLOCK_MONOTONIC, &stop_time);
|
||||
long long t = (stop_time.tv_nsec - start_time.tv_nsec) +
|
||||
(stop_time.tv_sec - start_time.tv_sec) * 1000000000;
|
||||
printf ("pwrite (gpio, \"1\", sizeof(\"1\"), 0) -> %lld ns\n", t/1000);
|
||||
|
||||
|
||||
// --> measurement with oscilloscope
|
||||
while(true) {
|
||||
if (on) {
|
||||
pwrite (gpio, "1", sizeof("1"), 0);
|
||||
} else {
|
||||
pwrite (gpio, "0", sizeof("0"), 0);
|
||||
}
|
||||
on = !on;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user