Added SSS7_TX_FINALIZE state

Fixes #2
This commit is contained in:
Sebastian 2016-12-22 19:00:53 +01:00
parent 14fd4e5eb5
commit f17f48b75e
5 changed files with 90 additions and 1 deletions

View File

@ -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");
}

View File

@ -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.

View File

@ -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

BIN
software/testutils/buffer_test Executable file

Binary file not shown.

View File

@ -0,0 +1,81 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <pthread.h>
#include <unistd.h>
#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;
}