diff options
Diffstat (limited to 'protocol/serial_soft.c')
| -rw-r--r-- | protocol/serial_soft.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/protocol/serial_soft.c b/protocol/serial_soft.c index beddc353c..e0661c3aa 100644 --- a/protocol/serial_soft.c +++ b/protocol/serial_soft.c | |||
| @@ -106,11 +106,19 @@ ISR(SERIAL_RXD_VECT) | |||
| 106 | SERIAL_RXD_INT_ENTER() | 106 | SERIAL_RXD_INT_ENTER() |
| 107 | 107 | ||
| 108 | uint8_t data = 0; | 108 | uint8_t data = 0; |
| 109 | |||
| 109 | #ifdef SERIAL_BIT_ORDER_MSB | 110 | #ifdef SERIAL_BIT_ORDER_MSB |
| 110 | uint8_t mask = 0x80; | 111 | uint8_t mask = 0x80; |
| 111 | #else | 112 | #else |
| 112 | uint8_t mask = 0x01; | 113 | uint8_t mask = 0x01; |
| 113 | #endif | 114 | #endif |
| 115 | |||
| 116 | #ifdef SERIAL_PARITY_ODD | ||
| 117 | uint8_t parity = 0; | ||
| 118 | #else | ||
| 119 | uint8_t parity = 1; | ||
| 120 | #endif | ||
| 121 | |||
| 114 | /* to center of start bit */ | 122 | /* to center of start bit */ |
| 115 | _delay_us(WAIT_US/2); | 123 | _delay_us(WAIT_US/2); |
| 116 | do { | 124 | do { |
| @@ -119,6 +127,7 @@ ISR(SERIAL_RXD_VECT) | |||
| 119 | 127 | ||
| 120 | if (SERIAL_RXD_READ()) { | 128 | if (SERIAL_RXD_READ()) { |
| 121 | data |= mask; | 129 | data |= mask; |
| 130 | parity ^= 1; | ||
| 122 | } | 131 | } |
| 123 | #ifdef SERIAL_BIT_ORDER_MSB | 132 | #ifdef SERIAL_BIT_ORDER_MSB |
| 124 | mask >>= 1; | 133 | mask >>= 1; |
| @@ -126,11 +135,18 @@ ISR(SERIAL_RXD_VECT) | |||
| 126 | mask <<= 1; | 135 | mask <<= 1; |
| 127 | #endif | 136 | #endif |
| 128 | } while (mask); | 137 | } while (mask); |
| 138 | |||
| 139 | /* to center of parity bit */ | ||
| 140 | _delay_us(WAIT_US); | ||
| 141 | parity ^= SERIAL_RXD_READ(); | ||
| 142 | |||
| 129 | /* to center of stop bit */ | 143 | /* to center of stop bit */ |
| 130 | _delay_us(WAIT_US); | 144 | _delay_us(WAIT_US); |
| 145 | _delay_us(WAIT_US/2); | ||
| 131 | 146 | ||
| 147 | parity = 1; | ||
| 132 | uint8_t next = (rbuf_head + 1) % RBUF_SIZE; | 148 | uint8_t next = (rbuf_head + 1) % RBUF_SIZE; |
| 133 | if (next != rbuf_tail) { | 149 | if (parity && next != rbuf_tail) { |
| 134 | rbuf[rbuf_head] = data; | 150 | rbuf[rbuf_head] = data; |
| 135 | rbuf_head = next; | 151 | rbuf_head = next; |
| 136 | } | 152 | } |
