wrap.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. #include "chip.h"
  2. #include "board.h"
  3. #include "FreeRTOS.h"
  4. #include "ff_stdio.h"
  5. #define WRAP_CTL_INRSTATUS (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x00))//00
  6. #define WRAP_CTL_WORK_EN (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x04))//01
  7. #define WRAP_CTL_02 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x08))//02
  8. #define WRAP_CTL_INTER_CLR (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x0C))//03
  9. #define WRAP_CTL_INTER_MASK (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x10))//04
  10. #define WRAP_CTL_05 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x14))//05
  11. #define WRAP_CTL_06 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x18))//06
  12. #define WRAP_CTL_07 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x1C))//07
  13. #define WRAP_CTL_08 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x20))//08
  14. #define WRAP_CTL_FISHEYE_H_W_INIT_S0 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x2C))//0b
  15. #define WRAP_CTL_FISHEYE_H_W_INIT_S1 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x30))
  16. #define WRAP_CTL_FISHEYE_H_W_INIT_S2 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x34))
  17. #define WRAP_CTL_FISHEYE_H_W_INIT_S3 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x38))
  18. #define WRAP_CTL_FISHEYE_H_W_INIT_S4 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x3C))
  19. #define WRAP_CTL_FISHEYE_H_W_INIT_S5 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x40))
  20. #define WRAP_CTL_RD_FADDR_Y_S0 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x44))//11
  21. #define WRAP_CTL_RD_FADDR_Y_S1 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x48))//12
  22. #define WRAP_CTL_RD_FADDR_Y_S2 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x4C))//13
  23. #define WRAP_CTL_RD_FADDR_Y_S3 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x50))//14
  24. #define WRAP_CTL_RD_FADDR_Y_S4 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x54))//15
  25. #define WRAP_CTL_RD_FADDR_Y_S5 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x58))//16
  26. #define WRAP_CTL_RD_HEIGHT_WIDETH_YUV_S0 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x5C))//17
  27. #define WRAP_CTL_RD_HEIGHT_WIDETH_YUV_S1 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x60))//18
  28. #define WRAP_CTL_RD_HEIGHT_WIDETH_YUV_S2 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x64))//19
  29. #define WRAP_CTL_RD_HEIGHT_WIDETH_YUV_S3 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x68))//1a
  30. #define WRAP_CTL_RD_HEIGHT_WIDETH_YUV_S4 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x6C))//1b
  31. #define WRAP_CTL_RD_HEIGHT_WIDETH_YUV_S5 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x70))//1c
  32. #define WRAP_CTL_RD_LINE_WIDE_INIT_S0 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x74))//1d
  33. #define WRAP_CTL_RD_LINE_WIDE_INIT_S1 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x78))//1e
  34. #define WRAP_CTL_RD_LINE_WIDE_INIT_S2 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x7c))//1f
  35. #define WRAP_CTL_RD_LINE_WIDE_INIT_S3 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x80))//20
  36. #define WRAP_CTL_RD_LINE_WIDE_INIT_S4 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x84))//21
  37. #define WRAP_CTL_RD_LINE_WIDE_INIT_S5 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x88))//22
  38. #define WRAP_CTL_RD_FADDR_ML_S0 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xA0))//28
  39. #define WRAP_CTL_RD_FADDR_ML_S1 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xA4))//29
  40. #define WRAP_CTL_RD_FADDR_ML_S2 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xA8))//2a
  41. #define WRAP_CTL_RD_FADDR_ML_S3 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xAC))//2b
  42. #define WRAP_CTL_RD_FADDR_ML_S4 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xB0))//2c
  43. #define WRAP_CTL_RD_FADDR_ML_S5 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xB4))//2d
  44. #define WRAP_CTL_ML_HEIGHT_WIDETH_S0 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xB8))//2e
  45. #define WRAP_CTL_ML_HEIGHT_WIDETH_S1 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xBC))//2f
  46. #define WRAP_CTL_ML_HEIGHT_WIDETH_S2 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xC0))//30
  47. #define WRAP_CTL_ML_HEIGHT_WIDETH_S3 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xC4))//31
  48. #define WRAP_CTL_ML_HEIGHT_WIDETH_S4 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xC8))//32
  49. #define WRAP_CTL_ML_HEIGHT_WIDETH_S5 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xCC))//33
  50. //畸变校正图坐标读取,整个坐标图在memory的一行宽度
  51. #define WRAP_CTL_IMG_R_S1_S0 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xD0))//34
  52. #define WRAP_CTL_IMG_R_S3_S2 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xD4))//35
  53. #define WRAP_CTL_IMG_R_S5_S4 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xD8))//36
  54. //畸变校正图回写memory时,memory中一行的宽度
  55. #define WRAP_CTL_IMG_W_MRM_S1_S0 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xDC))//37
  56. #define WRAP_CTL_IMG_W_MRM_S3_S2 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xE0))//38
  57. #define WRAP_CTL_IMG_W_MRM_S5_S4 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xE4))//39
  58. //畸变校正图,分段数据的存储起始地址
  59. #define WRAP_CTL_WR_FADDR_RGB_S0 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xE8))//3a
  60. #define WRAP_CTL_WR_FADDR_RGB_S1 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xEC))//3b
  61. #define WRAP_CTL_WR_FADDR_RGB_S2 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xF0))//3c
  62. #define WRAP_CTL_WR_FADDR_RGB_S3 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xF4))//3d
  63. #define WRAP_CTL_WR_FADDR_RGB_S4 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xF8))//3e
  64. #define WRAP_CTL_WR_FADDR_RGB_S5 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xFC))//3f
  65. #define WRAP_MAX_WIDTH 1024//VIN_WIDTH
  66. #define WRAP_MAX_HEIGHT 600//VIN_HEIGHTs
  67. static void *srcwrap_buf = NULL;
  68. static void *srcwrap_buf2 = NULL;
  69. static void *deswrap_buf = NULL;
  70. static void *coordinatewrap_buf = NULL;
  71. static TaskHandle_t wrap_task;
  72. QueueHandle_t xDataQueue;
  73. extern int usb_wait_stor_dev_pluged(uint32_t timeout);
  74. static void Wrap_interupt_handler(void *param)
  75. {
  76. unsigned int val;
  77. val = WRAP_CTL_INRSTATUS;
  78. WRAP_CTL_INTER_CLR = 1;
  79. if(val>>5 & 0x1)
  80. {
  81. printf("write back error!!\n");
  82. }
  83. if(val>>3 & 0x1)
  84. {
  85. xTaskNotifyFromISR(wrap_task, 0, eSetValueWithOverwrite, 0);
  86. printf("Fish eye work down!!\n");
  87. }
  88. }
  89. static void wrap_display(void *param)
  90. {
  91. unsigned int val;
  92. unsigned int srcwide,srcheight;
  93. unsigned int Pic_src_init_sel;
  94. unsigned int wb_bus_bvalid_dsen;
  95. unsigned int wb_wait_en;
  96. unsigned int fml_whc_sel;
  97. unsigned int fml_bit_sel;
  98. unsigned int width_mode;
  99. unsigned int Sections;
  100. uint32_t ulNotifiedValue;
  101. unsigned int status;
  102. FF_FILE *fp;
  103. size_t filesize;
  104. int rlen;
  105. srcwide = 800;
  106. srcheight = 480;
  107. Pic_src_init_sel = 0;//set srcpicture mode select bit22
  108. wb_bus_bvalid_dsen = 0;//interrupt mode bit20
  109. wb_wait_en = 0;//bit19
  110. fml_whc_sel = 1;//bit17
  111. fml_bit_sel = 0;//bit16
  112. Sections = 0x1; //bit8--13
  113. width_mode = 0;//0 --1024;1---512
  114. status = usb_wait_stor_dev_pluged(portMAX_DELAY);
  115. if (status == 0) {
  116. fp = ff_fopen("/usb/Distort_480x800_a888.bin", "rb");
  117. filesize = ff_filelength(fp);
  118. rlen = ff_fread(srcwrap_buf, 1, filesize, fp);
  119. if (rlen <= 0) {
  120. printf("read data fail.\n");
  121. }
  122. if (fp)
  123. ff_fclose(fp);
  124. fp = ff_fopen("/usb/out.bin", "rb");
  125. filesize = ff_filelength(fp);
  126. rlen = ff_fread(coordinatewrap_buf, 1, filesize, fp);
  127. if (rlen <= 0) {
  128. printf("read data fail.\n");
  129. }
  130. if (fp)
  131. ff_fclose(fp);
  132. }
  133. //wrap ram切换
  134. unsigned int value = 0;
  135. value = (*(volatile unsigned int *)(0x50000000 + 0x1c8));
  136. value |= (1<<0);
  137. (*(volatile unsigned int *)(0x50000000 + 0x1c8)) = value;
  138. //softreset
  139. WRAP_CTL_INRSTATUS |= 1<<1;
  140. val = WRAP_CTL_INRSTATUS;
  141. val &=~(0x3F<<8 | 0x1 << 16 | 0x1 << 17| 0x1 << 18 | 0x1 << 20| 0x1 << 19 | 0x1 << 22 );
  142. val |= Sections<<8 | fml_bit_sel<<16 | fml_whc_sel<<17 | width_mode<<18 | wb_wait_en<<19 | wb_bus_bvalid_dsen<<20 | Pic_src_init_sel<<22;
  143. WRAP_CTL_INRSTATUS = val;
  144. //原图的高度和高度
  145. WRAP_CTL_FISHEYE_H_W_INIT_S0 = (480<<16)|(800<<0);
  146. //源图,分段,Y(rgb)通道的起始地址
  147. WRAP_CTL_RD_FADDR_Y_S0 = (unsigned int )srcwrap_buf;
  148. //源图分段的高度和宽度
  149. WRAP_CTL_RD_HEIGHT_WIDETH_YUV_S0 = (480<<16)|(800<<0);
  150. //分段1源图的起始点在原图中的垂直位置和水平位置
  151. WRAP_CTL_RD_LINE_WIDE_INIT_S0 = (0<<16)|(0<<0);
  152. //畸变校正图坐标,分段,映射坐标的起始地址配置
  153. WRAP_CTL_RD_FADDR_ML_S0 = (unsigned int)coordinatewrap_buf;
  154. //畸变校正图坐标,分段的高度和宽度
  155. WRAP_CTL_ML_HEIGHT_WIDETH_S0 = (480<<16)|(800<<0);
  156. //畸变校正图坐标读取,整个坐标图在memory的一行宽度
  157. WRAP_CTL_IMG_R_S1_S0 = (800<<16)|(800<<0);
  158. //畸变校正图回写memory时,memory中一行的宽度
  159. WRAP_CTL_IMG_W_MRM_S1_S0 = (800<<16)|(800<<0);
  160. //畸变校正图,分段,数据的存储起始地址
  161. WRAP_CTL_WR_FADDR_RGB_S0 = (unsigned int )deswrap_buf;
  162. request_irq(WRAP_IRQn, 0, Wrap_interupt_handler, NULL);
  163. WRAP_CTL_INTER_MASK = 0;
  164. WRAP_CTL_02 |= 0x55<<12;
  165. WRAP_CTL_WORK_EN = 1;
  166. //while(!wrap_work_down);
  167. xTaskNotifyWait( 0x00, /* Don't clear any notification bits on entry. */
  168. 0xffffffff, /* Reset the notification value to 0 on exit. */
  169. &ulNotifiedValue, /* Notified value pass out in ulNotifiedValue. */
  170. portMAX_DELAY);
  171. ark_lcd_osd_enable(LCD_VIDEO_LAYER, 0);
  172. ark_lcd_osd_enable(LCD_UI_LAYER, 0);
  173. ark_lcd_set_osd_sync(LCD_VIDEO_LAYER);
  174. ark_lcd_set_osd_sync(LCD_UI_LAYER);
  175. ark_lcd_osd_coeff_enable(LCD_VIDEO_LAYER, 1);
  176. ark_lcd_osd_set_coeff(LCD_VIDEO_LAYER, 0xFF);
  177. ark_lcd_set_osd_possition(LCD_VIDEO_LAYER, 560,120);
  178. ark_lcd_set_osd_size(LCD_VIDEO_LAYER, srcwide, srcheight);
  179. ark_lcd_set_osd_format(LCD_VIDEO_LAYER, LCD_OSD_FORAMT_ARGB888);
  180. ark_lcd_set_osd_yaddr(LCD_VIDEO_LAYER, (unsigned int)deswrap_buf);
  181. ark_lcd_osd_enable(LCD_VIDEO_LAYER, 1);
  182. ark_lcd_set_osd_sync(LCD_VIDEO_LAYER);
  183. ark_lcd_wait_for_vsync();
  184. while(1)
  185. vTaskDelay(portMAX_DELAY);
  186. }
  187. void wrap_demo(void)
  188. {
  189. srcwrap_buf = (void *)pvPortMalloc(WRAP_MAX_WIDTH * WRAP_MAX_HEIGHT * 4);
  190. if (!srcwrap_buf) {
  191. printf("Src wrap buf malloc memory fail.\n");
  192. return;
  193. }
  194. deswrap_buf = (void *)pvPortMalloc(WRAP_MAX_WIDTH * WRAP_MAX_HEIGHT * 4);
  195. if (!deswrap_buf) {
  196. printf("Des wrap buf malloc memory fail.\n");
  197. return;
  198. }
  199. coordinatewrap_buf = (void *)pvPortMalloc(WRAP_MAX_WIDTH * WRAP_MAX_HEIGHT * 5);
  200. if (!coordinatewrap_buf) {
  201. printf("Des wrap buf malloc memory fail.\n");
  202. return;
  203. }
  204. memset(srcwrap_buf, 0, WRAP_MAX_WIDTH * WRAP_MAX_HEIGHT*4);
  205. memset(deswrap_buf, 0, WRAP_MAX_WIDTH * WRAP_MAX_HEIGHT*4);
  206. memset(coordinatewrap_buf, 0, WRAP_MAX_WIDTH * WRAP_MAX_HEIGHT * 5);
  207. printf(">>>srcwrap_buf 0x%x,deswrap_buf 0x%x,coordinatewrap_buf 0x%x\n",srcwrap_buf,deswrap_buf,coordinatewrap_buf);
  208. if (xTaskCreate(wrap_display, "wrapdis", configMINIMAL_STACK_SIZE * 10, NULL,
  209. configMAX_PRIORITIES - 3, &wrap_task) != pdPASS) {
  210. printf("create itu display task fail.\n");
  211. }
  212. }