comparison Small_CPU/Src/externalInterface.c @ 781:01b3eb9d55c3

Update real multiplexer implementation: The final multiplexer provides 4 sensor connections instead of three supported by the prototype => A mupping functionality has been introduced to map the 4 possible mux addresses to the three visible O2 sensor slots. In addition the request cycle time is not depending on the number of sensors connected to make sure that all sensors are read within a defined time frame. The error reaction had to be updated to reset mux channels if one of the sensors fails to respond.
author Ideenmodellierer
date Mon, 29 May 2023 18:26:55 +0200
parents 0b5f45448eb6
children 95af969fe0ae
comparison
equal deleted inserted replaced
780:e40790a67165 781:01b3eb9d55c3
333 case (EXT_INTERFACE_UART_SENTINEL >> 8): 333 case (EXT_INTERFACE_UART_SENTINEL >> 8):
334 if((externalAutoDetect <= DETECTION_START) 334 if((externalAutoDetect <= DETECTION_START)
335 || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_DIGO2_0)) 335 || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_DIGO2_0))
336 || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_DIGO2_1)) 336 || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_DIGO2_1))
337 || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_DIGO2_2)) 337 || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_DIGO2_2))
338 || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_DIGO2_3))
338 || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_UARTMUX)) 339 || ((protocol == EXT_INTERFACE_UART_O2 >> 8) && (externalAutoDetect == DETECTION_UARTMUX))
339 #ifdef ENABLE_CO2_SUPPORT 340 #ifdef ENABLE_CO2_SUPPORT
340 || ((protocol == EXT_INTERFACE_UART_CO2 >> 8) && (externalAutoDetect == DETECTION_CO2)) 341 || ((protocol == EXT_INTERFACE_UART_CO2 >> 8) && (externalAutoDetect == DETECTION_CO2))
341 #endif 342 #endif
342 #ifdef ENABLE_SENTINEL_MODE 343 #ifdef ENABLE_SENTINEL_MODE
462 return pret; 463 return pret;
463 } 464 }
464 465
465 void externalInterface_AutodetectSensor() 466 void externalInterface_AutodetectSensor()
466 { 467 {
467 static uint8_t tmpMuxMapping[MAX_ADC_CHANNEL]; 468 static uint8_t tmpMuxMapping[MAX_MUX_CHANNEL];
468 static uint8_t sensorIndex = 0; 469 static uint8_t sensorIndex = 0;
469 static uint8_t uartMuxChannel = 0; 470 static uint8_t uartMuxChannel = 0;
470 uint8_t index = 0; 471 uint8_t index = 0;
472 uint8_t index2 = 0;
471 473
472 if(externalAutoDetect != DETECTION_OFF) 474 if(externalAutoDetect != DETECTION_OFF)
473 { 475 {
474 switch(externalAutoDetect) 476 switch(externalAutoDetect)
475 { 477 {
484 for(index = 0; index < MAX_ADC_CHANNEL; index++) 486 for(index = 0; index < MAX_ADC_CHANNEL; index++)
485 { 487 {
486 UART_MapDigO2_Channel(index,index); /* request all addresses */ 488 UART_MapDigO2_Channel(index,index); /* request all addresses */
487 tmpMuxMapping[index] = 0xff; 489 tmpMuxMapping[index] = 0xff;
488 } 490 }
491 UART_MapDigO2_Channel(3,4);
492
489 if(externalInterfacePresent) 493 if(externalInterfacePresent)
490 { 494 {
491 externalInterface_SwitchPower33(0); 495 externalInterface_SwitchPower33(0);
492 externalInterface_SwitchUART(0); 496 externalInterface_SwitchUART(0);
493 for(index = 0; index < MAX_ADC_CHANNEL; index++) 497 for(index = 0; index < MAX_ADC_CHANNEL; index++)
521 tmpSensorMap[sensorIndex++] = SENSOR_NONE; 525 tmpSensorMap[sensorIndex++] = SENSOR_NONE;
522 } 526 }
523 } 527 }
524 externalAutoDetect = DETECTION_UARTMUX; 528 externalAutoDetect = DETECTION_UARTMUX;
525 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2 >> 8); 529 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2 >> 8);
526 UART_SetDigO2_Channel(3); 530 UART_SetDigO2_Channel(MAX_MUX_CHANNEL);
527 break; 531 break;
528 case DETECTION_UARTMUX: if(UART_isDigO2Connected()) 532 case DETECTION_UARTMUX: if(UART_isDigO2Connected())
529 { 533 {
530 uartMuxChannel = 1; 534 uartMuxChannel = 1;
531 } 535 }
534 UART_SetDigO2_Channel(0); 538 UART_SetDigO2_Channel(0);
535 539
536 break; 540 break;
537 case DETECTION_DIGO2_0: 541 case DETECTION_DIGO2_0:
538 case DETECTION_DIGO2_1: 542 case DETECTION_DIGO2_1:
539 case DETECTION_DIGO2_2: if(UART_isDigO2Connected()) 543 case DETECTION_DIGO2_2:
544 case DETECTION_DIGO2_3:
545 if(UART_isDigO2Connected())
540 { 546 {
541 for(index = 0; index < 3; index++) /* lookup a channel which may be used by digO2 */ 547 for(index = 0; index < 3; index++) /* lookup a channel which may be used by digO2 */
542 { 548 {
543 if(tmpSensorMap[index] == SENSOR_NONE) 549 if(tmpSensorMap[index] == SENSOR_NONE)
544 { 550 {
550 tmpSensorMap[2] = SENSOR_DIGO2; /* digital sensor overwrites ADC */ 556 tmpSensorMap[2] = SENSOR_DIGO2; /* digital sensor overwrites ADC */
551 } 557 }
552 else 558 else
553 { 559 {
554 tmpSensorMap[index] = SENSOR_DIGO2; 560 tmpSensorMap[index] = SENSOR_DIGO2;
555 tmpMuxMapping[index] = externalAutoDetect - DETECTION_DIGO2_0; 561 tmpMuxMapping[externalAutoDetect - DETECTION_DIGO2_0] = index;
556 } 562 }
557 UART_setTargetChannel(index); 563 }
558 564 else
559 /* tmpSensorMap[sensorIndex++] = SENSOR_DIGO2; */ 565 {
566 UART_MapDigO2_Channel(0xff, externalAutoDetect - DETECTION_DIGO2_0);
560 } 567 }
561 if(uartMuxChannel) 568 if(uartMuxChannel)
562 { 569 {
563 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2 >> 8); 570 externalInterface_SwitchUART(EXT_INTERFACE_UART_O2 >> 8);
564 UART_SetDigO2_Channel(uartMuxChannel); 571 UART_SetDigO2_Channel(uartMuxChannel);
565 uartMuxChannel++; 572 uartMuxChannel++;
566 } 573 }
567 else 574 else
568 { 575 {
569 externalAutoDetect = DETECTION_DIGO2_2; /* skip detection of other serial sensors */ 576 externalAutoDetect = DETECTION_DIGO2_3; /* skip detection of other serial sensors */
570 } 577 }
571 externalAutoDetect++; 578 externalAutoDetect++;
572 #ifdef ENABLE_CO2_SUPPORT 579 #ifdef ENABLE_CO2_SUPPORT
573 if(externalAutoDetect == DETECTION_CO2) 580 if(externalAutoDetect == DETECTION_CO2)
574 { 581 {
619 break; 626 break;
620 case DETECTION_DONE: if(uartMuxChannel) 627 case DETECTION_DONE: if(uartMuxChannel)
621 { 628 {
622 tmpSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_MUX; 629 tmpSensorMap[EXT_INTERFACE_SENSOR_CNT-1] = SENSOR_MUX;
623 } 630 }
624 for(index = 0; index < MAX_ADC_CHANNEL; index++) 631 index2 = 0; /* used for target channel */
625 { 632 for(index = 0; index < MAX_MUX_CHANNEL; index++)
626 UART_MapDigO2_Channel(index,tmpMuxMapping[index]); 633 {
634 if(tmpMuxMapping[index] != 0xff)
635 {
636 UART_MapDigO2_Channel(index2, index);
637 index2++;
638 }
627 } 639 }
628 externalAutoDetect = DETECTION_OFF; 640 externalAutoDetect = DETECTION_OFF;
629 externalInterface_SwitchUART(0); 641 externalInterface_SwitchUART(0);
630 UART_SetDigO2_Channel(0); 642 UART_SetDigO2_Channel(0);
631 memcpy(SensorMap, tmpSensorMap, sizeof(tmpSensorMap)); 643 memcpy(SensorMap, tmpSensorMap, sizeof(tmpSensorMap));
662 if(SensorMap[index] == SENSOR_DIGO2) 674 if(SensorMap[index] == SENSOR_DIGO2)
663 { 675 {
664 break; 676 break;
665 } 677 }
666 } 678 }
667 UART_setTargetChannel(index); /* if no slot for digO2 is found then the function will be called with an invalid parameter causing the overwrite function to fail */
668 } 679 }
669 break; 680 break;
670 default: 681 default:
671 break; 682 break;
672 } 683 }