Subversion Repositories svn.mios32

Rev

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

Rev 1009 Rev 1010
Line 16... Line 16...
16
/////////////////////////////////////////////////////////////////////////////
16
/////////////////////////////////////////////////////////////////////////////
17
17
18
#include <mios32.h>
18
#include <mios32.h>
19
19
20
#include <string.h>
20
#include <string.h>
-
 
21
-
 
22
extern "C" {
21
#include <ff.h>
23
#include <ff.h>
-
 
24
#include <diskio.h>
-
 
25
}
22
26
23
#include "app.h"
27
#include "app.h"
24
#include <FreeRTOS.h>
28
#include <FreeRTOS.h>
25
#include <semphr.h>
29
#include <semphr.h>
26
30
Line 36... Line 40...
36
// Local variables
40
// Local variables
37
/////////////////////////////////////////////////////////////////////////////
41
/////////////////////////////////////////////////////////////////////////////
38
42
39
// FatFs variables
43
// FatFs variables
40
static FATFS fs; // Work area (file system object) for logical drives
44
static FATFS fs; // Work area (file system object) for logical drives
41
static u8 line_buffer[100];
45
static char line_buffer[100];
42
static u8 dir_path[MAX_PATH];
46
static char dir_path[MAX_PATH];
43
static u8 tmp_buffer[_MAX_SS]; //_MAX_SS
47
static u8 tmp_buffer[_MAX_SS]; //_MAX_SS
44
static u16 line_ix;
48
static u16 line_ix;
45
static u8 disk_label[12];
49
static char disk_label[12];
46
static FIL fsrc, fdst; // File handles for copy routine.
50
static FIL fsrc, fdst; // File handles for copy routine.
47
51
48
xSemaphoreHandle xSDCardSemaphore;
52
xSemaphoreHandle xSDCardSemaphore;
49
# define MUTEX_SDCARD_TAKE { while( xSemaphoreTakeRecursive(xSDCardSemaphore, (portTickType)1) != pdTRUE ); }
53
# define MUTEX_SDCARD_TAKE { while( xSemaphoreTakeRecursive(xSDCardSemaphore, (portTickType)1) != pdTRUE ); }
50
# define MUTEX_SDCARD_GIVE { xSemaphoreGiveRecursive(xSDCardSemaphore); }
54
# define MUTEX_SDCARD_GIVE { xSemaphoreGiveRecursive(xSDCardSemaphore); }
Line 68... Line 72...
68
  // init the SD Card
72
  // init the SD Card
69
  MIOS32_SDCARD_Init(0);
73
  MIOS32_SDCARD_Init(0);
70
 
74
 
71
  // install the callback function which is called on incoming characters
75
  // install the callback function which is called on incoming characters
72
  // from MIOS Terminal
76
  // from MIOS Terminal
73
  MIOS32_MIDI_DebugCommandCallback_Init(APP_TERMINAL_Parse);
77
  MIOS32_MIDI_DebugCommandCallback_Init((void *)&APP_TERMINAL_Parse);
74
 
78
 
75
  // clear line buffer
79
  // clear line buffer
76
  line_buffer[0] = 0;
80
  line_buffer[0] = 0;
77
  line_ix = 0;
81
  line_ix = 0;
78
 
82
 
Line 109... Line 113...
109
    DEBUG_MSG("Failed to open directory %s - error status: %d\n",dir_path, res);
113
    DEBUG_MSG("Failed to open directory %s - error status: %d\n",dir_path, res);
110
    return -1; // error
114
    return -1; // error
111
  }
115
  }
112
116
113
  // Get volume label from base sector  
117
  // Get volume label from base sector  
114
  if(disk_read(0, &dir.fs->win, dir.fs->dirbase,  1) != 0){
118
  if(disk_read(0, (BYTE *)&dir.fs->win, dir.fs->dirbase,  1) != 0){
115
    DEBUG_MSG("Couldn't read directory sector...\n");
119
    DEBUG_MSG("Couldn't read directory sector...\n");
116
    return -1;  
120
    return -1;  
117
  }  
121
  }  
118
  strncpy( disk_label, dir.fs->win, 11 );
122
  strncpy( disk_label, (char *)dir.fs->win, 11 );
119
 
123
 
120
  return 0;
124
  return 0;
121
}  
125
}  
122
126
123
127
Line 308... Line 312...
308
                   C4_element,
312
                   C4_element,
309
                   C4_turn_dir);
313
                   C4_turn_dir);
310
                   
314
                   
311
      // print messages on LCD
315
      // print messages on LCD
312
      MIOS32_LCD_CursorSet(0, 0); // X, Y
316
      MIOS32_LCD_CursorSet(0, 0); // X, Y
313
      MIOS32_LCD_PrintFormattedString("C4 %s  %s  %s\       ",
317
      MIOS32_LCD_PrintFormattedString("C4 %s  %s  %s\\       ",
314
                   message_type,
318
                   message_type,
315
                   C4_element,
319
                   C4_element,
316
                   C4_turn_dir);
320
                   C4_turn_dir);
317
321
318
322
Line 611... Line 615...
611
  }
615
  }
612
}
616
}
613
617
614
void SDCARD_CD(char *directory)
618
void SDCARD_CD(char *directory)
615
{
619
{
616
  u8 new_path[MAX_PATH];
620
  char new_path[MAX_PATH];
617
  DIR dir;
621
  DIR dir;
618
  fullpath(directory,(char *)&new_path);
622
  fullpath(directory,(char *)&new_path);
619
  if((f_opendir(&dir, new_path)) != FR_OK ) {
623
  if((f_opendir(&dir, new_path)) != FR_OK ) {
620
    DEBUG_MSG("The system cannot find the path specified");
624
    DEBUG_MSG("The system cannot find the path specified");
621
  } else {
625
  } else {
Line 624... Line 628...
624
  return;
628
  return;
625
}
629
}
626
630
627
void SDCARD_Delete(char *directory)
631
void SDCARD_Delete(char *directory)
628
{
632
{
629
  u8 new_path[MAX_PATH];
633
  char new_path[MAX_PATH];
630
  fullpath(directory,(char *)&new_path);
634
  fullpath(directory,(char *)&new_path);
631
  if((f_unlink(new_path)) != FR_OK ) {
635
  if((f_unlink(new_path)) != FR_OK ) {
632
    DEBUG_MSG("The system cannot find the file/dir specified");
636
    DEBUG_MSG("The system cannot find the file/dir specified");
633
  } else {
637
  } else {
634
    DEBUG_MSG("File or Directory deleted.");
638
    DEBUG_MSG("File or Directory deleted.");
Line 636... Line 640...
636
  return;
640
  return;
637
}
641
}
638
642
639
void SDCARD_Mkdir(char *directory)
643
void SDCARD_Mkdir(char *directory)
640
{
644
{
641
  u8 new_path[MAX_PATH];
645
  char new_path[MAX_PATH];
642
  fullpath(directory,(char *)&new_path);
646
  fullpath(directory,(char *)&new_path);
643
  SDCARD_Messages(f_mkdir(new_path));
647
  SDCARD_Messages(f_mkdir(new_path));
644
  return;
648
  return;
645
}
649
}
646
650
Line 651... Line 655...
651
}
655
}
652
656
653
657
654
void SDCARD_Rename(char* source, char* dest)
658
void SDCARD_Rename(char* source, char* dest)
655
{  
659
{  
656
  u8 new_source[MAX_PATH];
660
  char new_source[MAX_PATH];
657
  u8 new_dest[MAX_PATH];
661
  char new_dest[MAX_PATH];
658
662
659
  fullpath(source,(char *)&new_source);
663
  fullpath(source,(char *)&new_source);
660
  fullpath(dest,(char *)&new_dest);
664
  fullpath(dest,(char *)&new_dest);
661
665
662
  DEBUG_MSG("Renaming/Moving from: %s to %s",new_source,new_dest);
666
  DEBUG_MSG("Renaming/Moving from: %s to %s",new_source,new_dest);
Line 667... Line 671...
667
void SDCARD_Copy(char* source, char* dest)
671
void SDCARD_Copy(char* source, char* dest)
668
{
672
{
669
673
670
  FRESULT res;
674
  FRESULT res;
671
  s32 status = 0;
675
  s32 status = 0;
672
  u8 new_source[MAX_PATH];
676
  char new_source[MAX_PATH];
673
  u8 new_dest[MAX_PATH];
677
  char new_dest[MAX_PATH];
674
 
678
 
675
  fullpath(source,(char *)&new_source);
679
  fullpath(source,(char *)&new_source);
676
  fullpath(dest,(char *)&new_dest);
680
  fullpath(dest,(char *)&new_dest);
677
681
678
  if( (res=f_open(&fsrc, new_source, FA_OPEN_EXISTING | FA_READ)) != FR_OK ) {
682
  if( (res=f_open(&fsrc, new_source, FA_OPEN_EXISTING | FA_READ)) != FR_OK ) {
Line 713... Line 717...
713
717
714
  f_close(&fdst);
718
  f_close(&fdst);
715
}
719
}
716
720
717
721
718
void SDCARD_Benchmark(num_sectors)
722
void SDCARD_Benchmark(u32 num_sectors)
719
{
723
{
720
724
721
  FRESULT res;
725
  FRESULT res;
722
  s32 status = 0;
726
  s32 status = 0;
723
  u8 source[MAX_PATH];
727
  char source[MAX_PATH];
724
  u8 dest[MAX_PATH];
728
  char dest[MAX_PATH];
725
  strcpy(source,"/benchmrk.tmp");
729
  strcpy(source,"/benchmrk.tmp");
726
  strcpy(dest,"/benchmrk.cpy");
730
  strcpy(dest,"/benchmrk.cpy");
727
  int f;
731
  int f;
728
732
729
  for(f=0;f<_MAX_SS;f++)
733
  for(f=0;f<_MAX_SS;f++)
Line 825... Line 829...
825
829
826
void SDCARD_ReadFile(char* source)
830
void SDCARD_ReadFile(char* source)
827
{
831
{
828
  FRESULT res;
832
  FRESULT res;
829
  s32 status = 0;
833
  s32 status = 0;
830
  u8 new_source[MAX_PATH];
834
  char new_source[MAX_PATH];
831
  char display="";
-
 
832
  //u8 new_dest[MAX_PATH];
835
  //u8 new_dest[MAX_PATH];
833
 
836
 
834
  fullpath(source,(char *)&new_source);
837
  fullpath(source,(char *)&new_source);
835
  //fullpath(dest,(char *)&new_dest);
838
  //fullpath(dest,(char *)&new_dest);
836
839
Line 867... Line 870...
867
            for (loop=0;loop<_MAX_SS;loop++)
870
            for (loop=0;loop<_MAX_SS;loop++)
868
              //string[loop]=tmp_buffer[loop];
871
              //string[loop]=tmp_buffer[loop];
869
              DEBUG_MSG("%c ", tmp_buffer[loop]);
872
              DEBUG_MSG("%c ", tmp_buffer[loop]);
870
          }
873
          }
871
       
874
       
872
          DEBUG_MSG(" -- %d\n", strlen(tmp_buffer));
875
      DEBUG_MSG(" -- %d\n", strlen((char *)tmp_buffer));
873
       num_bytes += successcount_wr;
876
       num_bytes += successcount_wr;
874
    }
877
    }
875
  } while( status==0 && successcount > 0 );
878
  } while( status==0 && successcount > 0 );
876
  mios32_sys_time_t t1=MIOS32_SYS_TimeGet();
879
  mios32_sys_time_t t1=MIOS32_SYS_TimeGet();
877
 
880