示例#1
1
//*****************************************************************************
//
// This function opens the drive number and prepares it for use by the Mass
// storage class device.
//
// /param ulDrive is the driver number to open.
//
// This function is used to initialize and open the physical drive number
// associated with the parameter /e ulDrive.  The function will return zero if
// the drive could not be opened for some reason.  In the case of removable
// device like an SD card this function should return zero if the SD card is
// not present.
//
// /return Returns a pointer to data that should be passed to other APIs or it
// will return 0 if no drive was found.
//
//*****************************************************************************
void *
USBDMSCStorageOpen(unsigned long ulDrive)
{
    unsigned char ucPower;
    unsigned long ulTemp;

    ASSERT(ulDrive == 0);

    //
    // Return if already in use.
    //
    if(g_sDriveInformation.ulFlags & SDCARD_IN_USE)
    {
        return(0);
    }

    //
    // Initialize the drive if it is present.
    //
    ulTemp = disk_initialize(0);

    if(ulTemp == RES_OK)
    {
        //
        // Power up the card.
        //
        ucPower = 1;
        disk_ioctl(0, CTRL_POWER, &ucPower);

        //
        // Card is present and in use.
        //
        g_sDriveInformation.ulFlags = SDCARD_PRESENT | SDCARD_IN_USE;
    }
    else if(ulTemp == STA_NODISK)
    {
        //
        // Allocate the card but it is not present.
        //
        g_sDriveInformation.ulFlags = SDCARD_IN_USE;
    }
    else
    {
        return(0);
    }

    return((void *)&g_sDriveInformation);
}
示例#2
0
void log_init(void)
{
	disk_initialize(0);
	delay(1);
	int result = disk_initialize(0);
	if(result == 0)
	{
		f_mount(0, &FATFS_Obj);

		char filename[200];
		{
			int filecounter = 0;
			FILINFO filetest;
			sprintf(filename,"0:log%05u.txt",filecounter);
			while(f_stat(filename,&filetest) == FR_OK)
			{
				filecounter++;
				sprintf(filename,"0:log%05u.txt",filecounter);
			}
		}
		int result = f_open(&file, filename, FA_CREATE_NEW | FA_WRITE);
		if(result != 0)
		{
			led_fastBlink(LED_SDCARD);
			sd_card_available = 0;
			return;
		}
		result = f_sync(&file);
		if(result != 0)
		{
			led_fastBlink(LED_SDCARD);
			sd_card_available = 0;
			return;
		}
		result = f_lseek(&file, file.fsize);
		if(result != 0)
		{
			led_fastBlink(LED_SDCARD);
			sd_card_available = 0;
			return;
		}
		//usb_printfi_buffered("SD filename: %s\n",filename);
		led_on(LED_SDCARD);
		sd_card_available = 1;
		
	}
	{
		//usb_printf_buffered("NO SD");
	}
}
示例#3
0
void sd_fs_init(void)
{
    /* SD卡中断初始化 */
		SDIO_NVIC_Configuration();		
		/* SD 卡硬件初始化,初始化盘符为0 */	 
    disk_initialize( 0 );	         
}
示例#4
0
//Init function 
void ICACHE_FLASH_ATTR
user_init()
{
    disk_initialize(MMC);
    //Start os task
    system_os_task(user_procTask, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);
}
示例#5
0
文件: sdcard.c 项目: Crob4/HackaGecko
/**************************************************************************//**
 * @brief
 *   SDCARD_Initialization.
 * @details
 *   Initialize SD Card
 *****************************************************************************/
void SDCARD_Initialization()
{
  /* Enable SPI */
  USART1->CMD = USART_CMD_MASTEREN | USART_CMD_TXEN | USART_CMD_RXEN;
  
  volatile int waiting;
  /* Initialize SD Card */
  while(1)
  {
    MICROSD_Init();                     /*Initialize MicroSD driver */
      USART1->CMD = USART_CMD_MASTEREN | USART_CMD_TXEN | USART_CMD_RXEN;

    resCard = disk_initialize(0);       /*Check micro-SD card status */
    
    switch(resCard)
    {
    case STA_NOINIT:                    /* Drive not initialized */
      break;
    case STA_NODISK:                    /* No medium in the drive */
      break;
    case STA_PROTECT:                   /* Write protected */
      break;
    default:
      break;
    }
   
    if (!resCard) break;                /* Drive initialized. */
 
    /* wait a moment */
    for(waiting = 0; waiting < 0xfff; waiting++){
      waiting++;
      waiting--;
    }
  }
}
示例#6
0
/*******************************************************************************
*                                 Main Routine
*******************************************************************************/
int main (void)
{
    printf("\n\rInitializing SD Card...\r\n");
    /* Initialize SPI driver and SD Card */
    if(RES_OK != disk_initialize(SD))
    {
      printf("Failed to initialize SD disk\r\n");
      while(1);
    }
    if(FR_OK != fatdemo())
    {
      printf("FAT Demo failed\r\n");
      g_card_initialized = 0;
    }
    /* if the SD card is initialized, enable the USB MSD device */
    if(g_card_initialized)
    {
      usbd_init();

      usbd_connect(__TRUE);

      usb_state = USB_CONNECTING;
      
      while (!usbd_configured ());          /* Wait for device to configure */
    }
      
    EnableInterrupts;
    
    while(1) 
    {
      Delayms(500);
    }
		
}
示例#7
0
BOOL SDCARD_Mount(void)
{
	if(fsMounted == FALSE)
	{
		if (!(disk_status(MMC_DRIVE) & STA_NODISK)) {
			// disk inserted so initialise it
			if (disk_initialize(MMC_DRIVE) == 0) {
				if (f_mount(MMC_DRIVE, &fatfs[MMC_DRIVE]) == FR_OK) {
					fsMounted = TRUE;
					return TRUE;
				}	
			}
			else
			{
				return FALSE;
			}
		}
		else
		{
			return FALSE;
		}
	}
	else
	{
		return TRUE;
	}
}
void fatfs_init(unsigned char prio)
{
	FRESULT fret;
	
	raw_printf("FatFs init...\r\t\t\t\t");
	disk_initialize(0);
	fret = f_mount(&_FS, _T("0"), 0);
	if(FR_OK != fret)
	{
		RAW_ASSERT(0);
	}
	raw_printf("[OK]\n");
	
//	if( need_format(0) )
	if(1)
	{
		raw_printf("mkfs ...\r\t\t\t\t");
		fret = f_mkfs(_T("0:"), 0, 512);
		if(FR_OK != fret)
		{
			RAW_ASSERT(0);
		}
		raw_printf("[OK]\n");
	}
}
示例#9
0
void data_hub_init(){
  log_file_opened = FALSE;
  free_page = locked_page = payload_buf;
  log_block_size = PAGE_SIZE;

  disk_initialize(0);
}
示例#10
0
void device_initialize (void)
{
   /* call for each type of device */
  disk_initialize ();
  simpledisk_initialize ();
  mems_initialize ();
}
示例#11
0
/**
 ** FIXME - actual support for multiple volumes
 **/
bool CFile::initialize(int volume)
{
    volatile uint8_t err=0;
    mInitialized=false;
    do {
        deinitialize(volume);
        if ( (mFileSystem = (FATFS*)malloc(sizeof(FATFS))) )
        {
            memset(mFileSystem,0,sizeof(FATFS));
            if ( ( err = disk_initialize(volume) ) == FR_OK )
            {
                if ( ( err = disk_status(volume) ) == FR_OK )
                {
                    if ( ( err = f_mount(mFileSystem,"",0) ) == FR_OK )
                    {
                        mInitialized=true;
                    }
                }
            }
            if ( !initialized() )
            {
                free(mFileSystem);
                mFileSystem=NULL;
                disk_init_fail(err);
            }
        }
    } while ( err );
    disk_init_fail(0); // clear the status/diag LEDs
    return mInitialized;
}
示例#12
0
bool USBMSD::connect() {

    //disk initialization
    if (disk_status() & NO_INIT) {
        if (disk_initialize()) {
            return false;
        }
    }

    // get number of blocks
    BlockCount = disk_sectors();

    // get memory size
    MemorySize = disk_size();

    if (BlockCount > 0) {
        BlockSize = MemorySize / BlockCount;
        if (BlockSize != 0) {
            page = (uint8_t *)malloc(BlockSize * sizeof(uint8_t));
            if (page == NULL)
                return false;
        }
    } else {
        return false;
    }

    //connect the device
    USBDevice::connect();
    return true;
}
示例#13
0
文件: Storage.c 项目: 0xE0F/ir-system
/** Инициализация хранилища */
bool InitStorage(void)
{
	FRESULT result;
	StorageInit = 0;
	printf("Initialazing storage...");
	WORD status = (WORD)disk_initialize(0);
	if (status) {
		if (status == STA_NODISK) {
			print("no disk\n\r");
		}
		if (status == STA_NOINIT) {
			print("interal error\n\r");
		}
		if (status == STA_PROTECT) {
			print("write protect\n\r");
		}

		return false;
	}

	result = f_mount(0, &_FatFs);
	if (result != FR_OK) {
		print("Unable to mount fs\n\r");
		return false;
	}

	StorageInit = 1;
	print("done\n\r");
	return true;
}
示例#14
0
void file_init() {
  // Set up the SD card SS pin.  Set it to off before setting it as an output,
  // in case it briefly gets turned on.
  spi_clear_ss(SELECT_SD_BIT);
  DDRC |= (1 << SELECT_SD_BIT);

  // Clear the file handle states.
  for (int i = 0; i < MAX_NUM_FILE_HANDLES; ++i)
    file_handle_active[i] = false;

  // Initialize the SD card file system.
  int status = disk_initialize(0);
#ifdef DEBUG
  if (status != RES_OK) {
    fprintf_P(stderr, file_init_str0, status);
    return;
  }
#endif  // defined(DEBUG)

  status = f_mount(0, &fatfs);
#ifdef DEBUG
  if (status != FR_OK) {
    fprintf_P(stderr, file_init_str1, status);
  }
#endif  // defined(DEBUG)
}
void OTPWriter_Init(void)
{
	u16 res;

#ifndef OTPWriter_IAP
	HS_PacketInfo PacketInfo;
#endif
	delay_init(72);
	//NVIC_Configuration();
	USB_Disconnect_Config();	  //USB软连接断开控制引脚
	//Console_init();
#ifdef OTPWriter_IAP
    u8 key = 0;
	printf("%s\r\n", SysInfo_OTPWriter_IAP);

	key = g_KEY.IsReleased();

	if(key==1)
	{
		MSD0_SPI_Configuration();
		//挂载文件系统
		disk_initialize(0);
		res = f_mount(0,&fs);
		if(res != FR_OK){
			printf("mount filesystem 0 failed : %d\r\n",res);
		}

		OTPWriter_IAP_from_SD();
		Execute_New_program();
	}
	else
		Execute_New_program();

#else		 //#ifdef OTPWriter_IAP
	printf("%s\r\n", SysInfo_OTPWriter);
	usb_init();
	//OTP_SPI_Init();
	MSD0_SPI_Configuration();
	//挂载文件系统
	disk_initialize(0);
	res = f_mount(0,&fs);
	if(res != FR_OK){
		printf("mount filesystem 0 failed : %d\r\n",res);
	}
	LED_Light(5);
#endif
}
示例#16
0
void OutPutFile(void)
{
  FRESULT res;
  FILINFO finfo;
  DIR dirs;
  int i;
  char *fn;
  char path[50]={""};  
  char name[]={"WVO.TXT"};
    
  printf("\n file system starting! \n");
  
  disk_initialize(0);
    
  f_mount(0, &fs);
/* 
  res = f_opendir(&dir, path);
  if (res == FR_OK) 
  {
    i = strlen(path);
    for (;;) 
    {
      res = f_readdir(&dir, &fno);
      if (res != FR_OK || fno.fname[0] == 0) break;
      fn = fno.fname;
      if (fno.fattrib & AM_DIR) 
      {
        sprintf(&path[i], "/%s", fn);
        res = scan_files(path);
        if (res != FR_OK) break;
        path[i] = 0;
      } 
      else 
      {
        printf("%s/%s\n\n", path, fn);
      }
    }
  }
*/  
 if (f_opendir(&dirs, path) == FR_OK) 
  {
    while (f_readdir(&dirs, &finfo) == FR_OK)  
    {
      if (finfo.fattrib & AM_ARC) 
      {
        if(!finfo.fname[0])	
          break;         
        printf("\n file name is:\n   %s\n",finfo.fname);
        res = f_open(&fsrc, finfo.fname, FA_OPEN_EXISTING | FA_READ);
        res = f_read(&fsrc, &buffer, 50, &br);
        printf("\n file contex is:\n   %s\n",buffer);
        f_close(&fsrc);			                      
      }
    } 
    
  }
  
  while(1);
}
示例#17
0
/** @brief Initialize a disk.

    @param bVolNum  The volume number of the volume whose block device is being
                    initialized.
    @param mode     The open mode, indicating the type of access required.

    @return A negated ::REDSTATUS code indicating the operation result.

    @retval 0           Operation was successful.
    @retval -RED_EIO    A disk I/O error occurred.
*/
static REDSTATUS DiskOpen(
    uint8_t         bVolNum,
    BDEVOPENMODE    mode)
{
    DSTATUS         status;
    uint32_t        ulTries;
    REDSTATUS       ret = 0;

    /*  With some implementations of disk_initialize(), such as the one
        implemented by Atmel for the ASF, the first time the disk is opened, the
        SD card can take a while to get ready, in which time disk_initialize()
        returns an error.  Try numerous times, waiting half a second after each
        failure.  Empirically, this has been observed to succeed on the second
        try, so trying 10x more than that provides a margin of error.
    */
    for(ulTries = 0U; ulTries < 20U; ulTries++) {
        /*  Assuming that the volume number is also the correct drive number.
            If this is not the case in your environment, a static constant array
            can be declared to map volume numbers to the correct driver number.
        */
        status = disk_initialize(bVolNum);
        if(status == 0) {
            break;
        }

        vTaskDelay(500U / portTICK_PERIOD_MS);
    }

    if(status != 0) {
        ret = -RED_EIO;
    }

    /*  Retrieve the sector size and sector count to ensure they are compatible
        with our compile-time geometry.
    */
    if(ret == 0) {
        WORD    wSectorSize;
        DWORD   dwSectorCount;
        DRESULT result;

        result = disk_ioctl(bVolNum, GET_SECTOR_SIZE, &wSectorSize);
        if(result == RES_OK) {
            result = disk_ioctl(bVolNum, GET_SECTOR_COUNT, &dwSectorCount);
            if(result == RES_OK) {
                if(    (wSectorSize != gaRedVolConf[bVolNum].ulSectorSize)
                        || (dwSectorCount < gaRedVolConf[bVolNum].ullSectorCount)) {
                    ret = -RED_EINVAL;
                }
            } else {
                ret = -RED_EIO;
            }
        } else {
            ret = -RED_EIO;
        }
    }

    return ret;
}
/**
 *	Mount the SD module. Internal static funtcion not to call from main 
 *	application.
 *
 *	\return TRUE - the initialization succeded
 *	\return FALSE - the initialization doesn't succeded (SD card not inserted?)
 */
static BOOL diskMount()
{	
	if ( f_mount(0, &Fatfs) == FR_OK)
	{
		disk_initialize(0);
		return TRUE;
	}
	else
		return FALSE;
}
示例#19
0
int main (void)
{
	clunet_init();  
	clunet_set_on_data_received(data_received);	
	time_init();
	sei();
	//eeprom_write_dword((void*)0, 0);
	record_num = eeprom_read_dword((void*)0); // Читаем кол-во записей
	mode_current = eeprom_read_byte((void*)4); // Режим 
	mode_temp = eeprom_read_byte((void*)5); // Временный режим

	disk_initialize(0);	

	unset_bit(DDRA, 3); set_bit(PORTA, 3);	 // Определение сигнала в линии	
	//unset_bit(DDRA, 4);	unset_bit(PORTA, 4); // Открывалка двери, напрямую
	set_bit(DDRA, 4);	unset_bit(PORTA, 4); // Открывалка двери, через реле
	set_bit(DDRA, 5); HANGUP; // Реле снимания трубки
	set_bit(DDRA, 6); MODE_NORMAL; // Реле выбора режима
	unset_bit(DDRG, 0); set_bit(PORTG, 0); // Определение, лежит ли трубка	
	set_bit(DDRD, 6); set_bit(DDRD, 7); // Светодиоды
	unset_bit(DDRA, 7); set_bit(PORTA, 7); // Счётчик оборотов диска

	unset_bit(DDRF, 0); // ADC+
	unset_bit(PORTF, 0);
	unset_bit(DDRF, 1); // ADC-
	unset_bit(PORTF, 1);

	beep(500, 200);
	beep(1500, 200);
	beep(3000, 200);
	_delay_ms(1000);
	if (play_wav_pgm(STARTED_WAV) == 0)
	{
		LED_GREEN_ON;
		while (sound_read() >= 0) ;
		LED_GREEN_OFF;
		sound_stop();
	} else {
		LED_RED_ON;
		beep(3000, 200);
		beep(1500, 200);
		beep(500, 200);
		LED_RED_OFF;
	}
	
	send_current_mode(CLUNET_BROADCAST_ADDRESS);

	while(1)
	{
		if (is_LINE_POWER()) incoming_ring();
		if (OFFHOOK) control_mode();
		transfer_data(); // Передаём данные на досуге.
	}
}
示例#20
0
DSTATUS PFFS::disk_init (
	void //unsigned char drv	/* Physical drive number (0) */
)
{
	DSTATUS res;

	SPI_SET_DIVIDER(_clkdivider);
	res = disk_initialize();
	SPI_SET_DIVIDER(_clkdivider);
	
	return res;
}
示例#21
0
void main()
{
	FATFS fs;
	FIL file;

	InitMCU();
	//VS_SinTest(0x74);
	VS_Init();

	if(disk_initialize(0))
		ConsoleWrite("Disk Initialization FAILED. :(\n");
	else
		ConsoleWrite("Disk Initialization Complete.\n");

	if(f_mount(0,&fs))
		ConsoleWrite("Mount FieSystem Failed\n");
	else
		ConsoleWrite("Mount FileSystem Success!\n");

	ConsoleWrite("Scaning Music Files...\n\n");
	if(scan_files("/",&(Player.TotalSongNum)))
		ConsoleWrite("Scan Files Failed\n");
	else{
		ConsoleWrite("\nScan Files Accomplished.\ntotal files: ");
		ConsolePutUInt (Player.TotalSongNum);
		ConsoleWrite ("\n\n");}

	if(scan_files_open (&file,"/",1))       // Start node to be scanned and opened
		ConsoleWrite("Open File Error\n");  //Playing mp3/track001.mp3 ... will apear in function		

	
	Player.currFile	= &file;
	Player.SongNum	= 1;
	Player.Status	= PS_PLAYING;
	Player.Mode		= SM_SONG;
	Player.Volume	= 170;
	Player.Bass		= 7;
	Player.Treble	= 0;

	VS_SetBassTreble(Player.Bass,Player.Treble);

	BufCnt = 0;
//	GenerateEvent(EV_BUFEMPTY);

	//Main loop
	while(1)
	{
		//Get system event
		Player.Event = GetEvent();
		//Handle Events
		HandleEvent();
	}
}
示例#22
0
/*******************************************************************************
* Function Name  : MAL_Init
* Description    : Initializes the Media on the STM32
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
uint16_t MAL_Init(uint8_t lun)
{
  uint16_t status = MAL_OK;

  switch (lun)
  {
    case 0:
      Status = disk_initialize(0);/* Physical drive number (0) */
      if(Status) Status = disk_initialize(0);/*Try again on error*/
      if(!Status && !Data_Buffer) Data_Buffer=(volatile uint32_t*)malloc(MAX_DMA_BUFF_SIZE);/*Allocate the data buffer*/
      break;
#ifdef USE_STM3210E_EVAL
    case 1:
      NAND_Init();
      break;
#endif
    default:
      return MAL_FAIL;
  }
  return status;
}
示例#23
0
uint8_t OpenSD(void){
	fr = disk_initialize(SD_CARD);
	if(fr){
		//TODO:: FAZER ALGUMA COISA COM UM ERRO DE inicialização
	}
	/* Register work area for each logical drive */
	fr = f_mount(&fs, "", 0);
	if(fr){
		//TODO:: FAZER ALGUMA COISA COM UM ERRO DE mount
	}
	return fr;
}
示例#24
0
/*******************************************************************************
* Function Name  : SD_Start
* Description    : Start a Writing Session 
* Input          : File Name, Flags
* Output         : None
* Return         : "1" for Success, "0" for Failure
*******************************************************************************/
int SD_Start(char file_name[], unsigned char Flags)
{
	/* Start Card Service */
	disk_timerproc();
	ret = disk_initialize(fs.drive);
	ret = f_mount(0,&fs);
	ret = f_open(&file, (const char*) file_name, Flags);
 	if( ret == 0 )
	{
		return 1;
	}
	return 0;
}
示例#25
0
文件: main.c 项目: bearxiong99/QUAD32
FRESULT newFile() {
  char fileName[] = "data00.txt\0";
  int i = 0;

  disk_initialize(0);
  f_mount(&FatFs, "", 0);
  while (f_stat(fileName, NULL) == FR_OK) {
    i++;
    fileName[4] = i / 10 + '0';
    fileName[5] = i % 10 + '0';
  }
  return f_open(&File, fileName, FA_WRITE | FA_CREATE_ALWAYS);
}
示例#26
0
void SDMMC::run(void)
{
	// If there is a disk in the socket.
	if(!(CARD_DETECT_PINREG & _BV(CARD_DETECT_PIN)))
	{
		// If the disk in the socket has not been initialized.
		if(Stat & (STA_NOINIT))
		{
			// If there was previously no disk in the socket.
			if(Stat & STA_NODISK)
			{
				/*Do nothing. With the setting of STA_NODISK below and the scheduling
				 * of the next run in 100ms, this will effectively provide a debouncing
				 * delay.*/

				Stat &= ~STA_NODISK; // Indicate the presence of disk in the socket.
				VERBOSE_PRINTLN_P("Disk detected");
			}
			// If there is a disk and it has been debounced, initialize it.
			else if(!disk_initialize())
			{
				// STA_NOINIT was cleared in disk_initialized because it succeeded.

				f_mount(0, &fatfs); // Mounts the disk.
				VERBOSE_PRINTLN_P("Disk initialized");

			}
			else
			{
				// Initialization will be attempted again in 100ms if it failed.
				ERROR_PRINTLN_P("Disk fail");
			}
		}

		schedule(100); // Run again in 100 ms.
	}
	else //If there is no disk in the socket
	{
		if(!(Stat & STA_NOINIT)) //If a disk has been initialized
		{
			VERBOSE_PRINTLN_P("Disk removed");
			f_mount(0, NULL); // Unmount the disk.
			power_off(); //Power it off.
		}

		// Indicate there is no disk and it has not been initialized.
		Stat = STA_NODISK + STA_NOINIT;

		schedule(1000); // Check again for the presence of a disk in 1 second.
	}
}
示例#27
0
void record_init()
{
	
	uint16_t num=0;
	int8_t i;
	NVIC_InitTypeDef NVIC_InitStructure;

  /* Configure the NVIC Preemption Priority Bits */
 // NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

  NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  NVIC_InitStructure.NVIC_IRQChannel = SD_SDIO_DMA_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_Init(&NVIC_InitStructure);  
	
	
	disk_initialize(0);
	res=f_mount(0, &fs[0]);

	res=f_open(&fsrc, "0:/num.txt",FA_OPEN_EXISTING | FA_READ | FA_WRITE);  //  以读方式打开,如果文件不存在则打开失败
	
	if ( res == FR_OK )
  { 

		res=f_read(&fsrc, read_Buff, sizeof(read_Buff), &br);
		for (i=0;i<br;i++)
		{
			num=num*10+(read_Buff[i]-0x30);
		}
		if (num>=99)
			num=0;


		sprintf(record_num,"%d",num+1);
		f_lseek(&fsrc,0);
		f_puts (record_num,&fsrc);
		f_truncate(&fsrc);		
    f_close(&fsrc);  
		
		sprintf(record_file_name,"0:/N%d.txt",num+1);
		f_open(&file, record_file_name,FA_CREATE_NEW| FA_WRITE);  //  以读方式打开,如果文件不存在则打开失败
		f_close(&file);  
  }
	else
		f_close(&fsrc);	                                      /* 关闭打开的文件 */	
	
}
示例#28
0
文件: SDcard.cpp 项目: markusk/direcs
uint8_t SDcard::mount(void)
{
  if(disk_initialize(0) & STA_NOINIT)
  {
    return 1;
  }

  if(f_mount(0, &fatfs) == FR_OK)
  {
    return 0;
  }

  return 2;
}
示例#29
0
文件: main.c 项目: Teknoman117/avr
int main ( void ) {
	initADC();
	init_stdusart0( BAUD, DB8 | P_N | SB1 );
	init_timer0_ctc( T0_PRESCALER_1024, PIN_DISCONNECT, PIN_DISCONNECT );// initalize timer 0 in ctc mode with a 1024 prescale
	DDRD |= (1 << PORTD4) | (1 << PORTD5);                              //set status LED pins to outputs
	set_ocr0a( 108 );                                                    // compare match every 156 ticks, producing 10ms interrupts
	enable_interrupt_t0a();                                             //enable interrupt on timer0 channel A          
	static FATFS FATFS_Obj;                                             //file system descriptor
	disk_timerproc();                                                   //produce a base timer clock
	FIL logfile;       													//file descriptor for datalogging file
	FILINFO info;                                                       //file info structure
	DSTATUS status = disk_initialize(0);                                //initalize the SD card
	if( status & STA_NOINIT ) {                                         //check for an error
		printf( "Disk Error\n\r" );
		PORTD |= (1 << PORTD4);                                         //Set LED to Error
		PORTD &= ~(1 << PORTD5);
		while (1);
	}
	PORTD |= (1 << PORTD5);                                             //set LED to Success
	PORTD &= ~(1 << PORTD4);
	f_mount(0, &FATFS_Obj);                                             //mount the filesystem
	double vout = 0.0;
	unsigned photo = 0, therm = 0, in = 0;
	while(1) {
		_delay_ms(5000);             //delay 5 seconds
		PORTD |= (1 << PORTD4);      //turn on the writing status
		int res = f_stat( "/avr/datalog.txt", &info );    //find the length of the datalog file
		if(f_open(&logfile, "/avr/datalog.txt", FA_OPEN_ALWAYS | FA_WRITE) != FR_OK) { //open the datalog and create anew ifnot present
			printf("System Error"); 
			PORTD |= (1 << PORTD4);                        //Set LED to Error
			PORTD &= ~(1 << PORTD5);	
			while(1);
        }		
		if(res == FR_OK) f_lseek( &logfile, info.fsize ); //If the file existed seek to the end
		in = getADC(0);                                   //Log the values
		vout = 3.3 * (in/1023.0);
		photo = (vout*10000.0)/(3.3-vout);
		printf( "Photo: %u ohms(%u raw) ", photo, in );
		f_printf( &logfile, "Photo: %u ohms(%u raw) ", photo, in );
		in = getADC(1);
		vout = 3.3 * (in/1023.0);
		therm = (vout*10000.0)/(3.3-vout);
		printf( "Therm: %u ohms(%u raw) \r\n", therm, in );
		f_printf( &logfile, "Therm: %u ohms(%u raw)\n", therm, in );
		f_close( &logfile );       //close the file
		PORTD &= ~(1 << PORTD4);   //off with the writing status
	}
	return 0;
}
示例#30
0
/**
 * @function main
 * @brief entry point
 * @param none
 * @return dummy
 */
int32_t main(void) {

  timer_t tmInit;

  UcInit();       /*uc init; shall be the first one*/
  TicksInit();    /*software clock init*/
  LCD_Init();     /*start the ILI932X*/

  /* start a timer; backlight will be turned on once this timer will elapse
   * -> this avoids a white flash*/
  tmInit = GetTimeout(120);

  P2D_Init();
  GUI_Init();
  TouchScreenCalib(NULL);
  TouchScreenEnable();

  /*mount the file system*/
  disk_initialize(0);
  f_mount(0, &Fatfs);

  /* wait the 120ms timeout */
  while(IsTimerElapsed(tmInit) == false) DelayMs(1);
  BacklightInit();

  /*set the main task*/
  pCurrentTask = &SetupTask;

  /*main loop*/
  while(1) {

    /*execute the main task, if any*/
    if(pCurrentTask != NULL) pCurrentTask();

    /*GUI task*/
    GUI_DrawObjects();
    GUI_DBG_Task();

    /*software RTC task*/
    RtcTask();

    /*CPU limiter; reduces the power consumption*/
    DelayMs(1);
  }

  /*never arrive here*/
  return -1;
}