src/occ_405/pss/avsbus.c
// Process AVS Bus read status results (or errors)
// Returns the status data or AVSBUS_STATUS_READ_ERROR on error
Process AVS Bus read status results (or errors)
Returns the status data or AVSBUS_STATUS_READ_ERROR on error
Process AVS Bus read status results ( or errors ) Returns the status data or AVSBUS_STATUS_READ_ERROR on error
uint16_t avsbus_read_status(const avsbus_type_e i_type)
{
    if (isSafeStateRequested())
    {
        return 0;
    }
    uint16_t o_reading = 0;
    bool l_failure = FALSE;
    static uint32_t L_error_count[AVSBUS_TYPE_MAX] = {0};
    uint32_t *      l_error_count = &L_error_count[i_type];
    char l_trace_type = 'd';
    avsbusData_t l_data = G_sysConfigData.avsbus_vdd;
    if (AVSBUS_VDN == i_type)
    {
        l_trace_type = 'n';
        l_data = G_sysConfigData.avsbus_vdn;
    }
#ifdef AVSDEBUG
    static uint32_t L_trace_count = 0;
    if (L_trace_count < DEBUG_TRACE_MAX)
    {
        TRAC_INFO("avsbus_read_status: Vd%c - bus[%d] rail[%d]",
                  l_trace_type, l_data.bus, l_data.rail);
    }
#endif
    uint32_t l_status = in32(OCB_O2SSTxB[l_data.bus]);
    DEBUG_IN32(OCB_O2SSTxB[l_data.bus], l_status, "OCB_O2SSTxB");
    if (0 != (l_status & AVSBUS_STATUS_ERRORS))
    {
        l_failure = TRUE;
        (*l_error_count)++;
        if ((*l_error_count == 1) || (*l_error_count == MAX_READ_ATTEMPTS))
        {
            TRAC_ERR("avsbus_read_status: Error found in Vd%c O2SST[0x%08X] = [0x%08X]",
                     l_trace_type, OCB_O2SSTxB[l_data.bus], l_status);
        }
    }
    else if (l_status & AVSBUS_STATUS_ONGOING) 
    {
         bit was still set (operation did not complete)
        l_failure = TRUE;
        (*l_error_count)++;
        if ((*l_error_count == 1) || (*l_error_count == MAX_READ_ATTEMPTS))
        {
            TRAC_ERR("avsbus_read_status: Vd%c timeout waiting for o2s_ongoing change O2SST[0x%08X] = [0x%08X]",
                     l_trace_type, OCB_O2SSTxB[l_data.bus], l_status);
        }
    }
    if (FALSE == l_failure)
    {
        uint32_t value = in32(OCB_O2SRDxB[l_data.bus]);
        DEBUG_IN32(OCB_O2SRDxB[l_data.bus], value, "OCB_O2SRDxB");
        const uint32_t crc = avs_crc_calculate(value);
        if (crc != (value & AVS_CRC_MASK))
        {
            l_failure = TRUE;
            (*l_error_count)++;
            if ((*l_error_count == 1) || (*l_error_count == MAX_READ_ATTEMPTS))
            {
                TRAC_ERR("avsbus_read_status: CRC mismatch in Vd%c rsp O2SRD[0x%08X] = [0x%08X] (calculated CRC 0x%08X)",
                         l_trace_type, OCB_O2SRDxB[l_data.bus], value, crc);
            }
        }
        else if (0 == (value & 0xC0000000))
        {
            o_reading = (value >> 8) & 0x0000FFFF;
#ifdef AVSDEBUG
            static uint16_t L_lastReading = 0;
            if ((L_trace_count < DEBUG_TRACE_MAX) || (o_reading != L_lastReading))
            {
                TRAC_INFO("avsbus_read_status: Successfully read Vd%c status 0x%04X [0x%08X]",
                          l_trace_type, o_reading, value);
                L_lastReading = o_reading;
            }
#endif
            if (*l_error_count)
            {
                TRAC_INFO("avsbus_read_status: Successfully read Vd%c status [0x%08X] (error count=%d)",
                          l_trace_type, value, *l_error_count);
                *l_error_count = 0;
            }
        }
        else
        {
            l_failure = TRUE;
            (*l_error_count)++;
            if ((*l_error_count == 1) || (*l_error_count == MAX_READ_ATTEMPTS))
            {
                TRAC_ERR("avsbus_read_status: SlaveAck reported no action taken[0x%08X]", value);
            }
        }
    }
    if (l_failure)
    {
        if (*l_error_count == MAX_READ_ATTEMPTS)
        {
            TRAC_ERR("avsbus_read_status: Reached %d consecutive Vd%c errors reading status",
                     *l_error_count, l_trace_type);
        }
        avsbus_resync(l_data.bus);
        o_reading = AVSBUS_STATUS_READ_ERROR;
    }
#ifdef AVSDEBUG
    ++L_trace_count;
    if (L_trace_count >= DEBUG_TRACE_MAX)
    {
        G_trace_scoms = FALSE;
    }
#endif
    return o_reading;
}
uint16_t avsbus_read_status ( const avsbus_type_e i_type ) { if ( isSafeStateRequested ( ) ) { return 0 ; } uint16_t o_reading = 0 ; bool l_failure = FALSE ; static uint32_t L_error_count [ AVSBUS_TYPE_MAX ] = { 0 } ; uint32_t * l_error_count = & L_error_count [ i_type ] ; char l_trace_type = ' ' ; avsbusData_t l_data = G_sysConfigData . avsbus_vdd ; if ( AVSBUS_VDN == i_type ) { l_trace_type = ' ' ; l_data = G_sysConfigData . avsbus_vdn ; } #ifdef AVSDEBUG static uint32_t L_trace_count = 0 ; if ( L_trace_count < DEBUG_TRACE_MAX ) { TRAC_INFO ( " " , l_trace_type , l_data . bus , l_data . rail ) ; } #endif uint32_t l_status = in32 ( OCB_O2SSTxB [ l_data . bus ] ) ; DEBUG_IN32 ( OCB_O2SSTxB [ l_data . bus ] , l_status , " " ) ; if ( 0 != ( l_status & AVSBUS_STATUS_ERRORS ) ) { l_failure = TRUE ; ( * l_error_count ) ++ ; if ( ( * l_error_count == 1 ) || ( * l_error_count == MAX_READ_ATTEMPTS ) ) { TRAC_ERR ( " " , l_trace_type , OCB_O2SSTxB [ l_data . bus ] , l_status ) ; } } else if ( l_status & AVSBUS_STATUS_ONGOING ) { l_failure = TRUE ; ( * l_error_count ) ++ ; if ( ( * l_error_count == 1 ) || ( * l_error_count == MAX_READ_ATTEMPTS ) ) { TRAC_ERR ( " " , l_trace_type , OCB_O2SSTxB [ l_data . bus ] , l_status ) ; } } if ( FALSE == l_failure ) { uint32_t value = in32 ( OCB_O2SRDxB [ l_data . bus ] ) ; DEBUG_IN32 ( OCB_O2SRDxB [ l_data . bus ] , value , " " ) ; const uint32_t crc = avs_crc_calculate ( value ) ; if ( crc != ( value & AVS_CRC_MASK ) ) { l_failure = TRUE ; ( * l_error_count ) ++ ; if ( ( * l_error_count == 1 ) || ( * l_error_count == MAX_READ_ATTEMPTS ) ) { TRAC_ERR ( " " , l_trace_type , OCB_O2SRDxB [ l_data . bus ] , value , crc ) ; } } else if ( 0 == ( value & 0xC0000000 ) ) { o_reading = ( value >> 8 ) & 0x0000FFFF ; #ifdef AVSDEBUG static uint16_t L_lastReading = 0 ; if ( ( L_trace_count < DEBUG_TRACE_MAX ) || ( o_reading != L_lastReading ) ) { TRAC_INFO ( " " , l_trace_type , o_reading , value ) ; L_lastReading = o_reading ; } #endif if ( * l_error_count ) { TRAC_INFO ( " " , l_trace_type , value , * l_error_count ) ; * l_error_count = 0 ; } } else { l_failure = TRUE ; ( * l_error_count ) ++ ; if ( ( * l_error_count == 1 ) || ( * l_error_count == MAX_READ_ATTEMPTS ) ) { TRAC_ERR ( " " , value ) ; } } } if ( l_failure ) { if ( * l_error_count == MAX_READ_ATTEMPTS ) { TRAC_ERR ( " " , * l_error_count , l_trace_type ) ; } avsbus_resync ( l_data . bus ) ; o_reading = AVSBUS_STATUS_READ_ERROR ; } #ifdef AVSDEBUG ++ L_trace_count ; if ( L_trace_count >= DEBUG_TRACE_MAX ) { G_trace_scoms = FALSE ; } #endif return o_reading ; }
Process AVS Bus read status results (or errors)
Returns the status data or AVSBUS_STATUS_READ_ERROR on error
Process AVS Bus read status results ( or errors ) Returns the status data or AVSBUS_STATUS_READ_ERROR on error
// No need to process data if OCC will be reset // Static error counters for each type (Vdd/Vdn) // HW: Wait for bus op to complete // HW: arbitration between two bridges // HW: o2s_ongoing: 0 -> 1 // HW: execution completes // HW: o2s_ongoing 1 -> 0 // Since read was started in previous tick, it should have already completed // (no need to poll/wait on o2s_ongoing) // OCC O2S Status Register //   0     o2s_ongoing //   1:4   reserved //   5     write_while_bridge_busy_error //   6     reserved //   7     FSM error //   8:63  reserved // GrrrrBrF rrrrrrrr rrrrrrrr rrrrrrrr // error bit was set // o2s_ongoing // o2s_ongoing bit was still set (operation did not complete) // Read the response data // AVS Bus response (read status): //   0:1   SlaveAck (0b00 from slave indicates good CRC and action was taken) //   2     0 //   3:7   StatusResp //   8:23  CmdData (LSB = 1mV or 10mA) //   24:28 Reserved (must be all 1s) //   29:31 CRC //   AA0SSSSS VVVVVVVV VVVVVVVV 11111CCC // Validate CRC // Check for valid command operation and extract read data // AVS Bus Status: //  0     VDone //  1     IOUT_OC_WARNING (over-current) //  2     VOUT_UV_WARNING (under-voltage) //  3     IOUT_OT_WARNING (over-temperature) //  4     POUT_OP_WARNING (over power) //  5-7   reserved //  8-15  reserved // Trace and clear the error count // Reading AVS bus status is not critical, so don't stop monitoring or commit error // Force a re-sync after any failure