Permalink
Browse files

removed HardwareSDIO, moved functions to sdmc library

  • Loading branch information...
Brian E Tovar
Brian E Tovar committed Apr 23, 2012
1 parent 554e389 commit 2f59b2819aacfdc2e7c585f6c2624ace92af0f56
View
@@ -99,7 +99,8 @@ void sdio_cfg_clkcr(sdio_dev *dev, uint32 spc, uint32 val) {
spc = (~SDIO_CLKCR_RESERVED & spc);
uint32 temp = dev->regs->CLKCR;
temp &= ~spc;
- dev->regs->CLKCR |= (spc & val);
+ temp |= (spc & val);
+ dev->regs->CLKCR = temp;
}
/**
@@ -158,39 +159,87 @@ void sdio_cfg_gpio(sdio_dev *dev, uint8 width) {
*/
/**
- * @brief Enable an SDIO peripheral
+ * @brief Enable SDIO Command Path State Machine
+ * @param dev SDIO Device
+ */
+void sdio_cpsm_enable(sdio_dev *dev) {
+ bb_peri_set_bit(&dev->regs->CMD, SDIO_CMD_CPSMEN_BIT, 1);
+}
+
+/**
+ * @brief Disable SDIO Command Path State Machine
+ * @param dev SDIO Device
+ */
+void sdio_cpsm_disable(sdio_dev *dev) {
+ bb_peri_set_bit(&dev->regs->CMD, SDIO_CMD_CPSMEN_BIT, 0);
+}
+
+/**
+ * @brief Enable SDIO HardWare Flow Control
+ * @param dev SDIO Device
+ */
+void sdio_hwfc_enable(sdio_dev *dev) {
+ bb_peri_set_bit(&dev->regs->CLKCR, SDIO_CLKCR_HWFC_EN_BIT, 1);
+}
+
+/**
+ * @brief Disable SDIO HardWare Flow Control
+ * @param dev SDIO Device
+ */
+void sdio_hwfc_disable(sdio_dev *dev) {
+ bb_peri_set_bit(&dev->regs->CLKCR, SDIO_CLKCR_HWFC_EN_BIT, 0);
+}
+
+/**
+ * @brief Enable SDIO Data Transfer
+ * @param dev SDIO Device
+ */
+void sdio_dt_enable(sdio_dev *dev) {
+ bb_peri_set_bit(&dev->regs->DCTRL, SDIO_DCTRL_DTEN_BIT, 1);
+}
+
+/**
+ * @brief Disable SDIO Data Transfer
+ * @param dev SDIO Device
+ */
+void sdio_dt_disable(sdio_dev *dev) {
+ bb_peri_set_bit(&dev->regs->DCTRL, SDIO_DCTRL_DTEN_BIT, 0);
+}
+
+/**
+ * @brief Enable SDIO peripheral clock
* @param dev SDIO Device
*/
-void sdio_peripheral_enable(sdio_dev *dev) {
- bb_peri_set_bit(&dev->regs->DCTRL, SDIO_DCTRL_SDIOEN_BIT, 1);
+void sdio_clock_enable(sdio_dev *dev) {
+ bb_peri_set_bit(&dev->regs->CLKCR, SDIO_CLKCR_CLKEN_BIT, 1);
}
/**
- * @brief Disable an SDIO peripheral
+ * @brief Disable SDIO peripheral clock
* @param dev SDIO Device
*/
-void sdio_peripheral_disable(sdio_dev *dev) {
- bb_peri_set_bit(&dev->regs->DCTRL, SDIO_DCTRL_SDIOEN_BIT, 0);
+void sdio_clock_disable(sdio_dev *dev) {
+ bb_peri_set_bit(&dev->regs->CLKCR, SDIO_CLKCR_CLKEN_BIT, 0);
}
/**
- * @brief Enable DMA requests whenever the transmit buffer is empty
+ * @brief Enable DMA requests
* @param dev SDIO device
*/
void sdio_dma_enable(sdio_dev *dev) {
bb_peri_set_bit(&dev->regs->DCTRL, SDIO_DCTRL_DMAEN_BIT, 1);
}
/**
- * @brief Disable DMA requests whenever the transmit buffer is empty
+ * @brief Disable DMA requests
* @param dev SDIO device
*/
void sdio_dma_disable(sdio_dev *dev) {
bb_peri_set_bit(&dev->regs->DCTRL, SDIO_DCTRL_DMAEN_BIT, 0);
}
/**
- * @brief
+ * @brief Configure DMA
* @param dev SDIO device
*/
void sdio_cfg_dma(sdio_dev *dev) {
View
@@ -344,8 +344,14 @@ void sdio_cfg_clkcr(sdio_dev *dev, uint32 spc, uint32 val);
void sdio_cfg_clock(sdio_dev *dev, uint8 div);
void sdio_cfg_gpio(sdio_dev *dev, uint8 width);
// SDIO hardware functions
-void sdio_peripheral_enable(sdio_dev *dev);
-void sdio_peripheral_disable(sdio_dev *dev);
+void sdio_cpsm_enable(sdio_dev *dev);
+void sdio_cpsm_disable(sdio_dev *dev);
+void sdio_hwfc_enable(sdio_dev *dev);
+void sdio_hwfc_disable(sdio_dev *dev);
+void sdio_dt_enable(sdio_dev *dev);
+void sdio_dt_disable(sdio_dev *dev);
+void sdio_clock_enable(sdio_dev *dev);
+void sdio_clock_disable(sdio_dev *dev);
void sdio_dma_enable(sdio_dev *dev);
void sdio_dma_disable(sdio_dev *dev);
void sdio_cfg_dma(sdio_dev *dev);
@@ -24,9 +24,10 @@
* SOFTWARE.
*****************************************************************************/
-/** @file Commands.h
- * @breif List of card commands for all SecureDigital and MultiMedia cards
-*/
+/**
+ * @file Commands.h
+ * @breif List of card commands for all SecureDigital and MultiMedia cards
+ */
#ifndef _SD_COMMANDS_H_
#define _SD_COMMANDS_H_
@@ -25,19 +25,76 @@
*****************************************************************************/
/**
- * @file SecureDigitalMemoryCard.cpp
+ * @file SDMC.cpp
* @author Brian E Tovar <betovar@leaflabs.com>
- * @brief Wirish SD card implementation using HardwareSDIO.
+ * @brief Wirish SD Memory Card implementation
*/
#include "SDMC.h"
+#include "wirish.h"
+#include "util.h"
+#include "rcc.h"
+#if CYCLES_PER_MICROSECOND != 72
+/* TODO [0.2.0?] something smarter than this */
+#warning "Unexpected clock speed; SDIO frequency calculation will be incorrect"
+#endif
+
+#define SDIO_HOST_CAPACITY_SUPPORT (0x1 << 30)
+#define SDIO_FAST_BOOT (0x1 << 29) //Reserved or eSD cards
+#define SDIO_SDXC_POWER_CONTROL (0x1 << 28)
+#define SDIO_SWITCH_1V8_REQUEST (0x1 << 24)
+#define SDIO_CHECK_PATTERN 0xAA
+#define SDIO_HOST_SUPPLY_VOLTAGE 0x1
+
+
+/**
+ * @brief Constructor
+ */
SecureDigitalMemoryCard::SecureDigitalMemoryCard() {
+ this->sdio_d = SDIO;
+}
+
+/**
+ * Public Members
+ */
+
+/**
+ * @brief
+ */
+void SecureDigitalMemoryCard::begin(void) {
+ sdio_cpsm_enable(this->sdio_d);
+ sdio_cfg_clkcr(this->sdio_d, SDIO_CLKCR_WIDBUS, 0);
+ sdio_cfg_gpio(this->sdio_d, (uint8)SDIO_DBW_1);
+ sdio_cfg_clock(this->sdio_d, (uint8)SDIO_INIT_FREQ);
+ //FIXME seven HCLK clock periods are needed between two write accesses
+ sdio_clock_enable(this->sdio_d);
+ sdio_init(this->sdio_d);
}
- /*
- * Setup functions
+/**
+ * @brief
+ */
+void SecureDigitalMemoryCard::end(void) {
+ sdio_reset(this->sdio_d);
+}
+
+/**
+ * @brief
*/
+void SecureDigitalMemoryCard::power(SDIOPowerState pwr) {
+ switch (pwr) {
+ case SDIO_PWR_ON:
+ sdio_power(this->sdio_d, SDIO_POWER_ON);
+ break;
+ case SDIO_PWR_OFF:
+ sdio_power(this->sdio_d, SDIO_POWER_OFF);
+ break;
+ default:
+ SerialUSB.println("SDIO_ERR: Invalid power state");
+ }//end of switch
+}
+
/**
* @brief Initialize the card
@@ -50,17 +107,15 @@ void SecureDigitalMemoryCard::init(void) {
(SDIO_HOST_SUPPLY_VOLTAGE << 8) || SDIO_CHECK_PATTERN,
SDIO_WRSP_SHRT,
(uint32*)&R7);
- uint32 arg;
- while (sdio_get_cmd() != (uint8)SEND_IF_COND) {
+ uint32 arg;
+
+ if ((R7.CHECK_PATTERN != SDIO_CHECK_PATTERN) ||
+ (R7.VOLTAGE_ACCEPTED != SDIO_HOST_SUPPLY_VOLTAGE) ) {
+ SerialUSB.println("SDIO_ERR: Unusuable Card");
+ return;
}
- if (R7 != 0) {
- if ( (R7.CHECK_PATTERN != SDIO_CHECK_PATTERN) ||
- (R7.VOLTAGE_ACCEPTED != SDIO_HOST_SUPPLY_VOLTAGE) ) {
- SerialUSB.println("SDIO_ERR: Unusuable Card");
- return;
- }
- arg = SDIO_HOST_CAPACITY_SUPPORT;
+ arg = SDIO_HOST_CAPACITY_SUPPORT;
} else {
/** the host should set HCS to 0 if the card returns no response to CMD8 */
arg = 0;
@@ -69,12 +124,8 @@ void SecureDigitalMemoryCard::init(void) {
arg,
SDIO_WRSP_SHRT,
(uint32*)&this->OCR);
- if (OCR != 0) {
- } else {
- SerialUSB.println("SDIO_ERR: Not SD Card");
- }
- uint32 timeout = 1000;
+ timeout = 1000;
while (OCR.BUSY != 0) {
this->getOCR(); //ACMD41: first ACMD41
if (OCR.VOLTAGE_WINDOW || (0x3 << 20)) {
@@ -113,7 +164,7 @@ void SecureDigitalMemoryCard::bus(SDIODataBusWidth width) {
case SDIO_DBW_4:
sdio_cfg_clkcr(this->sdio_d,
SDIO_CLKCR_WIDBUS,
- ((uint8)width << SDIO_CLKCR_WIDBUS_BIT));
+ ((uint32)width << SDIO_CLKCR_WIDBUS_BIT));
sdio_cfg_gpio(this->sdio_d, (uint8)width);
/** send command to set bus width in card: ACMD6 or (SDIO)CMD52 */
csr status;
@@ -139,7 +190,7 @@ void SecureDigitalMemoryCard::stop(void) {
}
/**
- Command and App Command wrapper functions
+ * Command and App Command wrapper functions
*/
/**
@@ -172,6 +223,26 @@ void SecureDigitalMemoryCard::cmd(SDIOCommand cmd,
uint32 *resp) {
uint8 indx = ((uint8)wrsp << 6) || (uint8)cmd;
this->send(indx, arg, resp);
+ sdio_load_arg(this->sdio_d, arg);
+ sdio_send_cmd(this->sdio_d, idx);
+ //check cmdsent
+ while (sdio_get_status(this->sdio_d, SDIO_STA_CMDSENT) != 1) {
+ if (sdio_get_status(this->sdio_d, SDIO_STA_CTIMEOUT == 1)) {
+ return;
+ }
+ }
+ sdio_clear_interrupt(this->sdio_d, SDIO_STA_CMDSENT);
+ //check cmdresp
+ while (sdio_get_status(this->sdio_d, SDIO_STA_CMDREND) != 1) {
+ if (sdio_get_status(this->sdio_d, SDIO_STA_CTIMEOUT == 1)) {
+ return;
+ }
+ }
+ sdio_clear_interrupt(this->sdio_d, SDIO_STA_CMDREND);
+ //check crc
+ if (sdio_get_status(this->sdio_d, SDIO_STA_CCRCFAIL) != 1) {
+ sdio_get_resp_long(this->sdio_d, (uint32*)resp);
+ }
}
/**
@@ -213,7 +284,7 @@ void SecureDigitalMemoryCard::acmd(SDIOAppCommand acmd,
this->send(indx, arg, resp);
}
-/*
+/**
* Card register functions
*/
@@ -262,6 +333,35 @@ void SecureDigitalMemoryCard::setDSR(void) {
this->cmd(SET_DSR, ((uint32)DSR << 16));
}
- /*
+/**
* I/O
*/
+
+ /**
+ * @brief Read next word from FIFO
+ * @retval Data that was read from FIFO
+ */
+uint32 HardwareSDIO::read(void) {
+ return sdio_read_data(this->sdio_d);
+/**
+ uint32 rxed = 0;
+ while (rxed < len) {
+ while (!spi_is_rx_nonempty(this->spi_d))
+ buf[rxed++] = (uint8)spi_rx_reg(this->spi_d);
+ }
+ */
+}
+
+/**
+ * @brief Write next word into FIFO
+ * @param word Data to write to FIFO
+ */
+void HardwareSDIO::write(const uint32 word) {
+ sdio_write_data(this->sdio_d, word);
+/**
+ uint32 txed = 0;
+ while (txed < length) {
+ txed += spi_tx(this->spi_d, data + txed, length - txed);
+ }
+ */
+}
Oops, something went wrong.

0 comments on commit 2f59b28

Please sign in to comment.