static void poll_mega64() { int16_t byte ; while ( ( byte = get_fifo64( &mega64_fifo ) ) != -1 ) { processSlaveByte( byte ) ; if (SlaveActionRequired) { SlaveActionRequired = 0 ; if ( SlaveType == 0x80 ) { if ( SlaveRxCount == 22 ) // Check in case of overrun error { uint16_t switches ; byte = SlaveTempReceiveBuffer[0] ; M64Buttons = byte & 0x7E ; M64Trims = SlaveTempReceiveBuffer[1] ; switches = SlaveTempReceiveBuffer[2] | ( ( byte & 1 ) << 8 ) ; if ( SlaveTempReceiveBuffer[19] & 0x20 ) { switches |= 0x0200 ; // Encoder switch } M64Switches = switches ; M64Analog[0] = SlaveTempReceiveBuffer[3] | ( SlaveTempReceiveBuffer[4] << 8 ) ; M64Analog[1] = SlaveTempReceiveBuffer[5] | ( SlaveTempReceiveBuffer[6] << 8 ) ; M64Analog[2] = SlaveTempReceiveBuffer[7] | ( SlaveTempReceiveBuffer[8] << 8 ) ; M64Analog[3] = SlaveTempReceiveBuffer[9] | ( SlaveTempReceiveBuffer[10] << 8 ) ; M64Analog[4] = SlaveTempReceiveBuffer[11] | ( SlaveTempReceiveBuffer[12] << 8 ) ; M64Analog[5] = SlaveTempReceiveBuffer[13] | ( SlaveTempReceiveBuffer[14] << 8 ) ; M64Analog[6] = SlaveTempReceiveBuffer[15] | ( SlaveTempReceiveBuffer[16] << 8 ) ; M64Analog[7] = SlaveTempReceiveBuffer[17] | ( SlaveTempReceiveBuffer[18] << 8 ) ; M64EncoderPosition = SlaveTempReceiveBuffer[20] ; M64Revision = SlaveTempReceiveBuffer[21] ; } else { M64CountErrors += 1 ; } } // else if ( SlaveType == 0x81 ) // EEPROM data // { // uint16_t address ; // uint32_t i ; // address = SlaveTempReceiveBuffer[0] | ( SlaveTempReceiveBuffer[1] << 8 ) ; // for ( i = 2 ; i < 34 ; i += 1 ) // { // EepromImage[address++] = SlaveTempReceiveBuffer[i] ; // } // EepromAddress += 32 ; // ReadingEeprom = 1 ; // } } } }
void arduinoDueSlave() { int16_t byte ; uint16_t address ; // Initialise serial at 100K baud DDRE &= ~(1 << DDE0) ; // set RXD0 pin as input PORTE &= ~(1 << PORTE0) ; // disable pullup on RXD0 pin UCSR0A &= ~(1 << U2X0) ; // disable double speed operation. UBRR0L = 4 ; // 200000 baud UBRR0H = 0 ; // set 8 N1 UCSR0B = 0 | (0 << RXCIE0) | (0 << TXCIE0) | (0 << UDRIE0) | (0 << RXEN0) | (0 << TXEN0) | (0 << UCSZ02) ; UCSR0C = 0 | (1 << UCSZ01) | (1 << UCSZ00) ; while (UCSR0A & (1 << RXC0)) UDR0 ; // flush receive buffer UCSR0B |= (1 << RXEN0); // enable RX UCSR0B |= (1 << RXCIE0); // enable Interrupt UCSR0B |= (1 << TXEN0) ; // enable TX, but not interrupt yet Arduino = 1 ; lcd_clear() ; lcd_puts_Pleft( 24, PSTR("Arduino Slave") ) ; refreshDiplay(); for(;;) { static uint8_t lastTMR ; wdt_reset() ; while ( ( byte = get_fifo64( &Arduino_fifo ) ) != -1 ) { processSlaveByte( byte ) ; if (SlaveActionRequired) { SlaveActionRequired = 0 ; if ( SlaveType < 16) { SlaveDisplayRefresh = 1 ; } else { switch ( SlaveType ) { case 0x10 : // Protocol + channels Protocol = SlaveTempReceiveBuffer[0] ; SubProtocol = SlaveTempReceiveBuffer[1] ; { uint8_t i ; uint8_t index = 0 ; for ( i = 2 ; i < 34 ; i += 2 ) { // May need cli/sei round this Channels[index] = SlaveTempReceiveBuffer[i] | ( SlaveTempReceiveBuffer[i+1] << 8 ) ; index += 1 ; } } break ; case 0x12 : // 0x01, 0x12, 16 bit address, 0x01 - send 32 bytes EEPROM data @ address address = SlaveTempReceiveBuffer[0] | ( SlaveTempReceiveBuffer[1] << 8 ) ; EepromAddress = address ; EepromRequested = 1 ; break ; } } } } uint8_t t10ms ; t10ms = g_tmr10ms ; tick10ms = t10ms - lastTMR ; lastTMR = t10ms ; if(tick10ms) //make sure the rest happen only every 10ms. { ControlsRequested = 1 ; if ( SlaveDisplayRefresh ) { SlaveDisplayRefresh = 0 ; refreshDiplay() ; } } if ( TxBusy == 0 ) { if ( EepromRequested ) { sendEeprom( EepromAddress ) ; EepromRequested = 0 ; } else if ( ControlsRequested ) { sendControls() ; ControlsRequested = 0 ; } } } }