comparison Small_CPU/Src/externalInterface.c @ 784:95af969fe0ae

Bugfixloop UART multiplexer integration: Fixed problems showing up in cases like no Mux detected, only one sensor connected to mux and mixed analog / digital sensor operation
author Ideenmodellierer
date Tue, 30 May 2023 18:44:20 +0200
parents 01b3eb9d55c3
children 19ab6f3ed52a
comparison
equal deleted inserted replaced
783:c31237d20491 784:95af969fe0ae
467 { 467 {
468 static uint8_t tmpMuxMapping[MAX_MUX_CHANNEL]; 468 static uint8_t tmpMuxMapping[MAX_MUX_CHANNEL];
469 static uint8_t sensorIndex = 0; 469 static uint8_t sensorIndex = 0;
470 static uint8_t uartMuxChannel = 0; 470 static uint8_t uartMuxChannel = 0;
471 uint8_t index = 0; 471 uint8_t index = 0;
472 uint8_t index2 = 0;
473 472
474 if(externalAutoDetect != DETECTION_OFF) 473 if(externalAutoDetect != DETECTION_OFF)
475 { 474 {
476 switch(externalAutoDetect) 475 switch(externalAutoDetect)
477 { 476 {
486 for(index = 0; index < MAX_ADC_CHANNEL; index++) 485 for(index = 0; index < MAX_ADC_CHANNEL; index++)
487 { 486 {
488 UART_MapDigO2_Channel(index,index); /* request all addresses */ 487 UART_MapDigO2_Channel(index,index); /* request all addresses */
489 tmpMuxMapping[index] = 0xff; 488 tmpMuxMapping[index] = 0xff;
490 } 489 }
491 UART_MapDigO2_Channel(3,4); 490 UART_MapDigO2_Channel(2,3);
492 491
493 if(externalInterfacePresent) 492 if(externalInterfacePresent)
494 { 493 {
495 externalInterface_SwitchPower33(0); 494 externalInterface_SwitchPower33(0);
496 externalInterface_SwitchUART(0); 495 externalInterface_SwitchUART(0);
557 } 556 }
558 else 557 else
559 { 558 {
560 tmpSensorMap[index] = SENSOR_DIGO2; 559 tmpSensorMap[index] = SENSOR_DIGO2;
561 tmpMuxMapping[externalAutoDetect - DETECTION_DIGO2_0] = index; 560 tmpMuxMapping[externalAutoDetect - DETECTION_DIGO2_0] = index;
561 if(externalAutoDetect == DETECTION_DIGO2_2 ) /* special handling needed because channel is used twice during mux detection */
562 {
563 UART_MapDigO2_Channel(0xff, externalAutoDetect - DETECTION_DIGO2_0);
564 }
562 } 565 }
563 } 566 }
564 else 567 else
565 { 568 {
566 UART_MapDigO2_Channel(0xff, externalAutoDetect - DETECTION_DIGO2_0); 569 UART_MapDigO2_Channel(0xff, externalAutoDetect - DETECTION_DIGO2_0);
567 } 570 }
568 if(uartMuxChannel) 571 if(uartMuxChannel)
569 { 572 {
570 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2 >> 8); 573 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2 >> 8);
571 UART_SetDigO2_Channel(uartMuxChannel); 574 UART_SetDigO2_Channel(uartMuxChannel);
572 uartMuxChannel++; 575 if(uartMuxChannel < MAX_ADC_CHANNEL - 1)
576 {
577 uartMuxChannel++;
578 }
573 } 579 }
574 else 580 else
575 { 581 {
576 externalAutoDetect = DETECTION_DIGO2_3; /* skip detection of other serial sensors */ 582 externalAutoDetect = DETECTION_DIGO2_3; /* skip detection of other serial sensors */
577 } 583 }
626 break; 632 break;
627 case DETECTION_DONE: if(uartMuxChannel) 633 case DETECTION_DONE: if(uartMuxChannel)
628 { 634 {
629 tmpSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_MUX; 635 tmpSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_MUX;
630 } 636 }
631 index2 = 0; /* used for target channel */ 637
632 for(index = 0; index < MAX_MUX_CHANNEL; index++) 638 for(index = 0; index < MAX_MUX_CHANNEL; index++)
633 { 639 {
634 if(tmpMuxMapping[index] != 0xff) 640 UART_MapDigO2_Channel(tmpMuxMapping[index], index);
635 { 641 }
636 UART_MapDigO2_Channel(index2, index); 642
637 index2++;
638 }
639 }
640 externalAutoDetect = DETECTION_OFF; 643 externalAutoDetect = DETECTION_OFF;
641 externalInterface_SwitchUART(0); 644 externalInterface_SwitchUART(0);
642 UART_SetDigO2_Channel(0); 645 UART_SetDigO2_Channel(0);
646 for(index = 0; index < MAX_ADC_CHANNEL; index++)
647 {
648 if(tmpSensorMap[index] != SENSOR_NONE)
649 {
650 break;
651 }
652 }
653
654 if(index == MAX_ADC_CHANNEL) /* return default sensor map if no sensor at all has been detected */
655 {
656 tmpSensorMap[0] = SENSOR_OPTIC;
657 tmpSensorMap[1] = SENSOR_OPTIC;
658 tmpSensorMap[2] = SENSOR_OPTIC;
659 }
643 memcpy(SensorMap, tmpSensorMap, sizeof(tmpSensorMap)); 660 memcpy(SensorMap, tmpSensorMap, sizeof(tmpSensorMap));
644 661
645 break; 662 break;
646 default: 663 default:
647 break; 664 break;