image/svg+xml
Brteve's API for EveApps
Version 0.0.1
The reference document for common folder of EveApps project.
 
Loading...
Searching...
No Matches
FileTransfer.c File Reference

File transfer interface from host to flash. More...

#include "Platform.h"
#include "EVE_CoCmd.h"
#include "FileIo.h"
#include "FileTransfer.h"
#include "Common.h"

Go to the source code of this file.

Macros

#define __ALIGN_MASK(x, mask)   (((x)+(mask))&~(mask))
 Alignment

 
#define ALIGN(x, a)   __ALIGN_MASK(x, a - 1)
 
#define FREAD_BLOCK   (8 * 1024)
 
#define BLOBSIZE   4096
 
#define EVE_FLASH_DIR   "/Test/common/eve_flash"
 
#define FILE_BLOB   (EVE_FLASH_DIR "\\BT815-unified.blob")
 Use BT815 blob as default.
 

Functions

uint32_t Ftf_Write_File_nBytes_To_RAM_G (EVE_HalContext *phost, const char *file, uint32_t addr, int nbytes, int offset)
 Transfer a file to RAM_G.
 
uint32_t Ftf_Write_File_To_RAM_G (EVE_HalContext *phost, const char *file, uint32_t addr)
 Transfer a file to RAM_G.
 
uint32_t Ftf_Write_FileArr_To_RAM_G (EVE_HalContext *phost, char *file[], uint32_t addr)
 Transfer a file list into RAM_G.
 
uint32_t Ftf_Read_File_From_RAM_G (EVE_HalContext *phost, const uint8_t *output, uint32_t startAddress, uint32_t size)
 Read data on RAM_G into a file.
 

Detailed Description

File transfer interface from host to flash.

Author
Tuan Nguyen tuan..nosp@m.nguy.nosp@m.en@br.nosp@m.tchi.nosp@m.p.com
Date
2019

MIT License

Copyright (c) [2019] [Bridgetek Pte Ltd (BRTChip)]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Definition in file FileTransfer.c.

Macro Definition Documentation

◆ __ALIGN_MASK

#define __ALIGN_MASK (   x,
  mask 
)    (((x)+(mask))&~(mask))

Alignment

Definition at line 40 of file FileTransfer.c.

◆ ALIGN

#define ALIGN (   x,
  a 
)    __ALIGN_MASK(x, a - 1)

Definition at line 41 of file FileTransfer.c.

◆ BLOBSIZE

#define BLOBSIZE   4096

Definition at line 45 of file FileTransfer.c.

◆ EVE_FLASH_DIR

#define EVE_FLASH_DIR   "/Test/common/eve_flash"

Definition at line 50 of file FileTransfer.c.

◆ FILE_BLOB

#define FILE_BLOB   (EVE_FLASH_DIR "\\BT815-unified.blob")

Use BT815 blob as default.

Definition at line 59 of file FileTransfer.c.

◆ FREAD_BLOCK

#define FREAD_BLOCK   (8 * 1024)

Definition at line 43 of file FileTransfer.c.

Function Documentation

◆ Ftf_Read_File_From_RAM_G()

uint32_t Ftf_Read_File_From_RAM_G ( EVE_HalContext phost,
const uint8_t output,
uint32_t  startAddress,
uint32_t  size 
)

Read data on RAM_G into a file.

Parameters
phostPointer to Hal context
outputFilename output
startAddressAddress on RAM_G
sizeSize to read
Returns
uint32_t 1 on successful, 0 on error

Definition at line 825 of file FileTransfer.c.

825 {
826 if (-1 == FileIO_File_Open(output, FILEIO_E_FOPEN_WRITE)) {
827 printf("Unable to open file: %s\n", output);
828 return 0;
829 }
830
831 uint8_t pbuff[FREAD_BLOCK];
832 uint32_t block = 0;
833 uint32_t offset = 0;
834
835 while (size > 0) {
836 block = size > FREAD_BLOCK ? FREAD_BLOCK : size;
837 EVE_Hal_rdMem(phost, pbuff, startAddress + offset, block);
838 offset += block;
839 size -= block;
840
841 if (0 == FileIO_File_Write(pbuff, block)) {
842 printf("Unable to write file: %s\n", output);
843 return 0;
844 }
845
846 }
848
849 return 1;
850}
EVE_HAL_EXPORT void EVE_Hal_rdMem(EVE_HalContext *phost, uint8_t *result, uint32_t addr, uint32_t size)
Read a block data from Coprocessor's memory.
Definition EVE_Hal.c:206
unsigned int uint32_t
unsigned char uint8_t
int FileIO_File_Write(const char *buffer, long buffersize)
Definition FileIo.c:510
int FileIO_File_Open(const char *filePath, enum _FILEIO_E_FOPEN e)
Definition FileIo.c:508
int FileIO_File_Close()
Definition FileIo.c:505
@ FILEIO_E_FOPEN_WRITE
Definition FileIo.h:40
#define FREAD_BLOCK

◆ Ftf_Write_File_nBytes_To_RAM_G()

uint32_t Ftf_Write_File_nBytes_To_RAM_G ( EVE_HalContext phost,
const char *  file,
uint32_t  addr,
int  nbytes,
int  offset 
)

Transfer a file to RAM_G.

Parameters
phostPointer to Hal context
fileFile to transfer
addrAddress on RAM_G
nbytesNumber of bytes to transfer
offsetOffset of the file
Returns
uint32_t Number of bytes transfered on successful, 0 on error

Definition at line 738 of file FileTransfer.c.

738 {
739 const uint32_t BufferSize = FREAD_BLOCK;
740 int32_t bytes;
741 int32_t sent = 0;
742 int32_t fileSize = 0;
743 uint8_t pbuff[FREAD_BLOCK];
744
745 fileSize = FileIO_File_Open(file, FILEIO_E_FOPEN_READ);
746 if (nbytes == 0){
747 nbytes = fileSize;
748 }
749
750 if (offset) {
751 FileIO_File_Seek(offset);
752 }
753
754 if (0 >= fileSize) {
755 printf("Unable to open file: %s\n", file);
756 return 0;
757 }
758 while (fileSize > 0 && sent < nbytes) {
759 bytes = FileIO_File_Read(pbuff, BufferSize);
760 if (bytes == 0) {
761 printf("Error on f_read\n");
762 break;
763 }
764 if ((sent + bytes) > nbytes) {
765 bytes = nbytes - sent;
766 }
767 EVE_Hal_wrMem(phost, addr, pbuff, bytes);
768 fileSize -= bytes;
769 sent += bytes;
770 addr += bytes;
771 }
772
774
775 return sent;
776}
EVE_HAL_EXPORT void EVE_Hal_wrMem(EVE_HalContext *phost, uint32_t addr, const uint8_t *buffer, uint32_t size)
Write a buffer to Coprocessor's memory.
Definition EVE_Hal.c:263
int int32_t
static ft_uint32_t addr
Definition FT_Gpu_Hal.h:139
int FileIO_File_Read(char *buffer, long bytes)
Definition FileIo.c:509
int FileIO_File_Seek(unsigned long offset)
Definition FileIo.c:506
@ FILEIO_E_FOPEN_READ
Definition FileIo.h:40

◆ Ftf_Write_File_To_RAM_G()

uint32_t Ftf_Write_File_To_RAM_G ( EVE_HalContext phost,
const char *  file,
uint32_t  addr 
)

Transfer a file to RAM_G.

Parameters
phostPointer to Hal context
fileFile to transfer
addrAddress on RAM_G
Returns
uint32_t Number of bytes transfered on successful, 0 on error

Definition at line 786 of file FileTransfer.c.

786 {
787 return Ftf_Write_File_nBytes_To_RAM_G(phost, file, addr, 0, 0);
788}
uint32_t Ftf_Write_File_nBytes_To_RAM_G(EVE_HalContext *phost, const char *file, uint32_t addr, int nbytes, int offset)
Transfer a file to RAM_G.

◆ Ftf_Write_FileArr_To_RAM_G()

uint32_t Ftf_Write_FileArr_To_RAM_G ( EVE_HalContext phost,
char *  file[],
uint32_t  addr 
)

Transfer a file list into RAM_G.

Parameters
phostPointer to Hal context
fileFile name array
addrAddress on RAM_G
Returns
uint32_t Number of bytes transfered on successful, 0 on error

Definition at line 798 of file FileTransfer.c.

798 {
799 int i = 0;
800 uint32_t bytes;
801 uint32_t sent = 0;
802 while (file[i] != NULL) {
803 bytes = Ftf_Write_File_To_RAM_G(phost, file[i], addr);
804 if (0 == bytes) {
805 printf("Error when write file: %s\n", file[i]);
806 return 0;
807 }
808
809 sent += bytes;
810 i++;
811 }
812
813 return sent;
814}
uint32_t Ftf_Write_File_To_RAM_G(EVE_HalContext *phost, const char *file, uint32_t addr)
Transfer a file to RAM_G.