//***************************************************************************** // // Initializes the SSI port and determines if the TRF79x0 is available. // // This function must be called prior to any other function offered by the // TRF79x0. It configures the SSI port to run in Motorola/Freescale // mode. // // \return None. // //***************************************************************************** void SSITRF79x0Init(void) { // // Enable the peripherals used to drive the TRF79x0 on SSI. // MAP_SysCtlPeripheralEnable(TRF79X0_SSI_PERIPH); // // Enable the GPIO peripherals associated with the SSI. // MAP_SysCtlPeripheralEnable(TRF79X0_CLK_PERIPH); MAP_SysCtlPeripheralEnable(TRF79X0_RX_PERIPH); MAP_SysCtlPeripheralEnable(TRF79X0_TX_PERIPH); MAP_SysCtlPeripheralEnable(TRF79X0_CS_PERIPH); // // Configure the appropriate pins to be SSI instead of GPIO. The CS // is configured as GPIO to support TRF79x0 SPI requirements for R/W // access. // MAP_GPIOPinConfigure(TRF79X0_CLK_CONFIG); MAP_GPIOPinConfigure(TRF79X0_RX_CONFIG); MAP_GPIOPinConfigure(TRF79X0_TX_CONFIG); MAP_GPIOPinTypeSSI(TRF79X0_CLK_BASE, TRF79X0_CLK_PIN); MAP_GPIOPinTypeSSI(TRF79X0_RX_BASE, TRF79X0_RX_PIN); MAP_GPIOPinTypeSSI(TRF79X0_TX_BASE, TRF79X0_TX_PIN); MAP_GPIOPinTypeGPIOOutput(TRF79X0_CS_BASE, TRF79X0_CS_PIN); MAP_GPIOPadConfigSet(TRF79X0_CLK_BASE, TRF79X0_CLK_PIN, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU); MAP_GPIOPadConfigSet(TRF79X0_RX_BASE, TRF79X0_RX_PIN, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU); MAP_GPIOPadConfigSet(TRF79X0_TX_BASE, TRF79X0_TX_PIN, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU); // // Deassert the SSI chip selects TRF79x0. // MAP_GPIOPinWrite(TRF79X0_CS_BASE, TRF79X0_CS_PIN, TRF79X0_CS_PIN); // // Configure the SSI port for 2MHz operation. // MAP_SSIConfigSetExpClk(TRF79X0_SSI_BASE, g_ui32SysClk, SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, SSI_CLK_RATE, 8); if(RF_DAUGHTER_TRF7970) { // // Switch from SPH=0 to SPH=1. Required for TRF7970. // HWREG(TRF79X0_SSI_BASE + SSI_O_CR0) |= SSI_CR0_SPH; } // // Enable the SSI controller. // MAP_SSIEnable(TRF79X0_SSI_BASE); }
//***************************************************************************** // //! Enable the RGB LED with already configured timer settings //! //! This function or RGBDisable should be called during application //! initialization to configure the GPIO pins to which the LEDs are attached. //! This function enables the timers and configures the GPIO pins as timer //! outputs. //! //! \return None. // //***************************************************************************** void RGBEnable(void) { // // Enable timers to begin counting // ROM_TimerEnable(RED_TIMER_BASE, TIMER_BOTH); ROM_TimerEnable(GREEN_TIMER_BASE, TIMER_BOTH); ROM_TimerEnable(BLUE_TIMER_BASE, TIMER_BOTH); // // Reconfigure each LED's GPIO pad for timer control // ROM_GPIOPinConfigure(GREEN_GPIO_PIN_CFG); ROM_GPIOPinTypeTimer(GREEN_GPIO_BASE, GREEN_GPIO_PIN); MAP_GPIOPadConfigSet(GREEN_GPIO_BASE, GREEN_GPIO_PIN, GPIO_STRENGTH_8MA_SC, GPIO_PIN_TYPE_STD); ROM_GPIOPinConfigure(BLUE_GPIO_PIN_CFG); ROM_GPIOPinTypeTimer(BLUE_GPIO_BASE, BLUE_GPIO_PIN); MAP_GPIOPadConfigSet(BLUE_GPIO_BASE, BLUE_GPIO_PIN, GPIO_STRENGTH_8MA_SC, GPIO_PIN_TYPE_STD); ROM_GPIOPinConfigure(RED_GPIO_PIN_CFG); ROM_GPIOPinTypeTimer(RED_GPIO_BASE, RED_GPIO_PIN); MAP_GPIOPadConfigSet(RED_GPIO_BASE, RED_GPIO_PIN, GPIO_STRENGTH_8MA_SC, GPIO_PIN_TYPE_STD); }
pio_type platform_pio_op( unsigned port, pio_type pinmask, int op ) { pio_type retval = 1, base = pio_base[ port ]; switch( op ) { case PLATFORM_IO_PORT_SET_VALUE: MAP_GPIOPinWrite( base, 0xFF, pinmask ); break; case PLATFORM_IO_PIN_SET: MAP_GPIOPinWrite( base, pinmask, pinmask ); break; case PLATFORM_IO_PIN_CLEAR: MAP_GPIOPinWrite( base, pinmask, 0 ); break; case PLATFORM_IO_PORT_DIR_INPUT: pinmask = 0xFF; case PLATFORM_IO_PIN_DIR_INPUT: MAP_GPIOPinTypeGPIOInput( base, pinmask ); break; case PLATFORM_IO_PORT_DIR_OUTPUT: pinmask = 0xFF; case PLATFORM_IO_PIN_DIR_OUTPUT: MAP_GPIOPinTypeGPIOOutput( base, pinmask ); break; case PLATFORM_IO_PORT_GET_VALUE: retval = MAP_GPIOPinRead( base, 0xFF ); break; case PLATFORM_IO_PIN_GET: retval = MAP_GPIOPinRead( base, pinmask ) ? 1 : 0; break; case PLATFORM_IO_PIN_PULLUP: case PLATFORM_IO_PIN_PULLDOWN: MAP_GPIOPadConfigSet( base, pinmask, GPIO_STRENGTH_8MA, op == PLATFORM_IO_PIN_PULLUP ? GPIO_PIN_TYPE_STD_WPU : GPIO_PIN_TYPE_STD_WPD ); break; case PLATFORM_IO_PIN_NOPULL: MAP_GPIOPadConfigSet( base, pinmask, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD ); break; default: retval = 0; break; } return retval; }
/* * @brief Initializes SPI unit. * * Enables peripherals * Configures GPIO * Sets radio, accelerometer, and LED as output * Sets word size as 0 * @returns void */ void SPIInit(void) { volatile unsigned long ulLoop; MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // configure SSI pins for peripheral control MAP_GPIOPinTypeSSI(GPIO_PORTA_BASE, (SPI_MOSI_PIN | SPI_MISO_PIN | SPI_CLK_PIN)); MAP_GPIOPinConfigure(GPIO_PA2_SSI0CLK); MAP_GPIOPinConfigure(GPIO_PA4_SSI0RX); MAP_GPIOPinConfigure(GPIO_PA5_SSI0TX); // Also, it may be better to just get rid of the pullups/downs entirely. -Jeremy MAP_GPIOPadConfigSet(GPIO_PORTA_BASE, (SPI_MOSI_PIN | SPI_MISO_PIN | SPI_CLK_PIN), GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD); #if (defined(RONE_V12) || defined(RONE_V9)) // enable output enable peripheral for SPI MAP_SysCtlPeripheralEnable(SPI_ENABLE_PERIPH); // enable peripheral for three SPI pins MAP_SysCtlPeripheralEnable(SPI_SELECT_PERIPH); // drive select pins to correct values while they are still in input mode SPIDeselectISR(); // enable output enable pin for output MAP_GPIOPinTypeGPIOOutput(SPI_ENABLE_PORT, SPI_ENABLE_PIN); // enable A,B,C SPI pins for output MAP_GPIOPinTypeGPIOOutput(SPI_SELECT_PORT, SPI_SELECT_PINS); #endif // force the port to be enabled by the first call to SPIConfigure() SPIWordSize = 0; }
//***************************************************************************** // //! Initializes the GPIO pins used by the board pushbuttons. //! //! This function must be called during application initialization to //! configure the GPIO pins to which the pushbuttons are attached. It enables //! the port used by the buttons and configures each button GPIO as an input //! with a weak pull-up. //! //! \return None. // //***************************************************************************** void ButtonsInit(void) { // // Enable the GPIO port to which the pushbuttons are connected. // ROM_SysCtlPeripheralEnable(BUTTONS_GPIO_PERIPH); // // Unlock PF0 so we can change it to a GPIO input // Once we have enabled (unlocked) the commit register then re-lock it // to prevent further changes. PF0 is muxed with NMI thus a special case. // HWREG(BUTTONS_GPIO_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY; HWREG(BUTTONS_GPIO_BASE + GPIO_O_CR) |= 0x01; HWREG(BUTTONS_GPIO_BASE + GPIO_O_LOCK) = 0; // // Set each of the button GPIO pins as an input with a pull-up. // ROM_GPIODirModeSet(BUTTONS_GPIO_BASE, ALL_BUTTONS, GPIO_DIR_MODE_IN); MAP_GPIOPadConfigSet(BUTTONS_GPIO_BASE, ALL_BUTTONS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // // Initialize the debounced button state with the current state read from // the GPIO bank. // g_ui8ButtonStates = ROM_GPIOPinRead(BUTTONS_GPIO_BASE, ALL_BUTTONS); }
void PlatformInit() { PortFunctionInit(); //configure SW pins pull-ups MAP_GPIOPadConfigSet(SW_BASE, (SW1|SW2), GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); }
//***************************************************************************** // // PoC2Repeater // //***************************************************************************** int main(void) { // Set the clocking to run directly from the crystal at 120MHz. g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // Enable the peripherals ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART7); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); // Enable the GPIO pins for the LEDs (PN0 and PN1). ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_4); // ButtonsInit ROM_GPIODirModeSet(GPIO_PORTJ_BASE, ALL_BUTTONS, GPIO_DIR_MODE_IN); MAP_GPIOPadConfigSet(GPIO_PORTJ_BASE, ALL_BUTTONS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // Enable processor interrupts. ROM_IntMasterEnable(); // Set GPIO PC4 and PC5 as UART pins. GPIOPinConfigure(GPIO_PC4_U7RX); GPIOPinConfigure(GPIO_PC5_U7TX); ROM_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5); // Configure the UART for 115,200, 8-N-1 operation. ROM_UARTConfigSetExpClk(UART7_BASE, g_ui32SysClock, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // Enable the UART interrupt. ROM_IntEnable(INT_UART7); ROM_UARTIntEnable(UART7_BASE, UART_INT_RX | UART_INT_RT); // Reset message info for(uint8_t i = 0; i < MSG; i++) message[i] = 0; // Loop forever echoing data through the UART. while(1) { } }
//***************************************************************************** // // Main entry point for the USB stick update example. // // This function will check to see if a flash update should be performed from // the USB memory stick, or if the user application should just be run without // any update. // // The following checks are made, any of which mean that an update should be // performed: // - the PC and SP for the user app do not appear to be valid // - a memory location contains a certain value, meaning the user app wants // to force an update // - the user button on the eval board is being pressed, meaning the user wants // to force an update even if there is a valid user app in memory // // If any of the above checks are true, then that means that an update should // be attempted. The USB stick updater will then wait for a USB stick to be // plugged in, and once it is look for a firmware update file. // // If none of the above checks are true, then the user application that is // already in flash is run and no update is performed. // // \return None. // //***************************************************************************** int main(void) { uint32_t *pui32App; // // See if the first location is 0xfffffffff or something that does not // look like a stack pointer, or if the second location is 0xffffffff or // something that does not look like a reset vector. // pui32App = (uint32_t *)APP_START_ADDRESS; if((pui32App[0] == 0xffffffff) || ((pui32App[0] & 0xfff00000) != 0x20000000) || (pui32App[1] == 0xffffffff) || ((pui32App[1] & 0xfff00001) != 0x00000001)) { // // App starting stack pointer or PC is not valid, so force an update. // UpdaterMain(); } // // Check to see if the application has requested an update // if(HWREG(FORCE_UPDATE_ADDR) == FORCE_UPDATE_VALUE) { HWREG(FORCE_UPDATE_ADDR) = 0; UpdaterMain(); } // // Enable the GPIO input for the user button. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM); ROM_GPIODirModeSet(GPIO_PORTM_BASE, GPIO_PIN_4, GPIO_DIR_MODE_IN); MAP_GPIOPadConfigSet(GPIO_PORTM_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // // Check if the button is pressed, if so then force an update. // if(ROM_GPIOPinRead(GPIO_PORTM_BASE, GPIO_PIN_4) == 0) { UpdaterMain(); } // // If we get to here that means that none of the conditions that should // cause an update are true. Therefore, call the application. // CallApplication(APP_START_ADDRESS); }
u32 platform_spi_setup( unsigned id, int mode, u32 clock, unsigned cpol, unsigned cpha, unsigned databits ) { unsigned protocol; if( cpol == 0 ) protocol = cpha ? SSI_FRF_MOTO_MODE_1 : SSI_FRF_MOTO_MODE_0; else protocol = cpha ? SSI_FRF_MOTO_MODE_3 : SSI_FRF_MOTO_MODE_2; mode = mode == PLATFORM_SPI_MASTER ? SSI_MODE_MASTER : SSI_MODE_SLAVE; MAP_SSIDisable( spi_base[ id ] ); MAP_GPIOPinTypeSSI( spi_gpio_base[ id ], spi_gpio_pins[ id ] ); MAP_GPIOPinTypeSSI( spi_gpio_clk_base[ id ], spi_gpio_clk_pin[ id ] ); // FIXME: not sure this is always "right" MAP_GPIOPadConfigSet( spi_gpio_base[ id ], spi_gpio_pins[ id ], GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU ); MAP_GPIOPadConfigSet( spi_gpio_clk_base[ id ], spi_gpio_clk_pin[ id ], GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU ); MAP_SSIConfigSetExpClk( spi_base[ id ], MAP_SysCtlClockGet(), protocol, mode, clock, databits ); MAP_SSIEnable( spi_base[ id ] ); return clock; }
void gpio_init(int pin, enum gpio_mode mode, int value) { uint32_t base = TO_BASE(pin); pin = 1 << (pin & 0x0F); switch (mode) { case GPIO_OUTPUT: MAP_GPIOPinTypeGPIOOutput(base, pin); gpio_set(pin, value); break; case GPIO_OUTPUT_SLOW: MAP_GPIOPinTypeGPIOOutput(base, pin); MAP_GPIOPadConfigSet(base, pin, GPIO_STRENGTH_8MA_SC, GPIO_PIN_TYPE_STD); gpio_set(pin, value); break; case GPIO_INPUT: MAP_GPIOPinTypeGPIOInput(base, pin); break; case GPIO_INPUT_PD: MAP_GPIOPinTypeGPIOInput(base, pin); MAP_GPIOPadConfigSet(base, pin, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD_WPD); break; case GPIO_INPUT_PU: MAP_GPIOPinTypeGPIOInput(base, pin); MAP_GPIOPadConfigSet(base, pin, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD_WPU); break; case GPIO_ANALOG: MAP_GPIOPinTypeGPIOInput(base, pin); MAP_GPIOPadConfigSet(base, pin, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_ANALOG); break; } }
//***************************************************************************** // // CheckBoardRevision uses PD1 with a weak pull down resistor to detect the // development board hardware revision. Code for the LM4F board can run on the // TM4C, but not vice versa. This function checks for the board verion and // warns the user if they are using the wrong board / software. // // The EK-LM4F232 (green) board uses an analog accelorometer. The DK-TM4C123G //(red) board uses a digitial I2C 9 axis accel, mag, gyro. // //***************************************************************************** void CheckBoardRevision(void) { uint32_t ui32BoardType; tContext sDisplayContext; // // Check if board is TM4C123G (red) or LM4F232 (green). This code // should not be run on green board. // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); MAP_GPIODirModeSet(GPIO_PORTD_BASE, GPIO_PIN_1, GPIO_DIR_MODE_IN); MAP_GPIOPadConfigSet(GPIO_PORTD_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD); ui32BoardType=MAP_GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_1); if(ui32BoardType==0) { // // The board is green, print error message and hang. // CFAL96x64x16Init(); GrContextInit(&sDisplayContext, &g_sCFAL96x64x16); GrContextForegroundSet(&sDisplayContext, ClrWhite); GrContextFontSet(&sDisplayContext, g_psFontFixed6x8); GrStringDrawCentered(&sDisplayContext, "ERROR:", -1, GrContextDpyWidthGet(&sDisplayContext) / 2, 4, 0); GrStringDrawCentered(&sDisplayContext, "Due to different", -1, GrContextDpyWidthGet(&sDisplayContext) / 2, 20, false); GrStringDrawCentered(&sDisplayContext, "hardware this", -1, GrContextDpyWidthGet(&sDisplayContext) / 2, 30, false); GrStringDrawCentered(&sDisplayContext, "code cannot run", -1, GrContextDpyWidthGet(&sDisplayContext) / 2, 40, false); GrStringDrawCentered(&sDisplayContext, "on this board", -1, GrContextDpyWidthGet(&sDisplayContext) / 2, 50, false); GrStringDrawCentered(&sDisplayContext, "Try diff code.", -1, GrContextDpyWidthGet(&sDisplayContext) / 2, 60, false); while(1) { // Hang here. } } else { // // The board is red, exit & continue as normal. // return ; } }
STATIC void pin_obj_configure (const pin_obj_t *self) { switch (self->port) { case PORT_A: //MAP_PRCMPeripheralClkEnable(PRCM_GPIOA0, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); break; case PORT_B: //MAP_PRCMPeripheralClkEnable(PRCM_GPIOA1, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); break; case PORT_C: //MAP_PRCMPeripheralClkEnable(PRCM_GPIOA2, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); break; case PORT_D: //MAP_PRCMPeripheralClkEnable(PRCM_GPIOA3, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); break; case PORT_E: //MAP_PRCMPeripheralClkEnable(PRCM_GPIOA3, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); break; case PORT_F: //MAP_PRCMPeripheralClkEnable(PRCM_GPIOA3, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); break; default: break; } // configure the direction for Input or Output mode // if mode = GPIO_DIR_MODE_HW this function set the AFSEL bit MAP_GPIODirModeSet(self->port, self->bit, self->mode); // Configure the ouput pad MAP_GPIOPadConfigSet(self->port, self->bit, self->strength, self->type); // set the pin value if the port is set as output if (self->mode == GPIO_DIR_MODE_OUT) { MAP_GPIOPinWrite(self->port, self->bit, self->value ? self->bit : 0); } }
//***************************************************************************** // //! Initializes the GPIO pins used by the board pushbuttons. //! //! This function must be called during application initialization to //! configure the GPIO pins to which the pushbuttons are attached. It enables //! the port used by the buttons and configures each button GPIO as an input //! with a weak pull-up. //! //! \return None. // //***************************************************************************** void ButtonsInit(void) { // // Enable the GPIO port to which the pushbuttons are connected. // MAP_SysCtlPeripheralEnable(BUTTONS_GPIO_PERIPH); // // Set each of the button GPIO pins as an input with a pull-up. // MAP_GPIODirModeSet(BUTTONS_GPIO_BASE, ALL_BUTTONS, GPIO_DIR_MODE_IN); MAP_GPIOPadConfigSet(BUTTONS_GPIO_BASE, ALL_BUTTONS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // // Initialize the debounced button state with the current state read from // the GPIO bank. // g_ui8ButtonStates = MAP_GPIOPinRead(BUTTONS_GPIO_BASE, ALL_BUTTONS); }
int main() { // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // MAP_FPUEnable(); MAP_FPULazyStackingEnable(); // // Set the clocking to run from the PLL at 50MHZ, change to SYSCTL_SYSDIV_2_5 for 80MHz if neeeded // MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); MAP_IntMasterDisable(); // // Initialize the SW2 button // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // // Unlock PF0 so we can change it to a GPIO input // Once we have enabled (unlocked) the commit register then re-lock it // to prevent further changes. PF0 is muxed with NMI thus a special case. // HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY; HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01; HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0; MAP_GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0); MAP_GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA , GPIO_PIN_TYPE_STD_WPU); // // Initialize the communication layer with a default UART setting // AbstractComm * comm = NULL; AbstractComm * uart_comm = new UARTComm(); purpinsComm communication(uart_comm); // // Initialize the robot object // purpinsRobot purpins; // // Initialize the EEPROM // purpinsSettings settings; // // Initialize the MPU6050-based IMU // mpudata_t mpu; //unsigned long sample_rate = 10 ; //mpu9150_init(0, sample_rate, 0); memset(&mpu, 0, sizeof(mpudata_t)); // // Get the current processor clock frequency. // ulClockMS = MAP_SysCtlClockGet() / (3 * 1000); //unsigned long loop_delay = (1000 / sample_rate) - 2; // // Configure SysTick to occur 1000 times per second // MAP_SysTickPeriodSet(MAP_SysCtlClockGet() / SYSTICKS_PER_SECOND); MAP_SysTickIntEnable(); MAP_SysTickEnable(); MAP_IntMasterEnable(); // // Load the settings from EEPROM // // Load the robot's ID settings.get(PP_SETTING_ID, &id, sizeof(uint32_t)); // Load the motors' PID gains settings.get(PP_SETTING_LEFT_PID, purpins.leftPIDGains(), sizeof(PIDGains)); settings.get(PP_SETTING_RIGHT_PID, purpins.rightPIDGains(), sizeof(PIDGains)); // Load the communication type uint32_t comm_type; settings.get(PP_SETTING_COMM_TYPE, &comm_type, sizeof(uint32_t)); // Holding SW2 at startup forces USB Comm if(comm_type != PP_COMM_TYPE_USB && MAP_GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0) == 1) { if(comm_type == PP_COMM_TYPE_CC3000) { comm = new WiFiComm(); // Load network and server settings settings.get(PP_SETTING_NETWORK_DATA, (static_cast<WiFiComm*>(comm))->network(), sizeof(Network)); settings.get(PP_SETTING_SERVER_DATA, (static_cast<WiFiComm*>(comm))->server(), sizeof(Server)); // Set WiFiComm as the underlying communication layer communication.setCommLayer(comm); } else if(comm_type == PP_COMM_TYPE_ESP8266) { // TODO } else if(comm_type == PP_COMM_TYPE_XBEE) { // TODO } } // // Communication variables and stuff // uint8_t sensors_pack[SENSORS_PACK_SIZE]; bool send_pack = false; unsigned long sensor_streaming_millis = 0; unsigned long last_millis = millis(); uint8_t data[SERIAL_BUFFER_SIZE]; size_t data_size; uint8_t action; // // Main loop, just managing communications // while(1) { // // Check for a new action // action = communication.getMsg(data, data_size); // If we got an action... if(action > 0) { // Process it!!! if(action == PP_ACTION_GET_VERSION) { uint8_t version = VERSION; communication.sendMsg(PP_ACTION_GET_VERSION, (void*)(&version), 1); } else if(action == PP_ACTION_DRIVE) { RobotSpeed speed; memcpy(&speed, data, sizeof(speed)); purpins.setSpeed(&speed); communication.sendAck(PP_ACTION_DRIVE); } else if(action == PP_ACTION_DRIVE_MOTORS) { MotorSpeeds motor_speeds; memcpy(&motor_speeds, data, sizeof(motor_speeds)); purpins.setMotorSpeeds(&motor_speeds); communication.sendAck(PP_ACTION_DRIVE_MOTORS); } else if(action == PP_ACTION_DRIVE_PWM) { MotorPWMs motor_pwms; memcpy(&motor_pwms, data, sizeof(motor_pwms)); purpins.setPWM(&motor_pwms); communication.sendAck(PP_ACTION_DRIVE_PWM); } else if(action == PP_ACTION_GET_ODOMETRY) { Pose odometry; purpins.getOdometry(&odometry); communication.sendMsg(PP_ACTION_GET_ODOMETRY, (void*)(&odometry), sizeof(odometry)); } else if(action == PP_ACTION_GET_MOTOR_SPEEDS) { MotorSpeeds speed; purpins.getMotorSpeeds(&speed); communication.sendMsg(PP_ACTION_GET_MOTOR_SPEEDS, (void*)(&speed), sizeof(speed)); } else if(action == PP_ACTION_GET_ENCODER_PULSES) { EncoderPulses encoder_pulses; purpins.getEncoderTicks(&encoder_pulses); communication.sendMsg(PP_ACTION_GET_ENCODER_PULSES, (void*)(&encoder_pulses), sizeof(encoder_pulses)); } else if(action == PP_ACTION_GET_IMU) { IMU imu_data; imu_data.orientation_x = mpu.fusedQuat[0]; imu_data.orientation_y = mpu.fusedQuat[1]; imu_data.orientation_z = mpu.fusedQuat[2]; imu_data.orientation_w = mpu.fusedQuat[4]; imu_data.linear_acceleration_x = mpu.calibratedAccel[0]; imu_data.linear_acceleration_y = mpu.calibratedAccel[1]; imu_data.linear_acceleration_z = mpu.calibratedAccel[2]; imu_data.angular_velocity_x = mpu.calibratedMag[0]; imu_data.angular_velocity_y = mpu.calibratedMag[1]; imu_data.angular_velocity_z = mpu.calibratedMag[2]; communication.sendMsg(PP_ACTION_GET_IMU, (void*)(&imu_data), sizeof(imu_data)); } else if(action == PP_ACTION_GET_IR_SENSORS) { // TODO: Add the IR sensors } else if(action == PP_ACTION_GET_GAS_SENSOR) { // TODO: Add the gas sensor } else if(action == PP_ACTION_SET_SENSORS_PACK) { bool ok = true; memset(sensors_pack, 0, SENSORS_PACK_SIZE); if(data_size > SENSORS_PACK_SIZE) { communication.error(PP_ERROR_BUFFER_SIZE); ok = false; break; } for(unsigned int i=0 ; i<data_size ; i++) { if(data[i] < PP_ACTION_GET_ODOMETRY || data[i] > PP_ACTION_GET_GAS_SENSOR) { communication.error(PP_ERROR_SENSOR_UNKNOWN); ok = false; break; } } if(ok) { memcpy(sensors_pack, data, data_size); communication.sendAck(PP_ACTION_SET_SENSORS_PACK); } } else if(action == PP_ACTION_GET_SENSORS_PACK) { send_pack = true; } else if(action == PP_ACTION_SET_SENSOR_STREAMING) { float sensor_streaming_frequency; memcpy(&sensor_streaming_frequency, data, sizeof(sensor_streaming_frequency)); sensor_streaming_millis = 1/sensor_streaming_frequency * 1000; communication.sendAck(PP_ACTION_SET_SENSOR_STREAMING); } else if(action == PP_ACTION_SET_GLOBAL_POSE) { Pose pose; memcpy(&pose, data, sizeof(pose)); purpins.setGlobalPose(&pose); communication.sendAck(PP_ACTION_SET_GLOBAL_POSE); } else if(action == PP_ACTION_SET_NEIGHBORS_POSES) { // TODO: Finish this } else if(action == PP_ACTION_SET_ID) { memcpy(&id, data, sizeof(id)); settings.save(PP_SETTING_ID, data, sizeof(uint32_t)); communication.sendAck(PP_ACTION_SET_ID); } else if(action == PP_ACTION_GET_ID) { communication.sendMsg(PP_ACTION_GET_ID, (void*)(&id), sizeof(id)); } else if(action == PP_ACTION_SET_PID_GAINS) { memcpy(purpins.leftPIDGains(), data, sizeof(PIDGains)); memcpy(purpins.rightPIDGains(), data+sizeof(PIDGains), sizeof(PIDGains)); settings.save(PP_SETTING_LEFT_PID, data, sizeof(PIDGains)); settings.save(PP_SETTING_RIGHT_PID, data+sizeof(PIDGains), sizeof(PIDGains)); communication.sendAck(PP_ACTION_SET_PID_GAINS); } else if(action == PP_ACTION_GET_PID_GAINS) { memcpy(data, purpins.leftPIDGains(), sizeof(PIDGains)); memcpy(data+sizeof(PIDGains), purpins.rightPIDGains(), sizeof(PIDGains)); communication.sendMsg(PP_ACTION_GET_ID, (void*)(data), 2*sizeof(PIDGains)); } else if(action == PP_ACTION_SET_SERVER_DATA) { settings.save(PP_SETTING_SERVER_DATA, data, sizeof(Server)); communication.sendAck(PP_ACTION_SET_SERVER_DATA); } else if(action == PP_ACTION_GET_SERVER_DATA) { settings.get(PP_SETTING_SERVER_DATA, data, sizeof(Server)); communication.sendMsg(PP_ACTION_GET_SERVER_DATA, (void*)(data), sizeof(Server)); } else if(action == PP_ACTION_SET_NETWORK_DATA) { settings.save(PP_SETTING_NETWORK_DATA, data, sizeof(Network)); communication.sendAck(PP_ACTION_SET_NETWORK_DATA); } else if(action == PP_ACTION_GET_NETWORK_DATA) { settings.get(PP_SETTING_NETWORK_DATA, data, sizeof(Network)); communication.sendMsg(PP_ACTION_GET_NETWORK_DATA, (void*)(data), sizeof(Network)); } else if(action == PP_ACTION_SET_COMM_TYPE) { memcpy(&comm_type, data, sizeof(comm_type)); if(comm_type != communication.type()) { if(comm_type == PP_COMM_TYPE_USB) { communication.setCommLayer(uart_comm); if(comm != NULL) delete comm; } if(comm_type == PP_COMM_TYPE_CC3000) { if(comm != NULL) delete comm; comm = new WiFiComm(); // Load network and server settings settings.get(PP_SETTING_NETWORK_DATA, (static_cast<WiFiComm*>(comm))->network(), sizeof(Network)); settings.get(PP_SETTING_SERVER_DATA, (static_cast<WiFiComm*>(comm))->server(), sizeof(Server)); // Set WiFiComm as the underlying communication layer communication.setCommLayer(comm); } else if(comm_type == PP_COMM_TYPE_ESP8266) { // TODO } else if(comm_type == PP_COMM_TYPE_XBEE) { // TODO } else { communication.error(PP_ERROR_COMM_UNKNOWN); } communication.sendAck(PP_ACTION_SET_COMM_TYPE); } } } // if(action > 0) // // Manage sensor streaming // unsigned long current_millis = millis(); if(send_pack || (sensor_streaming_millis > 0 && (current_millis - last_millis) >= sensor_streaming_millis)) { size_t size = 0; for(int i=0 ; i<SENSORS_PACK_SIZE ; i++) { if(sensors_pack[i] == 0) break; if(sensors_pack[i] == PP_ACTION_GET_ODOMETRY) { Pose odometry; purpins.getOdometry(&odometry); memcpy(data+size, &odometry, sizeof(odometry)); size += sizeof(odometry); } else if(sensors_pack[i] == PP_ACTION_GET_MOTOR_SPEEDS) { MotorSpeeds speed; purpins.getMotorSpeeds(&speed); memcpy(data+size, &speed, sizeof(speed)); size += sizeof(speed); } else if(sensors_pack[i] == PP_ACTION_GET_ENCODER_PULSES) { EncoderPulses encoder_pulses; purpins.getEncoderTicks(&encoder_pulses); memcpy(data+size, &encoder_pulses, sizeof(encoder_pulses)); size += sizeof(encoder_pulses); } else if(sensors_pack[i] == PP_ACTION_GET_IMU) { IMU imu_data; imu_data.orientation_x = mpu.fusedQuat[0]; imu_data.orientation_y = mpu.fusedQuat[1]; imu_data.orientation_z = mpu.fusedQuat[2]; imu_data.orientation_w = mpu.fusedQuat[4]; imu_data.linear_acceleration_x = mpu.calibratedAccel[0]; imu_data.linear_acceleration_y = mpu.calibratedAccel[1]; imu_data.linear_acceleration_z = mpu.calibratedAccel[2]; imu_data.angular_velocity_x = mpu.calibratedMag[0]; imu_data.angular_velocity_y = mpu.calibratedMag[1]; imu_data.angular_velocity_z = mpu.calibratedMag[2]; memcpy(data+size, &imu_data, sizeof(imu_data)); size += sizeof(imu_data); } else if(sensors_pack[i] == PP_ACTION_GET_IR_SENSORS) { // TODO: Add the IR sensors } else if(sensors_pack[i] == PP_ACTION_GET_GAS_SENSOR) { // TODO: Add the gas sensor } } communication.sendMsg(PP_ACTION_GET_SENSORS_PACK, (void*)(data), size); last_millis = current_millis; send_pack = false; } // if(send_pack ... } // while(1) return 0; }
/* * ======== EK_TM4C123GXL_initGPIO ======== */ void EK_TM4C123GXL_initGPIO(void) { // /* Setup the LED GPIO pins used */ // GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1); /* EK_TM4C123GXL_LED_RED */ // GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); /* EK_TM4C123GXL_LED_GREEN */ // GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3); /* EK_TM4C123GXL_LED_BLUE */ // // /* Setup the button GPIO pins used */ // GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4); /* EK_TM4C123GXL_GPIO_SW1 */ // GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU); // // /* PF0 requires unlocking before configuration */ // HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY; // HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= GPIO_PIN_0; // GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0); /* EK_TM4C123GXL_GPIO_SW2 */ // GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU); // HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_M; //Init debug gpio pin/pins // MAP_GPIOPinTypeGPIOOutput(DEBUG_GPIO_PORT_1, DEBUG_GPIO_PIN_1); //debug pin //Init radio power enable pin // MAP_GPIOPinTypeGPIOOutput(INEEDMD_GPIO_EN_PORT, INEEDMD_RADIO_ENABLE_PIN); //radio power enable pin //Init radio command mode pin // MAP_GPIOPinTypeGPIOOutput(INEEDMD_GPIO_CMND_PORT, INEEDMD_RADIO_CMND_PIN); //radio command mode pin //Init radio reset pin // MAP_GPIOPinTypeGPIOOutput(INEEDMD_GPIO_RST_PORT, INEEDMD_RADIO_RESET_PIN); //radio reset pin //Init external clock enable pin // MAP_GPIOPinTypeGPIOOutput(INEEDMD_XTAL_PORT, INEEDMD_XTAL_ENABLE_PIN); //external clock enable pin //Init ADC power on pin // MAP_GPIOPinTypeGPIOOutput(INEEDMD_ADC_GPIO_PORT, INEEDMD_ADC_PWR_PIN); //Init ADC reset pin // MAP_GPIOPinTypeGPIOOutput(INEEDMD_ADC_GPIO_PORT, INEEDMD_ADC_RESET_PIN); // Init ADC interrupt pin // MAP_GPIOPinTypeGPIOInput(INEEDMD_ADC_GPIO_PORT, INEEDMD_ADC_INTERUPT_PIN); // Init ADC start pin // MAP_GPIOPinTypeGPIOOutput(INEEDMD_ADC_GPIO_PORT, INEEDMD_ADC_START_PIN); //Init ADC nCS pin // MAP_GPIOPinTypeGPIOOutput(INEEDMD_ADC_GPIO_PORT, INEEDMD_ADC_nCS_PIN); //Init USB unplug detect pin // HWREG(GPIO_PORTB_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY; HWREG(GPIO_PORTB_BASE + GPIO_O_CR) |= GPIO_PIN_4; MAP_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_4); MAP_GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_4, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPD); HWREG(GPIO_PORTB_BASE + GPIO_O_LOCK) = GPIO_LOCK_M; /* Once GPIO_init is called, GPIO_config cannot be changed */ GPIO_init(); }
//***************************************************************************** // // Demonstrate the use of the USB stick update example. // //***************************************************************************** int main(void) { uint_fast32_t ui32Count; tContext sContext; tRectangle sRect; // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPULazyStackingEnable(); // // Set the system clock to run at 50MHz from the PLL. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Initialize the display driver. // CFAL96x64x16Init(); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sCFAL96x64x16); // // Fill the top 24 rows of the screen with blue to create the banner. // sRect.i16XMin = 0; sRect.i16YMin = 0; sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1; sRect.i16YMax = 9; GrContextForegroundSet(&sContext, ClrDarkBlue); GrRectFill(&sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&sContext, ClrWhite); GrRectDraw(&sContext, &sRect); // // Put the application name in the middle of the banner. // GrContextFontSet(&sContext, g_psFontFixed6x8); GrStringDrawCentered(&sContext, "usb-stick-demo", -1, GrContextDpyWidthGet(&sContext) / 2, 4, 0); // // Indicate what is happening. // GrStringDrawCentered(&sContext, "Press the", -1, GrContextDpyWidthGet(&sContext) / 2, 20, 0); GrStringDrawCentered(&sContext, "select button to", -1, GrContextDpyWidthGet(&sContext) / 2, 30, 0); GrStringDrawCentered(&sContext, "start the USB", -1, GrContextDpyWidthGet(&sContext) / 2, 40, 0); GrStringDrawCentered(&sContext, "stick updater.", -1, GrContextDpyWidthGet(&sContext) / 2, 50, 0); // // Flush any cached drawing operations. // GrFlush(&sContext); // // Enable the GPIO module which the select button is attached to. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM); // // Enable the GPIO pin to read the user button. // ROM_GPIODirModeSet(GPIO_PORTM_BASE, GPIO_PIN_4, GPIO_DIR_MODE_IN); MAP_GPIOPadConfigSet(GPIO_PORTM_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // // Wait for the pullup to take effect or the next loop will exist too soon. // SysCtlDelay(1000); // // Wait until the select button has been pressed for ~40ms (in order to // debounce the press). // ui32Count = 0; while(1) { // // See if the button is pressed. // if(ROM_GPIOPinRead(GPIO_PORTM_BASE, GPIO_PIN_4) == 0) { // // Increment the count since the button is pressed. // ui32Count++; // // If the count has reached 4, then the button has been debounced // as being pressed. // if(ui32Count == 4) { break; } } else { // // Reset the count since the button is not pressed. // ui32Count = 0; } // // Delay for approximately 10ms. // SysCtlDelay(16000000 / (3 * 100)); } // // Wait until the select button has been released for ~40ms (in order to // debounce the release). // ui32Count = 0; while(1) { // // See if the button is pressed. // if(ROM_GPIOPinRead(GPIO_PORTM_BASE, GPIO_PIN_4) != 0) { // // Increment the count since the button is released. // ui32Count++; // // If the count has reached 4, then the button has been debounced // as being released. // if(ui32Count == 4) { break; } } else { // // Reset the count since the button is pressed. // ui32Count = 0; } // // Delay for approximately 10ms. // SysCtlDelay(16000000 / (3 * 100)); } // // Indicate that the updater is being called. // GrStringDrawCentered(&sContext, "The USB stick", -1, GrContextDpyWidthGet(&sContext) / 2, 20, true); GrStringDrawCentered(&sContext, "updater is now", -1, GrContextDpyWidthGet(&sContext) / 2, 30, true); GrStringDrawCentered(&sContext, "waiting for a", -1, GrContextDpyWidthGet(&sContext) / 2, 40, true); GrStringDrawCentered(&sContext, "USB stick.", -1, GrContextDpyWidthGet(&sContext) / 2, 50, true); // // Flush any cached drawing operations. // GrFlush(&sContext); // // Call the updater so that it will search for an update on a memory stick. // (*((void (*)(void))(*(uint32_t *)0x2c)))(); // // The updater should take control, so this should never be reached. // Just in case, loop forever. // while(1) { } }
/* * initialize tm4c */ void init_satellite() { FPUEnable(); FPULazyStackingEnable(); /* * init clock */ MAP_SysCtlClockSet(SYSCTL_SYSDIV_3 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); //66.6..MHz MAP_IntMasterEnable(); /* * Enable peripherals */ MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //for LED indication MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); //for UART MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //for IRQ and SW_EN MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); //for SPI /* * configure */ MAP_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3); MAP_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, SIGNAL_LOW); //off MAP_GPIOPinConfigure(GPIO_PA0_U0RX); MAP_GPIOPinConfigure(GPIO_PA1_U0TX); MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioConfig(UART_PORT, UART_BAUDRATE, SysCtlClockGet()); MAP_GPIOIntDisable(GPIO_PORTB_BASE, SIGNAL_HIGH); //interrupt disable MAP_GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_2); //IRQ as input MAP_GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); MAP_GPIOIntTypeSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_FALLING_EDGE); //enable interrupt MAP_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_5); //sw enable MAP_GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_5, GPIO_DIR_MODE_OUT); MAP_GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_5, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD); MAP_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5, SIGNAL_LOW); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); MAP_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_0); MAP_GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); MAP_GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_0, SIGNAL_HIGH); //chip select MAP_GPIOIntEnable(GPIO_PORTB_BASE, GPIO_PIN_2); //enable interrupt for WLAN_IRQ pin SpiCleanGPIOISR(); //clear interrupt status MAP_IntEnable(INT_GPIOB); //spi init_worker(); setState(READY); }
//***************************************************************************** // // This example application demonstrates the use of the timers to generate // periodic interrupts. // //***************************************************************************** int main(void) { #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) uint32_t ui32SysClock; #endif // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPULazyStackingEnable(); // // Set the clocking to run directly from the crystal. // TODO: Set the system clock appropriately for your application. // #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_OSC), 25000000); #else ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); #endif // // Initialize the display on the board. This is not directly related // to the timer operation but makes it easier to see what's going on // when you run this on an EK-LM4F232 board. // // TODO: Remove or replace this call with something appropriate for // your hardware. // InitDisplay(); // // Enable the peripherals used by this example. // // TODO: Update this depending upon the general purpose timer and // CCP pin you intend using. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM); // // Configure PM0 as the CCP0 pin for timer 4. // // TODO: This is set up to use GPIO PM0 which can be configured // as the CCP0 pin for Timer4 and also happens to be attached to // a switch on the EK-LM4F232 board. Change this configuration to // correspond to the correct pin for your application. // ROM_GPIOPinTypeTimer(GPIO_PORTM_BASE, GPIO_PIN_0); GPIOPinConfigure(GPIO_PM0_T4CCP0); // // Set the pin to use the internal pull-up. // // TODO: Remove or replace this call to correspond to the wiring // of the CCP pin you are using. If your board has an external // pull-up or pull-down, this will not be required. // MAP_GPIOPadConfigSet(GPIO_PORTM_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Configure the timers in downward edge count mode. // // TODO: Modify this to configure the specific general purpose // timer you are using. The timer choice is intimately tied to // the pin whose edges you want to capture because specific CCP // pins are connected to specific timers. // ROM_TimerConfigure(TIMER4_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_COUNT)); ROM_TimerControlEvent(TIMER4_BASE, TIMER_A, TIMER_EVENT_POS_EDGE); ROM_TimerLoadSet(TIMER4_BASE, TIMER_A, 9); ROM_TimerMatchSet(TIMER4_BASE, TIMER_A, 0); // // Setup the interrupt for the edge capture timer. Note that we // use the capture match interrupt and NOT the timeout interrupt! // // TODO: Modify to enable the specific timer you are using. // ROM_IntEnable(INT_TIMER4A); ROM_TimerIntEnable(TIMER4_BASE, TIMER_CAPA_MATCH); // // Enable the timer. // // TODO: Modify to enable the specific timer you are using. // ROM_TimerEnable(TIMER4_BASE, TIMER_A); // // At this point, the timer will count down every time a positive // edge is detected on the relevant pin. When the count reaches // 0, the timer count reloads, the interrupt fires and the timer // is disabled. The ISR can then restart the timer if required. // MainLoopRun(); }
//***************************************************************************** // // This example application demonstrates the use of the different sleep modes // and different power configuration options. // //***************************************************************************** int main(void) { // // Set the clocking to run from the MOSC with the PLL at 16MHz. // g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_320), 16000000); // // Set the clocking for Deep-Sleep. // Power down the PIOSC & MOSC to save power and run from the // internal 30kHz osc. // ROM_SysCtlDeepSleepClockConfigSet(1, (SYSCTL_DSLP_OSC_INT30 | SYSCTL_DSLP_PIOSC_PD | SYSCTL_DSLP_MOSC_PD)); // // Initialize the UART and write the banner. // Indicate we are currently in Run Mode. // ConfigureUART(); UARTprintf("\033[2J\033[H"); UARTprintf("Sleep Modes example\n\n"); UARTprintf("Mode:\t\tClock Source:\tLED Toggle Source:"); UARTprintf("\nRun\t\tMOSC with PLL\tTimer"); // // Initialize the buttons driver. // ButtonsInit(); // // Enable the interrupt for the button. // ROM_GPIOIntEnable(GPIO_PORTJ_AHB_BASE, GPIO_INT_PIN_0); // // Enable the GPIO ports that are used for the on-board LEDs. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // // Set pad config. // MAP_GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // // Set direction. // ROM_GPIODirModeSet(GPIO_PORTJ_BASE, GPIO_PIN_0, GPIO_DIR_MODE_IN); // // Enable the interrupt for the button. // ROM_GPIOIntEnable(GPIO_PORTJ_BASE, GPIO_INT_PIN_0); // // Enable interrupt to NVIC. // ROM_IntEnable(INT_GPIOJ); // // Enable the GPIO ports that are used for the on-board LEDs. // ROM_SysCtlPeripheralEnable(RUN_GPIO_SYSCTL); ROM_SysCtlPeripheralEnable(SLEEP_GPIO_SYSCTL); ROM_SysCtlPeripheralEnable(DSLEEP_GPIO_SYSCTL); ROM_SysCtlPeripheralEnable(TOGGLE_GPIO_SYSCTL); // // Enable the GPIO pins for the LED. // ROM_GPIOPinTypeGPIOOutput(RUN_GPIO_BASE, RUN_GPIO_PIN); ROM_GPIOPinTypeGPIOOutput(SLEEP_GPIO_BASE, SLEEP_GPIO_PIN); ROM_GPIOPinTypeGPIOOutput(DSLEEP_GPIO_BASE, DSLEEP_GPIO_PIN); ROM_GPIOPinTypeGPIOOutput(TOGGLE_GPIO_BASE, TOGGLE_GPIO_PIN); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Configure the 32-bit periodic timer. // ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, g_ui32SysClock); // // Setup the interrupts for the timer timeout. // ROM_IntEnable(INT_TIMER0A); ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // // Configure the PWM0 to count down without synchronization. // This will be used in Deep-Sleep. // ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC); // // Enable the PWM0 output signal. // ROM_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true); // // Set up the period to match the timer. // ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 65000); // // Configure the PWM for a 50% duty cycle. // ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 65000 >> 1); // // Enable the timer. // ROM_TimerEnable(TIMER0_BASE, TIMER_A); // // Enable the Timer in Sleep Mode. // ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_TIMER0); // // Enable the PWM in Deep-Sleep Mode. // ROM_SysCtlPeripheralDeepSleepEnable(SYSCTL_PERIPH_PWM0); // // Enable the Button Port in Sleep & Deep-Sleep Mode. // ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_GPIOJ); ROM_SysCtlPeripheralDeepSleepEnable(SYSCTL_PERIPH_GPIOJ); // // Enable the LED Ports in Sleep & Deep-Sleep Mode. // ROM_SysCtlPeripheralSleepEnable(SLEEP_GPIO_SYSCTL); ROM_SysCtlPeripheralDeepSleepEnable(DSLEEP_GPIO_SYSCTL); ROM_SysCtlPeripheralSleepEnable(TOGGLE_GPIO_SYSCTL); ROM_SysCtlPeripheralDeepSleepEnable(TOGGLE_GPIO_SYSCTL); // // Enable Auto Clock Gating Control. // ROM_SysCtlPeripheralClockGating(true); // // Set LDO to 1.15V in Sleep. // Set LDO to 1.10V in Deep-Sleep. // SysCtlLDOSleepSet(SYSCTL_LDO_1_15V); SysCtlLDODeepSleepSet(SYSCTL_LDO_1_10V); // // Set SRAM to Standby when in Sleep Mode. // Set Flash & SRAM to Low Power in Deep-Sleep Mode. // SysCtlSleepPowerSet(SYSCTL_SRAM_STANDBY); SysCtlDeepSleepPowerSet(SYSCTL_FLASH_LOW_POWER | SYSCTL_SRAM_LOW_POWER); // // Call to set initial LED power state. // PowerLEDsSet(); // // Loop forever. // while(1) { // // Handle going into the different sleep modes outside of // interrupt context. // if (g_ui32SleepMode == 1) { // // Go into Sleep Mode. // ROM_SysCtlSleep(); } else if (g_ui32SleepMode == 2) { // // Go into Deep-Sleep Mode. // ROM_SysCtlDeepSleep(); } } }
//***************************************************************************** // // Demonstrate the use of the USB stick update example. // //***************************************************************************** int main(void) { uint_fast32_t ui32Count; // // Run from the PLL at 50 MHz. // g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 50000000); // // Configure the device pins. // PinoutSet(false, false); // // Initialize the UART. // ConfigureUART(); // // Clear the terminal and print banner. // UARTprintf("\033[2J\033[H"); UARTprintf("usb-stick-demo!\n"); // // Indicate what is happening. // UARTprintf("Press\n"); UARTprintf("USR_SW1 to\n"); UARTprintf("start the USB\n"); UARTprintf("stick updater.\n"); // // Enable the GPIO module which the select button is attached to. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ); // // Enable the GPIO pin to read the user button. // ROM_GPIODirModeSet(GPIO_PORTJ_BASE, GPIO_PIN_0, GPIO_DIR_MODE_IN); MAP_GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // // Wait for the pullup to take effect or the next loop will exist too soon. // SysCtlDelay(1000); // // Wait until the select button has been pressed for ~40ms (in order to // debounce the press). // ui32Count = 0; while(1) { // // See if the button is pressed. // if(ROM_GPIOPinRead(GPIO_PORTJ_BASE, GPIO_PIN_0) == 0) { // // Increment the count since the button is pressed. // ui32Count++; // // If the count has reached 4, then the button has been debounced // as being pressed. // if(ui32Count == 4) { break; } } else { // // Reset the count since the button is not pressed. // ui32Count = 0; } // // Delay for approximately 10ms. // SysCtlDelay(16000000 / (3 * 100)); } // // Wait until the select button has been released for ~40ms (in order to // debounce the release). // ui32Count = 0; while(1) { // // See if the button is pressed. // if(ROM_GPIOPinRead(GPIO_PORTJ_BASE, GPIO_PIN_0) != 0) { // // Increment the count since the button is released. // ui32Count++; // // If the count has reached 4, then the button has been debounced // as being released. // if(ui32Count == 4) { break; } } else { // // Reset the count since the button is pressed. // ui32Count = 0; } // // Delay for approximately 10ms. // SysCtlDelay(16000000 / (3 * 100)); } // // Indicate that the updater is being called. // UARTprintf("The USB stick\n"); UARTprintf("updater is now\n"); UARTprintf("waiting for a\n"); UARTprintf("USB stick.\n"); // // Call the updater so that it will search for an update on a memory stick. // (*((void (*)(void))(*(uint32_t *)0x2c)))(); // // The updater should take control, so this should never be reached. // Just in case, loop forever. // while(1) { } }
void pio_init() { // Board Initialization start // // // The FPU should be enabled because some compilers will use floating- // point registers, even for non-floating-point code. If the FPU is not // enabled this will cause a fault. This also ensures that floating- // point operations could be added to this application and would work // correctly and use the hardware floating-point unit. Finally, lazy // stacking is enabled for interrupt handlers. This allows floating- // point instructions to be used within interrupt handlers, but at the // expense of extra stack usage. // FPUEnable(); FPULazyStackingEnable(); //Init the device with 16 MHz clock. initClk(); /* Configure the system peripheral bus that IRQ & EN pin are map to */ MAP_SysCtlPeripheralEnable( SYSCTL_PERIPH_IRQ_PORT); // // Disable all the interrupts before configuring the lines // MAP_GPIOPinIntDisable(SPI_GPIO_IRQ_BASE, 0xFF); // // Cofigure WLAN_IRQ pin as input // MAP_GPIOPinTypeGPIOInput(SPI_GPIO_IRQ_BASE, SPI_IRQ_PIN); GPIOPadConfigSet(SPI_GPIO_IRQ_BASE, SPI_IRQ_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // // Setup the GPIO interrupt for this pin // MAP_GPIOIntTypeSet(SPI_GPIO_IRQ_BASE, SPI_IRQ_PIN, GPIO_FALLING_EDGE); // // Configure WLAN chip // MAP_GPIOPinTypeGPIOOutput(SPI_GPIO_IRQ_BASE, SPI_EN_PIN); MAP_GPIODirModeSet( SPI_GPIO_IRQ_BASE, SPI_EN_PIN, GPIO_DIR_MODE_OUT ); MAP_GPIOPadConfigSet( SPI_GPIO_IRQ_BASE, SPI_EN_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD ); MAP_GPIOPinWrite(SPI_GPIO_IRQ_BASE, SPI_EN_PIN, PIN_LOW); SysCtlDelay(600000); SysCtlDelay(600000); SysCtlDelay(600000); // // Disable WLAN CS with pull up Resistor // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_SPI_PORT); MAP_GPIOPinTypeGPIOOutput(SPI_CS_PORT, SPI_CS_PIN); GPIOPadConfigSet(SPI_CS_PORT, SPI_CS_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); MAP_GPIOPinWrite(SPI_CS_PORT, SPI_CS_PIN, PIN_HIGH); // // Enable interrupt for WLAN_IRQ pin // MAP_GPIOPinIntEnable(SPI_GPIO_IRQ_BASE, SPI_IRQ_PIN); // // Clear interrupt status // SpiCleanGPIOISR(); MAP_IntEnable(INT_GPIO_SPI); //init LED initLEDs(); }
void arch_GpioConf(uint_t nPort, uint_t nPin, uint_t nMode, uint_t nInit) { uint_t nBase; nBase = arch_GpioPortBase(nPort); nPin = BITMASK(nPin); arch_GpioClockEnable(nPort); //PB7(NMI) if ((nPort == GPIO_P1) && (nPin == 0x80)) { __raw_writel(GPIO_LOCK_KEY_DD, GPIO_PORTB_BASE + GPIO_O_LOCK); __raw_writel(0x80, GPIO_PORTB_BASE + GPIO_O_CR); } switch (nMode) { case GPIO_M_IN_ANALOG: MAP_GPIODirModeSet(nBase, nPin, GPIO_DIR_MODE_IN); MAP_GPIOPadConfigSet(nBase, nPin, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_ANALOG); break; case GPIO_M_IN_PD: MAP_GPIODirModeSet(nBase, nPin, GPIO_DIR_MODE_IN); MAP_GPIOPadConfigSet(nBase, nPin, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD); break; case GPIO_M_IN_PU: MAP_GPIODirModeSet(nBase, nPin, GPIO_DIR_MODE_IN); MAP_GPIOPadConfigSet(nBase, nPin, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); break; case GPIO_M_IN_FLOAT: MAP_GPIODirModeSet(nBase, nPin, GPIO_DIR_MODE_IN); MAP_GPIOPadConfigSet(nBase, nPin, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD); break; case GPIO_M_OUT_OD: MAP_GPIODirModeSet(nBase, nPin, GPIO_DIR_MODE_OUT); MAP_GPIOPadConfigSet(nBase, nPin, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_OD); break; case GPIO_M_AF_OD: MAP_GPIODirModeSet(nBase, nPin, GPIO_DIR_MODE_HW); MAP_GPIOPadConfigSet(nBase, nPin, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_OD); break; case GPIO_M_OUT_PP: MAP_GPIODirModeSet(nBase, nPin, GPIO_DIR_MODE_OUT); MAP_GPIOPadConfigSet(nBase, nPin, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD); break; case GPIO_M_AF_PP: MAP_GPIODirModeSet(nBase, nPin, GPIO_DIR_MODE_HW); MAP_GPIOPadConfigSet(nBase, nPin, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD); break; default: break; } if (nMode & GPIO_M_OUT_MASK) { switch (nInit) { case GPIO_INIT_HIGH: MAP_GPIOPinWrite(nBase, nPin, 0xFF); break; case GPIO_INIT_LOW: MAP_GPIOPinWrite(nBase, nPin, 0); break; default: break; } } //PB7(NMI) if ((nPort == GPIO_P1) && (nPin == 0x80)) { __raw_writel(GPIO_LOCK_KEY_DD, GPIO_PORTB_BASE + GPIO_O_LOCK); __raw_writel(0x00, GPIO_PORTB_BASE + GPIO_O_CR); } }
//***************************************************************************** // //! Configures the device pins for the standard usages on the EK-TM4C1294XL. //! //! \param bEthernet is a boolean used to determine function of Ethernet pins. //! If true Ethernet pins are configured as Ethernet LEDs. If false GPIO are //! available for application use. //! \param bUSB is a boolean used to determine function of USB pins. If true USB //! pins are configured for USB use. If false then USB pins are available for //! application use as GPIO. //! //! This function enables the GPIO modules and configures the device pins for //! the default, standard usages on the EK-TM4C1294XL. Applications that //! require alternate configurations of the device pins can either not call //! this function and take full responsibility for configuring all the device //! pins, or can reconfigure the required device pins after calling this //! function. //! //! \return None. // //***************************************************************************** void PinoutSet(bool bEthernet, bool bUSB) { // // Enable all the GPIO peripherals. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOQ); // // PA0-1 are used for UART0. // ROM_GPIOPinConfigure(GPIO_PA0_U0RX); ROM_GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // PB0-1/PD6/PL6-7 are used for USB. // PQ4 can be used as a power fault detect on this board but it is not // the hardware peripheral power fault input pin. // if(bUSB) { HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY; HWREG(GPIO_PORTD_BASE + GPIO_O_CR) = 0xff; ROM_GPIOPinConfigure(GPIO_PD6_USB0EPEN); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); ROM_GPIOPinTypeUSBDigital(GPIO_PORTD_BASE, GPIO_PIN_6); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTL_BASE, GPIO_PIN_6 | GPIO_PIN_7); ROM_GPIOPinTypeGPIOInput(GPIO_PORTQ_BASE, GPIO_PIN_4); } else { // // Keep the default config for most pins used by USB. // Add a pull down to PD6 to turn off the TPS2052 switch // ROM_GPIOPinTypeGPIOInput(GPIO_PORTD_BASE, GPIO_PIN_6); MAP_GPIOPadConfigSet(GPIO_PORTD_BASE, GPIO_PIN_6, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD); } // // PF0/PF4 are used for Ethernet LEDs. // if(bEthernet) { // // this app wants to configure for ethernet LED function. // ROM_GPIOPinConfigure(GPIO_PF0_EN0LED0); ROM_GPIOPinConfigure(GPIO_PF4_EN0LED1); GPIOPinTypeEthernetLED(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4); } else { // // This app does not want Ethernet LED function so configure as // standard outputs for LED driving. // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4); // // Default the LEDs to OFF. // ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4, 0); MAP_GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4, GPIO_STRENGTH_12MA, GPIO_PIN_TYPE_STD); } // // PJ0 and J1 are used for user buttons // ROM_GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_0 | GPIO_PIN_1); ROM_GPIOPinWrite(GPIO_PORTJ_BASE, GPIO_PIN_0 | GPIO_PIN_1, 0); // // PN0 and PN1 are used for USER LEDs. // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1); MAP_GPIOPadConfigSet(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1, GPIO_STRENGTH_12MA, GPIO_PIN_TYPE_STD); // // Default the LEDs to OFF. // ROM_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1, 0); }
//***************************************************************************** // // This example demonstrates how to send a string of data to the UART. // //***************************************************************************** int main(void) { uint32_t ui32_Period, ui32_PWM=0, ui32_PWM_step = 40, ui32_PWM_min=2000, ui32_PWM_max=4000; uint32_t ui32_sw1; uint32_t ui32_sw2; // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // //MAP_FPUEnable(); //MAP_FPULazyStackingEnable(); // // Set the clocking to run directly from the crystal. // MAP_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Enable the GPIO port that is used for the on-board LED. // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // // Enable the GPIO pins for the LED (PF2). // MAP_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); // Configure UART InitConsole(); // ----------------------------------------------------------------- // Configure PWM for servo control // ----------------------------------------------------------------- // follow page 1240 of the datasheet: ui32_Period = (MAP_SysCtlClockGet()/8) / 50; //PWM frequency 50HZ, T=20ms // GOTO middle of servo in the beginning ui32_PWM = ui32_PWM_min + (ui32_PWM_max - ui32_PWM_min) / 2; ui32_PWM_max = ui32_Period*.1; ui32_PWM_min = ui32_Period*.05; //Configure PWM Clock to match system MAP_SysCtlPWMClockSet(SYSCTL_PWMDIV_8); // Enable system clock for PWM0 module MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); // Enable the GPIO port that is used for the PWM outputs MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //Configure PB5,PB5 Pins as PWM MAP_GPIOPinConfigure(GPIO_PB4_M0PWM2); MAP_GPIOPinConfigure(GPIO_PB5_M0PWM3); MAP_GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_4); MAP_GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_5); //Configure PWM Options MAP_PWMGenConfigure(PWM0_BASE, PWM_GEN_1 , PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC); // // Set the PWM period to 50Hz. To calculate the appropriate parameter // use the following equation: N = (1 / f) * SysClk. Where N is the // function parameter, f is the desired frequency, and SysClk is the // system clock frequency. // In this case you get: (1 / 50Hz) * 16MHz/8div = 40000 cycles. Note that // the maximum period you can set is 2^16 - 1. // TODO: modify this calculation to use the clock frequency that you are // using. // PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, ui32_Period); //Set PWM duty - 25% and 75% PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, ui32_PWM); PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3, ui32_PWM); // Enable the PWM generator MAP_PWMGenEnable(PWM0_BASE, PWM_GEN_1); // Turn on the Output pins MAP_PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT | PWM_OUT_3_BIT, true); // ----------------------------------------------------------------- // Enable PORTF and Configure SW1 and SW2 as input // ----------------------------------------------------------------- MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIO_PORTF_LOCK_R = 0x4C4F434B; // unlock GPIO Port F GPIO_PORTF_CR_R = 0x1F; // allow changes to PF4-0 MAP_GPIOPadConfigSet(GPIO_PORTF_BASE, (GPIO_PIN_4 | GPIO_PIN_0), GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); MAP_GPIODirModeSet(GPIO_PORTF_BASE, (GPIO_PIN_4 | GPIO_PIN_0), GPIO_DIR_MODE_IN); // // Loop forever echoing data through the UART. // while(1) { // Get buttons: ui32_sw1 = MAP_GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_4); ui32_sw2 = MAP_GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0); // if pressing SW1 on LaunchPad TM4C123G if( ui32_sw1 == 0 ) { if(ui32_PWM >= ui32_PWM_min+ui32_PWM_step) { ui32_PWM -= ui32_PWM_step; } } if( ui32_sw2 == 0 ) { if(ui32_PWM <= ui32_PWM_max-ui32_PWM_step) { ui32_PWM += ui32_PWM_step; } } UARTprintf("Period: %d, PWM: %d\n", ui32_Period, ui32_PWM); MAP_SysCtlDelay(2000000); MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2 , ui32_Period - ui32_PWM); MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3 , ui32_PWM); } }