summaryrefslogtreecommitdiff
path: root/platforms/avr/drivers/serial.c
diff options
context:
space:
mode:
Diffstat (limited to 'platforms/avr/drivers/serial.c')
-rw-r--r--platforms/avr/drivers/serial.c46
1 files changed, 8 insertions, 38 deletions
diff --git a/platforms/avr/drivers/serial.c b/platforms/avr/drivers/serial.c
index 9a7345a53d..62908e5875 100644
--- a/platforms/avr/drivers/serial.c
+++ b/platforms/avr/drivers/serial.c
@@ -16,6 +16,7 @@
#include <util/delay.h>
#include <stddef.h>
#include <stdbool.h>
+#include "gpio.h"
#include "serial.h"
#ifdef SOFT_SERIAL_PIN
@@ -119,12 +120,6 @@
# error invalid SOFT_SERIAL_PIN value
# endif
-# define setPinInputHigh(pin) (DDRx_ADDRESS(pin) &= ~_BV((pin)&0xF), PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
-# define setPinOutput(pin) (DDRx_ADDRESS(pin) |= _BV((pin)&0xF))
-# define writePinHigh(pin) (PORTx_ADDRESS(pin) |= _BV((pin)&0xF))
-# define writePinLow(pin) (PORTx_ADDRESS(pin) &= ~_BV((pin)&0xF))
-# define readPin(pin) ((bool)(PINx_ADDRESS(pin) & _BV((pin)&0xF)))
-
# define ALWAYS_INLINE __attribute__((always_inline))
# define NO_INLINE __attribute__((noinline))
# define _delay_sub_us(x) __builtin_avr_delay_cycles(x)
@@ -414,13 +409,7 @@ ISR(SERIAL_PIN_INTERRUPT) {
// target recive phase
if (trans->initiator2target_buffer_size > 0) {
- if (serial_recive_packet((uint8_t *)split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size)) {
- *trans->status = TRANSACTION_ACCEPTED;
- } else {
- *trans->status = TRANSACTION_DATA_ERROR;
- }
- } else {
- *trans->status = TRANSACTION_ACCEPTED;
+ serial_recive_packet((uint8_t *)split_trans_initiator2target_buffer(trans), trans->initiator2target_buffer_size);
}
sync_recv(); // weit initiator output to high
@@ -429,19 +418,13 @@ ISR(SERIAL_PIN_INTERRUPT) {
/////////
// start transaction by initiator
//
-// int soft_serial_transaction(int sstd_index)
+// bool soft_serial_transaction(int sstd_index)
//
-// Returns:
-// TRANSACTION_END
-// TRANSACTION_NO_RESPONSE
-// TRANSACTION_DATA_ERROR
// this code is very time dependent, so we need to disable interrupts
-int soft_serial_transaction(int sstd_index) {
- if (sstd_index > NUM_TOTAL_TRANSACTIONS) return TRANSACTION_TYPE_ERROR;
+bool soft_serial_transaction(int sstd_index) {
+ if (sstd_index > NUM_TOTAL_TRANSACTIONS) return false;
split_transaction_desc_t *trans = &split_transaction_table[sstd_index];
- if (!trans->status) return TRANSACTION_TYPE_ERROR; // not registered
-
cli();
// signal to the target that we want to start a transaction
@@ -468,9 +451,8 @@ int soft_serial_transaction(int sstd_index) {
// slave failed to pull the line low, assume not present
serial_output();
serial_high();
- *trans->status = TRANSACTION_NO_RESPONSE;
sei();
- return TRANSACTION_NO_RESPONSE;
+ return false;
}
_delay_sub_us(SLAVE_INT_ACK_WIDTH_UNIT);
}
@@ -481,9 +463,8 @@ int soft_serial_transaction(int sstd_index) {
if (!serial_recive_packet((uint8_t *)split_trans_target2initiator_buffer(trans), trans->target2initiator_buffer_size)) {
serial_output();
serial_high();
- *trans->status = TRANSACTION_DATA_ERROR;
sei();
- return TRANSACTION_DATA_ERROR;
+ return false;
}
}
@@ -498,19 +479,8 @@ int soft_serial_transaction(int sstd_index) {
// always, release the line when not in use
sync_send();
- *trans->status = TRANSACTION_END;
- sei();
- return TRANSACTION_END;
-}
-
-int soft_serial_get_and_clean_status(int sstd_index) {
- split_transaction_desc_t *trans = &split_transaction_table[sstd_index];
- cli();
- int retval = *trans->status;
- *trans->status = 0;
- ;
sei();
- return retval;
+ return true;
}
#endif