You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
5.9 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * __prussdrv.h
  3. *
  4. *
  5. * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
  6. *
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * Neither the name of Texas Instruments Incorporated nor the names of
  21. * its contributors may be used to endorse or promote products derived
  22. * from this software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  27. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  28. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. *
  36. */
  37. /*
  38. * ============================================================================
  39. * Copyright (c) Texas Instruments Inc 2010-11
  40. *
  41. * Use of this software is controlled by the terms and conditions found in the
  42. * license agreement under which this software has been supplied or provided.
  43. * ============================================================================
  44. */
  45. #include <stdio.h>
  46. #include <stdlib.h>
  47. #include <stdint.h>
  48. #include <ctype.h>
  49. #include <fcntl.h>
  50. #include <string.h>
  51. #include <time.h>
  52. #include <unistd.h>
  53. #include <errno.h>
  54. #include <sys/ioctl.h>
  55. #include <sys/mman.h>
  56. #include <sys/types.h>
  57. #include <sys/stat.h>
  58. #include <linux/unistd.h>
  59. #define PRUSS_IRAM_SIZE 4096
  60. #define PRUSS_DATARAM_SIZE 512
  61. #define DATARAM0_PHYS_BASE 0x01C30000
  62. #define DATARAM1_PHYS_BASE 0x01C32000
  63. #define INTC_PHYS_BASE 0x01C34000
  64. #define PRU0CONTROL_PHYS_BASE 0x01C37000
  65. #define PRU0DEBUG_PHYS_BASE 0x01C37400
  66. #define PRU1CONTROL_PHYS_BASE 0x01C37800
  67. #define PRU1DEBUG_PHYS_BASE 0x01C37C00
  68. #define PRU0IRAM_PHYS_BASE 0x01C38000
  69. #define PRU1IRAM_PHYS_BASE 0x01C3C000
  70. //NOTE: Above defines are SOC specific
  71. #define PRU_INTC_REVID_REG 0x000
  72. #define PRU_INTC_CR_REG 0x004
  73. #define PRU_INTC_HCR_REG 0x00C
  74. #define PRU_INTC_GER_REG 0x010
  75. #define PRU_INTC_GNLR_REG 0x01C
  76. #define PRU_INTC_SISR_REG 0x020
  77. #define PRU_INTC_SICR_REG 0x024
  78. #define PRU_INTC_EISR_REG 0x028
  79. #define PRU_INTC_EICR_REG 0x02C
  80. #define PRU_INTC_HIEISR_REG 0x034
  81. #define PRU_INTC_HIDISR_REG 0x038
  82. #define PRU_INTC_GPIR_REG 0x080
  83. #define PRU_INTC_SRSR1_REG 0x200
  84. #define PRU_INTC_SRSR2_REG 0x204
  85. #define PRU_INTC_SECR1_REG 0x280
  86. #define PRU_INTC_SECR2_REG 0x284
  87. #define PRU_INTC_ESR1_REG 0x300
  88. #define PRU_INTC_ESR2_REG 0x304
  89. #define PRU_INTC_ECR1_REG 0x380
  90. #define PRU_INTC_ECR2_REG 0x384
  91. #define PRU_INTC_CMR1_REG 0x400
  92. #define PRU_INTC_CMR2_REG 0x404
  93. #define PRU_INTC_CMR3_REG 0x408
  94. #define PRU_INTC_CMR4_REG 0x40C
  95. #define PRU_INTC_CMR5_REG 0x410
  96. #define PRU_INTC_CMR6_REG 0x414
  97. #define PRU_INTC_CMR7_REG 0x418
  98. #define PRU_INTC_CMR8_REG 0x41C
  99. #define PRU_INTC_CMR9_REG 0x420
  100. #define PRU_INTC_CMR10_REG 0x424
  101. #define PRU_INTC_CMR11_REG 0x428
  102. #define PRU_INTC_CMR12_REG 0x42C
  103. #define PRU_INTC_CMR13_REG 0x430
  104. #define PRU_INTC_CMR14_REG 0x434
  105. #define PRU_INTC_CMR15_REG 0x438
  106. #define PRU_INTC_CMR16_REG 0x43C
  107. #define PRU_INTC_HMR1_REG 0x800
  108. #define PRU_INTC_HMR2_REG 0x804
  109. #define PRU_INTC_HMR3_REG 0x808
  110. #define PRU_INTC_SIPR1_REG 0xD00
  111. #define PRU_INTC_SIPR2_REG 0xD04
  112. #define PRU_INTC_SITR1_REG 0xD80
  113. #define PRU_INTC_SITR2_REG 0xD84
  114. #define PRU_INTC_HIER_REG 0x1500
  115. #define PRUSS_UIO_DRV_PRUSS_BASE "/sys/class/uio/uio0/maps/map0/addr"
  116. #define PRUSS_UIO_DRV_PRUSS_SIZE "/sys/class/uio/uio0/maps/map0/size"
  117. #define PRUSS_UIO_DRV_L3RAM_BASE "/sys/class/uio/uio0/maps/map1/addr"
  118. #define PRUSS_UIO_DRV_L3RAM_SIZE "/sys/class/uio/uio0/maps/map1/size"
  119. #define PRUSS_UIO_DRV_EXTRAM_BASE "/sys/class/uio/uio0/maps/map2/addr"
  120. #define PRUSS_UIO_DRV_EXTRAM_SIZE "/sys/class/uio/uio0/maps/map2/size"
  121. typedef struct __prussdrv {
  122. int fd[NUM_PRU_HOSTIRQS];
  123. void *pru0dataram_base;
  124. void *pru1dataram_base;
  125. void *intc_base;
  126. void *pru0control_base;
  127. void *pru0debug_base;
  128. void *pru1control_base;
  129. void *pru1debug_base;
  130. void *pru0iram_base;
  131. void *pru1iram_base;
  132. void *l3ram_base;
  133. void *extram_base;
  134. pthread_t irq_thread[NUM_PRU_HOSTIRQS];
  135. int mmap_fd;
  136. } tprussdrv;
  137. static unsigned int pruss_phys_base, pruss_map_size;
  138. static unsigned int l3ram_phys_base, l3ram_map_size;
  139. static unsigned int extram_phys_base, extram_map_size;
  140. void __prussintc_set_cmr(unsigned int *pruintc_io, unsigned short sysevt,
  141. unsigned short channel)
  142. {
  143. pruintc_io[(PRU_INTC_CMR1_REG + (sysevt & ~(0x3))) >> 2] |=
  144. ((channel & 0xF) << ((sysevt & 0x3) << 3));
  145. }
  146. void __prussintc_set_hmr(unsigned int *pruintc_io, unsigned short channel,
  147. unsigned short host)
  148. {
  149. pruintc_io[(PRU_INTC_HMR1_REG + (channel & ~(0x3))) >> 2] =
  150. pruintc_io[(PRU_INTC_HMR1_REG +
  151. (channel & ~(0x3))) >> 2] | (((host) & 0xF) <<
  152. (((channel) & 0x3) << 3));
  153. }