aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c
diff options
context:
space:
mode:
authorShlomo Hecht <shlomo@twine-s.com>2020-10-29 15:55:21 +0200
committerShlomo Hecht <shlomo@twine-s.com>2020-10-29 15:55:21 +0200
commit4b789f33eadfc5cc1d937a80ce03ea8425955ffe (patch)
tree7dbbd0529a24f9ca064cab688a0d6d2b8b762ea1 /Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c
parent8f3baa0d9097aa6ed800863a4680608e867c809a (diff)
parent11fb700fcbc4627162a9c3f84b03b5016248bd97 (diff)
downloadTango-4b789f33eadfc5cc1d937a80ce03ea8425955ffe.tar.gz
Tango-4b789f33eadfc5cc1d937a80ce03ea8425955ffe.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c')
-rw-r--r--Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c97
1 files changed, 59 insertions, 38 deletions
diff --git a/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c b/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c
index 84d8fa725..10f33c62b 100644
--- a/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c
+++ b/Software/Embedded_SW/Embedded/Common/SWUpdate/FileSystem.c
@@ -31,10 +31,11 @@
#include <Communication/PMR/IO/GetFilesResponse.pb-c.h>
#include <Communication/PMR/IO/FileAttribute.pb-c.h>
-#include "drivers/Flash_Memory/Flash_Memory.h"
+
#include "drivers/Flash_Memory/fatfs/ff.h"
#include "drivers/FPGA/FPGA_GPIO/FPGA_GPIO.h"
+#include "Modules/Control/Control.h"
#include "StateMachines/Printing/PrintingSTM.h"
@@ -59,6 +60,7 @@ uint32_t ReadBytes = 0;
Task_Handle CommRxTaskHandle;
extern Semaphore_Handle FFS_Sem;
+extern Semaphore_Handle FileUpload_sem_param;
ErrorCode getErrorCode(FRESULT Fresult)
{
@@ -75,12 +77,14 @@ bool FileUploadGetState(void)
{
return FileDone;
}
+int CommRxpri;
+
uint32_t FileUploadRequestFunc(MessageContainer* requestContainer)
{
//uint32_t status = OK;
FRESULT Fresult = FR_OK;
-
+ bool sem_ok = false;
MessageContainer responseContainer;
FileUploadRequest* request = file_upload_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data);
@@ -100,11 +104,22 @@ uint32_t FileUploadRequestFunc(MessageContainer* requestContainer)
Fresult = FR_DENIED;
else
{
- if (Semaphore_pend(FFS_Sem, BIOS_NO_WAIT))
+ if (1)//(Semaphore_pend(FileUpload_sem_param, BIOS_NO_WAIT))
+ {
+ sem_ok = true;
+ }
+ else
+ {
+ Semaphore_post(FileUpload_sem_param);
+ Report("semaphore was not free", __FILE__, __LINE__, request->length, RpWarning, (int)MAX_CHUNK_LENGTH, 0);
+ sem_ok = true;
+ }
+ if (sem_ok == true)
{
CommRxTaskHandle = Task_self();
- Task_setPri(CommRxTaskHandle, 2);
- // Report("Task_setPri", __FILE__, __LINE__, 4, RpWarning, (int)CommRxTaskHandle, 0);
+ CommRxpri = Task_getPri(CommRxTaskHandle);
+ Task_setPri(CommRxTaskHandle, 11);
+ Report("Task_setPri", __FILE__, __LINE__, 4, RpWarning, (int)CommRxTaskHandle, 0);
//Report("FileUploadRequestFunc 2", __FILE__, __LINE__, msec_millisecondCounter, RpWarning, (int)0, 0);
Fresult = f_open(UploadFileHandle,request->path,FA_READ | FA_WRITE | FA_OPEN_ALWAYS | FA_CREATE_ALWAYS);
if (Fresult == FR_OK)
@@ -124,7 +139,7 @@ uint32_t FileUploadRequestFunc(MessageContainer* requestContainer)
{
my_free (UploadFileHandle);
UploadFileHandle = 0;
- Semaphore_post(FFS_Sem);
+ Semaphore_post(FileUpload_sem_param);
}
}
else
@@ -152,6 +167,25 @@ uint32_t FileUploadRequestFunc(MessageContainer* requestContainer)
return OK;
}
FRESULT lFresult = FR_OK;
+uint32_t Chunk_ControlId = 0xFF;
+uint32_t FileChunkUploadCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag)
+{
+ Report("chunk timeout error",__FILE__,IfIndex,FileReceivedLength,RpWarning,BusyFlag,0);
+ f_close(UploadFileHandle);
+ my_free (UploadFileHandle);
+ UploadFileHandle = 0;
+ FileReceivedLength = 0;
+ FileDone = true;
+ Task_setPri(CommRxTaskHandle, CommRxpri);
+ Semaphore_post(FileUpload_sem_param);
+ Report("Task_setPri", __FILE__, __LINE__, CommRxpri, RpWarning, (int)CommRxTaskHandle, 0);
+ if (SafeRemoveControlCallback(Chunk_ControlId, FileChunkUploadCallBackFunction )==OK)
+ Chunk_ControlId = 0xFF;
+
+ return OK;
+
+}
+
uint32_t FileChunkUploadRequestFunc(MessageContainer* requestContainer)
{
//uint32_t status = OK;
@@ -177,13 +211,15 @@ uint32_t FileChunkUploadRequestFunc(MessageContainer* requestContainer)
if (ReceivedFileHandle==NULL)
{
Fresult = FR_DENIED;
- Report("file chunk uplad rejected - file not created", __FILE__, __LINE__, 4, RpWarning, (int)0, 0);
+ Report("file chunk upload rejected - file not created", __FILE__, __LINE__, 4, RpWarning, (int)0, 0);
FileDone = true;
}
else
{
KeepAliveOneSecondCounter = 0;
save_milisec = msec_millisecondCounter;
+ Chunk_ControlId = AddControlCallback("chunk", FileChunkUploadCallBackFunction, eOneSecond, TemplateDataReadCBFunction,0,request->buffer.len, WrittenBytes );
+
Fresult = f_write(ReceivedFileHandle,request->buffer.data,request->buffer.len,&WrittenBytes );
lFresult = Fresult;
if(Fresult != FR_OK)
@@ -195,6 +231,8 @@ uint32_t FileChunkUploadRequestFunc(MessageContainer* requestContainer)
{
FileReceivedLength += WrittenBytes;
ReportWithPackageFilter(CommFilter,"Chunk received", __FILE__,FileLength,FileReceivedLength, RpMessage,msec_millisecondCounter-save_milisec, 0);
+ RemoveControlCallback(Chunk_ControlId, FileChunkUploadCallBackFunction );
+ Chunk_ControlId = 0xFF;
//REPORT_MSG (FileReceivedLength,"file upload chunk");
if (FileReceivedLength == FileLength)
@@ -237,9 +275,9 @@ uint32_t FileChunkUploadRequestFunc(MessageContainer* requestContainer)
SendCharsWithType(container_buffer, container_size,MESSAGE_TYPE__FileChunkUploadResponse);
if (FileDone == true)
{
- Task_setPri(CommRxTaskHandle, 9);
- Semaphore_post(FFS_Sem);
- //Report("Task_setPri", __FILE__, __LINE__, 9, RpWarning, (int)CommRxTaskHandle, 0);
+ Task_setPri(CommRxTaskHandle, CommRxpri);
+ Semaphore_post(FileUpload_sem_param);
+ Report("Task_setPri", __FILE__, __LINE__, CommRxpri, RpWarning, (int)CommRxTaskHandle, 0);
}
return OK;
}
@@ -249,12 +287,12 @@ void FileChunkUploadError(void)
{
REPORT_MSG (FileReceivedLength,"file upload too much data!");
f_close(UploadFileHandle);
- my_free (UploadFileHandle);
+ //my_free (UploadFileHandle); CAN NOT CALL FREE() FROM INTERRUPT
UploadFileHandle = 0;
FileReceivedLength = 0;
FileDone = true;
- Task_setPri(CommRxTaskHandle, 9);
- Semaphore_post(FFS_Sem);
+ Task_setPri(CommRxTaskHandle, CommRxpri);
+ Semaphore_post(FileUpload_sem_param);
}
}
uint32_t FileDownloadRequestFunc(MessageContainer* requestContainer)
@@ -286,7 +324,7 @@ uint32_t FileDownloadRequestFunc(MessageContainer* requestContainer)
Fresult = FR_DENIED;
else
{
- if (Semaphore_pend(FFS_Sem, BIOS_NO_WAIT))
+ if (1)//(Semaphore_pend(FFS_Sem, BIOS_NO_WAIT))
{
Fresult = f_open(DownloadFileHandle,request->filename,FA_READ );
if (Fresult == FR_OK)
@@ -470,7 +508,7 @@ uint32_t CreateRequestFunc(MessageContainer* requestContainer)
Fresult = FR_DENIED;
else
{
- if (Semaphore_pend(FFS_Sem, BIOS_NO_WAIT))
+ if (1)//(Semaphore_pend(FFS_Sem, BIOS_NO_WAIT))
{
Fresult = f_open(UploadFileHandle,request->path,FA_READ | FA_WRITE | FA_OPEN_ALWAYS | FA_CREATE_ALWAYS);
if (Fresult == FR_OK)
@@ -528,7 +566,7 @@ uint32_t DeleteRequestFunc(MessageContainer* requestContainer)
//int NumOfFiles = 0;
FRESULT Fresult = FR_OK;
- if (Semaphore_pend(FFS_Sem, BIOS_NO_WAIT))
+ if (1)//(Semaphore_pend(FFS_Sem, BIOS_NO_WAIT))
{
Fresult = f_unlink(request->path);
Semaphore_post(FFS_Sem);
@@ -624,17 +662,8 @@ uint32_t GetFilesRequestFunc(MessageContainer* requestContainer)
FRESULT Fresult = FR_OK;
FileInfo **FilesInfo = (FileInfo**)my_malloc(sizeof(FileInfo *)*(MAX_NUM_OF_FILES));
FileInfo Data[MAX_NUM_OF_FILES];
- /*
- time_t t;
- struct tm *ltm;
- char *curTime;
- t = time(NULL);
- ltm = localtime(&t);
- curTime = asctime(ltm);
- Report(curTime, __FILE__, ltm->tm_hour,ltm->tm_min , RpWarning, ltm->tm_sec, 0);
- */
- if (Semaphore_pend(FFS_Sem, BIOS_NO_WAIT))
+ if (1)//(Semaphore_pend(FFS_Sem, BIOS_NO_WAIT))
{
Fresult |= f_opendir(&dir, g_cCwdBuf);
if(Fresult != FR_OK)
@@ -689,14 +718,6 @@ uint32_t GetFilesRequestFunc(MessageContainer* requestContainer)
Data[i].lastmodifieddate = fno[i]->fdate;
Data[i].has_lastmodifiedtime = true;
Data[i].lastmodifiedtime = fno[i]->ftime;
- /*
- t = (fno[i]->fdate<<16)+fno[i]->ftime;
- ltm = localtime(&t);
- curTime = asctime(ltm);
- usnprintf(&Datestr, 100, "File info %s %s",fno[i]->fname, curTime);
- Report(Datestr, __FILE__, __LINE__, t, RpWarning, (int)Data[i].lastmodifiedtime, 0);
- Task_sleep(50);
- */
if (i==0)
usnprintf(&FullPath[i], 50, "%s", request->path);
@@ -756,7 +777,7 @@ FRESULT FileWrite(void * buffer, uint16_t size,char *path, uint32_t timeout)
Fresult = FR_DENIED;
else
{
- if (Semaphore_pend(FFS_Sem, BIOS_NO_WAIT))
+ if (1)//(Semaphore_pend(FFS_Sem, BIOS_NO_WAIT))
{
Fresult = f_open(FileHandle,path,FA_WRITE | FA_OPEN_ALWAYS|FA_CREATE_ALWAYS);
if (Fresult == FR_OK)
@@ -811,7 +832,7 @@ FRESULT FileRead(char *path, uint32_t *Size, void **Buffer)
Fresult = FR_DENIED;
else
{
- if (Semaphore_pend(FFS_Sem, BIOS_NO_WAIT))
+ if (1)//(Semaphore_pend(FFS_Sem, BIOS_NO_WAIT))
{
Fresult = f_open(FileHandle,path,FA_READ);
if (Fresult == FR_OK)
@@ -874,7 +895,7 @@ FRESULT FileOpen(char *path, uint32_t *Size, FIL *FileHandle)
if (FileHandle == 0)
Fresult = FR_DENIED;
else
- if (Semaphore_pend(FFS_Sem, BIOS_NO_WAIT))
+ if (1)//(Semaphore_pend(FFS_Sem, BIOS_NO_WAIT))
{
Fresult = f_open(FileHandle,path,FA_READ);
Semaphore_post(FFS_Sem); //will be closed with the f_close, in the job
@@ -887,7 +908,7 @@ FRESULT FileOpen(char *path, uint32_t *Size, FIL *FileHandle)
}
else
{
- LOG_ERROR (Fresult,"f_stat error");
+ Report("f_stat error", __FILE__, __LINE__,Fresult, RpWarning, (int)0, 0);
}
my_free(fno);
return Fresult;