fatfs save to file emulation

This commit is contained in:
leo 2023-09-19 17:57:18 +02:00
parent 38e7b72b95
commit 0fcde7d33a
Signed by: leo
GPG Key ID: 0DD993BFB2B307DB
6 changed files with 30 additions and 14 deletions

@ -1 +1 @@
Subproject commit bf08fc69ff21c28482ade1eca086867e619b7fea
Subproject commit 8a099f5c215424ff34ceafaaa35615ec0fbeb685

30
fatfs.c
View File

@ -1,5 +1,6 @@
#include "fatfs.h"
#include <errno.h>
#include <stdio.h>
FRESULT f_open (
@ -7,8 +8,21 @@ FRESULT f_open (
const TCHAR* path, /* Pointer to the file name */
BYTE mode /* Access mode and file open mode flags */
){
printf("file open try\n");
return FR_NO_FILE;
FILE* f;
printf("mode %d\n", mode);
if(mode & FA_READ)
f = fopen(path, "r");
else if(mode & FA_WRITE && mode & FA_OPEN_ALWAYS)
f = fopen(path, "w+");
else
printf("Unimplemented mode");
if(f == NULL){
printf("errno %d\n",errno);
return FR_NO_FILE;
}
*fp = f;
return FR_OK;
}
FRESULT f_read (
@ -17,15 +31,15 @@ FRESULT f_read (
UINT btr, /* Number of bytes to read */
UINT* br /* Pointer to number of bytes read */
){
printf("file read try\n");
return FR_NO_FILE;
*br = fread(buff, 1, btr, *fp);
return FR_OK;
}
FRESULT f_close (
FIL *fp /* Pointer to the file object to be closed */
){
printf("file close try\n");
return FR_NO_FILE;
fclose(*fp);
return FR_OK;
}
FRESULT f_write (
@ -34,6 +48,6 @@ FRESULT f_write (
UINT btw, /* Number of bytes to write */
UINT* bw /* Pointer to number of bytes written */
){
printf("file write try\n");
return FR_NO_FILE;
*bw = fwrite(buff, 1, btw, *fp);
return FR_OK;
}

View File

@ -1,5 +1,6 @@
typedef struct {
} FIL;
#include <stdio.h>
typedef FILE* FIL;
typedef enum {
FR_OK = 0, /* (0) Succeeded */

3
main.c
View File

@ -32,6 +32,7 @@ TIM_HandleTypeDef htim5;
pse_unit pse_units[PSE_UNITS_NUM];
pse_syringe pse_syringes[PSE_UNITS_NUM];
pse_home_display pse_home_displays[PSE_UNITS_NUM];
pse_stepper_status pse_steppers_status[PSE_UNITS_NUM];
enum steppers_axis{PSE_X_STEPPER, PSE_Y_STEPPER, PSE_Z_STEPPER, PSE_E_STEPPER, PSE_STEPPER_NUM};
pse_stepper_conf pse_stepper_confs[PSE_STEPPER_NUM] = {
@ -120,7 +121,7 @@ int main(int argc, char** argv){
lv_label_set_text(cursor, "A");
lv_indev_set_cursor(my_indev, cursor);
load_units(pse_units, pse_syringes, pse_stepper_confs, pse_home_displays, PSE_UNITS_NUM, 0);
load_units(pse_units, pse_syringes, pse_stepper_confs, pse_steppers_status, pse_home_displays, PSE_UNITS_NUM, 0);
Home_Screen_Gen(pse_units, PSE_UNITS_NUM, false);
pthread_t tickThread;

View File

@ -47,7 +47,7 @@ static void* tim_handler(void* arg){
int backlog = nb_exec - exec_counter;
if(backlog > 10)
printf("timer simulation lagging behind (%d ticks)\n", backlog);
while(backlog > 0){
while(backlog > 0 && htim->started){
HAL_TIM_PeriodElapsedCallback(htim);
exec_counter++;
backlog = nb_exec - exec_counter;

View File

@ -10,7 +10,7 @@ typedef struct {
typedef struct{
uint16_t presc;
uint16_t period;
uint8_t started;
volatile uint8_t started;
} TIM_HandleTypeDef;
typedef int HAL_StatusTypeDef;