Пример #1
0
/*****************************************************************************
 *  FUNCTION: NVM_Read
 *
 *  INPUTS:
 *      NVM_BlockId_t p_BlockId
 *          MIN: 0
 *          MAX: NUM_NVM_BLOCKS
 *          DESC: NVM block ID for NVM_Blocks_sa
 *      uint8_t *p_Buf
 *          DESC: pointer to buffer to place EEPROM data, if NULL return value
 *                will be FALSE
 *
 *  OUTPUTS:
 *      uint8_t (return)
 *          TRUE - read was successful
 *          FALSE - read failed
 *
 *  MODULE VARIABLES:
 *      NVM_Blocks_sa used
 *
 *  DESCRIPTION:
 *      This function reads data from NVM into RAM at the address
 *      of the provided pointer.
 *
 *****************************************************************************/
uint8_t NVM_Read( NVM_BlockId_t p_BlockId, uint8_t *p_Buf )
{
    uint8_t l_return_u8 = FALSE;
    uint8_t l_inx_u8;
    uint16_t l_EEPROM_addr_u8;
    uint8_t l_crc_nvm_u8;
    uint8_t *l_ptr_u8;

    if (  ( p_BlockId < NUM_NVM_BLOCKS )
       && ( p_Buf != NULL ) ) {
        l_EEPROM_addr_u8 = NVM_Blocks_sa[p_BlockId].Addr_u16;
        l_ptr_u8 = p_Buf;
        for ( l_inx_u8 = 0; l_inx_u8 < NVM_Blocks_sa[p_BlockId].Size_u8; l_inx_u8++ ) {
            //*l_ptr_u8++ = EEPROM.read( l_EEPROM_addr_u8++ );
            *l_ptr_u8++ = EepromRead( l_EEPROM_addr_u8++ );
        }
        //l_crc_nvm_u8 = EEPROM.read( l_EEPROM_addr_u8 );
#if 0 /* CRC not implemented */
        l_crc_nvm_u8 = EepromRead( l_EEPROM_addr_u8 );

        if ( NVM_Blocks_sa[p_BlockId].Flags.b.UseCRC_bt ) {
            /* CRC calculation and comparison */
            uint8_t l_crc_calc_u8 = 0;

            l_crc_calc_u8 = CRC8_Calculate( NVM_Blocks_sa[ p_BlockId ].Size_u8, p_Buf );

            if ( l_crc_calc_u8 == l_crc_nvm_u8 ) {
                l_return_u8 = TRUE;
            } else {
                //Serial.print( "DEBUG: ERROR NVM_Read CRC mismatch: NVM - " );
                //Serial.print( l_crc_nvm_u8, DEC );
                //Serial.print( " RAM - " );
                //Serial.println( l_crc_calc_u8, DEC );

                l_return_u8 = FALSE;
            }
        } else {
            l_return_u8 = TRUE;
        } /* NVM_Blocks_sa[p_BlockId].Flags.b.UseCRC  */
#else
        l_return_u8 = TRUE;
#endif
    } else {
        //Serial.println( "DEBUG: ERROR NVM_Read invalid block ID, or NULL pointer!" );
        l_return_u8 = FALSE;
    } /* p_BlockId < NUM_NVM_BLOCKS */

    return l_return_u8;
} /* NVM_Read */
Пример #2
0
int OpenCameraByID(int camid)
{   
    qhyusb = new QUsb();

    qhyccd_device *dev;
    qhyccd_device_model *model;

    qhyusb->qhyccd_init();
    
    ssize_t n_device;
    n_device = qhyusb->qhyccd_get_device_list(&(qhyusb->QCam.device_list));
    #ifdef QHYCCD_DEBUG
    printf("Total devices %d\n",n_device);
    #endif
    
    int i;
    for(i = 0;i < n_device;i++)
    {
        model = qhyusb->qhyccd_get_device_model(qhyusb->QCam.device_list[i]);
        
        #ifdef QHYCCD_DEBUG
        printf("model is %d\n",model->model_id);
        #endif
        dev = qhyusb->QCam.device_list[i];
        qhyusb->qhyccd_open(dev,&(qhyusb->QCam.ccd_handle));

        if(model->model_id == QHYCCD_QHY5II)
        {            
            unsigned char buf[16];
            EepromRead(0x10,buf,16);
            if(buf[1] == 1)
                qhyusb->QCam.isColor = true;
            else 
                qhyusb->QCam.isColor = false;

            if(buf[0] == 6 && camid == DEVICETYPE_QHY5LII)
            {
                qhyusb->QCam.CAMERA = DEVICETYPE_QHY5LII;   
                q5lii = new QHY5LII();
                InitCamera();
                return DEVICETYPE_QHY5LII;
            }
            else if(buf[0] == 1 && camid == DEVICETYPE_QHY5II)
            {
                qhyusb->QCam.CAMERA = DEVICETYPE_QHY5II;
                q5ii = new QHY5II();
                InitCamera();
                return DEVICETYPE_QHY5II;
            }
        }
        else if(model->model_id == QHYCCD_QHY6 && camid == DEVICETYPE_QHY6)
        {
            #ifdef QHYCCD_DEBUG
            printf("QHY6 Found\n");
            #endif
            qhy6 = new QHY6();
            qhyusb->QCam.CAMERA = DEVICETYPE_QHY6;
            InitCamera();
            return DEVICETYPE_QHY6;
        }
        else if(model->model_id == QHYCCD_QHY9 && camid == DEVICETYPE_QHY9)
        {
            #ifdef QHYCCD_DEBUG
            printf("QHY9 Found\n");
            #endif
            qhy9 = new QHY9();
            qhyusb->QCam.CAMERA = DEVICETYPE_QHY9;
            InitCamera();
            return DEVICETYPE_QHY9;
        }
        else if(model->model_id == QHYCCD_IC8300 && camid == DEVICETYPE_IC8300)
        {
            ic8300 = new IC8300();
            qhyusb->QCam.CAMERA = DEVICETYPE_IC8300;
            InitCamera();
            ic8300->send2oled("USB CAM");
            return DEVICETYPE_IC8300;
        }
        else if(model->model_id == QHYCCD_QHY11 && camid == DEVICETYPE_QHY11)
        {
            qhy11 = new QHY11();
            qhyusb->QCam.CAMERA = DEVICETYPE_QHY11;
            InitCamera();
            return DEVICETYPE_QHY11;
        }
        else if(model->model_id == QHYCCD_QHY22 && camid == DEVICETYPE_QHY22)
        {
            qhy22 = new QHY22();
            #ifdef QHYCCD_DEBUG
            printf("QHY22 Found\n");
            #endif
            qhyusb->QCam.CAMERA = DEVICETYPE_QHY22;
            InitCamera();
            return DEVICETYPE_QHY22;
        }
        else if(model->model_id == QHYCCD_QHY21 && camid == DEVICETYPE_QHY21)
        {
            qhy21 = new QHY21();
            #ifdef QHYCCD_DEBUG
            printf("QHY21 Found\n");
            #endif
            qhyusb->QCam.CAMERA = DEVICETYPE_QHY21;
            InitCamera();
            return DEVICETYPE_QHY21;
        }  
        else if(model->model_id == QHYCCD_QHY23 && camid == DEVICETYPE_QHY23)
        {
            qhy23 = new QHY23();
            #ifdef QHYCCD_DEBUG
            printf("QHY23 Found\n");
            #endif
            qhyusb->QCam.CAMERA = DEVICETYPE_QHY23;
            InitCamera();
            return DEVICETYPE_QHY23;
        }      
        else if(model->model_id == QHYCCD_QHY16000 && camid == DEVICETYPE_QHY16000)
        {
            qhy16000 = new QHY16000();
            #ifdef QHYCCD_DEBUG
            printf("QHY16000 Found\n");
            #endif
            qhyusb->QCam.CAMERA = DEVICETYPE_QHY16000;
            InitCamera();
            return DEVICETYPE_QHY16000;
        } 
    }
    #ifdef QHYCCD_DEBUG
    printf("please check USB link or camid\n");
    #endif
    return DEVICETYPE_UNKOWN;   
}
Пример #3
0
unsigned char SetttingsAction(unsigned char mode)
{
	unsigned char i,save = FALSE;
/* mode:
#define SETTINGS_LOAD		0x00
#define SETTINGS_CLEAR		0x01
#define SETTINGS_NEW_ID		0x02
#define SETTINGS_NEW_ENCRYP	0x04	
#define SETTINGS_RESET_ALL	0x07
*/
	// Read settings from eeprom
	EepromRead((unsigned char*)&settings, sizeof(settings_t), SETTINGS_ADDRESS);

	// Check settings are valid first (or changing id will reset all)
	if(settings.checksum != SettingsChecksum())
	{
		mode |= SETTINGS_CLEAR; // Need to clear them
		save = TRUE;
	}

	// Check id is valid
	if(	(settings.deviceId.val32&0x00fffffful) == 0x00ffffffUL || 
		(settings.deviceId.val32&0x00fffffful) == 0x00000000UL ||
		(mode & SETTINGS_NEW_ID) )
	{
		// Make a random id
		settings.deviceId.val8[3] = HEADER_BYTE_MSB; 
		WriteRandom(settings.deviceId.val8, 3);
		save = TRUE;
	}

	// Check for invalid encryption 
	for(i=0;i<AES_KEY_SIZE;i++)
	{
		if(settings.key[i] != 0xff && settings.key[i] != 0x00) 
			break;
	}
	if((mode & SETTINGS_NEW_ENCRYP) || (i == AES_KEY_SIZE))
	{
		// Need to generate encryption mask
		WriteRandom(&settings.key, AES_KEY_SIZE);
		// Save encryption packet	
		save = TRUE;
	}

	// If setting to defaults
	if(mode & SETTINGS_CLEAR)
	{
		settings.batt_min = VBATT_MIN;
		settings.tx_power = RADIO_TX_PWR_DBM;
		settings.pir_threshold = PIR_THRESHOLD;
		settings.pir_suspect_val = PIR_THRESHOLD_SUSPECT_VAL;
		settings.pir_suspect_count = PIR_THRESHOLD_SUSPECT_COUNT;
		settings.pir_suspect_release = PIR_THRESHOLD_SUSPECT_RELEASE;
		settings.pir_disarm_time = PIR_DISARM_TIME;
		settings.pir_led_time = PIR_LED_TIME;
		settings.sensor_settle_time = PIR_SETTLE_TIME;
		settings.sw_led_time = SW_LED_TIME;
		settings.credit_interval = CREDIT_INTERVAL;
		settings.max_pir_credits = MAX_PIR_CREDITS;
		settings.max_switch_credits = MAX_SWITCH_CREDITS;
		settings.sample_interval = SAMPLE_INTERVAL;
		settings.num_tx_repeats = SAMPLE_RETRANSMITS;
		save = TRUE;
	}
	
	// Do we need to save
	if(save)
	{
		SettingsSave();
	}
	return save;
}
/*****************************************************************************
*
* The purpose of this function is to illustrate how to use the XSpiPs
* device driver in polled mode. This test writes and reads data from a
* serial EEPROM. The serial EEPROM part must be present in the hardware
* to use this example.
*
* @param	SpiInstancePtr is a pointer to the Spi Instance.
* @param	SpiDeviceId is the Device Id of Spi.
*
* @return	XST_SUCCESS if successful else XST_FAILURE.
*
* @note
*
* This function calls functions which contain loops that may be infinite
* if interrupts are not working such that it may not return. If the device
* slave select is not correct and the device is not responding on bus it will
* read a status of 0xFF for the status register as the bus is pulled up.
*
*****************************************************************************/
int SpiPsEepromPolledExample(XSpiPs *SpiInstancePtr, u16 SpiDeviceId)
{
	int Status;
	u8 *BufferPtr;
	u8 UniqueValue;
	int Count;
	int Page;
	XSpiPs_Config *SpiConfig;

	/*
	 * Initialize the SPI driver so that it's ready to use
	 */
	SpiConfig = XSpiPs_LookupConfig(SpiDeviceId);
	if (NULL == SpiConfig) {
		return XST_FAILURE;
	}

	Status = XSpiPs_CfgInitialize(SpiInstancePtr, SpiConfig,
				       SpiConfig->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Perform a self-test to check hardware build
	 */
	Status = XSpiPs_SelfTest(SpiInstancePtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Set the Spi device as a master. External loopback is required.
	 */
	XSpiPs_SetOptions(SpiInstancePtr, XSPIPS_MASTER_OPTION |
			   XSPIPS_FORCE_SSELECT_OPTION);

	XSpiPs_SetClkPrescaler(SpiInstancePtr, XSPIPS_CLK_PRESCALE_64);

	/*
	 * Initialize the write buffer for a pattern to write to the EEPROM
	 * and the read buffer to zero so it can be verified after the read, the
	 * test value that is added to the unique value allows the value to be
	 * changed in a debug environment to guarantee
	 */
	for (UniqueValue = 13, Count = 0; Count < MAX_DATA;
					Count++, UniqueValue++) {
		WriteBuffer[WRITE_DATA_OFFSET + Count] =
					(u8)(UniqueValue + Test);
		ReadBuffer[READ_DATA_OFFSET + Count] = 0xA5;
	}

	/*
	 * Assert the EEPROM chip select
	 */
	XSpiPs_SetSlaveSelect(SpiInstancePtr, EEPROM_SPI_SELECT);

	/*
	 * Write the data in the write buffer to the serial EEPROM a page at a
	 * time, read the data back from the EEPROM and verify it
	 */
	UniqueValue = 13;
	for (Page = 0; Page < PAGE_COUNT; Page++) {
		EepromWrite(SpiInstancePtr, Page * PAGE_SIZE, PAGE_SIZE,
				&WriteBuffer[Page * PAGE_SIZE]);
		EepromRead(SpiInstancePtr, Page * PAGE_SIZE, PAGE_SIZE,
				ReadBuffer);

		BufferPtr = &ReadBuffer[READ_DATA_OFFSET];
		for (Count = 0; Count < PAGE_SIZE; Count++, UniqueValue++) {
			if (BufferPtr[Count] != (u8)(UniqueValue + Test)) {
				return XST_FAILURE;
			}
		}
	}

	return XST_SUCCESS;
}
Пример #5
0
/**********************************************函数定义***************************************************** 
* 函数名称: void MotoInit(void) 
* 输入参数: void 
* 返回参数: void  
* 功    能:   
* 作    者: by lhb_steven
* 日    期: 2016/7/13
************************************************************************************************************/ 
void MotoInit(void) {
    PD_DDR_DDR2 = 1;//压纸机调速
    PD_CR1_C12 = 1;
    PD_CR2_C22 = 1;
    
    PD_DDR_DDR3 = 1;//切纸机调速
    PD_CR1_C13 = 1;
    PD_CR2_C23 = 1;
    
    PD_DDR_DDR4 = 1;//蜂鸣器
    PD_CR1_C14 = 1;
    PD_CR2_C24 = 1;
    
    PC_DDR_DDR4 = 1;//继电器-压纸方向
    PC_CR1_C14 = 1;
    PC_CR2_C24 = 1;
    
    PC_DDR_DDR5 = 1;//继电器-电源控制
    PC_CR1_C15 = 1;
    PC_CR2_C25 = 1;
    
    PC_DDR_DDR6 = 1;//继电器-切纸方向
    PC_CR1_C16 = 1;
    PC_CR2_C26 = 1;
    
    PC_DDR_DDR1 = 1;//步进电机-方向
    PC_CR1_C11 = 1;
    PC_CR2_C21 = 1;
    
    PC_DDR_DDR2 = 1;//步进电机-脉冲
    PC_CR1_C12 = 1;
    PC_CR2_C22 = 1;
    
    PB_DDR_DDR2 = 0;//压纸霍尔
    PB_CR1_C12 = 1;
    PB_CR2_C22 = 1;
    
    PB_DDR_DDR1 = 0;//压纸上限位
    PB_CR1_C11 = 1;
    PB_CR2_C21 = 0;
    
    PB_DDR_DDR0 = 0;//推纸后限位--步进电机限位
    PB_CR1_C10 = 1;
    PB_CR2_C20 = 0;
    
    PB_DDR_DDR3 = 0;//切纸下限位
    PB_CR1_C13 = 0;
    PB_CR2_C23 = 1;
    
    PB_DDR_DDR4 = 0;//切纸上限位
    PB_CR1_C14 = 1;
    PB_CR2_C24 = 1;
    
    PE_DDR_DDR5 = 0;//交流相位同步
    PE_CR1_C15 = 0;
    PE_CR2_C25 = 0;//需要载打开
    
    EXTI_CR2 |= BIT(1);//开启PD口中断
	EXTI_CR2 &= ~BIT(0);
    
    PC_DDR_DDR3 = 1;//刀光线使能
    PC_CR1_C13 = 1;
    PC_CR2_C23 = 1;
    
    PB_DDR_DDR5 = 0;//安全光幕
    PB_CR1_C15 = 0;
    PB_CR2_C25 = 0;
    
    CUTTER_SLEEP = 1;
    PLATEN_SLEEP = 1;
    
    TIM1_PSCRH = 0;
    TIM1_PSCRL = 15;          //(15+1)分频为1M
    TIM1_ARRH = 0x1;
    TIM1_ARRL = 0xF4;        //每500us中断一次
    TIM1_IER = 0x01;         //允许更新中断
    TIM1_CR1 = 0x00;         //计数器使能,开始计数
    
    //TIM2/3/4/5/6须使用与芯片对应的头文件
    TIM2_PSCR_PSC = 4;          //2^4 分频为1M 
    TIM2_ARRH = 0x17;
    TIM2_ARRL = 0xA0;        //每4000us中断一次
    TIM2_IER = 0x01;         //允许更新中断
    //TIM2_CR1 = 0x00;         //计数器使能,开始计数
    
    
    CUTTER_LIGHT = 1;//打开激光指示
    
    EXTI_CR1 &= ~BIT(2);//开启PD口中断 1 0
	EXTI_CR1 |= BIT(3);
    
    EXTI_CR1_PBIS = 2;    //PB下降沿触发
    //第一次初始化
    if(EepromRead(9) != 0x55) {
        EepromWrite(9,0x55);
        EepromWrite(10,0x00);
        EepromWrite(11,0x00);
//        //力度初始化
//        EepromWrite(12,0x04);
//        EepromWrite(13,0x04);
//        
//        EepromWrite(14,0x04);
    }
    EXTI_CR2_PEIS = 1;    //上升沿触发
    
    stepping1.position = EepromRead(10);
    stepping1.position |= (u16)(EepromRead(11) << 8);
    stepping1.position_last = stepping1.position;
    
    autu_n.process = 0;
    autu_n.push_book = EepromRead(12);
    autu_n.specal_rst = EepromRead(13);
    autu_n.sui_cut_num = EepromRead(14);
    
    autu_n.sui_length = EepromRead(15);
    autu_n.sui_length |= (u16)(EepromRead(16) << 8);
    
    autu_n.sui_length = EepromRead(15);
    autu_n.sui_length |= (u16)(EepromRead(16) << 8);
    
    autu_n.sui_length_book = EepromRead(17);
    autu_n.sui_length_book |= (u16)(EepromRead(18) << 8);
    
    moto1.strength = EepromRead(19);
    moto1.strength |= (u16)(EepromRead(20) << 8);
    //保护
    if(moto1.strength > 4000) {
        moto1.strength = 1000;
    } else if(moto1.strength < 1000) {
        moto1.strength = 1000;
    }
}
Пример #6
0
/**
* @brief  Identifies the SPIRIT1 Xtal frequency and version.
* @param  None
* @retval Status
*/
void SpiritManagementIdentificationRFBoard(void)
{
    do{
      /* Delay for state transition */
      for(volatile uint8_t i=0; i!=0xFF; i++);
      
      /* Reads the MC_STATUS register */
     SpiritRefreshStatus();
    }while(g_xStatus.MC_STATE!=MC_STATE_READY);

  SdkEvalSetHasEeprom(EepromIdentification());
  
  if(!SdkEvalGetHasEeprom()) /* EEPROM is not present*/
  {    
    SpiritManagementComputeSpiritVersion();
    SpiritManagementComputeXtalFrequency(); 
  }
  else  /* EEPROM found*/
  {
    /*read the memory and set the variable*/
    EepromRead(0x0000, 32, tmpBuffer);
    uint32_t xtal;
    if(tmpBuffer[0]==0 || tmpBuffer[0]==0xFF) {
      SpiritManagementComputeSpiritVersion();
      SpiritManagementComputeXtalFrequency();
      return;
    }
    switch(tmpBuffer[1]) {
    case 0:
      xtal = 24000000;
      SpiritRadioSetXtalFrequency(xtal);
      break;
    case 1:
      xtal = 25000000;
      SpiritRadioSetXtalFrequency(xtal);
      break;
    case 2:
      xtal = 26000000;
      SpiritRadioSetXtalFrequency(xtal);
      break;
    case 3:
      xtal = 48000000;
      SpiritRadioSetXtalFrequency(xtal);
      break;
    case 4:
      xtal = 50000000;
      SpiritRadioSetXtalFrequency(xtal);
      break;
    case 5:
      xtal = 52000000;
      SpiritRadioSetXtalFrequency(xtal);
      break;
    default:
      SpiritManagementComputeXtalFrequency();
      break;
    }
    
    SpiritVersion spiritVersion;
    if(tmpBuffer[2]==0 || tmpBuffer[2]==1) {
      spiritVersion = SPIRIT_VERSION_2_1;
      //SpiritGeneralSetSpiritVersion(spiritVersion); 
    }
    else if(tmpBuffer[2]==2) {
      spiritVersion = SPIRIT_VERSION_3_0;
      //SpiritGeneralSetSpiritVersion(spiritVersion);
    }
    else {
      SpiritManagementComputeSpiritVersion();
    }
    if(tmpBuffer[14]==1) {
      spiritVersion = SPIRIT_VERSION_3_0_D1;
     // SpiritGeneralSetSpiritVersion(spiritVersion);
    }
    
    RangeExtType range;
    if(tmpBuffer[5]==0) {
      range = RANGE_EXT_NONE;
    }
    else if(tmpBuffer[5]==1) {
      range = RANGE_EXT_SKYWORKS_169;
    }
    else if(tmpBuffer[5]==2) {
      range = RANGE_EXT_SKYWORKS_868;
    }
    else {
      range = RANGE_EXT_NONE;
    }
    SpiritManagementSetRangeExtender(range);
    
    SpiritManagementSetBand(tmpBuffer[3]);
    
  }
}
/*****************************************************************************
*
* The purpose of this function is to illustrate how to use the XSpiPs
* device driver in interrupt mode . This test writes and reads data from a
* serial EEPROM.
* This part must be present in the hardware to use this example.
*
* @param	IntcInstancePtr is a pointer to the GIC driver to use.
* @param	SpiInstancePtr is a pointer to the SPI driver to use.
* @param	SpiDeviceId is the DeviceId of the Spi device.
* @param	SpiIntrId is the Spi Interrupt Id.
*
* @return	XST_SUCCESS if successful else XST_FAILURE.
*
* @note
*
* This function calls functions which contain loops that may be infinite
* if interrupts are not working such that it may not return. If the device
* slave select is not correct and the device is not responding on bus it will
* read a status of 0xFF for the status register as the bus is pulled up.
*
*****************************************************************************/
int SpiPsEepromIntrExample(XScuGic *IntcInstancePtr, XSpiPs *SpiInstancePtr,
			 u16 SpiDeviceId, u16 SpiIntrId)
{
	int Status;
	u8 *BufferPtr;
	u8 UniqueValue;
	int Count;
	int Page;
	XSpiPs_Config *SpiConfig;

	/*
	 * Initialize the SPI driver so that it's ready to use
	 */
	SpiConfig = XSpiPs_LookupConfig(SpiDeviceId);
	if (NULL == SpiConfig) {
		return XST_FAILURE;
	}

	Status = XSpiPs_CfgInitialize(SpiInstancePtr, SpiConfig,
				       SpiConfig->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Perform a self-test to check hardware build
	 */
	Status = XSpiPs_SelfTest(SpiInstancePtr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Connect the Spi device to the interrupt subsystem such that
	 * interrupts can occur. This function is application specific
	 */
	Status = SpiSetupIntrSystem(IntcInstancePtr, SpiInstancePtr, SpiIntrId);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Setup the handler for the SPI that will be called from the
	 * interrupt context when an SPI status occurs, specify a pointer to
	 * the SPI driver instance as the callback reference so the handler is
	 * able to access the instance data
	 */
	XSpiPs_SetStatusHandler(SpiInstancePtr, SpiInstancePtr,
				 (XSpiPs_StatusHandler) SpiHandler);

	/*
	 * Set the Spi device as a master. External loopback is required.
	 */
	XSpiPs_SetOptions(SpiInstancePtr, XSPIPS_MASTER_OPTION |
			   XSPIPS_FORCE_SSELECT_OPTION);

	XSpiPs_SetClkPrescaler(SpiInstancePtr, XSPIPS_CLK_PRESCALE_64);

	/*
	 * Initialize the write buffer for a pattern to write to the EEPROM
	 * and the read buffer to zero so it can be verified after the read, the
	 * test value that is added to the unique value allows the value to be
	 * changed in a debug environment to guarantee
	 */
	for (UniqueValue = 13, Count = 0; Count < MAX_DATA;
					Count++, UniqueValue++) {
		WriteBuffer[WRITE_DATA_OFFSET + Count] =
					(u8)(UniqueValue + Test);
		ReadBuffer[READ_DATA_OFFSET + Count] = 0xA5;
	}

	/*
	 * Assert the EEPROM chip select
	 */
	XSpiPs_SetSlaveSelect(SpiInstancePtr, EEPROM_SPI_SELECT);

	/*
	 * Write the data in the write buffer to the serial EEPROM a page at a
	 * time
	 */
	for (Page = 0; Page < PAGE_COUNT; Page++) {
		EepromWrite(SpiInstancePtr, Page * PAGE_SIZE, PAGE_SIZE,
				&WriteBuffer[Page * PAGE_SIZE]);
	}

	/*
	 * Read the contents of the entire EEPROM from address 0, since this
	 * function reads the entire EEPROM it will take some amount of time to
	 * complete
	 */
	EepromRead(SpiInstancePtr, 0, MAX_DATA, ReadBuffer);

	/*
	 * Setup a pointer to the start of the data that was read into the read
	 * buffer and verify the data read is the data that was written
	 */
	BufferPtr = &ReadBuffer[READ_DATA_OFFSET];

	for (UniqueValue = 13, Count = 0; Count < MAX_DATA;
					Count++, UniqueValue++) {
		if (BufferPtr[Count] != (u8)(UniqueValue + Test)) {
			return XST_FAILURE;
		}
	}

	SpiDisableIntrSystem(IntcInstancePtr, SpiIntrId);
	return XST_SUCCESS;
}