/**************************************************************************** Module HardwareInitialize.c Revision 1.0.1 Description This is a hardware initialization file for the ME218B project for Team 3. Notes Private Definitions PWMTicksPerMS BitsPerNibble PWM0_GenA_Normal PWM0_GenB_Normal PWM1_GenA_Normal PWM1_GenB_Normal PWM2_GenA_Normal void InitializeHardware(void) ----------------------------------------------- // first enable the clocks to ports A, B, C, D, E, and F // wait for each of the peripherals to be ready // --> port A // --> port B // --> port C // --> port D // --> port E // --> port F // do all of the SPI initialization // do all of the PWM initialization // do all of the input capture initialization // do all of the GPIO initialization // globally enable interrupts static void InitializeSPI(void) --------------------------------------------- // enable clock to SSI module 0 // program GPIO for alternate functions // write in GPIOCTL to select desired functions // program PA2, PA3, PA4, & PA5 for digital I/O // set PA2, PA3, & PA5 to be outputs // set PA4 to be an input // turn on the pull-up resistor for the clock line for SPI mode 3 // wait for SSI0 to be ready // disable SSI0 0 // select Master mode, and TXRIS for End of Transmission // configure SSI clock source to be the system clock // configure clock prescaler (Bit Rate 15 kHz) Set CPSR to 132 // Set SCR to 19 // configure SPH = 1 because data is captured at the second edge // configure SPO = 1 because idle state is high // freescale SPI Mode // set up sending 8 bit data between command generator & TIVA // locally enable interrupts (TXIM in SSIIM) // enable SSI (DISABLING FOR ACTIVATING ON THE COMPASS MODULE ITSELF) // enable NVIC bit 7 in EN0 static void InitializePWM(void) --------------------------------------------- // start by enabling the clock to both PWM Modules (PWM0 & PWM1) // Select the PWM clock as System Clock/32 (this sets both modules) // make sure that the PWM module clock has gotten going // --> module 0 // --> module 1 // disable the PWMs while initializing // --> module 0 // --> module 1 // program generators to go to 1 at rising compare A/B, 0 on falling // compare A/B // ALL PERIOD-SETTING AND ENABLING STEPS SHOULD HAPPEN IN INDIVIDUAL // MODULES, NOT HERE. // now configure the pins to be PWM outputs // start by selecting the alternate functions for all pins // now choose to map PWM to those pins, using the specified mux values // --> PA6 and PA7 with mux value 5 // --> PB4, PB5, PB6, and PA7 with mux value 4 // --> PD0 with mux value 5 // enable all pins for digital I/O as digital outputs // set the up/down count mode, enable the PWM generator and make // both generator updates locally synchronized to zero count // --> PWM module 0, PWM0 + PWM1 (generator 0, A + B) // --> PWM module 0, PWM2 + PWM3 (generator 1, A + B) // --> PWM module 1, PWM0 (generator 0, A) // --> PWM module 1, PWM2 + PWM3 (generator 1, A + B) static void InitializeInputCapture(void) ------------------------------------ // enable the clock to the timers (Wide Timers 0 + 2) // wait for the peripherals to be ready // --> Wide Timer 0 // --> Wide Timer 2 // disable timers before configuring // --> wide timer 0, timers A + B // --> wide timer 2, timer B // set up timer in 32-bit wide individual (not concatenated) mode // (don't get confused by the name of this constant -- 16 means individual) // initialize the Interval Load Register to 0xffff.ffff // set up timers in capture mode (TAMR/TBMR=3, TAAMS/TBAMS=0), for edge // time (TACMR/TBCMR=1), and for up-counting (TACDIR/TBCDIR=1) // --> wide timer 0, timer A // --> wide timer 0, timer B // --> wide timer 2, timer B // set the event to rises only // --> wide timer 0, timers A + B // --> wide timer 2, timer B // select the alternate functions for all pins // now choose to map input capture to those pins, using the specified mux // values // --> PC4 and PC5 with mux value 7 // --> PD1 with mux value 7 // enable all pins for digital I/O as digital inputs // enable local capture interrupts for the timers // --> wide timer 0, timers A + B // --> wide timer 2, timer B // no NVIC initialization to occur in this function -- will be done in // individual modules. // enable the input capture timer // enable it to stall while stopped by the debugger // --> wide timer 0 timer A // --> wide timer 0 timer B // --> wide timer 2 timer B static void InitializeGPIO(void) -------------------------------------------- // initialize PB0 & PB1 to be digital outputs // initialize PE0, PE1, PE2, PE3, & PE5 to be digital inputs // initialize PF4 to be a digital input // initialize PF0 & PF1 to be digital outputs /***************************************************************************/