Subversion Repositories svn.mios32

Rev

Rev 1261 | Rev 1268 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1261 Rev 1264
Line 1... Line 1...
1
// $Id: midio_file_p.c 1261 2011-07-17 18:21:45Z tk $
1
// $Id: midio_file_p.c 1264 2011-07-19 21:59:04Z tk $
2
/*
2
/*
3
 * Global Config File access functions
3
 * Patch File access functions
4
 *
4
 *
5
 * NOTE: before accessing the SD Card, the upper level function should
5
 * NOTE: before accessing the SD Card, the upper level function should
6
 * synchronize with the SD Card semaphore!
6
 * synchronize with the SD Card semaphore!
7
 *   MUTEX_SDCARD_TAKE; // to take the semaphore
7
 *   MUTEX_SDCARD_TAKE; // to take the semaphore
8
 *   MUTEX_SDCARD_GIVE; // to release the semaphore
8
 *   MUTEX_SDCARD_GIVE; // to release the semaphore
Line 76... Line 76...
76
/////////////////////////////////////////////////////////////////////////////
76
/////////////////////////////////////////////////////////////////////////////
77
// Local variables
77
// Local variables
78
/////////////////////////////////////////////////////////////////////////////
78
/////////////////////////////////////////////////////////////////////////////
79
79
80
static midio_file_p_info_t midio_file_p_info;
80
static midio_file_p_info_t midio_file_p_info;
-
 
81
-
 
82
-
 
83
/////////////////////////////////////////////////////////////////////////////
-
 
84
// Global variables
-
 
85
/////////////////////////////////////////////////////////////////////////////
-
 
86
char midio_file_p_patch_name[MIDIO_FILE_P_FILENAME_LEN+1];
81
87
82
88
83
/////////////////////////////////////////////////////////////////////////////
89
/////////////////////////////////////////////////////////////////////////////
84
// Initialisation
90
// Initialisation
85
/////////////////////////////////////////////////////////////////////////////
91
/////////////////////////////////////////////////////////////////////////////
Line 91... Line 97...
91
  return 0; // no error
97
  return 0; // no error
92
}
98
}
93
99
94
100
95
/////////////////////////////////////////////////////////////////////////////
101
/////////////////////////////////////////////////////////////////////////////
96
// Loads global config file
102
// Loads patch file
97
// Called from MIDIO_FILE_PheckSDCard() when the SD card has been connected
103
// Called from MIDIO_FILE_CheckSDCard() when the SD card has been connected
98
// returns < 0 on errors
104
// returns < 0 on errors
99
/////////////////////////////////////////////////////////////////////////////
105
/////////////////////////////////////////////////////////////////////////////
100
s32 MIDIO_FILE_P_Load(void)
106
s32 MIDIO_FILE_P_Load(char *filename)
101
{
107
{
102
  s32 error;
108
  s32 error;
103
  error = MIDIO_FILE_P_Read();
109
  error = MIDIO_FILE_P_Read(filename);
104
#if DEBUG_VERBOSE_LEVEL >= 2
110
#if DEBUG_VERBOSE_LEVEL >= 2
105
  DEBUG_MSG("[MIDIO_FILE_P] Tried to open global config file, status: %d\n", error);
111
  DEBUG_MSG("[MIDIO_FILE_P] Tried to open patch %s, status: %d\n", filename, error);
106
#endif
112
#endif
107
113
108
  return error;
114
  return error;
109
}
115
}
110
116
111
117
112
/////////////////////////////////////////////////////////////////////////////
118
/////////////////////////////////////////////////////////////////////////////
113
// Unloads global config file
119
// Unloads patch file
114
// Called from MIDIO_FILE_PheckSDCard() when the SD card has been disconnected
120
// Called from MIDIO_FILE_CheckSDCard() when the SD card has been disconnected
115
// returns < 0 on errors
121
// returns < 0 on errors
116
/////////////////////////////////////////////////////////////////////////////
122
/////////////////////////////////////////////////////////////////////////////
117
s32 MIDIO_FILE_P_Unload(void)
123
s32 MIDIO_FILE_P_Unload(void)
118
{
124
{
119
  midio_file_p_info.valid = 0;
125
  midio_file_p_info.valid = 0;
Line 122... Line 128...
122
}
128
}
123
129
124
130
125
131
126
/////////////////////////////////////////////////////////////////////////////
132
/////////////////////////////////////////////////////////////////////////////
127
// Returns 1 if global config file valid
133
// Returns 1 if current patch file valid
128
// Returns 0 if global config file not valid
134
// Returns 0 if current patch file not valid
129
/////////////////////////////////////////////////////////////////////////////
135
/////////////////////////////////////////////////////////////////////////////
130
s32 MIDIO_FILE_P_Valid(void)
136
s32 MIDIO_FILE_P_Valid(void)
131
{
137
{
132
  return midio_file_p_info.valid;
138
  return midio_file_p_info.valid;
133
}
139
}
Line 179... Line 185...
179
    return 0; // invalid IP
185
    return 0; // invalid IP
180
}
186
}
181
187
182
188
183
/////////////////////////////////////////////////////////////////////////////
189
/////////////////////////////////////////////////////////////////////////////
184
// reads the global config file content (again)
190
// reads the patch file content (again)
185
// returns < 0 on errors (error codes are documented in midio_file.h)
191
// returns < 0 on errors (error codes are documented in midio_file.h)
186
/////////////////////////////////////////////////////////////////////////////
192
/////////////////////////////////////////////////////////////////////////////
187
s32 MIDIO_FILE_P_Read(void)
193
s32 MIDIO_FILE_P_Read(char *filename)
188
{
194
{
189
  s32 status = 0;
195
  s32 status = 0;
190
  midio_file_p_info_t *info = &midio_file_p_info;
196
  midio_file_p_info_t *info = &midio_file_p_info;
191
  file_t file;
197
  file_t file;
192
198
193
  info->valid = 0; // will be set to valid if file content has been read successfully
199
  info->valid = 0; // will be set to valid if file content has been read successfully
-
 
200
-
 
201
  // store current file name in global variable for UI
-
 
202
  memcpy(midio_file_p_patch_name, filename, MIDIO_FILE_P_FILENAME_LEN+1);
194
203
195
  char filepath[MAX_PATH];
204
  char filepath[MAX_PATH];
196
  sprintf(filepath, "%sMIDIO_P.V3", MIDIO_FILES_PATH);
205
  sprintf(filepath, "%s%s.MIO", MIDIO_FILES_PATH, midio_file_p_patch_name);
197
206
198
#if DEBUG_VERBOSE_LEVEL >= 2
207
#if DEBUG_VERBOSE_LEVEL >= 2
199
  DEBUG_MSG("[MIDIO_FILE_P] Open global config file '%s'\n", filepath);
208
  DEBUG_MSG("[MIDIO_FILE_P] Open patch '%s'\n", filepath);
200
#endif
209
#endif
201
210
202
  if( (status=FILE_ReadOpen(&file, filepath)) < 0 ) {
211
  if( (status=FILE_ReadOpen(&file, filepath)) < 0 ) {
203
#if DEBUG_VERBOSE_LEVEL >= 2
212
#if DEBUG_VERBOSE_LEVEL >= 2
204
    DEBUG_MSG("[MIDIO_FILE_P] failed to open file, status: %d\n", status);
213
    DEBUG_MSG("[MIDIO_FILE_P] failed to open file, status: %d\n", status);
205
#endif
214
#endif
206
    return status;
215
    return status;
207
  }
216
  }
208
217
209
  // read global config values
218
  // read patch values
210
  char line_buffer[128];
219
  char line_buffer[128];
211
  do {
220
  do {
212
    status=FILE_ReadLine((u8 *)line_buffer, 128);
221
    status=FILE_ReadLine((u8 *)line_buffer, 128);
213
222
214
    if( status > 1 ) {
223
    if( status > 1 ) {
Line 427... Line 436...
427
  return status;
436
  return status;
428
}
437
}
429
438
430
439
431
/////////////////////////////////////////////////////////////////////////////
440
/////////////////////////////////////////////////////////////////////////////
432
// writes data into global config file
441
// writes data into patch file
433
// returns < 0 on errors (error codes are documented in seq_file.h)
442
// returns < 0 on errors (error codes are documented in seq_file.h)
434
/////////////////////////////////////////////////////////////////////////////
443
/////////////////////////////////////////////////////////////////////////////
435
s32 MIDIO_FILE_P_Write(void)
444
s32 MIDIO_FILE_P_Write(char *filename)
436
{
445
{
437
  midio_file_p_info_t *info = &midio_file_p_info;
446
  midio_file_p_info_t *info = &midio_file_p_info;
-
 
447
-
 
448
  // store current file name in global variable for UI
-
 
449
  memcpy(midio_file_p_patch_name, filename, MIDIO_FILE_P_FILENAME_LEN+1);
438
450
439
  char filepath[MAX_PATH];
451
  char filepath[MAX_PATH];
440
  sprintf(filepath, "%sMIDIO_P.V3", MIDIO_FILES_PATH);
452
  sprintf(filepath, "%s%s.MIO", MIDIO_FILES_PATH, midio_file_p_patch_name);
441
453
442
#if DEBUG_VERBOSE_LEVEL >= 2
454
#if DEBUG_VERBOSE_LEVEL >= 2
443
  DEBUG_MSG("[MIDIO_FILE_P] Open global config file '%s' for writing\n", filepath);
455
  DEBUG_MSG("[MIDIO_FILE_P] Open patch '%s' for writing\n", filepath);
444
#endif
456
#endif
445
457
446
  s32 status = 0;
458
  s32 status = 0;
447
  if( (status=FILE_WriteOpen(filepath, 1)) < 0 ) {
459
  if( (status=FILE_WriteOpen(filepath, 1)) < 0 ) {
448
#if DEBUG_VERBOSE_LEVEL >= 1
460
#if DEBUG_VERBOSE_LEVEL >= 1
449
    DEBUG_MSG("[MIDIO_FILE_P] Failed to open/create global config file, status: %d\n", status);
461
    DEBUG_MSG("[MIDIO_FILE_P] Failed to open/create patch file, status: %d\n", status);
450
#endif
462
#endif
451
    FILE_WriteClose(); // important to free memory given by malloc
463
    FILE_WriteClose(); // important to free memory given by malloc
452
    info->valid = 0;
464
    info->valid = 0;
453
    return status;
465
    return status;
454
  }
466
  }
Line 463... Line 475...
463
  // check if file is valid
475
  // check if file is valid
464
  if( status >= 0 )
476
  if( status >= 0 )
465
    info->valid = 1;
477
    info->valid = 1;
466
478
467
#if DEBUG_VERBOSE_LEVEL >= 2
479
#if DEBUG_VERBOSE_LEVEL >= 2
468
  DEBUG_MSG("[MIDIO_FILE_P] global config file written with status %d\n", status);
480
  DEBUG_MSG("[MIDIO_FILE_P] patch file written with status %d\n", status);
469
#endif
481
#endif
470
482
471
  return (status < 0) ? MIDIO_FILE_P_ERR_WRITE : 0;
483
  return (status < 0) ? MIDIO_FILE_P_ERR_WRITE : 0;
472
484
473
}
485
}
474
486
475
/////////////////////////////////////////////////////////////////////////////
487
/////////////////////////////////////////////////////////////////////////////
476
// sends global config data to debug terminal
488
// sends patch data to debug terminal
477
// returns < 0 on errors
489
// returns < 0 on errors
478
/////////////////////////////////////////////////////////////////////////////
490
/////////////////////////////////////////////////////////////////////////////
479
s32 MIDIO_FILE_P_Debug(void)
491
s32 MIDIO_FILE_P_Debug(void)
480
{
492
{
481
  return MIDIO_FILE_P_Write_Hlp(0); // send to debug terminal
493
  return MIDIO_FILE_P_Write_Hlp(0); // send to debug terminal