board_support/fmc150/firmware/fmc150.c
// Plays back an array of t_cfgReg and sends initialization data
// stops on deviceId == DEV_ILLEGAL
// returns true on success
Plays back an array of t_cfgReg and sends initialization data
stops on deviceId == DEV_ILLEGAL
returns true on success
Plays back an array of t_cfgReg and sends initialization data stops on deviceId == DEV_ILLEGAL returns true on success
bool init_fmc150( const t_cfgReg *reg ) {
    if( !reg ) return false;
    t_deviceId dev = FMC150_DEV_ILLEGAL;
    while( 1 ){
        t_fmc150Error retVal = RET_UNKNOWN;
        if( dev != reg->deviceId ){
            dev = reg->deviceId;
            switch( dev ){
                case FMC150_DEV_ADS62P49:
                    ADS62P49_SPI_INIT();
                    break;
                case FMC150_DEV_AMC7823:
                    AMC7823_SPI_INIT();
                    break;
                case FMC150_DEV_CDCE72010:
                    CDCE72010_SPI_INIT();
                    break;
                case FMC150_DEV_DAC3283:
                    DAC3283_SPI_INIT();
                    break;
                default: ;
            }
        }
        uint8_t  r = reg->regAddr;
        uint32_t v = reg->val;
        switch( dev ){
            case FMC150_DEV_ADS62P49:
                FMC150_PRNT_HLP("ADS62P49(  ");
                ads62p49_write_reg(r,v);
                retVal = (ads62p49_read_reg(r)==v) ? RET_OK : RET_ERR_SPI;
                break;
            case FMC150_DEV_AMC7823:
                FMC150_PRNT_HLP("AMC7823(   ");
                amc7823_write_reg(1,r,v);
                retVal = (amc7823_read_reg(1,r)==v) ? RET_OK : RET_ERR_SPI;
                break;
            case FMC150_DEV_CDCE72010:
                FMC150_PRNT_HLP("CDCE72010( ");
                cdce72010_write_reg(r,v);
                if(r==0x0C) {
                    retVal = RET_OK;
                } else {
                    retVal = (cdce72010_read_reg(r)==v) ? RET_OK : RET_ERR_SPI;
                }
                break;
            case FMC150_DEV_DAC3283:
                FMC150_PRNT_HLP("DAC3283(   ");
                dac3283_write_reg(r,v);
                retVal = (dac3283_read_reg(r)==v) ? RET_OK : RET_ERR_SPI;
                break;
            case FMC150_DEV_LOCAL:
                if     (r==LOC_ADC_PRINT){ printEye(v);              }
                else if(r==LOC_ADC_ALIGN){ retVal=setIdelays();      }
                else if(r==LOC_DAC_TXEN ){ DAC3283_TXENABLE(v);      }
                else if(r==LOC_CDC_POWER){ CDCE72010_POWER_EN(v);    }
                else if(r==LOC_CDC_REF  ){ CDCE72010_REF_EN(v);      }
                else if(r==LOC_DAC_TPCHK){ retVal=dac3283_check_tp();}
                else if(r==LOC_FMC_RST  ){ retVal=reset_fmc150();    }
                else if(r==LOC_DAC_ALCHK){
                    print_str("dac3283_check_al()        ");
                    retVal=dac3283_check_al();
                }
                break;
            case FMC150_DEV_ILLEGAL: return true;
            default: ;
        }
        if( !errorHook(retVal) ){
            print_str("\nFMC150 init_fmc150() aborted!\n");
            return false;
        }
        if( retVal!=RET_UNKNOWN ) _putchar('\n');
        reg++;
    }
    return true;
}
bool init_fmc150 ( const t_cfgReg * reg ) { if ( ! reg ) return false ; t_deviceId dev = FMC150_DEV_ILLEGAL ; while ( 1 ) { t_fmc150Error retVal = RET_UNKNOWN ; if ( dev != reg -> deviceId ) { dev = reg -> deviceId ; switch ( dev ) { case FMC150_DEV_ADS62P49 : ADS62P49_SPI_INIT ( ) ; break ; case FMC150_DEV_AMC7823 : AMC7823_SPI_INIT ( ) ; break ; case FMC150_DEV_CDCE72010 : CDCE72010_SPI_INIT ( ) ; break ; case FMC150_DEV_DAC3283 : DAC3283_SPI_INIT ( ) ; break ; default : ; } } uint8_t r = reg -> regAddr ; uint32_t v = reg -> val ; switch ( dev ) { case FMC150_DEV_ADS62P49 : FMC150_PRNT_HLP ( " " ) ; ads62p49_write_reg ( r , v ) ; retVal = ( ads62p49_read_reg ( r ) == v ) ? RET_OK : RET_ERR_SPI ; break ; case FMC150_DEV_AMC7823 : FMC150_PRNT_HLP ( " " ) ; amc7823_write_reg ( 1 , r , v ) ; retVal = ( amc7823_read_reg ( 1 , r ) == v ) ? RET_OK : RET_ERR_SPI ; break ; case FMC150_DEV_CDCE72010 : FMC150_PRNT_HLP ( " " ) ; cdce72010_write_reg ( r , v ) ; if ( r == 0x0C ) { retVal = RET_OK ; } else { retVal = ( cdce72010_read_reg ( r ) == v ) ? RET_OK : RET_ERR_SPI ; } break ; case FMC150_DEV_DAC3283 : FMC150_PRNT_HLP ( " " ) ; dac3283_write_reg ( r , v ) ; retVal = ( dac3283_read_reg ( r ) == v ) ? RET_OK : RET_ERR_SPI ; break ; case FMC150_DEV_LOCAL : if ( r == LOC_ADC_PRINT ) { printEye ( v ) ; } else if ( r == LOC_ADC_ALIGN ) { retVal = setIdelays ( ) ; } else if ( r == LOC_DAC_TXEN ) { DAC3283_TXENABLE ( v ) ; } else if ( r == LOC_CDC_POWER ) { CDCE72010_POWER_EN ( v ) ; } else if ( r == LOC_CDC_REF ) { CDCE72010_REF_EN ( v ) ; } else if ( r == LOC_DAC_TPCHK ) { retVal = dac3283_check_tp ( ) ; } else if ( r == LOC_FMC_RST ) { retVal = reset_fmc150 ( ) ; } else if ( r == LOC_DAC_ALCHK ) { print_str ( " " ) ; retVal = dac3283_check_al ( ) ; } break ; case FMC150_DEV_ILLEGAL : return true ; default : ; } if ( ! errorHook ( retVal ) ) { print_str ( " \n \n " ) ; return false ; } if ( retVal != RET_UNKNOWN ) _putchar ( ' \n ' ) ; reg ++ ; } return true ; }
Plays back an array of t_cfgReg and sends initialization data
stops on deviceId == DEV_ILLEGAL
returns true on success
Plays back an array of t_cfgReg and sends initialization data stops on deviceId == DEV_ILLEGAL returns true on success
// Check if we speak to a different chip --> need to re-init SPI // Implement commands based on Device / register // Always write to page 1 // Skip check as reset bits read back differently // Let the user break on error by returning `false` in errorHook()