From 6148190afa00ef47ccfbf7d04ac5b28ec529ce87 Mon Sep 17 00:00:00 2001 From: F5OEO Date: Fri, 23 Nov 2018 12:01:47 +0000 Subject: [PATCH] GPCLK2 is used for Wifi, stop using it. Should fix the Wifi hangout --- src/dma.cpp | 4 +--- src/gpio.cpp | 22 +++++++++++----------- src/mailbox.c | 16 ++++++++-------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/dma.cpp b/src/dma.cpp index f793203..452d269 100644 --- a/src/dma.cpp +++ b/src/dma.cpp @@ -96,9 +96,7 @@ void dma::GetRpiInfo() dma::~dma() { stop(); - /* - unmapmem(mbox.virt_addr, NumPages * PAGE_SIZE); - */ + mem_unlock(mbox.handle, mbox.mem_ref); mem_free(mbox.handle, mbox.mem_ref); diff --git a/src/gpio.cpp b/src/gpio.cpp index ceee873..bdc3745 100644 --- a/src/gpio.cpp +++ b/src/gpio.cpp @@ -90,8 +90,8 @@ int clkgpio::SetPllNumber(int PllNo, int MashType) Mash = 0; gpioreg[GPCLK_CNTL] = 0x5A000000 | (Mash << 9) | pllnumber /*|(1 << 5)*/; //5 is Reset CLK usleep(100); - gpioreg[GPCLK_CNTL_2] = 0x5A000000 | (Mash << 9) | pllnumber /*|(1 << 5)*/; //5 is Reset CLK - usleep(100); + //gpioreg[GPCLK_CNTL_2] = 0x5A000000 | (Mash << 9) | pllnumber /*|(1 << 5)*/; //5 is Reset CLK + //usleep(100); Pllfrequency = GetPllFrequency(pllnumber); return 0; } @@ -128,8 +128,8 @@ int clkgpio::SetClkDivFrac(uint32_t Div, uint32_t Frac) gpioreg[GPCLK_DIV] = 0x5A000000 | ((Div) << 12) | Frac; usleep(100); - gpioreg[GPCLK_DIV_2] = 0x5A000000 | ((Div) << 12) | Frac; - usleep(100); + //gpioreg[GPCLK_DIV_2] = 0x5A000000 | ((Div) << 12) | Frac; + //usleep(100); fprintf(stderr, "Clk Number %d div %d frac %d\n", pllnumber, Div, Frac); //gpioreg[GPCLK_CNTL]= 0x5A000000 | (Mash << 9) | pllnumber |(1<<4) ; //4 is START CLK // usleep(10); @@ -314,18 +314,18 @@ int clkgpio::SetCenterFrequency(uint64_t Frequency, int Bandwidth) usleep(100); gpioreg[GPCLK_CNTL] = 0x5A000000 | (Mash << 9) | pllnumber | (1 << 4); //4 is START CLK usleep(100); - gpioreg[GPCLK_CNTL_2] = 0x5A000000 | (Mash << 9) | pllnumber | (1 << 4); //4 is START CLK - usleep(100); + //gpioreg[GPCLK_CNTL_2] = 0x5A000000 | (Mash << 9) | pllnumber | (1 << 4); //4 is START CLK + //usleep(100); gpioreg[GPCLK_CNTL] = 0x5A000000 | (Mash << 9) | pllnumber | (1 << 4); //4 is START CLK usleep(100); - gpioreg[GPCLK_CNTL_2] = 0x5A000000 | (Mash << 9) | pllnumber | (1 << 4); //4 is START CLK - usleep(100); + //gpioreg[GPCLK_CNTL_2] = 0x5A000000 | (Mash << 9) | pllnumber | (1 << 4); //4 is START CLK + //usleep(100); } else { GetPllFrequency(pllnumber); // Be sure to get the master PLL frequency gpioreg[GPCLK_CNTL] = 0x5A000000 | (Mash << 9) | pllnumber | (1 << 4); //4 is START CLK - gpioreg[GPCLK_CNTL_2] = 0x5A000000 | (Mash << 9) | pllnumber | (1 << 4); //4 is START CLK + //gpioreg[GPCLK_CNTL_2] = 0x5A000000 | (Mash << 9) | pllnumber | (1 << 4); //4 is START CLK } return 0; } @@ -334,9 +334,9 @@ void clkgpio::SetPhase(bool inversed) { uint32_t StateBefore = clkgpio::gpioreg[GPCLK_CNTL]; clkgpio::gpioreg[GPCLK_CNTL] = (0x5A << 24) | StateBefore | ((inversed ? 1 : 0) << 8) | 1 << 5; - clkgpio::gpioreg[GPCLK_CNTL_2] = (0x5A << 24) | StateBefore | ((inversed ? 1 : 0) << 8) | 1 << 5; + //clkgpio::gpioreg[GPCLK_CNTL_2] = (0x5A << 24) | StateBefore | ((inversed ? 1 : 0) << 8) | 1 << 5; clkgpio::gpioreg[GPCLK_CNTL] = (0x5A << 24) | StateBefore | ((inversed ? 1 : 0) << 8) | 0 << 5; - clkgpio::gpioreg[GPCLK_CNTL_2] = (0x5A << 24) | StateBefore | ((inversed ? 1 : 0) << 8) | 0 << 5; + //clkgpio::gpioreg[GPCLK_CNTL_2] = (0x5A << 24) | StateBefore | ((inversed ? 1 : 0) << 8) | 0 << 5; } //Should inspect https://github.com/raspberrypi/linux/blob/ffd7bf4085b09447e5db96edd74e524f118ca3fe/drivers/clk/bcm/clk-bcm2835.c#L695 void clkgpio::SetAdvancedPllMode(bool Advanced) diff --git a/src/mailbox.c b/src/mailbox.c index 7ea4534..e02afbf 100644 --- a/src/mailbox.c +++ b/src/mailbox.c @@ -49,7 +49,7 @@ void *mapmem(unsigned base, unsigned size) base = base - offset; /* open /dev/mem */ if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) { - printf("can't open /dev/mem\nThis program should be run as root. Try prefixing command with: sudo\n"); + fprintf(stderr,"can't open /dev/mem\nThis program should be run as root. Try prefixing command with: sudo\n"); exit (-1); } void *mem = mmap( @@ -60,10 +60,10 @@ void *mapmem(unsigned base, unsigned size) mem_fd, base); #ifdef DEBUG - printf("base=0x%x, mem=%p\n", base, mem); + fprintf(stderr,"base=0x%x, mem=%p\n", base, mem); #endif if (mem == MAP_FAILED) { - printf("mmap error %p\n", mem); + fprintf(stderr,"mmap error %p\n", mem); exit (-1); } close(mem_fd); @@ -90,13 +90,13 @@ static int mbox_property(int file_desc, void *buf) int ret_val = ioctl(file_desc, IOCTL_MBOX_PROPERTY, buf); if (ret_val < 0) { - printf("ioctl_set_msg failed:%d\n", ret_val); + fprintf(stderr,"ioctl_set_msg failed:%d\n", ret_val); } #ifdef DEBUG unsigned *p = buf; int i; unsigned size = *(unsigned *)buf; for (i=0; i= 0) { - printf("Using mbox device " VCIO_DEVICE_FILE_NAME ".\n"); + fprintf(stderr,"Using mbox device " VCIO_DEVICE_FILE_NAME ".\n"); return file_desc; } @@ -282,14 +282,14 @@ int mbox_open() { unlink(LOCAL_DEVICE_FILE_NAME); if(mknod(LOCAL_DEVICE_FILE_NAME, S_IFCHR|0600, makedev(MAJOR_NUM_A, 0)) >= 0 && (file_desc = open(LOCAL_DEVICE_FILE_NAME, 0)) >= 0) { - printf("Using local mbox device file with major %d.\n", MAJOR_NUM_A); + fprintf(stderr,"Using local mbox device file with major %d.\n", MAJOR_NUM_A); return file_desc; } unlink(LOCAL_DEVICE_FILE_NAME); if(mknod(LOCAL_DEVICE_FILE_NAME, S_IFCHR|0600, makedev(MAJOR_NUM_B, 0)) >= 0 && (file_desc = open(LOCAL_DEVICE_FILE_NAME, 0)) >= 0) { - printf("Using local mbox device file with major %d.\n", MAJOR_NUM_B); + fprintf(stderr,"Using local mbox device file with major %d.\n", MAJOR_NUM_B); return file_desc; }