Skip to content
Snippets Groups Projects
Commit 57cf372a authored by bbartels's avatar bbartels
Browse files

quad: add unix virtual quad stubs

parent 3d3bd145
No related branches found
No related tags found
No related merge requests found
Showing
with 387 additions and 2 deletions
...@@ -5,3 +5,4 @@ lib/ ...@@ -5,3 +5,4 @@ lib/
lib-zybo/ lib-zybo/
TAGS TAGS
out/ out/
bin/
\ No newline at end of file
INCDIR = inc INCDIR = inc
LIBDIR = lib LIBDIR = lib
OUTDIR = out OUTDIR = out
EXEDIR = bin
WS = $(CURDIR)/xsdk_workspace WS = $(CURDIR)/xsdk_workspace
BOOT = $(OUTDIR)/BOOT.bin BOOT = $(OUTDIR)/BOOT.bin
.PHONY: all libs zybo boot test clean deep-clean .PHONY: all libs zybo boot test clean deep-clean
all: libs all: libs bins
libs: libs:
$(MAKE) -C src/test $(MAKE) -C src/test
...@@ -16,6 +17,9 @@ libs: ...@@ -16,6 +17,9 @@ libs:
$(MAKE) -C src/commands $(MAKE) -C src/commands
$(MAKE) -C src/quad_app $(MAKE) -C src/quad_app
bins:
$(MAKE) -C src/virt_quad
zybo: zybo:
bash scripts/build_zybo.sh bash scripts/build_zybo.sh
...@@ -27,7 +31,7 @@ test: ...@@ -27,7 +31,7 @@ test:
$(MAKE) -C src/quad_app test $(MAKE) -C src/quad_app test
clean: clean:
rm -rf $(INCDIR) $(LIBDIR) $(OUTDIR) rm -rf $(INCDIR) $(LIBDIR) $(OUTDIR) $(EXEDIR)
deep-clean: deep-clean:
make clean make clean
......
GCC = gcc
INCDIR = $(TOP)/inc
OBJDIR = obj
EXEDIR = $(TOP)/bin
LIBDIR = $(TOP)/lib
SOURCES = $(wildcard *.c)
HEADERS = $(wildcard *.h)
INCLUDES = $(addprefix $(INCDIR)/, $(HEADERS))
OBJECTS = $(patsubst %.c, $(OBJDIR)/%.o, $(SOURCES))
TARGET = $(EXEDIR)/$(NAME)
.PHONY: default run clean
################
## User Targets
################
default: $(TARGET)
run: $(TARGET)
$(EXEDIR)/$(NAME)
clean:
rm -rf $(TARGET) $(OBJDIR)
####################
## Internal Targets
####################
$(TARGET): $(OBJECTS) | $(EXEDIR)
$(GCC) -g -o $(TARGET) $^ -I$(INCDIR) -L$(LIBDIR) $(REQLIBS)
$(OBJDIR)/%.o : %.c | $(OBJDIR) $(INCDIR)
$(GCC) -c -g -o $@ $< -I$(INCDIR)
$(OBJDIR):
mkdir $(OBJDIR)
$(EXEDIR):
mkdir $(EXEDIR)
TOP=../..
NAME = virt_quad
REQLIBS = -lquad_app -lcomputation_graph -lm -lcommands
include $(TOP)/executable.mk
#include "hw_impl_unix.h"
struct UARTDriver create_unix_uart() {
struct UARTDriver uart;
uart.state = NULL;
uart.reset = unix_uart_reset;
uart.write = unix_uart_write;
uart.read = unix_uart_read;
return uart;
}
struct PWMOutputDriver create_unix_pwm_outputs() {
struct PWMOutputDriver pwm_outputs;
pwm_outputs.state = NULL;
pwm_outputs.reset = unix_pwm_output_reset;
pwm_outputs.write = unix_pwm_output_write;
return pwm_outputs;
}
struct PWMInputDriver create_unix_pwm_inputs() {
struct PWMInputDriver pwm_inputs;
pwm_inputs.state = NULL;
pwm_inputs.reset = unix_pwm_input_reset;
pwm_inputs.read = unix_pwm_input_read;
return pwm_inputs;
}
struct I2CDriver create_unix_i2c() {
struct I2CDriver i2c;
i2c.state = NULL;
i2c.reset = unix_i2c_reset;
i2c.write = unix_i2c_write;
i2c.read = unix_i2c_read;
return i2c;
}
struct TimerDriver create_unix_global_timer() {
struct TimerDriver global_timer;
global_timer.state = NULL;
global_timer.reset = unix_global_timer_reset;
global_timer.restart = unix_global_timer_restart;
global_timer.read = unix_global_timer_read;
return global_timer;
}
struct TimerDriver create_unix_axi_timer() {
struct TimerDriver axi_timer;
axi_timer.state = NULL;
axi_timer.reset = unix_axi_timer_reset;
axi_timer.restart = unix_axi_timer_restart;
axi_timer.read = unix_axi_timer_read;
return axi_timer;
}
struct LEDDriver create_unix_mio7_led() {
struct LEDDriver mio7_led;
mio7_led.state = NULL;
mio7_led.reset = unix_mio7_led_reset;
mio7_led.turn_on = unix_mio7_led_turn_on;
mio7_led.turn_off = unix_mio7_led_turn_off;
return mio7_led;
}
struct SystemDriver create_unix_system() {
struct SystemDriver sys;
sys.state = NULL;
sys.reset = unix_system_reset;
sys.sleep = unix_system_sleep;
return sys;
}
#ifndef HW_IMPL_UNIX
#define HW_IMPL_UNIX
#include "hw_iface.h"
#include "type_def.h"
#include <sys/time.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
int unix_uart_reset(struct UARTDriver *self);
int unix_uart_write(struct UARTDriver *self, unsigned char c);
int unix_uart_read(struct UARTDriver *self, unsigned char *c);
int unix_pwm_output_reset(struct PWMOutputDriver *self);
int unix_pwm_output_write(struct PWMOutputDriver *self, unsigned int channel, unsigned long pulse_width_us);
int unix_pwm_input_reset(struct PWMInputDriver *self);
int unix_pwm_input_read(struct PWMInputDriver *self, unsigned int channel, unsigned long *pulse_width_us);
int unix_i2c_reset(struct I2CDriver *self);
int unix_i2c_write(struct I2CDriver *self,
unsigned short device_addr,
unsigned char *data,
unsigned int length);
int unix_i2c_read(struct I2CDriver *self,
unsigned short device_addr,
unsigned char *buff,
unsigned int length);
int unix_global_timer_reset(struct TimerDriver *self);
int unix_global_timer_restart(struct TimerDriver *self);
int unix_global_timer_read(struct TimerDriver *self, u64 *us);
int unix_axi_timer_reset(struct TimerDriver *self);
int unix_axi_timer_restart(struct TimerDriver *self);
int unix_axi_timer_read(struct TimerDriver *self, u64 *us);
int unix_mio7_led_reset(struct LEDDriver *self);
int unix_mio7_led_turn_on(struct LEDDriver *self);
int unix_mio7_led_turn_off(struct LEDDriver *self);
int unix_system_reset(struct SystemDriver *self);
int unix_system_sleep(struct SystemDriver *self, unsigned long us);
struct UARTDriver create_unix_uart();
struct PWMOutputDriver create_unix_pwm_outputs();
struct PWMInputDriver create_unix_pwm_inputs();
struct I2CDriver create_unix_i2c();
struct TimerDriver create_unix_global_timer();
struct TimerDriver create_unix_axi_timer();
struct LEDDriver create_unix_mio7_led();
struct SystemDriver create_unix_system();
int test_unix_i2c();
int test_unix_mio7_led_and_system();
int test_unix_pwm_inputs();
#endif
#include "hw_impl_unix.h"
int unix_axi_timer_reset(struct TimerDriver *self) {
if (self->state == NULL) {
self->state = malloc(sizeof(struct timeval));
}
return 0;
}
int unix_axi_timer_restart(struct TimerDriver *self) {
struct timeval *start = self->state;
struct timezone tz;
gettimeofday(start, &tz);
return 0;
}
int unix_axi_timer_read(struct TimerDriver *self, u64 *us) {
struct timeval *start = self->state;
struct timeval end;
struct timezone tz;
gettimeofday(&end, &tz);
*us = end.tv_usec - start->tv_usec;
return 0;
}
#include "hw_impl_unix.h"
int unix_global_timer_reset(struct TimerDriver *self) {
if (self->state == NULL) {
self->state = malloc(sizeof(struct timeval));
}
return 0;
}
int unix_global_timer_restart(struct TimerDriver *self) {
struct timeval *start = self->state;
struct timezone tz;
gettimeofday(start, &tz);
return 0;
}
int unix_global_timer_read(struct TimerDriver *self, u64 *us) {
struct timeval *start = self->state;
struct timeval end;
struct timezone tz;
gettimeofday(&end, &tz);
*us = end.tv_usec - start->tv_usec;
return 0;
}
#include "hw_impl_unix.h"
int unix_i2c_reset(struct I2CDriver *self) {
return 0;
}
int unix_i2c_write(struct I2CDriver *self,
unsigned short device_addr,
unsigned char *data,
unsigned int length) {
return 0;
}
int unix_i2c_read(struct I2CDriver *self,
unsigned short device_addr,
unsigned char *buff,
unsigned int length) {
return 0;
}
#include "hw_impl_unix.h"
int on;
int unix_mio7_led_reset(struct LEDDriver *self) {
return 0;
}
int unix_mio7_led_turn_on(struct LEDDriver *self) {
if (!on) {
puts("LED ON");
on = 1;
}
return 0;
}
int unix_mio7_led_turn_off(struct LEDDriver *self) {
if (on) {
puts("LED OFF");
on = 0;
}
return 0;
}
#include "hw_impl_unix.h"
int unix_pwm_input_reset(struct PWMInputDriver *self) {
return 0;
}
int unix_pwm_input_read(struct PWMInputDriver *self,
unsigned int channel,
unsigned long *pulse_width_us) {
static int inc = 0;
unsigned long gear;
switch (channel) {
case 0:
*pulse_width_us = 100000;
break;
case 1:
*pulse_width_us = 100000;
break;
case 2:
*pulse_width_us = 100000;
break;
case 3:
*pulse_width_us = 100000;
break;
case 4:
if (inc == 0) {
inc += 1;
puts("GEAR OFF");
}
if (inc < 20) {
inc += 1;
gear = 120000;
}
else if (inc == 20) {
puts("GEAR ON");
inc += 1;
}
else {
gear = 140000;
}
*pulse_width_us = gear;
break;
case 5:
// flap 1
*pulse_width_us = 192000;
break;
}
return 0;
}
#include "hw_impl_unix.h"
int unix_pwm_output_reset(struct PWMOutputDriver *self) {
return 0;
}
int unix_pwm_output_write(struct PWMOutputDriver *self,
unsigned int channel,
unsigned long pulse_width_us) {
//printf("PWM OUTPUT: %d %d\n", channel, pulse_width_us);
return 0;
}
#include "hw_impl_unix.h"
int unix_system_reset(struct SystemDriver *sys) {
return 0;
}
int unix_system_sleep(struct SystemDriver *sys, unsigned long us) {
struct timespec time;
struct timespec time2;
time.tv_sec = 0;
time.tv_nsec = us * 1000;
nanosleep(&time, &time2);
return 0;
}
#include "hw_impl_unix.h"
int unix_uart_reset(struct UARTDriver *self) {
return 0;
}
int unix_uart_write(struct UARTDriver *self, unsigned char c) {
return 0;
}
int unix_uart_read(struct UARTDriver *self, unsigned char *c) {
return 0;
}
#include <stdio.h>
#include "hw_impl_unix.h"
#include "quad_app.h"
int setup_hardware(hardware_t *hardware) {
hardware->i2c = create_unix_i2c();
hardware->pwm_inputs = create_unix_pwm_inputs();
hardware->pwm_outputs = create_unix_pwm_outputs();
hardware->uart = create_unix_uart();
hardware->global_timer = create_unix_global_timer();
hardware->axi_timer = create_unix_axi_timer();
hardware->mio7_led = create_unix_mio7_led();
hardware->sys = create_unix_system();
return 0;
}
int main()
{
quad_main(setup_hardware);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment