int main(int argc, char **argv) { int i; setvbuf(stdout, NULL, _IOLBF, 0); setup_sighandlers(); // check wiringPi setup if (wiringPiSetup() == -1) { printf("wiringPi-Error\n"); exit(1); } // init and clear lcd pinMode(_bk, OUTPUT); digitalWrite(_bk, HIGH); unlink(DEVFILE); if (mkfifo(DEVFILE, 0666) < 0) fatal("dispd: Failed to create %s: %m\n", DEVFILE); if (chmod(DEVFILE, 0666) < 0) fatal("didpd: Failed to set permissions on %s: %m\n", DEVFILE); //if (daemon(0,1) < 0) // fatal("dispd: Failed to daemonize process: %m\n"); LCDInit(_sclk, _din, _dc, _cs, _rst, contrast); LCDclear(); LCDshowLogo(); delay(2000); go_go_go(); return 0; }
int main(int argc, char **argv) { parseargs(argc, argv); mbox.handle = mbox_open(); if (mbox.handle < 0) fatal("Failed to open mailbox\n"); unsigned mbox_board_rev = get_board_revision(mbox.handle); printf("MBox Board Revision: %#x\n", mbox_board_rev); get_model(mbox_board_rev); unsigned mbox_dma_channels = get_dma_channels(mbox.handle); printf("DMA Channels Info: %#x, using DMA Channel: %d\n", mbox_dma_channels, DMA_CHAN_NUM); printf("Using hardware: %5s\n", delay_hw == DELAY_VIA_PWM ? "PWM" : "PCM"); printf("Number of channels: %5d\n", (int)num_channels); printf("PWM frequency: %5d Hz\n", 1000000/CYCLE_TIME_US); printf("PWM steps: %5d\n", NUM_SAMPLES); printf("Maximum period (100 %%): %5dus\n", CYCLE_TIME_US); printf("Minimum period (%1.3f%%): %5dus\n", 100.0*SAMPLE_US / CYCLE_TIME_US, SAMPLE_US); printf("DMA Base: %#010x\n", DMA_BASE); setup_sighandlers(); /* map the registers for all DMA Channels */ dma_virt_base = map_peripheral(DMA_BASE, (DMA_CHAN_SIZE * (DMA_CHAN_MAX + 1))); /* set dma_reg to point to the DMA Channel we are using */ dma_reg = dma_virt_base + DMA_CHAN_NUM * (DMA_CHAN_SIZE / sizeof(dma_reg)); pwm_reg = map_peripheral(PWM_BASE, PWM_LEN); pcm_reg = map_peripheral(PCM_BASE, PCM_LEN); clk_reg = map_peripheral(CLK_BASE, CLK_LEN); gpio_reg = map_peripheral(GPIO_BASE, GPIO_LEN); /* Use the mailbox interface to the VC to ask for physical memory */ mbox.mem_ref = mem_alloc(mbox.handle, NUM_PAGES * PAGE_SIZE, PAGE_SIZE, mem_flag); /* TODO: How do we know that succeeded? */ dprintf("mem_ref %u\n", mbox.mem_ref); mbox.bus_addr = mem_lock(mbox.handle, mbox.mem_ref); dprintf("bus_addr = %#x\n", mbox.bus_addr); mbox.virt_addr = mapmem(BUS_TO_PHYS(mbox.bus_addr), NUM_PAGES * PAGE_SIZE); dprintf("virt_addr %p\n", mbox.virt_addr); if ((unsigned long)mbox.virt_addr & (PAGE_SIZE-1)) fatal("pi-blaster: Virtual address is not page aligned\n"); /* we are done with the mbox */ mbox_close(mbox.handle); mbox.handle = -1; //fatal("TempFatal\n"); init_ctrl_data(); init_hardware(); init_channel_pwm(); // Init pin2gpio array with 0/false values to avoid locking all of them as PWM. init_pin2gpio(); // Only calls update_pwm after ctrl_data calculates the pin mask to unlock all pins on start. init_pwm(); unlink(DEVFILE); if (mkfifo(DEVFILE, 0666) < 0) fatal("pi-blaster: Failed to create %s: %m\n", DEVFILE); if (chmod(DEVFILE, 0666) < 0) fatal("pi-blaster: Failed to set permissions on %s: %m\n", DEVFILE); printf("Initialised, "); if (daemonize) { if (daemon(0,1) < 0) fatal("pi-blaster: Failed to daemonize process: %m\n"); else printf("Daemonized, "); } printf("Reading %s.\n", DEVFILE); go_go_go(); return 0; }