aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c')
-rw-r--r--Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c42
1 files changed, 37 insertions, 5 deletions
diff --git a/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c b/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c
index 8682f706a..48e29e54c 100644
--- a/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c
+++ b/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c
@@ -53,7 +53,7 @@ FIL *UploadFileHandle = 0; //the system supports a single active file
FIL *DownloadFileHandle = 0; //the system supports a single active file
char FileHandleChar[5];
char ErrorMsg[100];
-#define MAX_CHUNK_LENGTH 4000
+#define MAX_CHUNK_LENGTH 5500
int32_t FileLength = 0;
int32_t FileReceivedLength = 0;
int32_t FileSentLength = 0;
@@ -62,6 +62,7 @@ uint32_t WrittenBytes = 0;
uint32_t ReadBytes = 0;
Task_Handle CommRxTaskHandle;
+extern Semaphore_Handle FFS_Sem;
ErrorCode getErrorCode(FRESULT Fresult)
{
@@ -73,6 +74,7 @@ bool isDirectory(FileAttribute FileAtt)
return true;
return false;
}
+bool FileDone = false;
uint32_t FileUploadRequestFunc(MessageContainer* requestContainer)
{
@@ -96,6 +98,7 @@ uint32_t FileUploadRequestFunc(MessageContainer* requestContainer)
Fresult = FR_DENIED;
else
{
+ Semaphore_pend(FFS_Sem, BIOS_WAIT_FOREVER);
Fresult = f_open(UploadFileHandle,request->path,FA_READ | FA_WRITE | FA_OPEN_ALWAYS | FA_CREATE_ALWAYS);
if (Fresult == FR_OK)
{
@@ -106,17 +109,20 @@ uint32_t FileUploadRequestFunc(MessageContainer* requestContainer)
response.maxchunklength = MAX_CHUNK_LENGTH;
strcpy(FileHandleChar, "1234");
response.uploadid = FileHandleChar; //supporting only single file at each time.
+ FileDone = false;
}
else
{
my_free (UploadFileHandle);
UploadFileHandle = 0;
+ Semaphore_post(FFS_Sem);
}
}
}
CommRxTaskHandle = Task_self();
Task_setPri(CommRxTaskHandle, 4);
+ // Report("Task_setPri", __FILE__, __LINE__, 4, RpWarning, (int)CommRxTaskHandle, 0);
responseContainer = createContainer(MESSAGE_TYPE__FileUploadResponse, requestContainer->token, false, &response, &file_upload_response__pack, &file_upload_response__get_packed_size);
@@ -134,7 +140,6 @@ uint32_t FileUploadRequestFunc(MessageContainer* requestContainer)
return OK;
}
-bool FileDone = false;
FRESULT lFresult = FR_OK;
uint32_t FileChunkUploadRequestFunc(MessageContainer* requestContainer)
{
@@ -155,7 +160,8 @@ uint32_t FileChunkUploadRequestFunc(MessageContainer* requestContainer)
// memcpy (&ReceivedFileHandle,request->uploadid,sizeof(ReceivedFileHandle));
//if (ReceivedFileHandle == FileHandle)
//{
- Control_WD(ENABLE,10); //activate heaters/dispenser watchdog, 0.5 seconds
+ Control_WD(ENABLE,55); //activate heaters/dispenser watchdog, 0.5 seconds
+ GeneralHwReady = false;
KeepAliveOneSecondCounter = 0;
Fresult = f_write(ReceivedFileHandle,request->buffer.data,request->buffer.len,&WrittenBytes );
lFresult = Fresult;
@@ -213,8 +219,12 @@ uint32_t FileChunkUploadRequestFunc(MessageContainer* requestContainer)
my_free(responseContainer.data.data);
SendCharsWithType(container_buffer, container_size,MESSAGE_TYPE__FileChunkUploadResponse);
if (FileDone == true)
+ {
Task_setPri(CommRxTaskHandle, 9);
-
+ GeneralHwReady = true;
+ Semaphore_post(FFS_Sem);
+ //Report("Task_setPri", __FILE__, __LINE__, 9, RpWarning, (int)CommRxTaskHandle, 0);
+ }
return OK;
}
uint32_t FileDownloadRequestFunc(MessageContainer* requestContainer)
@@ -246,6 +256,7 @@ uint32_t FileDownloadRequestFunc(MessageContainer* requestContainer)
Fresult = FR_DENIED;
else
{
+ Semaphore_pend(FFS_Sem, BIOS_WAIT_FOREVER);
Fresult = f_open(DownloadFileHandle,request->filename,FA_READ );
if (Fresult == FR_OK)
{
@@ -303,6 +314,7 @@ uint32_t FileChunkDownloadRequestFunc(MessageContainer* requestContainer)
{
REPORT_MSG (FileSentLength,"file download ended successfully");
f_close(SentFileHandle);
+ Semaphore_post(FFS_Sem);
my_free (DownloadFileHandle);
FileSentLength = 0;
}
@@ -312,6 +324,7 @@ uint32_t FileChunkDownloadRequestFunc(MessageContainer* requestContainer)
{
REPORT_MSG (FileSentLength,"file download too much data!");
f_close(SentFileHandle);
+ Semaphore_post(FFS_Sem);
my_free (DownloadFileHandle);
FileSentLength = 0;
}
@@ -408,6 +421,7 @@ uint32_t CreateRequestFunc(MessageContainer* requestContainer)
Fresult = FR_DENIED;
else
{
+ Semaphore_pend(FFS_Sem, BIOS_WAIT_FOREVER);
Fresult = f_open(UploadFileHandle,request->path,FA_CREATE_NEW);
if (Fresult == FR_OK)
{
@@ -416,6 +430,7 @@ uint32_t CreateRequestFunc(MessageContainer* requestContainer)
Fresult = FR_LOCKED;
}
}
+ Semaphore_post(FFS_Sem);
}
}
if (Fresult != FR_OK)
@@ -455,7 +470,9 @@ uint32_t DeleteRequestFunc(MessageContainer* requestContainer)
//int NumOfFiles = 0;
FRESULT Fresult = FR_OK;
+ Semaphore_pend(FFS_Sem, BIOS_WAIT_FOREVER);
Fresult = f_unlink(request->path);
+ Semaphore_post(FFS_Sem);
REPORT_MSG(Fresult, "File Delete");
responseContainer = createContainer(MESSAGE_TYPE__DeleteResponse, requestContainer->token, false, &response, &delete_response__pack, &delete_response__get_packed_size);
@@ -537,9 +554,11 @@ uint32_t GetFilesRequestFunc(MessageContainer* requestContainer)
int i,NumOfFiles = 0;
FRESULT Fresult = FR_OK;
+ Semaphore_pend(FFS_Sem, BIOS_WAIT_FOREVER);
Fresult |= f_opendir(&dir, g_cCwdBuf);
if(Fresult != FR_OK)
{
+ Semaphore_post(FFS_Sem);
return(Fresult);
}
@@ -568,6 +587,7 @@ uint32_t GetFilesRequestFunc(MessageContainer* requestContainer)
}
}
}
+ Semaphore_post(FFS_Sem);
if ((Fresult == FR_OK)&&(NumOfFiles))
{
@@ -580,7 +600,9 @@ uint32_t GetFilesRequestFunc(MessageContainer* requestContainer)
Data[i].name = fno[i]->fname;
Data[i].has_length = true;
Data[i].length = fno[i]->fsize;
+ Data[i].has_lastmodifieddate = true;
Data[i].lastmodifieddate = fno[i]->fdate;
+ Data[i].has_lastmodifiedtime = true;
Data[i].lastmodifiedtime = fno[i]->ftime;
if (i==0)
usnprintf(&FullPath[i], 50, "%s", request->path);
@@ -624,7 +646,7 @@ uint32_t GetFilesRequestFunc(MessageContainer* requestContainer)
}
return Fresult;
}
-FRESULT FileWrite(void * buffer, uint16_t size,char *path)
+FRESULT FileWrite(void * buffer, uint16_t size,char *path, uint32_t timeout)
{
FRESULT Fresult = FR_OK;
FIL *FileHandle = 0; //the system supports a single active file
@@ -637,6 +659,12 @@ FRESULT FileWrite(void * buffer, uint16_t size,char *path)
Fresult = FR_DENIED;
else
{
+ if (Semaphore_pend(FFS_Sem, timeout) == false)
+ {
+ LOG_ERROR (false,"file system busy error");
+ return FR_TIMEOUT;
+ }
+
Fresult = f_open(FileHandle,path,FA_WRITE | FA_OPEN_ALWAYS);
if (Fresult == FR_OK)
{
@@ -651,6 +679,7 @@ FRESULT FileWrite(void * buffer, uint16_t size,char *path)
{
LOG_ERROR (Fresult,"fopen error");
}
+ Semaphore_post(FFS_Sem);
my_free(FileHandle);
}
}
@@ -680,6 +709,7 @@ FRESULT FileRead(char *path, uint32_t *Size, void **Buffer)
Fresult = FR_DENIED;
else
{
+ Semaphore_pend(FFS_Sem, BIOS_WAIT_FOREVER);
Fresult = f_open(FileHandle,path,FA_READ);
if (Fresult == FR_OK)
{
@@ -695,6 +725,7 @@ FRESULT FileRead(char *path, uint32_t *Size, void **Buffer)
my_free (buffer);
}
f_close(FileHandle);
+ Semaphore_post(FFS_Sem);
}
else
{
@@ -733,6 +764,7 @@ FRESULT FileOpen(char *path, uint32_t *Size, FIL *FileHandle)
if (FileHandle == 0)
Fresult = FR_DENIED;
else
+ Semaphore_pend(FFS_Sem, BIOS_WAIT_FOREVER);
Fresult = f_open(FileHandle,path,FA_READ);
}
else