1 /*******************************************************************************
\r
2 * (c) Copyright 2010-2013 Microsemi SoC Products Group. All rights reserved.
\r
4 * SmartFusion2 MSS HPDMA bare metal software driver public API.
\r
6 * SVN $Revision: 5583 $
\r
7 * SVN $Date: 2013-04-04 12:29:18 +0100 (Thu, 04 Apr 2013) $
\r
10 /*=========================================================================*//**
\r
11 @mainpage SmartFusion2 MSS HPDMA Bare Metal Driver.
\r
13 @section intro_sec Introduction
\r
14 The SmartFusion2 Microcontroller Subsystem (MSS) includes a High Performance
\r
15 Direct Memory Access (HPDMA) controller which performs fast data transfer
\r
16 between any MSS memory connected to the AHB bus matrix and MSS DDR-Bridge
\r
17 memory. This software driver provides a set of functions for controlling the
\r
18 MSS HPDMA as part of a bare metal system where no operating system is
\r
19 available. The driver can be adapted for use as part of an operating system
\r
20 but the implementation of the adaptation layer between the driver and the
\r
21 operating system's driver model is outside the scope of the driver.
\r
23 @section hw_dependencies Hardware Flow Dependencies
\r
24 The configuration of all features of the MSS HPDMA is covered by this driver.
\r
25 There are no dependencies on the hardware flow when configuring the MSS HPDMA.
\r
26 The base address, register addresses and interrupt number assignment for the
\r
27 MSS HPDMA blocks are defined as constants in the SmartFusion2 CMSIS HAL. You
\r
28 must ensure that the latest SmartFusion2 CMSIS HAL is included in the project
\r
29 settings of the software tool chain used to build your project and that it is
\r
30 generated into your project.
\r
32 @section theory_op Theory of Operation
\r
33 The MSS HPDMA driver functions are grouped into the following categories:
\r
34 - Initialization of the MSS HPDMA driver and hardware
\r
35 - Data transfer control
\r
36 - Data transfer status
\r
37 - Interrupt handling
\r
40 The MSS HPDMA driver is initialized through a call to the MSS_HPDMA_init()
\r
41 function. The MSS_HPDMA_init() function must be called before any other MSS
\r
42 HPDMA driver functions can be called.
\r
44 Data Transfer Control
\r
45 The driver provides the following functions to control HPDMA data transfers:
\r
46 - MSS_HPDMA_start()
\96 This function starts a HPDMA data transfer. You must
\r
47 provide the source and destination addresses along
\r
48 with transfer size and transfer direction.
\r
49 - MSS_HPDMA_pause()
\96 This function pauses the HPDMA transfer that is
\r
50 currently in progress.
\r
51 - MSS_HPDMA_resume()
\96 This function resumes a HPDMA transfer that was
\r
53 - MSS_HPDMA_abort()
\96 This function aborts the HPDMA transfer that is
\r
54 currently in progress.
\r
56 Data Transfer Status
\r
57 The status of the HPDMA transfer initiated by the last call to
\r
58 MSS_HPDMA_start() can be retrieved using the MSS_HPDMA_get_transfer_status()
\r
62 The MSS_HPDMA_set_handler() function is used to register a handler function
\r
63 that will be called by the driver when the HPDMA transfer completes. You must
\r
64 create and register a transfer completion handler function to suit your
\r
67 *//*=========================================================================*/
\r
68 #ifndef MSS_HPDMA_H_
\r
69 #define MSS_HPDMA_H_
\r
75 #include "../../CMSIS/m2sxxx.h"
\r
77 /*-------------------------------------------------------------------------*//**
\r
78 The HPDMA_TO_DDR constant is used to specify the data transfer direction. It
\r
79 indicates a transfer from memory connected to the AHB bus matrix to MSS
\r
80 DDR-Bridge memory. It is used as a parameter by the MSS_HPDMA_start()
\r
83 #define HPDMA_TO_DDR 0u
\r
85 /*-------------------------------------------------------------------------*//**
\r
86 The HPDMA_FROM_DDR constant is used to specify the data transfer direction. It
\r
87 indicates a transter from MSS DDR-Bridge memory to memory connected to the AHB
\r
88 bus matrix. It is used as a parameter by the MSS_HPDMA_start() function.
\r
90 #define HPDMA_FROM_DDR 1u
\r
92 /*-------------------------------------------------------------------------*//**
\r
93 The hpdma_status_t type is used to communicate the status of the HPDMA
\r
94 transfer initiated by the most recent call to HPDMA_start(). It indicates if
\r
95 a transfer is still currently in progress or the outcome of the latest
\r
96 transfer. This type is returned by the MSS_HPDMA_get_transfer_status()
\r
97 function and used as parameter to handler functions registered with the MSS
\r
98 HPDMA driver by the application.
\r
100 - HPDMA_IN_PROGRESS - A HPDMA transfer is taking place.
\r
101 - HPDMA_COMPLETED - The most recent HPDMA transfer initiated by a call
\r
102 to HPDMA_start() has completed successfully.
\r
103 - HPDMA_SOURCE_ERROR - The most recent HPDMA transfer failed because of a
\r
104 problem with the source address passed to
\r
106 - HPDMA_DESTINATION_ERROR - The most recent HPDMA transfer failed because of a
\r
107 problem with the destination address passed to
\r
109 - HPDMA_WORD_ALIGN_ERROR - The most recent HPDMA transfer failed because the
\r
110 transfer size was not word aligned. This means
\r
111 that the transfer size passed to HPDMA_start() was
\r
112 not a multiple of four.
\r
118 HPDMA_SOURCE_ERROR,
\r
119 HPDMA_DESTINATION_ERROR,
\r
120 HPDMA_WORD_ALIGN_ERROR
\r
123 /*-------------------------------------------------------------------------*//**
\r
124 This type definition specifies the prototype of a function that can be
\r
125 registered with this driver as a HPDMA transfer completion handler function
\r
126 through a call to MSS_HPDMA_set_handler(). The HPDMA transfer completion
\r
127 handler will be called by the driver when a HPDMA transfer completes. The MSS
\r
128 HPDMA driver passes the outcome of the transfer to the completion handler in
\r
129 the form of a hpdma_status_t parameter indicating if the transfer was
\r
130 successful or the type of error that occurred during the transfer.
\r
132 typedef void (*mss_hpdma_handler_t)(hpdma_status_t status);
\r
134 /*-------------------------------------------------------------------------*//**
\r
135 The MSS_HPDMA_init() function initializes the MSS HPDMA driver. It resets the
\r
136 HPDMA controller. It clears all pending HPDMA interrupts. It initializes
\r
137 internal data structures used by the MSS HPDMA driver. It disables interrupts
\r
138 related to HPDMA data transfers.
\r
141 This function has no parameters.
\r
144 This function does not return a value.
\r
152 /*-------------------------------------------------------------------------*//**
\r
153 The MSS_HPDMA_start() function starts a HPDMA data transfer. Its parameters
\r
154 specify the source and destination addresses of the transfer as well as its
\r
155 size and direction. HPDMA data transfers always use DDR memory as the source
\r
156 or destination of the transfer. The HPDMA controller transfers data in 32-bit
\r
157 chunks located on 32-bit word aligned address boundaries.
\r
160 The parameter src_addr is the address of the data that will be transferred
\r
161 by the HPDMA. This address must be 32-bit word aligned. The memory location
\r
162 specified by this address must be located in DDR memory if the transfer_dir
\r
163 parameter is set to HPDM_FROM_DDR.
\r
166 The parameter dest_addr is the address of the location at which the data
\r
167 will be transferred. This address must be 32-bit word aligned. The memory
\r
168 location specified by this address must be located in DDR memory if the
\r
169 transfer_dir parameter is set to HPDM_TO_DDR.
\r
171 @param transfer_size
\r
172 The parameter transfer_size specifies the size in bytes of the requested
\r
173 transfer. The value of transfer_size must be a multiple of four.
\r
175 @param transfer_dir
\r
176 The parameter transfer_dir is used for specifying the data transfer
\r
177 direction. Allowed values for transfer_dir are as follows:
\r
182 This function does not return a value.
\r
188 uint32_t dest_addr,
\r
189 uint32_t transfer_size,
\r
190 uint8_t transfer_dir
\r
193 /*-------------------------------------------------------------------------*//**
\r
194 The MSS_HPDMA_pause() function pauses the current HPDMA transfer. The HPDMA
\r
195 transfer can be resumed later by calling MSS_HPDMA_resume().
\r
198 This function has no parameters.
\r
201 This function does not return a value.
\r
209 /*-------------------------------------------------------------------------*//**
\r
210 The MSS_HPDMA_pause() function resumes the current HPDMA transfer after it was
\r
211 previously paused through a call to MSS_HPDMA_pause().
\r
214 This function has no parameters.
\r
217 This function does not return a value.
\r
225 /*-------------------------------------------------------------------------*//**
\r
226 The MSS_HPDMA_abort() function aborts the current HPDMA transfer.
\r
229 This function has no parameters.
\r
232 This function does not return a value.
\r
240 /*-------------------------------------------------------------------------*//**
\r
241 The MSS_HPDMA_get_transfer_status() function returns the status of the HPDMA
\r
242 transfer initiated by a call to MSS_HPDMA_start().
\r
245 This function has no parameters.
\r
248 The MSS_HPDMA_get_transfer_status() function returns the status of the HPDMA
\r
249 transfer as a value of type hpdma_status_t. The possible return values are:
\r
250 - HPDMA_IN_PROGRESS
\r
252 - HPDMA_SOURCE_ERROR
\r
253 - HPDMA_DESTINATION_ERROR
\r
254 - HPDMA_WORD_ALIGN_ERROR
\r
256 The example code below demonstrates the use of the
\r
257 MSS_HPDMA_get_transfer_status() function to detect the completion of the
\r
258 transfer of the content of eNVM into MDDR memory.
\r
260 void copy_envm_to_mddr(void)
\r
262 MSS_HPDMA_start(ENVM_BASE_ADDR,
\r
268 xfer_state = MSS_HPDMA_get_transfer_status();
\r
269 } while(HPDMA_IN_PROGRESS == xfer_state);
\r
274 MSS_HPDMA_get_transfer_status
\r
279 /*-------------------------------------------------------------------------*//**
\r
280 The MSS_HPDMA_set_handler() function is used to register a handler function
\r
281 that will be called by the driver when the HPDMA transfer completes. You must
\r
282 create and register a transfer completion handler function to suit your
\r
283 application. The MSS HPDMA driver passes the outcome of the transfer to the
\r
284 completion handler in the form of a hpdma_status_t parameter indicating if the
\r
285 transfer was successful or the type of error that occurred during the transfer
\r
286 if the transfer failed.
\r
289 The handler parameter is a pointer to a handler function provided by your
\r
290 application. This handler is of type mss_hpdma_handler_t. The handler
\r
291 function must take one parameter of type hpdma_status_t and must not return
\r
295 This function does not return a value.
\r
297 This example code demonstrates the use of the MSS_HPDMA_set_handler()
\r
300 void transfer_complete_handler(hpdma_status_t status);
\r
302 volatile uint32_t g_xfer_in_progress = 0;
\r
304 void demo_transfer(void)
\r
308 MSS_HPDMA_set_handler(transfer_complete_handler);
\r
310 g_xfer_in_progress = 1;
\r
311 MSS_HPDMA_start((uint32_t)0x20000000,
\r
312 (uint32_t)0x00000000,
\r
316 while(g_xfer_in_progress)
\r
322 void transfer_complete_handler(hpdma_status_t status)
\r
324 g_xfer_in_progress = 0;
\r
328 case HPDMA_COMPLETED:
\r
329 display("Transfer complete");
\r
332 case HPDMA_SOURCE_ERROR:
\r
333 display("Transfer failed: source error");
\r
336 case HPDMA_DESTINATION_ERROR:
\r
337 display("Transfer failed: destination error");
\r
340 case HPDMA_WORD_ALIGN_ERROR:
\r
341 display("Transfer failed: word alignment error");
\r
345 display("Unexpected status");
\r
352 MSS_HPDMA_set_handler
\r
354 mss_hpdma_handler_t handler
\r
361 #endif /* MSS_HPDMA_H_ */
\r