1
0

IntegrationTestRegister.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /*------------------------------------------------------------------------------
  2. -- --
  3. -- This software is confidential and proprietary and may be used --
  4. -- only as expressly authorized by a licensing agreement from --
  5. -- --
  6. -- Hantro Products Oy. --
  7. -- --
  8. -- (C) COPYRIGHT 2006 HANTRO PRODUCTS OY --
  9. -- ALL RIGHTS RESERVED --
  10. -- --
  11. -- The entire notice above must be reproduced --
  12. -- on all copies and should not be removed. --
  13. -- --
  14. --------------------------------------------------------------------------------
  15. --
  16. -- Abstract : Integration test register testbench
  17. --
  18. ------------------------------------------------------------------------------*/
  19. /*------------------------------------------------------------------------------
  20. 1. Include headers
  21. ------------------------------------------------------------------------------*/
  22. /* For encoder EWL interface */
  23. #include "ewl.h"
  24. /* For printing and file IO */
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <time.h>
  28. #ifdef USE_EFENCE
  29. #include "efence.h"
  30. #endif
  31. #define ERR_OUTPUT stdout
  32. /*------------------------------------------------------------------------------
  33. 2. External compiler flags
  34. --------------------------------------------------------------------------------
  35. --------------------------------------------------------------------------------
  36. 3. Module defines
  37. ------------------------------------------------------------------------------*/
  38. /* User selectable testbench configuration */
  39. /* Buffer size in 64-bit words */
  40. #define BUFFER_SIZE (4096)
  41. /* Amount of data to be copied from input buffer
  42. to output buffer in 64-bit words */
  43. #define DATA_LENGTH (2048)
  44. /* Global variables */
  45. /* EWL instance */
  46. const void *ewlInst = NULL;
  47. /* SW/HW shared memories */
  48. EWLLinearMem_t inbuf;
  49. EWLLinearMem_t outbuf;
  50. /*------------------------------------------------------------------------------
  51. 4. Local function prototypes
  52. ------------------------------------------------------------------------------*/
  53. static int AllocRes(void);
  54. static void FreeRes(void);
  55. static void TestRegister(void);
  56. void MemSet(u32 * buffer, int size);
  57. /*------------------------------------------------------------------------------
  58. main
  59. This testbench runs a number of tests for the ASIC integration register.
  60. It uses the EWL interface to access the ASIC registers and to allocate
  61. HW/SW shared memories.
  62. ------------------------------------------------------------------------------*/
  63. int main(int argc, char *argv[])
  64. {
  65. u32 id;
  66. i32 ret;
  67. EWLInitParam_t param;
  68. /* First we call the EWLReadAsicID function to read the ID from the
  69. * ASIC register */
  70. id = EWLReadAsicID();
  71. /* Print the ID to the screen */
  72. fprintf(stdout, "\nASIC Integration register test\n");
  73. fprintf(stdout, "HW ID: 0x%08x\n", id);
  74. /* We set the EWL parameters */
  75. param.clientType = EWL_CLIENT_TYPE_MPEG4_ENC;
  76. /* Then we call the EWLInit function to initialize the EWL
  77. * The EWL implementation is platform specific but by using
  78. * the EWL interface we make this testbench platform independent. */
  79. ewlInst = EWLInit(&param);
  80. /* Check the return value and exit if unsuccessful */
  81. if(!ewlInst)
  82. {
  83. fprintf(ERR_OUTPUT, "Failed to initialize EWL\n");
  84. return -1;
  85. }
  86. /* Allocate input and output buffers */
  87. if(AllocRes() != 0)
  88. {
  89. fprintf(ERR_OUTPUT, "Failed to allocate the external resources!\n");
  90. goto end;
  91. }
  92. if(EWLReserveHw(ewlInst) != EWL_OK)
  93. {
  94. fprintf(ERR_OUTPUT, "Failed to lock HW!\n");
  95. goto end;
  96. }
  97. /* Perform the integration register tests */
  98. TestRegister();
  99. EWLReleaseHw(ewlInst);
  100. end:
  101. /* Free memories */
  102. FreeRes();
  103. /* Release EWL instance */
  104. ret = EWLRelease(ewlInst);
  105. if(ret != EWL_OK)
  106. {
  107. fprintf(ERR_OUTPUT, "Failed to release the instance. Error code: %8i\n",
  108. ret);
  109. }
  110. return ret;
  111. }
  112. /*------------------------------------------------------------------------------
  113. AllocRes
  114. Allocate the physical memories used by both SW and HW.
  115. To access the memory HW uses the physical linear address (bus address)
  116. and SW uses virtual address (user address).
  117. ------------------------------------------------------------------------------*/
  118. int AllocRes(void)
  119. {
  120. i32 ret;
  121. /* Call EWL to allocate buffer for HW input */
  122. ret = EWLMallocLinear(ewlInst, BUFFER_SIZE * 8, &inbuf);
  123. if(ret != EWL_OK)
  124. {
  125. return -1;
  126. }
  127. /* Call EWL to allocate buffer for HW output */
  128. ret = EWLMallocLinear(ewlInst, BUFFER_SIZE * 8, &outbuf);
  129. if(ret != EWL_OK)
  130. {
  131. return -1;
  132. }
  133. /* Print the buffer information */
  134. printf("Input buffer size:\t%8d bytes\nOutput buffer size:\t%8d bytes\n",
  135. inbuf.size, outbuf.size);
  136. printf("Input buffer bus address:\t0x%08x\n", inbuf.busAddress);
  137. printf("Input buffer user address:\t0x%08x\n", (u32) inbuf.virtualAddress);
  138. printf("Output buffer bus address:\t0x%08x\n", outbuf.busAddress);
  139. printf("Output buffer user address:\t0x%08x\n",
  140. (u32) outbuf.virtualAddress);
  141. return 0;
  142. }
  143. /*------------------------------------------------------------------------------
  144. FreeRes
  145. ------------------------------------------------------------------------------*/
  146. void FreeRes(void)
  147. {
  148. EWLFreeLinear(ewlInst, &inbuf);
  149. EWLFreeLinear(ewlInst, &outbuf);
  150. }
  151. /*------------------------------------------------------------------------------
  152. TestRegister
  153. ------------------------------------------------------------------------------*/
  154. void TestRegister(void)
  155. {
  156. i32 i;
  157. u32 value;
  158. i32 ret;
  159. /* Interrupt test: integration test register bit 0
  160. * When bit 0 is set to 1 HW should generate interrupt */
  161. fprintf(stdout,
  162. "\nASIC Integration register test bit 0\n\tIRQ generation\n");
  163. EWLWriteReg(ewlInst, 0x04, 0); /* enable IRQ generation */
  164. value = 0x1;
  165. EWLWriteReg(ewlInst, 0xC, value);
  166. /* Check for interrupt */
  167. ret = EWLWaitHwRdy(ewlInst, NULL);
  168. if(ret != EWL_OK)
  169. {
  170. fprintf(ERR_OUTPUT, "\tFAILED to receive interrupt. Error code: %8i\n",
  171. ret);
  172. }
  173. else
  174. {
  175. fprintf(stdout, "\tPASSED\n");
  176. }
  177. EWLWriteReg(ewlInst, 0xC, 0); /* clear test IRQ generation */
  178. EWLWriteReg(ewlInst, 0x04, 0); /* clear IRQ status */
  179. /* Register cache coherency test: integration test register bit 1
  180. * When bit 1 is set to 1 HW should increase the value of bits 31:28 */
  181. fprintf(stdout,
  182. "ASIC Integration register test bit 1\n\tRegister aceess\n");
  183. value = 0xA0000002;
  184. EWLWriteReg(ewlInst, 0xC, value);
  185. /* Read the updated value from register */
  186. value = EWLReadReg(ewlInst, 0xC);
  187. if(value != 0xB0000002)
  188. {
  189. fprintf(ERR_OUTPUT,
  190. "\tFAILED to increment register. Updated register value: 0x%08x\n",
  191. value);
  192. }
  193. else
  194. {
  195. fprintf(stdout, "\tPASSED\n");
  196. }
  197. /* Memory cache coherency test: integration test register bit 2
  198. * When bit 2 is set to 1 HW should copy data from base address of swreg5
  199. * to base address of swreg6. Data length is in bits 20:3 in 64-bit words */
  200. fprintf(stdout, "ASIC Integration register test bit 2\n");
  201. fprintf(stdout, "\tCopying %i bytes of data\n", DATA_LENGTH * 8);
  202. /* Prepare data buffers */
  203. EWLmemset(inbuf.virtualAddress, 0, BUFFER_SIZE * 8);
  204. EWLmemset(outbuf.virtualAddress, 0, BUFFER_SIZE * 8);
  205. MemSet(inbuf.virtualAddress, DATA_LENGTH * 8);
  206. /* Write input buffer bus address to swreg5 */
  207. EWLWriteReg(ewlInst, 0x14, inbuf.busAddress);
  208. /* Write output buffer bus address to swreg6 */
  209. EWLWriteReg(ewlInst, 0x18, outbuf.busAddress);
  210. /* Write test bit and data length to swreg3 */
  211. value = 0x00000004 | (DATA_LENGTH << 3);
  212. EWLWriteReg(ewlInst, 0xC, value);
  213. /* Check for interrupt */
  214. ret = EWLWaitHwRdy(ewlInst, NULL);
  215. if(ret != EWL_OK)
  216. {
  217. fprintf(ERR_OUTPUT, "\tFAILED to receive interrupt. Error code: %8i\n",
  218. ret);
  219. }
  220. ret = 0;
  221. /* Check that the output buffer has correct data, using 32-bit words */
  222. for(i = 0; i < DATA_LENGTH * 2; i++)
  223. {
  224. if(outbuf.virtualAddress[i] != inbuf.virtualAddress[i])
  225. {
  226. fprintf(ERR_OUTPUT,
  227. "\tFAILED at 0x%08x [0x%08x] != [0x%08x]\n",
  228. (u32) (outbuf.virtualAddress + i), outbuf.virtualAddress[i],
  229. inbuf.virtualAddress[i]);
  230. ret = -1;
  231. break;
  232. }
  233. }
  234. /* Check that the output buffer beyond the copied area is not changed */
  235. for(i = DATA_LENGTH * 2; i < BUFFER_SIZE * 2; i++)
  236. {
  237. if(outbuf.virtualAddress[i] != 0x0)
  238. {
  239. fprintf(ERR_OUTPUT, "\tBuffer changed at 0x%08x [0x%08x]\n",
  240. (u32) (outbuf.virtualAddress + i),
  241. outbuf.virtualAddress[i]);
  242. ret = -1;
  243. break;
  244. }
  245. }
  246. EWLWriteReg(ewlInst, 0x0C, 0); /* clear test IRQ generation */
  247. EWLWriteReg(ewlInst, 0x04, 0); /* clear IRQ status */
  248. if(ret == 0)
  249. {
  250. fprintf(stdout, "\tPASSED\n\n");
  251. }
  252. }
  253. /* initialize memory buffer with random stuff */
  254. void MemSet(u32 * buffer, int size)
  255. {
  256. int i;
  257. int seed = (int) time(NULL);
  258. srand(seed++);
  259. for(i = 0; i < (size / 4); i++)
  260. {
  261. if(i >= RAND_MAX)
  262. srand(seed++);
  263. buffer[i] = rand();
  264. }
  265. }