7 #include "stm32f7xx_hal.h"
11 #define SET_LED_RED GPIOB->BSRR = GPIO_PIN_14
12 #define RESET_LED_RED GPIOB->BSRR = GPIO_PIN_14 << 16
14 #define SET_LED_BLUE GPIOB->BSRR = GPIO_PIN_7
15 #define RESET_LED_BLUE GPIOB->BSRR = GPIO_PIN_7 << 16
17 #define SET_LED_GREEN GPIOB->BSRR = GPIO_PIN_0
18 #define RESET_LED_GREEN GPIOB->BSRR = GPIO_PIN_0 << 16
23 #include <netinet/in.h>
25 #include <sys/socket.h>
27 #include <sys/types.h>
31 #include "interface.h"
35 volatile char uartf
= 0;
53 void HAL_UART_TxCpltCallback(UART_HandleTypeDef
*UartHandle
)
58 void killHandler(int i
)
60 printf("%i caught, Bye...\n", i
);
64 void usage(FILE *o
, char *arg0
){
65 fprintf(o
, "Usage: %s [opts]\n\nOptions\n"
66 "-p PORT Custom port number, default: 8123\n" , arg0
);
75 if (gettimeofday(&tv1
, NULL
) == -1)
77 return tv1
.tv_sec
*1000 + tv1
.tv_usec
/1000;
81 bool input_available(){
83 if(HAL_UART_Receive(&huart3
, &bt
, 1, 1) == HAL_TIMEOUT
)
93 if (select(fd
+1, &fds
, NULL
, NULL
, &tv
) == -1)
95 if(!FD_ISSET(fd
, &fds
))
105 HAL_UART_Receive(&huart3
, &bt
, 1, 1000);
113 void write_byte(uint8_t b
)
116 HAL_UART_Transmit_DMA(&huart3
, &b
, 1);
122 void write_dpin(uint8_t i
, bool b
)
126 debug("dwrite %d: %d", i
, b
);
132 bool read_dpin(uint8_t i
)
137 debug("dread %d", i
);
143 void write_apin(uint8_t i
, uint8_t a
)
160 debug("awrite %d: %d", i
, a
);
166 uint8_t read_apin(uint8_t i
)
171 debug("aread %d", i
);
190 int port
= 8123, opti
= 1;
191 //Register signal handler
192 if(signal(SIGINT
, killHandler
) == SIG_ERR
){
193 die("Couldn't register signal handler...");
195 if(signal(SIGTERM
, killHandler
) == SIG_ERR
){
196 die("Couldn't register signal handler...");
198 //Command line arguments
200 if(strcmp((*gargv
)+opti
, "-h") == 0){
201 usage(stdout
, gargv
[0]);
203 } else if(strcmp(gargv
[opti
], "-p") == 0 && opti
+1<gargc
){
204 port
= atoi(gargv
[++opti
]);
206 die("Port numbers are > 1");
208 usage(stderr
, gargv
[0]);
214 //Open file descriptors
215 struct sockaddr_in sa
;
217 memset(&sa
, 0, sizeof(sa
));
218 sa
.sin_family
= AF_INET
;
219 sa
.sin_addr
.s_addr
= INADDR_ANY
;
220 sa
.sin_port
= htons(port
);
222 if((sock_fd
= socket(AF_INET
, SOCK_STREAM
, 0)) == -1)
224 if(bind(sock_fd
, (struct sockaddr
*)&sa
, sizeof(sa
)) == -1)
226 if(listen(sock_fd
, 10) == -1)
229 printf("Listening on %d\n", port
);
231 if((fd
= accept(sock_fd
, (struct sockaddr
*)NULL
, NULL
)) == -1)