Exemple #1
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;
}
Exemple #2
0
unsigned int fs_items(const char *path)
{
  FILINFO finfo;
  DIR dir;
  unsigned int i=0;

#if _USE_LFN
  finfo.lfname = lfn;
  finfo.lfsize = sizeof(lfn);
#endif

  if(disk_status(0) & STA_NOINIT)
  {
    return 0;
  }

  if(f_opendir(&dir, path) == FR_OK)
  {
    while((f_readdir(&dir, &finfo) == FR_OK) && finfo.fname[0])
    {
      if(fs_checkitem(&finfo) == 0)
      {
        i++;
      }
    }
  }

  return i;
}
Exemple #3
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;
	}
}
Exemple #4
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;
}
Exemple #5
0
void USBMSD::memoryWrite (uint8_t * buf, uint16_t size) {

    if ((addr + size) > MemorySize) {
        size = MemorySize - addr;
        stage = ERROR;
        stallEndpoint(EPBULK_OUT);
    }

    // we fill an array in RAM of 1 block before writing it in memory
    for (int i = 0; i < size; i++)
        page[addr%BlockSize + i] = buf[i];

    // if the array is filled, write it in memory
    if (!((addr + size)%BlockSize)) {
        if (!(disk_status() & WRITE_PROTECT)) {
            disk_write(page, addr/BlockSize);
        }
    }

    addr += size;
    length -= size;
    csw.DataResidue -= size;

    if ((!length) || (stage != PROCESS_CBW)) {
        csw.Status = (stage == ERROR) ? CSW_FAILED : CSW_PASSED;
        sendCSW();
    }
}
/*-----------------------------------------------------------------------*/
DSTATUS
disk_initialize (
        BYTE drv		/* Physical drive number */
        )
{	
    return (disk_status (drv));
}
Exemple #7
0
DRESULT disk_ioctl (
	BYTE drv,		/* Physical drive nmuber (0) */
	BYTE ctrl,		/* Control code */
	void *buff		/* Buffer to send/receive control data */
)
{
	DRESULT res;
	// BYTE n, csd[16];
	// DWORD cs;


	if (disk_status(drv) & STA_NOINIT) return RES_NOTRDY;	/* Check if card is in the socket */

	res = RES_ERROR;
	switch (ctrl) {
		case CTRL_SYNC :		/* Make sure that no pending write process */
			// if (select()) res = RES_OK;
                        res = RES_OK;
			break;

		case GET_SECTOR_COUNT :	/* Get number of sectors on the disk (DWORD) */
                    /*
			if ((send_cmd(CMD9, 0) == 0) && rcvr_datablock(csd, 16)) {
				if ((csd[0] >> 6) == 1) {	// SDC ver 2.00 
					cs = csd[9] + ((WORD)csd[8] << 8) + ((DWORD)(csd[7] & 63) << 16) + 1;
					*(DWORD*)buff = cs << 10;
				} else {					// SDC ver 1.XX or MMC 
					n = (csd[5] & 15) + ((csd[10] & 128) >> 7) + ((csd[9] & 3) << 1) + 2;
					cs = (csd[8] >> 6) + ((WORD)csd[7] << 2) + ((WORD)(csd[6] & 3) << 10) + 1;
					*(DWORD*)buff = cs << (n - 9);
				}
				res = RES_OK;
			}
                     */
                                *(DWORD*)buff = 1000;
                                res = RES_OK;
			break;

		case GET_BLOCK_SIZE :	/* Get erase block size in unit of sector (DWORD) */
			*(DWORD*)buff = 1;
			res = RES_OK;
			break;
                        
                case GET_SECTOR_SIZE :
                        *(DWORD*)buff = 512;
                        res = RES_OK;
                    break;
                    
                case CTRL_ERASE_SECTOR :
                        res = RES_OK;
                    break;

		default:
			res = RES_PARERR;
	}


	return res;
}
Exemple #8
0
void OnGetDiskStatus(nwazetMessageContext_t* nmc){
  uint8_t res = (uint8_t) FR_OK;
  uint8_t status = disk_status(fs.drv);
  InitializeSendBuffer(nmc->respContext, nmc->responseBuffer, nmc->responseBufferSize);
  Put(nmc->respContext, (void*)&res, sizeof(res), 1);
  Put(nmc->respContext, (void*)&status, sizeof(status), 1);
  FinalizeSendBuffer(nmc->respContext);
}
DSTATUS disk_initialize (BYTE pdrv)
{
    assert(pdrv == 0);
    if (disk_memory == NULL) {
        disk_memory = malloc(SECTOR_COUNT * SECTOR_SIZE);
    }
    return disk_status(pdrv);
}
/**
 *	Initializes the hardware/software SD card module. If the SD card is not 
 *	inserted, loops waiting to mount it until the SD ready is ready.
 *
 *	\param int pin_sck - pin used as SPI SCLK signal
 *	\param int pin_si  - pin used as SPI MISO signal
 *	\param int pin_so  - pin used as SPI MOSI  signal
 *	\param int pin_cs  - pin used as SD Chip Select signal
 *	\param int pin_cd  - pin used as SD Card Detect signal
 *	\param BYTE _nTimeout - timeout of operation (expressed in about 0.1 sec scale, 255 to wait forever)
 *	\return
 *	BOOL result of operation
 */	
BOOL SDInit(int pin_sck, int pin_si, int pin_so, int pin_cs, int pin_cd, BYTE timeout)
{
	BYTE timecnt = 0;
	//	SD hardware initialization
	pinConfig(pin_sck, pin_si, pin_so, pin_cs, pin_cd);
			
	SDdebug("Initializing SD card...\r\n");

	if (diskMount())
		SDdebug("SD software module initialized!\r\n");
	else
		SDdebug("SD software module NOT initialized!\r\n");
		
	// Check to detect SD card insertion
	while (disk_status(0))
	{
		diskUnmount();
		vTaskDelay(5);
		SDdebug(".");
		diskMount();
		timecnt++;
		if ( (timecnt == timeout) && (timeout < 255) )
			break;
		vTaskDelay(5);
	}
	
	if (!disk_status(0))
	{
		SDdebug("SD card initialized and ready!\r\n");
		setSdErr(0);
		fileInit();
		sdInitOk = TRUE;
		return TRUE;
	}
	else 
	{
		SDdebug("ERROR\n");
		if (sdDetect())
			setSdErr(SD_FS_NOT_INIT);
		else
			setSdErr(SD_NOT_PRESENT);
		sdInitOk = FALSE;
		return FALSE;
	}
}
Exemple #11
0
void fs_mount(void)
{
  unsigned int mount_try=3;

  if(disk_status(0) & STA_NOINIT)
  {
    DEBUGOUT("MMC: init\n");
    while((disk_initialize(0) & STA_NOINIT) && --mount_try);
  }

  DEBUGOUT("MMC: mount\n");

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

  return;
}
Exemple #12
0
DRESULT disk_write (
	BYTE drv,			/* Physical drive nmuber (0) */
	const BYTE *buff,	/* Pointer to the data to be written */
	DWORD sector,		/* Start sector number (LBA) */
	BYTE count			/* Sector count (1..128) */
)
{
	DSTATUS s;


	s = disk_status(drv);
	if (s & STA_NOINIT) return RES_NOTRDY;
	if (s & STA_PROTECT) return RES_WRPRT;
	if (!count) return RES_PARERR;

//	if (!(CardType & CT_BLOCK)) sector *= 512;	/* Convert LBA to byte address if needed */
//
//
//	if (count == 1) {	/* Single block write */
//		if ((send_cmd(CMD24, sector) == 0)	/* WRITE_BLOCK */
//			&& xmit_datablock(buff, 0xFE))
//			count = 0;
//	}
//	else {				/* Multiple block write */
//		if (CardType & CT_SDC) send_cmd(ACMD23, count);
//		if (send_cmd(CMD25, sector) == 0) {	/* WRITE_MULTIPLE_BLOCK */
//			do {
//				if (!xmit_datablock(buff, 0xFC)) break;
//				buff += 512;
//			} while (--count);
//			if (!xmit_datablock(0, 0xFD))	/* STOP_TRAN token */
//				count = 1;
//		}
//	}
//	deselect();

	FILE *fp;

		sector = (sector * 512) ;

		if( ( fp = fopen( "./Disk_Image/virtualfs","rb+")) == NULL) {
		       puts("Cannot open the file");
		       return ( 0 );
		   }

		fseek (fp,sector,SEEK_SET);
		fwrite(buff, 512, count, fp);
		 count = 0;

		fclose(fp);

	return count ? RES_ERROR : RES_OK;
}
Exemple #13
0
DRESULT disk_read (
	BYTE drv,			/* Physical drive nmuber (0) */
	BYTE *buff,			/* Pointer to the data buffer to store read data */
	DWORD sector,		/* Start sector number (LBA) */
	BYTE count			/* Sector count (1..128) */
)
{
	DSTATUS s;


	s = disk_status(drv);
	if (s & STA_NOINIT) return RES_NOTRDY;
	if (!count) return RES_PARERR;


	FILE *fp;

		sector = (sector * 512) ;

		if( ( fp = fopen( "./Disk_Image/virtualfs", "r")) == NULL) {
		       puts("Cannot open the file");
		       return ( 0 );
		   }

		fseek (fp,sector,SEEK_SET);
		 fread(buff, 512, count, fp);
		 count = 0;

		fclose(fp);

//
//	if (!(CardType & CT_BLOCK)) sector *= 512;	/* Convert LBA to byte address if needed */
//
//	if (count == 1) {	/* Single block read */
//		if ((send_cmd(CMD17, sector) == 0)	/* READ_SINGLE_BLOCK */
//			&& rcvr_datablock(buff, 512))
//			count = 0;
//	}
//	else {				/* Multiple block read */
//		if (send_cmd(CMD18, sector) == 0) {	/* READ_MULTIPLE_BLOCK */
//			do {
//				if (!rcvr_datablock(buff, 512)) break;
//				buff += 512;
//			} while (--count);
//			send_cmd(CMD12, 0);				/* STOP_TRANSMISSION */
//		}
//	}
//	deselect();

	return count ? RES_ERROR : RES_OK;
}
Exemple #14
0
DSTATUS disk_initialize(BYTE drv)
{
    T_uezError error;
    DEVICE_MassStorage **p_ms;

    IEnsureInit();
	p_ms = G_fatfsMassStorageDevices[drv];
    if (p_ms) {
        error = (*p_ms)->Init(p_ms, 0);
        if (error == UEZ_ERROR_NONE) {
            return disk_status(drv);
        } else {
            return STA_NOINIT;
        }
    }

    return STA_NOINIT;
}
DRESULT disk_ioctl (
		BYTE drv,		/* Physical drive nmuber (0) */
		BYTE ctrl,		/* Control code */
		void *buff		/* Buffer to send/receive control data */
		)
{
    CyU3PReturnStatus_t status;
    CyU3PSibLunInfo_t   unitInfo;
    DRESULT res;

    disk_status (drv);
    if ((Stat[drv] == STA_NOINIT) || (Stat[drv] == STA_NODISK))
        return RES_NOTRDY;

    res = RES_ERROR;
    switch (ctrl) {
        case CTRL_SYNC :		/* Make sure that no pending write process */
            CyU3PSibCommitReadWrite ((uint8_t)drv);
            res = RES_OK;
            break;

        case GET_SECTOR_COUNT :	/* Get number of sectors on the disk (DWORD) */
            /* Query the 0th volume on the storage device to find the capacity. */
            status = CyU3PSibQueryUnit ((uint8_t)drv, 0, &unitInfo);
            if ((status != CY_U3P_SUCCESS) || (unitInfo.valid == 0))
                return RES_ERROR;

            *(DWORD *)buff = unitInfo.numBlocks;
            res = RES_OK;
            break;

        case GET_BLOCK_SIZE :	/* Get erase block size in unit of sector (DWORD) */
            *(DWORD*)buff = 128;
            res = RES_OK;
            break;

        default:
            res = RES_PARERR;
    }

    return res;
}
Exemple #16
0
DRESULT disk_ioctl (
	BYTE drv,		/* Physical drive nmuber (0) */
	BYTE ctrl,		/* Control code */
	void *buff		/* Buffer to send/receive control data */
)
{
	DRESULT res;
	BYTE n, csd[16];
	WORD cs;


	if (disk_status(drv) & STA_NOINIT)					/* Check if card is in the socket */
		return RES_NOTRDY;

	res = RES_ERROR;
	switch (ctrl) {
		case CTRL_SYNC :		/* Make sure that no pending write process */
				res = RES_OK;
			break;

		case GET_SECTOR_COUNT :	/* Get number of sectors on the disk (DWORD) */
				res = RES_PARERR;
				//res = RES_OK;
			break;

		case GET_BLOCK_SIZE :	/* Get erase block size in unit of sector (DWORD) */
			*(DWORD*)buff = 128;
			res = RES_OK;
			break;

		default:
			res = RES_PARERR;
	}

	deselect();

	return res;
}
Exemple #17
0
  int hal_io_input(int port) {
    static uint8_t character = 0;

    switch (port) {
      case 0x00:
        return 0;
      case 0x01: //serial read
        return term_in();
      case 0x08: 
        return disk_status();
      case 0x09:
        return disk_sector();
      case 0x0a: 
        return disk_read();
      case 0x10: //2SIO port 1 status
        if (!character) {
          // printf("2SIO port 1 status\n");
          character = term_in();
        }
        return (character ? 0b11 : 0b10); 
      case 0x11: //2SIO port 1, read
        if (character) {
          int tmp = character; 
          character = 0; 
          return tmp; 
        } else {
          return term_in();
        }
      case 0xff: //sense switches
        return 0;
      default:
        printf("%04x: in 0x%02x\n",i8080_pc(),port);
        exit(1);
        return 1;
    }
    return 1;
  }
Exemple #18
0
int main(void)
{
	static DWORD per_sec = 0;
	InitializeBoard();													// Initialize application specific hardware
	PowerONGSM(TRUE);
	Initialization();		

	//................File System Initialisation...................//
	
	while(disk_status(MMC_DRIVE));     //Wait untill SD card is inserted											
	if(!(disk_status(MMC_DRIVE) ))//& STA_NODISK))					//if SD card is inserted	
	{
		// disk inserted so initialise it
		if (disk_initialize(MMC_DRIVE) == 0) 							//if SD card initialize
		{
			if (f_mount(MMC_DRIVE, &fatfs[MMC_DRIVE]) == FR_OK) 
			{
				uc_Flag_SDInit = TRUE;	  //succefully initialise sd card							//if file system initialize properly
			}
			else
			{
				Reset();
			}
		}
		else
		{
			Reset();
		}
	}
	InitConnection();														//functional initialization gateway device sensors,etc	
	while(1)
	{
		ClrWdt();
		if(ReadADC==TRUE)
		{
			Sample_Flag++;
			ReadADC=FALSE;
			ADC_Read_Value=AnalogData*3.3/1024;
			Toatal_Value=Toatal_Value+ADC_Read_Value;
			if(ADC_Read_Value<min)
			{
				min=ADC_Read_Value;
			}
			else if(ADC_Read_Value>max)
			{
				max=ADC_Read_Value;
			}
			
		}
		if((Sample_Flag>=600) && (uc_HTTP_DONE==TRUE))
		{
			heartbeat++;
			value=Toatal_Value/Sample_Flag;
			if(uc_GPRS_Done==FALSE)
			{
				GPRSFailed++;
			}
			uc_GPRS_Done=FALSE;
		
			Sample_Flag=0;
			min=0;
			max=0;
			Toatal_Value=0;
			sendData=TRUE;
			POST_DATA=SEND_DATA;
			uc_HTTP_DONE=FALSE;	
		}
		if(sendData==TRUE)
		{
		
			switch(POST_DATA)
			{
				case GATE_HEARTBEAT:
				{
					if(url_build==FALSE)
					{
						Transmit_Gateway_Heartbeat();
						url_build=TRUE;
						uc_GPRS_Done=FALSE;
					}	
					SendURL((METHOD) POST);	
					if(uc_GPRS_Done==TRUE)
					{
						POST_DATA=SENS_HEARTBEAT;
						url_build=FALSE;
					}
					break;
				}
				
				case SENS_HEARTBEAT:
				{
					if(url_build==FALSE)
					{
						Transmit_Sensor_Heartbeat();
						url_build=TRUE;
						uc_GPRS_Done=FALSE;
					}	
					SendURL((METHOD) POST);	
					if(uc_GPRS_Done==TRUE)
					{
						url_build=FALSE;
						sendData=FALSE;
						uc_HTTP_DONE=TRUE;
						POST_DATA=10;
					}
					break;
				}
				case SEND_DATA:
				{
					if(url_build==FALSE)
					{
						Transmit_Analog_Data(value);
						url_build=TRUE;
						uc_GPRS_Done=FALSE;
						
						//	GetTimeStamp();
						//time=t_day;
					}	
					SendURL((METHOD)POST);	
					if(uc_GPRS_Done==TRUE)
					{
						if(heartbeat>=5)
						{
							heartbeat=0;
							POST_DATA=GATE_HEARTBEAT;
							url_build=FALSE;
						}
						else
						{
							POST_DATA=10;
							url_build=FALSE;
							sendData=FALSE;
							uc_HTTP_DONE=TRUE;
							//	GetTimeStamp();
							//time1=t_day;
							asm("NOP");
						}
					
					}
					break;
				}
				default:
				break;
			}
		}
		if(TickGet() - per_sec >= TICK_SECOND/2ul)								// Blink LED0 (right most one) every half second.
		{
			per_sec = TickGet();
			LED4_IO ^= 1;													//internal heartbit LED
			HRTBIT_LED_IO ^=1; 											//pannel heartbit LED
	
		}
		if((uc_GSMRestart==TRUE) || ((uc_GPRSFailed == TRUE) && (uc_GPRSTried == TRUE)))
		{
			PowerONGSM(FALSE);
			DelayMs(200);
			uc_GSMRestart=3;	
			PowerONGSM(TRUE);
			uc_GPRSFailed=FALSE;
			uc_GPRSTried=FALSE;
		}
	}
}
Exemple #19
0
int32_t main(void)
{
    FRESULT res;
    UINT s2, cnt;
    uint32_t i;

    /* Unlock protected registers */
    SYS_UnlockReg();

    /* Init System, IP clock and multi-function I/O */
    SYS_Init(); //In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register.

    /* Lock protected registers */
    SYS_LockReg();

    /* Init UART0 for printf */
    UART0_Init();
    
    /* Init USB host and prepare a root hub*/
    USBH_Open();

    /* Set USB host to support USB mass storage device*/
    USBH_MassInit();

    /*Delay for power stable*/
    Delay(0x500000);
  
    printf("+-----------------------------------------------+\n");
    printf("|                                               |\n");
    printf("|  M451 USB Host Mass Storage sample program    |\n");
    printf("|                                               |\n");
    printf("+-----------------------------------------------+\n");

    printf("OTG->PHYCTL = 0x%x\n", OTG->PHYCTL);
    printf("OTG->STS = 0x%x\n", OTG->STATUS);
    printf("OTG->CTL = 0x%x\n", OTG->CTL);

    while(1)
    {
        USBH_ProcessHubEvents();//Process hub events that include resume, suspense, plug-in, unplug and so on.
        Delay(0x500000); 
        
        if(disk_status(0)&&u8Disk) //Check mass storage device status
        {
            put_rc(f_mount(0, NULL));//No disk
      u8Disk = 0;
      printf("\n======= No disk found =======\n\n");
        }
        
        if((disk_status(0)==0)&&(u8Disk==0))
        {
            put_rc(f_mount(0, &FatFs[0]));//disk found
            u8Disk = 1;
            printf("\n======= Disk found =======\n");

#ifdef DiskTest
            putchar('\n');
            res = f_open(&file1, (TCHAR*)"Test.txt", FA_OPEN_EXISTING | FA_READ);// Open "Test.txt" file for read operation
            if(res)//Check the result of FatFs function
            {//Fail --> Maybe connection fail or Not find "Text.txt" file
                
                put_rc(res);//Print fail message

                res = f_open(&file1, (TCHAR*)"Test.txt", FA_CREATE_ALWAYS | FA_WRITE);// Open "Test.txt" file for write operation
                if(res)
          {//Fail
                    put_rc(res);//Print fail message
                }
                else
                {//Pass
                    cnt = 512;//Set data lenght
                    for(i=0;i<cnt;i++)
                        Buff[i] = i;//Prepare data for write

                    res = f_write(&file1, Buff, cnt, &s2);//Write data into file.
                    if(res != FR_OK)
                    {//Fail
                        put_rc(res);//Print fail message
                    }
                    f_close(&file1);//Close "Test.txt" file
                    printf("\nData lenght:%d\n",s2);//Print how many wrote data 
                }
            }
            else
            {//Pass
                cnt = 512;//Set data lenght
                res = f_read(&file1, Buff, cnt, &s2);//Read data from file. 
                if(res != FR_OK)
                {//Fail
                    put_rc(res);//Print fail message
                }
                else
                {//Pass
                    printf("Data size:%d\n",s2);//Print how many read data
                    for(i=0;i<s2;i++)
                    {
                        if((i%8) == 0 )
                            printf("\n");
                        printf("0x%2x ",Buff[i]);//Print read data
                    }
                }
                f_close(&file1);//Close "Test.txt" file  
                printf("\n\nData lenght:%d\n",s2);//Print how many wrote data   
                printf("Test finish.\n");//Print how many wrote data              
            } 
#endif                    
        }
    }
}
Exemple #20
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  bool     redraw, firstRun;
  FRESULT  res;
  int      mountStatus;
  /* Used when iterating through directory */
  FILINFO Finfo;
  DIR     dir;
  FRESULT listDirStatus = FR_OK;
  /* Used for manifest operation */
  bool useManifest = false;
  char buffer[20];

  /* Use 32MHZ HFXO as core clock frequency */
  CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);

  /* Initialize DK board register access */
  BSP_Init(BSP_INIT_DEFAULT);

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  /* Setup SysTick Timer for 10 msec interrupts  */
  if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 100))
  {
    while (1) ;
  }

  /* Enable SPI access to MicroSD card */
  BSP_PeripheralAccess(BSP_MICROSD, true);

  /* Initialize filesystem */
  mountStatus = initFatFS();

  /* Open Manifest file. If a manifest file is not present, iterate through the
   * File system in filesystem order. */
  if (f_open(&manifest, "files.txt", FA_READ) == FR_OK)
    useManifest = true;

  firstRun = true;
  /* Update TFT display forever */
  while (1)
  {
    if (!useManifest)
    {
      /* Open root directory */
      strcpy(path, "");
      listDirStatus = f_opendir(&dir, path);
    }
    /* Iterate through files */
    while (1)
    {
      /* Check if we should control TFT display instead of
       * AEM/board control application. Read state of AEM pushbutton */
      redraw = TFT_AddressMappedInit();
      if (redraw)
      {
        if ( firstRun )
        {
          firstRun = false;
          SLIDES_init();
        }

        /* Check disk status */
        if (disk_status(0) != 0)
        {
          /* Filesystem not mounted, show fatal error. */
          SLIDES_showError(true, "Fatal:\n  Filesystem is not ready.\n  (%d)", disk_status(0));
        }

        /* Check if filesystem was successfully mounted. */
        if (mountStatus != 0)
        {
          /* Filesystem not mounted, show fatal error. */
          SLIDES_showError(true, "Fatal:\n  Filesystem could not be mounted.\n  (%d)", mountStatus);
        }

        /* Is there a manifest file present? */
        if (useManifest)
        {
          /* If we are at the end of the file, reset filepointer */
          if (f_eof(&manifest))
            f_lseek(&manifest, 0);
          /* Read next file from manifest file */
          f_gets(buffer, 20, &manifest);
          /* Display Bitmap */
          SLIDES_showBMP(buffer);
        }
        else
        {
          /* Check to see if the root directory was correctly opened. */
          if (listDirStatus != FR_OK)
          {
            SLIDES_showError(true, "Fatal:\n  Could not read root directory.\n  (%d)", listDirStatus);
          }

          /* Open the next entry in directory */
          res = f_readdir(&dir, &Finfo);
          if ((res != FR_OK) || !Finfo.fname[0])
          {
            /* End of directory listing. Break out of inner loop and reopen
             * directory entry */
            break;
          }
          /* Update display */
          SLIDES_showBMP(Finfo.fname);
        }

        /* Delay to allow the user to see the BMP file. */
        Delay(200);
      }
    }
  }
}
Exemple #21
0
int partition_stat_get(partition_stat_t *stat)
{
    FILE *mnt_file     = NULL;
    struct mntent *mnt = NULL;
    struct statfs fsbuf;

    bzero(stat, sizeof(partition_stat_t));

    mnt_file = setmntent(MTAB_FILE, "r");
    if (NULL == mnt_file) {
        log_error("setmntext failed.");
        return 0;
    }

    while (NULL != (mnt = getmntent(mnt_file))) {
        if (stat->count >= MAX_PARTITIOn_COUNT) {
            log_warn("partition count >= %d.", MAX_PARTITIOn_COUNT);
            break;
        }

        if(strncmp(mnt->mnt_fsname, "/", 1)) {
            continue;
        }

        strncpy(stat->partitions[stat->count].fs_name, mnt->mnt_fsname + 5, MAX_FS_NAME_SIZE - 1);
        strncpy(stat->partitions[stat->count].mnt_dir, mnt->mnt_dir, MAX_MNT_DIR_SIZE - 1);

        if (!statfs(mnt->mnt_dir, &fsbuf)) {
            stat->partitions[stat->count].type   = fsbuf.f_type;
            stat->partitions[stat->count].bsize  = fsbuf.f_bsize;
            stat->partitions[stat->count].blocks = fsbuf.f_blocks;
            stat->partitions[stat->count].bfree  = fsbuf.f_bfree;
            stat->partitions[stat->count].bavail = fsbuf.f_bavail;
            stat->partitions[stat->count].status = disk_status(mnt->mnt_dir);
        }
        else {
            log_error("statfs for %s failed, %s.", mnt->mnt_dir); 
            stat->partitions[stat->count].status = PARTITION_STATUS_ERROR;
        }

        stat->partitions[stat->count].total_size         = (fsbuf.f_bsize/1024) * (fsbuf.f_blocks/1024); 
        stat->partitions[stat->count].nonroot_total_size = 
            (fsbuf.f_bsize/1024) * ((fsbuf.f_blocks - fsbuf.f_bfree + fsbuf.f_bavail)/1024);
        stat->partitions[stat->count].used_size          = (fsbuf.f_bsize/1024) * ((fsbuf.f_blocks - fsbuf.f_bfree)/1024);
        stat->partitions[stat->count].avail_size         = (fsbuf.f_bsize/1024) * (fsbuf.f_bavail/1024);

        if (stat->partitions[stat->count].nonroot_total_size != 0) {
            stat->partitions[stat->count].usage = 
                (float)stat->partitions[stat->count].used_size/(float)stat->partitions[stat->count].nonroot_total_size;
        }
        else {
            stat->partitions[stat->count].usage = 0;
        }

        stat->nonroot_total_size += stat->partitions[stat->count].nonroot_total_size;
        stat->total_size         += stat->partitions[stat->count].total_size;
        stat->used_size          += stat->partitions[stat->count].used_size;
        stat->avail_size         += stat->partitions[stat->count].avail_size;

        stat->count++;
    }

    stat->usage = (float)stat->used_size/(float)stat->nonroot_total_size;
    endmntent(mnt_file);

    return 1;
}
Exemple #22
0
int main(void)
{
	unsigned long ulPeriod;
	unsigned long ulDelay;

	unsigned long recvData = 11;

	volatile int status = 0;

	char buffer[40];
	unsigned int bytesdRead;

	FRESULT res;
	FIL fileobj;

	SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);

	//Initialize pins
	init_pins();

	//Initialize peripherals
	init_periph();

	I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(), false);//false for 100kHz mode
	    //0x68 is the 7-bit address of the DS1307
	I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, 0x68, false);//true for a read action
	I2CMasterDataPut(I2C0_MASTER_BASE, 0x10);      //first Date/Time Register
	I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND);
	while(I2CMasterBusy(I2C0_MASTER_BASE)){}
	I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
	while(I2CMasterBusy(I2C0_MASTER_BASE)){}
	recvData = I2CMasterDataGet(I2C0_MASTER_BASE);
	while(I2CMasterBusy(I2C0_MASTER_BASE)){}

	fs_mount();

	if(disk_status(0) == 0)
	{
		status++;
	}
	else
	{
	    status--;
	}

	if (status == 1) {
		res = f_open(&fileobj, "config.txt", FA_OPEN_EXISTING | FA_READ);
		res = f_read(&fileobj, buffer, 6, &bytesdRead);
	}

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

	GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0);

	ulPeriod = SysCtlClockGet() / 10;
	ulDelay = ((ulPeriod / 2) / 3) - 4 ;

	while(1)
	{
		// Turn on the LED
		GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, 0x01);

		// Delay for a bit
		SysCtlDelay(ulDelay);

		// Turn off the LED
		GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0, 0x00);

		// Delay for a bit
		SysCtlDelay(ulDelay);
	}
}
Exemple #23
0
Fichier : DF.C Projet : FDOS/defrag
int main(int argc, char **argv)
{
int fd,i;
char *buffer;
size_t bufsz;
int tracks,sectors,heads;

#if defined __WATCOMC__ || defined __GNUC__
    setvbuf(stdout,NULL,_IONBF,0);      /* flush stdout every printf */
#endif

    Reset = 0;
    Zero = 0;
    Keep = 0;
    Last = 0;
    Verify = 0;
    MaxTrack = MaxHead = -1;
    Bytes = 0;
    Disk = File = ToDisk = -1;
    SysOnly = 0;
    NoAsk = 0;

    options(argc,argv);

    if ((i = disk_get_physical(Disk,&tracks,&sectors,&heads)) != DISK_OK)
        die("BIOS error: ",disk_error(i),0);

    if ((buffer = malloc(bufsz = sectors * 512)) == NULL)
        die("Not enough memory found!"," (%u)",bufsz);

    printf("\n");

    if (Reset)
    {
        printf("Reseting controller...");
        disk_reset(Disk);
        printf(" Homing disk...");
        if ((i = disk_read_p(Disk,0,1,0,buffer,1)) != DISK_OK)
            die("BIOS error: ",disk_error(i),0);
        printf(" OK.\n");
    }

    printf("Drive %c: has %u tracks and %u sides.\n",Disk+'A',tracks+1,heads+1);

    if (Last)
        setlast(Disk,&MaxTrack,&MaxHead,0);

    if (SysOnly)
        setlast(Disk,&MaxTrack,&MaxHead,1);

    if (ToDisk == 1)
        printf("\nWrite file \"%s\" to disk in %c:",argv[File],Disk+'A');
    else
        printf("\nWrite disk in %c: to file \"%s\"",Disk+'A',argv[File]);

    if (!NoAsk && ask(NULL) == 0)
        return 1;

    if (ToDisk == 2)                                     /* writing file */
    {
        if ((fd = _open(argv[File],_O_RDONLY)) != -1)
        {
            _close(fd);
            printf("File \"%s\" exists",argv[File]);
            if (ask("; overwrite?") == 0)
                return 1;
        }
        fd = _open(argv[File],O_CREAT|O_RDWR|O_BINARY|O_TRUNC,S_IREAD|S_IWRITE);
    }
    else
    {
        fd = _open(argv[File],O_RDWR|O_BINARY);
    }

    if (fd == -1)
        die("file error: ",strerror(errno),errno);

    errno = 0;

    putchar('\n');

    /* on error we get back here with setjmp() returning non-zero */

    if (setjmp(Jmpbuf) == 0)
    {
        /* now that everything is verified and prepared, this is the meat */

        if (ToDisk == 1)
            i = file2disk(fd,Disk,tracks,heads,sectors,bufsz,buffer);
        else
            i = disk2file(fd,Disk,tracks,heads,sectors,bufsz,buffer);

        if (i == DISK_OK)
            printf("\nDone.            \n");

        /* that's not hard is it... */
    }
    else
    {
        puts("\n\nStopped.             \n");
        getch();    /* eat key from kbhit() */
    }

    _close(fd);

#ifdef _WIN32
    if (i)
#else
    if ((i = disk_status(Disk)) != 0)
#endif
        die("BIOS error: ",disk_error(i),0);

    if (errno)
        die("File error: ",strerror(errno),errno);

    if (Reset)
    {
        printf("\nReseting controller...");
        disk_reset(Disk);
        printf(" Homing disk...\n");
        disk_read_p(Disk,0,1,0,buffer,1);
    }

    printf("\n%ld bytes written\n",Bytes);

    return 0;

}
Exemple #24
0
DSTATUS disk_initialize(BYTE pdrv)
{
    return disk_status(pdrv);
}
Exemple #25
0
DSTATUS disk_initialize (
	BYTE drv				/* Physical drive nmuber (0..) */
)
{
	return disk_status(drv);
}