diff options
| author | Avi Levkovich <avi@twine-s.com> | 2018-07-25 09:22:26 +0300 |
|---|---|---|
| committer | Avi Levkovich <avi@twine-s.com> | 2018-07-25 09:22:26 +0300 |
| commit | 4c762fc44aebe2b566d41f5073c0f0ee72f87bca (patch) | |
| tree | 9758d04f700ea0ff7f720ad5faf3de931f21f139 /Software/Embedded_SW/Embedded/Drivers/Flash_Memory | |
| parent | 6509a45db0a72d65ce84078b8ad2096e224895fc (diff) | |
| download | Tango-4c762fc44aebe2b566d41f5073c0f0ee72f87bca.tar.gz Tango-4c762fc44aebe2b566d41f5073c0f0ee72f87bca.zip | |
Add functions to R/W buffers from the external Flash
Diffstat (limited to 'Software/Embedded_SW/Embedded/Drivers/Flash_Memory')
| -rw-r--r-- | Software/Embedded_SW/Embedded/Drivers/Flash_Memory/Flash_Memory.c | 105 | ||||
| -rw-r--r-- | Software/Embedded_SW/Embedded/Drivers/Flash_Memory/Flash_Memory.h | 10 |
2 files changed, 111 insertions, 4 deletions
diff --git a/Software/Embedded_SW/Embedded/Drivers/Flash_Memory/Flash_Memory.c b/Software/Embedded_SW/Embedded/Drivers/Flash_Memory/Flash_Memory.c index 2d6789fb3..08557697a 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Flash_Memory/Flash_Memory.c +++ b/Software/Embedded_SW/Embedded/Drivers/Flash_Memory/Flash_Memory.c @@ -1,5 +1,6 @@ //Avi Last update: 20/12/17 //Based on TM4C129_SSI3_MacronixFlash.c +//see also https://github.com/yuvadm/tiva-c/blob/master/boards/dk-tm4c129x/drivers/mx66l51235f.c //On board Quad SPI 512Mb Flash #include <stdlib.h> @@ -34,6 +35,7 @@ #include "drivers/twine_graphicslib/graphics_adapter.h" #include "include.h" #include <drivers/Flash_Memory/Flash_Memory.h> +#include <DataDef.h> //#define NUM_SSI_DATA 20 #define INS_WRITE_ENABLE 0x06 @@ -763,9 +765,108 @@ int Ext_Flash_Operation(uint32_t ui32Address,uint32_t Operation, uint32_t NumOf return 0; } +//------------------------------------------------------------- +Flash_Union Flash_RW; -//------------------------------ test ------------------------- +uint32_t WriteBuf[MaxFlashBytes]; +uint32_t ReadBuf[MaxFlashBytes]; + +uint32_t ExtFlashWriteBuf(uint32_t ui32Address,uint32_t NumOfWords, uint32_t* pui32DataTx) +{ + uint32_t status = PASSED; + + static uint32_t AddressCounter = 0; + uint32_t i; + uint32_t No_Bytes; + + assert(NumOfWords <= MaxFlashWords); + + No_Bytes = NumOfWords *4; + + memset(&Flash_RW,0,sizeof(Flash_RW)); + + for(i = 0; i < NumOfWords;i++) + { + Flash_RW.DWords[i] = pui32DataTx[i]; + } + + for(i = 0; i < No_Bytes;i++) + { + WriteBuf[i] = Flash_RW.Bytes[i]; + } + + if(No_Bytes >MaxBytesForAddress) + { + uint32_t number = No_Bytes / MaxBytesForAddress; + uint32_t Remainder = No_Bytes % MaxBytesForAddress; + + for(i=0;i<number;i++,AddressCounter++) + { + Ext_Flash_Operation(0X00 + (0X100*AddressCounter) , TX, MaxBytesForAddress , WriteBuf+ (MaxBytesForAddress*i), NULL ); + } + if(Remainder) + { + Ext_Flash_Operation(0X00 + (0X100*AddressCounter) , TX, Remainder , WriteBuf+ (MaxBytesForAddress*i), NULL ); + } + } + else + { + Ext_Flash_Operation(0X00 + (0X100*AddressCounter), TX, No_Bytes , WriteBuf, NULL ); + } + + return status; +} + + +uint32_t ExtFlashReadBuf(uint32_t ui32Address,uint32_t NumOfWords, uint32_t* pui32DataRx ) +{ + uint32_t status = PASSED; + + uint32_t No_Bytes; + + static uint32_t AddressCounter = 0; + uint32_t i = 0; + + assert(NumOfWords <= MaxFlashWords); + + No_Bytes = NumOfWords *4; + + memset(&Flash_RW,0,sizeof(Flash_RW)); + + if(No_Bytes >MaxBytesForAddress) + { + uint32_t number = No_Bytes / MaxBytesForAddress; + uint32_t Remainder = No_Bytes % MaxBytesForAddress; + + for(i=0;i<number;i++,AddressCounter++) + { + Ext_Flash_Operation(0X00 + (0X100*AddressCounter), RX, MaxBytesForAddress, NULL, ReadBuf + (MaxBytesForAddress*i) ); + } + if(Remainder) + { + Ext_Flash_Operation(0X00 + (0X100*AddressCounter), RX, Remainder, NULL, ReadBuf + (MaxBytesForAddress*i) ); + } + } + else + { + Ext_Flash_Operation(0X00 + (0X100*AddressCounter), RX, No_Bytes, NULL, ReadBuf ); + } + + for(i = 0; i < No_Bytes;i++) + { + Flash_RW.Bytes[i] = ReadBuf[i]; + } + + for(i = 0; i < NumOfWords;i++) + { + pui32DataRx[i] = Flash_RW.DWords[i]; + } + + return status; +} +//------------------------------ test ------------------------- +/* FlashMem Flash; uint32_t Test_Write_Flash_Buf() @@ -884,4 +985,4 @@ uint32_t Test_Write_Flash_Buf() return OK; } - +*/ diff --git a/Software/Embedded_SW/Embedded/Drivers/Flash_Memory/Flash_Memory.h b/Software/Embedded_SW/Embedded/Drivers/Flash_Memory/Flash_Memory.h index 7b27ce1fb..046dab705 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Flash_Memory/Flash_Memory.h +++ b/Software/Embedded_SW/Embedded/Drivers/Flash_Memory/Flash_Memory.h @@ -4,9 +4,15 @@ int Ext_Flash_Operation(); int FlashFS_Init(); +uint32_t ExtFlashWriteBuf(uint32_t ui32Address,uint32_t NumOfWords, uint32_t* pui32DataTx); +uint32_t ExtFlashReadBuf(uint32_t ui32Address,uint32_t NumOfWords, uint32_t* pui32DataRx ); -//--------------- +extern Flash_Union Flash_RW; +extern uint32_t WriteBuf[MaxFlashBytes]; +extern uint32_t ReadBuf[MaxFlashBytes]; +//--------------- +/* #include <stdlib.h> #include <stdint.h> #include <stdbool.h> @@ -122,5 +128,5 @@ typedef union Data_Struct DWord; uint32_t Buf[Data_Size]; }FlashMem; - +*/ #endif //FLASHMEMORY_H |
