From: Mart Lubbers Date: Sun, 15 Jan 2017 19:03:46 +0000 (+0100) Subject: update X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=8d881526eee2134ade0eb6f3b554876ecced2db6;p=mTask.git update --- diff --git a/Makefile b/Makefile index ddb4dfc..cef4b6a 100644 --- a/Makefile +++ b/Makefile @@ -35,4 +35,4 @@ int/mTaskSymbols.h: mTaskMakeSymbols clean: - $(RM) -r $(BINARIES) Clean\ System\ Files + $(RM) -r $(BINARIES) Clean\ System\ Files miTask-data diff --git a/int/nucleo-f767-blinky/src/interface.c b/int/nucleo-f767-blinky/src/interface.c index 96077b0..70e3326 100644 --- a/int/nucleo-f767-blinky/src/interface.c +++ b/int/nucleo-f767-blinky/src/interface.c @@ -5,8 +5,18 @@ #ifdef STM32F767xx #include "stm32f7xx_hal.h" -#include "gpio.h" #include "usart.h" +#include "gpio.h" + +#define SET_LED_RED GPIOB->BSRR = GPIO_PIN_14 +#define RESET_LED_RED GPIOB->BSRR = GPIO_PIN_14 << 16 + +#define SET_LED_BLUE GPIOB->BSRR = GPIO_PIN_7 +#define RESET_LED_BLUE GPIOB->BSRR = GPIO_PIN_7 << 16 + +#define SET_LED_GREEN GPIOB->BSRR = GPIO_PIN_0 +#define RESET_LED_GREEN GPIOB->BSRR = GPIO_PIN_0 << 16 + #else #include #include @@ -20,15 +30,6 @@ #include "interface.h" -#define SET_LED_RED GPIOB->BSRR = GPIO_PIN_14 -#define RESET_LED_RED GPIOB->BSRR = GPIO_PIN_14 << 16 - -#define SET_LED_BLUE GPIOB->BSRR = GPIO_PIN_7 -#define RESET_LED_BLUE GPIOB->BSRR = GPIO_PIN_7 << 16 - -#define SET_LED_GREEN GPIOB->BSRR = GPIO_PIN_0 -#define RESET_LED_GREEN GPIOB->BSRR = GPIO_PIN_0 << 16 - //Globals #ifdef STM32F767xx volatile char uartf = 0; @@ -79,6 +80,8 @@ long millis() { bool input_available(){ #ifdef STM32F767xx + if(HAL_UART_Receive(&huart3, &bt, 1, 1) == HAL_TIMEOUT) + return false; return true; #else struct timeval tv; @@ -89,7 +92,10 @@ bool input_available(){ FD_SET(fd, &fds); if (select(fd+1, &fds, NULL, NULL, &tv) == -1) pdie("select"); - return FD_ISSET(fd, &fds); + if(!FD_ISSET(fd, &fds)) + return false; + read(fd, &bt, 1); + return true; #endif } @@ -97,7 +103,7 @@ uint8_t read_byte() { #ifdef STM32F767xx HAL_UART_Receive(&huart3, &bt, 1, 1000); - return 0; + return bt; #else read(fd, &bt, 1); return bt; @@ -117,8 +123,10 @@ void write_dpin(uint8_t i, bool b) { #ifdef STM32F767xx #else - debug("dwrite %d: %d\n", i, b); + debug("dwrite %d: %d", i, b); #endif + (void) i; + (void) b; } bool read_dpin(uint8_t i) @@ -126,9 +134,10 @@ bool read_dpin(uint8_t i) #ifdef STM32F767xx return false; #else - debug("dread %d\n", i); + debug("dread %d", i); return false; #endif + (void) i; } void write_apin(uint8_t i, uint8_t a) @@ -148,8 +157,10 @@ void write_apin(uint8_t i, uint8_t a) SET_LED_GREEN; } #else - debug("awrite %d: %d\n", i, a); + debug("awrite %d: %d", i, a); #endif + (void) a; + (void) i; } uint8_t read_apin(uint8_t i) @@ -157,9 +168,10 @@ uint8_t read_apin(uint8_t i) #ifdef STM32F767xx return 0; #else - debug("aread %d\n", i); + debug("aread %d", i); return 0; #endif + (void) i; } void delay(long ms) @@ -178,10 +190,10 @@ void setup() int port = 8123, opti = 1; //Register signal handler if(signal(SIGINT, killHandler) == SIG_ERR){ - die("Couldn't register signal handler...\n"); + die("Couldn't register signal handler..."); } if(signal(SIGTERM, killHandler) == SIG_ERR){ - die("Couldn't register signal handler...\n"); + die("Couldn't register signal handler..."); } //Command line arguments while(opti < gargc){ @@ -191,7 +203,7 @@ void setup() } else if(strcmp(gargv[opti], "-p") == 0 && opti+1 1\n"); + die("Port numbers are > 1"); } else { usage(stderr, gargv[0]); exit(EXIT_FAILURE); diff --git a/int/nucleo-f767-blinky/src/interface.h b/int/nucleo-f767-blinky/src/interface.h index 23e5b59..8b29921 100644 --- a/int/nucleo-f767-blinky/src/interface.h +++ b/int/nucleo-f767-blinky/src/interface.h @@ -19,6 +19,7 @@ extern char buf[128]; extern int gargc; extern char **gargv; #endif +extern uint8_t bt; uint8_t read_byte(); void write_byte(uint8_t b); @@ -38,7 +39,7 @@ void setup(); #define read16() 256*read_byte() + read_byte() #ifdef STM32F767xx #define debug(s, ...) {\ - sprintf(buf, s, ##__VA_ARGS__);\ + sprintf(buf, "m" s "\r\n", ##__VA_ARGS__);\ HAL_UART_Transmit(&huart3, (uint8_t*)buf, strlen(buf), 1000);\ } #define pdie(s) ; @@ -46,13 +47,13 @@ void setup(); #else #ifdef DEBUG -#define debug(s, ...) printf(s, ##__VA_ARGS__); +#define debug(s, ...) printf(s "\n", ##__VA_ARGS__); #else #define debug(s, ...) ; #endif #define pdie(s) {perror(s); exit(1);} -#define die(s, ...) {fprintf(stderr, s, ##__VA_ARGS__); exit(1);} +#define die(s, ...) {fprintf(stderr, s "\n", ##__VA_ARGS__); exit(1);} #endif #endif diff --git a/int/nucleo-f767-blinky/src/interpret.c b/int/nucleo-f767-blinky/src/interpret.c index ad9cdad..e124589 100644 --- a/int/nucleo-f767-blinky/src/interpret.c +++ b/int/nucleo-f767-blinky/src/interpret.c @@ -11,7 +11,7 @@ #define trace(op, ...) ; #else #define trace(op, ...) ; -//printf("pc: %d, sp: %d, op: " op, pc, sp, ##__VA_ARGS__); +//printf("pc: %d, sp: %d, op: " op "\n", pc, sp, ##__VA_ARGS__); #endif void run_task(struct task *t) @@ -21,123 +21,123 @@ void run_task(struct task *t) int pc = 0; int sp = 0; char stack[STACKSIZE] = {0}; - debug("Running task with length: %d\n", plen); + debug("Running task with length: %d", plen); while(pc != plen){ - debug("program: %d\n", program[pc]); - debug("stack: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", + debug("program: %d", program[pc]); + debug("stack: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", 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"); + case BCNOP: trace("nop"); break; - case BCLAB: trace("label: 0x%02x!!!!!!\n", program[pc]); + case BCLAB: trace("label: 0x%02x!!!!!!", program[pc]); pc++; break; - case BCPUSH: trace("push %d\n", program[pc]*265+program[pc+1]); + case BCPUSH: trace("push %d", program[pc]*265+program[pc+1]); stack[sp++] = program[pc]*265 + program[pc+1]; pc+=2; break; - case BCPOP: trace("pop\n"); + case BCPOP: trace("pop"); sp--; break; - case BCSDSSTORE: trace("sds store: %d\n", program[pc]); + case BCSDSSTORE: trace("sds store: %d", program[pc]); sds_store(program[pc++], stack[--sp]); break; - case BCSDSFETCH: trace("sds fetch: %d\n", program[pc]); + case BCSDSFETCH: trace("sds fetch: %d", program[pc]); stack[sp++] = sds_fetch(program[pc++]); break; - case BCSDSPUBLISH: trace("sds publish %d\n", program[pc]); + case BCSDSPUBLISH: trace("sds publish %d", program[pc]); sds_publish(program[pc++]); break; - case BCNOT: trace("not\n"); + case BCNOT: trace("not"); stack[sp] = stack[sp] > 0 ? 0 : 1; break; - case BCADD: trace("add\n"); + case BCADD: trace("add"); stack[sp-2] = stack[sp-1] + stack[sp-2]; sp -= 1; break; - case BCSUB: trace("sub\n"); + case BCSUB: trace("sub"); stack[sp-2] = stack[sp-1] - stack[sp-2]; sp -= 1; break; - case BCMUL: trace("mul\n"); + case BCMUL: trace("mul"); stack[sp-2] = stack[sp-1] * stack[sp-2]; sp -= 1; break; - case BCDIV: trace("div\n"); + case BCDIV: trace("div"); stack[sp-2] = stack[sp-1] / stack[sp-2]; sp -= 1; break; - case BCAND: trace("and\n"); + case BCAND: trace("and"); stack[sp-2] = stack[sp-1] && stack[sp-2]; sp -= 1; break; - case BCOR: trace("or\n"); + case BCOR: trace("or"); stack[sp-2] = stack[sp-1] || stack[sp-2]; sp -= 1; break; - case BCEQ: trace("eq\n"); + case BCEQ: trace("eq"); stack[sp-2] = stack[sp-1] == stack[sp-2]; sp -= 1; break; - case BCNEQ: trace("neq\n"); + case BCNEQ: trace("neq"); stack[sp-2] = stack[sp-1] != stack[sp-2]; sp -= 1; break; - case BCLES: trace("les\n"); + case BCLES: trace("les"); stack[sp-2] = stack[sp-1] < stack[sp-2]; sp -= 1; break; - case BCGRE: trace("gre\n"); + case BCGRE: trace("gre"); stack[sp-2] = stack[sp-1] > stack[sp-2]; sp -= 1; break; - case BCLEQ: trace("leq\n"); + case BCLEQ: trace("leq"); stack[sp-2] = stack[sp-1] <= stack[sp-2]; sp -= 1; break; - case BCGEQ: trace("geq\n"); + case BCGEQ: trace("geq"); stack[sp-2] = stack[sp-1] >= stack[sp-2]; sp -= 1; break; - case BCJMP: trace("jmp to %d\n", program[pc]); + case BCJMP: trace("jmp to %d", program[pc]); pc = program[pc]-1; break; - case BCJMPT: trace("jmpt to %d\n", program[pc]); + case BCJMPT: trace("jmpt to %d", program[pc]); pc = stack[--sp] ? program[pc]-1 : pc+1; break; - case BCJMPF: trace("jmpf to %d\n", program[pc]); + case BCJMPF: trace("jmpf to %d", program[pc]); pc = stack[--sp] ? pc+1 : program[pc]-1; break; - case BCSERIALAVAIL: trace("SerialAvailable()\n"); + case BCSERIALAVAIL: trace("SerialAvailable()"); break; - case BCSERIALPRINT: trace("SerialPrint()\n"); + case BCSERIALPRINT: trace("SerialPrint()"); break; - case BCSERIALPRINTLN: trace("SerialPrintln()\n"); + case BCSERIALPRINTLN: trace("SerialPrintln()"); break; - case BCSERIALREAD: trace("SerialRead()\n"); + case BCSERIALREAD: trace("SerialRead()"); break; - case BCSERIALPARSEINT: trace("SerialParseInt()\n"); + case BCSERIALPARSEINT: trace("SerialParseInt()"); break; - case BCANALOGREAD: trace("AnalogRead(%d)\n", program[pc]); + case BCANALOGREAD: trace("AnalogRead(%d)", program[pc]); stack[sp++] = read_apin(program[pc++]); break; - case BCANALOGWRITE: trace("AnalogWrite(%d)\n", program[pc]); + case BCANALOGWRITE: trace("AnalogWrite(%d)", program[pc]); write_apin(program[pc++], stack[sp-1]); sp--; break; - case BCDIGITALREAD: trace("DigitalRead(%d)\n", program[pc]); + case BCDIGITALREAD: trace("DigitalRead(%d)", program[pc]); stack[sp++] = read_dpin(program[pc++]); break; - case BCDIGITALWRITE: trace("DigitalWrite(%d)\n", program[pc]); + case BCDIGITALWRITE: trace("DigitalWrite(%d)", program[pc]); write_dpin(program[pc++], stack[sp-1]); sp--; break; default: - trace("unrecognized\n"); - die("Unrecognized command: %d\n", program[pc-1]); + trace("unrecognized"); + die("Unrecognized command: %d", program[pc-1]); } } - debug("Task terminated\n"); + debug("Task terminated"); } diff --git a/int/nucleo-f767-blinky/src/main.c b/int/nucleo-f767-blinky/src/main.c index 0be5c0f..b00f73a 100644 --- a/int/nucleo-f767-blinky/src/main.c +++ b/int/nucleo-f767-blinky/src/main.c @@ -32,30 +32,33 @@ void read_message() { //Find next task - uint8_t c = read_byte(); - debug("Receiving input: %c\n", c); - switch(c){ - case MSG_SDS_SPEC: - debug("Receiving an sds\n"); - sds_register(); - break; - case MSG_SDS_UPD: - debug("Receiving an sds\n"); - //TODO do something with the return value - sds_update(); - break; - case MSG_DEL_TASK: - debug("Receiving a delete task request\n"); - task_delete(); - break; - case MSG_GET_TASK: - debug("Receiving a task\n"); - c = task_register(); - break; - case '\n': - break; - default: - debug("Unknown message: %X\n", c); + if(input_available()){ + //debug("Receiving input: %c\n", c); + switch(bt){ + case MSG_SDS_SPEC: + debug("Receiving an sds"); + sds_register(); + break; + case MSG_SDS_UPD: + debug("Receiving an sds"); + //TODO do something with the return value + sds_update(); + break; + case MSG_DEL_TASK: + debug("Receiving a delete task request"); + task_delete(); + break; + case MSG_GET_TASK: + debug("Receiving a task"); + task_register(); + break; + case '\0': + break; + case '\n': + break; + default: + debug("Unknown message: %X", bt); + } } } @@ -65,8 +68,7 @@ void loop() long cyclestart; struct task *curtask; - if(input_available()) - read_message(); + read_message(); //Run tasks cyclestart = millis(); @@ -81,7 +83,7 @@ void loop() // debug("Task %d not scheduled\n", ct); continue; } - debug("Current task to run: %d\n", ct); + debug("Current task to run: %d", ct); run_task(curtask); curtask->lastrun = cyclestart; write_byte('\n'); @@ -91,12 +93,14 @@ void loop() #ifdef STM32F767xx char s[128] = ""; int main1(void){ + uint8_t bt; + HAL_UART_Receive(&huart3, &bt, 1, 100000); #else int main(int argc, char *argv[]){ gargc = argc; gargv = argv; #endif - debug("booting up\r\n"); + debug("booting up"); //Initialize systems setup(); @@ -107,7 +111,7 @@ int main(int argc, char *argv[]){ while(true){ //Check for new tasks - debug("loop\r\n"); +// debug("loop\r\n"); loop(); delay(100); } diff --git a/int/nucleo-f767-blinky/src/sds.c b/int/nucleo-f767-blinky/src/sds.c index 1300c06..cd6452b 100644 --- a/int/nucleo-f767-blinky/src/sds.c +++ b/int/nucleo-f767-blinky/src/sds.c @@ -26,7 +26,7 @@ void sds_register() break; if(cs == MAXSDSS) - die("Trying to add too much sdss...\n"); + die("Trying to add too much sdss..."); memset(&sdss[cs], 0, sizeof(struct sds)); //Read identifier @@ -34,7 +34,7 @@ void sds_register() //Read value sdss[cs].value = read16(); - debug("\nReceived sds %d: %d\n", sdss[cs].id, sdss[cs].value); + debug("Received sds %d: %d", sdss[cs].id, sdss[cs].value); sdss[cs].used = true; } @@ -50,9 +50,9 @@ bool sds_update() if(sdss[cs].id == id){ //Read value sdss[cs].value = read16(); - debug("\nReceived sds update %d: %d\n", + debug("Received sds update %d: %d", sdss[cs].id, sdss[cs].value); - printf("\nReceived sds update %d: %d\n", + printf("Received sds update %d: %d", sdss[cs].id, sdss[cs].value); return true; } @@ -65,7 +65,7 @@ void sds_publish(int id) uint8_t cs; for(cs = 0; cs MAXTASKSIZE) - die("Task is too long: %d\n", tasks[ct].tlen); + die("Task is too long: %d", tasks[ct].tlen); //Read task bytecode for(unsigned int i = 0; i Task () mTaskTask ch = -// deviceSelectorNetwork >>= \(p,h)->syncNetworkChannel h p "\n" decode encode` ch ||- - deviceSelectorSerial >>= \(s,set)->syncSerialChannel s set decode` encode` ch ||- + deviceSelectorNetwork >>= \(p,h)->syncNetworkChannel h p "\n" decode encode ch ||- +// deviceSelectorSerial >>= \(s,set)->syncSerialChannel s set decode encode ch ||- sendMsg msgs ch ||- ( ( @@ -60,14 +60,6 @@ mTaskTask ch = ) >>* [OnAction ActionFinish (always shutDown)] ) where - encode` m - | 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" [] @@ -170,22 +162,27 @@ syncSerialChannel dev opts decodeFun encodeFun rw = Task eval (Ok _, iworld) = (DestroyedResult, iworld) serialDeviceBackgroundTask :: (Shared ([m],Bool,[n],Bool)) (String -> m) (n -> String) !*IWorld -> *IWorld -serialDeviceBackgroundTask rw en de iworld +serialDeviceBackgroundTask rw de en iworld = case read rw iworld of - (Error e, iworld) = iworld + (Error e, iworld) = abort "share couldn't be read" (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 = writet (map en s) tty + # (ml, tty) = case TTYavailable tty of + (False, tty) = ([], tty) (_, tty) - # (l, tty) = appFst en (TTYreadline tty) - # iworld = {iworld & resources=Just (TTYd tty)} - = snd (write (r ++ [l],rs,[],ss) rw iworld) + # (l, tty) = TTYreadline tty + = ([de l], tty) + # iworld = {iworld & resources=Just (TTYd tty)} + = case write (r++ml,rs,[],ss) rw iworld of + (Error e, iworld) = abort "share couldn't be written" + (Ok _, iworld) = case notify rw iworld of + (Error e, iworld) = abort "share couldn't be notified" + (Ok _, iworld) = iworld where writet :: [String] !*TTY -> *TTY writet [] t = t - writet [x:xs] t = writet xs (TTYwrite t x) + writet [x:xs] t = writet xs (TTYwrite x t) syncNetworkChannel :: String Int String (String -> m) (n -> String) (Shared ([m],Bool,[n],Bool)) -> Task () | iTask m & iTask n