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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
/*
* Copyright : (C) 2022 Phytium Information Technology, Inc.
* All Rights Reserved.
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
* FilePath: fsdmmc.h
* Date: 2022-02-10 14:53:42
* LastEditTime: 2022-02-18 08:55:57
* Description: This files is for
*
* Modify History:
* Ver Who Date Changes
* ----- ------ -------- --------------------------------------
* 1.0 zhugengyu 2021/12/2 init
*/
#ifndef DRIVERS_MMC_FSDMMC_H
#define DRIVERS_MMC_FSDMMC_H
#ifdef __cplusplus
extern "C"
{
#endif
/***************************** Include Files *********************************/
#include "ftypes.h"
#include "ferror_code.h"
#include "fkernel.h"
/************************** Constant Definitions *****************************/
#define FSDMMC_SUCCESS FT_SUCCESS
#define FSDMMC_ERR_NOT_READY FT_MAKE_ERRCODE(ErrModBsp, ErrBspMmc, 1)
#define FSDMMC_ERR_TIMEOUT FT_MAKE_ERRCODE(ErrModBsp, ErrBspMmc, 2)
#define FSDMMC_ERR_CMD_FAILED FT_MAKE_ERRCODE(ErrModBsp, ErrBspMmc, 3)
#define FSDMMC_ERR_DATA_FAILED FT_MAKE_ERRCODE(ErrModBsp, ErrBspMmc, 4)
#define FSDMMC_ERR_CARD_NO_FOUND FT_MAKE_ERRCODE(ErrModBsp, ErrBspMmc, 5)
#define FSDMMC_ERR_INVALID_BUF FT_MAKE_ERRCODE(ErrModBsp, ErrBspMmc, 6)
/**************************** Type Definitions *******************************/
enum
{
FSDMMC_DMA_BD_INTR = 0,
FSDMMC_CMD_INTR,
FSDMMC_ERROR_INTR,
FSDMMC_INTR_NUM
}; /* 中断类型 */
enum
{
FSDMMC_EVT_CARD_REMOVED = 0,
FSDMMC_EVT_CMD_DONE,
FSDMMC_EVT_CMD_ERROR,
FSDMMC_EVT_CMD_RESP_ERROR,
FSDMMC_EVT_DATA_ERROR,
FSDMMC_EVT_DATA_READ_DONE,
FSDMMC_EVT_DATA_WRITE_DONE,
FSDMMC_EVT_NUM
}; /* 事件类型 */
/**
* This typedef contains data information for the device.
*/
typedef struct
{
u8 *buf;
u32 blksz;
u32 blkcnt;
u32 datalen;
} FSdmmcData;
/**
* This typedef contains command information for the device.
*/
typedef struct
{
u32 cmdidx;
u32 cmdarg;
u32 resptype;
u32 response[4];
u32 flag;
#define FSDMMC_CMD_FLAG_NEED_STOP BIT(0)
#define FSDMMC_CMD_FLAG_NEED_INIT BIT(1)
#define FSDMMC_CMD_FLAG_EXP_RESP BIT(2)
#define FSDMMC_CMD_FLAG_EXP_LONG_RESP BIT(3)
#define FSDMMC_CMD_FLAG_NEED_RESP_CRC BIT(4)
#define FSDMMC_CMD_FLAG_EXP_DATA BIT(5)
#define FSDMMC_CMD_FLAG_WRITE_DATA BIT(6)
#define FSDMMC_CMD_FLAG_READ_DATA BIT(7)
#define FSDMMC_CMD_FLAG_NEED_AUTO_STOP BIT(8)
#define FSDMMC_CMD_FLAG_ADTC BIT(9)
FSdmmcData *data_p;
} FSdmmcCmd;
/**
* This typedef contains configuration information for the device.
*/
typedef struct
{
u32 instance_id; /* Device instance id */
uintptr base_addr; /* Device base address */
u32 irq_num[FSDMMC_INTR_NUM];
} FSdmmcConfig;
typedef void (*FSdmmcEventHandler)(void *instance_p);
/**
* This typedef contains driver instance data. The user is required to allocate a
* variable of this type for every device in the system. A pointer
* to a variable of this type is then passed to the driver API functions.
*/
typedef struct
{
FSdmmcConfig config; /* Current active configs */
u32 is_ready; /* Device is initialized and ready */
FSdmmcEventHandler evt_handler[FSDMMC_EVT_NUM];
} FSdmmc; /* Device instance */
/************************** Variable Definitions *****************************/
/***************** Macros (Inline Functions) Definitions *********************/
/************************** Function Prototypes ******************************/
/* 获取FSDMMC控制器默认配置 */
const FSdmmcConfig *FSdmmcLookupConfig(u32 instance_id);
/* 初始化FSDMMC控制器, 使之可以使用 */
FError FSdmmcCfgInitialize(FSdmmc *instance_p, const FSdmmcConfig *cofig_p);
/* 去使能FSDMMC控制器, 清零实例数据 */
void FSdmmcDeInitialize(FSdmmc *instance_p);
/* 通过FSDMMC轮询方式发送/接收数据和命令 */
FError FSdmmcPollTransfer(FSdmmc *instance_p, FSdmmcCmd *cmd_data_p);
/* 通过FSDMMC中断方式发送/接收数据和命令 */
FError FSdmmcInterruptTransfer(FSdmmc *instance_p, FSdmmcCmd *cmd_data_p);
/* 获取FSDMMC的中断掩码 */
u32 FSdmmcGetInterruptMask(uintptr base_addr, u32 intr_type);
/* 设置FSDMMC的中断掩码 */
void FSdmmcSetInterruptMask(uintptr base_addr, u32 intr_type, u32 mask, boolean enable);
/* 命令中断响应函数 */
void FSdmmcCmdInterrupHandler(s32 vector, void *param);
/* 错误中断响应函数 */
void FSdmmcErrInterrupHandler(s32 vector, void *param);
/* DMA中断响应函数 */
void FSdmmcDmaInterrupHandler(s32 vector, void *param);
/* 注册中断事件响应函数 */
void FSdmmcRegisterInterruptHandler(FSdmmc *instance_p, u32 event, FSdmmcEventHandler handler);
#ifdef __cplusplus
}
#endif
#endif
|