static void audio_init(void) { gpio_function_select(40, GPIO_ALT_0); gpio_function_select(45, GPIO_ALT_0); pause(2); clock_configure(CLOCK_OSCILLATOR, 2.0); pause(2); pwm_disable(); pwm_set_range(0x400, 0x400); pwm_enable(2); pause(2); }
void main() { gpio_function_select(16, GPIO_OUTPUT); gpio_set(16, 0); // 0 turns led on hit = 0; unsigned interval = 0x00080000; unsigned rx = CLO; rx += interval; CS = 0x2; // Clear status for Match 1 register C1 = rx; *irq_enable_1 = 0x2; // Enable System Timer IRQ (Where is this documented?) enable_irq(); while (1) { if (hit) { led_toggle(); Wait(50000); } } // Enable // audio_play(); }
/*! \fn void spi_pin_init(void) * \brief Initialises the Raspberry Pi's SPI0 Peripheral * * The standard chip selects used with this device (hardware pins 7 & 8) are not used. Instead GPIO pins are used as chip selects. This allows communication with more SPI devices. */ void spi_pin_init(void) { /* Set gpios to spi mode */ gpio_function_select(GPIO_SPI0_MISO, GPIO_FUNC_ALT0); gpio_function_select(GPIO_SPI0_MOSI, GPIO_FUNC_ALT0); gpio_function_select(GPIO_SPI0_SCK, GPIO_FUNC_ALT0); /* chip selects are not setup as all chip selects will operate as gpio chip selects */ //gpio_function_select(GPIO_SPI0_CS0, GPIO_FUNC_ALT0); //gpio_function_select(GPIO_SPI0_CS1, GPIO_FUNC_ALT0); //all the chip selects shape_set_cs(); /* clear control register */ *SPI0_CONTROL = 0; /* Set spi clock to 1 MHz */ *SPI0_CLK = 256; }
/*! \fn void gpio_set_interrupts() * \brief Configures gpio's to receive interrupts from MPU6000 devices\ * \todo This should probably be moved to cubePinMappings, as the way its currently written is cube dependant. It's probably better to write this in a way it can work with NUM_FACES, maybe add all these to an array NUM_FACES long and iterate through it? */ void gpio_set_interrupts() { /* set interrupt pins as input */ gpio_function_select(INT1, GPIO_FUNC_INPUT); gpio_function_select(INT2, GPIO_FUNC_INPUT); gpio_function_select(INT3, GPIO_FUNC_INPUT); gpio_function_select(INT4, GPIO_FUNC_INPUT); gpio_function_select(INT5, GPIO_FUNC_INPUT); gpio_function_select(INT6, GPIO_FUNC_INPUT); /* enable falling edge detection */ irq_gpio_falling_edge_en(INT1); irq_gpio_falling_edge_en(INT2); irq_gpio_falling_edge_en(INT3); irq_gpio_falling_edge_en(INT4); irq_gpio_falling_edge_en(INT5); irq_gpio_falling_edge_en(INT6); }
/*! \fn __attribute__((no_instrument_function)) void not_main(void) * \brief The main, or not so main function. * * not_main is a thing i picked up from some example code online and haven't done anything with it since :S This is the entry point of the c program. */ __attribute__((no_instrument_function)) void not_main(void) { /* board initialisation */ uart_init(); spi_pin_init(); flag = 0; struct mpu60x0_stateType mpu60x0_state[NUM_FACES]; for (int i=0; i<NUM_FACES; i++) { mpu60x0_state[i].gyro_rate = INV_MPU60x0_FSR_250DPS; mpu60x0_state[i].accel_rate = INV_MPU60x0_FS_02G; mpu60x0_state[i].filter_cutoff = INV_MPU60x0_FILTER_256HZ_NOLPF2; } int init_failed = 0; /* initialise all mpu 6000 boards */ for (int i=0; i<NUM_FACES; i++) { if (!mpu60x0_init(shape_cs_mappings[i], &(mpu60x0_state[i]))) { init_failed = 1; printf("MPUDev: %d failed\n", i); } } if (init_failed) return; //Configure SD Status LED for output gpio_function_select(16, GPIO_FUNC_OUTPUT); int mode = select_mode(); printf("mode is: %d\n", mode); /* interrupt pin config */ gpio_set_interrupts(); c_enable_irq(); //assign function to handle gpio_irqs register_irq_handler ( GPIO_INT0, gpio_irq ); register_irq_handler ( GPIO_INT1, gpio_irq ); register_irq_handler ( GPIO_INT2, gpio_irq ); register_irq_handler ( GPIO_INT3, gpio_irq ); //enable irq handling on gpio interrupts enable_interrupt_for_irq(GPIO_INT0); enable_interrupt_for_irq(GPIO_INT1); enable_interrupt_for_irq(GPIO_INT2); enable_interrupt_for_irq(GPIO_INT3); flag = 0; unsigned int prevTs = 0; GPIO_OUTPUT_LEVEL prevLevel = GPIO_OUTPUT_HIGH; switch (mode) { case 0: main_readings(mpu60x0_state); return; case 1: static_calibration(mpu60x0_state); return; case 2: main_debug(mpu60x0_state); return; default: printf("invalid mode\n"); return; } }
uint32_t pl011_uart_init(struct serial_type *serial) { /* Make this configurable? */ serial->baud=115200; serial->bits=8; serial->stop=1; serial->parity=SERIAL_PARITY_NONE; /* Set up function pointers */ serial->uart_enable_interrupts=pl011_uart_enable_interrupts; serial->uart_enable_locking=pl011_uart_enable_locking; serial->uart_putc=pl011_uart_putc; serial->uart_getc=pl011_uart_getc; serial->uart_getc_noblock=pl011_uart_getc_noblock; serial->uart_interrupt_handler=pl011_uart_interrupt_handler; /* Disable UART */ bcm2835_write(UART0_CR, 0x0); /* Setup GPIO pins 14 and 15 */ gpio_request(14,"uart_tx"); gpio_request(15,"uart_rx"); /* Set GPIO14 and GPIO15 to be pl011 TX, so ALT0 */ gpio_function_select(14,GPIO_GPFSEL_ALT0); gpio_function_select(15,GPIO_GPFSEL_ALT0); /* Disable the pull up/down on pins 14 and 15 */ /* See the Peripheral Manual for more info */ /* Configure to disable pull up/down and delay for 150 cycles */ bcm2835_write(GPIO_GPPUD, GPIO_GPPUD_DISABLE); delay(150); /* Pass the disable clock to GPIO pins 14 and 15 and delay*/ bcm2835_write(GPIO_GPPUDCLK0, (1 << 14) | (1 << 15)); delay(150); /* Write 0 to GPPUDCLK0 to make it take effect */ bcm2835_write(GPIO_GPPUDCLK0, 0x0); /* Clear pending interrupts. */ bcm2835_write(UART0_ICR, 0x7FF); /* Set integer & fractional part of baud rate. */ /* Divider = UART_CLOCK/(16 * Baud) */ /* Fraction part register = (Fractional part * 64) + 0.5 */ /* UART_CLOCK = 3000000; Baud = 115200. */ /* Divider = 3000000 / (16 * 115200) = 1.627 */ /* Integer part = 1 */ /* Fractional part register = (.627 * 64) + 0.5 = 40.6 = 40 */ // bcm2835_write(UART0_IBRD, 1); // bcm2835_write(UART0_FBRD, 40); /* On Pi3 (and all other Pis with recent firmware) */ /* UART clock is now 48MHz */ bcm2835_write(UART0_IBRD, 26); bcm2835_write(UART0_FBRD, 3); /* Enable FIFO */ /* Set 8N1 (8 bits of data, no parity, 1 stop bit */ bcm2835_write(UART0_LCRH, UART0_LCRH_FEN | UART0_LCRH_WLEN_8BIT); /* Mask all interrupts. */ /* URGH to mask them "off" write a 0, not a 1 :( */ bcm2835_write(UART0_IMSC, 0); /* Enable UART0, receive, and transmit */ bcm2835_write(UART0_CR, UART0_CR_UARTEN | UART0_CR_TXE | UART0_CR_RXE); // Memory barrier? //{ //uint32_t dest = 0; //__asm__ __volatile__("mcr p15,0,%0,c7,c10,5" :"=&r"(dest) : : "memory"); //} pl011_uart_initialized=1; return 0; }