123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- #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;
- }
|