void mspSerialAllocatePorts(void) { uint8_t portIndex = 0; serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_MSP); while (portConfig && portIndex < MAX_MSP_PORT_COUNT) { mspPort_t *mspPort = &mspPorts[portIndex]; if (mspPort->port) { portIndex++; continue; } serialPort_t *serialPort = openSerialPort(portConfig->identifier, FUNCTION_MSP, NULL, NULL, baudRates[portConfig->msp_baudrateIndex], MODE_RXTX, SERIAL_NOT_INVERTED); if (serialPort) { bool sharedWithTelemetry = isSerialPortShared(portConfig, FUNCTION_MSP, TELEMETRY_PORT_FUNCTIONS_MASK); resetMspPort(mspPort, serialPort, sharedWithTelemetry); portIndex++; } portConfig = findNextSerialPortConfig(FUNCTION_MSP); } }
void mspSerialAllocatePorts(void) { for(serialPortConfig_t *portConfig = findSerialPortConfig(FUNCTION_MSP_SERVER | FUNCTION_MSP_CLIENT); portConfig != NULL; portConfig = findNextSerialPortConfig(FUNCTION_MSP_SERVER | FUNCTION_MSP_CLIENT)) { if(isSerialPortOpen(portConfig)) continue; // port is already open // find unused mspPort for this serial mspPort_t *mspPort = mspPortFindFree(); if(mspPort == NULL) { // no mspPort available, give up // this error should be signalized to user (invalid configuration) return; } uint16_t function = portConfig->functionMask & (FUNCTION_MSP_SERVER | FUNCTION_MSP_CLIENT); // assume server unless the function indicates client. uint8_t baudRatesIndex = BAUDRATE_MSP_SERVER; mspPortMode_e mode = MSP_MODE_SERVER; #ifdef USE_MSP_CLIENT if (function & FUNCTION_MSP_CLIENT) { baudRatesIndex = BAUDRATE_MSP_CLIENT; mode = MSP_MODE_CLIENT; } #endif serialPort_t *serialPort = openSerialPort(portConfig->identifier, function, NULL, baudRates[portConfig->baudRates[baudRatesIndex]], MODE_RXTX, SERIAL_NOT_INVERTED); if (serialPort) { resetMspPort(mspPort, serialPort); mspPort->mode = mode; } else { // unexpected error, inform user } } }
serialPortConfig_t *findSerialPortConfig(serialPortFunction_e function) { memset(&findSerialPortConfigState, 0, sizeof(findSerialPortConfigState)); return findNextSerialPortConfig(function); }
serialPortConfig_t *findSerialPortConfig(uint16_t mask) { memset(&findSerialPortConfigState, 0, sizeof(findSerialPortConfigState)); return findNextSerialPortConfig(mask); }