Exemple #1
0
static ai_device_status_t ai_sd_mmc_get_device_status(ai_async_status_t *cmd_ai_status)
{
  *cmd_ai_status = CMD_DONE;

#if defined(SD_MMC_CARD_DETECT_PIN)
  if (gpio_get_pin_value(SD_MMC_CARD_DETECT_PIN))
#endif
#if defined(SUPPORT_SD_MMC_MCI) && SUPPORT_SD_MMC_MCI == true
  if (sd_mmc_mci_mem_check(SD_SLOT))
  {
    volatile uint32_t card_size;
    sd_mmc_mci_read_capacity(SD_SLOT, (uint32_t *) &card_size);
    return AI_DEVICE_STATUS_CONNECTED;
  }
#else
  if (sd_mmc_spi_check_presence() == true)
    return AI_DEVICE_STATUS_CONNECTED;
#endif

  return AI_DEVICE_STATUS_NOT_PRESENT;
}
void GetProductionInfos (typeStick20ProductionInfos_st * Infos_st,u8 WriteTestEnabled)
{
typeStick20Configuration_st SC_Status_st;
volatile u32* id_data = (u32 *) 0x80800204; // Place of 120 bit CPU ID
u32 i;
u32 CPU_ID_u32;
cid_t* cid;
u32 Blockcount_u32;

    // Clear data field
    memset ((void *) Infos_st, 0, sizeof (Infos_st));

    Infos_st->FirmwareVersion_au8[0]     = VERSION_MAJOR;
    Infos_st->FirmwareVersion_au8[1]     = VERSION_MINOR;
    Infos_st->FirmwareVersionInternal_u8 = INTERNAL_VERSION_NR;

    if (TRUE == WriteTestEnabled)
    {
      // Get smartcard infos
      GetSmartCardStatus (&SC_Status_st);

      // Run the check only if the initial pw is aktive
      if (3 == SC_Status_st.UserPwRetryCount)
      {
          if (FALSE == LA_OpenPGP_V20_Test_SendUserPW2 ((unsigned char *) "123456"))
          {
              CI_TickLocalPrintf ("GetProductionInfos: Intial password is not activ\r\n");
              Infos_st->SC_AdminPwRetryCount = 99;    // Marker for wrong pw
              return;
          }
      }
      else
      {
          CI_TickLocalPrintf ("GetProductionInfos: Password retry count is not 3 : %d\r\n", SC_Status_st.UserPwRetryCount);
          Infos_st->SC_AdminPwRetryCount = 88;    // Marker for wrong pw retry count
          return;
      }
    }

    // Get XORed CPU ID
    CPU_ID_u32 = 0;
    for (i = 0; i < 4; i++)
    {
          CPU_ID_u32 ^= id_data[i];
    }
    Infos_st->CPU_CardID_u32 = CPU_ID_u32;

    // Init SD - read capacity
    sd_mmc_mci_read_capacity (SD_SLOT, (unsigned long int *) &Blockcount_u32);

    Infos_st->SD_Card_Size_u8 = Blockcount_u32 / 2 / 1024 / 1024 + 1;   // in GB

    // Save smartcard infos
    if (TRUE == WriteTestEnabled)
    {
      Infos_st->SC_UserPwRetryCount = SC_Status_st.UserPwRetryCount;
      Infos_st->SC_AdminPwRetryCount = SC_Status_st.AdminPwRetryCount;
      Infos_st->SmartCardID_u32 = SC_Status_st.ActiveSmartCardID_u32;
    }
    else
    {
      Infos_st->SC_UserPwRetryCount  = 0;
      Infos_st->SC_AdminPwRetryCount = 0;
      Infos_st->SmartCardID_u32      = 0;
    }

    // Get SD card infos
    cid = (cid_t *) GetSdCidInfo ();

    Infos_st->SD_CardID_u32 = (cid->psnh << 8) + cid->psnl;
    Infos_st->SD_Card_ManufacturingYear_u8 = cid->mdt / 16;
    Infos_st->SD_Card_ManufacturingMonth_u8 = cid->mdt % 0x0f;
    Infos_st->SD_Card_OEM_u16 = cid->oid;
    Infos_st->SD_Card_Manufacturer_u8 = cid->mid;

    // Get SD card speed
    if (TRUE == WriteTestEnabled)
    {
      Infos_st->SD_WriteSpeed_u16 = SD_SpeedTest ();
    }
    else
    {
      Infos_st->SD_WriteSpeed_u16 = 0;
    }

}
Exemple #3
0
/*! \brief Main function. Execution starts here.
 */
int main(void)
{
  U32 n_sector = 0;
  U32 card_size; // Unit is in sector.
  U32 bench_start_sector;
  U16 i = 0;
  U16 j = 0;
  t_cpu_time timer;
  Ctrl_status status;

  // Set CPU and PBA clock
  if( PM_FREQ_STATUS_FAIL==pm_configure_clocks(&pm_freq_param) )
     return 42;

  // Initialize HMatrix
  init_hmatrix();

  // Initialize debug RS232 with PBA clock
  init_dbg_rs232(pm_freq_param.pba_f);

  // Start test
  print_dbg("\r\nInitialize SD/MMC driver");

  // Initialize SD/MMC driver resources: GPIO, SDIO and SD/MMC.
  sd_mmc_mci_resources_init();

  // Wait for a card to be inserted
  #if (BOARD == EVK1104)
    #if EXAMPLE_SD_SLOT == SD_SLOT_8BITS
    print_dbg("\r\nInsert a MMC/SD card into the SD/MMC 8bits slot...");
    #elif EXAMPLE_SD_SLOT == SD_SLOT_4BITS
    print_dbg("\r\nInsert a MMC/SD card into the SD/MMC 4bits slot...");
    #else
    # error SD_SLOT not supported
    #endif
    while (!sd_mmc_mci_mem_check(EXAMPLE_SD_SLOT));
  #else
  # error Board not supported
  #endif

  print_dbg("Card detected!\r\n");

  // Read Card capacity
  sd_mmc_mci_read_capacity(EXAMPLE_SD_SLOT, &card_size);
  print_dbg("\r\nCapacity = ");
  print_dbg_ulong(card_size*512);
  print_dbg(" Bytes\r\n");



  // Read the first sector number 0 of the card
  status = sd_mmc_mci_mem_2_ram(EXAMPLE_SD_SLOT, 0, buffer_in);
  if( status!=CTRL_GOOD )
  {
    print_dbg("\r\nERROR: can not read device.\r\n");
    return -1;
  }

  // Display the ram_buffer content
  print_dbg("\r\nFirst sector of the card:\r\n");
  for (i=0;i<(512);i++)
  {
    print_dbg_char_hex(buffer_in[i]);
    j++;
    if (j%32==0)
      print_dbg("\r\n"), j=0;
    else if (j%4==0)
      print_dbg(" ");
  }



  // Write some patterns in the first sector number 0 of the card
  print_dbg("Testing write.\r\n");
  if( !test_sd_mmc_write(0) ) return -1;
  if( !test_sd_mmc_write(1) ) return -1;
  if( !test_sd_mmc_write(2) ) return -1;
  if( !test_sd_mmc_write(3) ) return -1;


  // Bench single-block read operations without DMA
  //
  print_dbg("Benching single-block read (without DMA). Please wait...");
  n_sector =
  bench_start_sector = (card_size<BENCH_START_SECTOR) ? 0 : BENCH_START_SECTOR;

  cpu_set_timeout( cpu_ms_2_cy(BENCH_TIME_MS, pm_freq_param.cpu_f), &timer);
  while( !cpu_is_timeout(&timer) )
  {
    status = sd_mmc_mci_mem_2_ram(EXAMPLE_SD_SLOT, n_sector, buffer_in);
    if( status!=CTRL_GOOD )
    {
      print_dbg("\r\nERROR: can not read device.\r\n");
      return -1;
    }
    n_sector+=1;
  }
  display_perf_bps((((U64)n_sector-bench_start_sector)*512)/(BENCH_TIME_MS/1000));



  // Bench single-block read operations with DMA
  //
  print_dbg("Benching single-block read (with DMA).    Please wait...");
  n_sector =
  bench_start_sector = (card_size<BENCH_START_SECTOR) ? 0 : BENCH_START_SECTOR;

  cpu_set_timeout( cpu_ms_2_cy(BENCH_TIME_MS, pm_freq_param.cpu_f), &timer);
  while( !cpu_is_timeout(&timer) )
  {
    status = sd_mmc_mci_dma_mem_2_ram(EXAMPLE_SD_SLOT, n_sector, buffer_in);
    if( status!=CTRL_GOOD )
    {
      print_dbg("\r\nERROR: can not read device.\r\n");
      return -1;
    }
    n_sector+=1;
  }
  display_perf_bps((((U64)n_sector-bench_start_sector)*512)/(BENCH_TIME_MS/1000));



  // Bench multi-block read operations without DMA
  //
  print_dbg("Benching multi-block read  (without DMA). Please wait...");
  n_sector =
  bench_start_sector = (card_size<BENCH_START_SECTOR) ? 0 : BENCH_START_SECTOR;

  cpu_set_timeout( cpu_ms_2_cy(BENCH_TIME_MS, pm_freq_param.cpu_f), &timer);
  while( !cpu_is_timeout(&timer) )
  {
    status = sd_mmc_mci_multiple_mem_2_ram(EXAMPLE_SD_SLOT, n_sector, buffer_in, ALLOCATED_SECTORS);
    if( status!=CTRL_GOOD )
    {
      print_dbg("\r\nERROR: can not read device.\r\n");
      return -1;
    }
    n_sector+=ALLOCATED_SECTORS;
  }
  display_perf_bps((((U64)n_sector-bench_start_sector)*512)/(BENCH_TIME_MS/1000));



  // Bench multi-block read operations with DMA
  //
  print_dbg("Benching multi-block read  (with DMA).    Please wait...");
  n_sector =
  bench_start_sector = (card_size<BENCH_START_SECTOR) ? 0 : BENCH_START_SECTOR;

  cpu_set_timeout( cpu_ms_2_cy(BENCH_TIME_MS, pm_freq_param.cpu_f), &timer);
  while( !cpu_is_timeout(&timer) )
  {
    status = sd_mmc_mci_dma_multiple_mem_2_ram(EXAMPLE_SD_SLOT, n_sector, buffer_in, ALLOCATED_SECTORS);
    if( status!=CTRL_GOOD )
    {
      print_dbg("\r\nERROR: can not read device.\r\n");
      return -1;
    }
    n_sector+=ALLOCATED_SECTORS;
  }
  display_perf_bps((((U64)n_sector-bench_start_sector)*512)/(BENCH_TIME_MS/1000));



  // Bench single-block write operations without DMA
  //
  print_dbg("Benching single-block write (without DMA). Please wait...");
  status = sd_mmc_mci_mem_2_ram(EXAMPLE_SD_SLOT, 0, buffer_in); // Backup the first sector number 0 of the card
  if( status!=CTRL_GOOD )
  {
    print_dbg("\r\nERROR: can not read device.\r\n");
    return -1;
  }

  n_sector =
  bench_start_sector = (card_size<BENCH_START_SECTOR) ? 0 : BENCH_START_SECTOR;
  cpu_set_timeout( cpu_ms_2_cy(BENCH_TIME_MS, pm_freq_param.cpu_f), &timer);
  while( !cpu_is_timeout(&timer) )
  {
    status = sd_mmc_mci_ram_2_mem(EXAMPLE_SD_SLOT, n_sector, buffer_in);
    if( status!=CTRL_GOOD )
    {
      print_dbg("\r\nERROR: can not write device.\r\n");
      return -1;
    }
    n_sector+=1;
  }
  display_perf_bps((((U64)n_sector-bench_start_sector)*512)/(BENCH_TIME_MS/1000));



  // Bench single-block write operations with DMA
  //
  print_dbg("Benching single-block write (with DMA).    Please wait...");
  status = sd_mmc_mci_mem_2_ram(EXAMPLE_SD_SLOT, 0, buffer_in); // Backup the first sector number 0 of the card
  if( status!=CTRL_GOOD )
  {
    print_dbg("\r\nERROR: can not read device.\r\n");
    return -1;
  }

  n_sector =
  bench_start_sector = (card_size<BENCH_START_SECTOR) ? 0 : BENCH_START_SECTOR;
  cpu_set_timeout( cpu_ms_2_cy(BENCH_TIME_MS, pm_freq_param.cpu_f), &timer);
  while( !cpu_is_timeout(&timer) )
  {
    status = sd_mmc_mci_dma_ram_2_mem(EXAMPLE_SD_SLOT, n_sector, buffer_in);
    if( status!=CTRL_GOOD )
    {
      print_dbg("\r\nERROR: can not write device.\r\n");
      return -1;
    }
    n_sector+=1;
  }
  display_perf_bps((((U64)n_sector-bench_start_sector)*512)/(BENCH_TIME_MS/1000));



  // Bench multi-block write operations without DMA
  //
  print_dbg("Benching multi-block write  (without DMA). Please wait...");
  status = sd_mmc_mci_mem_2_ram(EXAMPLE_SD_SLOT, 0, buffer_in); // Backup the first sector number 0 of the card
  if( status!=CTRL_GOOD )
  {
    print_dbg("\r\nERROR: can not read device.\r\n");
    return -1;
  }

  n_sector =
  bench_start_sector = (card_size<BENCH_START_SECTOR) ? 0 : BENCH_START_SECTOR;
  cpu_set_timeout( cpu_ms_2_cy(BENCH_TIME_MS, pm_freq_param.cpu_f), &timer);
  while( !cpu_is_timeout(&timer) )
  {
    status = sd_mmc_mci_multiple_ram_2_mem(EXAMPLE_SD_SLOT, n_sector, buffer_in, ALLOCATED_SECTORS);
    if( status!=CTRL_GOOD )
    {
      print_dbg("\r\nERROR: can not write device.\r\n");
      return -1;
    }
    n_sector+=ALLOCATED_SECTORS;
  }
  display_perf_bps((((U64)n_sector-bench_start_sector)*512)/(BENCH_TIME_MS/1000));



  // Bench multi-block write operations with DMA
  //
  print_dbg("Benching multi-block write  (with DMA).    Please wait...");
  status = sd_mmc_mci_mem_2_ram(EXAMPLE_SD_SLOT, 0, buffer_in); // Backup the first sector number 0 of the card
  if( status!=CTRL_GOOD )
  {
    print_dbg("\r\nERROR: can not read device.\r\n");
    return -1;
  }

  n_sector =
  bench_start_sector = (card_size<BENCH_START_SECTOR) ? 0 : BENCH_START_SECTOR;
  cpu_set_timeout( cpu_ms_2_cy(BENCH_TIME_MS, pm_freq_param.cpu_f), &timer);
  while( !cpu_is_timeout(&timer) )
  {
    status = sd_mmc_mci_dma_multiple_ram_2_mem(EXAMPLE_SD_SLOT, n_sector, buffer_in, ALLOCATED_SECTORS);
    if( status!=CTRL_GOOD )
    {
      print_dbg("\r\nERROR: can not write device.\r\n");
      return -1;
    }
    n_sector+=ALLOCATED_SECTORS;
  }
  display_perf_bps((((U64)n_sector-bench_start_sector)*512)/(BENCH_TIME_MS/1000));

  return 0;
}
Ctrl_status sd_mmc_mci_read_capacity_1(uint32_t *nb_sector)
{
  return sd_mmc_mci_read_capacity(1, nb_sector);
}