Section to put temporary code that we use in a close future.... ////////////////////////////////////////////////////////////////////////// //Start of code //////////////////////////////////////////////////////////// //Local variables const char *boot_msg = BOOT_MSG; cfgPort cfgVCOM1, cfgVCOM2, cfgVCOM3, cfgVCOM4; uint8_t ledsCfg; //Output buffer uint8_t MCOMBuf[256], VCOM1Buf[256], VCOM2Buf[256], VCOM3Buf[256], VCOM4Buf[256]; //Output buffer index uint8_t MCOMIndex = 0, VCOM1Index = 0, VCOM2Index = 0, VCOM3Index = 0, VCOM4Index = 0; //local timer counter for local process (blink led, ect...) uint32_t timerCnt = 0; //local timer for counting how many cycles passed since we've got activity on serial port ? uint32_t serialTimer = 0; //Counter to make a timeout if all data has passed uint16_t MCOM_counter = 0; uint16_t VCOM1_counter = 0; uint16_t VCOM2_counter = 0; uint16_t VCOM3_counter = 0; uint16_t VCOM4_counter = 0; for(int i = 0; i < 256; i++) { MCOMBuf[i] = 0; VCOM1Buf[i] = 0; VCOM2Buf[i] = 0; VCOM3Buf[i] = 0; VCOM4Buf[i] = 0; } PORTD.DIR = 0x01; // DEBUG LED //PORTMUX.USARTROUTEA = _USART0_REG_WR; //set TX and RX on PD4 and PD5 pins _PROTECTED_WRITE(CLKCTRL.OSCHFCTRLA, _FREQSEL_REG_WR); //switch to 24 MHz /////////////////////////////////////////// //Prepare VCOM configuration //At first read EEPROM ! getEEPROMCfg(); //Get serial port configuration ledsCfg = getDebugLedsConfiguration(); //get debug leds configuration //And then, read configuration for each port... readConfiguration(&cfgVCOM1, 0); readConfiguration(&cfgVCOM2, 1); readConfiguration(&cfgVCOM3, 2); readConfiguration(&cfgVCOM4, 3); /////////////////////////////////////////// //Interrupt & serial port setup //Set port with debug leds initPort1(UART_BAUD_VALUE, (ledsCfg & 0x1), F8BIT_MODE, ONE_STOPBIT, EVEN_PARITY); //initPort0(UART_BAUD_VALUE, (ledsCfg & 0x1), F8BIT_MODE, ONE_STOPBIT, EVEN_PARITY); //init master port with debug leds //initPort1(cfgVCOM1.baud, (ledsCfg & 0x2) >> 1, cfgVCOM1.dataByte, cfgVCOM1.stopBit, cfgVCOM1.parity); //init vcom1 port with debug leds //initPort2(cfgVCOM2.baud, (ledsCfg & 0x4) >> 2, cfgVCOM2.dataByte, cfgVCOM2.stopBit, cfgVCOM2.parity); //init vcom2 port with debug leds //initPort3(cfgVCOM3.baud, (ledsCfg & 0x8) >> 3, cfgVCOM3.dataByte, cfgVCOM3.stopBit, cfgVCOM3.parity); //init vcom3 port with debug leds //initPort4(cfgVCOM4.baud, (ledsCfg & 0x16) >> 4, cfgVCOM4.dataByte, cfgVCOM4.stopBit, cfgVCOM4.parity); //init vcom4 port with debug leds //Timer init //Setup for interrupt every 25ms timerInterruptInit(0x2EE0); sei(); //never forget to enable global interrupt mask ! /////////////////////////////////////////// //Debug led on boot sequence WATCHDOG_RESET; //reset WD counter bootSequence(); //Launch leds sequence for(uint8_t i = 0; i < 11; i++) { txWrite0(boot_msg[i]); } while(1) { WATCHDOG_RESET; //Always call this to prevent undesired boot... /////////////////////////////////////////////////////////////// //Master Port buffer read if(portAvailable0() > 0) { MCOMBuf[MCOMIndex] = rxRead0(); //store byte into buffer MCOMIndex++; //increment to next byte global_n = MCOMIndex; MCOM_counter = 0; //refresh timeout counter } /////////////////////////////////////////////////////////////// //Virtual Port 1 buffer read if(portAvailable1() > 0) //check if we have bytes to read { VCOM1Buf[VCOM1Index] = rxRead1(); //store byte into buffer VCOM1Index++; //increment to next byte VCOM1_counter = 0; //refresh timeout counter } /////////////////////////////////////////////////////////////// //Virtual Port 2 buffer read if(portAvailable2() > 0) //check if we have bytes to read { VCOM2Buf[VCOM2Index] = rxRead2(); //store byte into buffer VCOM2Index++; //increment to next byte VCOM2_counter = 0; //refresh timeout counter } /////////////////////////////////////////////////////////////// //Virtual Port 3 buffer read if(portAvailable3() > 0) //check if we have bytes to read { VCOM3Buf[VCOM3Index] = rxRead3(); //store byte into buffer VCOM3Index++; //increment to next byte VCOM3_counter = 0; //refresh timeout counter } /////////////////////////////////////////////////////////////// //Virtual Port 4 buffer read if(portAvailable4() > 0) //check if we have bytes to read { VCOM4Buf[VCOM4Index] = rxRead4(); //store byte into buffer VCOM4Index++; //increment to next byte VCOM4_counter = 0; //refresh timeout counter } //////////////////////////////////////////////////////////////////////// /////////////////////////////////////// //When buf is ready if(MCOM_counter > SERIAL_PORT_TIMEOUT_COUNT) { //Send buffer to VCOM MCOM_sendframe(MCOMBuf, MCOMIndex); //Clear the buffer for(uint8_t i = 0; i < MCOMIndex; i++) { MCOMBuf[i] = 0; } MCOMIndex = 0; //reset index buffer MCOM_counter = 0; //reset counter } /////////////////////////////////////// //When buf is ready if(VCOM1_counter > SERIAL_PORT_TIMEOUT_COUNT) { //Send buffer to VCOM VCOM_sendframe(VCOM1Buf, VCOM1Index, VCOM1_INDEX); //Clear the buffer for(uint8_t i = 0; i < VCOM1Index; i++) { VCOM1Buf[i] = 0; } VCOM1Index = 0; //reset index buffer VCOM1_counter = 0; //reset counter } /////////////////////////////////////// //When buf is ready if(VCOM2_counter > SERIAL_PORT_TIMEOUT_COUNT) { //Send buffer to VCOM VCOM_sendframe(VCOM2Buf, VCOM2Index, VCOM2_INDEX); //Clear the buffer for(uint8_t i = 0; i < VCOM2Index; i++) { VCOM2Buf[i] = 0; } VCOM2Index = 0; //reset index buffer VCOM2_counter = 0; //reset counter } /////////////////////////////////////// //When buf is ready if(VCOM3_counter > SERIAL_PORT_TIMEOUT_COUNT) { //Send buffer to VCOM VCOM_sendframe(VCOM3Buf, VCOM3Index, VCOM3_INDEX); //Clear the buffer for(uint8_t i = 0; i < VCOM3Index; i++) { VCOM3Buf[i] = 0; } VCOM3Index = 0; //reset index buffer VCOM3_counter = 0; //reset counter } /////////////////////////////////////// //When buf is ready if(VCOM4_counter > SERIAL_PORT_TIMEOUT_COUNT) { //Send buffer to VCOM VCOM_sendframe(VCOM4Buf, VCOM4Index, VCOM4_INDEX); //Clear the buffer for(uint8_t i = 0; i < VCOM4Index; i++) { VCOM4Buf[i] = 0; } VCOM4Index = 0; //reset index buffer VCOM4_counter = 0; //reset counter } //////////////////////////////////////////////////////////////////////// //NOTE : Not sure that stuff will be useful... //Just in case if bytes does not match, clear counter //Refresh led status if(abs(getTimerCounts() - timerCnt) >= 25) { senseDebugLeds(); //display leds status timerCnt = getTimerCounts(); //refresh counter } //count if(abs(getTimerCounts() - serialTimer) >= TIMEBASE_COUNT) { //prevent incrementing counter if no bytes available... //For master port if(MCOMIndex > 0) MCOM_counter++; //For virtual port 1 if(VCOM1Index > 0) VCOM1_counter++; //For virtual port 2 if(VCOM2Index > 0) VCOM2_counter++; //For virtual port 3 if(VCOM3Index > 0) VCOM3_counter++; //For virtual port 4 if(VCOM4Index > 0) VCOM4_counter++; if(MCOMIndex >= 255) MCOMIndex = 0; if(VCOM1Index >= 255) VCOM1Index = 0; if(VCOM2Index >= 255) VCOM2Index = 0; if(VCOM3Index >= 255) VCOM3Index = 0; if(VCOM4Index >= 255) VCOM4Index = 0; serialTimer = getTimerCounts(); //refresh counter } }