Пример #1
0
//Initializes the timer.
void soc_timer_init(){
	uint32_t register_a;
	timer = (timer_registers *)IO_VA_ADDRESS(TIMER_BASE);
    //Disable timer clock and interrupts.
    register_a = timer->tc;
	register_a &= ~((1<<5)|(1<<7)); //Could write decimal 5 shifted 5 instead
    timer->tc = register_a;

}
Пример #2
0
//Enables writing to the GPIO pins we want to use.
void soc_gpio_init(){
	unsigned int register_a;
	gppud = (gppud_registers *)IO_VA_ADDRESS(GPPUD_BASE);

	//Control signal: Disable pull-up/pull-down on GPIO pin 
	//determined by GPPUDCLK.
	gppud->gppud = 0;

	//Delay for at least 150 CPU cycles (set-up time of control 
	//signal).
	for(register_a = 0; register_a < 150; register_a++){
		delay();
	}

	//Writing a "1" to a bit in GPPUDCLK0 or GPPUDCLK1 allows us to 
	//select that bit (bits in GPPUDCLK1 are transposed by 32) for 
	//control.
	//JTAG:		4 (Alt5: ARM_TDI), 22 (Alt4: ARM_TRST), 24 (Alt4: ARM_TDO),
	//			25 (Alt4: ARM_TCK), 27 (Alt4: ARM_TMS)
	//UART:		14 (Alt1: TXD0), 15 (Alt1: RXD0)
	////TODO: (currently removed) LED:		47 (Alt1: OK LED)	
	gppud->gppudclk0 = (1<<4)|(1<<14)|(1<<15)|(1<<22)|(1<<24)|(1<<25)|(1<<27);

	////gppud->gppudclk1 = (1<<15);
	//Delay for at least 150 CPU cycles (holding time of control signal).
	for(register_a = 0; register_a < 150; register_a++){
		delay();
	}

	//Remove the clock and control signal
	gppud->gppud = 0;
	gppud->gppudclk0 = 0;
	////gppud->gppudclk1 = 0;

	//////////////////////////////////////////////////////////////////////
	//Now, initialize certain pins on the RPi2 to function as JTAG pins.
	//This is only needed for SoCs which do not have JTAG pins by default.
	//////////////////////////////////////////////////////////////////////

	fsel = (function_select_registers *)IO_VA_ADDRESS(GPFSEL_BASE);

	//Set GPIO4 to alternative function 5 by writing to GPFSEL0.
	register_a = fsel->gpfsel0; //Now holds the 32 bits of register GPFSEL0.
	register_a &= ~(7<<12); //Clear settings for GPIO4.
	register_a |= 2<<12; //Set GPIO4 to alternative function 5 (ARM_TDI).
	fsel->gpfsel0 = register_a;

	//Set other GPIOs to alternative functions by writing at GPFSEL2.
	register_a = fsel->gpfsel2; //Now holds the 32 bits of register GPFSEL2.
	register_a &= ~(7<<6); //Clear settings for GPIO22.
	register_a |= 3<<6; //Set GPIO22 to alternative function 4 (ARM_TRST).
	register_a &= ~(7<<12); //Clear settings for GPIO24.
	register_a |= 3<<12; //Set GPIO24 to alternative function 4 (ARM_TDO).
	register_a &= ~(7<<15); //Clear settings for GPIO25.
	register_a |= 3<<15; //Set GPIO25 to alternative function 4 (ARM_TCK).
	register_a &= ~(7<<21); //Clear settings for GPIO27.
	register_a |= 3<<21; //Set GPIO27 to alternative function 4 (ARM_TMS).
	fsel->gpfsel2 = register_a;

	//Now, physical pins number 7 (GPIO 4), 13 (GPIO 27), 15 (GPIO 22),
	//18 (GPIO 24) and 22 (GPIO 25) should work as JTAG pins with their
	//respective signals.
}