blob: 4235341305d53b58fa67ae1a64d4ec8fe2ec6687 [file] [log] [blame]
Christina Quast637ace92014-11-28 13:28:37 +01001/* ----------------------------------------------------------------------------
2 * ATMEL Microcontroller Software Support
3 * ----------------------------------------------------------------------------
4 * Copyright (c) 2008, Atmel Corporation
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * - Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the disclaimer below.
13 *
14 * Atmel's name may not be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * ----------------------------------------------------------------------------
28 */
29
30/** \addtogroup hsmci_module Working with HSMCI
31 * The HSMCI driver provides the interface to configure and use the HSMCI
32 * peripheral.
33 *
34 * The user needs to set the number of wait states depending on the frequency used.\n
35 * Configure number of cycles for flash read/write operations in the FWS field of HSMCI_FMR.
36 *
37 * It offers a function to send flash command to HSMCI and waits for the
38 * flash to be ready.
39 *
40 * To send flash command, the user could do in either of following way:
41 * <ul>
42 * <li>Write a correct key, command and argument in HSMCI_FCR. </li>
43 * <li>Or, Use IAP (In Application Programming) function which is executed from
44 * ROM directly, this allows flash programming to be done by code running in flash.</li>
45 * <li>Once the command is achieved, it can be detected even by polling EEFC_FSR or interrupt.
46 * </ul>
47 *
48 * The command argument could be a page number,GPNVM number or nothing, it depends on
49 * the command itself. Some useful functions in this driver could help user tranlate physical
50 * flash address into a page number and vice verse.
51 *
52 * For more accurate information, please look at the EEFC section of the
53 * Datasheet.
54 *
55 * Related files :\n
56 * \ref hsmci_pdc.c\n
57 * \ref hsmci.h.\n
58*/
59/*@{*/
60/*@}*/
61
62/**
63 * \file
64 */
65
66/**
67 *
68 * \section Purpose
69 *
70 * Implement MultiMediaCard(MCI) Interface Driver
71 *
72 * \section Usage
73 *
74 * -# MCI_Init(): Initializes a MCI driver instance and the underlying
75 * peripheral.
76 * -# MCI_Handler() : Interrupt handler which is called by ISR handler.
77 * -# MCI_SetSpeed() : Configure the MCI CLKDIV in the _MR register
78 * (\ref Hsmci::HSMCI_MR).
79 * -# MCI_SetBusWidth() : Configure the MCI SDCBUS in the _SDCR register
80 * (\ref Hsmci::HSMCI_SDCR).
81 * -# MCI_EnableHsMode() : Configure the MCI HSMODE in the _CFG register
82 * (\ref Hsmci::HSMCI_CFG).
83 */
84
85#ifndef HSMCID_H
86#define HSMCID_H
87/** \addtogroup sdmmc_hal
88 *@{
89 */
90
91/*----------------------------------------------------------------------------
92 * Headers
93 *----------------------------------------------------------------------------*/
94
95#include "chip.h"
96
97#include <stdint.h>
98#include <stdio.h>
99
100//#include <memories/sdmmc/sdmmc_cmd.h>
101
102/*----------------------------------------------------------------------------
103 * Constants
104 *----------------------------------------------------------------------------*/
105
106/* Transfer type */
107
108/** MultiMedia Transfer type: no data */
109#define MCI_NO_TRANSFER 0
110/** MultiMedia Transfer type: Device to Host (read) */
111#define MCI_START_READ 1
112/** MultiMedia Transfer type: Host to Device (write) & check BUSY */
113#define MCI_START_WRITE 2
114/** Device to Host (read) without command */
115#define MCI_READ 3
116/** Host to Device (write) without command & check BUSY */
117#define MCI_WRITE 4
118/** MultiMedia Transfer type: STOP transfer */
119#define MCI_STOP_TRANSFER 5
120
121/** MCI Initialize clock 400K Hz */
122#define MCI_INITIAL_SPEED 400000
123
124/*----------------------------------------------------------------------------
125 * Types
126 *----------------------------------------------------------------------------*/
127
128#ifdef __cplusplus
129 extern "C" {
130#endif
131
132/**
133 * \brief MCI Transfer Request prepared by the application upper layer.
134 *
135 * This structure is sent to the Sdmmc_SendCommand function to start the transfer.
136 * At the end of the transfer, the callback is invoked.
137 */
138typedef struct _MciCmd {
139
140 /** Command code. */
141 uint32_t cmd;
142 /** Command argument. */
143 uint32_t arg;
144 /** Data buffer, with MCI_DMA_ENABLE defined 1, the buffer can be
145 * 1, 2 or 4 bytes aligned. It has to be 4 byte aligned if no DMA.
146 */
147 uint8_t *pData;
148 /** Size of data block in bytes. */
149 uint16_t blockSize;
150 /** Number of blocks to be transfered */
151 uint16_t nbBlock;
152 /** Response buffer. */
153 uint32_t *pResp;
154 /** Optional user-provided callback function. */
155 void (*callback)( uint8_t status, void *pArg ) ;
156 /** Optional argument to the callback function. */
157 void *pArg;
158 /** SD card command option. */
159 uint8_t resType:7, /** Response */
160 busyCheck:1; /** Check busy as end of command */
161 /** Indicate transfer type */
162 uint8_t tranType;
163
164 /** Indicate end of transfer status */
165 uint8_t status;
166
167 /** Command state. */
168 volatile uint8_t state;
169} MciCmd;
170
171/**
172 * \brief MCI Driver
173 */
174typedef struct
175{
176 /** Pointer to a MCI peripheral. */
177 Hsmci *pMciHw;
178 /** Pointer to currently executing command. */
179 MciCmd *pCommand;
180 /** MCI peripheral identifier. */
181 uint8_t mciId;
182 /** Mutex. */
183 volatile uint8_t semaphore;
184} Mcid;
185
186/*----------------------------------------------------------------------------
187 * Exported functions
188 *----------------------------------------------------------------------------*/
189
190extern void MCI_Disable(Hsmci *pMciHw);
191extern void MCI_Enable(Hsmci *pMciHw);
192extern uint8_t MCI_EnableHsMode(Mcid * pMci, uint8_t hsEnable);
193extern void MCI_Init( Mcid *pMci, Hsmci *pMciHw, uint8_t mciId, uint32_t dwMCk ) ;
194extern uint32_t MCI_SetBusWidth(Mcid *pMci, uint32_t busWidth);
195extern uint32_t MCI_SetSpeed(Mcid *pMci, uint32_t mciSpeed, uint32_t mck);
196
197/* pdc if used */
198extern void MCI_Reset(Mcid *pMci, uint8_t keepSettings);
199
200#ifdef __cplusplus
201}
202#endif
203
204/**@}*/
205#endif //#ifndef HSMCID_H
206