int main(void)
{
	hardware_init();
	configure_gpio_pins(PORTB_IDX);
	configure_gpio_pins(PORTE_IDX);
	GPIO_DRV_SetPinDir(kGpioLED1, kGpioDigitalOutput);
	GPIO_DRV_SetPinDir(kGpioLED2, kGpioDigitalOutput);
	GPIO_DRV_SetPinDir(kGpioLED3, kGpioDigitalOutput);
	PRINTF("LED Color Select:\n\r");
	PRINTF("R: RED/n/rG: Green/n/rB: Blue\n\r");
	while(1){
	PRINTF("Please Select LED:\n\r");
		ch = GETCHAR();
		switch(ch){
			case 'r':
			case 'R':
				PRINTF("Red led on\n\r");
				LED1_ON;
				LED2_OFF;
				LED3_OFF;
				/*GPIO_DRV_WritePinOutput(kGpioLED1, 1);
				GPIO_DRV_WritePinOutput(kGpioLED2, 0);
				GPIO_DRV_WritePinOutput(kGpioLED3, 1);*/
				break;
			case 'g':
			case 'G':
				PRINTF("Green led on\n\r");
				LED1_OFF;
				LED2_ON;
				LED3_OFF;
				/*GPIO_DRV_WritePinOutput(kGpioLED1, 1);
				GPIO_DRV_WritePinOutput(kGpioLED2, 1);
				GPIO_DRV_WritePinOutput(kGpioLED3, 0);*/
				break;
			case 'b':
			case 'B':
				LED1_OFF;
				LED2_OFF;
				LED3_ON;
				PRINTF("Blue led on\n\r");
				/*GPIO_DRV_WritePinOutput(kGpioLED1, 0);
				GPIO_DRV_WritePinOutput(kGpioLED2, 1);
				GPIO_DRV_WritePinOutput(kGpioLED3, 1);*/
				break;
			default:
				PRINTF("Wrong selection go again\n\r");
				break;

		}
	}
    return 0;
}
void hardware_init(void) {

  uint8_t i;

  /* enable clock for PORTs */
  for (i = 0; i < HW_PORT_INSTANCE_COUNT; i++) {
    CLOCK_SYS_EnablePortClock(i);
  }

  /* Setup board clock source. */
  g_xtal0ClkFreq = 50000000U;
//  g_xtalRtcClkFreq = 32768U;

  for (i = 0; i < HW_PORT_INSTANCE_COUNT; i++)
  {
    configure_gpio_pins(i);
  }

  configure_i2c_pins(0);//FXO8700 & L3G4200d

 // configure_adc_pins_for_quadcopter();
  
  configure_remote_control_pins_for_quadcopter() ; 
  
  configure_sensors_interrupt_pins_for_quadcopter();

  configure_ftm_pins_for_quadcopter();
  
  configure_uart_pins(BOARD_DEBUG_UART_INSTANCE);
}
示例#3
0
void hardware_init(void) 
{
  /* enable clock for PORTs */
  CLOCK_SYS_EnablePortClock(PORTC_IDX);
  CLOCK_SYS_EnablePortClock(PORTD_IDX);
  CLOCK_SYS_EnablePortClock(PORTE_IDX);
  CLOCK_SYS_EnablePortClock(PORTF_IDX);
  CLOCK_SYS_EnablePortClock(PORTI_IDX);
  CLOCK_SYS_EnablePortClock(PORTJ_IDX);

  /* Init board clock */
  BOARD_ClockInit();
  
  configure_gpio_pins(PORTC_IDX);
  configure_gpio_pins(PORTD_IDX);
  configure_gpio_pins(PORTE_IDX);
  configure_gpio_pins(PORTF_IDX);
  configure_gpio_pins(PORTJ_IDX);
  
  /* Configure the UART TX/RX pins */
  configure_uart_pins(2U);
}
void hardware_init(void)
{
    int32_t i;

    /* enable clock for PORTs */
    for (i = 0; i < HW_PORT_INSTANCE_COUNT; i++)
    {
        CLOCK_SYS_EnablePortClock(i);
    }
    /* Setup board clock source. */
    g_xtal0ClkFreq = 8000000U;

    /* init the general pinmux */
    for (i = 0; i < HW_PORT_INSTANCE_COUNT; i++)
    {
        configure_gpio_pins(i);
    }
}
示例#5
0
void hardware_init(void)
{

    uint8_t i;

    /* enable clock for PORTs */
    for (i = 0; i < PORT_INSTANCE_COUNT; i++)
    {
        CLOCK_SYS_EnablePortClock(i);
    }

    /* Init board clock */
    BOARD_ClockInit();
    dbg_uart_init();

    for (i = 0; i < PORT_INSTANCE_COUNT; i++)
    {
        configure_gpio_pins(i);
    }
}
示例#6
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 */