NetBurner 3.5.6
PDF Version
sdhc_mcf.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
5#ifndef _SDHC_H_
6#define _SDHC_H_
7
8#include "fat.h"
9//#include "common.h"
10#include "effs_fat/common.h"
11
12#ifdef __cplusplus
13extern "C"
14{
15#endif
16
17// Logging levels
18#define SDHC_LOG_LEVEL_OFF (0)
19#define SDHC_LOG_LEVEL_INFO (1)
20#define SDHC_LOG_LEVEL_WARNING (2)
21#define SDHC_LOG_LEVEL_ERROR (3)
22#define SDHC_LOG_LEVEL_DEBUG (4)
23
24#ifdef _DEBUG
25//#undef SDHC_LOG_LEVEL
26#define SDHC_LOG_LEVEL SDHC_LOG_LEVEL_DEBUG // Secify appropriate logging level here if required
27#else
28//#define SDHC_LOG_LEVEL SDHC_LOG_LEVEL_DEBUG // Secify appropriate logging level here if required
29#define SDHC_LOG_LEVEL SDHC_LOG_LEVEL_OFF // Secify appropriate logging level here if required
30#endif
31
32#define IsLogEnabled(x) (SDHC_LOG_LEVEL >= x)
33
34#if defined(SDHC_LOG_LEVEL) && (SDHC_LOG_LEVEL != SDHC_LOG_LEVEL_OFF)
35
36#include <stdio.h>
37
38#if (SDHC_LOG_LEVEL >= SDHC_LOG_LEVEL_INFO)
39#define SDHC_LOG_INFO(args...) iprintf(args)
40#else
41#define SDHC_LOG_INFO(args...)
42#endif
43
44#if (SDHC_LOG_LEVEL >= SDHC_LOG_LEVEL_WARNING)
45#define SDHC_LOG_WARNING(args...) iprintf(args)
46#else
47#define SDHC_LOG_WARNING(...)
48#endif
49
50#if (SDHC_LOG_LEVEL >= SDHC_LOG_LEVEL_ERROR)
51#define SDHC_LOG_ERROR(args...) iprintf(args)
52#else
53#define SDHC_LOG_ERROR(...)
54#endif
55
56#if (SDHC_LOG_LEVEL >= SDHC_LOG_LEVEL_DEBUG)
57#define SDHC_LOG_DEBUG(args...) iprintf(args)
58#else
59#define SDHC_LOG_DEBUG(...)
60#endif
61
62#else
63#define SDHC_LOG_INFO(...)
64#define SDHC_LOG_WARNING(...)
65#define SDHC_LOG_ERROR(...)
66#define SDHC_LOG_DEBUG(...)
67#endif
68
69#define SDHC_LOG_LINE SDHC_LOG_DEBUG("Got to line %d in file %s\r\n", __LINE__, __FILE__);
70#define SDHC_LOG_FUNC(args...) \
71 { \
72 SDHC_LOG_DEBUG("%s: ", __FUNCTION__); \
73 SDHC_LOG_DEBUG(args); \
74 }
75#define SDHC_LOG_TICK(args...) // SDHC_LOG_INFO("%s: %lu, %s\n\r", __FUNCTION__, TimeTick, args);
76
77#define MAX_SDHC_DRIVES (1)
78#define F_SDHC_DRIVE0 0
79//#define F_SDHC_AUTOASSIGN -1
80
81//#define ENABLE_HIGH_SPEED_MODE (1) // Uncomment to enable High Speed Mode if supported
82//#define ENABLE_PREERASE (1) // Enables execution of pre-erase command (can increase write speed on some cards)
83//#define ENABLE_BLOCS_COUNT_CMD (1)
84#define ESDHC_ENDIAN_CONVERSION (1) // Must be define to make card format compatible with PC
85
86#define CMD_RETRIES_COUNT 1
87#define DAT_RETRIES_COUNT 3
88#define SECTOR_SIZE ((uint32_t)F_SECTOR_SIZE)
89#define RW_BUFF_SECTORS (128UL)
90
91#define INIT_BAUDRATE (100000UL) // Hz
92#define WORK_BAUDRATE (25000000UL) // Hz
93#ifdef __MIMXRT10xx__
94#define ENABLE_HIGH_SPEED_MODE (1) // Uncomment to enable High Speed Mode if supported
95#define HIGHSPED_BAUDRATE (50000000UL) //(50000000UL)
96#else
97#define HIGHSPED_BAUDRATE (31250000) //(50000000UL)
98#endif
99
100#define ESDHC_IRQ_LEVEL (5U) // Defines the IRQ level of ESDHC interrupt routine 0-6, 0 - auto
101
102 int sdhc_init(int drv); /* Init SDHC drive */
103 int sdhc_close(int drv); /* Init SDHC drive */
104
105 int sdhc_read(int drv, void *buff, unsigned long sector, unsigned int count); /* Read data from SDHC device */
106 int sdhc_write(int drv, void *buff, unsigned long sector, unsigned int count); /* Write data to SDHC device*/
107 int sdhc_get_cd(int drv); /* Get Card Detect state */
108 int sdhc_get_wp(int drv); /* Get Write Protect state */
109 int sdhc_check_card_status(int drv);
110 void sdhc_init_card(int drv);
111 unsigned long sdhc_get_card_size(int drv);
112
113 extern F_DRIVER *sdhc_initfunc(unsigned long driver_param);
114
115 enum
116 {
117 SDHC_NO_ERROR,
118 SDHC_ERR_NOTINITIALIZED = 101,
119 SDHC_ERR_INIT,
120 SDHC_ERROR, // A general or an unknown error occurred during the operation
121 SDHC_ERR_CMD,
122 SDHC_ERR_TIMEOUT,
123 SDHC_ERR_BUSY,
124 SDHC_ERR_CRC,
125 SDHC_ERR_READ,
126 SDHC_ERR_WRITE,
127 SDHC_ERR_WRITEPROTECT,
128 SDHC_ERR_LOCKED,
129 SDHC_ERR_NOTAVAILABLE
130 };
131
132#ifdef __cplusplus
133}
134#endif
135
136/******************************************************************************
137 *
138 * end of sdhc_mcf.h
139 *
140 *****************************************************************************/
141
142#endif /* _SDHC_H_ */