Beispiel #1
0
/*
 * fs_stm32_init
 * This function is responsible for initializing file systems for STM32.
 */
void fs_stm32_init(void)
{
#if (defined(FS_FAT) && defined(CONFIG_MMC))
    char mount_point[4] = "0:\\";

#ifdef MMC_SPI_FS
    /* Register MMC device with file system */
    mmc_spi_fsregister(&mmc_spi, "\\mmc0");
#endif /* MMC_SPI_FS */

    /* Initialize SPI device data. */
    mmc_spi_stm32.device_num = 2;

    /* Hook-up SPI interface. */
    mmc_spi.spi.baudrate = 21000000;
    mmc_spi.spi.cfg_flags = (SPI_CFG_MASTER | SPI_CFG_CLK_IDLE_HIGH);
    mmc_spi.spi.data = &mmc_spi_stm32;
    mmc_spi.spi.init = &spi_stm32f103_init;
    mmc_spi.spi.slave_select = &spi_stm32f103_slave_select;
    mmc_spi.spi.slave_unselect = &spi_stm32f103_slave_unselect;
    mmc_spi.spi.msg = &spi_stm32f103_message;

    /* Register this device with FatFile system. */
    disk_register(&mmc_spi, &mmc_spi_init, &mmc_spi_read, &mmc_spi_write, MMC_SPI_SECTOR_SIZE, 0);

    /* Mount this drive later. */
    f_mount(&fat_fs, mount_point, 0);
#endif /* (defined(FS_FAT) && defined(CONFIG_MMC)) */

} /* fs_avr_init */
Beispiel #2
0
static rtems_task Init(rtems_task_argument argument)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;
  rtems_bdbuf_buffer *bd = NULL;
  dev_t dev = 0;
  rtems_disk_device *dd = NULL;

  printk("\n\n*** TEST BLOCK 9 ***\n");

  sc = rtems_disk_io_initialize();
  ASSERT_SC(sc);

  sc = disk_register(BLOCK_SIZE, BLOCK_COUNT, &dev);
  ASSERT_SC(sc);

  dd = rtems_disk_obtain(dev);
  assert(dd != NULL);

  check_read(dd, BLOCK_READ_IO_ERROR, RTEMS_IO_ERROR);
  check_read(dd, BLOCK_READ_UNSATISFIED, RTEMS_UNSATISFIED);
  check_read(dd, BLOCK_READ_SUCCESSFUL, RTEMS_SUCCESSFUL);
  check_read(dd, BLOCK_WRITE_IO_ERROR, RTEMS_SUCCESSFUL);

  /* Check write IO error */

  sc = rtems_bdbuf_read(dd, BLOCK_WRITE_IO_ERROR, &bd);
  ASSERT_SC(sc);

  bd->buffer [0] = 1;

  sc = rtems_bdbuf_sync(bd);
  ASSERT_SC(sc);

  sc = rtems_bdbuf_read(dd, BLOCK_WRITE_IO_ERROR, &bd);
  ASSERT_SC(sc);

  assert(bd->buffer [0] == 0);

  sc = rtems_bdbuf_release(bd);
  ASSERT_SC(sc);

  /* Check write to deleted disk */

  sc = rtems_bdbuf_read(dd, BLOCK_READ_SUCCESSFUL, &bd);
  ASSERT_SC(sc);

  sc = rtems_disk_delete(dev);
  ASSERT_SC(sc);

  sc = rtems_bdbuf_sync(bd);
  ASSERT_SC(sc);

  sc = rtems_disk_release(dd);
  ASSERT_SC(sc);

  printk("*** END OF TEST BLOCK 9 ***\n");

  exit(0);
}
Beispiel #3
0
/*
 * ======== ramdisk_start ========
 *
 */
DRESULT ramdisk_start(BYTE drive, unsigned char *data, int numBytes, int mkfs)
{
    DRESULT result;

    /* ensure 'drive' is a valid index */
    if (drive >= _VOLUMES) {
        return RES_PARERR;
    }

    /* ensure this volume isn't already in use */
    if (diskMem[drive] != NULL) {
        return RES_PARERR;
    }

    /*
     *  Register the ramdisk functions with the diskio module.  FatFS will
     *  call these via the diskio function table.
     */
    if ((result = disk_register(drive, ramdisk_init, ramdisk_status,
            ramdisk_read, ramdisk_write, ramdisk_ioctl)) != RES_OK) {
        return result;
    }

    /* if creating a new ramdisk, zero out 'data[]' and call f_mkfs() */
    if (mkfs) {
        memset(data, 0, numBytes);
    }

    diskMem[drive]    = data;
    numSectors[drive] = numBytes / SECTORSIZE;

    /* mount the drive */
    if (f_mount(drive, &(ramdisk_filesystems[drive])) != FR_OK) {
        return RES_ERROR;
    }

    if (mkfs) {
        if (f_mkfs(drive, 0, 512) != FR_OK) {
            return RES_ERROR; 
        }
    }

    return RES_OK;
}
Beispiel #4
0
static rtems_task Init(rtems_task_argument argument)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;
  unsigned i = 0;

  rtems_test_begink();

  task_id_init = rtems_task_self();

  sc = rtems_disk_io_initialize();
  ASSERT_SC(sc);

  disk_register(BLOCK_SIZE_A, BLOCK_COUNT_A, &dd_a);

  disk_register(BLOCK_SIZE_B, BLOCK_COUNT_B, &dd_b);

  sc = rtems_task_create(
    rtems_build_name(' ', 'L', 'O', 'W'),
    PRIORITY_LOW,
    0,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id_low
  );
  ASSERT_SC(sc);

  sc = rtems_task_start(task_id_low, task_low, 0);
  ASSERT_SC(sc);

  sc = rtems_task_create(
    rtems_build_name('H', 'I', 'G', 'H'),
    PRIORITY_HIGH,
    0,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id_high
  );
  ASSERT_SC(sc);

  sc = rtems_task_start(task_id_high, task_high, 0);
  ASSERT_SC(sc);

  sc = rtems_task_create(
    rtems_build_name('R', 'E', 'S', 'U'),
    PRIORITY_RESUME,
    0,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id_resume
  );
  ASSERT_SC(sc);

  sc = rtems_task_start(task_id_resume, task_resume, 0);
  ASSERT_SC(sc);

  sc = rtems_task_suspend(task_id_low);
  ASSERT_SC(sc);

  sc = rtems_task_suspend(task_id_high);
  ASSERT_SC(sc);

  for (trig = SUSP; trig <= CONT; ++trig) {
    for (trig_get = GET; trig_get <= READ; ++trig_get) {
      for (low_get = GET; low_get <= READ; ++low_get) {
        for (high_get = GET; high_get <= READ; ++high_get) {
          for (trig_blk = BLK_A0; trig_blk <= BLK_B0; ++trig_blk) {
            for (low_blk = BLK_A0; low_blk <= BLK_B0; ++low_blk) {
              for (high_blk = BLK_A0; high_blk <= BLK_B0; ++high_blk) {
                for (trig_rel = REL; trig_rel <= SYNC; ++trig_rel) {
                  for (low_rel = REL; low_rel <= SYNC; ++low_rel) {
                    for (high_rel = REL; high_rel <= SYNC; ++high_rel) {
                      execute_test(i);
                      ++i;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }

  rtems_test_endk();

  exit(0);
}
static rtems_task Init(rtems_task_argument argument)
{
  rtems_status_code sc = RTEMS_SUCCESSFUL;
  size_t i_w = 0;
  size_t i_ac = 0;
  size_t i_rel = 0;
  size_t i_p = 0;

  printk("\n\n*** TEST BLOCK 10 ***\n");

  task_id_init = rtems_task_self();

  sc = rtems_disk_io_initialize();
  ASSERT_SC(sc);

  sc = disk_register(BLOCK_SIZE, BLOCK_COUNT, &dev);
  ASSERT_SC(sc);

  sc = rtems_task_create(
    rtems_build_name('P', 'U', 'R', 'G'),
    PRIORITY_HIGH,
    0,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id_purger
  );
  ASSERT_SC(sc);

  sc = rtems_task_start(task_id_purger, task_purger, 0);
  ASSERT_SC(sc);

  set_task_prio(task_id_purger, PRIORITY_LOW);

  sc = rtems_task_create(
    rtems_build_name('W', 'A', 'I', 'T'),
    PRIORITY_HIGH,
    0,
    RTEMS_DEFAULT_MODES,
    RTEMS_DEFAULT_ATTRIBUTES,
    &task_id_waiter
  );
  ASSERT_SC(sc);

  sc = rtems_task_start(task_id_waiter, task_waiter, 0);
  ASSERT_SC(sc);

  for (i_ac = 0; i_ac < ACCESS_COUNT; ++i_ac) {
    for (i_rel = 0; i_rel < RELEASE_COUNT; ++i_rel) {
      for (i_w = 0; i_w < WAITER_COUNT; ++i_w) {
        printk("test case [access]: %s and %s %s\n", access_assoc_table [i_ac], release_assoc_table [i_rel], waiter_assoc_table [i_w]);
        check_access(access_table [i_ac], release_table [i_rel], waiter_table [i_w]);
      }
    }
  }

  for (i_rel = 0; i_rel < RELEASE_COUNT; ++i_rel) {
    for (i_w = 0; i_w < WAITER_COUNT; ++i_w) {
      printk("test case [intermediate]: %s %s\n", release_assoc_table [i_rel], waiter_assoc_table [i_w]);
      check_intermediate(release_table [i_rel], waiter_table [i_w]);
    }
  }

  for (i_p = 0; i_p < PURGER_COUNT; ++i_p) {
    for (i_w = 0; i_w < WAITER_COUNT; ++i_w) {
      printk("test case [transfer]: %s %s\n", purger_assoc_table [i_p], waiter_assoc_table [i_w]);
      check_transfer(purger_table [i_p], waiter_table [i_w]);
    }
  }

  printk("*** END OF TEST BLOCK 10 ***\n");

  exit(0);
}
/*
 *  ======== USBMSCHFatFsTiva_open ========
 */
USBMSCHFatFs_Handle USBMSCHFatFsTiva_open(USBMSCHFatFs_Handle handle,
                                          unsigned char drv,
                                          USBMSCHFatFs_Params *params)
{
    unsigned int                    key;
    DRESULT                         dresult;
    FRESULT                         fresult;
    USBMSCHFatFsTiva_Object        *object = handle->object;
    USBMSCHFatFsTiva_HWAttrs const *hwAttrs = handle->hwAttrs;
    union {
        Task_Params                 taskParams;
        Semaphore_Params            semParams;
        GateMutex_Params            gateParams;
        Hwi_Params                  hwiParams;
    } paramsUnion;

    /* Determine if the device was already opened */
    key = Hwi_disable();
    if (object->driveNumber != DRIVE_NOT_MOUNTED) {
        Hwi_restore(key);
        return (NULL);
    }
    /* Mark as being used */
    object->driveNumber = drv;
    Hwi_restore(key);

    /* Store the USBMSCHFatFs parameters */
    if (params == NULL) {
        /* No params passed in, so use the defaults */
        params = (USBMSCHFatFs_Params *) &USBMSCHFatFs_defaultParams;
    }

    /* Initialize the USB stack for host mode. */
    USBStackModeSet(0, eUSBModeHost, NULL);

    /* Register host class drivers */
    USBHCDRegisterDrivers(0, usbHCDDriverList, numHostClassDrivers);

    /* Open an instance of the MSC host driver */
    object->MSCInstance = USBHMSCDriveOpen(0, USBMSCHFatFsTiva_cbMSCHandler);
    if (!(object->MSCInstance)) {
        Log_print0(Diags_USER1,"USBMSCHFatFs: Error initializing the MSC Host");
        USBMSCHFatFsTiva_close(handle);
        return (NULL);
    }

    /* Create the Hwi object to service interrupts */
    Hwi_Params_init(&(paramsUnion.hwiParams));
    paramsUnion.hwiParams.priority = hwAttrs->intPriority;

    Hwi_construct(&(object->hwi), hwAttrs->intNum, USBMSCHFatFsTiva_hwiHandler,
                 &(paramsUnion.hwiParams), NULL);

    /* Initialize USB power configuration */
    USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER);

    /* Enable the USB stack */
    USBHCDInit(0, object->memPoolHCD, HCDMEMORYPOOLSIZE);

    /* RTOS primitives */
    Semaphore_Params_init(&(paramsUnion.semParams));
    paramsUnion.semParams.mode = Semaphore_Mode_BINARY;
    Semaphore_construct(&(object->semUSBConnected), 0, &(paramsUnion.semParams));

    GateMutex_Params_init(&(paramsUnion.gateParams));
    paramsUnion.gateParams.instance->name = "USB Library Access";
    GateMutex_construct(&(object->gateUSBLibAccess), &(paramsUnion.gateParams));

    paramsUnion.gateParams.instance->name = "USB Wait";
    GateMutex_construct(&(object->gateUSBWait), &(paramsUnion.gateParams));

    /*
     * Note that serviceUSBHost() should not be run until the USB Stack has been
     * initialized!!
     */
    Task_Params_init(&(paramsUnion.taskParams));

    /*
     * If serviceTaskStackPtr is null, then Task_construct performs a
     * Memory_alloc - requiring a Heap
     */
    paramsUnion.taskParams.stack = params->serviceTaskStackPtr;

    /*
     * If service priority passed in is higher than what is configured by the
     * Task module, then use the highest priority available.
     */
    if (Task_numPriorities - 1 < params->servicePriority) {
        paramsUnion.taskParams.priority = (Task_numPriorities - 1);
    }
    else {
        paramsUnion.taskParams.priority = params->servicePriority;
    }

    /* If no stack size is passed in, then use the default task stack size */
    if (params->serviceTaskStackSize) {
        paramsUnion.taskParams.stackSize = params->serviceTaskStackSize;
    }
    else {
        paramsUnion.taskParams.stackSize = Task_defaultStackSize;
    }

    Task_construct(&(object->taskHCDMain),USBMSCHFatFsTiva_serviceUSBHost,
                   &(paramsUnion.taskParams), NULL);

    /* Register the new disk_*() functions */
    dresult = disk_register(drv,
                            USBMSCHFatFsTiva_diskInitialize,
                            USBMSCHFatFsTiva_diskStatus,
                            USBMSCHFatFsTiva_diskRead,
                            USBMSCHFatFsTiva_diskWrite,
                            USBMSCHFatFsTiva_diskIOctl);

    /* Check for drive errors */
    if (dresult != RES_OK) {
        Log_error0("USBMSCHFatFs: disk functions not registered");
        USBMSCHFatFsTiva_close(handle);
        return (NULL);
    }

    /* Mount the FatFs (this function does not access the SDCard yet...) */
    fresult = f_mount(drv, &(object->filesystem));
    if (fresult != FR_OK) {
        Log_error1("USBMSCHFatFs: drive %d not mounted", drv);
        USBMSCHFatFsTiva_close(handle);
        return (NULL);
    }

    Log_print1(Diags_USER1, "USBMSCHFatFs: drive %d opened", drv);

    return (handle);
}