1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- #include <avr/interrupt.h>
- #include "sendchar.h"
- #include "usb_debug.h"
- volatile uint8_t debug_flush_timer = 0;
- int8_t sendchar(uint8_t c) {
- static uint8_t previous_timeout = 0;
- uint8_t timeout, intr_state;
-
- if (!usb_configured()) return -1;
-
-
-
- intr_state = SREG;
- cli();
- UENUM = DEBUG_TX_ENDPOINT;
-
- if (previous_timeout) {
- if (!(UEINTX & (1 << RWAL))) {
- SREG = intr_state;
- return -1;
- }
- previous_timeout = 0;
- }
-
- timeout = UDFNUML + 4;
- while (1) {
-
- if (UEINTX & (1 << RWAL)) break;
- SREG = intr_state;
-
- if (UDFNUML == timeout) {
- previous_timeout = 1;
- return -1;
- }
-
- if (!usb_configured()) return -1;
-
- intr_state = SREG;
- cli();
- UENUM = DEBUG_TX_ENDPOINT;
- }
-
- UEDATX = c;
-
- if (!(UEINTX & (1 << RWAL))) {
- UEINTX = 0x3A;
- debug_flush_timer = 0;
- } else {
- debug_flush_timer = 2;
- }
- SREG = intr_state;
- return 0;
- }
- void usb_debug_flush_output(void) {
- uint8_t intr_state;
- intr_state = SREG;
- cli();
- if (debug_flush_timer) {
- UENUM = DEBUG_TX_ENDPOINT;
- while ((UEINTX & (1 << RWAL))) {
- UEDATX = 0;
- }
- UEINTX = 0x3A;
- debug_flush_timer = 0;
- }
- SREG = intr_state;
- }
|