1
0

ewl_x280_polling.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 : Encoder Wrapper Layer for 6280/7280/8270/8290 without interrupts
  17. --
  18. ------------------------------------------------------------------------------*/
  19. /*------------------------------------------------------------------------------
  20. 1. Include headers
  21. ------------------------------------------------------------------------------*/
  22. #include "basetype.h"
  23. #include "ewl.h"
  24. #include "ewl_linux_lock.h"
  25. #include "ewl_x280_common.h"
  26. #include "hx280enc.h"
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include <assert.h>
  31. #include <errno.h>
  32. #include <sys/types.h>
  33. #include <unistd.h>
  34. #include <pthread.h>
  35. #ifndef EWL_NO_HW_TIMEOUT
  36. #define EWL_WAIT_HW_TIMEOUT 2 /* HW IRQ timeout in seconds */
  37. #endif
  38. extern volatile u32 asic_status;
  39. void HandleSIGIO(hx280ewl_t * enc)
  40. {
  41. enc->sigio_needed = 0; /* no need for SIGIO when polling */
  42. return;
  43. }
  44. /*******************************************************************************
  45. Function name : EWLReserveHw
  46. Description : Reserve HW resource for currently running codec
  47. *******************************************************************************/
  48. i32 EWLReserveHw(const void *inst)
  49. {
  50. hx280ewl_t *enc = (hx280ewl_t *) inst;
  51. assert(enc != NULL);
  52. PTRACE("EWLReserveHw: PID %d trying to reserve ...\n", getpid());
  53. /* Check invalid parameters */
  54. if(inst == NULL)
  55. return EWL_ERROR;
  56. if(binary_semaphore_wait(enc->semid, 0) != 0)
  57. {
  58. PTRACE("binary_semaphore_wait error: %s\n", strerror(errno));
  59. return EWL_ERROR;
  60. }
  61. PTRACE("Codec semaphore locked\n");
  62. /* we have to lock postprocessor also */
  63. if(binary_semaphore_wait(enc->semid, 1) != 0)
  64. {
  65. PTRACE("binary_semaphore_wait error: %s\n", strerror(errno));
  66. if(binary_semaphore_post(enc->semid, 0) != 0)
  67. {
  68. PTRACE("binary_semaphore_post error: %s\n", strerror(errno));
  69. assert(0);
  70. }
  71. return EWL_ERROR;
  72. }
  73. PTRACE("Post-processor semaphore locked\n");
  74. PTRACE("EWLReserveHw: HW locked by PID %d\n", getpid());
  75. EWLWriteReg(inst, 0x38, 0);
  76. return EWL_OK;
  77. }
  78. /*******************************************************************************
  79. Function name : EWLWaitHwRdy
  80. Description : Poll the encoder interrupt register to notice IRQ
  81. Return type : i32
  82. Argument : void
  83. *******************************************************************************/
  84. i32 EWLWaitHwRdy(const void *inst, u32 *slicesReady)
  85. {
  86. hx280ewl_t *enc = (hx280ewl_t *) inst;
  87. volatile u32 irq_stats;
  88. u32 prevSlicesReady = 0;
  89. i32 ret = EWL_HW_WAIT_TIMEOUT;
  90. struct timespec t;
  91. u32 timeout = 1000; /* Polling interval in microseconds */
  92. int loop = 100; /* How many times to poll before timeout */
  93. assert(enc != NULL);
  94. PTRACE("EWLWaitHwRdy\n");
  95. (void) enc;
  96. /* The function should return when a slice is ready */
  97. if (slicesReady)
  98. prevSlicesReady = *slicesReady;
  99. if(timeout == (u32) (-1) )
  100. {
  101. loop = -1; /* wait forever (almost) */
  102. timeout = 1000; /* 1ms polling interval */
  103. }
  104. t.tv_sec = 0;
  105. t.tv_nsec = timeout - t.tv_sec * 1000;
  106. t.tv_nsec = 1000 * 1000;
  107. do
  108. {
  109. /* Get the number of completed slices from ASIC registers. */
  110. if (slicesReady)
  111. *slicesReady = (enc->pRegBase[21] >> 16) & 0xFF;
  112. irq_stats = enc->pRegBase[1];
  113. PTRACE("EWLWaitHw: IRQ stat = %08x\n", irq_stats);
  114. if((irq_stats & ASIC_STATUS_ALL))
  115. {
  116. /* clear IRQ and slice ready status */
  117. irq_stats &= (~(ASIC_STATUS_SLICE_READY|ASIC_IRQ_LINE));
  118. EWLWriteReg(inst, 0x04, irq_stats);
  119. ret = EWL_OK;
  120. loop = 0;
  121. }
  122. if (slicesReady)
  123. {
  124. if (*slicesReady > prevSlicesReady)
  125. {
  126. ret = EWL_OK;
  127. loop = 0;
  128. }
  129. }
  130. if (loop)
  131. {
  132. if(nanosleep(&t, NULL) != 0)
  133. PTRACE("EWLWaitHw: Sleep interrupted!\n");
  134. }
  135. }
  136. while(loop--);
  137. asic_status = irq_stats; /* update the buffered asic status */
  138. if (slicesReady)
  139. PTRACE("EWLWaitHw: slicesReady = %d\n", *slicesReady);
  140. PTRACE("EWLWaitHw: asic_status = %x\n", asic_status);
  141. PTRACE("EWLWaitHw: OK!\n");
  142. return ret;
  143. }