예제 #1
0
/*TASK*-----------------------------------------------------
* 
* Task Name    : Ram_disk_start
* Comments     : Open device and install MFS on device
*    
*
*END*-----------------------------------------------------*/
void Ram_disk_start(void)
{ /* Body */
   int                        dev_fd, a_fd_ptr;
   int32_t                    error_code;
   _mqx_uint                  mqx_status;
   uint32_t                   isFormatted = 0;
   const NIO_MEM_INIT_DATA_STRUCT nmid = { (uint32_t)RAM_DISK_BASE, (uint32_t)RAM_DISK_SIZE };

   a_fd_ptr = 0;

   /* install device */
   if (NULL == _nio_dev_install("mfs_ramdisk:", &nio_mem_dev_fn, (void *)&nmid, NULL))
   {
   /* Number of sectors is returned by ioctl IO_IOCTL_GET_NUM_SECTORS function */
   /* If another disc structure is desired, use MFS_FORMAT_DATA structure to   */
   /* define it and call standart format function instead default_format       */   
      printf("\nError installing memory device");
      _task_block();
   } /* Endif */

   /* Open the device which MFS will be installed on */
   dev_fd = open("mfs_ramdisk:", 0);
   if ( dev_fd < 0 ) {
      printf("\nUnable to open Ramdisk device");
      _task_block();
   } /* Endif */

   /* Install MFS  */
   mqx_status = _io_mfs_install(dev_fd, "a:", (_file_size)0);
   if (mqx_status != MFS_NO_ERROR) {
      printf("\nError initializing a:");
      _task_block();
   } else {
      printf("\nInitialized Ram Disk to a:\\");
   } /* Endif */

   /* Open the filesystem and format detect, if format is required */
   a_fd_ptr = open("a:", O_RDWR);
   if (0 > a_fd_ptr) {
      printf("\nError while opening a:\\ (%s)", MFS_Error_text((uint32_t)errno));
      _task_block();
   }

   _io_register_file_system(a_fd_ptr, "a:");

   /* We check if the device is formatted with the ioctl command.*/
   error_code = ioctl(a_fd_ptr, IO_IOCTL_CHECK_FORMATTED, &isFormatted);
   if (0 > error_code) {
      printf("\nError while accessing a:\\ (%s)", MFS_Error_text((uint32_t)error_code));
      _task_block();
   }
   else{
     if(!isFormatted){
        printf("\nNOT A DOS DISK! You must format to continue."); 
     } 
   }
} /* Endbody */ 
예제 #2
0
파일: init_bsp.c 프로젝트: afbcom/ceng455
/**FUNCTION********************************************************************
*
* Function Name    : _bsp_nio_stdio_install
* Returned Value   : void
* Comments         :
*   This function is to be called after _nio_init() to install stdio devices
*
*END**************************************************************************/
_WEAK_FUNCTION(void _bsp_nio_stdio_install(void))
{
    void *res;
    int fd;


    /* Install serial driver for default input and output */
    res = _nio_dev_install(BSP_DEFAULT_IO_CHANNEL, &nio_serial_dev_fn, (void*) &nio_serial_default_init, NULL);
    assert(NULL != res);

    /* Install and open dummy drivers for stdin, stdou and stderr. */
    res = _nio_dev_install("dummy:",&nio_dummy_dev_fn, (NULL), NULL);
    assert(NULL != res);

    fd = open("dummy:", 0);  // 0 - stdin
    assert(fd == 0);
    fd = open("dummy:", 0);  // 1 - stdout
    assert(fd == 1);
    fd = open("dummy:", 0);  // 2 - stderr
    assert(fd == 2);

    /* Instal and set tty driver */
    res = _nio_dev_install("tty:", &nio_tty_dev_fn, (void*)&(NIO_TTY_INIT_DATA_STRUCT){BSP_DEFAULT_IO_CHANNEL, 0}, NULL);
    assert(NULL != res);

    close(0);
    fd = open("tty:", NIO_TTY_FLAGS_EOL_RN | NIO_TTY_FLAGS_ECHO);  // 0 - stdin
    assert(fd == 0);

    close(1);
    fd = open("tty:", NIO_TTY_FLAGS_EOL_RN | NIO_TTY_FLAGS_ECHO);  // 1 - stdout
    assert(fd == 1);

    close(2);
    fd = open("tty:", NIO_TTY_FLAGS_EOL_RN | NIO_TTY_FLAGS_ECHO);  // 2 - stderr
    assert(fd == 2);

    /* Dummy driver is not needed any more, therefore should be uninstalled */
    _nio_dev_uninstall("dummy:", NULL);

    /* Avoid warnings on fd and res variables in release targets */
    (void)fd;
    (void)res;
}
예제 #3
0
/*TASK*-----------------------------------------------------
* 
* Task Name    : sdcard_task
* Comments     : Open device and install MFS on device
*    
*
*END*-----------------------------------------------------*/
void sdcard_task(void)
{ /* Body */
   int                          dev_fd = -1, a_fd = -1;
   bool                         inserted = FALSE, last = FALSE;
   int32_t                      error_code;
   uint32_t                     isFormatted = 0;
   int                          esdhc_handle = -1;
   char                         partman_name[] = "pm:";
   char                         partition_name[] = "pm:1";
   int                          partition_handle;
   SDCARD_INIT_STRUCT           sdcard_init_data;
   LWSEM_STRUCT                 lwsem;

   /* Create and post card detection semaphore */
   if( _lwsem_create(&lwsem, 0) != MQX_OK ){
       printf("\nlwsem create failed!");
       _task_block();
   }
   if( _lwsem_post(&lwsem) != MQX_OK ){
       printf("\nlwsem post failed!");
       _task_block();
   }

#ifdef BOARD_SDHC_GPIO_INSTANCE
   configure_gpio_pins(GPIO_EXTRACT_PORT(BOARD_SDHC_GPIO_INSTANCE));
#endif

   /* initialize SDHC pins */
   configure_sdhc_pins(BOARD_SDHC_INSTANCE);

   /* install SDHC low-level driver */
   _nio_dev_install("esdhc:", &nio_esdhc_dev_fn, (void*)&_bsp_esdhc_init, NULL);

   /* get an instance of the SDHC driver */
   esdhc_handle = open("esdhc:", 0);

   if(esdhc_handle < 0)
   {
      printf("\nCould not open esdhc!");
      _task_block();
   }

   /* prepare init data structure */
   sdcard_init_data.com_dev = esdhc_handle;
   sdcard_init_data.const_data = (SDCARD_CONST_INIT_STRUCT_PTR)&sdcard_esdhc_init_data;

   /* install device */
   if (_nio_dev_install("sdcard:", &nio_sdcard_dev_fn, (void*)&sdcard_init_data, NULL) == NULL)
   {
   /* Number of sectors is returned by ioctl IO_IOCTL_GET_NUM_SECTORS function */
   /* If another disc structure is desired, use MFS_FORMAT_DATA structure to   */
   /* define it and call standart format function instead default_format       */   
      printf("\nError installing memory device");
      _task_block();
   } /* Endif */

   /* install isr for card detection handling and initialize gpio pin */
   _int_install_isr(g_portIrqId[GPIO_EXTRACT_PORT(CDET_PIN->pinName)], card_detect_isr, &lwsem);   
   GPIO_DRV_InputPinInit(CDET_PIN);

   for(;;){

     /* Wait for card insertion or removal */
     if( _lwsem_wait(&lwsem) != MQX_OK ){
       printf("\nlwsem_wait failed!");
       _task_block();
     }

     /* Check if card is present */
     if(CDET_PIN->config.pullSelect == kPortPullDown)
         inserted = GPIO_DRV_ReadPinInput(CDET_PIN->pinName);
     else
         inserted = !GPIO_DRV_ReadPinInput(CDET_PIN->pinName);

     if(last != inserted){
       last = inserted;

       /* Card detection switch debounce delay */
       _time_delay(100);

       if(inserted)
       {
         /* Open the device which MFS will be installed on */
         dev_fd = open("sdcard:", O_RDWR);
         if ( dev_fd <= 0 ) {
              printf("\nUnable to open SDCARD device");
              _task_block();
         } /* Endif */

         /* Install partition manager over SD card driver */
         error_code = _io_part_mgr_install(dev_fd, partman_name, 0);
         if (error_code != MFS_NO_ERROR)
         {
             printf("Error installing partition manager: %s\n", MFS_Error_text((uint32_t)error_code));
             _task_block();
         }

         /* Open partition */
         partition_handle = open(partition_name, O_RDWR);
         if (partition_handle >= 0)
         {
             printf("Installing MFS over partition...\n");
        
             /* Validate partition */
             error_code = ioctl(partition_handle, IO_IOCTL_VAL_PART, NULL);
             if (error_code != MFS_NO_ERROR)
             {
                 printf("Error validating partition: %s\n", MFS_Error_text((uint32_t)error_code));
                 printf("Not installing MFS.\n");
                 _task_block();
             }

             /* Install MFS over partition */
             error_code = _io_mfs_install(partition_handle, "a:", 0);
             if (error_code != MFS_NO_ERROR)
             {
                 printf("Error initializing MFS over partition: %s\n", MFS_Error_text((uint32_t)error_code));
             }

         } else
         {
           printf("Installing MFS over SD card driver...\n");
            
           /* Install MFS over SD card driver */
           error_code = _io_mfs_install(dev_fd, "a:", (_file_size)0);
           if (error_code != MFS_NO_ERROR)
           {
               printf("Error initializing MFS: %s\n", MFS_Error_text((uint32_t)error_code));
           }
         }

         /* Open the filesystem and format detect, if format is required */
         a_fd = open("a:", O_RDWR);
         if (0 >= a_fd) {
             printf("\nError while opening a:\\ (%s)", MFS_Error_text((uint32_t)errno));
             _task_block();
         }

         _io_register_file_system(a_fd, "a:");

         /* We check if the device is formatted with the ioctl command. */
         error_code = ioctl(a_fd, IO_IOCTL_CHECK_FORMATTED, &isFormatted);
         if (0 > error_code) {
             printf("\nError while accessing a:\\ (%s)", MFS_Error_text((uint32_t)error_code));
             _task_block();
         }
         else{
           if(!isFormatted){
               printf("\nNOT A DOS DISK! You must format to continue.");
           }
         }
       }
       else
       {
         /* Close the filesystem */
         if ((a_fd >= 0) && (MQX_OK != close(a_fd)))
         {
             printf("Error closing filesystem.\n");
         }
         a_fd = -1;

         /* Force uninstall filesystem */
         error_code = _nio_dev_uninstall_force("a:", NULL);
         if (error_code < 0)
         {
             printf("Error uninstalling filesystem.\n");
         }

         /* Close partition */
         if ((partition_handle >= 0) && (MQX_OK != close(partition_handle)))
         {
             printf("Error closing partition.\n");
         }
         partition_handle = -1;

         /* Uninstall partition manager */
         error_code = _nio_dev_uninstall_force(partman_name, NULL);
         if (error_code < 0)
         {
             printf("Error uninstalling partition manager.\n");
         }

         /* Close the SD card device */
         if ((dev_fd >= 0) && (MQX_OK != close(dev_fd)))
         {
             printf("Error closing SD card device.\n");
         }

         dev_fd = -1;

         printf ("SD card uninstalled.\n");
       }
     }
   }
} /* Endbody */