kernel/sdcard.c
static int check_block_size(void) {
	uint8 result = 0xff;
	uint8 ocr[4];

	int timeout = 0xff;
	while (timeout --) {
		sd_send_cmd(SD_CMD58, 0, 0);
		result = sd_get_response_R1();
		sd_get_response_R3_rest(ocr);
		sd_end_cmd();

		if (0 == result) {
			if (ocr[0] & 0x40) {
				printf("SDHC/SDXC detected\n");
				if (512 != BSIZE) {
					printf("BSIZE != 512\n");
					return 0xff;
				}

				is_standard_sd = 0;
			}
			else {
				printf("SDSC detected, setting block size\n");

				// setting SD card block size to BSIZE 
				int timeout = 0xff;
				int result = 0xff;
				while (--timeout) {
					sd_send_cmd(SD_CMD16, BSIZE, 0);
					result = sd_get_response_R1();
					sd_end_cmd();

					if (0 == result) break;
				}
				if (0 == timeout) {
					printf("check_OCR(): fail to set block size");
					return 0xff;
				}

				is_standard_sd = 1;
			}

			return 0;
		}
	}

	// timeout! 
	printf("check_OCR() timeout!\n");
	printf("result = %d\n", result);
	return 0xff;
}
// check OCR register to see the type of sdcard, 
// thus determine whether block size is suitable to buffer size
check OCR register to see the type of sdcard,
thus determine whether block size is suitable to buffer size
check OCR register to see the type of sdcard thus determine whether block size is suitable to buffer size
static int check_block_size(void) {
	uint8 result = 0xff;
	uint8 ocr[4];
	int timeout = 0xff;
	while (timeout --) {
		sd_send_cmd(SD_CMD58, 0, 0);
		result = sd_get_response_R1();
		sd_get_response_R3_rest(ocr);
		sd_end_cmd();
		if (0 == result) {
			if (ocr[0] & 0x40) {
				printf("SDHC/SDXC detected\n");
				if (512 != BSIZE) {
					printf("BSIZE != 512\n");
					return 0xff;
				}
				is_standard_sd = 0;
			}
			else {
				printf("SDSC detected, setting block size\n");
				int timeout = 0xff;
				int result = 0xff;
				while (--timeout) {
					sd_send_cmd(SD_CMD16, BSIZE, 0);
					result = sd_get_response_R1();
					sd_end_cmd();
					if (0 == result) break;
				}
				if (0 == timeout) {
					printf("check_OCR(): fail to set block size");
					return 0xff;
				}
				is_standard_sd = 1;
			}
			return 0;
		}
	}
	printf("check_OCR() timeout!\n");
	printf("result = %d\n", result);
	return 0xff;
}
static int check_block_size ( void ) { uint8 result = 0xff ; uint8 ocr [ 4 ] ; int timeout = 0xff ; while ( timeout -- ) { sd_send_cmd ( SD_CMD58 , 0 , 0 ) ; result = sd_get_response_R1 ( ) ; sd_get_response_R3_rest ( ocr ) ; sd_end_cmd ( ) ; if ( 0 == result ) { if ( ocr [ 0 ] & 0x40 ) { printf ( " \n " ) ; if ( 512 != BSIZE ) { printf ( " \n " ) ; return 0xff ; } is_standard_sd = 0 ; } else { printf ( " \n " ) ; int timeout = 0xff ; int result = 0xff ; while ( -- timeout ) { sd_send_cmd ( SD_CMD16 , BSIZE , 0 ) ; result = sd_get_response_R1 ( ) ; sd_end_cmd ( ) ; if ( 0 == result ) break ; } if ( 0 == timeout ) { printf ( " " ) ; return 0xff ; } is_standard_sd = 1 ; } return 0 ; } } printf ( " \n " ) ; printf ( " \n " , result ) ; return 0xff ; }
check OCR register to see the type of sdcard,
thus determine whether block size is suitable to buffer size
check OCR register to see the type of sdcard thus determine whether block size is suitable to buffer size
// setting SD card block size to BSIZE  // timeout! 