void pinMode(uint8_t pin, uint8_t mode) { uint8_t bit = digitalPinToBitMask(pin); uint8_t port = digitalPinToPort(pin); uint32_t portBase = (uint32_t) portBASERegister(port); volatile uint32_t *lock = portLOCKRegister(port); volatile uint32_t *cr = portCRRegister(port); if (port == NOT_A_PORT) return; if (mode == INPUT) { ROM_GPIOPinTypeGPIOInput(portBase, bit); } else if (mode == INPUT_PULLUP) { *lock = GPIO_LOCK_KEY_DD; *cr |= bit; *lock = 0; ROM_GPIODirModeSet(portBase, bit, GPIO_DIR_MODE_IN); GPIOPadConfigSet(portBase, bit, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); *cr &= ~bit; } else if (mode == INPUT_PULLDOWN) { *lock = GPIO_LOCK_KEY_DD; *cr |= bit; *lock = 0; ROM_GPIODirModeSet(portBase, bit, GPIO_DIR_MODE_IN); GPIOPadConfigSet(portBase, bit, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPD); *cr &= ~bit; } else {//mode == OUTPUT ROM_GPIOPinTypeGPIOOutput(portBase, bit); } }
//--- Dynmxl Functions ----// void DymxlTx(const uint8_t id, const uint8_t instruction, const uint8_t *params, const uint8_t params_len, const uint32_t BASE) { uint8_t checksum = 0; uint8_t tx_buf[256]; uint8_t* tbuf = tx_buf; ROM_GPIODirModeSet(GPIO_PORTJ_BASE, GPIO_PIN_1, GPIO_DIR_MODE_HW); //ROM_GPIODirModeSet(GPIO_PORTJ_BASE, GPIO_PIN_0, GPIO_DIR_MODE_IN); // find disable reciver HWREG(BASE + UART_O_CTL) &= ~UART_CTL_RXE; tx_buf[0] = 0xff; tx_buf[1] = 0xff; tx_buf[2] = id; tx_buf[3] = 2 + params_len; tx_buf[4] = instruction; checksum = 2+ params_len + id + instruction; for (uint8_t i = 0; i < params_len; i++) { tx_buf[5+i] = params[i]; checksum += params[i]; } checksum = ((~checksum) & 255); tx_buf[5+params_len] = checksum; UARTWrite(BASE,tbuf, 6+params_len); while(HWREG(BASE + UART_O_FR) & UART_FR_BUSY) { } ROM_GPIODirModeSet(GPIO_PORTJ_BASE, GPIO_PIN_1, GPIO_DIR_MODE_IN); HWREG(BASE + UART_O_CTL) |= UART_CTL_RXE; }
//***************************************************************************** // //! 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); ROM_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); }
//***************************************************************************** // //! Initialize LEDs //! //! \param none //! //! \return none //! //! \brief Initializes LED Ports and Pins // //***************************************************************************** void initLEDs() { // Enable use of PORTF to toggle LED and disable interrupt on this port 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_DD; HWREG(GPIO_PORTF_BASE + GPIO_O_CR) |= 0x01; HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0; MAP_GPIOPinIntDisable(GPIO_PORTF_BASE, 0xFF); // Configure Red LED MAP_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1); MAP_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, PIN_LOW); // Configure Blue LED MAP_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); MAP_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, PIN_LOW); // Configure Green LED MAP_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3); MAP_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, PIN_LOW); // Button inputs ROM_GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); }
BOOL xMBTCPPortInit(USHORT port) { ROM_SysCtlPeripheralEnable(WIZ610_GPIO_PERIPH); ROM_GPIODirModeSet(WIZ610_GPIO_BASE,WIZ610_GPIO_PIN_CMD_ENABLE ,GPIO_DIR_MODE_OUT); ROM_GPIOPadConfigSet(WIZ610_GPIO_BASE,WIZ610_GPIO_PIN_CMD_ENABLE,GPIO_STRENGTH_8MA,GPIO_PIN_TYPE_STD_WPU); ROM_GPIOPinWrite(WIZ610_GPIO_BASE,WIZ610_GPIO_PIN_CMD_ENABLE,WIZ610_GPIO_PIN_CMD_ENABLE); // uart setup ROM_SysCtlPeripheralEnable(WIZ610_UART_PERIPH); ROM_GPIOPinConfigure(GPIO_PB0_U1RX); ROM_GPIOPinConfigure(GPIO_PB1_U1TX); ROM_GPIOPinTypeUART(WIZ610_GPIO_BASE, WIZ610_GPIO_PIN_RX | WIZ610_GPIO_PIN_TX); ROM_UARTConfigSetExpClk(WIZ610_UART_BASE, ROM_SysCtlClockGet(), 38400, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); ROM_GPIOPinWrite(WIZ610_GPIO_BASE,WIZ610_GPIO_PIN_CMD_ENABLE,WIZ610_GPIO_PIN_CMD_ENABLE); ROM_UARTFIFOLevelSet(WIZ610_UART_BASE, UART_FIFO_TX4_8, UART_FIFO_RX1_8); ROM_IntEnable(INT_UART1); ROM_UARTEnable(WIZ610_UART_BASE); ROM_UARTDMAEnable(WIZ610_UART_BASE, UART_DMA_TX); ROM_UARTIntEnable(WIZ610_UART_BASE, UART_INT_RX); ROM_IntEnable(INT_UDMA); WIZ610Transfer(); cmd_modbus_switch=0; g_ulRxBufACount=0; modbus_tcp_rab=MODBUS_TCP_IDLE; return TRUE; }
//***************************************************************************** // // This function initializes the state of the button handler and prepares it // to debounce the state of the button. If the button is initially pressed, // the state of the motor controller is reverted to the factory settings. // //***************************************************************************** void ButtonInit(void) { // // Set the GPIO as an input and enable the weak pull up. When pressed, the // button is read as 0. // ROM_GPIODirModeSet(BUTTON_PORT, BUTTON_PIN, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(BUTTON_PORT, BUTTON_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // // Delay for a bit before sampling the reset state of the button. // SysCtlDelay(1000); // // Read the current state of the button and consider it to be the debounced // state. // g_ulDebouncedState = ROM_GPIOPinRead(BUTTON_PORT, BUTTON_PIN); // // Reset the debounce and hold counters. // g_ulDebounceCount = BUTTON_DEBOUNCE_COUNT; g_ulHoldCount = 0; // // See if the button was initially pressed. // if(g_ulDebouncedState == BUTTON_DOWN) { // // Reset the parameters to the default values. // ParamLoadDefault(); // // Save the default parameters. // ParamSave(); // // Indicate that the configuration was just reset to the default // settings. // LEDParameterReset(); // // Set the hold count such that the power-on hold of the push button // will not cause the servo calibration process to start. // g_ulHoldCount = BUTTON_HOLD_COUNT; } }
//***************************************************************************** // // 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) { } }
void cfg_GPIO() { ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); //Enable clock for GPIOF /* Unlock pull ups to buttons on board */ 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; /* Unlock pull ups to buttons on board */ ROM_GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_4|GPIO_PIN_0, GPIO_DIR_MODE_IN); //Configure as input the PORTF_0 and PORTF_4 ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4|GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); //Configure as input with fan in of 2mA, weak pull-up }
//***************************************************************************** // // 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); ROM_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); }
int main() { uint8_t ui8Buttons; uint8_t ui8ButtonsChanged; ROM_SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,LED_RED | LED_BLUE | LED_GREEN); ROM_SysCtlPeripheralEnable(BUTTONS_GPIO_PERIPH); 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; ROM_GPIODirModeSet(BUTTONS_GPIO_BASE, ALL_BUTTONS, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(BUTTONS_GPIO_BASE,ALL_BUTTONS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); g_ui8ButtonStates = ROM_GPIOPinRead(BUTTONS_GPIO_BASE, ALL_BUTTONS); for(;;) { /* ui8Buttons = ButtonsPoll(&ui8ButtonsChanged, 0); if(BUTTON_PRESSED(LEFT_BUTTON, ui8Buttons, ui8ButtonsChanged)) { ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, LED_RED); }//Button leftside, if button leftside is pressed the LED will be flash red else if(BUTTON_PRESSED(RIGHT_BUTTON, ui8Buttons, ui8ButtonsChanged)) { ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, LED_GREEN); }//Button rightside, if button leftside is pressed the LED will be flash green else if(BUTTON_RELEASED(LEFT_BUTTON|RIGHT_BUTTON, ui8Buttons, ui8ButtonsChanged)) { ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, 0); }//If the buttons will be release the LED turn off. */ //----Wenn beide Buttons gedrueckt werden leuchten auch --- ui8Buttons = (uint8_t)~ROM_GPIOPinRead(BUTTONS_GPIO_BASE, ALL_BUTTONS); led_switch = 0; if(LEFT_BUTTON & ui8Buttons) led_switch |= LED_RED; if(RIGHT_BUTTON & ui8Buttons) led_switch |= LED_GREEN; ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, led_switch); } return 0; }
/********************************************************************************************************* ** Function name: ConfigureFanFb ** Descriptions: ** input parameters: ** ** Output parameters:: 无 ** Returned value: ** ** Created by: zhangwen ** Created Date: **-------------------------------------------------------------------------------------------------------- ** Modified by: ** Modified date: **-------------------------------------------------------------------------------------------------------- *********************************************************************************************************/ void ConfigureFanFb() { SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // // Reset the error indicator. GPIOPinTypeGPIOInput(GPIO_PORTD_BASE,GPIO_PIN_2); GPIOIntTypeSet(GPIO_PORTD_BASE, GPIO_PIN_2, GPIO_RISING_EDGE); ROM_GPIODirModeSet(GPIO_PORTD_BASE, GPIO_PIN_2, GPIO_DIR_MODE_IN); //GPIOPadConfigSet(GPIO_PORTD_BASE, GPIO_PIN_2,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_OD); GPIOIntEnable(GPIO_PORTD_BASE,GPIO_PIN_2); IntEnable(INT_GPIOD); // 使能GPIOD端口中断 }
int main() { uint8_t ui8Buttons; uint8_t led_switch; /* uint8_t ui8ButtonsChanged; */ ROM_SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, LED_RED|LED_BLUE|LED_GREEN); ROM_SysCtlPeripheralEnable(BUTTONS_GPIO_PERIPH); 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; ROM_GPIODirModeSet(BUTTONS_GPIO_BASE, ALL_BUTTONS, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(BUTTONS_GPIO_BASE, ALL_BUTTONS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); /* ButtonsInit(); */ for (;;) { /* ui8Buttons = ButtonsPoll(&ui8ButtonsChanged, 0); if(BUTTON_PRESSED(LEFT_BUTTON, ui8Buttons, ui8ButtonsChanged)) ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, LED_RED); else if(BUTTON_PRESSED(RIGHT_BUTTON, ui8Buttons, ui8ButtonsChanged)) ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, LED_GREEN); else if(BUTTON_RELEASED(LEFT_BUTTON|RIGHT_BUTTON, ui8Buttons, ui8ButtonsChanged)) ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, 0); */ ui8Buttons = (uint8_t)~ROM_GPIOPinRead(BUTTONS_GPIO_BASE, ALL_BUTTONS); led_switch = 0; if(LEFT_BUTTON & ui8Buttons) led_switch |= LED_RED; if(RIGHT_BUTTON & ui8Buttons) led_switch |= LED_GREEN; ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, led_switch); } return 0; }
//***************************************************************************** // // This function initializes the fan interface, preparing it to manage the // operation of the fan. // //***************************************************************************** void FanInit(void) { // // Configure the GPIO as an output and enable the 8 mA drive. // ROM_GPIODirModeSet(FAN_PORT, FAN_PIN, GPIO_DIR_MODE_OUT); ROM_GPIOPadConfigSet(FAN_PORT, FAN_PIN, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD); // // Turn on the fan to test it. // g_ulFanState = 1; ROM_GPIOPinWrite(FAN_PORT, FAN_PIN, FAN_ON); // // Set the fan time to FAN_TEST_TIME. // g_ulFanTime = FAN_TEST_TIME; }
//***************************************************************************** // //! 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); // // 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); ROM_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_ucButtonStates = ROM_GPIOPinRead(BUTTONS_GPIO_BASE, ALL_BUTTONS); }
int gpio_init_int(gpio_t pin, gpio_mode_t mode, gpio_flank_t flank, gpio_cb_t cb, void *arg) { const uint8_t port_num = _port_num(pin); const uint32_t port_addr = _port_base[port_num]; const uint32_t icr_reg_addr = port_addr + GPIO_ICR_R_OFF; const uint8_t pin_num = _pin_num(pin); const uint8_t pin_bit = 1<<pin_num; const unsigned int int_num = _int_assign[port_num]; const uint32_t sysctl_port_base = _sysctl_port_base[port_num]; ROM_SysCtlPeripheralEnable(sysctl_port_base); gpio_config[port_num][pin_num].cb = cb; gpio_config[port_num][pin_num].arg = arg; DEBUG("init int pin:%d, int num %d, port addr %" PRIx32 "\n", pin_num, int_num, port_addr); ROM_GPIODirModeSet(port_addr, 1<<pin_num, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(port_addr, 1<<pin_num, GPIO_STRENGTH_2MA, TYPE(mode)); ROM_IntMasterDisable(); HWREG(icr_reg_addr) = pin_bit; ROM_GPIOIntTypeSet(port_addr, pin_bit, flank); HWREG(port_addr+GPIO_LOCK_R_OFF) = GPIO_LOCK_KEY; HWREG(port_addr+GPIO_CR_R_OFF) |= pin_bit; HWREG(port_addr+GPIO_DEN_R_OFF) |= pin_bit; HWREG(port_addr+GPIO_LOCK_R_OFF) = 0; gpio_irq_enable(pin); ROM_IntEnable(int_num); ROM_IntMasterEnable(); return 0; }
void wiz610_init(void) { ROM_SysCtlPeripheralEnable(WIZ610_GPIO_PERIPH); ROM_GPIODirModeSet(WIZ610_GPIO_BASE,WIZ610_GPIO_PIN_CMD_ENABLE ,GPIO_DIR_MODE_OUT); ROM_GPIOPadConfigSet(WIZ610_GPIO_BASE,WIZ610_GPIO_PIN_CMD_ENABLE,GPIO_STRENGTH_8MA,GPIO_PIN_TYPE_STD_WPU); ROM_GPIOPinWrite(WIZ610_GPIO_BASE,WIZ610_GPIO_PIN_CMD_ENABLE,WIZ610_GPIO_PIN_CMD_ENABLE); // uart setup ROM_SysCtlPeripheralEnable(WIZ610_UART_PERIPH); ROM_GPIOPinConfigure(GPIO_PB0_U1RX); ROM_GPIOPinConfigure(GPIO_PB1_U1TX); ROM_GPIOPinTypeUART(WIZ610_GPIO_BASE, WIZ610_GPIO_PIN_RX | WIZ610_GPIO_PIN_TX); ROM_UARTConfigSetExpClk(WIZ610_UART_BASE, ROM_SysCtlClockGet(), 38400, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); ROM_GPIOPinWrite(WIZ610_GPIO_BASE,WIZ610_GPIO_PIN_CMD_ENABLE,0); ROM_UARTFIFOLevelSet(WIZ610_UART_BASE, UART_FIFO_TX4_8, UART_FIFO_RX1_8); ROM_IntEnable(INT_UART1); ROM_UARTEnable(WIZ610_UART_BASE); ROM_UARTDMAEnable(WIZ610_UART_BASE, UART_DMA_TX); ROM_UARTIntEnable(WIZ610_UART_BASE, UART_INT_RX); ROM_IntEnable(INT_UDMA); cmd_modbus_switch=1; }
int gpio_init(gpio_t pin, gpio_mode_t mode) { const uint8_t port_num = _port_num(pin); const uint32_t port_addr = _port_base[port_num]; const uint8_t pin_num = _pin_num(pin); const uint32_t sysctl_port_base = _sysctl_port_base[port_num]; const unsigned long pin_bit = 1ul << pin_num; DEBUG("Init GPIO: port %c, %d\n", 'A' + port_num, pin_num); DEBUG("Sysctl %" PRIx32 "\n", sysctl_port_base); ROM_SysCtlPeripheralEnable(sysctl_port_base); HWREG(port_addr+GPIO_LOCK_R_OFF) = GPIO_LOCK_KEY; HWREG(port_addr+GPIO_CR_R_OFF) |= pin_bit; HWREG(port_addr+GPIO_DEN_R_OFF) |= pin_bit; HWREG(port_addr+GPIO_LOCK_R_OFF) = 0; ROM_GPIOPadConfigSet(port_addr, pin_bit, GPIO_STRENGTH_2MA, TYPE(mode)); ROM_GPIODirModeSet(port_addr, pin_bit, MODE(mode)); return 0; }
void Hardware_Init(void) { // Initially wait for device connection. g_eState = STATE_NO_DEVICE; g_eUIState = STATE_NO_DEVICE; // Set the clocking to run from the PLL at 50MHz. ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // Initialize the UART. ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioInit(0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_4 | GPIO_PIN_5); UARTprintf("\n\nUSB Android ADK Firmware for EvalBot by [email protected]\n"); /* Configure EvalBot available Buttons (User Switch 1, 2 ...) */ // Enable the GPIO pin to read the select button. ROM_SysCtlPeripheralEnable(USER_SW1_SYSCTL_PERIPH); ROM_GPIODirModeSet(USER_SW1_PORT_BASE, USER_SW1_PIN, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(USER_SW1_PORT_BASE, USER_SW1_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // Enable the GPIO pin to read the select button. ROM_SysCtlPeripheralEnable(USER_SW2_SYSCTL_PERIPH); ROM_GPIODirModeSet(USER_SW2_PORT_BASE, USER_SW2_PIN, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(USER_SW2_PORT_BASE, USER_SW2_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // Enable the GPIO pin to read the select button. // Enable the GPIO ports used for the bump sensors. ROM_SysCtlPeripheralEnable(BUMP_L_SW3_SYSCTL_PERIPH); ROM_GPIODirModeSet(BUMP_L_SW3_PORT_BASE, BUMP_L_SW3_PIN, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(BUMP_L_SW3_PORT_BASE, BUMP_L_SW3_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // Enable the GPIO pin to read the select button. ROM_SysCtlPeripheralEnable(BUMP_R_SW4_SYSCTL_PERIPH); ROM_GPIODirModeSet(BUMP_R_SW4_PORT_BASE, BUMP_R_SW4_PIN, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(BUMP_R_SW4_PORT_BASE, BUMP_R_SW4_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // Enable the GPIO pin for the LED1 (PF4) & LED2 (PF5) // Set the direction as output, and enable the GPIO pin for digital function. ROM_SysCtlPeripheralEnable(LED1_SYSCTL_PERIPH); GPIOPinTypeGPIOOutput(LED1_PORT_BASE, LED1_PIN); ROM_SysCtlPeripheralEnable(LED2_SYSCTL_PERIPH); GPIOPinTypeGPIOOutput(LED2_PORT_BASE, LED2_PIN); // Configure SysTick for a 1KHz interrupt. ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // Enable Clocking to the USB controller. ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); // Set the USB pins to be controlled by the USB controller. ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); GPIOPinConfigure(GPIO_PA6_USB0EPEN); ROM_GPIOPinTypeUSBDigital(GPIO_PORTA_BASE, GPIO_PIN_6); // Enable the GPIO pin for the USB HOST / DEVICE Selection (PB0). Set the direction as output, and // enable the GPIO pin for digital function. GPIO_PORTB_DIR_R |= GPIO_PIN_0; GPIO_PORTB_DEN_R |= GPIO_PIN_0; // PB0 = GND =USB HOST Enabled. GPIO_PORTB_DATA_R &= ~(GPIO_PIN_0); // Enable the uDMA controller and set up the control table base. ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); ROM_uDMAEnable(); ROM_uDMAControlBaseSet(g_sDMAControlTable); // Initialize the USB stack mode and pass in a mode callback. USBStackModeSet(0, USB_MODE_OTG, ModeCallback); // Register the host class drivers. USBHCDRegisterDrivers(0, g_ppHostClassDrivers, NUM_CLASS_DRIVERS); // Initialize the power configuration. This sets the power enable signal // to be active high and does not enable the power fault. USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER); // Initialize the USB controller for OTG operation with a 250ms polling // rate. // Warning if this delay is higher it cannot connect correctly to Android ADK. USBOTGModeInit(0, 250, g_pHCDPool, HCD_MEMORY_SIZE); }
//***************************************************************************** // //! Initializes the SDRAM. //! //! \param ulEPIDivider is the EPI clock divider to use. //! \param ulConfig is the SDRAM interface configuration. //! \param ulRefresh is the refresh count in core clocks (0-2047). //! //! This function must be called prior to ExtRAMAlloc() or ExtRAMFree(). It //! configures the Stellaris microcontroller EPI block for SDRAM access and //! initializes the SDRAM heap (if SDRAM is found). The parameter \e ulConfig //! is the logical OR of several sets of choices: //! //! The processor core frequency must be specified with one of the following: //! //! - \b EPI_SDRAM_CORE_FREQ_0_15 - core clock is 0 MHz < clk <= 15 MHz //! - \b EPI_SDRAM_CORE_FREQ_15_30 - core clock is 15 MHz < clk <= 30 MHz //! - \b EPI_SDRAM_CORE_FREQ_30_50 - core clock is 30 MHz < clk <= 50 MHz //! - \b EPI_SDRAM_CORE_FREQ_50_100 - core clock is 50 MHz < clk <= 100 MHz //! //! The low power mode is specified with one of the following: //! //! - \b EPI_SDRAM_LOW_POWER - enter low power, self-refresh state //! - \b EPI_SDRAM_FULL_POWER - normal operating state //! //! The SDRAM device size is specified with one of the following: //! //! - \b EPI_SDRAM_SIZE_64MBIT - 64 Mbit device (8 MB) //! - \b EPI_SDRAM_SIZE_128MBIT - 128 Mbit device (16 MB) //! - \b EPI_SDRAM_SIZE_256MBIT - 256 Mbit device (32 MB) //! - \b EPI_SDRAM_SIZE_512MBIT - 512 Mbit device (64 MB) //! //! The parameter \e ulRefresh sets the refresh counter in units of core //! clock ticks. It is an 11-bit value with a range of 0 - 2047 counts. //! //! \return Returns \b true on success of \b false if no SDRAM is found or //! any other error occurs. // //***************************************************************************** tBoolean SDRAMInit(unsigned long ulEPIDivider, unsigned long ulConfig, unsigned long ulRefresh) { // // Enable the EPI peripheral // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_EPI0); // // Configure the GPIO for communication with SDRAM. // #ifdef EPI_PORTA_PINS ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_GPIOPadConfigSet(GPIO_PORTA_BASE, EPI_PORTA_PINS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); ROM_GPIODirModeSet(GPIO_PORTA_BASE, EPI_PORTA_PINS, GPIO_DIR_MODE_HW); #endif #ifdef EPI_GPIOB_PINS ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_GPIOPadConfigSet(GPIO_PORTB_BASE, EPI_GPIOB_PINS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); ROM_GPIODirModeSet(GPIO_PORTB_BASE, EPI_GPIOB_PINS, GPIO_DIR_MODE_HW); #endif #ifdef EPI_PORTC_PINS ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_GPIOPadConfigSet(GPIO_PORTC_BASE, EPI_PORTC_PINS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); ROM_GPIODirModeSet(GPIO_PORTC_BASE, EPI_PORTC_PINS, GPIO_DIR_MODE_HW); #endif #ifdef EPI_PORTD_PINS ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_GPIOPadConfigSet(GPIO_PORTD_BASE, EPI_PORTD_PINS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); ROM_GPIODirModeSet(GPIO_PORTD_BASE, EPI_PORTD_PINS, GPIO_DIR_MODE_HW); #endif #ifdef EPI_PORTE_PINS ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); ROM_GPIOPadConfigSet(GPIO_PORTE_BASE, EPI_PORTE_PINS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); ROM_GPIODirModeSet(GPIO_PORTE_BASE, EPI_PORTE_PINS, GPIO_DIR_MODE_HW); #endif #ifdef EPI_PORTF_PINS ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, EPI_PORTF_PINS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); ROM_GPIODirModeSet(GPIO_PORTF_BASE, EPI_PORTF_PINS, GPIO_DIR_MODE_HW); #endif #ifdef EPI_PORTG_PINS ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); ROM_GPIOPadConfigSet(GPIO_PORTG_BASE, EPI_PORTG_PINS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); ROM_GPIODirModeSet(GPIO_PORTG_BASE, EPI_PORTG_PINS, GPIO_DIR_MODE_HW); #endif #ifdef EPI_PORTH_PINS ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH); ROM_GPIOPadConfigSet(GPIO_PORTH_BASE, EPI_PORTH_PINS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); ROM_GPIODirModeSet(GPIO_PORTH_BASE, EPI_PORTH_PINS, GPIO_DIR_MODE_HW); #endif #ifdef EPI_PORTJ_PINS ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ); ROM_GPIOPadConfigSet(GPIO_PORTJ_BASE, EPI_PORTJ_PINS, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); ROM_GPIODirModeSet(GPIO_PORTJ_BASE, EPI_PORTJ_PINS, GPIO_DIR_MODE_HW); #endif #if defined(EPI_CLK_PORT) && defined(EPI_CLK_PIN) ROM_GPIOPadConfigSet(EPI_CLK_PORT, EPI_CLK_PIN, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD_WPU); #endif // // Set the EPI divider. // EPIDividerSet(EPI0_BASE, ulEPIDivider); // // Select SDRAM mode. // EPIModeSet(EPI0_BASE, EPI_MODE_SDRAM); // // Configure SDRAM mode. // EPIConfigSDRAMSet(EPI0_BASE, ulConfig, ulRefresh); // // Set the address map. // EPIAddressMapSet(EPI0_BASE, EPI_ADDR_RAM_SIZE_256MB | EPI_ADDR_RAM_BASE_6); // // Set the EPI mem pointer to the base of EPI mem // g_pusEPIMem = (unsigned short *)0x60000000; // // Wait for the EPI initialization to complete. // while(HWREG(EPI0_BASE + EPI_O_STAT) & EPI_STAT_INITSEQ) { // // Wait for SDRAM initialization to complete. // } // // At this point, the SDRAM should be accessible. We attempt a couple // of writes then read back the memory to see if it seems to be there. // g_pusEPIMem[0] = 0xABCD; g_pusEPIMem[1] = 0x5AA5; // // Read back the patterns we just wrote to make sure they are valid. Note // that we declared g_pusEPIMem as volatile so the compiler should not // optimize these reads out of the image. // if((g_pusEPIMem[0] == 0xABCD) && (g_pusEPIMem[1] == 0x5AA5)) { // // The memory appears to be there so remember that we found it. // g_bSDRAMPresent = true; // // Now set up the heap that ExtRAMAlloc() and ExtRAMFree() will use. // bpool((void *)g_pusEPIMem, SDRAM_SIZE_BYTES); } // // If we get this far, the SDRAM heap has been successfully initialized. // return(g_bSDRAMPresent); }
//***************************************************************************** // // Demonstrate the use of the USB stick update example. // //***************************************************************************** int main(void) { unsigned long ulCount; 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.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&sContext) - 1; sRect.sYMax = 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_pFontFixed6x8); 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); ROM_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). // ulCount = 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. // ulCount++; // // If the count has reached 4, then the button has been debounced // as being pressed. // if(ulCount == 4) { break; } } else { // // Reset the count since the button is not pressed. // ulCount = 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). // ulCount = 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. // ulCount++; // // If the count has reached 4, then the button has been debounced // as being released. // if(ulCount == 4) { break; } } else { // // Reset the count since the button is pressed. // ulCount = 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))(*(unsigned long *)0x2c)))(); // // The updater should take control, so this should never be reached. // Just in case, loop forever. // while(1) { } }
//***************************************************************************** // // This function initializes the limit switch inputs, preparing them to sense // the state of the limit switches. // // The limit switches are normally closed switches that open when the switches // are pressed. When closed, the switches connect the input to ground. When // opened, the on-chip weak pull-up connects the input to Vdd. // // Before final initialization, this function can set the Voltage Mode ramp // rate when it detects a cross-connected jumper across the limit swich inputs; // essentially enabling an automatic voltage ramp without the use of CAN. // // This function should always be called sometime after ControllerInit() // because it depends on the controller being initialized. // //***************************************************************************** void LimitInit(void) { // // Configure the limit switch inputs with the weak pull-up enabled. // #if LIMIT_FWD_PORT == LIMIT_REV_PORT ROM_GPIODirModeSet(LIMIT_FWD_PORT, LIMIT_FWD_PIN | LIMIT_REV_PIN, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(LIMIT_FWD_PORT, LIMIT_FWD_PIN | LIMIT_REV_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); #else ROM_GPIODirModeSet(LIMIT_FWD_PORT, LIMIT_FWD_PIN, GPIO_DIR_MODE_IN); ROM_GPIODirModeSet(LIMIT_REV_PORT, LIMIT_REV_PIN, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(LIMIT_FWD_PORT, LIMIT_FWD_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); ROM_GPIOPadConfigSet(LIMIT_REV_PORT, LIMIT_REV_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); #endif // // Clear the limit flags. // g_ulLimitFlags = 0; // // Set the sticky limit flags since no limits have tripped on startup. // HWREGBITW(&g_ulLimitFlags, LIMIT_FLAG_STKY_FWD_OK) = 1; HWREGBITW(&g_ulLimitFlags, LIMIT_FLAG_STKY_REV_OK) = 1; HWREGBITW(&g_ulLimitFlags, LIMIT_FLAG_STKY_SFWD_OK) = 1; HWREGBITW(&g_ulLimitFlags, LIMIT_FLAG_STKY_SREV_OK) = 1; // // If both limit switch inputs are high, determine if there is a // cross-connected jumper. // if(ROM_GPIOPinRead(LIMIT_FWD_PORT, LIMIT_FWD_PIN) && ROM_GPIOPinRead(LIMIT_REV_PORT, LIMIT_REV_PIN)) { // // Configure forward limit pin as an open-drain output with a weak // pull-up. // ROM_GPIODirModeSet(LIMIT_FWD_PORT, LIMIT_FWD_PIN, GPIO_DIR_MODE_OUT); ROM_GPIOPadConfigSet(LIMIT_FWD_PORT, LIMIT_FWD_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD_WPU); // // Set the forward limit pin low. // ROM_GPIOPinWrite(LIMIT_FWD_PORT, LIMIT_FWD_PIN, 0); // // Wait a bit. // SysCtlDelay(1000); // // If the reverse limit pin is now low too, a cross-connected jumper // was successfully detected. // if(ROM_GPIOPinRead(LIMIT_REV_PORT, LIMIT_REV_PIN) == 0) { // // Set the Automatic Ramp Flag. // HWREGBITW(&g_ulLimitFlags, LIMIT_FLAG_AUTO_RAMP_EN) = 1; // // Set Voltage Mode ramp to AUTO_RAMP_RATE. // ControllerVoltageRateSet(AUTO_RAMP_RATE); } // // Reconfigure the forward limit pin as an input with a weak pull-up. // ROM_GPIODirModeSet(LIMIT_FWD_PORT, LIMIT_FWD_PIN, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(LIMIT_FWD_PORT, LIMIT_FWD_PIN, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); } }
//***************************************************************************** // // 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(); } } }
//***************************************************************************** // // This example demonstrates how to use the uDMA controller to transfer data // between memory buffers and to and from a peripheral, in this case a UART. // The uDMA controller is configured to repeatedly transfer a block of data // from one memory buffer to another. It is also set up to repeatedly copy a // block of data from a buffer to the UART output. The UART data is looped // back so the same data is received, and the uDMA controlled is configured to // continuously receive the UART data using ping-pong buffers. // // The processor is put to sleep when it is not doing anything, and this allows // collection of CPU usage data to see how much CPU is being used while the // data transfers are ongoing. // //***************************************************************************** int main(void) { static unsigned long ulPrevSeconds; static unsigned long ulPrevXferCount; static unsigned long ulPrevUARTCount = 0; unsigned long ulXfersCompleted; unsigned long ulBytesTransferred; unsigned long ulButton; // // Set the clocking to run from the PLL at 50 MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Enable peripherals to operate when CPU is in sleep. // ROM_SysCtlPeripheralClockGating(true); // // Set the push button as an input with a pull-up. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_4, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // // Initialize the UART. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioInit(0); UARTprintf("\033[2JuDMA Example\n"); // // Show the clock frequency and exit instructions. // UARTprintf("Stellaris @ %u MHz\n", ROM_SysCtlClockGet() / 1000000); UARTprintf("Press button to use debugger.\n\n"); // // Show statistics headings. // UARTprintf("CPU Memory UART\n"); UARTprintf("Usage Transfers Transfers\n"); // // Configure SysTick to occur 100 times per second, to use as a time // reference. Enable SysTick to generate interrupts. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Initialize the CPU usage measurement routine. // CPUUsageInit(ROM_SysCtlClockGet(), SYSTICKS_PER_SECOND, 2); // // Enable the uDMA controller at the system level. Enable it to continue // to run while the processor is in sleep. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UDMA); // // Enable the uDMA controller error interrupt. This interrupt will occur // if there is a bus error during a transfer. // ROM_IntEnable(INT_UDMAERR); // // Enable the uDMA controller. // ROM_uDMAEnable(); // // Point at the control table to use for channel control structures. // ROM_uDMAControlBaseSet(ucControlTable); // // Initialize the uDMA memory to memory transfers. // InitSWTransfer(); // // Initialize the uDMA UART transfers. // InitUART1Transfer(); // // Remember the current SysTick seconds count. // ulPrevSeconds = g_ulSeconds; // // Remember the current count of memory buffer transfers. // ulPrevXferCount = g_ulMemXferCount; // // Loop until the button is pressed. The processor is put to sleep // in this loop so that CPU utilization can be measured. When the // processor is sleeping a lot, it can be hard to connect to the target // with the debugger. Pressing the button will cause this loop to exit // and the processor will no longer sleep. // while(1) { // // Check for the select button press. If the button is pressed, // then exit this loop. // ulButton = ROM_GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_4); if(!ulButton) { break; } // // Check to see if one second has elapsed. If so, the make some // updates. // if(g_ulSeconds != ulPrevSeconds) { // // Print a message to the display showing the CPU usage percent. // The fractional part of the percent value is ignored. // UARTprintf("\r%3d%% ", g_ulCPUUsage >> 16); // // Remember the new seconds count. // ulPrevSeconds = g_ulSeconds; // // Calculate how many memory transfers have occurred since the last // second. // ulXfersCompleted = g_ulMemXferCount - ulPrevXferCount; // // Remember the new transfer count. // ulPrevXferCount = g_ulMemXferCount; // // Compute how many bytes were transferred in the memory transfer // since the last second. // ulBytesTransferred = ulXfersCompleted * MEM_BUFFER_SIZE * 4; // // Print a message showing the memory transfer rate. // if(ulBytesTransferred >= 100000000) { UARTprintf("%3d MB/s ", ulBytesTransferred / 1000000); } else if(ulBytesTransferred >= 10000000) { UARTprintf("%2d.%01d MB/s ", ulBytesTransferred / 1000000, (ulBytesTransferred % 1000000) / 100000); } else if(ulBytesTransferred >= 1000000) { UARTprintf("%1d.%02d MB/s ", ulBytesTransferred / 1000000, (ulBytesTransferred % 1000000) / 10000); } else if(ulBytesTransferred >= 100000) { UARTprintf("%3d KB/s ", ulBytesTransferred / 1000); } else if(ulBytesTransferred >= 10000) { UARTprintf("%2d.%01d KB/s ", ulBytesTransferred / 1000, (ulBytesTransferred % 1000) / 100); } else if(ulBytesTransferred >= 1000) { UARTprintf("%1d.%02d KB/s ", ulBytesTransferred / 1000, (ulBytesTransferred % 1000) / 10); } else if(ulBytesTransferred >= 100) { UARTprintf("%3d B/s ", ulBytesTransferred); } else if(ulBytesTransferred >= 10) { UARTprintf("%2d B/s ", ulBytesTransferred); } else { UARTprintf("%1d B/s ", ulBytesTransferred); } // // Calculate how many UART transfers have occurred since the last // second. // ulXfersCompleted = (g_ulRxBufACount + g_ulRxBufBCount - ulPrevUARTCount); // // Remember the new UART transfer count. // ulPrevUARTCount = g_ulRxBufACount + g_ulRxBufBCount; // // Compute how many bytes were transferred by the UART. The number // of bytes received is multiplied by 2 so that the TX bytes // transferred are also accounted for. // ulBytesTransferred = ulXfersCompleted * UART_RXBUF_SIZE * 2; // // Print a message showing the UART transfer rate. // if(ulBytesTransferred >= 1000000) { UARTprintf("%1d.%02d MB/s ", ulBytesTransferred / 1000000, (ulBytesTransferred % 1000000) / 10000); } else if(ulBytesTransferred >= 100000) { UARTprintf("%3d KB/s ", ulBytesTransferred / 1000); } else if(ulBytesTransferred >= 10000) { UARTprintf("%2d.%01d KB/s ", ulBytesTransferred / 1000, (ulBytesTransferred % 1000) / 100); } else if(ulBytesTransferred >= 1000) { UARTprintf("%1d.%02d KB/s ", ulBytesTransferred / 1000, (ulBytesTransferred % 1000) / 10); } else if(ulBytesTransferred >= 100) { UARTprintf("%3d B/s ", ulBytesTransferred); } else if(ulBytesTransferred >= 10) { UARTprintf("%2d B/s ", ulBytesTransferred); } else { UARTprintf("%1d B/s ", ulBytesTransferred); } // // Print a spinning line to make it more apparent that there is // something happening. // UARTprintf("%c", g_pcTwirl[ulPrevSeconds % 4]); } // // Put the processor to sleep if there is nothing to do. This allows // the CPU usage routine to measure the number of free CPU cycles. // If the processor is sleeping a lot, it can be hard to connect to // the target with the debugger. // ROM_SysCtlSleep(); }
//***************************************************************************** // // Demonstrate the use of the USB stick update example. // //***************************************************************************** int main(void) { unsigned long ulCount; // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Enable the UART. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTStdioInit(0); UARTprintf("\n\nUSB Stick Update Demo\n---------------------\n\n"); // // Enable the GPIO module which the select button is attached to. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // // Indicate what is happening. // UARTprintf("Press the user button to start the USB stick updater\n\n"); // // Enable the GPIO pin to read the select button. // ROM_GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_4, GPIO_DIR_MODE_IN); ROM_GPIOPadConfigSet(GPIO_PORTB_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). // ulCount = 0; while(1) { // // See if the button is pressed. // if(ROM_GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_4) == 0) { // // Increment the count since the button is pressed. // ulCount++; // // If the count has reached 4, then the button has been debounced // as being pressed. // if(ulCount == 4) { break; } } else { // // Reset the count since the button is not pressed. // ulCount = 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). // ulCount = 0; while(1) { // // See if the button is pressed. // if(ROM_GPIOPinRead(GPIO_PORTB_BASE, GPIO_PIN_4) != 0) { // // Increment the count since the button is released. // ulCount++; // // If the count has reached 4, then the button has been debounced // as being released. // if(ulCount == 4) { break; } } else { // // Reset the count since the button is pressed. // ulCount = 0; } // // Delay for approximately 10ms. // SysCtlDelay(16000000 / (3 * 100)); } // // Indicate that the updater is being called. // UARTprintf("The USB stick updater is now running and looking for a\n" "USB memory stick\n\n"); // // Wait for the entire message above to transmit before continuing // while(UARTBusy(UART0_BASE)) { } // // Call the updater so that it will search for an update on a memory stick. // (*((void (*)(void))(*(unsigned long *)0x2c)))(); // // The updater should take control, so this should never be reached. // Just in case, loop forever. // while(1) { } }
//***************************************************************************** // // 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) { } }