2011-01-24 08:52:14 +01:00
|
|
|
/*
|
|
|
|
* pios_flash_w25x.c
|
|
|
|
* OpenPilotOSX
|
|
|
|
*
|
|
|
|
* Created by James Cotton on 1/23/11.
|
|
|
|
* Copyright 2011 OpenPilot. All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "pios.h"
|
|
|
|
#include "pios_flash_w25x.h"
|
2011-01-25 18:46:27 +01:00
|
|
|
#include "pios_adxl345.h"
|
2011-01-24 08:52:14 +01:00
|
|
|
|
|
|
|
void PIOS_FLASH_W25X_ClaimBus()
|
|
|
|
{
|
2011-01-24 08:52:17 +01:00
|
|
|
PIOS_SPI_ClaimBus(PIOS_SPI_FLASH);
|
2011-01-25 18:46:27 +01:00
|
|
|
PIOS_ADXL_DISABLE;
|
2011-01-24 08:52:14 +01:00
|
|
|
PIOS_FLASH_ENABLE;
|
2011-01-25 18:46:27 +01:00
|
|
|
PIOS_DELAY_WaituS(1);
|
2011-01-24 08:52:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PIOS_FLASH_W25X_ReleaseBus()
|
|
|
|
{
|
2011-01-25 18:46:27 +01:00
|
|
|
PIOS_ADXL_DISABLE;
|
2011-01-24 08:52:14 +01:00
|
|
|
PIOS_FLASH_DISABLE;
|
2011-01-25 18:46:27 +01:00
|
|
|
PIOS_SPI_ReleaseBus(PIOS_SPI_FLASH);
|
2011-01-24 08:52:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PIOS_FLASH_W25X_Init()
|
|
|
|
{
|
|
|
|
PIOS_FLASH_W25X_ClaimBus();
|
|
|
|
PIOS_FLASH_W25X_ReleaseBus();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Read the status register from flash chip and return it
|
|
|
|
*/
|
|
|
|
uint8_t PIOS_FLASH_ReadStatus()
|
|
|
|
{
|
|
|
|
PIOS_FLASH_W25X_ClaimBus();
|
|
|
|
uint8_t out[2] = {W25X_READ_STATUS, 0};
|
|
|
|
uint8_t in[2] = {0,0};
|
|
|
|
PIOS_SPI_TransferBlock(PIOS_SPI_FLASH,out,in,sizeof(out),NULL);
|
|
|
|
PIOS_FLASH_W25X_ReleaseBus();
|
|
|
|
return in[1];
|
|
|
|
}
|
|
|
|
|
2011-01-25 18:46:27 +01:00
|
|
|
/**
|
|
|
|
* @brief Read the status register from flash chip and return it
|
|
|
|
*/
|
|
|
|
uint8_t PIOS_FLASH_ReadID()
|
|
|
|
{
|
|
|
|
PIOS_FLASH_W25X_ClaimBus();
|
|
|
|
uint8_t out[] = {W25X_DEVICE_ID, 0, 0, 0, 0, 0};
|
|
|
|
uint8_t in[6];
|
|
|
|
PIOS_SPI_TransferBlock(PIOS_SPI_FLASH,out,in,sizeof(out),NULL);
|
|
|
|
PIOS_FLASH_W25X_ReleaseBus();
|
|
|
|
return in[5];
|
|
|
|
}
|
|
|
|
|
2011-01-24 08:52:14 +01:00
|
|
|
void PIOS_FLASH_W25X_WriteData(uint32_t addr, uint8_t * data, uint16_t len)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void PIOS_FLASH_W25X_ReadData(uint32_t addr, uint8_t * data, uint16_t len)
|
|
|
|
{
|
|
|
|
}
|