From 0efbd98973520d55ec4e80e443911f43b3c28a0d Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Thu, 12 Jan 2017 15:30:21 +0100 Subject: [PATCH] add external libraries and update stm version --- .gitmodules | 6 ++ CleanSerial | 1 + Makefile | 20 ++--- iTasks-SDK | 1 + int/nucleo-f767-blinky/src/Makefile | 4 +- int/nucleo-f767-blinky/src/interface.c | 52 ++++++++++++- int/nucleo-f767-blinky/src/interface.h | 18 ++++- int/nucleo-f767-blinky/src/interpret.c | 22 +++--- int/nucleo-f767-blinky/src/main.c | 10 ++- int/nucleo-f767-blinky/src/misc.h | 22 ------ int/nucleo-f767-blinky/src/sds.c | 5 +- int/nucleo-f767-blinky/src/task.c | 2 +- mTaskInterpret.icl | 2 +- miTask.icl | 104 ++++++++++++++++++++++--- 14 files changed, 203 insertions(+), 66 deletions(-) create mode 160000 CleanSerial create mode 160000 iTasks-SDK delete mode 100644 int/nucleo-f767-blinky/src/misc.h diff --git a/.gitmodules b/.gitmodules index 98b81d8..2788b6e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -2,3 +2,9 @@ path = clean-platform url = https://gitlab.science.ru.nl/clean-and-itasks/clean-platform.git branch = patch-JSON +[submodule "CleanSerial"] + path = CleanSerial + url = https://gitlab.science.ru.nl/mlubbers/CleanSerial +[submodule "iTasks-SDK"] + path = iTasks-SDK + url = https://gitlab.science.ru.nl/mlubbers/iTasks-SDK.git diff --git a/CleanSerial b/CleanSerial new file mode 160000 index 0000000..553b662 --- /dev/null +++ b/CleanSerial @@ -0,0 +1 @@ +Subproject commit 553b66228cfc990be3b34578f3a4f020e70fcf61 diff --git a/Makefile b/Makefile index 6be8eb5..ddb4dfc 100644 --- a/Makefile +++ b/Makefile @@ -2,21 +2,21 @@ CLEAN_HOME?=/opt/clean CLM:=clm override CLMFLAGS+=-dynamics -h 200M -nt -l -no-pie CLMLIBS:=\ - -I $(CLEAN_HOME)/lib/iTasks-SDK/Patches/Dynamics\ - -I $(CLEAN_HOME)/lib/iTasks-SDK/Patches/Generics\ - -I $(CLEAN_HOME)/lib/iTasks-SDK/Patches/StdEnv\ - -I $(CLEAN_HOME)/lib/iTasks-SDK/Patches/TCPIP\ - -I $(CLEAN_HOME)/lib/iTasks-SDK/Server\ + -I ./iTasks-SDK/Patches/Dynamics\ + -I ./iTasks-SDK/Patches/Generics\ + -I ./iTasks-SDK/Patches/StdEnv\ + -I ./iTasks-SDK/Patches/TCPIP\ + -I ./iTasks-SDK/Server\ -I ./clean-platform/src/libraries/OS-Independent\ -I ./clean-platform/src/libraries/OS-Independent/Deprecated/StdLib\ -I ./clean-platform/src/libraries/OS-Posix\ -I ./clean-platform/src/libraries/OS-Linux\ -I ./clean-platform/src/libraries/OS-Linux-64\ - -I $(CLEAN_HOME)/lib/iTasks-SDK/Dependencies/graph_copy/linux64\ - -I $(CLEAN_HOME)/lib/iTasks-SDK/Dependencies/graph_copy/common\ - -I $(CLEAN_HOME)/lib/iTasks-SDK/Dependencies/SAPL\ - -I $(CLEAN_HOME)/lib/iTasks-SDK/Dependencies/clean-sapl/src\ - -I $(CLEAN_HOME)/lib/iTasks-SDK/Server/lib\ + -I ./iTasks-SDK/Dependencies/graph_copy/linux64\ + -I ./iTasks-SDK/Dependencies/graph_copy/common\ + -I ./iTasks-SDK/Dependencies/SAPL\ + -I ./iTasks-SDK/Dependencies/clean-sapl/src\ + -I ./iTasks-SDK/Server/lib\ -I $(CLEAN_HOME)/lib/StdEnv\ -I $(CLEAN_HOME)/lib/Generics\ -I $(CLEAN_HOME)/lib/Dynamics\ diff --git a/iTasks-SDK b/iTasks-SDK new file mode 160000 index 0000000..890b822 --- /dev/null +++ b/iTasks-SDK @@ -0,0 +1 @@ +Subproject commit 890b822813baa638e27a01376e95d995d37fdcea diff --git a/int/nucleo-f767-blinky/src/Makefile b/int/nucleo-f767-blinky/src/Makefile index 72506e8..17dd912 100644 --- a/int/nucleo-f767-blinky/src/Makefile +++ b/int/nucleo-f767-blinky/src/Makefile @@ -1,4 +1,4 @@ -CFLAGS:=-g -Wall -Wextra -Werror -DDEBUG +CFLAGS:=-g -Wall -Wextra # -DDEBUG PROG:=main OBJS:=interpret.o sds.o task.o main.o interface.o @@ -7,7 +7,7 @@ all: mTaskSymbols.h $(PROG) %.o: %.cpp gcc $(CFLAGS) -c $< -o $@ -$(PROG): $(OBJS) misc.h +$(PROG): $(OBJS) gcc $(LDFLAGS) -o $@ $(OBJS) mTaskSymbols.h: diff --git a/int/nucleo-f767-blinky/src/interface.c b/int/nucleo-f767-blinky/src/interface.c index 2f7fb57..96077b0 100644 --- a/int/nucleo-f767-blinky/src/interface.c +++ b/int/nucleo-f767-blinky/src/interface.c @@ -32,6 +32,7 @@ //Globals #ifdef STM32F767xx volatile char uartf = 0; +char buf[128]; #else struct timeval tv1; int sock_fd = -1; @@ -78,7 +79,7 @@ long millis() { bool input_available(){ #ifdef STM32F767xx - return false; + return true; #else struct timeval tv; fd_set fds; @@ -112,6 +113,55 @@ void write_byte(uint8_t b) #endif } +void write_dpin(uint8_t i, bool b) +{ +#ifdef STM32F767xx +#else + debug("dwrite %d: %d\n", i, b); +#endif +} + +bool read_dpin(uint8_t i) +{ +#ifdef STM32F767xx + return false; +#else + debug("dread %d\n", i); + return false; +#endif +} + +void write_apin(uint8_t i, uint8_t a) +{ +#ifdef STM32F767xx + if(i == 1){ + SET_LED_RED; + RESET_LED_BLUE; + RESET_LED_GREEN; + } else if(i == 2){ + RESET_LED_RED; + SET_LED_BLUE; + RESET_LED_GREEN; + } else if(i == 3){ + RESET_LED_RED; + RESET_LED_BLUE; + SET_LED_GREEN; + } +#else + debug("awrite %d: %d\n", i, a); +#endif +} + +uint8_t read_apin(uint8_t i) +{ +#ifdef STM32F767xx + return 0; +#else + debug("aread %d\n", i); + return 0; +#endif +} + void delay(long ms) { #ifdef STM32F767xx diff --git a/int/nucleo-f767-blinky/src/interface.h b/int/nucleo-f767-blinky/src/interface.h index b9c223a..23e5b59 100644 --- a/int/nucleo-f767-blinky/src/interface.h +++ b/int/nucleo-f767-blinky/src/interface.h @@ -3,8 +3,19 @@ #include #include +#include +#include -#ifndef STM32F767xx +#ifdef STM32F767xx +#include "stm32f7xx_hal.h" +#include "gpio.h" +#include "usart.h" +#endif + +#ifdef STM32F767xx +extern volatile char uartf; +extern char buf[128]; +#else extern int gargc; extern char **gargv; #endif @@ -26,7 +37,10 @@ void setup(); #define read16() 256*read_byte() + read_byte() #ifdef STM32F767xx -#define debug(s, ...) ; +#define debug(s, ...) {\ + sprintf(buf, s, ##__VA_ARGS__);\ + HAL_UART_Transmit(&huart3, (uint8_t*)buf, strlen(buf), 1000);\ + } #define pdie(s) ; #define die(s, ...) ; #else diff --git a/int/nucleo-f767-blinky/src/interpret.c b/int/nucleo-f767-blinky/src/interpret.c index bbfa351..ad9cdad 100644 --- a/int/nucleo-f767-blinky/src/interpret.c +++ b/int/nucleo-f767-blinky/src/interpret.c @@ -3,7 +3,7 @@ #include "mTaskSymbols.h" #include "interpret.h" -#include "misc.h" +#include "interface.h" #include "task.h" #include "sds.h" @@ -21,12 +21,12 @@ void run_task(struct task *t) int pc = 0; int sp = 0; char stack[STACKSIZE] = {0}; - printf("Running task with length: %d\n", plen); + debug("Running task with length: %d\n", plen); while(pc != plen){ - //printf("program: %d\n", program[pc]); - //printf("stack: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", - // stack[0], stack[1], stack[2], stack[3], stack[4], - // stack[5], stack[6], stack[7], stack[8], stack[9]); + debug("program: %d\n", program[pc]); + debug("stack: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", + stack[0], stack[1], stack[2], stack[3], stack[4], + stack[5], stack[6], stack[7], stack[8], stack[9]); switch(program[pc++]){ case BCNOP: trace("nop\n"); @@ -121,16 +121,18 @@ void run_task(struct task *t) case BCSERIALPARSEINT: trace("SerialParseInt()\n"); break; case BCANALOGREAD: trace("AnalogRead(%d)\n", program[pc]); - pc++; + stack[sp++] = read_apin(program[pc++]); break; case BCANALOGWRITE: trace("AnalogWrite(%d)\n", program[pc]); - pc++; + write_apin(program[pc++], stack[sp-1]); + sp--; break; case BCDIGITALREAD: trace("DigitalRead(%d)\n", program[pc]); - pc++; + stack[sp++] = read_dpin(program[pc++]); break; case BCDIGITALWRITE: trace("DigitalWrite(%d)\n", program[pc]); - pc++; + write_dpin(program[pc++], stack[sp-1]); + sp--; break; default: trace("unrecognized\n"); diff --git a/int/nucleo-f767-blinky/src/main.c b/int/nucleo-f767-blinky/src/main.c index 1a704b4..0be5c0f 100644 --- a/int/nucleo-f767-blinky/src/main.c +++ b/int/nucleo-f767-blinky/src/main.c @@ -81,20 +81,23 @@ void loop() // debug("Task %d not scheduled\n", ct); continue; } - printf("Current task to run: %d\n", ct); + debug("Current task to run: %d\n", ct); run_task(curtask); curtask->lastrun = cyclestart; + write_byte('\n'); } - write_byte('\n'); } #ifdef STM32F767xx +char s[128] = ""; int main1(void){ #else int main(int argc, char *argv[]){ gargc = argc; gargv = argv; #endif + debug("booting up\r\n"); + //Initialize systems setup(); sds_init(); @@ -104,8 +107,9 @@ int main(int argc, char *argv[]){ while(true){ //Check for new tasks + debug("loop\r\n"); loop(); - delay(10); + delay(100); } return 0; } diff --git a/int/nucleo-f767-blinky/src/misc.h b/int/nucleo-f767-blinky/src/misc.h deleted file mode 100644 index 198dcc4..0000000 --- a/int/nucleo-f767-blinky/src/misc.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef MISC_H -#define MISC_H -#include "interface.h" - -#define read16() 256*read_byte() + read_byte() -#ifdef STM32F767xx -#define debug(s, ...) ; -#define pdie(s) ; -#define die(s, ...) ; -#else - -#ifdef DEBUG -#define debug(s, ...) printf(s, ##__VA_ARGS__); -#else -#define debug(s, ...) ; -#endif - -#define pdie(s) {perror(s); exit(1);} -#define die(s, ...) {fprintf(stderr, s, ##__VA_ARGS__); exit(1);} -#endif - -#endif diff --git a/int/nucleo-f767-blinky/src/sds.c b/int/nucleo-f767-blinky/src/sds.c index 8e3d2f6..1300c06 100644 --- a/int/nucleo-f767-blinky/src/sds.c +++ b/int/nucleo-f767-blinky/src/sds.c @@ -8,7 +8,6 @@ #include "interface.h" #include "interpret.h" -#include "misc.h" #include "sds.h" struct sds sdss[MAXSDSS]; @@ -27,7 +26,7 @@ void sds_register() break; if(cs == MAXSDSS) - die("Trying to add too much tasks...\n"); + die("Trying to add too much sdss...\n"); memset(&sdss[cs], 0, sizeof(struct sds)); //Read identifier @@ -53,6 +52,8 @@ bool sds_update() sdss[cs].value = read16(); debug("\nReceived sds update %d: %d\n", sdss[cs].id, sdss[cs].value); + printf("\nReceived sds update %d: %d\n", + sdss[cs].id, sdss[cs].value); return true; } } diff --git a/int/nucleo-f767-blinky/src/task.c b/int/nucleo-f767-blinky/src/task.c index 06b738d..29c955b 100644 --- a/int/nucleo-f767-blinky/src/task.c +++ b/int/nucleo-f767-blinky/src/task.c @@ -6,8 +6,8 @@ #include #endif -#include "misc.h" #include "task.h" +#include "interface.h" struct task tasks[MAXTASKS]; diff --git a/mTaskInterpret.icl b/mTaskInterpret.icl index 9685913..306f93d 100644 --- a/mTaskInterpret.icl +++ b/mTaskInterpret.icl @@ -27,12 +27,12 @@ encode (MTSds i v) = "s" +++ to16bit i +++ v +++ "\n" encode (MTTask to data) = "t" +++ to16bit to +++ to16bit (size data) +++ data +++ "\n" encode (MTUpd i v) = "u" +++ to16bit i +++ v +++ "\n" - decode :: String -> MTaskMSGRecv decode x | size x == 0 = MTEmpty = case x.[0] of '\0' = MTEmpty + 'm' = MTMessage x 'u' = MTPub (from16bit (x % (1,3))) (x % (3,5)) _ = abort ("Didn't understand message: " +++ join " " [toString (toInt c)\\c<-: x] +++ "\n") diff --git a/miTask.icl b/miTask.icl index e5483cc..d483490 100644 --- a/miTask.icl +++ b/miTask.icl @@ -1,24 +1,56 @@ module miTask import StdDebug, StdMisc - -from Text import class Text(concat,join,split), instance Text String +from StdFunc import flip import iTasks import mTask +from Text import class Text(startsWith,concat,split,join), instance Text String + +import Data.Tuple +import System.Directory + +import iTasks.UI.Definition + +import iTasks._Framework.TaskState +import iTasks._Framework.TaskServer +import iTasks._Framework.IWorld +import iTasks._Framework.Store + +import TTY + +derive class iTask Queue, TTYSettings, Parity, BaudRate, ByteSize derive class iTask MTaskMSGRecv, MTaskMSGSend +:: *Resource | TTYd !*TTY + Start :: *World -> *World -Start world = startEngine ( - enterInformation "Port Number?" [] - >>= \port->withShared ([], False, [], False) (mTaskTask port) - ) world +Start world = startEngine (withShared ([], False, [], False) mTaskTask) world //Start world = startEngine mTaskTask world +// +deviceSelectorNetwork :: Task (Int, String) +deviceSelectorNetwork = enterInformation "Port Number?" [] + -&&- enterInformation "Network address" [] + +deviceSelectorSerial :: Task (String, TTYSettings) +deviceSelectorSerial = accWorld getDevices + >>= \dl->(enterChoice "Device" [] dl -&&- deviceSettings) + where + deviceSettings = updateInformation "Settings" [] zero -mTaskTask :: Int (Shared ([MTaskMSGRecv],Bool,[MTaskMSGSend],Bool)) -> Task () -mTaskTask port ch = - syncNetworkChannel "localhost" port "\n" decode encode` ch ||- + getDevices :: !*World -> *(![String], !*World) + getDevices w = case readDirectory "/dev" w of + (Error (errcode, errmsg), w) = abort errmsg + (Ok entries, w) = (map ((+++) "/dev/") (filter isTTY entries), w) + where + isTTY s = not (isEmpty (filter (flip startsWith s) prefixes)) + prefixes = ["ttyS", "ttyACM", "ttyUSB", "tty.usbserial"] + +mTaskTask :: (Shared ([MTaskMSGRecv],Bool,[MTaskMSGSend],Bool)) -> Task () +mTaskTask ch = + deviceSelectorNetwork >>= \(p,h)->syncNetworkChannel h p "\n" decode encode` ch ||- +// deviceSelectorSerial >>= \(s,set)->syncSerialChannel s set decode` encode` ch ||- sendMsg msgs ch ||- ( ( @@ -32,6 +64,10 @@ mTaskTask port ch = | not (trace_tn (toString (toJSON m))) = undef = encode m + decode` m + | not (trace_tn (toString (toJSON m))) = undef + = decode m + messageShare :: Shared [String] messageShare = sharedStore "mTaskMessagesRecv" [] @@ -73,11 +109,11 @@ mTaskTask port ch = sdsShares = makeShares st - (msgs, st) = toMessages 500 (toRealByteCode (unMain bc)) + (msgs, st) = toMessages 1000 (toRealByteCode (unMain bc)) bc :: Main (ByteCode () Stmt) bc = sds \x=1 In sds \pinnetje=1 In {main = - x =. x +. lit 1 :. + x =. x +. pinnetje :. pub x :. IF (pinnetje ==. lit 1) ( analogWrite A0 (lit 1) :. @@ -103,11 +139,55 @@ mTaskTask port ch = makeShares :: BCState -> [(Int, Shared Int)] makeShares {sdss=[]} = [] makeShares s=:{sdss=[(i,d):xs]} = - [(i, sharedStore ("mTaskSDS-" +++ toString i) 0):makeShares {s & sdss=xs}] + [(i, sharedStore ("mTaskSDS-" +++ toString i) 1):makeShares {s & sdss=xs}] sendMsg :: [MTaskMSGSend] (Shared ([MTaskMSGRecv],Bool,[MTaskMSGSend],Bool)) -> Task () sendMsg m ch = upd (\(r,rs,s,ss)->(r,rs,s ++ m,ss)) ch @! () +syncSerialChannel :: String TTYSettings (String -> m) (n -> String) (Shared ([m],Bool,[n],Bool)) -> Task () | iTask m & iTask n +syncSerialChannel dev opts decodeFun encodeFun rw = Task eval + where + eval event evalOpts tree=:(TCInit taskId ts) iworld=:{IWorld|world} + = case TTYopen dev opts world of + (False, _, world) + # (err, world) = TTYerror world + = (ExceptionResult (exception err), {iworld & world=world}) + (True, tty, world) + # iworld = {iworld & world=world, resources=Just (TTYd tty)} + = case addBackgroundTask 42 (BackgroundTask (serialDeviceBackgroundTask rw decodeFun encodeFun)) iworld of + (Error e, iworld) = (ExceptionResult (exception "h"), iworld) + (Ok _, iworld) = (ValueResult NoValue {TaskEvalInfo|lastEvent=ts,removedTasks=[],refreshSensitive=True} NoRep (TCBasic taskId ts JSONNull False), iworld) + + eval _ _ tree=:(TCBasic _ ts _ _) iworld + = (ValueResult NoValue {TaskEvalInfo|lastEvent=ts,removedTasks=[],refreshSensitive=False} NoRep tree, iworld) + + eval event evalOpts tree=:(TCDestroy _) iworld=:{IWorld|resources,world} + # (TTYd tty) = fromJust resources + # (ok, world) = TTYclose tty world + # iworld = {iworld & world=world,resources=Nothing} + = case removeBackgroundTask 42 iworld of + (Error e, iworld) = (ExceptionResult (exception "h"), iworld) + (Ok _, iworld) = (DestroyedResult, iworld) + +serialDeviceBackgroundTask :: (Shared ([m],Bool,[n],Bool)) (String -> m) (n -> String) !*IWorld -> *IWorld +serialDeviceBackgroundTask rw en de iworld + = case read rw iworld of + (Error e, iworld) = iworld + (Ok (r,rs,s,ss), iworld) + # (Just (TTYd tty)) = iworld.resources + # tty = writet (map de s) tty + = case TTYavailable tty of + (False, tty) = {iworld & resources=Just (TTYd tty)} + (_, tty) + # (l, tty) = appFst en (TTYreadline tty) + # iworld = {iworld & resources=Just (TTYd tty)} + = snd (write (r ++ [l],rs,[],ss) rw iworld) + where + writet :: [String] !*TTY -> *TTY + writet [] t = t + writet [x:xs] t = writet xs (TTYwrite t x) + + syncNetworkChannel :: String Int String (String -> m) (n -> String) (Shared ([m],Bool,[n],Bool)) -> Task () | iTask m & iTask n syncNetworkChannel server port msgSeparator decodeFun encodeFun channel = tcpconnect server port channel {ConnectionHandlers|onConnect=onConnect,whileConnected=whileConnected,onDisconnect=onDisconnect} @! () -- 2.20.1