src/occ_405/amec/amec_sensors_power.c
// Function Specification
//
// Name: amec_update_avsbus_sensors
//
// Description: Read AVS Bus data and update sensors (called every tick)
//   Tick 0: start read current (for Vdd/Vdn)
//   Tick 1: process current, start voltage read (Vdd/Vdn)
//   Tick 2: process voltage, start Vdd temp read
//   Tick 3: process Vdd temp, start current read (Vdd/Vdn)
//   Tick 4: process current, start voltage read (Vdd/Vdn)
//   Tick 5: process voltage, start status read (Vdd/Vdn)
//   Tick 6: process status, start current read (Vdd/Vdn)
//   (back to tick 1)
//
//   Vdd/Vdn current and voltage are read every 3 ticks
//   Vdd temperature and status is read every 6 ticks
//
// Thread: RealTime Loop
//
// End Function Specification
Function Specification
Name: amec_update_avsbus_sensors



Vdd/Vdn current and voltage are read every 3 ticks
Vdd temperature and status is read every 6 ticks



End Function Specification
Function Specification Name : amec_update_avsbus_sensors Vdd / Vdn current and voltage are read every 3 ticks Vdd temperature and status is read every 6 ticks End Function Specification
void amec_update_avsbus_sensors(void)
{
    static enum {
        AVSBUS_STATE_DISABLED           = 0,
        AVSBUS_STATE_INITIATE_READ      = 1,
        AVSBUS_STATE_PROCESS_TEMPERATURE= 2,
        AVSBUS_STATE_PROCESS_VOLTAGE    = 3,
        AVSBUS_STATE_PROCESS_CURRENT    = 4,
        AVSBUS_STATE_PROCESS_STATUS     = 5
    } L_avsbus_state = AVSBUS_STATE_INITIATE_READ;
    if (isSafeStateRequested())
    {
        L_avsbus_state = AVSBUS_STATE_DISABLED;
        G_avsbus_vdd_monitoring = FALSE;
        G_avsbus_vdn_monitoring = FALSE;
    }
    switch (L_avsbus_state)
    {
        case AVSBUS_STATE_INITIATE_READ:
            switch ( G_amec_slv_state.state )
            {
                case 0:
                case 4:
                    TRAC_IMP("amec_update_avsbus_sensors: Starting with temperature in slave state %d", G_amec_slv_state.state);
                    avsbus_read_start(AVSBUS_VDD, AVSBUS_TEMPERATURE);
                    L_avsbus_state = AVSBUS_STATE_PROCESS_TEMPERATURE;
                    break;
                case 1:
                case 5:
                    TRAC_IMP("amec_update_avsbus_sensors: Starting with voltage in slave state %d", G_amec_slv_state.state);
                    initiate_avsbus_reads(AVSBUS_VOLTAGE);
                    L_avsbus_state = AVSBUS_STATE_PROCESS_VOLTAGE;
                    break;
                case 2:
                case 3:
                case 6:
                case 7:
                    break;
                default:
                    TRAC_ERR("amec_update_avsbus_sensors: INVALID AMEC SLAVE STATE 0x%02X", G_amec_slv_state.state);
                    avsbus_read_start(AVSBUS_VDD, AVSBUS_TEMPERATURE);
                    L_avsbus_state = AVSBUS_STATE_PROCESS_TEMPERATURE;
                    break;
            }
            break;  
        case AVSBUS_STATE_PROCESS_TEMPERATURE:
                avsbus_read(AVSBUS_VDD, AVSBUS_TEMPERATURE);
                initiate_avsbus_reads(AVSBUS_VOLTAGE);
                L_avsbus_state = AVSBUS_STATE_PROCESS_VOLTAGE;
            break;
        case AVSBUS_STATE_PROCESS_VOLTAGE:
            process_avsbus_voltage();
            if (G_sysConfigData.vdd_current_rollover_10mA != 0xFFFF)
            {
                clear_status_errors(G_sysConfigData.avsbus_vdd.bus, AVSBUS_STATUS_OVER_CURRENT_MASK);
            }
            initiate_avsbus_reads(AVSBUS_CURRENT);
            L_avsbus_state = AVSBUS_STATE_PROCESS_CURRENT;
            break;
        case AVSBUS_STATE_PROCESS_CURRENT:
            process_avsbus_current();
            initiate_avsbus_read_status();
            L_avsbus_state = AVSBUS_STATE_PROCESS_STATUS;
            break;
        case AVSBUS_STATE_PROCESS_STATUS:
            {
                process_avsbus_status();
                avsbus_read_start(AVSBUS_VDD, AVSBUS_TEMPERATURE);
                L_avsbus_state = AVSBUS_STATE_PROCESS_TEMPERATURE;
            }
            break;
        case AVSBUS_STATE_DISABLED:
            break;
        default:
            TRAC_ERR("amec_update_avsbus_sensors: INVALID AVSBUS STATE 0x%02X", L_avsbus_state);
            L_avsbus_state = AVSBUS_STATE_INITIATE_READ;
            break;
    }
}
void amec_update_avsbus_sensors ( void ) { static enum { AVSBUS_STATE_DISABLED = 0 , AVSBUS_STATE_INITIATE_READ = 1 , AVSBUS_STATE_PROCESS_TEMPERATURE = 2 , AVSBUS_STATE_PROCESS_VOLTAGE = 3 , AVSBUS_STATE_PROCESS_CURRENT = 4 , AVSBUS_STATE_PROCESS_STATUS = 5 } L_avsbus_state = AVSBUS_STATE_INITIATE_READ ; if ( isSafeStateRequested ( ) ) { L_avsbus_state = AVSBUS_STATE_DISABLED ; G_avsbus_vdd_monitoring = FALSE ; G_avsbus_vdn_monitoring = FALSE ; } switch ( L_avsbus_state ) { case AVSBUS_STATE_INITIATE_READ : switch ( G_amec_slv_state . state ) { case 0 : case 4 : TRAC_IMP ( " " , G_amec_slv_state . state ) ; avsbus_read_start ( AVSBUS_VDD , AVSBUS_TEMPERATURE ) ; L_avsbus_state = AVSBUS_STATE_PROCESS_TEMPERATURE ; break ; case 1 : case 5 : TRAC_IMP ( " " , G_amec_slv_state . state ) ; initiate_avsbus_reads ( AVSBUS_VOLTAGE ) ; L_avsbus_state = AVSBUS_STATE_PROCESS_VOLTAGE ; break ; case 2 : case 3 : case 6 : case 7 : break ; default : TRAC_ERR ( " " , G_amec_slv_state . state ) ; avsbus_read_start ( AVSBUS_VDD , AVSBUS_TEMPERATURE ) ; L_avsbus_state = AVSBUS_STATE_PROCESS_TEMPERATURE ; break ; } break ; case AVSBUS_STATE_PROCESS_TEMPERATURE : avsbus_read ( AVSBUS_VDD , AVSBUS_TEMPERATURE ) ; initiate_avsbus_reads ( AVSBUS_VOLTAGE ) ; L_avsbus_state = AVSBUS_STATE_PROCESS_VOLTAGE ; break ; case AVSBUS_STATE_PROCESS_VOLTAGE : process_avsbus_voltage ( ) ; if ( G_sysConfigData . vdd_current_rollover_10mA != 0xFFFF ) { clear_status_errors ( G_sysConfigData . avsbus_vdd . bus , AVSBUS_STATUS_OVER_CURRENT_MASK ) ; } initiate_avsbus_reads ( AVSBUS_CURRENT ) ; L_avsbus_state = AVSBUS_STATE_PROCESS_CURRENT ; break ; case AVSBUS_STATE_PROCESS_CURRENT : process_avsbus_current ( ) ; initiate_avsbus_read_status ( ) ; L_avsbus_state = AVSBUS_STATE_PROCESS_STATUS ; break ; case AVSBUS_STATE_PROCESS_STATUS : { process_avsbus_status ( ) ; avsbus_read_start ( AVSBUS_VDD , AVSBUS_TEMPERATURE ) ; L_avsbus_state = AVSBUS_STATE_PROCESS_TEMPERATURE ; } break ; case AVSBUS_STATE_DISABLED : break ; default : TRAC_ERR ( " " , L_avsbus_state ) ; L_avsbus_state = AVSBUS_STATE_INITIATE_READ ; break ; } }
Function Specification
Name: amec_update_avsbus_sensors
Function Specification Name : amec_update_avsbus_sensors
// general order Vdd temp, voltage, current, status, Vdd temp, voltage.... // status must happen immediately after current to handle if current overflow is enabled // Start reading from AVS bus, what we start with depends on the amec slave state // with goal of processing status on the same tick that WOF runs (amec slave state 4) // Want processing of Temperature on state 1, voltage on 2, current on 3, to give status on 4 // can only start with temperature or voltage, since the status must be last and requires // voltage and current to have been read in order to update the power sensor // Initiate AVS Bus read for Vdd temperature // temperature will be processed on next tick (state 1/5) // Initiate read of voltages // voltages will be processed on next tick (state 2/6) // Need to wait another tick, can only start with temperature or voltage readings // this should never happen, this would mean the whole state machine is broken! // just start reading with temperature // case AVSBUS_STATE_INITIATE_READ // Read and process Vdd temperature // Initiate read of voltages // Process the voltage readings // Initiate read of currents // Before starting the Current read clear the Vdd OCW bit if it is being used for rollover detection // Process the current readings // Initiate read of status // Process the status // Initiate read of Vdd temperature