Use dmac for data blk transfer from sd. Fix set bus with function. Clean up.
[bertos.git] / bertos / drv / sd.h
index c9eff3c0926a00cb0ca40174c2cdb6d82d373c8c..d706038beed1ac31830f3c3128608917ec1bd0ab 100644 (file)
@@ -81,26 +81,12 @@ typedef struct SDcsd
 } SDcsd;
 
 
-typedef struct SDAddr
-{
-       uint32_t rca;
-       uint32_t status;
-} SDAddr;
-
-int sd_decode_csd(SDcsd *csd, uint32_t *resp, size_t len);
-void sd_dump_csd(SDcsd *csd);
-void sd_decode_cid(SDcid *cid, uint32_t *resp, size_t len);
-void sd_dump_cid(SDcid *cid);
-void sd_send_init(void);
-void sd_go_idle(void);
-int sd_send_if_cond(void);
-int sd_send_app_op_cond(void);
-int sd_get_cid(uint32_t *resp, size_t len);
-int sd_get_csd(uint32_t *resp, size_t len);
-int sd_app_status(uint32_t *resp, size_t len);
-int sd_send_relative_addr(uint32_t *resp, size_t len);
-void sd_decode_addr(SDAddr *addr, uint32_t *resp, size_t len);
-void sd_dump_addr(SDAddr *addr);
+#define SD_READY_FOR_DATA         BV(8)
+#define SD_CARD_IS_LOCKED         BV(25)
+
+#define SD_SEND_CID_RCA     0
+#define SD_SEND_ALL_CID   BV(0)
+
 #endif
 
 
@@ -111,15 +97,63 @@ void sd_dump_addr(SDAddr *addr);
  */
 typedef struct Sd
 {
+
        KBlock b;   ///< KBlock base class
        KFile *ch;  ///< SPI communication channel
        uint16_t r1;  ///< Last status data received from SD
        uint16_t tranfer_len; ///< Lenght for the read/write commands, cached in order to increase speed.
+
+       #if CPU_CM3_SAM3X8
+       SDcid cid;
+       SDcsd csd;
+       uint32_t addr;
+       uint32_t status;
+       #endif
+
 } Sd;
 
 bool sd_initUnbuf(Sd *sd, KFile *ch);
 bool sd_initBuf(Sd *sd, KFile *ch);
 
+
+#if CPU_CM3_SAM3X8
+
+void sd_dumpCsd(Sd *sd);
+void sd_dumpCid(Sd *sd);
+
+void sd_sendInit(void);
+void sd_goIdle(void);
+int sd_sendIfCond(void);
+int sd_sendAppOpCond(void);
+
+int sd_getCid(Sd *sd, uint32_t addr, uint8_t flag);
+int sd_getCsd(Sd *sd);
+int sd_getSrc(Sd *sd);
+
+int sd_appStatus(Sd *sd);
+int sd_getRelativeAddr(Sd *sd);
+
+int sd_selectCard(Sd *sd);
+int sd_deSelectCard(Sd *sd);
+int sd_setBusWidth(Sd *sd, size_t len);
+int sd_set_BlockLen(Sd *sd, size_t len);
+
+int sd_readSingleBlock(Sd *sd, size_t index, void *_buf, size_t len);
+
+
+INLINE int sd_setBus4bit(Sd *sd)
+{
+       return sd_setBusWidth(sd, 1);
+}
+
+INLINE int sd_setBus1bit(Sd *sd)
+{
+       return sd_setBusWidth(sd, 0);
+}
+
+#endif
+
+
 #if CONFIG_SD_OLD_INIT
        #if !(ARCH & ARCH_NIGHTTEST)
                #warning "Deprecated: this API will be removed in the next major release,"
@@ -171,3 +205,4 @@ INLINE Sd *SD_CAST(KBlock *b)
 }
 
 #endif /* DRV_SD_H */
+