drivers/storage/spi_sdcard.c
/*
 * sd_spi_send_cmd - helper function to send a SPI command
 *
 * @cmd - the requested commands
 * @arguments - <optional> the command argument
 *
 */
helper function to send a SPI command
@cmd - the requested commands
@arguments -  the command argument
helper function to send a SPI command @cmd - the requested commands @arguments - the command argument
static void sd_spi_send_cmd(uint8_t cmd, uint32_t arguments)
{
  uint8_t sd_card_cmd[SPI_CMD_LEN];
  uint8_t crc7 = 0;
  uint8_t res = 0;
  g_rsp_index = 0;
  sd_spi_set_cs(0);
#if IS_BIG_ENDIAN
#error "Unsupported endianness"
#endif
  sd_card_cmd[0] = (cmd & 0x3f) | 0x40;
  crc7 = sd_crc_add(crc7, sd_card_cmd[0]);
  sd_card_cmd[1] = (arguments & 0xFF000000) >> 24;
  crc7 = sd_crc_add(crc7, sd_card_cmd[1]);
  sd_card_cmd[2] = (arguments & 0xFF0000) >> 16;
  crc7 = sd_crc_add(crc7, sd_card_cmd[2]);
  sd_card_cmd[3] = (arguments & 0xFF00) >> 8;
  crc7 = sd_crc_add(crc7, sd_card_cmd[3]);
  sd_card_cmd[4] = arguments & 0xFF;
  crc7 = sd_crc_add(crc7, sd_card_cmd[4]);
  sd_card_cmd[5] = (crc7 << 1) | 0x1;
  memset(g_sd_resp, 0xFF, sizeof(g_sd_resp));
  spi_send_recv(g_sd_spi, sd_card_cmd, sizeof(sd_card_cmd), g_sd_resp,
                sizeof(g_sd_resp));
  sd_spi_set_cs(1);
#ifdef CONFIG_DEBUG_SD_CARD
  for (int i = 6; i < sizeof(g_sd_resp); i++) {
    printf("\r\n0x%x,", g_sd_resp[i]);
  }
  printf("\r\n");
#endif
}
static void sd_spi_send_cmd ( uint8_t cmd , uint32_t arguments ) { uint8_t sd_card_cmd [ SPI_CMD_LEN ] ; uint8_t crc7 = 0 ; uint8_t res = 0 ; g_rsp_index = 0 ; sd_spi_set_cs ( 0 ) ; #if IS_BIG_ENDIAN #error  "Unsupported endianness" #endif sd_card_cmd [ 0 ] = ( cmd & 0x3f ) | 0x40 ; crc7 = sd_crc_add ( crc7 , sd_card_cmd [ 0 ] ) ; sd_card_cmd [ 1 ] = ( arguments & 0xFF000000 ) >> 24 ; crc7 = sd_crc_add ( crc7 , sd_card_cmd [ 1 ] ) ; sd_card_cmd [ 2 ] = ( arguments & 0xFF0000 ) >> 16 ; crc7 = sd_crc_add ( crc7 , sd_card_cmd [ 2 ] ) ; sd_card_cmd [ 3 ] = ( arguments & 0xFF00 ) >> 8 ; crc7 = sd_crc_add ( crc7 , sd_card_cmd [ 3 ] ) ; sd_card_cmd [ 4 ] = arguments & 0xFF ; crc7 = sd_crc_add ( crc7 , sd_card_cmd [ 4 ] ) ; sd_card_cmd [ 5 ] = ( crc7 << 1 ) | 0x1 ; memset ( g_sd_resp , 0xFF , sizeof ( g_sd_resp ) ) ; spi_send_recv ( g_sd_spi , sd_card_cmd , sizeof ( sd_card_cmd ) , g_sd_resp , sizeof ( g_sd_resp ) ) ; sd_spi_set_cs ( 1 ) ; #ifdef CONFIG_DEBUG_SD_CARD for ( int i = 6 ; i < sizeof ( g_sd_resp ) ; i ++ ) { printf ( " \r \n " , g_sd_resp [ i ] ) ; } printf ( " \r \n " ) ; #endif }
sd_spi_send_cmd - helper function to send a SPI command
 @cmd - the requested commands
 @arguments - <optional> the command argument
sd_spi_send_cmd - helper function to send a SPI command @cmd - the requested commands @arguments - <optional > the command argument
/* Start bit (value 0) followed by transmission bit (value 1)
   * followed by cmd (6 bits).
   */ /* CRC7 (7 bits) + end bit (1 bit) */