void mainBoardCommonInitCommonDrivers(void) { // -> Eeproms appendString(getDebugOutputStreamLogger(), "EEPROM ..."); eepromI2cBusConnection = addI2cBusConnection(i2cBus, ST24C512_ADDRESS_0, true); init24C512Eeprom(&eeprom, eepromI2cBusConnection); appendStringLN(getDebugOutputStreamLogger(), "OK"); // -> Clock appendString(getDebugOutputStreamLogger(), "CLOCK ..."); clockI2cBusConnection = addI2cBusConnection(i2cBus, PCF8563_WRITE_ADDRESS, true); initClockPCF8563(&clock, clockI2cBusConnection); appendStringLN(getDebugOutputStreamLogger(), "OK"); // -> Temperature appendString(getDebugOutputStreamLogger(), "TEMPERATURE ..."); temperatureI2cBusConnection = addI2cBusConnection(i2cBus, LM75A_ADDRESS, true); initTemperatureLM75A(&temperature, temperatureI2cBusConnection); appendStringLN(getDebugOutputStreamLogger(), "OK"); /* //--> Current appendString(getDebugOutputStreamLogger(), "CURRENT..."); currentI2CBusConnection = addI2cBusConnection(i2cBus, INA3221_ADDRESS_1, true); initCurrentINA3221(¤t, currentI2CBusConnection); appendStringLN(getDebugOutputStreamLogger(), "OK"); */ // -> Servo initServoList(&servoList, (Servo(*)[]) &servoListArray, MAIN_BOARD_SERVO_LIST_LENGTH); addServos_1_2_5(&servoList, "PWM 1", "PWM 2", "PWM 5"); // -> Accelerometer /* appendString(getDebugOutputStreamLogger(), "ACCELEROMETER ..."); I2cBusConnection* adxl345BusConnection = addI2cBusConnection(i2cBus, ADXL345_ALT_ADDRESS, true); initADXL345AsAccelerometer(&accelerometer, &accelerometerData, adxl345BusConnection); adxl345_setupInterruptOnSingleTapOnInt1(&accelerometer, 8000, 2, TAP_AXES_ALL_ENABLE, ADXL345_RATE_400HZ, ADXL345_RANGE_16G); appendStringLN(getDebugOutputStreamLogger(), "OK"); */ // Start interruptions startTimerList(true); }
int main(void) { setBoardName("MAIN BOARD"); setRobotMustStop(false); // LOG Global Configuration initLogs(DEBUG, &logHandlerListArray, MAIN_BOARD_LOG_HANDLER_LIST_LENGTH, LOG_HANDLER_CATEGORY_ALL_MASK); // LCD (LCD via Parallel interface) initLCDOutputStream(&lcdOutputStream); addLogHandler("LCD", &lcdOutputStream, LOG_LEVEL_ERROR, LOG_HANDLER_CATEGORY_ALL_MASK); // CONFIG initRobotConfigPic32(&robotConfig); // Open the serial Link for debug and LOG ! openSerialLink(&debugSerialStreamLink, &debugInputBuffer, &debugInputBufferArray, MAIN_BOARD_DEBUG_INPUT_BUFFER_LENGTH, &debugOutputBuffer, &debugOutputBufferArray, MAIN_BOARD_DEBUG_OUTPUT_BUFFER_LENGTH, &debugOutputStream, SERIAL_PORT_DEBUG, DEFAULT_SERIAL_SPEED); // Serial Debug LOG addLogHandler("UART", &debugOutputStream, DEBUG, LOG_HANDLER_CATEGORY_ALL_MASK); // LOG the BoardName appendString(getAlwaysOutputStreamLogger(), getBoardName()); println(getAlwaysOutputStreamLogger()); // SERIAL // Open the serial Link for the Motor Board openSerialLink(&motorSerialStreamLink, &motorInputBuffer, &motorInputBufferArray, MAIN_BOARD_MOTOR_INPUT_BUFFER_LENGTH, &motorOutputBuffer, &motorOutputBufferArray, MAIN_BOARD_MOTOR_OUTPUT_BUFFER_LENGTH, &motorOutputStream, SERIAL_PORT_MOTOR, DEFAULT_SERIAL_SPEED); // Open the serial Link for the Mechanical Board openSerialLink(&mechanicalBoard2SerialStreamLink, &mechanicalBoard2InputBuffer, &mechanicalBoard2InputBufferArray, MAIN_BOARD_MECA2_INPUT_BUFFER_LENGTH, &mechanicalBoard2OutputBuffer, &mechanicalBoard2OutputBufferArray, MAIN_BOARD_MECA2_OUTPUT_BUFFER_LENGTH, &mechanicalBoard2OutputStream, SERIAL_PORT_MECA2, DEFAULT_SERIAL_SPEED); // Open the serial Link for the PC openSerialLink(&pcSerialStreamLink, &pcInputBuffer, &pcInputBufferArray, MAIN_BOARD_PC_INPUT_BUFFER_LENGTH, &pcOutputBuffer, &pcOutputBufferArray, MAIN_BOARD_PC_OUTPUT_BUFFER_LENGTH, &pcOutputStream, SERIAL_PORT_PC, DEFAULT_SERIAL_SPEED); // MAIN I2C initI2cBus(&i2cBus, I2C_BUS_TYPE_MASTER, I2C_BUS_PORT_1); i2cMasterInitialize(&i2cBus); initI2cBusConnection(&motorI2cBusConnection, &i2cBus, MOTOR_BOARD_I2C_ADDRESS); initI2cBusConnection(&mechanicalBoard2I2cBusConnection, &i2cBus, MECHANICAL_BOARD_2_I2C_ADDRESS); // I2C Debug initI2CDebugBuffers(&i2cMasterDebugInputBuffer, &i2cMasterDebugInputBufferArray, MAIN_BOARD_I2C_DEBUG_MASTER_IN_BUFFER_LENGTH, &i2cMasterDebugOutputBuffer, &i2cMasterDebugOutputBufferArray, MAIN_BOARD_I2C_DEBUG_MASTER_OUT_BUFFER_LENGTH); setDebugI2cEnabled(false); // -> Eeproms initI2cBusConnection(&eepromI2cBusConnection, &i2cBus, ST24C512_ADDRESS_0); init24C512Eeprom(&eeprom, &eepromI2cBusConnection); // -> Clock initI2cBusConnection(&clockI2cBusConnection, &i2cBus, PCF8563_WRITE_ADDRESS); initClockPCF8563(&clock, &clockI2cBusConnection); // -> Temperature initI2cBusConnection(&temperatureI2cBusConnection, &i2cBus, LM75A_ADDRESS); initTemperatureLM75A(&temperature, &temperatureI2cBusConnection); // TIMERS initTimerList(&timerListArray, MAIN_BOARD_TIMER_LENGTH); // DEVICES, DRIVERS, DISPATCHERS initMainBoardDevicesDescriptor(); initMainBoardDriversDescriptor(); initMainBoardDriverDataDispatcherList(); // Start interruptions startTimerList(); loopUntilStart(&startMatch); counter = 1; clearBuffer(&mechanicalBoard2InputBuffer); // enableNotificationRobotInfraredDetector(DETECTOR_GROUP_TYPE_FORWARD); while (1) { if (!mainBoardWaitForInstruction(&startMatch)) { break; } } showEnd(getAlwaysOutputStreamLogger()); while (1) { // Avoid reboot even at end } }