Exemplo n.º 1
0
/*FUNCTION*/
void hook_fclose(pExecuteObject pEo,
                  FILE *fp
  ){
/*noverbatim
CUT*/
  file_fclose(fp);
  }
Exemplo n.º 2
0
void
cfs_close(int fd)
{
  File *file = get_file(fd);
  if (!file) return;
  file_fclose(file);
  fs_flushFs(&sdcard_efs.myFs);
}
Exemplo n.º 3
0
/* The audio task is responsible for continuously playing music
 * off the SD card.
 */
void audio_task(void *pdata) {
	int err = 0;

	err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_ACTIVE_CTRL, 0x00);
	err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_LEFT_LINE_IN, 0x97);
	err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_RIGHT_LINE_IN, 0x97);
	err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_LEFT_HEADPHONE_OUT, 0x79);
	err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_RIGHT_HEADPHONE_OUT, 0x79);
	err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_ANALOG_AUDIO_PATH_CTRL, 0x12);
	err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_DIGITAL_AUDIO_PATH_CTRL, 0x05);
	err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_POWER_DOWN_CTRL, 0x07);
	err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_AUDIO_DIGITAL_INTERFACE, 0x42);
	err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_SAMPLING_CTRL, 0x22);
	err += alt_up_av_config_write_audio_cfg_register(av_dev, AUDIO_REG_ACTIVE_CTRL, 0x01);
	err += audio_set_headphone_volume(av_dev, DEFAULT_VOLUME);

	if(err < 0)
		printf("Audio Configuration Failed\n");

	alt_up_audio_reset_audio_core(audio_dev);
	alt_up_audio_disable_read_interrupt(audio_dev);
	alt_up_audio_disable_write_interrupt(audio_dev);

	char fileName[10] = {"class.wav\0"};
	if (file_fopen(&readFile, &efsl.myFs, fileName, 'r') != 0)
		printf("Error:\tCould not open file\n");

	int readSize = 0;
	euint32 currentSize = 44;

	euint8 buf[AUDIO_BUF_SIZE];
	int i;

	/* The task is suspended so that it can be played by another task. */
	OSTaskSuspend(AUDIO_TASK_PRIORITY);
	while(1) {
		if (currentSize < readFile.FileSize) {
			int fifospace = alt_up_audio_write_fifo_space(audio_dev, ALT_UP_AUDIO_LEFT);
			if (fifospace > WORD_COUNT) {
				readSize = file_fread(&readFile, currentSize, AUDIO_BUF_SIZE, buf);
				currentSize += readSize;
				i = 0;
				while(i < AUDIO_BUF_SIZE) {
					IOWR_ALT_UP_AUDIO_LEFTDATA(audio_dev->base, (buf[i+1]<<8)|buf[i]);
					IOWR_ALT_UP_AUDIO_RIGHTDATA(audio_dev->base, (buf[i+3]<<8)|buf[i+2]);

					i+=4;
				}
			}
		} else {
			currentSize = 44;
		}
	}

	file_fclose(&readFile);
}
Exemplo n.º 4
0
/* close the file sent, disconnect and close the connection */
void tftp_cleanup_rd(struct udp_pcb *upcb, tftp_connection_args *args)
{
  /* close the filesystem */
  file_fclose(&file_SD);
  fs_umount(&efs1.myFs);
  /* Free the tftp_connection_args structure reserverd for */
  mem_free(args);

  /* Disconnect the udp_pcb*/
  udp_disconnect(upcb);

  /* close the connection */
  udp_remove(upcb);

  udp_recv(UDPpcb, recv_callback_tftp, NULL);
}
Exemplo n.º 5
0
int main(int argc, char** argv)
{
	EmbeddedFileSystem efs;
	EmbeddedFile file;	
	unsigned short e;
	unsigned short bufsize;
	signed short ret;
	char *buf;
	FILE *localfile;
	
	if(argc<4){
		fprintf(stderr,"Argument error : cpa <fs> <local_read> <file_append> [bufsize]\n");
		exit(-1);
	}

	if(argc==5)
		bufsize=atoi(argv[4]);
	else
		bufsize=4096;
	buf=malloc(bufsize);
	
	if(efs_init(&efs,argv[1])!=0){
		printf("Could not open filesystem.\n");
		return(-1);
	}
	
	ret=file_fopen(&file,&efs.myFs,argv[3],'a');
	if((ret!=0)){
		printf("Could not open file %s (return value: %d).\n",argv[3],ret);
		return(-2);
	}

	if(!(localfile=fopen(argv[2],"r"))){
		printf("Could not open local file.\n");
		return(-3);
	}
	
	while((e=fread(buf,1,bufsize,localfile))){
		file_write(&file,e,buf);
	}

	file_fclose(&file);
	fclose(localfile);
	fs_umount(&(efs.myFs));

	return(0);
}
Exemplo n.º 6
0
static int wrap_fs_close(struct _reent *r, int file)
{
    if (fd_list[file].used) {
	int ret = 0;
	fprintf(stderr, "close file\n");
	if (file_fclose(fd_list[file].file)) {
	    fprintf(stderr, "f_close %d\n", ret);
	    r->_errno = EIO;
	    ret = -1;
	}
	free(fd_list[file].file);
	fd_list[file].file = NULL;
	fd_list[file].used = 0;
	return 0;
    }
    r->_errno = EBADF;
    return -1;
}
Exemplo n.º 7
0
/**
 * This function will set a hook function, which will be invoked when a memory 
 * block is allocated from heap memory.
 * 
 * @param hook the hook function
 */
int efs_close(struct dfs_fd* file)
{
	int result = 0;
	
	if (!file || !(file->flags & DFS_F_OPEN)) return -DFS_STATUS_EBADF;
	
	if(!(file->flags & DFS_F_DIRECTORY)) 
		result = file_fclose((File *)file->data);
	else
	{
		dfs_log(DFS_DEBUG_INFO, ("close a directory, %s", file->path));
	}

	dfs_log(DFS_DEBUG_INFO, ("close a file, %s", file->path));

	/* free directory or file */
	rt_free(file->data);
	file->data = RT_NULL;

	return result;
}
Exemplo n.º 8
0
static void _MyCloseFile(void *fp, void *p){
  file_fclose((FILE *)fp);
  }
int main()
{
	int8_t res;
    uint32_t n, m, p, cnt;
    uint32_t cclk = CLKPWR_GetCLK(CLKPWR_CLKTYPE_CPU);
    uint32_t filesize = 0;
    uint32_t time_end;

//	SystemInit();
    SysTick_Config(cclk/1000 - 1); /* Generate interrupt each 1 ms   */

	debug_frmwrk_init(); // UART0
    xfunc_out = put_char;
	xfunc_in  = get_char; 

    xprintf("%s",mciFsMenu);

	xprintf("\nMMC/SD Card Filesystem Test (P:LPC1788 L:EFSL)\n");

	xprintf("\nCARD init...");

	// init file system
	if ( ( res = efs_init( &efs, 0 ) ) != 0 ) {
		xprintf("failed with %d\n",res);
	}
	else 
	{
		xprintf("ok\n");

        xprintf("Card type: ");
        switch (CardConfig.CardType)
        {
            case MCI_MMC_CARD:
                xprintf("MMC\n");
                break;
            case MCI_SDSC_V1_CARD:
                xprintf("Version 1.x Standard Capacity SD card.\n");
                break;
            case MCI_SDSC_V2_CARD:
                xprintf("Version 2.0 or later Standard Capacity SD card.\n");
                break;
            case MCI_SDHC_SDXC_CARD:
                xprintf("Version 2.0 or later High/eXtended Capacity SD card.\n");
                break;
            default:
                break;            
        }
        xprintf("Sector size: %d bytes\n", CardConfig.SectorSize);
        xprintf("Sector count: %d\n", CardConfig.SectorCount);
        xprintf("Block size: %d sectors\n", CardConfig.BlockSize);
        xprintf("Card capacity: %d MByte\n\n", (((CardConfig.SectorCount >> 10) * CardConfig.SectorSize)) >> 10);
		xprintf("\nDirectory of 'root':\n");
		
		/* list files in root directory */
		ls_openDir( &list, &(efs.myFs) , "/");
		while ( ls_getNext( &list ) == 0 ) {
			// list.currentEntry is the current file
			list.currentEntry.FileName[LIST_MAXLENFILENAME-1] = '\0';
			xprintf("%s, 0x%x bytes\n", list.currentEntry.FileName, list.currentEntry.FileSize ) ;
		}
#if READ_TEST_ENABLED!=0
        /* Read test */
        xprintf("\nFile read test:\n");
        xprintf("Open file %s ...", FILE_NAME_R);
        xmemset(Buff,0,sizeof(Buff));
        if (file_fopen( &filer, &efs.myFs , FILE_NAME_R , 'r' ) == 0 )
        {
            xprintf(" OK. \nReading %lu bytes ...\n", FILE_RW_SIZE);

            n=FILE_RW_SIZE; 
            m = 0;
            Timer = 0;
            xprintf("File's content:\n");
            while (n)
            {
                if (n>=blen) {cnt = blen; n -= blen;}
                else         {cnt = n; n = 0;}

                p =  file_read( &filer, cnt, &Buff[m] );
                xprintf("%s",&Buff[m]);
                m += p;
                if (p != cnt) break;                
            }
            filesize = m;
            time_end = Timer;
            xprintf("\n%lu bytes read in %lu milisec.\n", m, time_end);
            file_fclose( &filer ); 

        } else
        {
            xprintf (" Failed.\n");    
        }
#endif
#if WRITE_TEST_ENABLED!=0
        /* Write test*/  
        xprintf("\nFile write test:\n");
        xprintf("Open file %s ...", FILE_NAME_W);
        if (file_fopen( &filew, &efs.myFs , FILE_NAME_W , 'a' ) == 0 )
        {
            xprintf(" OK. \nWriting %lu bytes ...\n", filesize);
            n=filesize;
            m = 0;
            Timer = 0;
            while (n)
            {
                if (n>=blen) {
                    cnt = blen;
                    n -= blen;
                } else {
                    cnt = n;
                    n = 0;
                }
                p = file_write( &filew, cnt, &Buff[m] );
                m += p;
                if (p != cnt) break;
            }
            time_end = Timer;
            xprintf("%lu bytes written in %lu milisec.\n", m, time_end);

            file_fclose( &filew );                          

        } else {
            xprintf (" Failed.\n");
        }
#endif
#if READ_TEST_ENABLED!=0
        /* Read test */
        xprintf("\nFile read test:\n");
        xprintf("Open file %s ...", FILE_NAME_W);
        xmemset(Buff,0,sizeof(Buff));
        if (file_fopen( &filer, &efs.myFs , FILE_NAME_W , 'r' ) == 0 )
        {
            xprintf(" OK. \nReading %lu bytes ...\n", FILE_RW_SIZE);

            n=FILE_RW_SIZE; 
            m = 0;
            Timer = 0;
            xprintf("File's content:\n");
            while (n)
            {
                if (n>=blen) {cnt = blen; n -= blen;}
                else         {cnt = n; n = 0;}

                p =  file_read( &filer, cnt, &Buff[m] );
                xprintf("%s",&Buff[m]);
                m += p;
                if (p != cnt) break;                
            }
            filesize = m;
            time_end = Timer;
            xprintf("\n%lu bytes read in %lumiliseconds.\n", m, time_end);
            file_fclose( &filer ); 

        } else
        {
            xprintf (" Failed.\n");    
        }
#endif
        /* close file system */
	    fs_umount( &efs.myFs ) ;
    }

	xprintf("\nEFSL test complete.\n");

	while (1);
}
Exemplo n.º 10
0
int main()
{
	int8_t res;
    uint32_t n, m, p, cnt;

//	SystemInit();
    SysTick_Config(SystemCoreClock/1000 - 1); /* Generate interrupt each 1 ms   */

	LPC17xx_UART_Init(115200); // UART0
    xfunc_out = LPC17xx_UART_PutChar;
	xfunc_in  = LPC17xx_UART_GetChar; 

	xprintf("\nMMC/SD Card Filesystem Test (P:LPC1768 L:EFSL)\n");

	xprintf("\nCARD init...");

	// init file system
	if ( ( res = efs_init( &efs, 0 ) ) != 0 ) {
		xprintf("failed with %i\n",res);
	}
	else 
	{
		xprintf("ok\n");

        xprintf("Card type: ");
        switch (CardType)
        {
            case CARDTYPE_MMC:
                xprintf("MMC\n");
                break;
            case CARDTYPE_SDV1:
                xprintf("Version 1.x Standard Capacity SD card.\n");
                break;
            case CARDTYPE_SDV2_SC:
                xprintf("Version 2.0 or later Standard Capacity SD card.\n");
                break;
            case CARDTYPE_SDV2_HC:
                xprintf("Version 2.0 or later High/eXtended Capacity SD card.\n");
                break;
            default:
                break;            
        }
        xprintf("Sector size: %d bytes\n", CardConfig.sectorsize);
        xprintf("Sector count: %d\n", CardConfig.sectorcnt);
        xprintf("Block size: %d sectors\n", CardConfig.blocksize);
        xprintf("Card capacity: %d MByte\n\n", (((CardConfig.sectorcnt >> 10) * CardConfig.sectorsize)) >> 10);

		xprintf("\nDirectory of 'root':\n");
		
		/* list files in root directory */
		ls_openDir( &list, &(efs.myFs) , "/");
		while ( ls_getNext( &list ) == 0 ) {
			// list.currentEntry is the current file
			list.currentEntry.FileName[LIST_MAXLENFILENAME-1] = '\0';
			xprintf("%s, 0x%x bytes\n", list.currentEntry.FileName, list.currentEntry.FileSize ) ;
		}

#if WRITE_TEST_ENABLED!=0
        /* Write test*/  
        xprintf("\nFile write test:\n");
        xprintf("Open file %s ...", FILE_NAME);
        if (file_fopen( &filew, &efs.myFs , FILE_NAME , 'a' ) == 0 )
        {
            xprintf(" OK. \nWriting %lu bytes ...\n", FILE_RW_SIZE);

            xmemset(Buff, 0xAA, blen);
            n=FILE_RW_SIZE;
            m = 0;
            Timer = 0;
            while (n)
            {
                if (n>=blen) {
                    cnt = blen;
                    n -= blen;
                } else {
                    cnt = n;
                    n = 0;
                }
                p = file_write( &filew, cnt, Buff );
                m += p;
                if (p != cnt) break;
            }
            xprintf("%lu bytes written with %lu kB/sec.\n", m, Timer ? (m / Timer) : 0);

            file_fclose( &filew );                          

        } else {
            xprintf (" Failed.\n");
        }
#endif

#if READ_TEST_ENABLED!=0
        /* Read test */
        xprintf("\nFile read test:\n");
        xprintf("Open file %s ...", FILE_NAME);
        if (file_fopen( &filer, &efs.myFs , FILE_NAME , 'r' ) == 0 )
        {
            xprintf(" OK. \nReading %lu bytes ...\n", FILE_RW_SIZE);

            n=FILE_RW_SIZE; 
            m = 0;
            Timer = 0;
            while (n)
            {
                if (n>=blen) {cnt = blen; n -= blen;}
                else         {cnt = n; n = 0;}

                p =  file_read( &filer, cnt, Buff );
                m += p;
                if (p != cnt) break;                
            }
            xprintf("%lu bytes read with %lu kB/sec.\n", m, Timer ? (m / Timer) : 0);

            file_fclose( &filer ); 

        } else
        {
            xprintf (" Failed.\n");    
        }
#endif

        /* close file system */
	    fs_umount( &efs.myFs ) ;
    }

	xprintf("\nEFSL test complete.\n");

	while (1);
}
Exemplo n.º 11
0
void main(void)
{
	EmbeddedFileSystem efs;
	EmbeddedFile file_w;
	unsigned short i;
	unsigned char e;
	unsigned char t;
	signed char err;
	unsigned char offset1;
	unsigned char offset2;
	char path[100];

	debug_init();
	
	DBG((TXT("Welcome (2).\n-------------\n\n")));
	if(efs_init(&efs,0)!=0){
		DBG((TXT("Could not init filesystem.\n")));
		hang();
	}

	for(i=1;i<=4;i++){
		offset1=c2str(1,path);
		path[offset1++]='/';
		for(e=1;e<=12;e++){
			offset2=offset1;
			offset2+=c2str(e,path+offset1);
			DBG((TXT("Dir name: %s.\n"),path));
		}
	}
	/*for(i=1;i<10;i++){	
		path[0]='D';
		path[1]='I';
		path[2]='R';
		path[3]=0x30+((i%10000)/1000);
		path[4]=0x30+((i%1000)/100);
		path[5]=0x30+((i%100)/10);
		path[6]=0x30+((i%10)/1);
		path[7]='\0';
		err=mkdir(&efs.myFs,path);
		if(err!=0){
			DBG((TXT("ERROR: Could not create directory %s (%d) - returned ERR %d.\n"),path,i,err));
			hang();
		}
		DBG((TXT("DIR %s created.\n"),path));
		for(e=1;e<6;e++){
			path[7]='/';
			path[8]=0x40+e;
			path[9]='\0';
			err=mkdir(&efs.myFs,path);
			if(err!=0){
				DBG((TXT("ERROR: Could not create directory %s (%d) - returned ERR %d.\n"),path,i,err));
				hang();
			}
			DBG((TXT("DIR %s created.\n"),path));
			for(t=0;t<26;t++){
				path[9]='/';
				path[10]='t';
				path[11]='e';
				path[12]='s';
				path[13]='t';
				path[14]='-';
				path[15]=0x41+t;
				path[16]='.';
				path[17]='t';
				path[18]='x';
				path[19]='t';
				path[20]='\0';
				if(file_fopen(&file_w,&efs.myFs,path,'w')!=0){
					DBG((TXT("Could not open file %s for writing.\n"),path));		
					hang();
				}
				file_write(&file_w,15,"Dit is een test");
				file_fclose(&file_w);
			}
		}
	}*/

	file_fclose(&file_w);
	fs_umount(&efs.myFs);

	DBG((TXT("Done :-)\n\n")));
	
	hang();
}
Exemplo n.º 12
0
void write_file_cli(int argc, char** argv)
{
	char* filename;
	char a,b,c;
	int quit =1;
	signed char retval;
	File output;
	MESSAGE("opening file\n\r");
	retval = file_fopen(&output, &(efs.myFs), argv[1], 'w');
	MESSAGE("opened file\n\r");
	switch(retval)
	{
		case -2: //File already exists, open it for appending
			MESSAGE("File already exists, append to it?(Y/N):");
			c = UART0_Getchar();
			if(c == 'Y' || c == 'y')
			{
				if(file_fopen(&output, &(efs.myFs), argv[1], 'a') == -3)
				{
					MESSAGE("No more space!\n\r");
					return;
				}
				else
				{
					MESSAGE("appended to %s\n\r", argv[1]);
				}
			
			}
			else
				return;
			break;
		case -3:
			MESSAGE("No more space!\n\r");
			return;

		case 0:
			MESSAGE("file opened successfully\n\r");
			break;
		default:
			MESSAGE("unknown error occured\n\r");
	}
	MESSAGE("chars are being entered into the file until ~`! is recieved:\n\r");
	a = 0;
	b = 0;
	c = 0;
	
	while(quit)
	{
		a = UART0_Getchar();
		if(a == '~')
		{
			b = UART0_Getchar();
			if(b == '`')
			{
				c = UART0_Getchar();
				if(c == '!')
				{
					quit = 1;
					MESSAGE("quit recieved\n\r");
					file_fclose(&output);
					return;
				}
				else
				{
					file_write(&output, 1, &a);
					file_write(&output, 1, &b);
					file_write(&output, 1, &c);
				}
			}
			else
			{
				file_write(&output, 1, &a);
				file_write(&output, 1, &b);
			}
	
		}
		else
		{

			file_write(&output, 1, &a);

		}
		

	}

}
Exemplo n.º 13
0
int main(void)
{
	int ch;
	int8_t res;
	
	systemInit();
	gpioInit();
	
	uart1Init(UART_BAUD(BAUD), UART_8N1, UART_FIFO_8); // setup the UART
		
	uart1Puts("\r\nMMC/SD Card Filesystem Test (P:LPC2138 L:EFSL)\r\n");
	uart1Puts("efsl LPC2000-port and this Demo-Application\r\n");
	uart1Puts("done by Martin Thomas, Kaiserslautern, Germany\r\n");
	
	/* init efsl debug-output */
	lpc2000_debug_devopen(uart1Putch);
		
	ledToggle();
	
	rprintf("CARD init...");
	if ( ( res = efs_init( &efs, 0 ) ) != 0 ) {
		rprintf("failed with %i\n",res);
	}
	else {
		rprintf("ok\n");
		rprintf("Directory of 'root':\n");
		ls_openDir( &list, &(efs.myFs) , "/");
		while ( ls_getNext( &list ) == 0 ) {
			list.currentEntry.FileName[LIST_MAXLENFILENAME-1] = '\0';
			rprintf( "%s ( %li bytes )\n" ,
				list.currentEntry.FileName,
				list.currentEntry.FileSize ) ;
		}
		
		if ( file_fopen( &filer, &efs.myFs , LogFileName , 'r' ) == 0 ) {
			rprintf("File %s open. Content:\n", LogFileName);
			while ( ( e = file_read( &filer, 512, buf ) ) != 0 ) {
				buf[e]='\0';
				uart1Puts((char*)buf);
			}
			rprintf("\n");
			file_fclose( &filer );
		}
		
		if ( file_fopen( &filew, &efs.myFs , LogFileName , 'a' ) == 0 ) {
			rprintf("File %s open for append. Appending...", LogFileName);
			strcpy((char*)buf, "Martin hat's angehaengt\r\n");
			if ( file_write( &filew, strlen((char*)buf), buf ) == strlen((char*)buf) ) {
				rprintf("ok\n");
			}
			else {
				rprintf("fail\n");
			}
			file_fclose( &filew );
		}
		
		if ( file_fopen( &filer, &efs.myFs , LogFileName , 'r' ) == 0 ) {
			rprintf("File %s open. Content:\n", LogFileName);
			while ( ( e = file_read( &filer, 512, buf ) ) != 0 ) {
				buf[e]='\0';
				uart1Puts((char*)buf);
			}
			rprintf("\n");
			file_fclose( &filer );
		}
		
		fs_umount( &efs.myFs ) ;
	}
	
	while(1) {
		if ((ch = uart1Getch()) >= 0) {
			uart1Puts("You pressed : ");
			uart1Putch(ch);
			uart1Puts("\r\n");
			if ( ch == 'M' ) {
				rprintf("Creating FS\n");
				mkfs_makevfat(&efs.myPart);
			}
			ledToggle();
		}
	}
	
	return 0; /* never reached */
}