parent
14fd4e5eb5
commit
f17f48b75e
|
@ -25,6 +25,7 @@ int main(int argc, char const *argv[]) {
|
||||||
while(!libsss7_can_send());
|
while(!libsss7_can_send());
|
||||||
libsss7_send(msg);
|
libsss7_send(msg);
|
||||||
while(!libsss7_can_send());
|
while(!libsss7_can_send());
|
||||||
|
printf("Send done\n");
|
||||||
if(libsss7_send_failed()) {
|
if(libsss7_send_failed()) {
|
||||||
printf("Send failed\n");
|
printf("Send failed\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -240,6 +240,11 @@ void sss7_process_tx(void) {
|
||||||
// Send the crc precalculated by sss_send
|
// Send the crc precalculated by sss_send
|
||||||
sss7_send_byte(sss7_tx_crc);
|
sss7_send_byte(sss7_tx_crc);
|
||||||
// Reset the state to idle
|
// Reset the state to idle
|
||||||
|
sss7_state = SSS7_TX_FINALIZE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SSS7_TX_FINALIZE:
|
||||||
|
//Not much to do here
|
||||||
sss7_state = SSS7_IDLE;
|
sss7_state = SSS7_IDLE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@ enum sss7State {
|
||||||
SSS7_TX_CRC, // Sending the last paylaod by has started,
|
SSS7_TX_CRC, // Sending the last paylaod by has started,
|
||||||
// waiting for the it to complete, to send crc byte
|
// 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_HEADER, // First header byte has been reived, waiting for the second one
|
||||||
|
|
||||||
SSS7_RX_PAYLOAD, // Receiving payload bytes
|
SSS7_RX_PAYLOAD, // Receiving payload bytes
|
||||||
|
|
Binary file not shown.
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue