Use mmap_device_memory to map the hardware address in the program and assign program variable values to the hardware address through memcpy

#define MAP_FAILED ((void *)-1) -----The system comes with

#define REG_ADDR 0x80003000 --- artificially defined

1. Map the hardware address to the program

    void* ptr = mmap_device_memory( 0, 0x1000, PROT_READ|PROT_WRITE|PROT_NOCACHE, 0, REG_ADDR );
    if(ptr == MAP_FAILED)
    {
       printf("failed");
        return -1;
    }
   Trig_value*  ptr_value = (Trig_value*)ptr;

 After mapping, we can use ptr_value to get the data;

2. Assign the value in the program to the hardware

Trig_value m_value= .....;//m_value初始化

memcpy(ptr_value,&m_value,sizeof(Trig_value));

The meaning of the above statement is: assign the value of m_value to the memory unit pointed to by ptr_value;

The ptr_value refers to the mapped hardware address.

3. Summary

1) Through the use of mmap_device_memory, multiple programs of the hardware can share the data on the memory;

2) Pay attention to the use of pointers and memcpy. Memcpy copies data to the memory space pointed to by the pointer. Although the pointers are not the same pointer, the memory space is the same space.

In the same way, we can also use the fread function to read data from the file and assign it directly to this memory space.

int len_cfgfile = sizeof(Trig_value);

fread((void*)ptr_value,sizeof(char),len_cfgfile,fp))

 

 

 

 

 

Guess you like

Origin blog.csdn.net/modi000/article/details/113928592