diff --git a/firmware/ec/platform/oc-sdr/cfg/OC_CONNECT_GBC.c b/firmware/ec/platform/oc-sdr/cfg/OC_CONNECT_GBC.c index a8355207ef..16e41e0253 100644 --- a/firmware/ec/platform/oc-sdr/cfg/OC_CONNECT_GBC.c +++ b/firmware/ec/platform/oc-sdr/cfg/OC_CONNECT_GBC.c @@ -72,7 +72,7 @@ AT45DB_Dev gbc_spi_flash_memory = { .bus = OC_CONNECT1_SPI0, .chip_select = &(OcGpio_Pin){ &ec_io, OC_EC_FLASH_nCS }, }, - //.pin_evt = NULL, + .pin_alert = NULL, }, .obj = {}, }; diff --git a/firmware/ec/src/Board.h b/firmware/ec/src/Board.h index c9467a313c..551d82422f 100644 --- a/firmware/ec/src/Board.h +++ b/firmware/ec/src/Board.h @@ -53,7 +53,6 @@ extern "C" { #define Board_initUSB OC_CONNECT1_initUSB #define Board_initWatchdog OC_CONNECT1_initWatchdog -#define Board_EC_FLASH OC_EC_FLASH_nCS #define Board_IOEXP_ALERT OC_EC_GBC_IOEXP71_ALERT #define Board_ECINA_ALERT OC_EC_GBC_INA_ALERT #define Board_APINA_ALERT OC_EC_GBC_AP_INA_ALERT diff --git a/firmware/ec/src/devices/at45db.c b/firmware/ec/src/devices/at45db.c index e608d19e2d..fb51ee88e6 100644 --- a/firmware/ec/src/devices/at45db.c +++ b/firmware/ec/src/devices/at45db.c @@ -6,12 +6,17 @@ * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * +* This file is used as Device layer for AT45DB641E. Mainly it contains Data read, +* Data write, Page erase, Status check functions, these functions are called by +* littlefs filesystyem in order to perform read/write operation for data using SPI +* interface. Also while post execution device and manufacturing id's of AT45DB641E +* will be verified by probe function. */ #include "inc/devices/at45db.h" #include "inc/common/spibus.h" #include "inc/common/global_header.h" -#include +#include "inc/global/OC_CONNECT1.h" #define AT45DB_MANFACTURE_ID 0x1F #define AT45DB_DEVICE_ID 0x0028 @@ -37,10 +42,10 @@ /***************************************************************************** ** FUNCTION NAME : AT45DB_read_reg ** - ** DESCRIPTION : Read a 8 bit value from at45db page or register. + ** DESCRIPTION : Write 8 bit value to at45db page or register. ** - ** ARGUMENTS : spi device, Register address and value - ** to be read. + ** ARGUMENTS : spi device configuration, cmd buffer, register value, + ** page offset, numOfBytes to be read, cmd write count. ** ** RETURN TYPE : Success or failure ** @@ -76,8 +81,8 @@ static ReturnStatus AT45DB_read_reg(AT45DB_Dev *dev, ** ** DESCRIPTION : Write 8 bit value to at45db page or register. ** - ** ARGUMENTS : spi device, Register address and value - ** to be written. + ** ARGUMENTS : spi device configuration, cmd buffer, register value, + ** page offset, numOfBytes to be written, cmd write count. ** ** RETURN TYPE : Success or failure ** @@ -107,26 +112,48 @@ static ReturnStatus AT45DB_write_reg(AT45DB_Dev *dev, return status; } -unsigned char at45db_readStatusRegister(AT45DB_Dev *dev) +/***************************************************************************** + ** FUNCTION NAME : at45db_readStatusRegister + ** + ** DESCRIPTION : Reads status of at45db device whether it is ready for + ** + ** r/w operation + ** + ** ARGUMENTS : spi device configuration + ** + ** RETURN TYPE : 8-bit status code + ** + *****************************************************************************/ +uint8_t at45db_readStatusRegister(AT45DB_Dev *dev) { - unsigned char txBuffer = AT45DB_STATUS_OPCODE; /* opcode for ready status of AT45DB */; - unsigned char status; + uint8_t txBuffer = AT45DB_STATUS_OPCODE; /* opcode for ready status of AT45DB */; + uint8_t status; AT45DB_read_reg(dev, &txBuffer, &status, NULL, AT45DB_STATUS_RD_BYTES, AT45DB_STATUS_OPCODE_WR_COUNT); return (status); } +/***************************************************************************** + ** FUNCTION NAME : at45db_erasePage + ** + ** DESCRIPTION : Erases at45db memory page before writing data to it + ** + ** ARGUMENTS : spi device configuration, page number to be erased + ** + ** RETURN TYPE : Success or failure + ** + *****************************************************************************/ ReturnStatus at45db_erasePage(AT45DB_Dev *dev, uint32_t page) { ReturnStatus status = RETURN_NOTOK; - unsigned char txBuffer[4]; + uint8_t txBuffer[4]; waitForReady(dev); txBuffer[0] = AT45DB_PAGE_ERASE_OPCODE; /* opcode to erase main memory page */ - txBuffer[1] = (unsigned char)(page >> 7); /* Page size is 15 bits 8 in tx1 and 7 in tx2 */ - txBuffer[2] = (unsigned char)(page << 1); + txBuffer[1] = (uint8_t)(page >> 7); /* Page size is 15 bits 8 in tx1 and 7 in tx2 */ + txBuffer[2] = (uint8_t)(page << 1); txBuffer[3] = 0x00; status = AT45DB_write_reg(dev, txBuffer, NULL, NULL, NULL, AT45DB_ERASE_OPCODE_WR_COUNT); @@ -134,34 +161,58 @@ ReturnStatus at45db_erasePage(AT45DB_Dev *dev, uint32_t page) return status; } +/***************************************************************************** + ** FUNCTION NAME : at45db_data_read + ** + ** DESCRIPTION : Reads data from at45db memory page + ** + ** ARGUMENTS : spi device configuration, data pointer, data size, + ** + ** page offset, page number + ** + ** RETURN TYPE : Success or failure + ** + *****************************************************************************/ ReturnStatus at45db_data_read(AT45DB_Dev *dev, uint8_t *data, uint32_t data_size, uint32_t byte, uint32_t page) { ReturnStatus status = RETURN_NOTOK; - unsigned char txBuffer[8]; /* last 4 bytes are needed, but have don't care values */ + uint8_t txBuffer[8]; /* last 4 bytes are needed, but have don't care values */ waitForReady(dev); txBuffer[0] = AT45DB_PAGE_RD_OPCODE; /* opcode to read main memory page */ - txBuffer[1] = (unsigned char)(page >> 7); /* Page size is 15 bits 8 in tx1 and 7 in tx2 */ - txBuffer[2] = (unsigned char)((page << 1)); - txBuffer[3] = (unsigned char)(0xFF & byte); + txBuffer[1] = (uint8_t)(page >> 7); /* Page size is 15 bits 8 in tx1 and 7 in tx2 */ + txBuffer[2] = (uint8_t)((page << 1)); + txBuffer[3] = (uint8_t)(0xFF & byte); status = AT45DB_read_reg(dev, &txBuffer, data, byte, data_size, AT45DB_DATA_RD_OPCODE_WR_COUNT); return status; } +/***************************************************************************** + ** FUNCTION NAME : at45db_data_write + ** + ** DESCRIPTION : Writes data to at45db memory page + ** + ** ARGUMENTS : spi device configuration, data pointer, data size, + ** + ** page offset, page number + ** + ** RETURN TYPE : Success or failure + ** + *****************************************************************************/ ReturnStatus at45db_data_write(AT45DB_Dev *dev, uint8_t *data, uint32_t data_size, uint32_t byte, uint32_t page) { ReturnStatus status = RETURN_NOTOK; - unsigned char txBuffer[4]; + uint8_t txBuffer[4]; waitForReady(dev); txBuffer[0] = AT45DB_SRAM_BUFF2_WR_OPCODE; /* opcode to write data to AT45DB SRAM Buffer2 */ txBuffer[1] = 0x00; - txBuffer[2] = (unsigned char)(0x1 & (byte >> 8)); /* 9 bit buffer address */ - txBuffer[3] = (unsigned char)(0xFF & byte); + txBuffer[2] = (uint8_t)(0x1 & (byte >> 8)); /* 9 bit buffer address */ + txBuffer[3] = (uint8_t)(0xFF & byte); status = AT45DB_write_reg(dev, &txBuffer, data, byte, data_size, AT45DB_DATA_WR_OPCODE_WR_COUNT); @@ -169,8 +220,8 @@ ReturnStatus at45db_data_write(AT45DB_Dev *dev, uint8_t *data, uint32_t data_siz waitForReady(dev); txBuffer[0] = AT45DB_PAGE_WR_OPCODE; /* opcode to Push the data from AT45DB SRAM Buffer2 to the page */ - txBuffer[1] = (unsigned char)(page >> 7); /* Page size is 15 bits 8 in tx1 and 7 in tx2 */ - txBuffer[2] = (unsigned char)(page << 1); + txBuffer[1] = (uint8_t)(page >> 7); /* Page size is 15 bits 8 in tx1 and 7 in tx2 */ + txBuffer[2] = (uint8_t)(page << 1); txBuffer[3] = 0x00; status = AT45DB_write_reg(dev, &txBuffer, data, byte, data_size, AT45DB_DATA_WR_OPCODE_WR_COUNT); @@ -178,13 +229,33 @@ ReturnStatus at45db_data_write(AT45DB_Dev *dev, uint8_t *data, uint32_t data_siz return status; } +/***************************************************************************** + ** FUNCTION NAME : at45db_getDevID + ** + ** DESCRIPTION : Reads Device id and manufacturing id of at45db device + ** + ** ARGUMENTS : spi device configuration, data pointer + ** + ** RETURN TYPE : Success or failure + ** + *****************************************************************************/ static ReturnStatus at45db_getDevID(AT45DB_Dev *dev, uint32_t *devID) { - unsigned char txBuffer = AT45DB_DEVID_RD_OPCODE; /* opcode to get device id */ + uint8_t txBuffer = AT45DB_DEVID_RD_OPCODE; /* opcode to get device id */ return AT45DB_read_reg(dev, &txBuffer, devID, NULL, AT45DB_DEVID_RD_BYTES, AT45DB_DEVID_OPCODE_WR_COUNT); } +/***************************************************************************** + ** FUNCTION NAME : at45db_probe + ** + ** DESCRIPTION : Compares device and manufacturing id's for post + ** + ** ARGUMENTS : spi device configuration, post data pointer + ** + ** RETURN TYPE : ePostCode type status, can be found in post_frame.h + ** + *****************************************************************************/ ePostCode at45db_probe(AT45DB_Dev *dev, POSTData *postData) { uint32_t value = 0; diff --git a/firmware/ec/src/devices/ocmp_wrappers/ocmp_at45db.c b/firmware/ec/src/devices/ocmp_wrappers/ocmp_at45db.c index ba2f579fab..519a802490 100644 --- a/firmware/ec/src/devices/ocmp_wrappers/ocmp_at45db.c +++ b/firmware/ec/src/devices/ocmp_wrappers/ocmp_at45db.c @@ -6,12 +6,25 @@ * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * +* This is wrapper file for at45db device contains wrapper functions like probe +* and function table of it. probe function calls device layer functions to +* complete post execution */ #include "common/inc/global/Framework.h" #include "common/inc/ocmp_wrappers/ocmp_at45db.h" #include "inc/devices/at45db.h" +/***************************************************************************** + ** FUNCTION NAME : _probe + ** + ** DESCRIPTION : Wrapper function for post execution + ** + ** ARGUMENTS : spi device configuration, post data pointer + ** + ** RETURN TYPE : ePostCode type status, can be found in post_frame.h + ** + *****************************************************************************/ static ePostCode _probe(void *driver, POSTData *postData) { return at45db_probe(driver,postData); diff --git a/firmware/ec/src/devices/spibus.c b/firmware/ec/src/devices/spibus.c index 1ff0a14c1c..465dcd18cc 100644 --- a/firmware/ec/src/devices/spibus.c +++ b/firmware/ec/src/devices/spibus.c @@ -5,6 +5,9 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. + * + * This file contains SPI driver's API within spi_get_handle, spi_reg_read and + * spi_reg_write which ccan be called by device layer to communicate any SPI device. */ //***************************************************************************** @@ -14,7 +17,7 @@ #include "Board.h" #include "drivers/OcGpio.h" #include "inc/common/spibus.h" -#include +#include "inc/global/OC_CONNECT1.h" #include #include #include @@ -30,7 +33,17 @@ #define PIN_LOW (0) #define PIN_HIGH ~(0) -SPI_Handle spi_get_handle(unsigned int index) { +/***************************************************************************** + ** FUNCTION NAME : spi_get_handle + ** + ** DESCRIPTION : Initialize SPI Bus + ** + ** ARGUMENTS : SPI bus index + ** + ** RETURN TYPE : SPI_Handle (NULL on failure) + ** + *****************************************************************************/ +SPI_Handle spi_get_handle(uint32_t index) { SPI_Params spiParams; SPI_Handle spiHandle; @@ -44,6 +57,18 @@ SPI_Handle spi_get_handle(unsigned int index) { return spiHandle; } +/***************************************************************************** + ** FUNCTION NAME : spi_reg_read + ** + ** DESCRIPTION : Writing device register over SPI bus. + ** + ** ARGUMENTS : SPI handle, chip select, register address, data, data + ** + ** length, offset byte, numOfBytes for cmd write count + ** + ** RETURN TYPE : Success or failure + ** + *****************************************************************************/ ReturnStatus spi_reg_read(SPI_Handle spiHandle, OcGpio_Pin *chip_select, void *regAddress, @@ -85,6 +110,18 @@ ReturnStatus spi_reg_read(SPI_Handle spiHandle, return (status); } +/***************************************************************************** + ** FUNCTION NAME : spi_reg_write + ** + ** DESCRIPTION : Writing device register over SPI bus. + ** + ** ARGUMENTS : SPI handle, chip select, register address, data, data + ** + ** length, offset byte, numOfBytes for cmd write count + ** + ** RETURN TYPE : Success or failure + ** + *****************************************************************************/ ReturnStatus spi_reg_write(SPI_Handle spiHandle, OcGpio_Pin *chip_select, void *regAddress, diff --git a/firmware/ec/src/filesystem/fs_wrapper.c b/firmware/ec/src/filesystem/fs_wrapper.c index 8515d4a628..ba520f061e 100644 --- a/firmware/ec/src/filesystem/fs_wrapper.c +++ b/firmware/ec/src/filesystem/fs_wrapper.c @@ -6,13 +6,17 @@ * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. * +* This file acts as wrapper for little filesystem, contains filesystem initialization, +* block read, block write, block erase as a main functions moreover provides API's +* like fileRead, fileWrite for external application to read and write data to +* at45db flash memory by using SPI interface. */ #include "Board.h" #include "common/inc/global/Framework.h" #include "common/inc/global/ocmp_frame.h" #include "inc/utils/util.h" -#include +#include "inc/global/OC_CONNECT1.h" #include "inc/common/global_header.h" #include "inc/devices/at45db.h" #include "inc/common/bigbrother.h" @@ -41,6 +45,18 @@ static Queue_Struct fsTxMsg; lfs_t lfs; lfs_file_t file; +/***************************************************************************** + ** FUNCTION NAME : block_device_read + ** + ** DESCRIPTION : It is called by filesystem to read block device + ** + ** ARGUMENTS : context for device configuration, block or page number, + ** + ** block or page offset, data buffer, size of data to read + ** + ** RETURN TYPE : Success or failure + ** + *****************************************************************************/ int block_device_read(const struct lfs_config *cfg, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) { @@ -51,6 +67,18 @@ int block_device_read(const struct lfs_config *cfg, lfs_block_t block, return LFS_ERR_OK; } +/***************************************************************************** + ** FUNCTION NAME : block_device_write + ** + ** DESCRIPTION : it is called by filesystem to write block device + ** + ** ARGUMENTS : context for device configuration, block or page number, + ** + ** block or page offset, data buffer, size of data to write + ** + ** RETURN TYPE : Success or failure + ** + *****************************************************************************/ int block_device_write(const struct lfs_config *cfg, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) { @@ -61,6 +89,16 @@ int block_device_write(const struct lfs_config *cfg, lfs_block_t block, return LFS_ERR_OK; } +/***************************************************************************** + ** FUNCTION NAME : block_device_erase + ** + ** DESCRIPTION : It is called by filesystem to erase block device + ** + ** ARGUMENTS : context for device configuration, block or page number, + ** + ** RETURN TYPE : Success or failure + ** + *****************************************************************************/ int block_device_erase(const struct lfs_config *cfg, lfs_block_t block) { if(at45db_erasePage(cfg->context, block) != RETURN_OK){ @@ -70,6 +108,16 @@ int block_device_erase(const struct lfs_config *cfg, lfs_block_t block) return LFS_ERR_OK; } +/***************************************************************************** + ** FUNCTION NAME : block_device_sync + ** + ** DESCRIPTION : It is called by filesystem to sync with block device + ** + ** ARGUMENTS : context for device configuration + ** + ** RETURN TYPE : Success or failure + ** + *****************************************************************************/ int block_device_sync(const struct lfs_config *cfg) { if(at45db_readStatusRegister(cfg->context) != RETURN_OK){ @@ -79,6 +127,16 @@ int block_device_sync(const struct lfs_config *cfg) return LFS_ERR_OK; } +/***************************************************************************** + ** FUNCTION NAME : fileSize + ** + ** DESCRIPTION : Returns size of saved file + ** + ** ARGUMENTS : Path or file name + ** + ** RETURN TYPE : file size + ** + *****************************************************************************/ int fileSize(const char *path) { uint32_t fileSize = 0; @@ -91,6 +149,17 @@ int fileSize(const char *path) return fileSize; } + +/***************************************************************************** + ** FUNCTION NAME : fileWrite + ** + ** DESCRIPTION : It write data to specified file + ** + ** ARGUMENTS : Path or file name, pointer to data, data length or size + ** + ** RETURN TYPE : true or flase + ** + *****************************************************************************/ bool fileWrite(const char *path, uint8_t *pMsg, uint32_t size ) { if(lfs_file_open(&lfs, &file, path, LFS_O_RDWR | LFS_O_CREAT | LFS_O_APPEND) == LFS_ERR_OK) { @@ -105,6 +174,17 @@ bool fileWrite(const char *path, uint8_t *pMsg, uint32_t size ) return true; } + +/***************************************************************************** + ** FUNCTION NAME : fileRead + ** + ** DESCRIPTION : It reads data from specified file + ** + ** ARGUMENTS : Path or file name, pointer to data, data length or size + ** + ** RETURN TYPE : true or flase + ** + *****************************************************************************/ bool fileRead(const char *path, UChar *buf, uint32_t size) { if(lfs_file_open(&lfs, &file, path, LFS_O_RDONLY) == LFS_ERR_OK) { @@ -119,6 +199,17 @@ bool fileRead(const char *path, UChar *buf, uint32_t size) return true; } + +/***************************************************************************** + ** FUNCTION NAME : fsMsgHandler + ** + ** DESCRIPTION : It is called when data to be written + ** + ** ARGUMENTS : data pointer + ** + ** RETURN TYPE : true or flase + ** + *****************************************************************************/ static bool fsMsgHandler(OCMPMessageFrame *pMsg) { char fileName[] = "logs"; @@ -127,6 +218,17 @@ static bool fsMsgHandler(OCMPMessageFrame *pMsg) return true; } + +/***************************************************************************** + ** FUNCTION NAME : fs_init + ** + ** DESCRIPTION : It initializes filesystem by mounting device + ** + ** ARGUMENTS : arg0 for SPI device configuration, arg1 for return + ** + ** RETURN TYPE : true or flase + ** + *****************************************************************************/ void fs_init(UArg arg0, UArg arg1) { /*configuration of the filesystem is provided by this struct */