diff --git a/software/linux/test.c b/software/linux/test.c index cf97351..688306f 100644 --- a/software/linux/test.c +++ b/software/linux/test.c @@ -25,6 +25,7 @@ int main(int argc, char const *argv[]) { while(!libsss7_can_send()); libsss7_send(msg); while(!libsss7_can_send()); + printf("Send done\n"); if(libsss7_send_failed()) { printf("Send failed\n"); } diff --git a/software/sss7core/sss7.c b/software/sss7core/sss7.c index dd652a6..6719347 100644 --- a/software/sss7core/sss7.c +++ b/software/sss7core/sss7.c @@ -240,9 +240,14 @@ void sss7_process_tx(void) { // Send the crc precalculated by sss_send sss7_send_byte(sss7_tx_crc); // Reset the state to idle - sss7_state = SSS7_IDLE; + sss7_state = SSS7_TX_FINALIZE; break; + case SSS7_TX_FINALIZE: + //Not much to do here + sss7_state = SSS7_IDLE; + break; + default: // Controlflow should never ever end up here. // Calling the tx handler while being in rx state is messed up. diff --git a/software/sss7core/sss7.h b/software/sss7core/sss7.h index e9ee99e..8d2c04a 100644 --- a/software/sss7core/sss7.h +++ b/software/sss7core/sss7.h @@ -27,6 +27,8 @@ enum sss7State { SSS7_TX_CRC, // Sending the last paylaod by has started, // waiting for the it to complete, to send crc byte + SSS7_TX_FINALIZE, // Wait until the crc byte has been read back + SSS7_RX_HEADER, // First header byte has been reived, waiting for the second one SSS7_RX_PAYLOAD, // Receiving payload bytes diff --git a/software/testutils/buffer_test b/software/testutils/buffer_test new file mode 100755 index 0000000..89f4dea Binary files /dev/null and b/software/testutils/buffer_test differ diff --git a/software/testutils/buffer_test.c b/software/testutils/buffer_test.c new file mode 100644 index 0000000..bd790bb --- /dev/null +++ b/software/testutils/buffer_test.c @@ -0,0 +1,81 @@ +#include +#include +#include +#include +#include + +#define buffer_elements 8 +#define buffer_size (buffer_elements + 1) + +int buffer[buffer_size]; +volatile uint8_t read_pos; +volatile uint8_t write_pos; + + +void *producer_function(void* arg) { + uint8_t foo = 1; + uint8_t next_pos = 0; + while(1) { + + + + + next_pos = (write_pos + 1) % buffer_size; + if(next_pos != read_pos) { + buffer[write_pos] = foo; + write_pos = next_pos; + buffer[write_pos] = -1; + printf("Produced %d\n", foo); + foo = (foo + 1) % 255; + } + + usleep((rand() % 500) * 100); + } +} + +void *consumer_function(void* arg) { + int bar = 0; + + while(1) { + + if(read_pos != write_pos) { + if(buffer[read_pos] != (bar + 1) % 255) { + printf("Error occured\n"); + printf("bar: %d\n", bar); + printf("foo: %d\n", buffer[read_pos]); + return 0; + } + + bar = buffer[read_pos]; + printf("Consumed: %d (%d)\n", buffer[read_pos], (write_pos - read_pos + buffer_size) % buffer_size); + read_pos = (read_pos + 1) % buffer_size; + } + + usleep((rand() % 500) * 100); + } +} + + +int main() { + pthread_t producer, consumer; + int ret; + + read_pos = 0; + write_pos = 0; + + ret = pthread_create(&producer, NULL, producer_function, NULL); + if(ret) { + fprintf(stderr,"Error - pthread_create() return code: %d\n", ret); + exit(-1); + } + + ret = pthread_create(&consumer, NULL, consumer_function, NULL); + if(ret) { + fprintf(stderr,"Error - pthread_create() return code: %d\n",ret); + exit(-1); + } + + pthread_join( consumer, NULL); + + return 0; +}