/******************************************************************************
 *  Copyright  2015 National Oilwell Varco
 *  1200 Cypress Creek Rd
 *  Cedar Park, TX 78613 USA
 *
 *  This software is the confidential and proprietary information of
 *  National Oilwell Varco ("Confidential Information"). You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with National Oilwell Varco.
*******************************************************************************

    gpio.c

    Created on: 30 July 2015
      Author: Ray Mack

*******************************************************************************/
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_gpio.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include <ti/sysbios/knl/Task.h>
#include "driverlib/gpio.h"


/*****************************************************************************
  FUNCTION:    init_GPIO

  DESCRIPTION: This function sets .

  INPUTS:      None
               
  OUTPUTS:     Updated hardware configuration

  RETURNS:     Nothing.

  NOTES:       None.

  CONTEXT:     This function only runs in user task context.

*****************************************************************************/

void init_GPIO(void)
{

  // Enable GPIO Port A
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
  
  // Port B has no connections!!!

  // enable Port C 
  // BE EXTREMELY CAREFUL.  This port is shared with JTAG for the debugger.
  // Messing up the pins will turn off the JTAG debugger and make it *really* hard to
  // connect
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); 

  // Port D has the SPI signals clk, mosi, and miso as well as 4 analog input channels
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); 
  
  // Port E has only analog input connections.  This port is enabled in another
  // function
  
  // Port F only has PWM output connections.
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); 
  
  // Port G only has PWM output connections.  It is initialized for PWM operation
  // in another function.
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); 

  // Port M implements 6 analog inputs. It also implements the Data Ready input for the analog system (U4)
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM);

  // set up the PWM drive pins
  GPIOPinTypeGPIOOutput(GPIO_PORTK_BASE, GPIO_PIN_4 | GPIO_PIN_5);
  GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
  GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_0 | GPIO_PIN_1);

  GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_4 | GPIO_PIN_5, 0);
  GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0);
  GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_0 | GPIO_PIN_1, 0);

  //
  // Configure TimerA as a half-width one-shot timer, and TimerB as a
  // half-width edge capture counter.
  //
  TimerConfigure(TIMER0_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_ONE_SHOT |
                 TIMER_CFG_B_CAP_COUNT));
  //
  // Set the count time for the the one-shot timer (TimerA).
  //
  TimerLoadSet(TIMER0_BASE, TIMER_A, 3000);
}

