diff --git a/spi_linux_monitor/linux_test_end.c b/spi_linux_monitor/linux_test_end.c index 1de5f4d..0278043 100644 --- a/spi_linux_monitor/linux_test_end.c +++ b/spi_linux_monitor/linux_test_end.c @@ -39,12 +39,11 @@ static void pabort(const char *s) static const char *device = "/dev/spidev0.0"; static uint8_t mode; static uint8_t bits = 8; -static uint32_t speed = 8388608U; // TODO +static uint32_t speed = 8388608U; static uint16_t delay; #define SPI_TRANSFER_SIZE SPI_PACKET_LEN -//TODO make this less brittle extern uint8_t spi_in_buf[SPI_TRANSFER_SIZE], spi_out_buf[SPI_TRANSFER_SIZE]; void transfer(int fd) { diff --git a/spi_linux_test_endpoint/linux_test_end.c b/spi_linux_test_endpoint/linux_test_end.c index 4c9999a..eba517a 100644 --- a/spi_linux_test_endpoint/linux_test_end.c +++ b/spi_linux_test_endpoint/linux_test_end.c @@ -36,7 +36,7 @@ static void pabort(const char *s) static const char *device = "/dev/spidev0.0"; static uint8_t mode; static uint8_t bits = 8; -static uint32_t speed = 8388608U; // TODO +static uint32_t speed = 8388608U; static uint16_t delay; #define SPI_TRANSFER_SIZE SPI_PACKET_LEN diff --git a/spi_proto_lib/spi_proto.c b/spi_proto_lib/spi_proto.c index 19f8acb..7cd102d 100644 --- a/spi_proto_lib/spi_proto.c +++ b/spi_proto_lib/spi_proto.c @@ -172,7 +172,6 @@ spi_proto_prep_msg(struct spi_state *s, void *buf, size_t n) s->queue[s->first_unsent_seq].magic = SPI_PROTO_MAGIC_REAL; pack = &s->queue[s->first_unsent_seq]; - //TODO maybe bump seq? s->queue[s->first_unsent_seq].crc = spi_msg_crc(&s->queue[s->first_unsent_seq]); s->first_unsent_seq++; s->first_unsent_seq %= 16; diff --git a/spi_proto_lib/spi_proto_util.c b/spi_proto_lib/spi_proto_util.c index 5a8d838..653d92a 100644 --- a/spi_proto_lib/spi_proto_util.c +++ b/spi_proto_lib/spi_proto_util.c @@ -58,10 +58,11 @@ print_spi_state_full(struct spi_state *s) return; print_spi_state(s); if (s) { - //TODO print out spi queue + //print out spi queue for (unsigned int j = 0; j < SPI_MSG_QUEUE_SIZE; j++) { print_spi_packet(&s->queue[j]); } + //TODO is there anything else that isn't printed? } } diff --git a/spi_remote_host.c b/spi_remote_host.c index 8948f12..5825c6c 100644 --- a/spi_remote_host.c +++ b/spi_remote_host.c @@ -1,7 +1,3 @@ -//TODO temp for compilation -int unknown_chunk_type_msg_count; -extern int out_of_range_chunks; - #include #include #include "binary_semaphore.h" @@ -16,10 +12,11 @@ extern int out_of_range_chunks; #define CHUNK_LEN_GPIO CHUNK_LEN_GPIO_S2M //TODO temp for compilation +int unknown_chunk_type_msg_count; +extern int out_of_range_chunks; uint16_t bad_chunk_counter; -//TODO put semaphores on each endpoint to allow waiting on them, give on the semaphore for each value that is received. the give should be nonblocking //TODO possible issue, when the thread takes on the semaphore it could end up getting the value of a previous read that some other thread triggered //a sempahore with a queue where only one taker is released per give would solve this issue @@ -42,7 +39,7 @@ host_remote_init(struct host_remote *r) int remote_chunk_handler(struct host_remote *r, uint8_t *buf, size_t len) { - //TODO go through chunk types and bounce semaphores + //go through chunk types and bounce semaphores, maybe store a value if (len < 2) return -1; // length zero isn't a real chunk, length 1 can't carry data switch(buf[1]) { case CHUNK_TYPE_GPIO: diff --git a/spi_remote_host.h b/spi_remote_host.h index a72f889..3d1ec7c 100644 --- a/spi_remote_host.h +++ b/spi_remote_host.h @@ -1,6 +1,5 @@ //here for now, if we had multiple boards this would need to be separate -//TODO centralize in a config file -//TODO temp for compilation +//TODO centralize in a config file, temp for compilation #define SOLENOID_NUM 8 #define FLOW_NUM 1 #define GPIO_NUM 17 diff --git a/spi_slave.c b/spi_slave.c deleted file mode 100644 index 27634e8..0000000 --- a/spi_slave.c +++ /dev/null @@ -1,167 +0,0 @@ -/* -The communication protocol for letting the master use the peripherals of the slave is as follows -data direction is always known and so never marked in the protocol. -typeCode | id | ... - -typeCodes are -syntax error 0 TODO use this for info commands instead -GPIO 1 -ADC 2 - -TODO there should be a way to get maximum id of type, as well as a short description of a type-id pair. - -*/ - -struct spi_protocol_state { - bool waiting_on_deadman; - struct spi_prosthetic_msg deadman_pending_msg; - long deadman_deadline; -} - -struct spi_prosthetic_msg { - byte type_code; - byte id; //an id, in the case of deadman a non-sequential code - byte payload[0]; -} - -#define CONTROL_BAD_ID 0 -#define CONTROL_BAD_OPCODE 1 - -#define MTYPE_CONTROL 0 -#define MTYPE_GPIO 1 -#define MTYPE_ADC 2 -#define MTYPE_DEADMAN 3 -#define NUM_M_TYPE 4 - -typedef void (type_handler_function_t)(struct spi_prosthetic_msg *m); - -type_handler_function_t *type_handlers[NUM_M_TYPE] = { - handle_control, handle_gpio, handle_adc, handle_deadman -}; - -void -process(struct spi_protocol_state *s, struct spi_prosthetic_msg *m) -{ - if (waiting_on_deadman) { - //TODO store the message in the current deadman handler for later processing - s->deadman_pending_msg = *m; // TODO copy it - //TODO note that the waiting period begins now - } - if (m->type_code < NUM_M_TYPE) { - if (&& m->type_code != MTYPE_DEADMAN) { - type_handlers[m->type_code](m); - } else { - //TODO create a deadman handler for this message, or update an existing one - } - } -} - -struct gpio_spi_box { - GPIO_Type *base; - uint8_t pin_ix; // the mask is 1 << pin_ix - //int clock; //TODO other stuff that's needed - char *desc; // has a max length, should be something simple like "D6" -}; - -int -read_gpio(struct gpio_spi_box *g) -{ - return GPIO_ReadPinInput(g->base, g->pin_ix); -} -void -write_gpio(struct gpio_spi_box *g, int level) -{ - GPIO_WritePinOutput(g->base, g->pin_ix, level); -} -void -handle_gpio(struct spi_prosthetic_msg *m) -{ - /* - if valid id - case opcode of - read - read that gpio, compose a packet reporting it - write - write that gpio - settings change - apply the settings - description query - compose message with short description (e.g. D7) - other - compose unreckognized opcode message - else - compose invalid id opcode - */ - if (m->id < gpios.max_id) { - switch (m->payload[0]) { - case OP_GPIO_READ: - //read GPIO - unsigned char gpio_read_val = read_gpio(&gpios[m->id]); - //TODO compose response message - break; - case OP_GPIO_WRITE: - //DONE write the gpio, no response - write_gpio(&gpios[m->id], m->payload[1]); - break; - case OP_GPIO_SETTINGS: - //TODO apply the settings change, no response - break; - case OP_GPIO_DESCRIPTION: - //TODO compose response with description for this GPIO - break; - default: - //TODO compose BAD OPCODE response, with gpio id and opcode? - break; - } - } else { - //TODO compose BAD ID (GPIO) message - } -} - -void -handle_adc(struct spi_prosthetic_msg *m) -{ - /* - if valid id - case opcode of - read - read that adc, compose a packet reporting it - settings change - apply the settings - description query - compose message with short description (e.g. D7) - other - compose unrecognized opcode message - else - compose invalid id opcode - */ - if (m->id < adc.adc_num) { - switch (m->payload[0]) { - case OP_ADC_READ: - //TODO read the adc, compose a response - break; - case OP_ADC_SETTINGS: - //TODO apply the settings change, no response - break; - case OP_ADC_DESCRIPTION: - //TODO get the description, compose response - break; - default: - //TODO compose BAD OPCODE message with adc id and opcode - } - } else { - //TODO compose BAD ID (ADC) message - } -} - -void -compose_unfailing(struct spi_protocol_state *s, struct spi_prosthetic_msg *m /*TODO ARGS*/) -{ - /* - the key thing here is that this function is unfailing. This invariant is maintained by disabling receipt of messages if the queue fills. So when the program starts the queue is empty, and if messages are transmitted correctly the queue will never have more than one message in it. If messages are repeatedly dropped in both directions, the queue state won't change. If messages are dropped in one direction, the queue on one edge might fill up. If the side with the full queue stops accepting messages, things will balance unless the other side also suddenly has a full queue. - - TODO can this problem can be avoided by taking note of the SEQ/ACK data in each message rather than simply discarding it? - */ - - //TODO enqueue the message or whatever -} \ No newline at end of file diff --git a/test/test_chunks.c b/test/test_chunks.c index d8f58a5..8d5828c 100644 --- a/test/test_chunks.c +++ b/test/test_chunks.c @@ -70,7 +70,6 @@ num_free_chunks(struct waiting_chunk *c, size_t n) } //FIXED somehow the first chunk written is getting its length put into the spi_state num_sent_but_unconfirmed. -//TODO The issue was in the amm spi_proto, so it's basically junk at this point. Ice it void prepare_chunks(struct spi_state *s, unsigned char *msg, size_t msg_len, struct waiting_chunk *wait_chunks, size_t wait_len, int (*send_chunk)(uint8_t *buf, size_t len))