diff options
| author | tmk <nobody@nowhere> | 2013-11-08 04:25:22 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2013-11-08 04:25:22 +0900 |
| commit | 94823030f00e9293ffc7ae4bec9611c8224d3532 (patch) | |
| tree | 3b35c27f27630e910af75ad2c4f591b935665dcb | |
| parent | eea3b699a6cf9976fc0179633feee6d079e5db78 (diff) | |
| download | qmk_firmware-94823030f00e9293ffc7ae4bec9611c8224d3532.tar.gz qmk_firmware-94823030f00e9293ffc7ae4bec9611c8224d3532.zip | |
Add cli() to protoect ADB critical timing part
| -rw-r--r-- | protocol/adb.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/protocol/adb.c b/protocol/adb.c index 750f4b965..a4783f36e 100644 --- a/protocol/adb.c +++ b/protocol/adb.c | |||
| @@ -41,7 +41,6 @@ POSSIBILITY OF SUCH DAMAGE. | |||
| 41 | #include <avr/io.h> | 41 | #include <avr/io.h> |
| 42 | #include <avr/interrupt.h> | 42 | #include <avr/interrupt.h> |
| 43 | #include "adb.h" | 43 | #include "adb.h" |
| 44 | #include "debug.h" | ||
| 45 | 44 | ||
| 46 | 45 | ||
| 47 | // GCC doesn't inline functions normally | 46 | // GCC doesn't inline functions normally |
| @@ -125,16 +124,15 @@ bool adb_host_psw(void) | |||
| 125 | uint16_t adb_host_kbd_recv(void) | 124 | uint16_t adb_host_kbd_recv(void) |
| 126 | { | 125 | { |
| 127 | uint16_t data = 0; | 126 | uint16_t data = 0; |
| 127 | cli(); | ||
| 128 | attention(); | 128 | attention(); |
| 129 | send_byte(0x2C); // Addr:Keyboard(0010), Cmd:Talk(11), Register0(00) | 129 | send_byte(0x2C); // Addr:Keyboard(0010), Cmd:Talk(11), Register0(00) |
| 130 | place_bit0(); // Stopbit(0) | 130 | place_bit0(); // Stopbit(0) |
| 131 | if (!wait_data_lo(500)) { // Tlt/Stop to Start(140-260us) | 131 | if (!wait_data_lo(500)) { // Tlt/Stop to Start(140-260us) |
| 132 | sei(); | ||
| 132 | return 0; // No data to send | 133 | return 0; // No data to send |
| 133 | } | 134 | } |
| 134 | 135 | ||
| 135 | // ad hoc fix: without block inerrupt read wrong bit occasionally and get keys stuck | ||
| 136 | // TODO: is this needed anymore with improved timing? | ||
| 137 | //cli(); | ||
| 138 | uint8_t n = 17; // start bit + 16 data bits | 136 | uint8_t n = 17; // start bit + 16 data bits |
| 139 | do { | 137 | do { |
| 140 | uint8_t lo = (uint8_t) wait_data_hi(130); | 138 | uint8_t lo = (uint8_t) wait_data_hi(130); |
| @@ -153,10 +151,8 @@ uint16_t adb_host_kbd_recv(void) | |||
| 153 | data |= 1; | 151 | data |= 1; |
| 154 | } | 152 | } |
| 155 | else if (n == 17) { | 153 | else if (n == 17) { |
| 156 | // Service Request | ||
| 157 | dprintf("Startbit ERROR\n"); | ||
| 158 | sei(); | 154 | sei(); |
| 159 | return -2; | 155 | return -20; |
| 160 | } | 156 | } |
| 161 | } | 157 | } |
| 162 | while ( --n ); | 158 | while ( --n ); |
| @@ -164,21 +160,20 @@ uint16_t adb_host_kbd_recv(void) | |||
| 164 | // Stop bit can't be checked normally since it could have service request lenghtening | 160 | // Stop bit can't be checked normally since it could have service request lenghtening |
| 165 | // and its high state never goes low. | 161 | // and its high state never goes low. |
| 166 | if (!wait_data_hi(351) || wait_data_lo(91)) { | 162 | if (!wait_data_hi(351) || wait_data_lo(91)) { |
| 167 | dprintf("Stopbit ERROR\n"); | ||
| 168 | sei(); | 163 | sei(); |
| 169 | return -3; | 164 | return -21; |
| 170 | } | 165 | } |
| 171 | sei(); | 166 | sei(); |
| 172 | return data; | 167 | return data; |
| 173 | 168 | ||
| 174 | error: | 169 | error: |
| 175 | dprintf("Bit ERROR\n"); | ||
| 176 | sei(); | 170 | sei(); |
| 177 | return -4; | 171 | return -n; |
| 178 | } | 172 | } |
| 179 | 173 | ||
| 180 | void adb_host_listen(uint8_t cmd, uint8_t data_h, uint8_t data_l) | 174 | void adb_host_listen(uint8_t cmd, uint8_t data_h, uint8_t data_l) |
| 181 | { | 175 | { |
| 176 | cli(); | ||
| 182 | attention(); | 177 | attention(); |
| 183 | send_byte(cmd); | 178 | send_byte(cmd); |
| 184 | place_bit0(); // Stopbit(0) | 179 | place_bit0(); // Stopbit(0) |
| @@ -187,6 +182,7 @@ void adb_host_listen(uint8_t cmd, uint8_t data_h, uint8_t data_l) | |||
| 187 | send_byte(data_h); | 182 | send_byte(data_h); |
| 188 | send_byte(data_l); | 183 | send_byte(data_l); |
| 189 | place_bit0(); // Stopbit(0); | 184 | place_bit0(); // Stopbit(0); |
| 185 | sei(); | ||
| 190 | } | 186 | } |
| 191 | 187 | ||
| 192 | // send state of LEDs | 188 | // send state of LEDs |
