-
Notifications
You must be signed in to change notification settings - Fork 1
/
SD_SPI_Erase.c
67 lines (51 loc) · 2.36 KB
/
SD_SPI_Erase.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//############################################################################
//
// FILE: SD_SPI_Erase.c
//
// TITLE: SD/MMC Erase Function
//
//############################################################################
// Author: Hecotr Ta
// Release Date: Dec 2021
//############################################################################
/* ***********************************************************
* You may not use the Program in non-TI devices.
* ********************************************************* */
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#include "SD.h" //SD Include File
//############################# SD_ERASE_BLOCK ###############################
void sd_erase_block(Uint16 starting_sector, Uint16 total_sectors)
{
CS_LOW; //Pull CS low
data_manipulation = TRUE; //Data manipulation function
//Transmit Erase Start Block Command
spi_xmit_command(ERASE_WR_BLK_START_ADDR, starting_sector, DUMMY_CRC);
RESET_RESPONSE; //Reset response
while(response != SUCCESS) //Wait until card responds with SUCCESS response
sd_command_response();
//After receiving response clock must be active for 8 clock cycles
EIGHT_CLOCK_CYCLE_DELAY;
//Add starting sector to total number of sectors to find ending address
total_sectors += starting_sector;
//Transmit Erase End Block command
spi_xmit_command(ERASE_WR_BLK_END_ADDR, total_sectors, DUMMY_CRC);
RESET_RESPONSE; //Reset response
while(response != SUCCESS) //Wait until card responds with SUCCESS response
sd_command_response();
//After receiving response clock must be active for 8 clock cycles
EIGHT_CLOCK_CYCLE_DELAY;
//Transmit ERASE command
spi_xmit_command(ERASE, STUFF_BITS, DUMMY_CRC);
RESET_RESPONSE; //Reset response
while(response != SUCCESS) //Wait until card responds with SUCCESS response
sd_command_response();
//Card will respond with the DATA OUT line pulled low if the card is still busy
//erasing. Continue checking DATA OUT line until line is released high.
while(response != DUMMY_DATA)
response = spi_xmit_byte(DUMMY_DATA);
CS_HIGH; //Pull CS high
//After receiving response clock must be active for 8 clock cycles
EIGHT_CLOCK_CYCLE_DELAY;
}
//############################# SD_ERASE_BLOCK ###############################