コード例 #1
0
ファイル: asCARD.c プロジェクト: FMMT666/PIC32Lua
//**************************************************************************************
//*** asCARD_Detect
//***
//*** 
//**************************************************************************************
int asCARD_Detect()
{
	if(MDD_MediaDetect())
	{
		gCardState |= CARD_DETECTED;
		return 1;
	}
	else
	{
		gCardState &= ~CARD_DETECTED;
		return 0;
	}
}
コード例 #2
0
ファイル: JPEGDemo.c プロジェクト: Athuli7/Microchip
/************************************************************************
Function: void MonitorDriveMedia( void )

Precondition: None

Overview: This function calls the background tasks necessary to support
          USB Host operation.  Upon initial insertion of the media, it
          initializes the file system support and reads the volume label.
          Upon removal of the media, the volume label is marked invalid.

Input: None

Output: None
*************************************************************************/
void MonitorDriveMedia(void)
{
    BYTE        mediaPresentNow;
    BYTE        mountTries;
    SearchRec   searchRecord;

        #if defined ENABLE_USB_MSD_DEMO

    // Call to USBTasks() is assumed to be done in the main. If not you can
    // call it here.
    //USBTasks();	
    mediaPresentNow = USBHostMSDSCSIMediaDetect();
        #elif defined ENABLE_SD_MSD_DEMO
    mediaPresentNow = MDD_MediaDetect();
        #endif
    if(mediaPresentNow != mediaPresent)
    {
        if(mediaPresentNow)
        {
            mountTries = 10;
            while(!FSInit() && mountTries--);
            if(!mountTries)
            {
                //UART2PrintString("APP: Could not mount media\r\n");
                mediaPresent = FALSE;
            }
            else
            {
                mediaPresent = TRUE;

                // Find the volume label.  We need to do this here while we are at the
                // root directory.
                if(!FindFirst("*.*", ATTR_VOLUME, &searchRecord))
                {
                    strcpy(volume.label, searchRecord.filename);
                    volume.valid = TRUE;
                }
            }
        }
        else
        {
            mediaPresent = FALSE;
            volume.valid = FALSE;
        }
    }
}
コード例 #3
0
ファイル: fsman.c プロジェクト: dtbingle/vi-firmware
uint8_t fsmanMountSD(uint8_t * result_code){
    
    uint8_t ret=0;
    
    MEDIA_INFORMATION  *mediainfo = MDD_MediaInitialize();
    
    if(mediainfo->errorCode != MEDIA_NO_ERROR){
        __debug("MDD media init failed");
    }
    
    if(MDD_MediaDetect() == 0){
        __debug("MDD media detect failed");
        return 0;
    }
    
    if(FSInit() == 0){
        __debug("FSInit failed");
        return 0;
    }

    return 1;
       
}
コード例 #4
0
ファイル: fsio_main.c プロジェクト: vladislav1983/GPSTRK
/*=====================================================================================================================
 * Parameters: void
 *
 * Return: void
 *
 * Description: 
 *===================================================================================================================*/
void FSIO_Task(void)
{
    switch(CardState)
    {
    //------------------------------------------------------------------------------------------------------------------
    case cInitState:
         OSStartTimer(&CardInitTimer);
         CardState = eCardWaitState;
         _DioWritePin(cDioPin_SD_CardLed, 1);
        break;
    //------------------------------------------------------------------------------------------------------------------
    case eCardInitialize:
        // card is inserted, initialize card
        if(cFalse != MDD_MediaDetect())
        {
            if (cFalse != FSInit())
            {
                // init OK
                _set_sd_card_present(1);
                _DioWritePin(cDioPin_SD_CardLed, 0);
                // load device configuration
                Devconfig_LoadConfig();
                App_Statemachine_SD_CardCallback(cCallbackCtrlOK);

                CardState = eCardInserted;
            }
            else
            {
                // init error
                _set_sd_card_present(0);
                _DioWritePin(cDioPin_SD_CardLed, 1);

                CardState = eCardNotPresent;
            }
        }
        else
        {
            _set_sd_card_present(0);
            CardState = eCardNotPresent;
        }
        break;
    //-----------------------------------------------------------------------------------------------------------------
    case eCardInserted:
        if(cDioCardInsertsed != _DioReadPinFiltered(cDioPin_SD_CardPresent))
        {
            _set_sd_card_present(0);
            _DioWritePin(cDioPin_SD_CardLed, 1);
            App_Statemachine_SD_CardCallback(cCallbackCtrlNOK);

            CardState = eCardNotPresent;
        }
        break;
    //-------------------------------------------------------------------------------------------------------------------
    case eCardNotPresent:
        // wait card inserted
        if(cDioCardInsertsed == _DioReadPinFiltered(cDioPin_SD_CardPresent))
        {
            CardState = eCardInitialize;
        }
        break;
    //------------------------------------------------------------------------------------------------------------------
    case eCardWaitState:
        if(cFalse != OSIsTimerElapsed(&CardInitTimer, cFSIO_DioInitTime_ms/(cOsTimerTickUs/1000UL)))
        {
            // wait some time before start polling card state
            CardState = eCardNotPresent;
        }
        break;
    //-------------------------------------------------------------------------------------------------------------------
    default:
        _assert(cFalse);
        CardState = eCardNotPresent;
        break;
    }
}
コード例 #5
0
int main (void)
{

   FSFILE * pointer=NULL;
   DWORD first_sector;
   BYTE test_array[512];
   SearchRec rec;
   pointer=NULL;
   unsigned char attributes;
   unsigned char size = 0, i;
   PLLFBD =38;
   CLKDIVbits.PLLPOST=0;
   CLKDIVbits.PLLPRE=0;
   __builtin_write_OSCCONH(0b011);
   __builtin_write_OSCCONL(0b01);
	while (OSCCONbits.COSC != 0b011);	// Wait for Clock switch to occur	
	while(OSCCONbits.LOCK != 1) {};
	UART2Init();
	printf("starting Integration test\r\n");
	//DataEEInit();
	int id=0;
	id=Get_ID_Code();
	printf("ID: %u\r\n",id);
	OFB_init(id);
	Increment_ID_Code();
	#ifdef __DEBUG
		printf("Clock Switch Complete, Waiting For Media\r\n");
	#endif
	//waits for a card to be inserted
   while (!MDD_MediaDetect());
	#ifdef __DEBUG
		printf("Media Found, Waiting for FSinit\r\n");
	#endif
   // Initialize the library
   while (!FSInit());
   char filename[9];
   sprintf(filename,"%05d.bin",id);
   // Create a file
   printf("filename will be: %s\r\n",filename);
   while(pointer==NULL)
   {
   		pointer = FSfopen (filename, "w");
   }
   #ifdef __DEBUG
   	printf("File Has been opened\r\n");
   #endif		
	
	while(1)
	{
		Service_Spi(pointer);
	}	
	//printf("stuipd thing");
	//TRISD=0x0FF;
	//setting up pins to show on usb debugger
	TRISDbits.TRISD6=1;
	TRISAbits.TRISA7=0;
	TRISAbits.TRISA6=0;
	TRISAbits.TRISA5=0;
	TRISAbits.TRISA4=0;
	TRISGbits.TRISG0=0;
	AD1PCFGLbits.PCFG0=1;	
	//LATA=1;
	//_LATA4=1;
	//_RA7=1;
	//_LATA6=1;
	
	//_LATA5=1;
	//_LATA7=1;
	
	//printf("they should be on now");
	//while(1);
	//LATAbits.LATA7=0;
	//TRISB=0xFFFF;
	//AD1PCFGLbits.PCFG1=1;	
	//Service_Spi();
	/*#ifdef __DEBUG
		printf("Clock Switch Complete, Waiting For Media\r\n");
	#endif
	//waits for a card to be inserted
   while (!MDD_MediaDetect());
   
   
	#ifdef __DEBUG
		printf("Media Found, Waiting for FSinit\r\n");
	#endif
   // Initialize the library
   while (!FSInit());
	char temp;
	int character_count,remove_success;
	character_count=0;
   // Create a file
   printf("starting up\r\n");
   remove_success=FSremove("WRITE.TXT");
   printf("Removal of prev: %d\r\n",remove_success);
   pointer = FSfopen ("WRITE.TXT", "w");

   if (pointer == NULL)
   {
	   #ifdef __DEBUG
	   	printf("File open failed\r\n");
	   #endif
      while(1);
   }   

   printf("waiting for operation\r\n");
   printf("in file resize_test\r\n");
   
   
   DWORD sizeinbytes;
   //need to convert from number of sectors to number of bytes and allocate that much space
   sizeinbytes=(DWORD)FILESIZE*(DWORD)512;
   printf("Chew Fat: %lu\r\nChew Fat Sectors: %d\r\n",CHEW_FAT_SIZE,CHEW_FAT_SIZE_IN_SECTORS);
   //sizeinbytes=3774873*(DWORD)512;
   //allocate_size(sizeinbytes,pointer,FALSE);
   //FSfclose(pointer);*/
   /*FILEallocate_multiple_clusters(pointer,24);
   FAT_print_cluster_chain(pointer->cluster, pointer->dsk);
   FILEallocate_multiple_clusters(pointer,24);
   FAT_print_cluster_chain(pointer->cluster, pointer->dsk);
   int numclus,numcount;
   //DWORD clusttemp;
   printf("First CLuster in main: %lu\r\n",get_First_Sector(pointer));
   for (numclus=0;numclus<48;numclus++)
   {
		for(numcount=0;numcount<512;numcount++)
		{
		   test_array[numcount]=numclus+48;
		}
		MDD_SDSPI_SectorWrite(get_First_Sector(pointer)+numclus,test_array,FALSE);
	}*/
   //FILEallocate_multiple_clusters(pointer,24);
   //FILEallocate_multiple_clusters(pointer,24);
   //FILEallocate_multiple_clusters(pointer,CHEW_FAT_SIZE_IN_SECTORS);
   //FSfclose(pointer);
   //FILEallocate_multiple_clusters(pointer,4096);
   //FSfclose(pointer);
   //FILEallocate_multiple_clusters(pointer,1024);
   //FILEallocate_multiple_clusters(pointer,1024);
   
   //FSfseek(pointer,0,SEEK_SET);
   first_sector=get_First_Sector(pointer);
   set_First_Sector(first_sector);
   DWORD erasure;
   OFB_init(0x1f1f);
   //FSfclose(pointer);
   //MDD_ShutdownMedia();
   printf("done with file allocation\r\n");
   #ifdef DMAON
   #else
   #endif
      
      //while(UART2IsEmpty());
      //temp=UART2GetChar();
      //write_array[character_count]=temp;
      //character_count++;
    while(1)
    {
	    Service_Spi(pointer);
	}
}
コード例 #6
0
int main (void)
{
   FSFILE * pointer;
   #if defined(SUPPORT_LFN)
   char count = 80;
   #endif
   char * pointer2;
   SearchRec rec;
   unsigned char attributes;
   unsigned char size = 0, i;

    // Initialize and configure Primary PLL, and enabled Secondary Oscillator
    PLLFBD = 58;			/* M  = 60	*/
    CLKDIVbits.PLLPOST = 0;	/* N1 = 2	*/
    CLKDIVbits.PLLPRE = 0;	/* N2 = 2	*/
    OSCTUN = 0;
    __builtin_write_OSCCONH(0x03);		
    __builtin_write_OSCCONL(0x03);
    while (OSCCONbits.COSC != 0x3); 
    while (_LOCK == 0);

   // Activate the RTCC module
   __builtin_write_RTCWEN();
   Nop();
   Nop();
   RCFGCALbits.RTCPTR0 = 1;
   RCFGCALbits.RTCPTR1 = 1;
   
   // Set it to the correct time
   // These values won't be accurate
   RTCVAL = 0x0011;   
   RTCVAL = 0x0815;
   RTCVAL = 0x0108;
   RTCVAL = 0x2137;
   RCFGCAL = 0x8000;

   while (!MDD_MediaDetect());

   // Initialize the library
   while (!FSInit());

#ifdef ALLOW_WRITES
   // Create a file
   pointer = FSfopen ("FILE1.TXT", "w");
   if (pointer == NULL)
      while(1);

   // Write 21 1-byte objects from sendBuffer into the file
   if (FSfwrite (sendBuffer, 1, 21, pointer) != 21)
      while(1);

   // FSftell returns the file's current position
   if (FSftell (pointer) != 21)
      while(1);

   // FSfseek sets the position one byte before the end
   // It can also set the position of a file forward from the
   // beginning or forward from the current position
   if (FSfseek(pointer, 1, SEEK_END))
      while(1);

   // Write a 2 at the end of the string
   if (FSfwrite (send2, 1, 1, pointer) != 1)
      while(1);

   // Close the file
   if (FSfclose (pointer))
      while(1);

   // Create a second file
   pointer = FSfopen ("Microchip File 1.TXT", "w");
   if (pointer == NULL)
      while(1);

   // Write the string to it again
   if (FSfwrite ((void *)sendBuffer, 1, 21, pointer) != 21)
      while(1);

   // Close the file
   if (FSfclose (pointer))
      while(1);
#endif

   // Open file 1 in read mode
   pointer = FSfopen ("FILE1.TXT", "r");
   if (pointer == NULL)
      while(1);

   if (FSrename ("Microchip File 2.TXT", pointer))
      while(1);

   // Read one four-byte object
   if (FSfread (receiveBuffer, 4, 1, pointer) != 1)
      while(1);

   // Check if this is the end of the file- it shouldn't be
   if (FSfeof (pointer))
      while(1);

   // Close the file
   if (FSfclose (pointer))
      while(1);

   // Make sure we read correctly
   if ((receiveBuffer[0] != 'T') ||
         (receiveBuffer[1] != 'h')  ||
         (receiveBuffer[2] != 'i')  ||
         (receiveBuffer[3] != 's'))
   {
      while(1);
   }

#ifdef ALLOW_DIRS
   // Create a small directory tree
   // Beginning the path string with a '.' will create the tree in
   // the current directory.  Beginning with a '..' would create the
   // tree in the previous directory.  Beginning with just a '\' would
   // create the tree in the root directory.  Beginning with a dir name
   // would also create the tree in the current directory
   if (FSmkdir (".\\Mchp Directory 1\\Dir2\\Directory 3"))
      while(1);

   // Change to 'Directory 3' in our new tree
   if (FSchdir ("Mchp Directory 1\\Dir2\\Directory 3"))
      while(1);

   // Create another tree in 'Directory 3'
   if (FSmkdir ("Directory 4\\Directory 5\\Directory 6"))
      while(1);

   // Create a third file in directory THREE
   pointer = FSfopen ("CWD.TXT", "w");
   if (pointer == NULL)
      while(1);

   #if defined(SUPPORT_LFN)
   // Get the name of the current working directory
   /* it should be "\Mchp Directory 1\Dir2\Directory 3" */
   pointer2 = wFSgetcwd ((unsigned short int *)path1, count);
   #endif

   if (pointer2 != path1)
      while(1);

   // Simple string length calculation
   i = 0;
   while(*((unsigned short int *)path1 + i) != 0x00)
   {
      size++;
      size++;
      i++;
   }
   // Write the name to CWD.TXT
   if (FSfwrite (path1, size, 1, pointer) != 1)
      while(1);

   // Close the file
   if (FSfclose (pointer))
      while(1);

   // Create some more directories
   if (FSmkdir ("Directory 4\\Directory 5\\Directory 7\\..\\Directory 8\\..\\..\\DIRNINE\\Directory 10\\..\\Directory 11\\..\\Directory 12"))
      while(1);

   /*******************************************************************
      Now our tree looks like this

 \ -> Mchp Directory 1 -> Dir2 -> Directory 3 -> Directory 4 -> Directory 5 -> Directory 6
                                                                                 -> Directory 7
                                                                                 -> Directory 8

                                                                    DIRNINE -> Directory 10
                                                                            -> Directory 11
                                                                            -> Directory 12
   ********************************************************************/

   // This will delete only Directory 8
   // If we tried to delete Directory 5 with this call, the FSrmdir
   // function would return -1, since Directory 5 is non-empty
   if (FSrmdir ("\\Mchp Directory 1\\Dir2\\Directory 3\\Directory 4\\Directory 5\\Directory 8", FALSE))
      while(1);

   // This will delete DIRNINE and all three of its sub-directories
   if (FSrmdir ("Directory 4\\DIRNINE", TRUE))
      while(1);

   // Change directory to the root dir
   if (FSchdir ("\\"))
      while(1);
#endif

#ifdef ALLOW_FILESEARCH
   // Set attributes
   attributes = ATTR_ARCHIVE | ATTR_READ_ONLY | ATTR_HIDDEN;

   // Functions "FindFirst" & "FindNext" can be used to find files
   // and directories with required attributes in the current working directory.

   // Find the first TXT file with any (or none) of those attributes that
   // has a name beginning with the letters "Mic"
   // These functions are more useful for finding out which files are
   // in your current working directory
   if (FindFirst ("Mic*.TXT", attributes, &rec))
      while(1);

 //   Find file to get "Microchip File 2.TXT"
      if (FindNext (&rec))
         while(1);

   #if defined(SUPPORT_LFN) 
  // Delete file 2
   // If the file name is long
   if(rec.utf16LFNfoundLength)
   {
      // NOTE : "wFSremove" function deletes specific file not directory.
      //        To delete directories use "wFSrmdir" function
      if (wFSremove (rec.utf16LFNfound))
         while(1);
   }
   else
   #endif
   {
      // NOTE : "FSremove" function deletes specific file not directory.
      //        To delete directories use "FSrmdir" function
      if (FSremove (rec.filename))
         while(1);
   }

#endif


/*********************************************************************
   The final contents of our card should look like this:
   \ -> Microchip File 1.TXT
      -> Mchp Directory 1 -> Dir2 -> Directory 3 -> CWD.TXT
                                                 -> Directory 4 -> Directory 5 -> Directory 6
                                                                               -> Directory 7

*********************************************************************/


   while(1);
}
コード例 #7
0
ファイル: Demonstration2.c プロジェクト: Athuli7/Microchip
int main (void)
{
   FSFILE * pointer;
   #if defined(SUPPORT_LFN)
   char count = 80;
   #endif
   char * pointer2;
   SearchRec rec;
   unsigned char attributes;
   unsigned char size = 0, i;

	// Turn on the secondary oscillator
	__asm__ ("MOV #OSCCON,w1");
	__asm__ ("MOV.b #0x02, w0");
	__asm__ ("MOV #0x46, w2");
	__asm__ ("MOV #0x57, w3");
	__asm__ ("MOV.b w2, [w1]");
	__asm__ ("MOV.b w3, [w1]");
	__asm__ ("MOV.b w0, [w1]");

	// Activate the RTCC module
	__asm__ ("mov #NVMKEY,W0");
	__asm__ ("mov #0x55,W1");
	__asm__ ("mov #0xAA,W2");
	__asm__ ("mov W1,[W0]");
	__asm__ ("nop");
	__asm__ ("mov W2,[W0]");
	__asm__ ("bset RCFGCAL,#13");
	__asm__ ("nop");
	__asm__ ("nop");
	RCFGCALbits.RTCPTR0 = 1;
	RCFGCALbits.RTCPTR1 = 1;
	// Set it to the correct time
	// These values won't be accurate
	RTCVAL = 0x0007;   
	RTCVAL = 0x0717;
	RTCVAL = 0x0208;
	RTCVAL = 0x2137;
	RCFGCAL = 0x8000;

	#if defined(__PIC24FJ256DA210__)

		// Make Analog Pins Digital
		ANSB = 0x0000 ; 
		ANSA = 0x0000;
		ANSC = 0x0000;
		ANSD = 0x0000;

		// Enable PLL
		CLKDIVbits.PLLEN = 1; 

		// Configure SPI1 PPS pins (ENC28J60/ENCX24J600/MRF24WB0M or other PICtail Plus cards)
		__builtin_write_OSCCONL(OSCCON & 0xbf); // unlock PPS

		RPOR1bits.RP2R = 8;       // assign RP2 for SCK1
		RPOR0bits.RP1R = 7;       // assign RP1 for SDO1
		RPINR20bits.SDI1R = 0;    // assign RP0 for SDI1

		__builtin_write_OSCCONL(OSCCON | 0x40); // lock   PPS                

	#elif defined(__PIC24FJ256GB110__)

		AD1PCFGL = 0xFFFF;

		//Initialize the SPI
		RPINR20bits.SDI1R = 23;
		RPOR7bits.RP15R = 7;
		RPOR0bits.RP0R = 8;    

		//enable a pull-up for the card detect, just in case the SD-Card isn't attached
		//  then lets have a pull-up to make sure we don't think it is there.
		CNPU5bits.CN68PUE = 1; 

	#endif

   while (!MDD_MediaDetect());

   // Initialize the library
   while (!FSInit());

#ifdef ALLOW_WRITES
   // Create a file
   pointer = FSfopen ("FILE1.TXT", "w");
   if (pointer == NULL)
      while(1);

   // Write 21 1-byte objects from sendBuffer into the file
   if (FSfwrite (sendBuffer, 1, 21, pointer) != 21)
      while(1);

   // FSftell returns the file's current position
   if (FSftell (pointer) != 21)
      while(1);

   // FSfseek sets the position one byte before the end
   // It can also set the position of a file forward from the
   // beginning or forward from the current position
   if (FSfseek(pointer, 1, SEEK_END))
      while(1);

   // Write a 2 at the end of the string
   if (FSfwrite (send2, 1, 1, pointer) != 1)
      while(1);

   // Close the file
   if (FSfclose (pointer))
      while(1);

   // Create a second file
   pointer = FSfopen ("Microchip File 1.TXT", "w");
   if (pointer == NULL)
      while(1);

   // Write the string to it again
   if (FSfwrite ((void *)sendBuffer, 1, 21, pointer) != 21)
      while(1);

   // Close the file
   if (FSfclose (pointer))
      while(1);
#endif

   // Open file 1 in read mode
   pointer = FSfopen ("FILE1.TXT", "r");
   if (pointer == NULL)
      while(1);

   if (FSrename ("Microchip File 2.TXT", pointer))
      while(1);

   // Read one four-byte object
   if (FSfread (receiveBuffer, 4, 1, pointer) != 1)
      while(1);

   // Check if this is the end of the file- it shouldn't be
   if (FSfeof (pointer))
      while(1);

   // Close the file
   if (FSfclose (pointer))
      while(1);

   // Make sure we read correctly
   if ((receiveBuffer[0] != 'T') ||
         (receiveBuffer[1] != 'h')  ||
         (receiveBuffer[2] != 'i')  ||
         (receiveBuffer[3] != 's'))
   {
      while(1);
   }

#ifdef ALLOW_DIRS
   // Create a small directory tree
   // Beginning the path string with a '.' will create the tree in
   // the current directory.  Beginning with a '..' would create the
   // tree in the previous directory.  Beginning with just a '\' would
   // create the tree in the root directory.  Beginning with a dir name
   // would also create the tree in the current directory
   if (FSmkdir (".\\Mchp Directory 1\\Dir2\\Directory 3"))
      while(1);

   // Change to 'Directory 3' in our new tree
   if (FSchdir ("Mchp Directory 1\\Dir2\\Directory 3"))
      while(1);

   // Create another tree in 'Directory 3'
   if (FSmkdir ("Directory 4\\Directory 5\\Directory 6"))
      while(1);

   // Create a third file in directory THREE
   pointer = FSfopen ("CWD.TXT", "w");
   if (pointer == NULL)
      while(1);

   #if defined(SUPPORT_LFN)
   // Get the name of the current working directory
   /* it should be "\Microchip Directory 1\Dir2\Directory 3" */
   pointer2 = wFSgetcwd ((unsigned short int *)path1, count);
   #endif

   if (pointer2 != path1)
      while(1);

   // Simple string length calculation
   i = 0;
   while(*((unsigned short int *)path1 + i) != 0x00)
   {
      size++;
      size++;
      i++;
   }
   // Write the name to CWD.TXT
   if (FSfwrite (path1, size, 1, pointer) != 1)
      while(1);

   // Close the file
   if (FSfclose (pointer))
      while(1);

   // Create some more directories
   if (FSmkdir ("Directory 4\\Directory 5\\Directory 7\\..\\Directory 8\\..\\..\\DIRNINE\\Directory 10\\..\\Directory 11\\..\\Directory 12"))
      while(1);

   /*******************************************************************
      Now our tree looks like this

 \ -> Mchp Directory 1 -> Dir2 -> Directory 3 -> Directory 4 -> Directory 5 -> Directory 6
                                                                                 -> Directory 7
                                                                                 -> Directory 8

                                                                    DIRNINE -> Directory 10
                                                                            -> Directory 11
                                                                            -> Directory 12
   ********************************************************************/

   // This will delete only Directory 8
   // If we tried to delete Directory 5 with this call, the FSrmdir
   // function would return -1, since Directory 5 is non-empty
   if (FSrmdir ("\\Mchp Directory 1\\Dir2\\Directory 3\\Directory 4\\Directory 5\\Directory 8", FALSE))
      while(1);

   // This will delete DIRNINE and all three of its sub-directories
   if (FSrmdir ("Directory 4\\DIRNINE", TRUE))
      while(1);

   // Change directory to the root dir
   if (FSchdir ("\\"))
      while(1);
#endif

#ifdef ALLOW_FILESEARCH
   // Set attributes
   attributes = ATTR_ARCHIVE | ATTR_READ_ONLY | ATTR_HIDDEN;

   // Functions "FindFirst" & "FindNext" can be used to find files
   // and directories with required attributes in the current working directory.

   // Find the first TXT file with any (or none) of those attributes that
   // has a name beginning with the letters "Mic"
   // These functions are more useful for finding out which files are
   // in your current working directory
   if (FindFirst ("Mic*.TXT", attributes, &rec))
      while(1);

 //   Find file to get "Microchip File 2.TXT"
      if (FindNext (&rec))
         while(1);

   #if defined(SUPPORT_LFN) 
  // Delete file 2
   // If the file name is long
   if(rec.utf16LFNfoundLength)
   {
      // NOTE : "wFSremove" function deletes specific file not directory.
      //        To delete directories use "wFSrmdir" function
      if (wFSremove (rec.utf16LFNfound))
         while(1);
   }
   else
   #endif
   {
      // NOTE : "FSremove" function deletes specific file not directory.
      //        To delete directories use "FSrmdir" function
      if (FSremove (rec.filename))
         while(1);
   }

#endif


/*********************************************************************
   The final contents of our card should look like this:
   \ -> Microchip File 1.TXT
      -> Mchp Directory 1 -> Dir2 -> Directory 3 -> CWD.TXT
                                                 -> Directory 4 -> Directory 5 -> Directory 6
                                                                               -> Directory 7

*********************************************************************/


   while(1);
}
コード例 #8
0
ファイル: Demonstration.c プロジェクト: JEB12345/SLUGS-Logger
int main (void)
{

    FSFILE * pointer;
    char path[30];
    char count = 30;
    char * pointer2;
    int gh;
    BYTE write_array[512];
    for(gh=0; gh<512; gh++)
        if(gh%8)
            write_array[gh]='a';
        else
            write_array[gh]='b';
    DWORD first_sector;
    BYTE test_array[512];
    /* OFB_init();
     OFB_push(write_array);
     calc_checksum(write_array);
     while(1);*/
    SearchRec rec;
    pointer=NULL;
    unsigned char attributes;
    unsigned char size = 0, i;
    PLLFBD =38;
    CLKDIVbits.PLLPOST=0;
    CLKDIVbits.PLLPRE=0;
    __builtin_write_OSCCONH(0b011);
    __builtin_write_OSCCONL(0b01);
    while (OSCCONbits.COSC != 0b011);	// Wait for Clock switch to occur
    while(OSCCONbits.LOCK != 1) {};
    UART2Init();
    //printf("stuipd thing");
    //TRISD=0x0FF;
    //setting up pins to show on usb debugger
    TRISDbits.TRISD6=1;
    TRISAbits.TRISA7=0;
    TRISAbits.TRISA6=0;
    TRISAbits.TRISA5=0;
    TRISAbits.TRISA4=0;
    //LATA=1;
    //_LATA4=1;
    //_RA7=1;
    //_LATA6=1;

    //_LATA5=1;
    //_LATA7=1;

    //printf("they should be on now");
    //while(1);
    //LATAbits.LATA7=0;
    //TRISB=0xFFFF;
    //AD1PCFGLbits.PCFG1=1;

#ifdef TESTOVERFLOWBUFFER
#ifdef __DEBUG
    printf("Starting test of overflow buffer");

    unsigned char ofbtestin[SECTORSIZE];
    unsigned char ofbtestout[SECTORSIZE];
    OFB_init();
    int ofbi,ofbj,ofbk,result;
    char num=0;
    printf("Starting insertion test\r\n");
    for(ofbj=0; ofbj<=OVERFLOWBUFFERDEPTH; ofbj++)
    {
        for(ofbi=0; ofbi<SECTORSIZE; ofbi++)
            ofbtestin[ofbi]=num+48;
        printf("Size of Buffer: %d\r\n",OFB_getSize());
        printf("Result of Insertion: %d\r\n",OFB_push(ofbtestin));
        printf("New Size: %d\r\n",OFB_getSize());
        num++;
    }
    printf("Starting retrieval test\r\n");
    for(ofbj=0; ofbj<=OVERFLOWBUFFERDEPTH; ofbj++)
    {
        printf("Size of Buffer: %d\r\n",OFB_getSize());
        result=OFB_read_tail(ofbtestout);
        printf("result of read: %d\r\n",result);
        printf("343rd entry in array: %c\r\n",ofbtestout[342]);
        /*for(i=0;i<SECTORSIZE;i++)
        {
        	printf("%d",ofbtestout[i]);
        	while(UART2IsEmpty());
        }*/
        //printf("\r\n");
        result=OFB_pop();
        printf("Result of Pop: %d\r\n",result);
    }
    while(1);
#endif
#endif

    //Service_Spi();
#ifdef __DEBUG
    printf("Clock Switch Complete, Waiting For Media\r\n");
#endif
    //waits for a card to be inserted
    while (!MDD_MediaDetect());


#ifdef __DEBUG
    printf("Media Found, Waiting for FSinit\r\n");
#endif
    // Initialize the library
    while (!FSInit());
    char temp;
    int character_count,remove_success;
    character_count=0;
    // Create a file
    printf("starting up\r\n");
    remove_success=FSremove("WRITE.TXT");
    printf("Removal of prev: %d\r\n",remove_success);
    pointer = FSfopen ("WRITE.TXT", "w");

    if (pointer == NULL)
    {
#ifdef __DEBUG
        printf("File open failed\r\n");
#endif
        while(1);
    }
    //FSfseek(pointer,0,SEEK_SET);
    //set_First_Sector(first_sector);
    //FSfwrite("greetings",1,9,pointer);
    printf("waiting for operation\r\n");
    //FSfwrite("greetings",1,9,pointer);
    //allocate_size(38769,pointer);
    DWORD sizeinbytes;
    //need to convert from number of sectors to number of bytes and allocate that much space
    sizeinbytes=(DWORD)FILESIZE*(DWORD)512;
    //sizeinbytes=3774873*(DWORD)512;
    allocate_size(sizeinbytes,pointer,FALSE);
    FSfseek(pointer,0,SEEK_SET);
    first_sector=get_First_Sector(pointer);
    set_First_Sector(first_sector);
    DWORD erasure;
    OFB_init();
    for(erasure=0; erasure<FILESIZE; erasure++)
    {
        MDD_SDSPI_SectorWrite(first_sector, write_array,FALSE);
        first_sector++;
        if(erasure%100==0)
            printf("%lu\r",erasure);
    }
    int bleh;

    FSfclose(pointer);
    //MDD_ShutdownMedia();
    printf("done with file allocation\r\n");
#ifdef DMAON
#else
#endif

    //while(UART2IsEmpty());
    //temp=UART2GetChar();
    //write_array[character_count]=temp;
    //character_count++;
    while(1)
    {
        Service_Spi();
    }
    /*while(temp!='+')
    {
    	if(character_count<512)
    	{
    		if(!UART2IsEmpty())
    		{
    			temp=UART2GetChar();
    			write_array[character_count]=temp;
    			character_count++;
    			//printf("%08d\r",character_count);
    		}
    	}
    	else
    	{
    	FSfwrite(write_array,1,character_count, pointer);
    	character_count=0;
    	}
    }*/
    //FSfwrite(write_array,1,character_count, pointer);
    //FSfwrite(sendBuffer,1,21, pointer);
    unsigned int buffer[512];
    char buffersign;
    //bufferreturn(buffer);
    while(1)
    {
        /*buffersign=bufferreturn(buffer);
        if(buffersign==1)
        {
         //FSfwrite(buffer,1,512,pointer);
        }*/
        if(!PORTDbits.RD6)
        {
            DMA0CONbits.CHEN=0;
            //FSfclose(pointer);
            DMA0CONbits.CHEN=0;
            printf("done with operations\r\n");
            MDD_ShutdownMedia();
            while(1) {}
        }
    }
    while(1);
}