Browse Source

Merge branch 'jeroen' of video.vreeken.net:public_html/dt_ctrl into jeroen

jeroen
Jeroen Vreeken 3 years ago
parent
commit
87a30f7f92
98 changed files with 4147 additions and 285 deletions
  1. +46
    -5
      Dockerfile
  2. +2
    -2
      Makefile
  3. +2
    -0
      README
  4. +15
    -1
      build.mk
  5. +11
    -0
      buildflags.mk.in
  6. +5
    -1
      common/command/build.mk
  7. +2
    -1
      common/command/command.h
  8. +3
    -0
      common/command/command_joystick.c
  9. +7
    -0
      common/log/build.mk
  10. +2
    -0
      common/log/log.h
  11. +105
    -0
      common/log/log_std.c
  12. +4
    -0
      common/trace/build.mk
  13. +8
    -4
      common/utils/build.mk
  14. +105
    -1
      configure.ac
  15. +8
    -2
      console/console/console_httpd.c
  16. +5
    -1
      console/console/console_j2000tracker.c
  17. +1
    -0
      console/console/start_console.sh
  18. +1
    -0
      console/htdocs/index.html
  19. +14
    -24
      console/js/dt_status.js
  20. +15
    -1
      console/js/offset.js
  21. +2
    -0
      controller/atsamx70/Makefile
  22. +117
    -0
      controller/atsamx70/block_atsamx70_afec.c
  23. +218
    -0
      controller/atsamx70/block_atsamx70_gmac.c
  24. +111
    -0
      controller/atsamx70/block_atsamx70_pio_in.c
  25. +111
    -0
      controller/atsamx70/block_atsamx70_pio_out.c
  26. +193
    -0
      controller/atsamx70/block_atsamx70_pwm.c
  27. +299
    -0
      controller/atsamx70/block_atsamx70_tc.c
  28. +29
    -0
      controller/atsamx70/build.mk
  29. +108
    -0
      controller/block/block_bool2float.c
  30. +147
    -0
      controller/block/block_deadzone.c
  31. +28
    -0
      controller/block/block_deadzone.test.ctrl
  32. +33
    -12
      controller/block/block_debug.c
  33. +92
    -0
      controller/block/block_debug_bool.c
  34. +79
    -0
      controller/block/block_debug_sint32.c
  35. +1
    -1
      controller/block/block_decoder_uint32_bool.c
  36. +93
    -0
      controller/block/block_delay_bool.c
  37. +2
    -2
      controller/block/block_ex.c
  38. +11
    -3
      controller/block/block_gain_ratio_abs.c
  39. +11
    -4
      controller/block/block_i2t.c
  40. +1
    -1
      controller/block/block_joystick.c
  41. +5
    -3
      controller/block/block_motor_model_dc_v.c
  42. +10
    -4
      controller/block/block_motor_model_dc_v.test.ctrl
  43. +93
    -0
      controller/block/block_quadratic_sign.c
  44. +25
    -0
      controller/block/block_quadratic_sign.test.ctrl
  45. +1
    -1
      controller/block/block_quadrature_decoder.c
  46. +86
    -41
      controller/block/block_setpoint_generator_3d.c
  47. +12
    -2
      controller/block/block_setpoint_generator_3d.test.ctrl
  48. +3
    -3
      controller/block/block_state_machine.c
  49. +1
    -0
      controller/block/block_subtract.c
  50. +1
    -1
      controller/block/block_trajectplayer.c
  51. +2
    -0
      controller/block/block_value.c
  52. +10
    -1
      controller/block/build.mk
  53. +1
    -0
      controller/block/il2c/build.mk
  54. +18
    -2
      controller/build.mk
  55. +31
    -7
      controller/controller/build.mk
  56. +4
    -17
      controller/controller/controller_block.c
  57. +5
    -2
      controller/controller/controller_block.h
  58. +6
    -2
      controller/controller/controller_block_trace.c
  59. +9
    -1
      controller/controller/controller_command.c
  60. +42
    -0
      controller/controller/controller_lib.c
  61. +36
    -0
      controller/controller/controller_lib.h
  62. +38
    -0
      controller/controller/controller_lib_static.c
  63. +31
    -12
      controller/controller/controller_load.c
  64. +1
    -0
      controller/controller/controller_load.h
  65. +4
    -1
      controller/controller/controller_load_parser.l
  66. +4
    -0
      controller/controller/controller_load_parser.y
  67. +1
    -1
      controller/controller/controller_mem.c
  68. +100
    -79
      controller/controller/controller_sample.c
  69. +2
    -0
      controller/controller/controller_sample.h
  70. +18
    -1
      controller/controller/controller_sample_task.c
  71. +3
    -3
      controller/controller/controller_trace.c
  72. +4
    -0
      controller/controller/controller_trigger.h
  73. +220
    -0
      controller/ctrl_embedded.ctrl
  74. +35
    -9
      controller/dt_ctrl.c
  75. +28
    -5
      controller/dt_ctrl.ctrl
  76. +14
    -3
      controller/dt_ctrl_az_sim.ctrl
  77. +4
    -9
      controller/dt_ctrl_el_sim.ctrl
  78. +2
    -2
      controller/ec/build.mk
  79. +1
    -1
      controller/ec/esc_registers.h
  80. +1
    -1
      controller/ec/eth_linux.c
  81. +5
    -0
      controller/packet/Makefile
  82. +225
    -0
      controller/packet/block_packet_eth.c
  83. +94
    -0
      controller/packet/block_packet_in_bool_byte.c
  84. +99
    -0
      controller/packet/block_packet_in_float_be.c
  85. +97
    -0
      controller/packet/block_packet_out_bool_byte.c
  86. +100
    -0
      controller/packet/block_packet_out_float_be.c
  87. +130
    -0
      controller/packet/block_packet_sim.c
  88. +38
    -0
      controller/packet/build.mk
  89. +124
    -0
      controller/packet/packet.c
  90. +50
    -0
      controller/packet/packet.h
  91. +38
    -0
      controller/packet/packet.test.ctrl
  92. +32
    -0
      controller/packet/packet_bus.h
  93. +30
    -0
      controller/packet/packet_eth.ctrl
  94. +6
    -2
      controller/shell/build.mk
  95. +5
    -2
      controller/test/build.mk
  96. +10
    -1
      controller/trigger/build.mk
  97. +102
    -0
      controller/trigger/trigger_systick.c
  98. +3
    -0
      controller/vesp/vesp.h

+ 46
- 5
Dockerfile View File

@ -4,9 +4,12 @@
# ```
# git clone gitlab.camras.nl/dijkema/dt_ctrl
# ```
# Copy the Dockerfile to the empty directory: `cp dt_ctrl/Dockerfile .`
# Tar the source code with `tar czf dt_ctrl.tgz dt_ctrl`
# Create the docker file with `docker build --tag consoledemo .`
# This Dockerfile is hardcoded to run the websockets server at
# port 8000.
# Start the docker container with
# docker run -it -p 8081:80 -p 8000:8000 -p 11031:11031 -p 11030:11030 -p 11040:11040 -p 11041:11041 -p 11042:11042 -p 11011:11011 consoledemo
# Then visit the consoledemo from the host machine at http://localhost:8081 (NOT at port 8000, which will show a non-working HTML page)
FROM ubuntu:16.04
RUN apt-get -y update
@ -18,8 +21,7 @@ RUN cd /root/libnova-libnova && libtoolize && autoreconf -i && ./configure && ma
RUN cd /root && git clone https://github.com/warmcat/libwebsockets.git
RUN cd /root/libwebsockets && mkdir build && cd build && cmake .. && make && make install
ADD dt_ctrl.tgz /root
RUN cd /root tar xf dt_ctrl.tgz
RUN cd /root && git clone https://gitlab.camras.nl/dijkema/dt_ctrl
RUN cd /root/dt_ctrl && autoconf && ./configure --with-libwebsockets=/usr/local && make
RUN cd /root/dt_ctrl && make console/console/console_httpd
@ -33,6 +35,45 @@ RUN cp -r /root/dt_ctrl/console/htdocs /var/www/
RUN cp -r /root/dt_ctrl/console/js /var/www/
RUN mkdir -p /var/www/htdocs/tle && touch /var/www/htdocs/tle/amateur.txt && touch /var/www/htdocs/tle/gps-ops.txt && touch /var/www/htdocs/tle/tle-new.txt
CMD screen -d -m /root/dt_ctrl/controller/dt_ctrl /root/dt_ctrl/controller/dt_ctrl.ctrl && screen -d -m bash -c 'cd /root/dt_ctrl/console/console && ./start_console.sh' && /bin/bash
RUN apt-get -y install apache2 net-tools
RUN mkdir -p /var/www/console/ && cp -r /root/dt_ctrl/console/htdocs /var/www/console && cp -r /root/dt_ctrl/console/js /var/www/console
# Configure apache to serve the console htdocs
RUN echo '\
<VirtualHost *:80>\n\
\tServerAdmin webmaster@localhost\n\
\tDocumentRoot /var/www/console/htdocs\n\
\t<Directory "/var/www/console/htdocs">\n\
\t\tOrder allow,deny\n\
\t\tAllow from all\n\
\t\tAllowOverride None\n\
\t\tAddHandler cgi-script .cgi\n\
\t\tOptions +ExecCGI -MultiViews +SymLinksIfOwnerMatch\n\
\t</Directory>\n\
\n\
ErrorLog ${APACHE_LOG_DIR}/error.log\n\
CustomLog ${APACHE_LOG_DIR}/access.log combined\n\
</VirtualHost>\n\
' > /etc/apache2/sites-enabled/000-default.conf
# Configure ports for the console and controller
RUN mkdir /etc/dt && echo '\
[console]\n\
host=localhost\n\
\n\
[controller]\n\
host=localhost\n\
\n\
[htdocs]\n\
path=/var/www/console/htdocs\n\
port=8000\n\
' > /etc/dt/dt_host.ini
# Patch the console software to point the websockets port
RUN sed -i -e 's/window.location.host/window.location.hostname+":8000"/' /var/www/console/htdocs/index.html && \
sed -i -e 's/window.location.host/window.location.hostname+":8000"/' /var/www/console/htdocs/mech.html
CMD screen -d -m /root/dt_ctrl/controller/dt_ctrl /root/dt_ctrl/controller/dt_ctrl.ctrl && screen -d -m bash -c 'cd /root/dt_ctrl/console/console && ./start_console.sh' && /bin/bash -c 'service apache2 start' && bash
EXPOSE 80

+ 2
- 2
Makefile View File

@ -118,8 +118,8 @@ TARGETS:= $$($(DIR)_TMPTARGETS) $$(TARGETS)
DIR := $(DIR)
endef
CFLAGS := -pthread -D_GNU_SOURCE -Icommon -Icommon/include -Icontroller -Iconsole/console -Iinclude
LDFLAGS := -pthread -Lcommon/lib -Lcontroller/lib -Lconsole/console/lib -Llib -Wl,--as-needed
CFLAGS := $(BUILD_CFLAGS) -D_GNU_SOURCE -Icommon -Icommon/include -Icontroller -Iconsole/console -Iinclude
LDFLAGS := -Lcommon/lib -Lcontroller/lib -Lconsole/console/lib -Llib -Wl,--as-needed
VPATH += common/lib controller/lib console/console/lib lib
VPATH += include


+ 2
- 0
README View File

@ -21,3 +21,5 @@ Building the software
Just run "make". To see more targets, run "make help". You may also run make in
the individual directories.
./configure --host arm-none-eabihf CFLAGS=-specs /usr/local/arm-none-eabihf/lib/atsamx70x21_flash.specs --disable-am335x --enable-embedded --disable-test --disable-ethercat --disable-vesp

+ 15
- 1
build.mk View File

@ -26,6 +26,9 @@ endif
ifdef HOSTSYS
CC=${HOSTSYS}-gcc
LD=${HOSTSYS}-ld
OBJCOPY=${HOSTSYS}-objcopy
OBJDUMP=${HOSTSYS}-objdump
LIBTOOL=${HOSTSYS}-libtool
CONF_HOST=--host=${HOSTSYS}
HW=$(HOSTSYS)
@ -41,9 +44,13 @@ endif
@${LIBTOOL} --quiet --mode=compile --tag=CC $(CC) -MMD $(CFLAGS) -c $< -o $@
@sed -e "s:\.il2c.c:\.il:" -i -i $*.il2c.d
%.o : %.ctrl
@echo "BLOB LD $@"
@$(LD) -r -b binary $< -o $@
%: %.o
@echo " LD $@"
@${LIBTOOL} --quiet --mode=link --tag=CC $(LINK.o) $(filter %.o,$^) $(LOADLIBS) $(LDLIBS) $($@_LDFLAGS) -o $@
@${LIBTOOL} --quiet --mode=link --tag=CC $(LINK.o) $(filter %.o,$^) $(LOADLIBS) $(LDLIBS) $($@_LDFLAGS) $(CFLAGS) -o $@
%.lo: %.c
@echo "LT CC $<"
@ -96,3 +103,10 @@ endef
%.dtbo: %.dts
@echo " DTCo $<"
@dtc -I dts $< -O dtb -o $@
%.hex: %
$(OBJCOPY) --strip-debug --strip-unneeded $? -O ihex $?.hex
%.asm: %
$(OBJDUMP) -D $? > $?.asm

+ 11
- 0
buildflags.mk.in View File

@ -10,5 +10,16 @@ BUILD_CONSOLE_J2000_INDI=@BUILD_CONSOLE_J2000_INDI@
BUILD_ETHERCAT=@BUILD_ETHERCAT@
BUILD_VESP=@BUILD_VESP@
BUILD_AM335X=@BUILD_AM335X@
BUILD_ATSAMX70=@BUILD_ATSAMX70@
BUILD_LINUX_JOYSTICK=@BUILD_LINUX_JOYSTICK@
BUILD_TEST=@BUILD_TEST@
BUILD_PTHREAD=@BUILD_PTHREAD@
BUILD_TCP=@BUILD_TCP@
BUILD_DYNAMICLINKING=@BUILD_DYNAMICLINKING@
BUILD_FILEIO=@BUILD_FILEIO@
BUILD_EMBEDDED=@BUILD_EMBEDDED@
BUILD_SYSTICK=@BUILD_SYSTICK@
BUILD_CFLAGS=@CFLAGS@ @CFLAGS_PTHREAD@ @CFLAGS_TCP@ @CFLAGS_SEMAPHORE@ @CFLAGS_FILEIO@ @CFLAGS_EMBEDDED@ @CFLAGS_SYSTICK@

+ 5
- 1
common/command/build.mk View File

@ -1,9 +1,11 @@
ifdef BUILD_TCP
COMMAND_TARGETS += $(LIBDIR)/libcommand.la
COMMAND_TARGETS += $(DIR)/command_list $(DIR)/command_send
ifneq ($(OS), FreeBSD)
ifdef BUILD_LINUX_JOYSTICK
COMMAND_TARGETS += $(DIR)/command_joystick
endif
@ -46,3 +48,5 @@ CLEAN += $(COMMAND_TARGETS) $(ARCHOBJS) \
$(COMMAND_SEND_OBJS) \
$(COMMAND_JOYSTICK_OBJS) \
$(LIBDIR)/libcommand.a
endif

+ 2
- 1
common/command/command.h View File

@ -36,7 +36,8 @@ enum command_ptype {
COMMAND_PTYPE_SPEED = 5, /* Simple direct 1st derivative setpoint */
COMMAND_PTYPE_SETPOINT_TIME = 6, /* Setpoint to be reached @ time */
COMMAND_PTYPE_SETPOINT_TRACK = 7, /* Use setpoint from track input */
COMMAND_PTYPE_SPEED_TRACK = 8, /* Use 1st derivative from track input */
COMMAND_PTYPE_MAX, /* Always the last entry! */
};


+ 3
- 0
common/command/command_joystick.c View File

@ -18,6 +18,9 @@
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <linux/joystick.h>
#include <command/command.h>
#include <dt_port_numbers.h>


+ 7
- 0
common/log/build.mk View File

@ -1,5 +1,10 @@
ifdef BUILD_TCP
ARCHSRCS = $(DIR)/log.c
else
ARCHSRCS = $(DIR)/log_std.c
endif
ARCHOBJS = $(ARCHSRCS:.c=.lo)
SRCS+=$(ARCHSRCS)
@ -7,8 +12,10 @@ SRCS+=$(ARCHSRCS)
TARGETS += $(LIBDIR)/liblog.la
$(ARCHOBJS): CFLAGS += -Wall -O3 -fPIC
ifdef BUILD_TCP
$(LIBDIR)/liblog.la: libutils.la
$(LIBDIR)/liblog.la_LDFLAGS += -lutils
endif
$(LIBDIR)/liblog.la: $(ARCHOBJS)
$(LIB_LINK)


+ 2
- 0
common/log/log.h View File

@ -22,6 +22,8 @@
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
#include <inttypes.h>
enum log_type {
LOG_T_ERROR,


+ 105
- 0
common/log/log_std.c View File

@ -0,0 +1,105 @@
/*
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2008, 2013, 2014, 2015
Copyright Stichting C.A. Muller Radioastronomiestation, 2008, 2013
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <stdarg.h>
#include <log/log.h>
static enum log_type log_level_console;
static enum log_type log_level_remote;
static uint64_t def_timestamp(void)
{
static uint64_t ctr = 0;
return ctr++;
}
uint64_t (*log_timestamp)(void) = def_timestamp;
static char *logtype(enum log_type type)
{
switch(type) {
case LOG_T_ERROR:
return " ERROR: ";
case LOG_T_WARNING:
return "WARNING: ";
case LOG_T_INFO:
return " INFO: ";
case LOG_T_DEBUG:
return " DEBUG: ";
default:
return "UNKNOWN: ";
}
}
void log_send(enum log_type type, char *fmt, ...)
{
va_list ap;
if (log_level_console < type && log_level_remote < type)
return;
printf("%s", logtype(type));
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
printf("\n");
}
int log_server_start(int port, enum log_type console_level,
enum log_type remote_level)
{
log_level_console = console_level;
log_level_remote = remote_level;
return 0;
}
void log_server_flush(void)
{
}
void log_level_set(enum log_type console_level, enum log_type remote_level)
{
log_level_console = console_level;
log_level_remote = remote_level;
}
int log_time_source_set(
uint64_t (*timestamp)(void),
void (*stamp2spec)(struct timespec *, uint64_t))
{
log_timestamp = timestamp;
return 0;
}

+ 4
- 0
common/trace/build.mk View File

@ -1,4 +1,6 @@
ifdef BUILD_TCP
TRACE_TARGETS += $(LIBDIR)/libtrace.la
TRACE_TARGETS += $(DIR)/trace_dump
TRACE_TARGETS += $(DIR)/trace_dumpdiff
@ -79,3 +81,5 @@ CLEAN += $(TRACE_LIST_OBJS)
CLEAN += $(TRACE_VIEW_OBJS)
CLEAN += $(TRACE2FILE_OBJS)
CLEAN += $(TRACE2PORT_OBJS)
endif

+ 8
- 4
common/utils/build.mk View File

@ -1,4 +1,5 @@
ifdef BUILD_TCP
TARGETS += $(LIBDIR)/libutils.la
TARGETS += $(DIR)/weather_test
@ -6,8 +7,8 @@ TARGETS += $(DIR)/weather_test
WEATHER_SRCS := $(DIR)/weather_test.c $(DIR)/weather.c $(DIR)/tcp_connect.c
WEATHER_OBJS := $(WEATHER_SRCS:.c=.o)
$(DIR)/weather_test_CFLAGS += -pthread
$(DIR)/weather_test_LDFLAGS += -pthread
$(DIR)/weather_test_CFLAGS +=
$(DIR)/weather_test_LDFLAGS += -lpthread
$(DIR)/weather_test: $(WEATHER_OBJS)
ARCHSRCS := $(DIR)/tcp_connect.c \
@ -22,8 +23,8 @@ ARCHSRCS := $(DIR)/tcp_connect.c \
ARCHOBJS := $(ARCHSRCS:.c=.lo)
LU_CFLAGS := -Wall -O3 -fPIC -pthread
LU_LDFLAGS := -lrt -lm
LU_CFLAGS := -Wall -O3 -fPIC
LU_LDFLAGS := -lrt -lm -lpthread
LU_CFLAGS += `pkg-config --cflags glib-2.0`
LU_LDFLAGS += `pkg-config --libs glib-2.0`
@ -39,3 +40,6 @@ CLEAN += $(DIR)/weather_test
CLEAN += $(WEATHER_OBJS) $(ARCHOBJS) $(LIBDIR)/libutils.a
SRCS += $(ARCHSRCS) $(WEATHER_SRCS)
endif

+ 105
- 1
configure.ac View File

@ -31,6 +31,10 @@ AC_ARG_ENABLE([test],
[:],
[enable_test=yes])
AC_ARG_ENABLE([embedded],
[AS_HELP_STRING([--enable-embedded], [Enable/Disable embedde controller @<:@no@:>@])],
[enable_embedded=yes],
[:])
#######################################################################
#
@ -105,13 +109,37 @@ AS_CASE(["$with_libnova"],
[AC_CHECK_HEADERS([libnova/libnova.h])]
)
#######################################################################
#
# Support for linux joystick
AC_CHECK_HEADER(linux/joystick.h,[HAVE_HEADER_LINUX_JOYSTICK=1],[HAVE_HEADER_LINUX_JOYSTICK=0])
#######################################################################
#
# Real OS or embedded?
AC_CHECK_LIB(pthread,pthread_attr_init,[HAVE_LIBPTHREAD=1],[HAVE_LIBPTHREAD=0])
AC_CHECK_LIB(c,realpath,[HAVE_FILEIO=1],[HAVE_FILEIO=0])
AC_CHECK_HEADER(sys/socket.h,[HAVE_TCP=1],[HAVE_TCP=0])
AC_CHECK_HEADER(semaphore.h,[HAVE_SEMAPHORE=1],[HAVE_SEMAPHORE=0])
AC_CHECK_HEADER(dlfcn.h,[HAVE_DYNAMICLINKING=1],[HAVE_DYNAMICLINKING=0])
AC_CHECK_HEADER(sysclk.h,[HAVE_SYSTICK=1],[HAVE_SYSTICK=0])
AC_CHECK_HEADER(samx70.h,[HAVE_ATSAMX70=1],[HAVE_ATSAMX70=0])
#######################################################################
#
# Some conclusions based on test results
#
AS_IF([test "$enable_console" = "yes"],
AS_IF([test "$enable_console" = "yes" && test "$HAVE_TCP" = "1"],
[AC_SUBST(BUILD_CONSOLE,["yes"])],
[AC_SUBST(BUILD_CONSOLE,[""])])
@ -148,6 +176,66 @@ AS_IF([test "$enable_test" = "yes"],
[AC_SUBST(BUILD_TEST,["yes"])],
[AC_SUBST(BUILD_TEST,[""])])
AS_IF([test "$HAVE_LIBPTHREAD" = "1"],
[AC_SUBST(CFLAGS_PTHREAD,["-DHAVE_PTHREAD"])],
[AC_SUBST(CFLAGS_PTHREAD,[""])])
AS_IF([test "$HAVE_LIBPTHREAD" = "1"],
[AC_SUBST(BUILD_PTHREAD,["yes"])],
[AC_SUBST(BUILD_PTHREAD,[""])])
AS_IF([test "$HAVE_TCP" = "1"],
[AC_SUBST(CFLAGS_TCP,["-DHAVE_TCP"])],
[AC_SUBST(CFLAGS_TCP,[""])])
AS_IF([test "$HAVE_TCP" = "1"],
[AC_SUBST(BUILD_TCP,["yes"])],
[AC_SUBST(BUILD_TCP,[""])])
AS_IF([test "$HAVE_SEMAPHORE" = "1"],
[AC_SUBST(CFLAGS_SEMAPHORE,["-DHAVE_SEMAPHORE"])],
[AC_SUBST(CFLAGS_SEMAPHORE,[""])])
AS_IF([test "$HAVE_HEADER_LINUX_JOYSTICK" = "1"],
[AC_SUBST(BUILD_LINUX_JOYSTICK,["yes"])],
[AC_SUBST(BUILD_LINUX_JOYSTICK,[""])])
AS_IF([test "$HAVE_DYNAMICLINKING" = "1"],
[AC_SUBST(BUILD_DYNAMICLINKING,["yes"])],
[AC_SUBST(BUILD_DYNAMICLINKING,[""])])
AS_IF([test "$HAVE_FILEIO" = "1"],
[AC_SUBST(BUILD_FILEIO,["yes"])],
[AC_SUBST(BUILD_FILEIO,[""])])
AS_IF([test "$HAVE_FILEIO" = "1"],
[AC_SUBST(CFLAGS_FILEIO,["-DHAVE_FILEIO"])],
[AC_SUBST(CFLAGS_FILEIO,[""])])
AS_IF([test "$enable_embedded" = "yes"],
[AC_SUBST(BUILD_EMBEDDED,["yes"])],
[AC_SUBST(BUILD_EMBEDDED,[""])])
AS_IF([test "$enable_embedded" = "yes"],
[AC_SUBST(CFLAGS_EMBEDDED,["-DHAVE_EMBEDDED"])],
[AC_SUBST(CFLAGS_EMBEDDED,[""])])
AS_IF([test "$HAVE_SYSTICK" = "1"],
[AC_SUBST(BUILD_SYSTICK,["yes"])],
[AC_SUBST(BUILD_SYSTICK,[""])])
AS_IF([test "$HAVE_SYSTICK" = "1"],
[AC_SUBST(CFLAGS_SYSTICK,["-DHAVE_SYSTICK -D_POSIX_TIMERS"])],
[AC_SUBST(CFLAGS_SYSTICK,[""])])
AS_IF([test "$HAVE_ATSAMX70" = "1"],
[AC_SUBST(BUILD_ATSAMX70,["yes"])],
[AC_SUBST(BUILD_ATSAMX70,[""])])
AS_IF([test "$HAVE_ATSAMX70" = "1"],
[AC_SUBST(CFLAGS_ATSAMX70,["-DHAVE_ATSAMX70"])],
[AC_SUBST(CFLAGS_ATSAMX70,[""])])
#######################################################################
#
# Output
@ -192,10 +280,26 @@ AS_IF([test "$BUILD_VESP" != ""],
AC_MSG_NOTICE([ vesp: yes]),
AC_MSG_NOTICE([ vesp: no]))
AS_IF([test "$BUILD_LINUX_JOYSTICK" != ""],
AC_MSG_NOTICE([ linux joystick: yes]),
AC_MSG_NOTICE([ linux joystick: no]))
AS_IF([test "$BUILD_AM335X" != ""],
AC_MSG_NOTICE([ am335x: yes]),
AC_MSG_NOTICE([ am335x: no]))
AS_IF([test "$BUILD_ATSAMX70" != ""],
AC_MSG_NOTICE([ atsamx70: yes]),
AC_MSG_NOTICE([ atsamx70: no]))
AS_IF([test "$BUILD_SYSTICK" != ""],
AC_MSG_NOTICE([ systick: yes]),
AC_MSG_NOTICE([ systick: no]))
AS_IF([test "$BUILD_EMBEDDED" != ""],
AC_MSG_NOTICE([ embedded: yes]),
AC_MSG_NOTICE([ embedded: no]))
AS_IF([test "$BUILD_TEST" != ""],
AC_MSG_NOTICE([ test: yes]),
AC_MSG_NOTICE([ test: no]))

+ 8
- 2
console/console/console_httpd.c View File

@ -692,7 +692,9 @@ static int callback_http(struct lws *wsi,
switch (reason) {
case LWS_CALLBACK_RECEIVE: {
char *rcv = in;
char rcv[len+1];
memcpy(rcv, in, len);
rcv[len] = 0;
struct ws_client *ws_client;
printf("lws receive: %s\n", rcv);
@ -836,7 +838,11 @@ static int callback_http(struct lws *wsi,
free(resource_path);
break;
}
case LWS_CALLBACK_HTTP_FILE_COMPLETION:
/* kill the connection after we sent one file */
r = -1;
break;
case LWS_CALLBACK_ADD_POLL_FD: {
struct lws_pollargs *args = in;


+ 5
- 1
console/console/console_j2000tracker.c View File

@ -136,7 +136,11 @@ void a2coord(char *ara, char *adec, struct ln_hms *ra, struct ln_dms *dec)
i = 1;
} else {
dec->neg = 0;
i = 0;
if (strlen(adec) && adec[0] =='+') {
i = 1;
} else {
i = 0;
}
}
dec->degrees = 0;
dec->minutes = 0;


+ 1
- 0
console/console/start_console.sh View File

@ -24,6 +24,7 @@ screen -S console -X screen -t console_sattracker console_sattracker
screen -S console -X screen -t console_weather console_weather
screen -S console -X screen -t console_httpd console_httpd
screen -S console -X screen -t console_trace2port ../../common/trace/trace2port -d localhost Azimuth_Position Elevation_Position azimuth_setpoint_error.difference elevation_setpoint_error.difference Azimuth_Speed Elevation_Speed_Right Focusbox_Position
screen -S console -X screen -t trace_az_pos ../../common/trace/trace2file localhost 10000 Azimuth_Position /var/log/dt/traces/Azimuth_Position.trace 15000 100000 5
screen -S console -X screen -t trace_az_pos ../../common/trace/trace2file localhost 10000 Elevation_Position /var/log/dt/traces/Elevation_Position.trace 15000 100000 5


+ 1
- 0
console/htdocs/index.html View File

@ -243,6 +243,7 @@ status_dt.button_disable.onclick = function() {
azimuth_enable_command.send(0);
elevation_enable_command.send(0);
elevation_recover_command.send(0);
status_dt.fb_enable_command.send(0);
}


+ 14
- 24
console/js/dt_status.js View File

@ -55,8 +55,8 @@ function dt_status(element_name) {
this.val_az_safe = new dt_ui_value_trace(element_name + "_val_az_safe", "Azimuth_Safe", 0);
this.val_el_safe = new dt_ui_value_trace(element_name + "_val_el_safe", "Elevation_Safe", 0);
this.button_fb_p = new dt_ui_button(element_name + "_fb_p");
this.button_fb_m = new dt_ui_button(element_name + "_fb_m");
this.text_fb_setpoint = new dt_ui_text(element_name + "_fb_setpoint");
this.button_fb_e = new dt_ui_button(element_name + "_fb_e");
this.button_az_enable = new dt_ui_button(element_name + "_az_enable");
this.button_el_enable = new dt_ui_button(element_name + "_el_enable");
@ -72,7 +72,7 @@ function dt_status(element_name) {
this.val_az_en, this.val_el_en,
this.val_az_safe, this.val_el_safe,
this.az_view, this.el_view,
this.button_fb_p, this.button_fb_m,
this.text_fb_setpoint, this.button_fb_e,
this.button_az_enable, this.button_el_enable, this.button_disable,
this.val_az_sp, this.val_el_sp, this.val_az_north]);
@ -94,10 +94,10 @@ function dt_status(element_name) {
this.val_az_sp.suffix_set("&deg;");
this.val_el_sp.suffix_set("&deg;");
this.button_fb_p.text_set("+");
this.button_fb_m.text_set("-");
this.button_fb_p.color_set("black");
this.button_fb_m.color_set("black");
this.text_fb_setpoint.length_set(3);
this.text_fb_setpoint.width_set(100);
this.button_fb_e.text_set("set");
this.button_fb_e.color_set("black");
this.button_az_enable.text_set("Azimuth Enable");
this.button_el_enable.text_set("Elevation Enable");
this.button_disable.text_set("Disable");
@ -115,8 +115,6 @@ function dt_status(element_name) {
this.window.resize_equal([
this.val_az_sp, this.val_el_sp, this.val_az_north]);
this.window.resize_equal([this.button_fb_p, this.button_fb_m]);
this.window.resize_equal([
this.button_az_enable, this.button_el_enable, this.button_disable]);
@ -128,7 +126,7 @@ function dt_status(element_name) {
this.window.align_horizontal([
this.lbl_el, this.val_el_pos, this.val_el_en, this.val_el_safe], 5);
this.window.align_horizontal([
this.lbl_fb, this.val_fb_pos, this.button_fb_m, this.button_fb_p], 5);
this.lbl_fb, this.val_fb_pos, this.text_fb_setpoint, this.button_fb_e ], 5);
this.window.align_horizontal([
this.lbl_t, this.val_t], 5);
@ -286,21 +284,13 @@ function dt_status(element_name) {
this.button_disable.onclick = function() {
}
this.fb_plus_command = new controller_command("focusbox_plus", "bool");
this.fb_min_command = new controller_command("focusbox_min", "bool");
this.fb_setpoint_command = new controller_command("focusbox_setpoint", "float");
this.fb_enable_command = new controller_command("focusbox_enable", "bool");
this.button_fb_p.onmousedown = function() {
dt_status_this.fb_plus_command.send(1);
}
this.button_fb_p.onmouseup = function() {
dt_status_this.fb_plus_command.send(0);
}
this.button_fb_m.onmousedown = function() {
dt_status_this.fb_min_command.send(1);
}
this.button_fb_m.onmouseup = function() {
dt_status_this.fb_min_command.send(0);
this.button_fb_e.onclick = function() {
fb_val = dt_status_this.text_fb_setpoint.value_get() / 100.0;
dt_status_this.fb_setpoint_command.send(fb_val);
dt_status_this.fb_enable_command.send(1);
}
}


+ 15
- 1
console/js/offset.js View File

@ -142,17 +142,31 @@ function offset(element_name) {
*/
this.highlight_title = function(az, el)
{
if (az!=0 || el!=0)
{
this.window.title.element.style.background = 'yellow';
}
else
{
this.window.title.element.style.background = 'silver';
}
}
this.set_offset = function(az, el)
{
this.val_az.value_set(decimals(rad2deg(az), 4));
this.val_el.value_set(decimals(rad2deg(el), 4));
this.highlight_title(az, el);
}
this.send = function(az, el)
{
az = deg2rad(floatval(az));
el = deg2rad(floatval(el));
this.highlight_title(az, el);
dt_websocket_send("command offset" + " " + az + " " + el);
}


+ 2
- 0
controller/atsamx70/Makefile View File

@ -0,0 +1,2 @@
all:
@$(MAKE) --no-print-directory -C ../.. targets_controller/atsamx70

+ 117
- 0
controller/atsamx70/block_atsamx70_afec.c View File

@ -0,0 +1,117 @@
/*
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2018
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <samx70.h>
#include <afec.h>
#include <pio/samx70.h>
#include <ioport.h>
#include <controller/controller_block.h>
#include <log/log.h>
struct controller_block_private {
float value;
uint32_t afecnr;
uint32_t channel;
float factor;
};
static void afec_calculate(struct controller_block *afec)
{
struct controller_block_private *priv = afec->private;
int16_t data = afec_read_conversion_data(priv->afecnr, priv->channel);
float value = data * priv->factor;
priv->value = value;
}
static struct controller_block_outterm_list outterms[] = {
{ "value", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, value) },
{ NULL },
};
static struct controller_block * block_atsamx70_afec_create(char *name, int argc, va_list ap)
{
struct controller_block *afec;
int afec_nr;
afec_nr = va_arg(ap, int);
if (afec_nr < 0 || afec_nr > 1) {
log_send(LOG_T_ERROR, "%s: afec%d is not valid. (valid: 0-1)",
name, afec_nr);
return NULL;
}
if (!(afec = controller_block_alloc("atsamx70_afec", name, sizeof(struct controller_block_private))))
goto err_alloc;
if (controller_block_outterm_list_init(afec, outterms))
goto err_outterm;
afec->calculate = afec_calculate;
uint32_t pin;
switch (afec_nr) {
case 0:
afec->private->afecnr = AFEC0;
afec->private->channel = 0;
pin = PIO_PD30_IDX;
break;
case 1:
afec->private->afecnr = AFEC1;
afec->private->channel = 1;
pin = PIO_PC13_IDX;
break;
}
afec->private->factor = 1.0 / 2048.0;
ioport_init();
ioport_disable_pin(pin);
afec_init(afec->private->afecnr,
AFEC_MR_FREERUN | AFEC_MR_PRESCAL((sysclk_get_peripheral_hz()+AFEC_FMAX-1)/AFEC_FMAX),
AFEC_EMR_RES_16 | AFEC_EMR_STM_SINGLE | AFEC_EMR_SIGNMODE_SIGNED);
afec_channel_set_offset(afec->private->afecnr, 0, (AFEC_ACR_AOFF_MAX+1)/2);
afec_channel_set_gain(afec->private->afecnr, 0, 0); // set gain to 1 (value 0)
afec_channel_enable(afec->private->afecnr, afec_nr);
if (controller_block_add(afec))
goto err_add;
return afec;
err_add:
err_outterm:
controller_block_free(afec);
err_alloc:
return NULL;
}
BLOCK_CREATE(atsamx70_afec) = {
.create = block_atsamx70_afec_create,
.args = { "int", NULL },
};

+ 218
- 0
controller/atsamx70/block_atsamx70_gmac.c View File

@ -0,0 +1,218 @@
/*
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2018
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <controller/controller_block.h>
#include <controller/controller_bus.h>
#include <controller/controller_mem.h>
#include <controller/controller_sample.h>
#include <log/log.h>
#include <packet/packet.h>
#include <packet/packet_bus.h>
#include <samx70.h>
#include <pio/samx70.h>
#include <ioport.h>
#include <gmac.h>
#define TX_Q_SIZE 4
struct controller_block_private {
struct controller_bus *bus;
void *rx_packet;
void *tx_packet;
size_t rx_size;
size_t tx_size;
struct gmac_state gmac;
struct gmac_tx_buffer_descriptor tx_q[TX_Q_SIZE];
char tx_buffer[TX_Q_SIZE][1600];
};
static void atsamx70_gmac_tx_calculate(struct controller_block *packet_tx)
{
struct controller_block_private *priv = packet_tx->private;
((char*)priv->tx_packet)[11]++;
gmac_tx(&priv->gmac, priv->tx_packet, priv->tx_size);
}
static void packet_sample_start(void *arg)
{
struct controller_block *packet = arg;
struct controller_bus *bus = packet->private->bus;
size_t header_size = 14;
packet->private->tx_size = bus->private->tx_end_offset + header_size;
packet->private->rx_size = bus->private->rx_end_offset + header_size;
packet->private->tx_packet = controller_mem_calloc(
CONTROLLER_MEM_PERIODIC_READ | CONTROLLER_MEM_PERIODIC_WRITE,
packet->private->tx_size, 1);
packet->private->rx_packet = controller_mem_calloc(
CONTROLLER_MEM_PERIODIC_READ | CONTROLLER_MEM_PERIODIC_WRITE,
packet->private->rx_size, 1);
char *tx_start = packet->private->tx_packet;
char *rx_start = packet->private->rx_packet;
memcpy(tx_start + 0, (char[]){0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 6);
memcpy(tx_start + 6, (char[]){0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, 6);
tx_start[12] = 0x44;
tx_start[13] = 0x4d;
tx_start += header_size;
rx_start += header_size;
packet_client_callbacks(bus, rx_start, tx_start);
}
static enum controller_bus_state atsamx70_gmac_poll(struct controller_bus *bus)
{
struct gmac_state *gmac = &bus->owner->private->gmac;
uint32_t nsr = gmac_network_status_get(gmac);
uint32_t tsr = gmac_transmit_status_get(gmac);
uint32_t isr = gmac_interrupt_status_get(gmac);
log_send(LOG_T_DEBUG, "%s: NSR: 0x%08"PRIx32" TSR: 0x%08"PRIx32" ISR: 0x%08"PRIx32,
bus->owner->name, nsr, tsr, isr);
if (tsr) {
gmac_transmit_status_set(gmac, tsr);
}
return CONTROLLER_BUS_STATE_OK;
}
static int atsamx70_gmac_recover(struct controller_bus *bus)
{
return 0;
}
static struct controller_block * block_atsamx70_gmac_create(char *name, int argc,
va_list val)
{
struct controller_block *packet;
struct controller_bus *bus;
char *name_tx;
struct controller_block *packet_tx;
asprintf(&name_tx, "%s_tx", name);
if (!name_tx)
return NULL;
packet = controller_block_alloc("atsamx70_gmac", name, sizeof(struct controller_block_private));
if (!packet)
goto err_block;
packet_tx = controller_block_alloc("atsamx70_gmac_tx", name_tx, 0);
if (!packet)
goto err_block_tx;
packet_tx->private = packet->private;
free(name_tx);
name_tx = NULL;
bus = packet_bus_create(name, packet);
if (!bus)
goto err_bus;
controller_bus_output_set(bus, packet_tx);
controller_bus_input_set(bus, packet);
controller_bus_poll_set(bus, atsamx70_gmac_poll, atsamx70_gmac_recover);
packet->private->bus = bus;
packet_tx->calculate = atsamx70_gmac_tx_calculate;
if (controller_block_add(packet))
goto err_add;
if (controller_block_add(packet_tx))
goto err_add;
controller_sample_start_hook(packet_sample_start, packet);
/* RMII pins:
GTXCK PD0,A
GTXEN PD1,A
GTX0 PD2,A
GTX1 PD3,A
GRXDV PD4,A
GRX0 PD5,A
GRX1 PD6,A
GRXER PD7,A
GMDC PD8,A
GMDIO PD9,A
same70 xplained:
RESET PC10
INT PA14
*/
ioport_disable_pin(PIO_GTXCK_IDX);
ioport_set_pin_mode(PIO_GTXCK_IDX, IOPORT_MODE_GTXCK);
ioport_disable_pin(PIO_GTXEN_IDX);
ioport_set_pin_mode(PIO_GTXEN_IDX, IOPORT_MODE_GTXEN);
ioport_disable_pin(PIO_GTX0_IDX);
ioport_set_pin_mode(PIO_GTX0_IDX, IOPORT_MODE_GTX0);
ioport_disable_pin(PIO_GTX1_IDX);
ioport_set_pin_mode(PIO_GTX1_IDX, IOPORT_MODE_GTX1);
ioport_disable_pin(PIO_GRXDV_IDX);
ioport_set_pin_mode(PIO_GRXDV_IDX, IOPORT_MODE_GRX0);
ioport_disable_pin(PIO_GRX0_IDX);
ioport_set_pin_mode(PIO_GRX1_IDX, IOPORT_MODE_GRX1);
ioport_disable_pin(PIO_GRXER_IDX);
ioport_set_pin_mode(PIO_GRXER_IDX, IOPORT_MODE_GRXER);
ioport_disable_pin(PIO_GMDC_IDX);
ioport_set_pin_mode(PIO_GMDC_IDX, IOPORT_MODE_GMDC);
ioport_disable_pin(PIO_GMDIO_IDX);
ioport_set_pin_mode(PIO_GMDIO_IDX, IOPORT_MODE_GMDIO);
struct gmac_state *gmac = &packet->private->gmac;
log_send(LOG_T_DEBUG, "gmac: %p, tx_q: %p", gmac, packet->private->tx_q);
int i;
for (i = 0; i < TX_Q_SIZE; i++) {
packet->private->tx_q[i].buffer = packet->private->tx_buffer[i];
}
gmac_init(gmac, packet->private->tx_q, TX_Q_SIZE);
gmac_network_configuration_set(gmac,
GMAC_NCFGR_SPD | GMAC_NCFGR_FD | GMAC_NCFGR_DBW(0) |
GMAC_NCFGR_CLK_MCK_64 | GMAC_NCFGR_MAXFS | GMAC_NCFGR_PEN |
GMAC_NCFGR_RFCS);
return packet;
err_add:
err_bus:
err_block_tx:
controller_block_free(packet);
err_block:
free(name_tx);
return NULL;
}
BLOCK_CREATE(atsamx70_gmac) = {
.create = block_atsamx70_gmac_create,
.args = { NULL },
};

+ 111
- 0
controller/atsamx70/block_atsamx70_pio_in.c View File

@ -0,0 +1,111 @@
/*
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2018
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <samx70.h>
#include <pio/samx70.h>
#include <ioport.h>
#include <controller/controller_block.h>
#include <log/log.h>
struct controller_block_private {
bool value;
ioport_pin_t pin;
};
static void pio_in_calculate(struct controller_block *pio)
{
struct controller_block_private *priv = pio->private;
priv->value = ioport_get_pin_level(priv->pin);
}
static struct controller_block_outterm_list outterms[] = {
{ "value", CONTROLLER_BLOCK_TERM_BOOL, offsetof(struct controller_block_private, value) },
{ NULL },
};
static struct controller_block * block_atsamx70_pio_in_create(char *name, int argc, va_list ap)
{
struct controller_block *pio;
int pio_nr;
int pin_nr;
pio_nr = va_arg(ap, int);
if (pio_nr < 0 || pio_nr > 4) {
log_send(LOG_T_ERROR, "%s: pio%d is not valid. (valid: 0-4)", name, pio_nr);
return NULL;
}
pin_nr = va_arg(ap, int);
if (pin_nr < 0 || pin_nr > 31) {
log_send(LOG_T_ERROR, "%s: pin%d is not valid. (valid: 0-31)", name, pin_nr);
}
if (!(pio = controller_block_alloc("atsamx70_pio_in", name, sizeof(struct controller_block_private))))
goto err_alloc;
if (controller_block_outterm_list_init(pio, outterms))
goto err_outterm;
pio->calculate = pio_in_calculate;
switch (pio_nr) {
case 0:
pio->private->pin = PIO_PA_IDX;
break;
case 1:
pio->private->pin = PIO_PB_IDX;
break;
case 2:
pio->private->pin = PIO_PC_IDX;
break;
case 3:
pio->private->pin = PIO_PD_IDX;
break;
case 4:
pio->private->pin = PIO_PE_IDX;
break;
}
pio->private->pin |= pin_nr;
ioport_init();
ioport_enable_pin(pio->private->pin);
ioport_set_pin_mode(pio->private->pin, IOPORT_MODE_PULLUP | IOPORT_MODE_GLITCH_FILTER);
ioport_set_pin_dir(pio->private->pin, IOPORT_DIR_INPUT);
ioport_set_pin_sense_mode(pio->private->pin, IOPORT_SENSE_BOTHEDGES);
if (controller_block_add(pio))
goto err_add;
return pio;
err_add:
err_outterm:
controller_block_free(pio);
err_alloc:
return NULL;
}
BLOCK_CREATE(atsamx70_pio_in) = {
.create = block_atsamx70_pio_in_create,
.args = { "int,int", NULL },
};

+ 111
- 0
controller/atsamx70/block_atsamx70_pio_out.c View File

@ -0,0 +1,111 @@
/*
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2018
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <samx70.h>
#include <pio/samx70.h>
#include <ioport.h>
#include <controller/controller_block.h>
#include <log/log.h>
struct controller_block_private {
bool *value;
ioport_pin_t pin;
};
static void pio_out_calculate(struct controller_block *pio)
{
struct controller_block_private *priv = pio->private;
bool value = *priv->value;
ioport_set_pin_level(priv->pin, value);
}
static struct controller_block_interm_list interms[] = {
{ "value", CONTROLLER_BLOCK_TERM_BOOL, offsetof(struct controller_block_private, value) },
{ NULL },
};
static struct controller_block * block_atsamx70_pio_out_create(char *name, int argc, va_list ap)
{
struct controller_block *pio;
int pio_nr;
int pin_nr;
pio_nr = va_arg(ap, int);
if (pio_nr < 0 || pio_nr > 4) {
log_send(LOG_T_ERROR, "%s: pio%d is not valid. (valid: 0-4)", name, pio_nr);
return NULL;
}
pin_nr = va_arg(ap, int);
if (pin_nr < 0 || pin_nr > 31) {
log_send(LOG_T_ERROR, "%s: pin%d is not valid. (valid: 0-31)", name, pin_nr);
}
if (!(pio = controller_block_alloc("atsamx70_pio_out", name, sizeof(struct controller_block_private))))
goto err_alloc;
if (controller_block_interm_list_init(pio, interms))
goto err_interm;
pio->calculate = pio_out_calculate;
switch (pio_nr) {
case 0:
pio->private->pin = PIO_PA_IDX;
break;
case 1:
pio->private->pin = PIO_PB_IDX;
break;
case 2:
pio->private->pin = PIO_PC_IDX;
break;
case 3:
pio->private->pin = PIO_PD_IDX;
break;
case 4:
pio->private->pin = PIO_PE_IDX;
break;
}
pio->private->pin |= pin_nr;
ioport_init();
ioport_enable_pin(pio->private->pin);
ioport_set_pin_dir(pio->private->pin, IOPORT_DIR_OUTPUT);
ioport_set_pin_mode(pio->private->pin, 0);
if (controller_block_add(pio))
goto err_add;
return pio;
err_add:
err_interm:
controller_block_free(pio);
err_alloc:
return NULL;
}
BLOCK_CREATE(atsamx70_pio_out) = {
.create = block_atsamx70_pio_out_create,
.args = { "int,int", NULL },
};

+ 193
- 0
controller/atsamx70/block_atsamx70_pwm.c View File

@ -0,0 +1,193 @@
/*
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2018
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <samx70.h>
#include <pwm.h>
#include <pio/samx70.h>
#include <ioport.h>
#include <controller/controller_block.h>
#include <log/log.h>
struct controller_block_private {
float *in;
int period;
uint32_t pwm;
int ch_nr;
uint32_t outputh;
uint32_t outputl;
};
static void pwm_calculate(struct controller_block *pwm)
{
struct controller_block_private *priv = pwm->private;
uint32_t pw = priv->pwm;
float in = *priv->in;
int period = priv->period;
uint32_t outputl = priv->outputl;
uint32_t outputh = priv->outputh;
int ch_nr = priv->ch_nr;
int duty = in * period;
uint32_t dty = abs(duty);
/* Make sure we generate negative pulses for capacitor loading */
// TODO make this a parameter (in seconds off)
if (dty >= period) {
dty-=1 + period / 1000;
}
if (duty > 0) {
pwm_output_selection_set(pw, outputl);
pwm_channel_duty_cycle_update_set(pw, ch_nr, dty);
pwm_output_selection_clear_update(pw, outputh);
} else if (duty < 0) {
pwm_output_selection_set(pw, outputh);
pwm_channel_duty_cycle_update_set(pw, ch_nr, dty);
pwm_output_selection_clear_update(pw, outputl);
} else {
pwm_output_selection_set(pw, outputh | outputl);
pwm_channel_duty_cycle_update_set(pw, ch_nr, dty);
}
pwm_sync_update(pw);
}
static struct controller_block_interm_list interms[] = {
{ "in", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, in) },
{ NULL },
};
static struct controller_block * block_atsamx70_pwm_create(char *name, int argc, va_list ap)
{
struct controller_block *pwm;
int pwm_nr;
int ch_nr;
double frequency;
pwm_nr = va_arg(ap, int);
if (pwm_nr < 0 || pwm_nr > 1) {
log_send(LOG_T_ERROR, "%s: pwm%d is not valid. (valid: 0-1)",
name, pwm_nr);
return NULL;
}
ch_nr = va_arg(ap, int);
if (ch_nr < 0 || ch_nr > 3) {
log_send(LOG_T_ERROR, "%s: channel %d is not valid. (valid: 0-3)",
name, ch_nr);
return NULL;
}
double fclock = sysclk_get_peripheral_hz();
frequency = va_arg(ap, double);
int period = fclock / frequency;
log_send(LOG_T_DEBUG, "%s: Frequency: %fHz, period: %d (%fHz)", name,
frequency, period, fclock / period);
if (!(pwm = controller_block_alloc("atsamx70_pwm", name, sizeof(struct controller_block_private))))
goto err_alloc;
if (controller_block_interm_list_init(pwm, interms))
goto err_interm;
pwm->calculate = pwm_calculate;
pwm->private->ch_nr = ch_nr;
pwm->private->period = period;
switch (pwm_nr) {
case 0:
pwm->private->pwm = PWM0;
break;
case 1:
pwm->private->pwm = PWM1;
break;
}
pwm_init(pwm->private->pwm);
pwm_disable(pwm->private->pwm, ch_nr);
uint32_t oov = pwm_output_override_get(pwm->private->pwm);
switch (ch_nr) {
case 0:
oov &= ~(PWM_OOV_OOVL0 | PWM_OOV_OOVH0);
pwm->private->outputh = PWM_OS_OSL0;
pwm->private->outputl = PWM_OS_OSH0;
ioport_disable_pin(PIO_PD20_IDX);
ioport_set_pin_mode(PIO_PD20_IDX, IOPORT_MODE_MUX_A);
ioport_set_pin_dir(PIO_PD20_IDX, IOPORT_DIR_OUTPUT);
ioport_disable_pin(PIO_PA19_IDX);
ioport_set_pin_mode(PIO_PA19_IDX, IOPORT_MODE_MUX_B);
ioport_set_pin_dir(PIO_PA19_IDX, IOPORT_DIR_OUTPUT);
break;
case 1:
oov &= ~(PWM_OOV_OOVL1 | PWM_OOV_OOVH1);
pwm->private->outputh = PWM_OS_OSL1;
pwm->private->outputl = PWM_OS_OSH1;
break;
case 2:
oov &= ~(PWM_OOV_OOVL2 | PWM_OOV_OOVH2);
pwm->private->outputh = PWM_OS_OSL0;
pwm->private->outputl = PWM_OS_OSH2;
break;
case 3:
oov &= ~(PWM_OOV_OOVL3 | PWM_OOV_OOVH3);
pwm->private->outputh = PWM_OS_OSL3;
pwm->private->outputl = PWM_OS_OSH3;
break;
}
pwm_output_override_set(pwm->private->pwm, oov);
pwm_output_selection_set_update(pwm->private->pwm, pwm->private->outputh | pwm->private->outputl);
pwm_sync_mode_set(pwm->private->pwm,
PWM_SCM_SYNC0 | PWM_SCM_SYNC1 | PWM_SCM_SYNC2 | PWM_SCM_SYNC3);
pwm_channel_mode_set(pwm->private->pwm, ch_nr, PWM_CMR_CPOL | PWM_CMR_DPOLI | PWM_CMR_DTLI);
pwm_channel_period_set(pwm->private->pwm, ch_nr, period);
pwm_channel_duty_cycle_update_set(pwm->private->pwm, ch_nr, 0);
pwm_channel_dead_time_set(pwm->private->pwm, ch_nr, 0);
pwm_sync_update(pwm->private->pwm);
pwm_enable(pwm->private->pwm, ch_nr);
if (controller_block_add(pwm))
goto err_add;
return pwm;
err_add:
err_interm:
controller_block_free(pwm);
err_alloc:
return NULL;
}
BLOCK_CREATE(atsamx70_pwm) = {
.create = block_atsamx70_pwm_create,
.args = { "int,int,double", NULL },
};

+ 299
- 0
controller/atsamx70/block_atsamx70_tc.c View File

@ -0,0 +1,299 @@
/*
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2018
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <samx70.h>
#include <tc.h>
#include <pio/samx70.h>
#include <ioport.h>
#include <controller/controller_block.h>
#include <controller/controller_time.h>
#include <log/log.h>
enum tc_mode {
TC_MODE_POSITION = 0,
TC_MODE_SPEED = 1,
};
struct controller_block_private {
float position;
float speed;
bool homed;
bool *reset;
uint16_t prevcnt0;
int rev;
float speedfac;
float posfac;
uint32_t tcn;
};
static void tc_calculate(struct controller_block *tc)
{
struct controller_block_private *priv = tc->private;
uint16_t cnt0;
int16_t cnt0p;
// int16_t cnt1;
uint16_t prevcnt0 = priv->prevcnt0;
float speed;
float position;
int rev = priv->rev;
cnt0 = tc_get_cv(priv->tcn, 0);
// cnt1 = tc_get_cv(priv->tcn, 1);