cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Observer
Observer
315 Views
Registered: ‎07-17-2019

Zynq 7000 cannot unlock slcr's with linux

So I have a zynq 7010 with linux and I am trying to write to the slcr's. I followed this this guide to do so get the virtual address of the registers. Below is the code to get the address: (ignore the silly comments)

void* compute_base_addr(unsigned adc_bse) {
    int fd;
    unsigned gpio_addr = 0;
    unsigned page_addr;
    void *BaseAddr0;
    unsigned page_size=sysconf(_SC_PAGESIZE); //figure out why they need this?

    //printf("GPIO access through /dev/mem. (page_size: %i)\n", page_size);

    gpio_addr = adc_bse; //memory map for the adc 
    if (gpio_addr == 0) {
        printf("GPIO physical address is required.\n");
        exit(1);
    }

    /* Open /dev/mem file */
    fd = open ("/dev/mem", O_RDWR | O_SYNC);
    if (fd < 1) {
        printf("Error, unable to open /dev/mem with O_RDWR");
        exit(1);
    }

    /* mmap the device into memory */
    page_addr = (gpio_addr & (~(page_size-1))); //wut
    BaseAddr0 = mmap(NULL, page_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, page_addr);

    return BaseAddr0;

All I am trying to do now is verify that I can lock and unlock the slcr's through the slcr lock, unlock, and lockstat registers. Here is my code to verify

int main() {
	int* lock_status = compute_base_addr(0xF800000C);
	printf("%02x\n",lock_status);
	int* lock_key = compute_base_addr(0xF8000004);
	*lock_key = 0x0000767b; 
	int* unlock_key = compute_base_addr(0xF8000008);
	printf("%02x\n",*lock_status);
	*unlock_key = 0x0000df0d;

As you can see, I check the status, lock it, check the status again, unlock it and check again. I should see

00
01
00

as the outputs. Instead what I get is

00
01
01

on the first run of the program and

01
01
01

on all following runs. So it locks, but it does not unlock. Furthermore, it seems for some reason that if I just do an unlock and never do the lock, it still locks! I've been banging my head over this for some time now. Why does my unlock not work? What's more, why does my unlock also lock it?

Thanks ahead of time!

 

0 Kudos
0 Replies