- // Check if Tx Buffers are empty and the Tx Ring buffers have data to send
- // This happens if there was previously nothing to send
- if ( uart0_buffer_items > 0 && UART0_TCFIFO == 0 )
- uart_fillTxFifo( 0 );
- if ( uart1_buffer_items > 0 && UART1_TCFIFO == 0 )
- uart_fillTxFifo( 1 );
+ // Check if initially configured as a slave and usb comes up
+ // Then reconfigure as a master
+ if ( !Connect_master && Output_Available )
+ {
+ Connect_setup( Output_Available );
+ }
+
+ // Limit how often we do cable checks
+ uint32_t time_compare = 0x7FF; // Must be all 1's, 0x3FF is valid, 0x4FF is not
+ uint32_t current_time = systick_millis_count;
+ if ( Connect_lastCheck != current_time
+ && ( current_time & time_compare ) == time_compare
+ )
+ {
+ // Make sure we don't double check if the clock speed is too high
+ Connect_lastCheck = current_time;
+
+ // Send a cable check command of 2 bytes
+ Connect_send_CableCheck( UARTConnectCableCheckLength_define );
+
+ // If this is a slave, and we don't have an id yeth
+ // Don't bother sending if there are cable issues
+ if ( !Connect_master && Connect_id == 0xFF && Connect_cableOkMaster )
+ {
+ Connect_send_IdRequest();
+ }
+ }
+
+ // Only process commands if uarts have been configured
+ if ( uarts_configured )
+ {
+ // Check if Tx Buffers are empty and the Tx Ring buffers have data to send
+ // This happens if there was previously nothing to send
+ if ( uart0_buffer_items > 0 && UART0_TCFIFO == 0 )
+ uart_fillTxFifo( 0 );
+ if ( uart1_buffer_items > 0 && UART1_TCFIFO == 0 )
+ uart_fillTxFifo( 1 );
+ }