// Scan for updates in the master/slave // - Interrupts will deal with most input functions // - Used to send queries // - SyncEvent is sent immediately once the current command is sent // - SyncEvent is also blocking until sent void Connect_scan() { // Latency measurement start Latency_start_time( connectLatencyResource ); // Check if initially configured as a slave and usb comes up // Then reconfigure as a master if ( !Connect_master && Output_Available && !Connect_override ) { Connect_setup( Output_Available, 0 ); } // Limit how often we do cable checks //uint32_t time_compare = 0x007; // XXX Used for debugging cables -HaaTa 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 == DEFAULT_SLAVE_ID && 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 defined(_kinetis_) if ( uart_tx_buf[ 0 ].items > 0 && UART0_TCFIFO == 0 ) uart_fillTxFifo( 0 ); if ( uart_tx_buf[ 1 ].items > 0 && UART1_TCFIFO == 0 ) uart_fillTxFifo( 1 ); #elif defined(_sam_) //SAM TODO #endif // Process Rx Buffers Connect_rx_process( 0 ); Connect_rx_process( 1 ); } // Latency measurement end Latency_end_time( connectLatencyResource ); }
// Setup inline void Scan_setup() { // Setup UART Connect, if Output_Available, this is the master node Connect_setup( Output_Available ); // Setup GPIO pins for matrix scanning Matrix_setup(); // Setup ISSI chip to control the leds LED_setup(); // Reset scan count Scan_scanCount = 0; }