【ZYNQ_LINUX 】使用问题 invalid conversion from 'unsigned int' to 'unsigned char*' [-fpermissive]

http://blog.csdn.net/qtebook/article/details/51969713

http://blog.csdn.net/luotong86/article/details/52486365#insertcode

http://blog.csdn.net/lst227405/article/details/25975661

https://lauri.xn--vsandi-pxa.com/hdl/zynq/xilinx-video-capture.html


修改方法 :

                 arm-xilinx-linux-gnueabi-gcc -fpermissive -o vdma vdma.cpp

编译结果仍然出错。

于是我都改成了int 

修改成最下方的样子,可以编译出来了,我去搭一个vivado 工程试一下结果

vdma.cpp: In function 'int vdma_setup(vdma_handle*, unsigned int, int, int, int, unsigned int, unsigned int, unsigned int)':
vdma.cpp:90:147: error: cannot convert 'unsigned int*' to 'unsigned char*' in assignment
vdma.cpp:96:34: warning: invalid conversion from 'unsigned int' to 'unsigned char*' [-fpermissive]
vdma.cpp:103:34: warning: invalid conversion from 'unsigned int' to 'unsigned char*' [-fpermissive]
vdma.cpp:110:34: warning: invalid conversion from 'unsigned int' to 'unsigned char*' [-fpermissive]
vdma.cpp:118:92: error: 'memset' was not declared in this scope
vdma.cpp: In function 'void vdma_halt(vdma_handle*)':
vdma.cpp:126:84: error: 'vdma_set' was not declared in this scope
vdma.cpp: In function 'void vdma_start_triple_buffering(vdma_handle*)':
vdma.cpp:214:79: warning: invalid conversion from 'unsigned char*' to 'unsigned int' [-fpermissive]
vdma.cpp:139:6: warning:   initializing argument 3 of 'void vdma_set(vdma_handle*, int, unsigned int)' [-fpermissive]
vdma.cpp:215:79: warning: invalid conversion from 'unsigned char*' to 'unsigned int' [-fpermissive]
vdma.cpp:139:6: warning:   initializing argument 3 of 'void vdma_set(vdma_handle*, int, unsigned int)' [-fpermissive]
vdma.cpp:216:79: warning: invalid conversion from 'unsigned char*' to 'unsigned int' [-fpermissive]
vdma.cpp:139:6: warning:   initializing argument 3 of 'void vdma_set(vdma_handle*, int, unsigned int)' [-fpermissive]
vdma.cpp:218:79: warning: invalid conversion from 'unsigned char*' to 'unsigned int' [-fpermissive]
vdma.cpp:139:6: warning:   initializing argument 3 of 'void vdma_set(vdma_handle*, int, unsigned int)' [-fpermissive]
vdma.cpp:219:79: warning: invalid conversion from 'unsigned char*' to 'unsigned int' [-fpermissive]
vdma.cpp:139:6: warning:   initializing argument 3 of 'void vdma_set(vdma_handle*, int, unsigned int)' [-fpermissive]
vdma.cpp:220:79: warning: invalid conversion from 'unsigned char*' to 'unsigned int' [-fpermissive]
vdma.cpp:139:6: warning:   initializing argument 3 of 'void vdma_set(vdma_handle*, int, unsigned int)' [-fpermissive]
vdma.cpp: In function 'int main()':
vdma.cpp:263:59: error: 'memset' was not declared in this scope



修改后:

#include <stdio.h>  
#include <cstring>
#include<string.h>
#include <unistd.h>  
#include <fcntl.h>  
#include <sys/mman.h>  
#include <pthread.h>  
  
/* Register offsets */  
#define OFFSET_PARK_PTR_REG                     0x28  
#define OFFSET_VERSION                          0x2c  
  
#define OFFSET_VDMA_MM2S_CONTROL_REGISTER       0x00  
#define OFFSET_VDMA_MM2S_STATUS_REGISTER        0x04  
#define OFFSET_VDMA_MM2S_VSIZE                  0x50  
#define OFFSET_VDMA_MM2S_HSIZE                  0x54  
#define OFFSET_VDMA_MM2S_FRMDLY_STRIDE          0x58  
#define OFFSET_VDMA_MM2S_FRAMEBUFFER1           0x5c  
#define OFFSET_VDMA_MM2S_FRAMEBUFFER2           0x60  
#define OFFSET_VDMA_MM2S_FRAMEBUFFER3           0x64  
#define OFFSET_VDMA_MM2S_FRAMEBUFFER4           0x68  
  
#define OFFSET_VDMA_S2MM_CONTROL_REGISTER       0x30  
#define OFFSET_VDMA_S2MM_STATUS_REGISTER        0x34  
#define OFFSET_VDMA_S2MM_IRQ_MASK               0x3c  
#define OFFSET_VDMA_S2MM_REG_INDEX              0x44  
#define OFFSET_VDMA_S2MM_VSIZE                  0xa0  
#define OFFSET_VDMA_S2MM_HSIZE                  0xa4  
#define OFFSET_VDMA_S2MM_FRMDLY_STRIDE          0xa8  
#define OFFSET_VDMA_S2MM_FRAMEBUFFER1           0xac  
#define OFFSET_VDMA_S2MM_FRAMEBUFFER2           0xb0  
#define OFFSET_VDMA_S2MM_FRAMEBUFFER3           0xb4  
#define OFFSET_VDMA_S2MM_FRAMEBUFFER4           0xb8  
  
/* S2MM and MM2S control register flags */  
#define VDMA_CONTROL_REGISTER_START                     0x00000001  
#define VDMA_CONTROL_REGISTER_CIRCULAR_PARK             0x00000002  
#define VDMA_CONTROL_REGISTER_RESET                     0x00000004  
#define VDMA_CONTROL_REGISTER_GENLOCK_ENABLE            0x00000008  
#define VDMA_CONTROL_REGISTER_FrameCntEn                0x00000010  
#define VDMA_CONTROL_REGISTER_INTERNAL_GENLOCK          0x00000080  
#define VDMA_CONTROL_REGISTER_WrPntr                    0x00000f00  
#define VDMA_CONTROL_REGISTER_FrmCtn_IrqEn              0x00001000  
#define VDMA_CONTROL_REGISTER_DlyCnt_IrqEn              0x00002000  
#define VDMA_CONTROL_REGISTER_ERR_IrqEn                 0x00004000  
#define VDMA_CONTROL_REGISTER_Repeat_En                 0x00008000  
#define VDMA_CONTROL_REGISTER_InterruptFrameCount       0x00ff0000  
#define VDMA_CONTROL_REGISTER_IRQDelayCount             0xff000000  
  
/* S2MM status register */  
#define VDMA_STATUS_REGISTER_HALTED                     0x00000001  // Read-only  
#define VDMA_STATUS_REGISTER_VDMAInternalError          0x00000010  // Read or write-clear  
#define VDMA_STATUS_REGISTER_VDMASlaveError             0x00000020  // Read-only  
#define VDMA_STATUS_REGISTER_VDMADecodeError            0x00000040  // Read-only  
#define VDMA_STATUS_REGISTER_StartOfFrameEarlyError     0x00000080  // Read-only  
#define VDMA_STATUS_REGISTER_EndOfLineEarlyError        0x00000100  // Read-only  
#define VDMA_STATUS_REGISTER_StartOfFrameLateError      0x00000800  // Read-only  
#define VDMA_STATUS_REGISTER_FrameCountInterrupt        0x00001000  // Read-only  
#define VDMA_STATUS_REGISTER_DelayCountInterrupt        0x00002000  // Read-only  
#define VDMA_STATUS_REGISTER_ErrorInterrupt             0x00004000  // Read-only  
#define VDMA_STATUS_REGISTER_EndOfLineLateError         0x00008000  // Read-only  
#define VDMA_STATUS_REGISTER_FrameCount                 0x00ff0000  // Read-only  
#define VDMA_STATUS_REGISTER_DelayCount                 0xff000000  // Read-only  
  
typedef struct {  
    unsigned int baseAddr;  
    int vdmaHandler;  
    int width;  
    int height;  
    int pixelLength;  
    int fbLength;  
    unsigned int* vdmaVirtualAddress;
    unsigned int* fb1VirtualAddress;
    unsigned int* fb1PhysicalAddress;
    unsigned int* fb2VirtualAddress;
    unsigned int* fb2PhysicalAddress;
    unsigned int* fb3VirtualAddress;
    unsigned int* fb3PhysicalAddress;
  
    pthread_mutex_t lock;  
} vdma_handle;  
  
  
  
int vdma_setup(vdma_handle *handle, unsigned int baseAddr, int width, int height, int pixelLength, unsigned char fb1Addr, unsigned char fb2Addr, unsigned int fb3Addr) {
    handle->baseAddr=baseAddr;  
    handle->width=width;  
    handle->height=height;  
    handle->pixelLength=pixelLength;  
    handle->fbLength=pixelLength*width*height;  
    handle->vdmaHandler = open("/dev/mem", O_RDWR | O_SYNC);  
    handle->vdmaVirtualAddress = (unsigned int*)mmap(NULL, 65535, PROT_READ | PROT_WRITE, MAP_SHARED, handle->vdmaHandler, (off_t)handle->baseAddr);  
    if(handle->vdmaVirtualAddress == MAP_FAILED) {  
        perror("vdmaVirtualAddress mapping for absolute memory access failed.\n");  
        return -1;  
    }  
  
    handle->fb1PhysicalAddress = fb1Addr;  
    handle->fb1VirtualAddress = (unsigned int*)mmap(NULL, handle->fbLength, PROT_READ | PROT_WRITE, MAP_SHARED, handle->vdmaHandler, (off_t)fb1Addr);  
    if(handle->fb1VirtualAddress == MAP_FAILED) {  
        perror("fb1VirtualAddress mapping for absolute memory access failed.\n");  
        return -2;  
    }  
  
    handle->fb2PhysicalAddress = fb2Addr;  
    handle->fb2VirtualAddress = (unsigned int*)mmap(NULL, handle->fbLength, PROT_READ | PROT_WRITE, MAP_SHARED, handle->vdmaHandler, (off_t)fb2Addr);  
    if(handle->fb2VirtualAddress == MAP_FAILED) {  
        perror("fb2VirtualAddress mapping for absolute memory access failed.\n");  
        return -3;  
    }  
  
    handle->fb3PhysicalAddress = fb3Addr;  
    handle->fb3VirtualAddress = (unsigned int*)mmap(NULL, handle->fbLength, PROT_READ | PROT_WRITE, MAP_SHARED, handle->vdmaHandler, (off_t)fb3Addr);  
    if(handle->fb3VirtualAddress == MAP_FAILED)  
    {  
     perror("fb3VirtualAddress mapping for absolute memory access failed.\n");  
     return -3;  
    }  
  
    memset(handle->fb1VirtualAddress, 255, handle->width*handle->height*handle->pixelLength);  
    memset(handle->fb2VirtualAddress, 255, handle->width*handle->height*handle->pixelLength);  
    memset(handle->fb3VirtualAddress, 255, handle->width*handle->height*handle->pixelLength);  
    return 0;  
}  
  
unsigned int vdma_get(vdma_handle *handle, int num) {  
    return handle->vdmaVirtualAddress[num>>2];  
}  


void vdma_set(vdma_handle *handle, int num, unsigned int val) {  
    handle->vdmaVirtualAddress[num>>2]=val;  
}  
  
void vdma_halt(vdma_handle *handle) {  
    vdma_set(handle, OFFSET_VDMA_S2MM_CONTROL_REGISTER, VDMA_CONTROL_REGISTER_RESET);  
    vdma_set(handle, OFFSET_VDMA_MM2S_CONTROL_REGISTER, VDMA_CONTROL_REGISTER_RESET);  
    munmap((void *)handle->vdmaVirtualAddress, 65535);  
    munmap((void *)handle->fb1VirtualAddress, handle->fbLength);  
    munmap((void *)handle->fb2VirtualAddress, handle->fbLength);  
    munmap((void *)handle->fb3VirtualAddress, handle->fbLength);  
    close(handle->vdmaHandler);  
}  
  


  
void vdma_status_dump(int status) {  
    if (status & VDMA_STATUS_REGISTER_HALTED) printf(" halted"); else printf("running");  
    if (status & VDMA_STATUS_REGISTER_VDMAInternalError) printf(" vdma-internal-error");  
    if (status & VDMA_STATUS_REGISTER_VDMASlaveError) printf(" vdma-slave-error");  
    if (status & VDMA_STATUS_REGISTER_VDMADecodeError) printf(" vdma-decode-error");  
    if (status & VDMA_STATUS_REGISTER_StartOfFrameEarlyError) printf(" start-of-frame-early-error");  
    if (status & VDMA_STATUS_REGISTER_EndOfLineEarlyError) printf(" end-of-line-early-error");  
    if (status & VDMA_STATUS_REGISTER_StartOfFrameLateError) printf(" start-of-frame-late-error");  
    if (status & VDMA_STATUS_REGISTER_FrameCountInterrupt) printf(" frame-count-interrupt");  
    if (status & VDMA_STATUS_REGISTER_DelayCountInterrupt) printf(" delay-count-interrupt");  
    if (status & VDMA_STATUS_REGISTER_ErrorInterrupt) printf(" error-interrupt");  
    if (status & VDMA_STATUS_REGISTER_EndOfLineLateError) printf(" end-of-line-late-error");  
    printf(" frame-count:%d", (status & VDMA_STATUS_REGISTER_FrameCount) >> 16);  
    printf(" delay-count:%d", (status & VDMA_STATUS_REGISTER_DelayCount) >> 24);  
    printf("\n");  
}  
  
void vdma_s2mm_status_dump(vdma_handle *handle) {  
    int status = vdma_get(handle, OFFSET_VDMA_S2MM_STATUS_REGISTER);  
    printf("S2MM status register (%08x):", status);  
    vdma_status_dump(status);  
}  
  
void vdma_mm2s_status_dump(vdma_handle *handle) {  
    int status = vdma_get(handle, OFFSET_VDMA_MM2S_STATUS_REGISTER);  
    printf("MM2S status register (%08x):", status);  
    vdma_status_dump(status);  
}  
  
void vdma_start_triple_buffering(vdma_handle *handle) {  
    // Reset VDMA  
    vdma_set(handle, OFFSET_VDMA_S2MM_CONTROL_REGISTER, VDMA_CONTROL_REGISTER_RESET);  
    vdma_set(handle, OFFSET_VDMA_MM2S_CONTROL_REGISTER, VDMA_CONTROL_REGISTER_RESET);  
  
    // Wait for reset to finish  
    while((vdma_get(handle, OFFSET_VDMA_S2MM_CONTROL_REGISTER) & VDMA_CONTROL_REGISTER_RESET)==4);  
    while((vdma_get(handle, OFFSET_VDMA_MM2S_CONTROL_REGISTER) & VDMA_CONTROL_REGISTER_RESET)==4);  
  
    // Clear all error bits in status register  
    vdma_set(handle, OFFSET_VDMA_S2MM_STATUS_REGISTER, 0);  
    vdma_set(handle, OFFSET_VDMA_MM2S_STATUS_REGISTER, 0);  
  
    // Do not mask interrupts  
    vdma_set(handle, OFFSET_VDMA_S2MM_IRQ_MASK, 0xf);  
  
    int interrupt_frame_count = 3;  
  
    // Start both S2MM and MM2S in triple buffering mode  
    vdma_set(handle, OFFSET_VDMA_S2MM_CONTROL_REGISTER,  
        (interrupt_frame_count << 16) |  
        VDMA_CONTROL_REGISTER_START |  
        VDMA_CONTROL_REGISTER_GENLOCK_ENABLE |  
        VDMA_CONTROL_REGISTER_INTERNAL_GENLOCK |  
        VDMA_CONTROL_REGISTER_CIRCULAR_PARK);  
    vdma_set(handle, OFFSET_VDMA_MM2S_CONTROL_REGISTER,  
        (interrupt_frame_count << 16) |  
        VDMA_CONTROL_REGISTER_START |  
        VDMA_CONTROL_REGISTER_GENLOCK_ENABLE |  
        VDMA_CONTROL_REGISTER_INTERNAL_GENLOCK |  
        VDMA_CONTROL_REGISTER_CIRCULAR_PARK);  
  
  
    while((vdma_get(handle, 0x30)&1)==0 || (vdma_get(handle, 0x34)&1)==1) {  
        printf("Waiting for VDMA to start running...\n");  
        sleep(1);  
    }  
  
    // Extra register index, use first 16 frame pointer registers  
    vdma_set(handle, OFFSET_VDMA_S2MM_REG_INDEX, 0);  
  
    // Write physical addresses to control register  
    vdma_set(handle, OFFSET_VDMA_S2MM_FRAMEBUFFER1, handle->fb1PhysicalAddress);  
    vdma_set(handle, OFFSET_VDMA_S2MM_FRAMEBUFFER2, handle->fb1PhysicalAddress);  
    vdma_set(handle, OFFSET_VDMA_S2MM_FRAMEBUFFER3, handle->fb1PhysicalAddress);  
      
    vdma_set(handle, OFFSET_VDMA_MM2S_FRAMEBUFFER1, handle->fb2PhysicalAddress);  
    vdma_set(handle, OFFSET_VDMA_MM2S_FRAMEBUFFER2, handle->fb2PhysicalAddress);  
    vdma_set(handle, OFFSET_VDMA_MM2S_FRAMEBUFFER3, handle->fb2PhysicalAddress);  
  
    // Write Park pointer register  
    vdma_set(handle, OFFSET_PARK_PTR_REG, 0);  
  
    // Frame delay and stride (bytes)  
    vdma_set(handle, OFFSET_VDMA_S2MM_FRMDLY_STRIDE, handle->width*handle->pixelLength);  
    vdma_set(handle, OFFSET_VDMA_MM2S_FRMDLY_STRIDE, handle->width*handle->pixelLength);  
  
    // Write horizontal size (bytes)  
    vdma_set(handle, OFFSET_VDMA_S2MM_HSIZE, handle->width*handle->pixelLength);  
    vdma_set(handle, OFFSET_VDMA_MM2S_HSIZE, handle->width*handle->pixelLength);  
  
    // Write vertical size (lines), this actually starts the transfer  
    vdma_set(handle, OFFSET_VDMA_S2MM_VSIZE, handle->height);  
    vdma_set(handle, OFFSET_VDMA_MM2S_VSIZE, handle->height);  
}  
  
int vdma_running(vdma_handle *handle) {  
    // Check whether VDMA is running, that is ready to start transfers  
    return (vdma_get(handle, 0x34)&1)==1;  
}  
  
int vdma_idle(vdma_handle *handle) {  
    // Check whtether VDMA is transferring  
    return (vdma_get(handle, OFFSET_VDMA_S2MM_STATUS_REGISTER) & VDMA_STATUS_REGISTER_FrameCountInterrupt)!=0;  
}  
  
int main() {  
    int j, i;  
    vdma_handle handle;  
      
    // Setup VDMA handle and memory-mapped ranges  
    vdma_setup(&handle, 0x43000000, 640, 480, 4, 0x1f400000, 0x1f500000, 0x1f600000);  
      
    // Start triple buffering  
    vdma_start_triple_buffering(&handle);  
  
    // Run for 10 seconds, just monitor status registers  
    for(i=0; i<10; i++) {  
        vdma_s2mm_status_dump(&handle);  
        vdma_mm2s_status_dump(&handle);  
          
        memset(handle.fb2VirtualAddress, 0xCC+i, 640*480*4);  
          
        printf("FB1:\n");  
        for (j = 0; j < 256; j++)   
            printf(" %02x", handle.fb1VirtualAddress[j]); printf("\n");  
        sleep(1);  
    }  
  
    // Halt VDMA and unmap memory ranges  
    vdma_halt(&handle);  
}  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值