|
@@ -9,40 +9,85 @@
|
|
#include <avr/io.h>
|
|
#include <avr/io.h>
|
|
#include <avr/interrupt.h>
|
|
#include <avr/interrupt.h>
|
|
#include <util/delay.h>
|
|
#include <util/delay.h>
|
|
|
|
+#include <stddef.h>
|
|
#include <stdbool.h>
|
|
#include <stdbool.h>
|
|
#include "serial.h"
|
|
#include "serial.h"
|
|
|
|
+
|
|
|
|
|
|
#ifdef USE_SERIAL
|
|
#ifdef USE_SERIAL
|
|
|
|
|
|
|
|
+#ifndef SERIAL_USE_MULTI_TRANSACTION
|
|
|
|
+
|
|
|
|
+ #if SERIAL_SLAVE_BUFFER_LENGTH > 0
|
|
|
|
+ uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0};
|
|
|
|
+ #endif
|
|
|
|
+ #if SERIAL_MASTER_BUFFER_LENGTH > 0
|
|
|
|
+ uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0};
|
|
|
|
+ #endif
|
|
|
|
+ uint8_t volatile status0 = 0;
|
|
|
|
+
|
|
|
|
+SSTD_t transactions[] = {
|
|
|
|
+ { (uint8_t *)&status0,
|
|
|
|
+ #if SERIAL_MASTER_BUFFER_LENGTH > 0
|
|
|
|
+ sizeof(serial_master_buffer), (uint8_t *)serial_master_buffer,
|
|
|
|
+ #else
|
|
|
|
+ 0, (uint8_t *)NULL,
|
|
|
|
+ #endif
|
|
|
|
+ #if SERIAL_SLAVE_BUFFER_LENGTH > 0
|
|
|
|
+ sizeof(serial_slave_buffer), (uint8_t *)serial_slave_buffer
|
|
|
|
+ #else
|
|
|
|
+ 0, (uint8_t *)NULL,
|
|
|
|
+ #endif
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+void serial_master_init(void)
|
|
|
|
+{ soft_serial_initiator_init(transactions); }
|
|
|
|
+
|
|
|
|
+void serial_slave_init(void)
|
|
|
|
+{ soft_serial_target_init(transactions); }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+int serial_update_buffers()
|
|
|
|
+{ return soft_serial_transaction(); }
|
|
|
|
+
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+#define ALWAYS_INLINE __attribute__((always_inline))
|
|
|
|
+#define NO_INLINE __attribute__((noinline))
|
|
#define _delay_sub_us(x) __builtin_avr_delay_cycles(x)
|
|
#define _delay_sub_us(x) __builtin_avr_delay_cycles(x)
|
|
|
|
|
|
|
|
|
|
|
|
+#define TID_SEND_ADJUST 14
|
|
|
|
+
|
|
#define SELECT_SERIAL_SPEED 1
|
|
#define SELECT_SERIAL_SPEED 1
|
|
#if SELECT_SERIAL_SPEED == 0
|
|
#if SELECT_SERIAL_SPEED == 0
|
|
|
|
|
|
#define SERIAL_DELAY 4
|
|
#define SERIAL_DELAY 4
|
|
- #define READ_WRITE_START_ADJUST 30
|
|
+ #define READ_WRITE_START_ADJUST 33
|
|
- #define READ_WRITE_WIDTH_ADJUST 10
|
|
+ #define READ_WRITE_WIDTH_ADJUST 3
|
|
#elif SELECT_SERIAL_SPEED == 1
|
|
#elif SELECT_SERIAL_SPEED == 1
|
|
|
|
|
|
#define SERIAL_DELAY 6
|
|
#define SERIAL_DELAY 6
|
|
- #define READ_WRITE_START_ADJUST 23
|
|
+ #define READ_WRITE_START_ADJUST 30
|
|
- #define READ_WRITE_WIDTH_ADJUST 10
|
|
+ #define READ_WRITE_WIDTH_ADJUST 3
|
|
#elif SELECT_SERIAL_SPEED == 2
|
|
#elif SELECT_SERIAL_SPEED == 2
|
|
|
|
|
|
#define SERIAL_DELAY 12
|
|
#define SERIAL_DELAY 12
|
|
- #define READ_WRITE_START_ADJUST 25
|
|
+ #define READ_WRITE_START_ADJUST 30
|
|
- #define READ_WRITE_WIDTH_ADJUST 10
|
|
+ #define READ_WRITE_WIDTH_ADJUST 3
|
|
#elif SELECT_SERIAL_SPEED == 3
|
|
#elif SELECT_SERIAL_SPEED == 3
|
|
|
|
|
|
#define SERIAL_DELAY 24
|
|
#define SERIAL_DELAY 24
|
|
- #define READ_WRITE_START_ADJUST 25
|
|
+ #define READ_WRITE_START_ADJUST 30
|
|
- #define READ_WRITE_WIDTH_ADJUST 10
|
|
+ #define READ_WRITE_WIDTH_ADJUST 3
|
|
#elif SELECT_SERIAL_SPEED == 4
|
|
#elif SELECT_SERIAL_SPEED == 4
|
|
|
|
|
|
#define SERIAL_DELAY 50
|
|
#define SERIAL_DELAY 50
|
|
- #define READ_WRITE_START_ADJUST 25
|
|
+ #define READ_WRITE_START_ADJUST 30
|
|
- #define READ_WRITE_WIDTH_ADJUST 10
|
|
+ #define READ_WRITE_WIDTH_ADJUST 3
|
|
#else
|
|
#else
|
|
#error Illegal Serial Speed
|
|
#error Illegal Serial Speed
|
|
#endif
|
|
#endif
|
|
@@ -51,14 +96,15 @@
|
|
#define SERIAL_DELAY_HALF1 (SERIAL_DELAY/2)
|
|
#define SERIAL_DELAY_HALF1 (SERIAL_DELAY/2)
|
|
#define SERIAL_DELAY_HALF2 (SERIAL_DELAY - SERIAL_DELAY/2)
|
|
#define SERIAL_DELAY_HALF2 (SERIAL_DELAY - SERIAL_DELAY/2)
|
|
|
|
|
|
-#define SLAVE_INT_WIDTH 1
|
|
+#define SLAVE_INT_WIDTH_US 1
|
|
-#define SLAVE_INT_RESPONSE_TIME SERIAL_DELAY
|
|
+#ifndef SERIAL_USE_MULTI_TRANSACTION
|
|
-
|
|
+ #define SLAVE_INT_RESPONSE_TIME SERIAL_DELAY
|
|
-uint8_t volatile serial_slave_buffer[SERIAL_SLAVE_BUFFER_LENGTH] = {0};
|
|
+#else
|
|
-uint8_t volatile serial_master_buffer[SERIAL_MASTER_BUFFER_LENGTH] = {0};
|
|
+ #define SLAVE_INT_ACK_WIDTH_UNIT 2
|
|
|
|
+ #define SLAVE_INT_ACK_WIDTH 4
|
|
|
|
+#endif
|
|
|
|
|
|
-#define SLAVE_DATA_CORRUPT (1<<0)
|
|
+static SSTD_t *Transaction_table = NULL;
|
|
-volatile uint8_t status = 0;
|
|
|
|
|
|
|
|
inline static
|
|
inline static
|
|
void serial_delay(void) {
|
|
void serial_delay(void) {
|
|
@@ -75,12 +121,14 @@ void serial_delay_half2(void) {
|
|
_delay_us(SERIAL_DELAY_HALF2);
|
|
_delay_us(SERIAL_DELAY_HALF2);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+inline static void serial_output(void) ALWAYS_INLINE;
|
|
inline static
|
|
inline static
|
|
void serial_output(void) {
|
|
void serial_output(void) {
|
|
SERIAL_PIN_DDR |= SERIAL_PIN_MASK;
|
|
SERIAL_PIN_DDR |= SERIAL_PIN_MASK;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+inline static void serial_input_with_pullup(void) ALWAYS_INLINE;
|
|
inline static
|
|
inline static
|
|
void serial_input_with_pullup(void) {
|
|
void serial_input_with_pullup(void) {
|
|
SERIAL_PIN_DDR &= ~SERIAL_PIN_MASK;
|
|
SERIAL_PIN_DDR &= ~SERIAL_PIN_MASK;
|
|
@@ -92,50 +140,58 @@ uint8_t serial_read_pin(void) {
|
|
return !!(SERIAL_PIN_INPUT & SERIAL_PIN_MASK);
|
|
return !!(SERIAL_PIN_INPUT & SERIAL_PIN_MASK);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+inline static void serial_low(void) ALWAYS_INLINE;
|
|
inline static
|
|
inline static
|
|
void serial_low(void) {
|
|
void serial_low(void) {
|
|
SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK;
|
|
SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+inline static void serial_high(void) ALWAYS_INLINE;
|
|
inline static
|
|
inline static
|
|
void serial_high(void) {
|
|
void serial_high(void) {
|
|
SERIAL_PIN_PORT |= SERIAL_PIN_MASK;
|
|
SERIAL_PIN_PORT |= SERIAL_PIN_MASK;
|
|
}
|
|
}
|
|
|
|
|
|
-void serial_master_init(void) {
|
|
+void soft_serial_initiator_init(SSTD_t *sstd_table)
|
|
- serial_output();
|
|
+{
|
|
- serial_high();
|
|
+ Transaction_table = sstd_table;
|
|
|
|
+ serial_output();
|
|
|
|
+ serial_high();
|
|
}
|
|
}
|
|
|
|
|
|
-void serial_slave_init(void) {
|
|
+void soft_serial_target_init(SSTD_t *sstd_table)
|
|
- serial_input_with_pullup();
|
|
+{
|
|
|
|
+ Transaction_table = sstd_table;
|
|
|
|
+ serial_input_with_pullup();
|
|
|
|
|
|
#if SERIAL_PIN_MASK == _BV(PD0)
|
|
#if SERIAL_PIN_MASK == _BV(PD0)
|
|
-
|
|
+
|
|
- EIMSK |= _BV(INT0);
|
|
+ EIMSK |= _BV(INT0);
|
|
-
|
|
+
|
|
- EICRA &= ~(_BV(ISC00) | _BV(ISC01));
|
|
+ EICRA &= ~(_BV(ISC00) | _BV(ISC01));
|
|
#elif SERIAL_PIN_MASK == _BV(PD2)
|
|
#elif SERIAL_PIN_MASK == _BV(PD2)
|
|
-
|
|
+
|
|
- EIMSK |= _BV(INT2);
|
|
+ EIMSK |= _BV(INT2);
|
|
-
|
|
+
|
|
- EICRA &= ~(_BV(ISC20) | _BV(ISC21));
|
|
+ EICRA &= ~(_BV(ISC20) | _BV(ISC21));
|
|
#else
|
|
#else
|
|
#error unknown SERIAL_PIN_MASK value
|
|
#error unknown SERIAL_PIN_MASK value
|
|
#endif
|
|
#endif
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+static void sync_recv(void) NO_INLINE;
|
|
static
|
|
static
|
|
void sync_recv(void) {
|
|
void sync_recv(void) {
|
|
- for (int i = 0; i < SERIAL_DELAY*5 && serial_read_pin(); i++ ) {
|
|
+ for (uint8_t i = 0; i < SERIAL_DELAY*5 && serial_read_pin(); i++ ) {
|
|
}
|
|
}
|
|
-
|
|
+
|
|
-
|
|
+
|
|
while (!serial_read_pin());
|
|
while (!serial_read_pin());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+static void sync_send(void)NO_INLINE;
|
|
static
|
|
static
|
|
void sync_send(void) {
|
|
void sync_send(void) {
|
|
serial_low();
|
|
serial_low();
|
|
@@ -144,152 +200,245 @@ void sync_send(void) {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-static
|
|
+static uint8_t serial_read_chunk(uint8_t *pterrcount, uint8_t bit) NO_INLINE;
|
|
-uint8_t serial_read_byte(void) {
|
|
+static uint8_t serial_read_chunk(uint8_t *pterrcount, uint8_t bit) {
|
|
- uint8_t byte = 0;
|
|
+ uint8_t byte, i, p, pb;
|
|
|
|
+
|
|
_delay_sub_us(READ_WRITE_START_ADJUST);
|
|
_delay_sub_us(READ_WRITE_START_ADJUST);
|
|
- for ( uint8_t i = 0; i < 8; ++i) {
|
|
+ for( i = 0, byte = 0, p = 0; i < bit; i++ ) {
|
|
- serial_delay_half1();
|
|
+ serial_delay_half1();
|
|
- byte = (byte << 1) | serial_read_pin();
|
|
+ if( serial_read_pin() ) {
|
|
- _delay_sub_us(READ_WRITE_WIDTH_ADJUST);
|
|
+ byte = (byte << 1) | 1; p ^= 1;
|
|
- serial_delay_half2();
|
|
+ } else {
|
|
|
|
+ byte = (byte << 1) | 0; p ^= 0;
|
|
|
|
+ }
|
|
|
|
+ _delay_sub_us(READ_WRITE_WIDTH_ADJUST);
|
|
|
|
+ serial_delay_half2();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ serial_delay_half1();
|
|
|
|
+ pb = serial_read_pin();
|
|
|
|
+ _delay_sub_us(READ_WRITE_WIDTH_ADJUST);
|
|
|
|
+ serial_delay_half2();
|
|
|
|
+
|
|
|
|
+ *pterrcount += (p != pb)? 1 : 0;
|
|
|
|
+
|
|
return byte;
|
|
return byte;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-static
|
|
+void serial_write_chunk(uint8_t data, uint8_t bit) NO_INLINE;
|
|
-void serial_write_byte(uint8_t data) {
|
|
+void serial_write_chunk(uint8_t data, uint8_t bit) {
|
|
- uint8_t b = 1<<7;
|
|
+ uint8_t b, p;
|
|
- while( b ) {
|
|
+ for( p = 0, b = 1<<(bit-1); b ; b >>= 1) {
|
|
- if(data & b) {
|
|
+ if(data & b) {
|
|
- serial_high();
|
|
+ serial_high(); p ^= 1;
|
|
- } else {
|
|
+ } else {
|
|
- serial_low();
|
|
+ serial_low(); p ^= 0;
|
|
|
|
+ }
|
|
|
|
+ serial_delay();
|
|
}
|
|
}
|
|
- b >>= 1;
|
|
+
|
|
|
|
+ if(p & 1) { serial_high(); }
|
|
|
|
+ else { serial_low(); }
|
|
serial_delay();
|
|
serial_delay();
|
|
- }
|
|
|
|
- serial_low();
|
|
|
|
-}
|
|
|
|
|
|
|
|
-
|
|
+ serial_low();
|
|
-ISR(SERIAL_PIN_INTERRUPT) {
|
|
+}
|
|
- serial_output();
|
|
|
|
|
|
|
|
-
|
|
+static void serial_send_packet(uint8_t *buffer, uint8_t size) NO_INLINE;
|
|
- uint8_t checksum = 0;
|
|
+static
|
|
- for (int i = 0; i < SERIAL_SLAVE_BUFFER_LENGTH; ++i) {
|
|
+void serial_send_packet(uint8_t *buffer, uint8_t size) {
|
|
|
|
+ for (uint8_t i = 0; i < size; ++i) {
|
|
|
|
+ uint8_t data;
|
|
|
|
+ data = buffer[i];
|
|
sync_send();
|
|
sync_send();
|
|
- serial_write_byte(serial_slave_buffer[i]);
|
|
+ serial_write_chunk(data,8);
|
|
- checksum += serial_slave_buffer[i];
|
|
|
|
}
|
|
}
|
|
- sync_send();
|
|
+}
|
|
- serial_write_byte(checksum);
|
|
+
|
|
-
|
|
+static uint8_t serial_recive_packet(uint8_t *buffer, uint8_t size) NO_INLINE;
|
|
-
|
|
+static
|
|
- sync_send();
|
|
+uint8_t serial_recive_packet(uint8_t *buffer, uint8_t size) {
|
|
- serial_delay_half1();
|
|
+ uint8_t pecount = 0;
|
|
- serial_low();
|
|
+ for (uint8_t i = 0; i < size; ++i) {
|
|
- serial_input_with_pullup();
|
|
+ uint8_t data;
|
|
- serial_delay_half1();
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- uint8_t checksum_computed = 0;
|
|
|
|
- for (int i = 0; i < SERIAL_MASTER_BUFFER_LENGTH; ++i) {
|
|
|
|
sync_recv();
|
|
sync_recv();
|
|
- serial_master_buffer[i] = serial_read_byte();
|
|
+ data = serial_read_chunk(&pecount, 8);
|
|
- checksum_computed += serial_master_buffer[i];
|
|
+ buffer[i] = data;
|
|
}
|
|
}
|
|
|
|
+ return pecount == 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+inline static
|
|
|
|
+void change_sender2reciver(void) {
|
|
|
|
+ sync_send();
|
|
|
|
+ serial_delay_half1();
|
|
|
|
+ serial_low();
|
|
|
|
+ serial_input_with_pullup();
|
|
|
|
+ serial_delay_half1();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+inline static
|
|
|
|
+void change_reciver2sender(void) {
|
|
|
|
+ sync_recv();
|
|
|
|
+ serial_delay();
|
|
|
|
+ serial_low();
|
|
|
|
+ serial_output();
|
|
|
|
+ serial_delay_half1();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ISR(SERIAL_PIN_INTERRUPT) {
|
|
|
|
+
|
|
|
|
+#ifndef SERIAL_USE_MULTI_TRANSACTION
|
|
|
|
+ serial_low();
|
|
|
|
+ serial_output();
|
|
|
|
+ SSTD_t *trans = Transaction_table;
|
|
|
|
+#else
|
|
|
|
+
|
|
|
|
+ uint8_t tid;
|
|
|
|
+ uint8_t pecount = 0;
|
|
sync_recv();
|
|
sync_recv();
|
|
- uint8_t checksum_received = serial_read_byte();
|
|
+ tid = serial_read_chunk(&pecount,4);
|
|
|
|
+ if(pecount> 0)
|
|
|
|
+ return;
|
|
|
|
+ serial_delay_half1();
|
|
|
|
|
|
- if ( checksum_computed != checksum_received ) {
|
|
+ serial_high();
|
|
- status |= SLAVE_DATA_CORRUPT;
|
|
+ serial_output();
|
|
|
|
+ _delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT*SLAVE_INT_ACK_WIDTH);
|
|
|
|
+ SSTD_t *trans = &Transaction_table[tid];
|
|
|
|
+ serial_low();
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if( trans->target2initiator_buffer_size > 0 )
|
|
|
|
+ serial_send_packet((uint8_t *)trans->target2initiator_buffer,
|
|
|
|
+ trans->target2initiator_buffer_size);
|
|
|
|
+
|
|
|
|
+ change_sender2reciver();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if( trans->initiator2target_buffer_size > 0 ) {
|
|
|
|
+ if (serial_recive_packet((uint8_t *)trans->initiator2target_buffer,
|
|
|
|
+ trans->initiator2target_buffer_size) ) {
|
|
|
|
+ *trans->status = TRANSACTION_ACCEPTED;
|
|
|
|
+ } else {
|
|
|
|
+ *trans->status = TRANSACTION_DATA_ERROR;
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
- status &= ~SLAVE_DATA_CORRUPT;
|
|
+ *trans->status = TRANSACTION_ACCEPTED;
|
|
}
|
|
}
|
|
|
|
|
|
- sync_recv();
|
|
+ sync_recv();
|
|
-}
|
|
|
|
-
|
|
|
|
-inline
|
|
|
|
-bool serial_slave_DATA_CORRUPT(void) {
|
|
|
|
- return status & SLAVE_DATA_CORRUPT;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
+
|
|
-
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-int serial_update_buffers(void) {
|
|
+
|
|
-
|
|
+#ifndef SERIAL_USE_MULTI_TRANSACTION
|
|
|
|
+int soft_serial_transaction(void) {
|
|
|
|
+ SSTD_t *trans = Transaction_table;
|
|
|
|
+#else
|
|
|
|
+int soft_serial_transaction(int sstd_index) {
|
|
|
|
+ SSTD_t *trans = &Transaction_table[sstd_index];
|
|
|
|
+#endif
|
|
cli();
|
|
cli();
|
|
|
|
|
|
-
|
|
+
|
|
serial_output();
|
|
serial_output();
|
|
serial_low();
|
|
serial_low();
|
|
- _delay_us(SLAVE_INT_WIDTH);
|
|
+ _delay_us(SLAVE_INT_WIDTH_US);
|
|
|
|
|
|
-
|
|
+#ifndef SERIAL_USE_MULTI_TRANSACTION
|
|
|
|
+
|
|
serial_input_with_pullup();
|
|
serial_input_with_pullup();
|
|
_delay_us(SLAVE_INT_RESPONSE_TIME);
|
|
_delay_us(SLAVE_INT_RESPONSE_TIME);
|
|
|
|
|
|
-
|
|
+
|
|
if (serial_read_pin()) {
|
|
if (serial_read_pin()) {
|
|
-
|
|
+
|
|
serial_output();
|
|
serial_output();
|
|
serial_high();
|
|
serial_high();
|
|
|
|
+ *trans->status = TRANSACTION_NO_RESPONSE;
|
|
sei();
|
|
sei();
|
|
- return 1;
|
|
+ return TRANSACTION_NO_RESPONSE;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
+#else
|
|
-
|
|
+
|
|
|
|
+ sync_send();
|
|
|
|
+ _delay_sub_us(TID_SEND_ADJUST);
|
|
|
|
+ serial_write_chunk(sstd_index, 4);
|
|
|
|
+ serial_delay_half1();
|
|
|
|
|
|
- uint8_t checksum_computed = 0;
|
|
+
|
|
-
|
|
+ serial_input_with_pullup();
|
|
- for (int i = 0; i < SERIAL_SLAVE_BUFFER_LENGTH; ++i) {
|
|
+ while( !serial_read_pin() ) {
|
|
- sync_recv();
|
|
+ _delay_sub_us(2);
|
|
- serial_slave_buffer[i] = serial_read_byte();
|
|
|
|
- checksum_computed += serial_slave_buffer[i];
|
|
|
|
}
|
|
}
|
|
- sync_recv();
|
|
|
|
- uint8_t checksum_received = serial_read_byte();
|
|
|
|
|
|
|
|
- if (checksum_computed != checksum_received) {
|
|
+
|
|
- serial_output();
|
|
+ for( int i = 0; serial_read_pin(); i++ ) {
|
|
- serial_high();
|
|
+ if (i > SLAVE_INT_ACK_WIDTH + 1) {
|
|
- sei();
|
|
+
|
|
- return 2;
|
|
+ serial_output();
|
|
|
|
+ serial_high();
|
|
|
|
+ *trans->status = TRANSACTION_NO_RESPONSE;
|
|
|
|
+ sei();
|
|
|
|
+ return TRANSACTION_NO_RESPONSE;
|
|
|
|
+ }
|
|
|
|
+ _delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT);
|
|
}
|
|
}
|
|
|
|
+#endif
|
|
|
|
|
|
-
|
|
+
|
|
- sync_recv();
|
|
+
|
|
- serial_delay();
|
|
+ if( trans->target2initiator_buffer_size > 0 ) {
|
|
- serial_low();
|
|
+ if (!serial_recive_packet((uint8_t *)trans->target2initiator_buffer,
|
|
- serial_output();
|
|
+ trans->target2initiator_buffer_size) ) {
|
|
- serial_delay_half1();
|
|
+ serial_output();
|
|
-
|
|
+ serial_high();
|
|
-
|
|
+ *trans->status = TRANSACTION_DATA_ERROR;
|
|
- uint8_t checksum = 0;
|
|
+ sei();
|
|
-
|
|
+ return TRANSACTION_DATA_ERROR;
|
|
- for (int i = 0; i < SERIAL_MASTER_BUFFER_LENGTH; ++i) {
|
|
+ }
|
|
- sync_send();
|
|
+ }
|
|
- serial_write_byte(serial_master_buffer[i]);
|
|
+
|
|
- checksum += serial_master_buffer[i];
|
|
+
|
|
|
|
+ change_reciver2sender();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if( trans->initiator2target_buffer_size > 0 ) {
|
|
|
|
+ serial_send_packet((uint8_t *)trans->initiator2target_buffer,
|
|
|
|
+ trans->initiator2target_buffer_size);
|
|
}
|
|
}
|
|
- sync_send();
|
|
|
|
- serial_write_byte(checksum);
|
|
|
|
|
|
|
|
|
|
|
|
sync_send();
|
|
sync_send();
|
|
|
|
|
|
|
|
+ *trans->status = TRANSACTION_END;
|
|
sei();
|
|
sei();
|
|
- return 0;
|
|
+ return TRANSACTION_END;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#ifdef SERIAL_USE_MULTI_TRANSACTION
|
|
|
|
+int soft_serial_get_and_clean_status(int sstd_index) {
|
|
|
|
+ SSTD_t *trans = &Transaction_table[sstd_index];
|
|
|
|
+ cli();
|
|
|
|
+ int retval = *trans->status;
|
|
|
|
+ *trans->status = 0;;
|
|
|
|
+ sei();
|
|
|
|
+ return retval;
|
|
|
|
+}
|
|
|
|
+#endif
|
|
|
|
+
|
|
#endif
|
|
#endif
|