| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- #include "chip.h"
- #include "board.h"
- #include "FreeRTOS.h"
- #include "ff_stdio.h"
- #define WRAP_CTL_INRSTATUS (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x00))//00
- #define WRAP_CTL_WORK_EN (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x04))//01
- #define WRAP_CTL_02 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x08))//02
- #define WRAP_CTL_INTER_CLR (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x0C))//03
- #define WRAP_CTL_INTER_MASK (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x10))//04
- #define WRAP_CTL_05 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x14))//05
- #define WRAP_CTL_06 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x18))//06
- #define WRAP_CTL_07 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x1C))//07
- #define WRAP_CTL_08 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x20))//08
- #define WRAP_CTL_FISHEYE_H_W_INIT_S0 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x2C))//0b
- #define WRAP_CTL_FISHEYE_H_W_INIT_S1 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x30))
- #define WRAP_CTL_FISHEYE_H_W_INIT_S2 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x34))
- #define WRAP_CTL_FISHEYE_H_W_INIT_S3 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x38))
- #define WRAP_CTL_FISHEYE_H_W_INIT_S4 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x3C))
- #define WRAP_CTL_FISHEYE_H_W_INIT_S5 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x40))
- #define WRAP_CTL_RD_FADDR_Y_S0 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x44))//11
- #define WRAP_CTL_RD_FADDR_Y_S1 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x48))//12
- #define WRAP_CTL_RD_FADDR_Y_S2 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x4C))//13
- #define WRAP_CTL_RD_FADDR_Y_S3 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x50))//14
- #define WRAP_CTL_RD_FADDR_Y_S4 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x54))//15
- #define WRAP_CTL_RD_FADDR_Y_S5 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x58))//16
- #define WRAP_CTL_RD_HEIGHT_WIDETH_YUV_S0 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x5C))//17
- #define WRAP_CTL_RD_HEIGHT_WIDETH_YUV_S1 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x60))//18
- #define WRAP_CTL_RD_HEIGHT_WIDETH_YUV_S2 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x64))//19
- #define WRAP_CTL_RD_HEIGHT_WIDETH_YUV_S3 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x68))//1a
- #define WRAP_CTL_RD_HEIGHT_WIDETH_YUV_S4 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x6C))//1b
- #define WRAP_CTL_RD_HEIGHT_WIDETH_YUV_S5 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x70))//1c
- #define WRAP_CTL_RD_LINE_WIDE_INIT_S0 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x74))//1d
- #define WRAP_CTL_RD_LINE_WIDE_INIT_S1 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x78))//1e
- #define WRAP_CTL_RD_LINE_WIDE_INIT_S2 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x7c))//1f
- #define WRAP_CTL_RD_LINE_WIDE_INIT_S3 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x80))//20
- #define WRAP_CTL_RD_LINE_WIDE_INIT_S4 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x84))//21
- #define WRAP_CTL_RD_LINE_WIDE_INIT_S5 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0x88))//22
- #define WRAP_CTL_RD_FADDR_ML_S0 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xA0))//28
- #define WRAP_CTL_RD_FADDR_ML_S1 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xA4))//29
- #define WRAP_CTL_RD_FADDR_ML_S2 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xA8))//2a
- #define WRAP_CTL_RD_FADDR_ML_S3 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xAC))//2b
- #define WRAP_CTL_RD_FADDR_ML_S4 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xB0))//2c
- #define WRAP_CTL_RD_FADDR_ML_S5 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xB4))//2d
- #define WRAP_CTL_ML_HEIGHT_WIDETH_S0 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xB8))//2e
- #define WRAP_CTL_ML_HEIGHT_WIDETH_S1 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xBC))//2f
- #define WRAP_CTL_ML_HEIGHT_WIDETH_S2 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xC0))//30
- #define WRAP_CTL_ML_HEIGHT_WIDETH_S3 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xC4))//31
- #define WRAP_CTL_ML_HEIGHT_WIDETH_S4 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xC8))//32
- #define WRAP_CTL_ML_HEIGHT_WIDETH_S5 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xCC))//33
- //畸变校正图坐标读取,整个坐标图在memory的一行宽度
- #define WRAP_CTL_IMG_R_S1_S0 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xD0))//34
- #define WRAP_CTL_IMG_R_S3_S2 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xD4))//35
- #define WRAP_CTL_IMG_R_S5_S4 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xD8))//36
- //畸变校正图回写memory时,memory中一行的宽度
- #define WRAP_CTL_IMG_W_MRM_S1_S0 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xDC))//37
- #define WRAP_CTL_IMG_W_MRM_S3_S2 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xE0))//38
- #define WRAP_CTL_IMG_W_MRM_S5_S4 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xE4))//39
- //畸变校正图,分段数据的存储起始地址
- #define WRAP_CTL_WR_FADDR_RGB_S0 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xE8))//3a
- #define WRAP_CTL_WR_FADDR_RGB_S1 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xEC))//3b
- #define WRAP_CTL_WR_FADDR_RGB_S2 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xF0))//3c
- #define WRAP_CTL_WR_FADDR_RGB_S3 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xF4))//3d
- #define WRAP_CTL_WR_FADDR_RGB_S4 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xF8))//3e
- #define WRAP_CTL_WR_FADDR_RGB_S5 (*(volatile unsigned int *)(REGS_WRAP_BASE + 0xFC))//3f
- #define WRAP_MAX_WIDTH 1024//VIN_WIDTH
- #define WRAP_MAX_HEIGHT 600//VIN_HEIGHTs
- static void *srcwrap_buf = NULL;
- static void *srcwrap_buf2 = NULL;
- static void *deswrap_buf = NULL;
- static void *coordinatewrap_buf = NULL;
- static TaskHandle_t wrap_task;
- QueueHandle_t xDataQueue;
- extern int usb_wait_stor_dev_pluged(uint32_t timeout);
- static void Wrap_interupt_handler(void *param)
- {
- unsigned int val;
- val = WRAP_CTL_INRSTATUS;
- WRAP_CTL_INTER_CLR = 1;
- if(val>>5 & 0x1)
- {
- printf("write back error!!\n");
- }
- if(val>>3 & 0x1)
- {
- xTaskNotifyFromISR(wrap_task, 0, eSetValueWithOverwrite, 0);
- printf("Fish eye work down!!\n");
- }
- }
- static void wrap_display(void *param)
- {
- unsigned int val;
- unsigned int srcwide,srcheight;
- unsigned int Pic_src_init_sel;
- unsigned int wb_bus_bvalid_dsen;
- unsigned int wb_wait_en;
- unsigned int fml_whc_sel;
- unsigned int fml_bit_sel;
- unsigned int width_mode;
- unsigned int Sections;
- uint32_t ulNotifiedValue;
- unsigned int status;
- FF_FILE *fp;
- size_t filesize;
- int rlen;
- srcwide = 800;
- srcheight = 480;
- Pic_src_init_sel = 0;//set srcpicture mode select bit22
- wb_bus_bvalid_dsen = 0;//interrupt mode bit20
- wb_wait_en = 0;//bit19
- fml_whc_sel = 1;//bit17
- fml_bit_sel = 0;//bit16
- Sections = 0x1; //bit8--13
- width_mode = 0;//0 --1024;1---512
- status = usb_wait_stor_dev_pluged(portMAX_DELAY);
- if (status == 0) {
- fp = ff_fopen("/usb/Distort_480x800_a888.bin", "rb");
- filesize = ff_filelength(fp);
- rlen = ff_fread(srcwrap_buf, 1, filesize, fp);
- if (rlen <= 0) {
- printf("read data fail.\n");
- }
- if (fp)
- ff_fclose(fp);
- fp = ff_fopen("/usb/out.bin", "rb");
- filesize = ff_filelength(fp);
- rlen = ff_fread(coordinatewrap_buf, 1, filesize, fp);
- if (rlen <= 0) {
- printf("read data fail.\n");
- }
- if (fp)
- ff_fclose(fp);
- }
- //wrap ram切换
- unsigned int value = 0;
- value = (*(volatile unsigned int *)(0x50000000 + 0x1c8));
- value |= (1<<0);
- (*(volatile unsigned int *)(0x50000000 + 0x1c8)) = value;
- //softreset
- WRAP_CTL_INRSTATUS |= 1<<1;
- val = WRAP_CTL_INRSTATUS;
- val &=~(0x3F<<8 | 0x1 << 16 | 0x1 << 17| 0x1 << 18 | 0x1 << 20| 0x1 << 19 | 0x1 << 22 );
- 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;
- WRAP_CTL_INRSTATUS = val;
- //原图的高度和高度
- WRAP_CTL_FISHEYE_H_W_INIT_S0 = (480<<16)|(800<<0);
- //源图,分段,Y(rgb)通道的起始地址
- WRAP_CTL_RD_FADDR_Y_S0 = (unsigned int )srcwrap_buf;
- //源图分段的高度和宽度
- WRAP_CTL_RD_HEIGHT_WIDETH_YUV_S0 = (480<<16)|(800<<0);
- //分段1源图的起始点在原图中的垂直位置和水平位置
- WRAP_CTL_RD_LINE_WIDE_INIT_S0 = (0<<16)|(0<<0);
- //畸变校正图坐标,分段,映射坐标的起始地址配置
- WRAP_CTL_RD_FADDR_ML_S0 = (unsigned int)coordinatewrap_buf;
- //畸变校正图坐标,分段的高度和宽度
- WRAP_CTL_ML_HEIGHT_WIDETH_S0 = (480<<16)|(800<<0);
- //畸变校正图坐标读取,整个坐标图在memory的一行宽度
- WRAP_CTL_IMG_R_S1_S0 = (800<<16)|(800<<0);
- //畸变校正图回写memory时,memory中一行的宽度
- WRAP_CTL_IMG_W_MRM_S1_S0 = (800<<16)|(800<<0);
- //畸变校正图,分段,数据的存储起始地址
- WRAP_CTL_WR_FADDR_RGB_S0 = (unsigned int )deswrap_buf;
- request_irq(WRAP_IRQn, 0, Wrap_interupt_handler, NULL);
- WRAP_CTL_INTER_MASK = 0;
- WRAP_CTL_02 |= 0x55<<12;
- WRAP_CTL_WORK_EN = 1;
- //while(!wrap_work_down);
- xTaskNotifyWait( 0x00, /* Don't clear any notification bits on entry. */
- 0xffffffff, /* Reset the notification value to 0 on exit. */
- &ulNotifiedValue, /* Notified value pass out in ulNotifiedValue. */
- portMAX_DELAY);
- ark_lcd_osd_enable(LCD_VIDEO_LAYER, 0);
- ark_lcd_osd_enable(LCD_UI_LAYER, 0);
- ark_lcd_set_osd_sync(LCD_VIDEO_LAYER);
- ark_lcd_set_osd_sync(LCD_UI_LAYER);
- ark_lcd_osd_coeff_enable(LCD_VIDEO_LAYER, 1);
- ark_lcd_osd_set_coeff(LCD_VIDEO_LAYER, 0xFF);
- ark_lcd_set_osd_possition(LCD_VIDEO_LAYER, 560,120);
- ark_lcd_set_osd_size(LCD_VIDEO_LAYER, srcwide, srcheight);
- ark_lcd_set_osd_format(LCD_VIDEO_LAYER, LCD_OSD_FORAMT_ARGB888);
- ark_lcd_set_osd_yaddr(LCD_VIDEO_LAYER, (unsigned int)deswrap_buf);
- ark_lcd_osd_enable(LCD_VIDEO_LAYER, 1);
- ark_lcd_set_osd_sync(LCD_VIDEO_LAYER);
- ark_lcd_wait_for_vsync();
- while(1)
- vTaskDelay(portMAX_DELAY);
- }
- void wrap_demo(void)
- {
- srcwrap_buf = (void *)pvPortMalloc(WRAP_MAX_WIDTH * WRAP_MAX_HEIGHT * 4);
- if (!srcwrap_buf) {
- printf("Src wrap buf malloc memory fail.\n");
- return;
- }
- deswrap_buf = (void *)pvPortMalloc(WRAP_MAX_WIDTH * WRAP_MAX_HEIGHT * 4);
- if (!deswrap_buf) {
- printf("Des wrap buf malloc memory fail.\n");
- return;
- }
- coordinatewrap_buf = (void *)pvPortMalloc(WRAP_MAX_WIDTH * WRAP_MAX_HEIGHT * 5);
- if (!coordinatewrap_buf) {
- printf("Des wrap buf malloc memory fail.\n");
- return;
- }
- memset(srcwrap_buf, 0, WRAP_MAX_WIDTH * WRAP_MAX_HEIGHT*4);
- memset(deswrap_buf, 0, WRAP_MAX_WIDTH * WRAP_MAX_HEIGHT*4);
- memset(coordinatewrap_buf, 0, WRAP_MAX_WIDTH * WRAP_MAX_HEIGHT * 5);
- printf(">>>srcwrap_buf 0x%x,deswrap_buf 0x%x,coordinatewrap_buf 0x%x\n",srcwrap_buf,deswrap_buf,coordinatewrap_buf);
- if (xTaskCreate(wrap_display, "wrapdis", configMINIMAL_STACK_SIZE * 10, NULL,
- configMAX_PRIORITIES - 3, &wrap_task) != pdPASS) {
- printf("create itu display task fail.\n");
- }
- }
|