Advertisement
huuhuynh

Untitled

May 25th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.10 KB | None | 0 0
  1. /*
  2.  * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
  3.  *
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  *  * Redistributions of source code must retain the above copyright
  10.  *    notice, this list of conditions and the following disclaimer.
  11.  *
  12.  *  * Redistributions in binary form must reproduce the above copyright
  13.  *    notice, this list of conditions and the following disclaimer in the
  14.  *    documentation and/or other materials provided with the
  15.  *    distribution.
  16.  *
  17.  *  * Neither the name of Texas Instruments Incorporated nor the names of
  18.  *    its contributors may be used to endorse or promote products derived
  19.  *    from this software without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32.  */
  33.  
  34. #include <stdint.h>
  35. #include <pru_cfg.h>
  36. #include "resource_table_empty.h"
  37.  
  38. volatile register uint32_t __R30;
  39. volatile register uint32_t __R31;
  40.  
  41. /* 1D Transfer Parameters */
  42. typedef struct {
  43.     uint32_t src;
  44.     uint32_t dst;
  45.     uint32_t chan;
  46. } hostBuffer;
  47.  
  48. /* EDMA PARAM registers */
  49. typedef struct {
  50.     uint32_t sam        : 1;
  51.     uint32_t dam        : 1;
  52.     uint32_t syncdim    : 1;
  53.     uint32_t static_set : 1;
  54.     uint32_t        : 4;
  55.     uint32_t fwid       : 3;
  56.     uint32_t tccmode    : 1;
  57.     uint32_t tcc        : 6;
  58.     uint32_t        : 2;
  59.     uint32_t tcinten    : 1;
  60.     uint32_t itcinten   : 1;
  61.     uint32_t tcchen     : 1;
  62.     uint32_t itcchen    : 1;
  63.     uint32_t privid     : 4;
  64.     uint32_t        : 3;
  65.     uint32_t priv       : 1;
  66. } edmaParamOpt;
  67.  
  68. /*typedef struct{
  69.     uint32_t src;
  70. } edmaParamSrc;*/
  71.  
  72. typedef struct {
  73.     uint32_t acnt       : 16;
  74.     uint32_t bcnt       : 16;
  75. } edmaParamABcnt;
  76.  
  77. /*typedef struct{
  78.     uint32_t dst;
  79. } edmaParamDst;*/
  80.  
  81. typedef struct {
  82.     uint32_t srcbidx    : 16;
  83.     uint32_t dstbidx    : 16;
  84. } edmaParamBidx;
  85.  
  86. typedef struct {
  87.     uint32_t link       : 16;
  88.     uint32_t bcntrld    : 16;
  89. } edmaParamLnkRld;
  90.  
  91. typedef struct {
  92.     uint32_t srccidx    : 16;
  93.     uint32_t dstcidx    : 16;
  94. } edmaParamCidx;
  95.  
  96. typedef struct {
  97.     uint32_t ccnt       : 16;
  98.     uint32_t        : 16;
  99. } edmaParamCcnt;
  100.  
  101. typedef struct {
  102.     edmaParamOpt    opt;
  103.     /*edmaParamSrc*/ uint32_t   src;
  104.     edmaParamABcnt  abcnt;
  105.     /*edmaParamDst*/ uint32_t   dst;
  106.     edmaParamBidx   bidx;
  107.     edmaParamLnkRld lnkrld;
  108.     edmaParamCidx   cidx;
  109.     edmaParamCcnt   ccnt;
  110. } edmaParam;
  111.  
  112. /* This is a compiler hack so that the PRU knows where the parameters are stored
  113.  * This is effectively a pointer to DRAM
  114.  */
  115. #pragma LOCATION(buf, 0)
  116. hostBuffer buf;
  117.  
  118. /* Addresses for Constant Table pointer registers
  119.  * CTBIR_0 -> C24 (PRU0 DRAM)
  120.  * CTBIR_1 -> C25 (PRU1 DRAM)
  121.  */
  122. #define CTBIR_0         (*(volatile uint32_t *)(0x22020))
  123. #define CTBIR_1         (*(volatile uint32_t *)(0x22024))
  124.  
  125. /* EDMA Channel Registers */
  126. #define CM_PER_BASE ((volatile uint32_t *)(0x44E00000))
  127. #define TPTC0_CLKCTRL (0x24 / 4)
  128. #define TPCC_CLKCTRL  (0xBC / 4)
  129. #define ON (0x2)
  130.  
  131. /* EDMA Channel Registers */
  132. #define EDMA0_CC_BASE   ((volatile uint32_t *)(0x49000000))
  133. #define DMAQNUM0    (0x0240 / 4)
  134. #define DMAQNUM1    (0x0244 / 4)
  135. #define DCHMAP_10   (0x0128 / 4)
  136. #define QUEPRI      (0x0284 / 4)
  137. #define EMR     (0x0300 / 4)
  138. #define EMCR        (0x0307 / 4)
  139. #define EMCRH       (0x030C / 4)
  140. #define QEMCR       (0x0314 / 4)
  141. #define CCERRCLR    (0x031C / 4)
  142. #define DRAE0       (0x0340 / 4)
  143. #define DRAE1       (0x0348 / 4)
  144. #define DRAE2       (0x0350 / 4)
  145. #define DRAE3       (0x0358 / 4)
  146. #define QWMTHRA     (0x0620 / 4)
  147. #define GLOBAL_ESR  (0x1010 / 4)
  148. #define GLOBAL_ESRH (0x1014 / 4)
  149. #define GLOBAL_EECR (0x1028 / 4)
  150. #define GLOBAL_EECRH    (0x102C / 4)
  151. #define GLOBAL_SECR (0x1040 / 4)
  152. #define GLOBAL_SECRH    (0x1044 / 4)
  153. #define GLOBAL_IESR (0x1060 / 4)
  154. #define GLOBAL_IESRH    (0x1064 / 4)
  155. #define GLOBAL_ICR  (0x1070 / 4)
  156. #define GLOBAL_ICRH (0x1074 / 4)
  157.  
  158. /* EDMA Shadow Region 1 */
  159. #define ESR     (0x2210 / 4)
  160. #define ESRH        (0x2214 / 4)
  161. #define EESR        (0x1030 / 4)
  162. #define EECR        (0x2228 / 4)
  163. #define EECRH       (0x222C / 4)
  164. #define SECR        (0x2240 / 4)
  165. #define SECRH       (0x2244 / 4)
  166. #define IPR     (0x2268 / 4)
  167. #define IPRH        (0x226C / 4)
  168. #define ICR     (0x2270 / 4)
  169. #define ICRH        (0x2274 / 4)
  170. #define IESR        (0x2260 / 4)
  171. #define IESRH       (0x2264 / 4)
  172. #define IEVAL       (0x2278 / 4)
  173. #define IECR        (0x2258 / 4)
  174. #define IECRH       (0x225C / 4)
  175.  
  176. /* EDMA PARAM registers */
  177. #define PARAM_OFFSET    (0x4000 / 4)
  178. #define OPT     0x00
  179. #define SRC     0x04
  180. #define ACNT        0x100
  181. #define BCNT        0x1
  182. #define DST     0x0C
  183. #define SRC_DST_BIDX    0x10
  184. #define LINK_BCNTRLD    0x14
  185. #define SRC_DST_CIDX    0x18
  186. #define CCNT        0x1
  187.  
  188.  
  189. #define COPY_LENGTH 32
  190.  
  191. void main(void)
  192. {
  193.     hostBuffer hostData;
  194.     uint32_t channelMask;
  195.     uint16_t paramOffset;
  196.     edmaParam params;
  197.     volatile uint32_t *ptr;
  198.     volatile uint32_t *ptr_cm;
  199.     volatile edmaParam *pParams;
  200.  
  201.     ptr = EDMA0_CC_BASE;
  202.     ptr_cm = CM_PER_BASE;
  203.  
  204.     /* Clear SYSCFG[STANDBY_INIT] to enable OCP master port */
  205.     CT_CFG.SYSCFG_bit.STANDBY_INIT = 0;
  206.  
  207.     ptr_cm[TPTC0_CLKCTRL] = ON;
  208.     ptr_cm[TPCC_CLKCTRL] = ON;
  209.  
  210.     /* Load channel parameters from DRAM - loaded by host */
  211.     hostData.src = /*buf.src*/ 0x4A310000;  //PRU Shared memory
  212.     hostData.dst = /*buf.dst*/ 0x4A310100;  //PRU Shared memory
  213.     hostData.chan = /*buf.chan*/ 10;
  214.  
  215.     channelMask = (1 << hostData.chan);
  216.  
  217.     /* Map Channel 10 to PaRAM 10 */
  218.     ptr[DCHMAP_10] = (hostData.chan << 5);
  219.  
  220.     /* Setup EDMA region access for Shadow Region 1 */
  221.     ptr[DRAE1] |= channelMask;
  222.  
  223.     /* Clear channel event from EDMA event registers */
  224.     ptr[SECR] |= channelMask;
  225.     ptr[ICR] |= channelMask;
  226.  
  227.     /* Enable channel interrupt */
  228.     ptr[IESR] |= channelMask;
  229.  
  230.     /* Enable channel */
  231.     ptr[EESR] |= channelMask;
  232.  
  233.     /* Clear event missed register */
  234.     ptr[EMCR] |= channelMask;
  235.  
  236.     /* Setup channel to submit to EDMA TC0 */
  237.     ptr[DMAQNUM1] &= 0xFFFFF0FF;
  238.  
  239.     /* Setup and store PaRAM set for transfer */
  240.     paramOffset = PARAM_OFFSET;
  241.     /* channel * 0x20, word address */
  242.     paramOffset += ((hostData.chan << 5) / 4);
  243.  
  244.     params.lnkrld.link = 0xFFFF;
  245.     params.lnkrld.bcntrld = 0x0000;
  246.     params.opt.tcc = hostData.chan;
  247.     params.opt.tcinten = 1;
  248.     params.opt.itcchen = 1;
  249.  
  250.     params.ccnt.ccnt = CCNT;
  251.     params.abcnt.acnt = ACNT;
  252.     params.abcnt.bcnt = BCNT;
  253.     params.bidx.srcbidx = 0x1;
  254.     params.bidx.dstbidx = 0x1;
  255.     params.src = hostData.src;
  256.     params.dst = hostData.dst;
  257.  
  258.     pParams = (volatile edmaParam *)(ptr + paramOffset);
  259.     *pParams = params;
  260.  
  261.     /* Trigger transfer */
  262.     ptr[ESR] = (channelMask);
  263.  
  264.     /* Wait for transfer completion */
  265.     while (!(ptr[IPR] & channelMask)) {
  266.     }
  267.  
  268.     /* Halt PRU core */
  269.     __halt();
  270. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement