NetBurner 3.5.6
PDF Version
usdhc.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
5
6#ifndef _USDHC_H
7#define _USDHC_H
8
9#include <predef.h>
10#include <stdio.h>
11#include <init.h>
12#include <sim.h> /*on-chip register definitions*/
13#include <pins.h>
14#include <nbrtos.h>
15
16#include <sim.h>
17#include "effs_fat/sdhc_mcf.h"
18
19#ifndef __cplusplus
20#error eSDHC driver is a C++ only library
21#endif
22
23/*
24 USDHC state
25*/
26#define USDHC_OK ( 0 )
27#define USDHC_BUSY ( 1 )
28#define USDHC_ERROR ( 2 )
29#define USDHC_TIMEOUT ( 3 )
30
31//#define __DEBUG_USDHC // Enable debug messages
32
33#define DMA_MODE_SIMPLE 1
34//#define DMA_MODE_ADMA2 1
35#define USDHC_IRQ_MODE 1
36
37/*
38 *****************************************************************************-
39 *
40 * dspiDriverStruct
41 *
42 * This struct contains the major variables/configurations used for a eSDHC transfer
43 *
44 *
45 * OS_SEM* USDHC_Sem - This is a pointer to an external semaphore provided by ()
46 *
47 * uint8_t USDHC_INT_STATUS - Status of the spi device
48 *
49 *
50 *****************************************************************************-
51 */
52typedef struct
53{
54 void* pBlockData;
55 uint16_t BlockSize;
56 uint32_t BlocksCount;
57 uint32_t CmdMask;
58 uint32_t CmdMix;
59 uint32_t CmdArg;
60 OS_SEM* finishedSem;
61 void* pResp;
62 volatile uint8_t USDHC_INT_STATUS;
63 volatile BOOL USDHCfinished;
64} esdhcDriverStruct;
65
66class USDHCModule
67{
68 USDHC_Type &usdhc;
69 OS_CRIT m_critSec;
70 OS_SEM *m_finishedSem;
71 uint32_t m_actualBaudrate;
72 int m_bitWidth;
73
74public:
75 //static USDHCModule *lastCxts;
76 static esdhcDriverStruct tranCtx;
77 static bool m_inProgress;
78
79public:
80 USDHCModule(USDHC_Type &hw);
81 ~USDHCModule();
82
83 uint8_t Init(uint32_t Baudrate = 0, bool hw_reset = false);
84 void Reset(uint32_t Baudrate = INIT_BAUDRATE, bool hw_reset = true);
85 bool SetBaudrate(uint32_t Baudrate);
86 bool SetDataBusWidth(uint8_t width);
87 uint8_t GetDataBusWidth(void);
88 void ClearTransferStatus(bool abortTransfer = true);
89
90 void SetTimeouts(double rdTimeout_us, double wrTimeout_us);
91
92 bool RegisterSem( OS_SEM *finishedSem );
93 inline bool ClrSem() { return RegisterSem(NULL); }
94 inline OS_SEM * GetSem() { return m_finishedSem; }
95
96 uint8_t TransferCmd(uint8_t cmdIdx, uint32_t cmdArg = 0, void *cmdRsp = NULL);
97 uint8_t TransferCmdData(uint8_t cmdIdx, uint32_t cmdArg,
98 bool dataRead, void *blkData,
99 uint16_t blk_size, uint16_t blkCount = 1,
100 void *cmdRsp = NULL, bool autoCMD12 = true);
101 uint8_t GetTransferStatus();
102 bool AbortTransfer(uint32_t timeout, bool force = false);
103
104 inline bool Done() { return !m_inProgress; }
105
106 inline uint32_t GetActualBaudrate() { return m_actualBaudrate; }
107
108 bool CardReady();
109
110#ifndef USDHC_IRQ_MODE
111 static uint8_t send_cmd(unsigned long cmd_index, unsigned long cmd_arg = 0, void *resp_data= NULL);
112 static uint8_t send_cmd_dt(unsigned long cmd_index, unsigned long cmd_arg,
113 void *data, unsigned short data_size,
114 void *resp_data = NULL);
115 //static uint8_t read_block(int drv, unsigned long blk_addr, unsigned short blk_size, void *buff);
116 //static uint8_t write_block(int drv, unsigned long blk_addr, unsigned short blk_size, void *buff);
117#endif
118
119private:
120 bool TransferDone(bool dataPresent = true);
121
122 uint32_t mRdDTOCV;
123 uint32_t mWrDTOCV;
124};
125
126#endif /* _USDHC_H_ */