sdma.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (c) 2011-2012, Freescale Semiconductor, Inc.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. /*!
  31. * @file sdma.h
  32. * @brief SDMA library macros, structures and functions
  33. */
  34. #ifndef SDMA_H
  35. #define SDMA_H
  36. #include "sdk.h"
  37. /*--------------------------------- macros --------------------------------------*/
  38. #define SDMA_ENV_BUF_SIZE 0x800
  39. #define SDMA_CHANNEL_PRIORITY_FREE 0
  40. #define SDMA_CHANNEL_PRIORITY_LOW 1
  41. #define SDMA_CHANNEL_PRIORITY_HIGH 7
  42. //! @brief List of scripts' names.
  43. typedef enum {
  44. SDMA_AP_2_AP = 0,
  45. SDMA_APP_2_MCU,
  46. SDMA_MCU_2_APP,
  47. SDMA_UART_2_MCU,
  48. SDMA_SHP_2_MCU,
  49. SDMA_MCU_2_SHP,
  50. SDMA_SPDIF_2_MCU,
  51. SDMA_MCU_2_SPDIF,
  52. SDMA_FIRI_2_MCU,
  53. SDMA_MCU_2_FIRI,
  54. SDMA_MCU_2_SSIAPP,
  55. SDMA_MCU_2_SSISH,
  56. SDMA_P_2_P,
  57. SDMA_SSIAPP_2_MCU,
  58. SDMA_SSISH_2_MCU,
  59. SDMA_NUM_SCRIPTS
  60. } script_name_e;
  61. //! @brief SDMA buffer descriptor modes.
  62. typedef enum {
  63. SDMA_FLAGS_BUSY = (1 << 16),
  64. SDMA_FLAGS_WRAP = (1 << 17),
  65. SDMA_FLAGS_CONT = (1 << 18),
  66. SDMA_FLAGS_INTR = (1 << 19),
  67. SDMA_FLAGS_ERROR = (1 << 20),
  68. SDMA_FLAGS_NFC_RD = (1 << 28),
  69. SDMA_FLAGS_BW8 = (1 << 24),
  70. SDMA_FLAGS_BW16 = (2 << 24),
  71. SDMA_FLAGS_BW24 = (3 << 24),
  72. SDMA_FLAGS_BW32 = (0 << 24)
  73. } sdma_flag_e;
  74. //! @brief SDMA transfer information in buffer descriptor.
  75. typedef enum {
  76. SDMA_CHANNEL_STATUS_ERROR,
  77. SDMA_CHANNEL_STATUS_BUSY,
  78. SDMA_CHANNEL_STATUS_DONE
  79. } sdma_channel_status_e;
  80. //! @brief The return value of function.
  81. typedef enum {
  82. SDMA_RETV_SUCCESS = 0,
  83. SDMA_RETV_FAIL = -1,
  84. SDMA_RETV_NULLP = -2,
  85. SDMA_RETV_PRIORITY = -3,
  86. SDMA_RETV_NO_FREE_CHANNEL = -4,
  87. SDMA_RETV_SET_CONTEXT = -5,
  88. SDMA_RETV_BD_VALIDATE = -6,
  89. SDMA_RETV_NOT_INITED = -7
  90. } sdma_error_e;
  91. //! @brief SDMA buffer descriptor structure.
  92. typedef struct {
  93. uint32_t mode; //mode word, including count, command, flag...
  94. uint32_t buf_addr; //buffer address, while peripheral address in channel context
  95. uint32_t ext_buf_addr; //extended buffer address, not mandatory for scripts
  96. } sdma_bd_t, *sdma_bd_p;
  97. //! @brief SDMA channel descriptor.
  98. typedef struct {
  99. uint32_t script_addr; //script to use
  100. uint32_t gpr[8]; //r0-r7, including DMA mask, watermark...
  101. uint32_t dma_mask[2]; //dma_mask[0]: DMA request 0-31, 1: 32-47
  102. uint32_t priority; //priority of channel(0-7)
  103. uint32_t nbd; //number of buffer descriptors
  104. } sdma_chan_desc_t, *sdma_chan_desc_p;
  105. typedef void (*sdma_channel_isr) (uint32_t);
  106. /*--------------------------------- functions -------------------------------------*/
  107. int32_t sdma_init(uint32_t *, uint32_t);
  108. void sdma_deinit(void);
  109. int32_t sdma_channel_start(uint32_t);
  110. int32_t sdma_channel_stop(uint32_t);
  111. int32_t sdma_channel_request(sdma_chan_desc_p, sdma_bd_p);
  112. int32_t sdma_channel_release(uint32_t);
  113. uint32_t sdma_channel_status(uint32_t, uint32_t *);
  114. int32_t sdma_lookup_script(script_name_e, uint32_t *);
  115. void sdma_setup_interrupt(void);
  116. int32_t sdma_channel_isr_attach(uint32_t, sdma_channel_isr isr);
  117. #endif