예제 #1
0
static void sdk_task(void *param) {
  (void)param;
  for(;;) {
    gpio_toggle_pin_output(LED_BLUE);
	  time_delay(1000);
  }
}
예제 #2
0
static void usb_host_mass_test_storage
   (
      void
   )
{ /* Body */
   static USB_STATUS                                 status = USB_OK;
   static uint_8                                     bLun = 0;
   static INQUIRY_DATA_FORMAT                        inquiry;
   static MASS_STORAGE_READ_CAPACITY_CMD_STRUCT_INFO read_capacity;
   static CAPACITY_LIST                              capacity_list;
   static REQ_SENSE_DATA_FORMAT                      req_sense;
   static FORMAT_UNIT_PARAMETER_BLOCK                formatunit = { 0};
   static CBW_STRUCT_PTR cbw_ptr; 
   static CSW_STRUCT_PTR csw_ptr;

   uint_8 res;

   switch(test)
   {
    case 0:
      cbw_ptr = pCmd.CBW_PTR;
      csw_ptr = pCmd.CSW_PTR;

      memset(buff_in, 0, BUFF_IN_SIZE);
      memset(buff_out, 0, 0x0F);
      memset(pCmd.CSW_PTR, 0, sizeof(CSW_STRUCT));
      memset(pCmd.CBW_PTR, 0, sizeof(CBW_STRUCT));
      memset(&pCmd, 0, sizeof(COMMAND_OBJECT_STRUCT));
      
      pCmd.CBW_PTR  = cbw_ptr;
      pCmd.CSW_PTR  = csw_ptr;
      pCmd.LUN      = bLun;
      pCmd.CALL_PTR = (pointer)&mass_device.class_intf;
      pCmd.CALLBACK = callback_bulk_pipe;

      printf("\n ================ START OF A NEW SESSION ================");
      test++;
      ontest = 1;
      count = 0;
      break;
      
      
    case 1:
        count++;
        /* Send standard commands once, after each enumeration in order to 
         * communicate well with most usb sticks */
        if(count == 1){
#if 0
            /* Read LUN info (type, and some strings) */
            res = disk_ioctl(0, UFI_INQUIRY, NULL);
            //res = disk_ioctl(0, UFI_READ_FORMAT_CAPACITY, NULL);
            res = disk_ioctl(0, UFI_REQUEST_SENSE, NULL);
            //res = disk_ioctl(0, UFI_READ_FORMAT_CAPACITY, NULL);
#endif
#if 1
            res = disk_ioctl(0, UFI_INQUIRY, NULL);
            res = disk_ioctl(0, UFI_TEST_UNIT_READY, NULL);
            //res = disk_ioctl(0, UFI_READ_CAPACITY, NULL);
            printf("");
#endif
        }
        
      /* Test the GET MAX LUN command */
      if (1 == ontest)
      {
        printf("\n Testing: GET MAX LUN Command");
        bCallBack = FALSE;

        status = usb_class_mass_getmaxlun_bulkonly(
          (pointer)&mass_device.class_intf, &bLun,
          usb_host_mass_ctrl_callback);
          ontest = 0;
      } 
      else 
      {
        if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
        {
          printf (".......................ERROR");
          return;
        }
        else
        {
          /* Wait till command comes back */
          if (!bCallBack) {break;}
          if (!bStatus) 
          {
             printf("..........................OK\n");
             test++;
             ontest = 1;
          }
          else 
          {
             printf("...Unsupported (bStatus=0x%08x)\n", (unsigned int)bStatus);
             test++;
             ontest = 1;
          }
        }
      }
      break;
      
    case 2:
        if (1 == ontest)
        {
            printf(" Testing: TEST UNIT READY Command");
            bCallBack = FALSE;

            status =  usb_mass_ufi_test_unit_ready(&pCmd);
            ontest = 0;
        } 
        else 
        {
            if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
            {
                printf ("...................ERROR");
                return;
            }
            else
            {
                /* Wait till command comes back */
                if (!bCallBack) {break;}
                if (!bStatus)
                {
                    printf("......................OK\n");
                    test++;
                    ontest = 1;
                }
                else 
                {
                    printf("...Unsupported(bStatus=0x%08x)\n", (unsigned int)bStatus);
                    test++;
                    ontest = 1;
                }
            }
        }
        break;
      
    case 3:
        printf(" Testing: REQUEST SENSE Command");
        res = disk_ioctl(0, UFI_REQUEST_SENSE, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: INQUIRY Command");
        res = disk_ioctl(0, UFI_INQUIRY, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: REQUEST SENSE Command");
        res = disk_ioctl(0, UFI_REQUEST_SENSE, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        time_delay(2000);
        printf(" Testing: READ CAPACITY Command");
        res = disk_ioctl(0, UFI_READ_CAPACITY, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: REQUEST SENSE Command");
        res = disk_ioctl(0, UFI_REQUEST_SENSE, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: READ FORMAT CAPACITIES Command");
        res = disk_ioctl(0, UFI_READ_FORMAT_CAPACITY, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: REQUEST SENSE Command");
        res = disk_ioctl(0, UFI_REQUEST_SENSE, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: MODE SENSE Command");
        res = disk_ioctl(0, UFI_MODE_SENSE, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: PREVENT-ALLOW MEDIUM REMOVAL Command");
        res = disk_ioctl(0, UFI_PREVENT_ALLOW_MEDIUM_ROMVAL, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: REQUEST SENSE Command");
        res = disk_ioctl(0, UFI_REQUEST_SENSE, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: VERIFY Command");
        res = disk_ioctl(0, UFI_VERIFY, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: WRITE(10) Command");
        res = disk_ioctl(0, UFI_WRITE10, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: REQUEST SENSE Command");
        
        printf(" Testing: REQUEST SENSE Command");
        res = disk_ioctl(0, UFI_REQUEST_SENSE, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: READ(10) Command");
        res = disk_ioctl(0, UFI_READ10, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        
        printf(" Testing: START-STOP UNIT Command");
        res = disk_ioctl(0, UFI_START_STOP, NULL);
        if(!res)
            printf("......................OK\n");
        else
            printf("FAILED(%x)\n\r", res);
        /* ------------------------------------------------------------------ */
        test++;
      break;
      
    case 4:
      printf("\n Test done!\n");
      test++;
      break;
      
    default:
      break;
   } /* End of switch */
   
   /* ------------------------------------------------------------------ */
   if(test == 19)
   {
       
   }

} /* Endbody */
예제 #3
0
int main(int argc,char **argv)
{
LONG seconds;
struct timerequest *tr;      /* IO block for timer commands */
struct timeval oldtimeval;   /* timevals to store times     */
struct timeval mytimeval;
struct timeval currentval;

printf("\nTimer test\n");

/* sleep for two seconds */
currentval.tv_secs = 2;
currentval.tv_micro = 0;
time_delay( &currentval, UNIT_VBLANK );
printf( "After 2 seconds delay\n" );

/* sleep for four seconds */
currentval.tv_secs = 4;
currentval.tv_micro = 0;
time_delay( &currentval, UNIT_VBLANK );
printf( "After 4 seconds delay\n" );

/* sleep for 500,000 micro-seconds = 1/2 second */
currentval.tv_secs = 0;
currentval.tv_micro = 500000;
time_delay( &currentval, UNIT_MICROHZ );
printf( "After 1/2 second delay\n" );

printf( "DOS Date command shows: " );
(void) Execute( "date", 0, 0 );

/* save what system thinks is the time....we'll advance it temporarily */
get_sys_time( &oldtimeval );
printf("Original system time is:\n");
show_time(oldtimeval.tv_secs );

printf("Setting a new system time\n");

seconds = 1000 * SECSPERDAY + oldtimeval.tv_secs;

set_new_time( seconds );
/* (if user executes the AmigaDOS DATE command now, he will*/
/* see that the time has advanced something over 1000 days */

printf( "DOS Date command now shows: " );
(void) Execute( "date", 0, 0 );

get_sys_time( &mytimeval );
printf( "Current system time is:\n");
show_time(mytimeval.tv_secs);

/* Added the microseconds part to show that time keeps */
/* increasing even though you ask many times in a row  */

printf("Now do three TR_GETSYSTIMEs in a row (notice how the microseconds increase)\n\n");
get_sys_time( &mytimeval );
printf("First TR_GETSYSTIME \t%ld.%ld\n",mytimeval.tv_secs, mytimeval.tv_micro);
get_sys_time( &mytimeval );
printf("Second TR_GETSYSTIME \t%ld.%ld\n",mytimeval.tv_secs, mytimeval.tv_micro);
get_sys_time( &mytimeval );
printf("Third TR_GETSYSTIME \t%ld.%ld\n",mytimeval.tv_secs, mytimeval.tv_micro);

printf( "\nResetting to former time\n" );
set_new_time( oldtimeval.tv_secs );

get_sys_time( &mytimeval );
printf( "Current system time is:\n");
show_time(mytimeval.tv_secs);

/* just shows how to set up for using the timer functions, does not */
/* demonstrate the functions themselves.  (TimerBase must have a    */
/* legal value before AddTime, SubTime or CmpTime are performed.    */
tr = create_timer( UNIT_MICROHZ );
if (tr)
    TimerBase = (struct Library *)tr->tr_node.io_Device;
else
    printf("Could't create timer with UNIT_MICROHZ\n");

/* and how to clean up afterwards */
TimerBase = (struct Library *)(-1);
delete_timer( tr );

return 0;
}
/*FUNCTION****************************************************************
 *
 * Function Name: enet_mac_init
 * Return Value: The execution status.
 * Description:Initialize the ENET device with the basic configuration
 * When ENET is used, this function need to be called by the NET initialize
 * interface.
 *END*********************************************************************/
uint32_t enet_mac_init(enet_dev_if_t * enetIfPtr, enet_rxbd_config_t *rxbdCfg,
                            enet_txbd_config_t *txbdCfg)
{
    uint32_t timeOut = 0;
    uint32_t devNumber, result = 0;

    /* Check the input parameters*/
    if (enetIfPtr == NULL)
    {
        return kStatus_ENET_InvalidInput;
    }

    /* Get device number and check the parameter*/
    devNumber = enetIfPtr->deviceNumber;

    /* Store the global ENET structure for ISR input parameters */
    enetIfHandle = enetIfPtr;

    /* Turn on ENET module clock gate */
    CLOCK_SYS_EnableEnetClock(0U);

    /* Reset ENET mac*/
    enet_hal_reset_ethernet(devNumber);
    while ((!enet_hal_is_reset_completed(devNumber)) && (timeOut < kEnetMaxTimeout))
    {
        time_delay(1);
        timeOut++;
    }

    /* Check out if timeout*/
    if (timeOut == kEnetMaxTimeout)
    {
        return kStatus_ENET_TimeOut;
    }

    /* Disable all ENET mac interrupt and Clear all interrupt events*/
    enet_hal_config_interrupt(devNumber, kEnetAllInterrupt, false);
    enet_hal_clear_interrupt(devNumber, kEnetAllInterrupt);

    /* Program this station's physical address*/
    enet_hal_set_mac_address(devNumber, enetIfPtr->macCfgPtr->macAddr);

    /* Enable Multicast group filtering. The entry is All F because we want to listen
     * all multicast*/
    uint32_t i = 0;
    for (i=0; i<=63; i++){
    enet_hal_set_group_hashtable(devNumber, i<<26, kEnetSpecialAddressEnable);
    }

    /* Enable Unicast Group with 0 hash table entry. It means it
     * will accept only its own MAC address as the destination address if
     * something is received.*/
    enet_hal_set_individual_hashtable(devNumber, 0, kEnetSpecialAddressInit);

	  /* Configure mac controller*/
    result = enet_mac_configure_controller(enetIfPtr);
    if(result != kStatus_ENET_Success)
    {
        return result;
    }
    /* Clear mib zero counters*/
    enet_hal_clear_mib(devNumber, true);

    /* Initialize FIFO and accelerator*/
    result = enet_mac_configure_fifo_accel(enetIfPtr);
    if(result != kStatus_ENET_Success)
    {
        return result;
    }
    /* Initialize receive buffer descriptors*/
    result = enet_mac_rxbd_init(enetIfPtr, rxbdCfg);
    if(result != kStatus_ENET_Success)
    {
        return result;
    }
    /* Initialize transmit buffer descriptors*/
	  result = enet_mac_txbd_init(enetIfPtr, txbdCfg);
    if(result != kStatus_ENET_Success)
    {
        return result;
    }
    /* Initialize rmii/mii interface*/
    result = enet_mac_mii_init(enetIfPtr);
    if (result != kStatus_ENET_Success)
    {
        return result;
    }

    return kStatus_ENET_Success;
}
예제 #5
0
/*FUNCTION****************************************************************
 *
 * Function Name: enet_mac_init
 * Return Value: The execution status.
 * Description:Initialize the ENET device with the basic configuration
 * When ENET is used, this function need to be called by the NET initialize 
 * interface.
 *END*********************************************************************/
uint32_t enet_mac_init(enet_dev_if_t * enetIfPtr, enet_rxbd_config_t *rxbdCfg,
                            enet_txbd_config_t *txbdCfg)
{   
    uint32_t timeOut = 0;
    uint32_t devNumber, result = 0; 
	
    /* Check the input parameters*/
    if (enetIfPtr == NULL)
    {
        return kStatus_ENET_InvalidInput;
    }

    /* Get device number and check the parameter*/
    devNumber = enetIfPtr->deviceNumber;

    /* Store the global ENET structure for ISR input parameters for instance 0*/
    if (!devNumber)
    {
        enetIfHandle = enetIfPtr;
    }

    /* Turn on ENET module clock gate */
    clock_manager_set_gate(kClockModuleENET, 0U, true);

    /* Reset ENET mac*/
    enet_hal_reset_ethernet(devNumber);
    while ((!enet_hal_is_reset_completed(devNumber)) && (timeOut < kEnetMaxTimeout))
    {
        time_delay(1);
        timeOut++;
    }

    /* Check out if timeout*/
    if (timeOut == kEnetMaxTimeout)
    {
        return kStatus_ENET_TimeOut;
    }
	
    /* Disable all ENET mac interrupt and Clear all interrupt events*/
    enet_hal_config_interrupt(devNumber, kEnetAllInterrupt, false);
    enet_hal_clear_interrupt(devNumber, kEnetAllInterrupt);
	
    /* Program this station's physical address*/
    enet_hal_set_mac_address(devNumber, enetIfPtr->macCfgPtr->macAddr);

    /* Clear group and individual hash register*/
    enet_hal_set_group_hashtable(devNumber, 0, kEnetSpecialAddressInit);
    enet_hal_set_individual_hashtable(devNumber, 0, kEnetSpecialAddressInit);

	  /* Configure mac controller*/
    result = enet_mac_configure_controller(enetIfPtr);
    if(result != kStatus_ENET_Success)
    {
        return result;
    }
    /* Clear mib zero counters*/
    enet_hal_clear_mib(devNumber, true);

    /* Initialize FIFO and accelerator*/
    result = enet_mac_configure_fifo_accel(enetIfPtr);
    if(result != kStatus_ENET_Success)
    {
        return result;
    }
    /* Initialize receive buffer descriptors*/
    result = enet_mac_rxbd_init(enetIfPtr, rxbdCfg);
    if(result != kStatus_ENET_Success)
    {
        return result;
    }
    /* Initialize transmit buffer descriptors*/
	  result = enet_mac_txbd_init(enetIfPtr, txbdCfg);
    if(result != kStatus_ENET_Success)
    {
        return result;
    }	
    /* Initialize rmii/mii interface*/
    result = enet_mac_mii_init(enetIfPtr);
    if (result != kStatus_ENET_Success)
    {
        return result;
    }
    
    return kStatus_ENET_Success;
}