]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo/FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC/ThirdParty/LPCOpen/lpc_core/lpc_chip/chip_18xx_43xx/sdmmc_18xx_43xx.h
Update LPC18xx FreeRTOS+UDP demo to use LPCOpen USB and Ethernet drivers.
[freertos] / FreeRTOS-Plus / Demo / FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC / ThirdParty / LPCOpen / lpc_core / lpc_chip / chip_18xx_43xx / sdmmc_18xx_43xx.h
1 /*\r
2  * @brief LPC18xx/43xx SD/MMC card driver\r
3  *\r
4  * @note\r
5  * Copyright(C) NXP Semiconductors, 2012\r
6  * All rights reserved.\r
7  *\r
8  * @par\r
9  * Software that is described herein is for illustrative purposes only\r
10  * which provides customers with programming information regarding the\r
11  * LPC products.  This software is supplied "AS IS" without any warranties of\r
12  * any kind, and NXP Semiconductors and its licensor disclaim any and\r
13  * all warranties, express or implied, including all implied warranties of\r
14  * merchantability, fitness for a particular purpose and non-infringement of\r
15  * intellectual property rights.  NXP Semiconductors assumes no responsibility\r
16  * or liability for the use of the software, conveys no license or rights under any\r
17  * patent, copyright, mask work right, or any other intellectual property rights in\r
18  * or to any products. NXP Semiconductors reserves the right to make changes\r
19  * in the software without notification. NXP Semiconductors also makes no\r
20  * representation or warranty that such application will be suitable for the\r
21  * specified use without further testing or modification.\r
22  *\r
23  * @par\r
24  * Permission to use, copy, modify, and distribute this software and its\r
25  * documentation is hereby granted, under NXP Semiconductors' and its\r
26  * licensor's relevant copyrights in the software, without fee, provided that it\r
27  * is used in conjunction with NXP Semiconductors microcontrollers.  This\r
28  * copyright, permission, and disclaimer notice must appear in all copies of\r
29  * this code.\r
30  */\r
31 \r
32 #ifndef __SDMMC_18XX_43XX_H_\r
33 #define __SDMMC_18XX_43XX_H_\r
34 \r
35 #include "lpc_sdmmc.h"\r
36 \r
37 #ifdef __cplusplus\r
38 extern "C" {\r
39 #endif\r
40 \r
41 /** @defgroup SDMMC_18XX_43XX CHIP: LPC18xx/43xx SD/MMC driver\r
42  * @ingroup CHIP_18XX_43XX_Drivers\r
43  * @{\r
44  */\r
45 \r
46 #define CMD_MASK_RESP       (0x3UL << 28)\r
47 #define CMD_RESP(r)         (((r) & 0x3) << 28)\r
48 #define CMD_RESP_R0         (0 << 28)\r
49 #define CMD_RESP_R1         (1 << 28)\r
50 #define CMD_RESP_R2         (2 << 28)\r
51 #define CMD_RESP_R3         (3 << 28)\r
52 #define CMD_BIT_AUTO_STOP   (1 << 24)\r
53 #define CMD_BIT_APP         (1 << 23)\r
54 #define CMD_BIT_INIT        (1 << 22)\r
55 #define CMD_BIT_BUSY        (1 << 21)\r
56 #define CMD_BIT_LS          (1 << 20)   /* Low speed, used during acquire */\r
57 #define CMD_BIT_DATA        (1 << 19)\r
58 #define CMD_BIT_WRITE       (1 << 18)\r
59 #define CMD_BIT_STREAM      (1 << 17)\r
60 #define CMD_MASK_CMD        (0xff)\r
61 #define CMD_SHIFT_CMD       (0)\r
62 \r
63 #define CMD(c, r)        ( ((c) &  CMD_MASK_CMD) | CMD_RESP((r)) )\r
64 \r
65 #define CMD_IDLE            CMD(MMC_GO_IDLE_STATE, 0) | CMD_BIT_LS    | CMD_BIT_INIT\r
66 #define CMD_SD_OP_COND      CMD(SD_APP_OP_COND, 1)      | CMD_BIT_LS | CMD_BIT_APP\r
67 #define CMD_SD_SEND_IF_COND CMD(SD_CMD8, 1)      | CMD_BIT_LS\r
68 #define CMD_MMC_OP_COND     CMD(MMC_SEND_OP_COND, 3)    | CMD_BIT_LS | CMD_BIT_INIT\r
69 #define CMD_ALL_SEND_CID    CMD(MMC_ALL_SEND_CID, 2)    | CMD_BIT_LS\r
70 #define CMD_MMC_SET_RCA     CMD(MMC_SET_RELATIVE_ADDR, 1) | CMD_BIT_LS\r
71 #define CMD_SD_SEND_RCA     CMD(SD_SEND_RELATIVE_ADDR, 1) | CMD_BIT_LS\r
72 #define CMD_SEND_CSD        CMD(MMC_SEND_CSD, 2) | CMD_BIT_LS\r
73 #define CMD_SEND_EXT_CSD    CMD(MMC_SEND_EXT_CSD, 1) | CMD_BIT_LS | CMD_BIT_DATA\r
74 #define CMD_DESELECT_CARD   CMD(MMC_SELECT_CARD, 0)\r
75 #define CMD_SELECT_CARD     CMD(MMC_SELECT_CARD, 1)\r
76 #define CMD_SET_BLOCKLEN    CMD(MMC_SET_BLOCKLEN, 1)\r
77 #define CMD_SEND_STATUS     CMD(MMC_SEND_STATUS, 1)\r
78 #define CMD_READ_SINGLE     CMD(MMC_READ_SINGLE_BLOCK, 1) | CMD_BIT_DATA\r
79 #define CMD_READ_MULTIPLE   CMD(MMC_READ_MULTIPLE_BLOCK, 1) | CMD_BIT_DATA | CMD_BIT_AUTO_STOP\r
80 #define CMD_SD_SET_WIDTH    CMD(SD_APP_SET_BUS_WIDTH, 1) | CMD_BIT_APP\r
81 #define CMD_STOP            CMD(MMC_STOP_TRANSMISSION, 1) | CMD_BIT_BUSY\r
82 #define CMD_WRITE_SINGLE    CMD(MMC_WRITE_BLOCK, 1) | CMD_BIT_DATA | CMD_BIT_WRITE\r
83 #define CMD_WRITE_MULTIPLE  CMD(MMC_WRITE_MULTIPLE_BLOCK, 1) | CMD_BIT_DATA | CMD_BIT_WRITE | CMD_BIT_AUTO_STOP\r
84 \r
85 /* Card specific setup data */\r
86 typedef struct _mci_card_struct {\r
87         sdif_device sdif_dev;\r
88         SDMMC_CARD_T card_info;\r
89 } mci_card_struct;\r
90 \r
91 /**\r
92  * @brief       Get card's current state (idle, transfer, program, etc.)\r
93  * @param       pSDMMC  : SDMMC peripheral selected\r
94  * @return      Current SD card transfer state\r
95  */\r
96 int32_t Chip_SDMMC_GetState(LPC_SDMMC_T *pSDMMC);\r
97 \r
98 /**\r
99  * @brief       Function to enumerate the SD/MMC/SDHC/MMC+ cards\r
100  * @param       pSDMMC          : SDMMC peripheral selected\r
101  * @param       pcardinfo       : Pointer to pre-allocated card info structure\r
102  * @return      1 if a card is acquired, otherwise 0\r
103  */\r
104 uint32_t Chip_SDMMC_Acquire(LPC_SDMMC_T *pSDMMC, mci_card_struct *pcardinfo);\r
105 \r
106 /**\r
107  * @brief       Get the device size of SD/MMC card (after enumeration)\r
108  * @param       pSDMMC  : SDMMC peripheral selected\r
109  * @return      Card size in number of bytes (capacity)\r
110  */\r
111 int32_t Chip_SDMMC_GetDeviceSize(LPC_SDMMC_T *pSDMMC);\r
112 \r
113 /**\r
114  * @brief       Get the number of device blocks of SD/MMC card (after enumeration)\r
115  * Since Chip_SDMMC_GetDeviceSize is limited to 32 bits cards with greater than\r
116  * 2 GBytes of data will not be correct, in such cases users can use this function\r
117  * to get the size of the card in blocks.\r
118  * @param       pSDMMC  : SDMMC peripheral selected\r
119  * @return      Number of 512 bytes blocks in the card\r
120  */\r
121 int32_t Chip_SDMMC_GetDeviceBlocks(LPC_SDMMC_T *pSDMMC);\r
122 \r
123 /**\r
124  * @brief       Performs the read of data from the SD/MMC card\r
125  * @param       pSDMMC          : SDMMC peripheral selected\r
126  * @param       buffer          : Pointer to data buffer to copy to\r
127  * @param       start_block     : Start block number\r
128  * @param       num_blocks      : Number of block to read\r
129  * @return      Bytes read, or 0 on error\r
130  */\r
131 int32_t Chip_SDMMC_ReadBlocks(LPC_SDMMC_T *pSDMMC, void *buffer, int32_t start_block, int32_t num_blocks);\r
132 \r
133 /**\r
134  * @brief       Performs write of data to the SD/MMC card\r
135  * @param       pSDMMC          : SDMMC peripheral selected\r
136  * @param       buffer          : Pointer to data buffer to copy to\r
137  * @param       start_block     : Start block number\r
138  * @param       num_blocks      : Number of block to write\r
139  * @return      Number of bytes actually written, or 0 on error\r
140  */\r
141 int32_t Chip_SDMMC_WriteBlocks(LPC_SDMMC_T *pSDMMC, void *buffer, int32_t start_block, int32_t num_blocks);\r
142 \r
143 /**\r
144  * @}\r
145  */\r
146 \r
147 #ifdef __cplusplus\r
148 }\r
149 #endif\r
150 \r
151 #endif /* __SDMMC_18XX_43XX_H_ */\r