static void uart_drivers_setup() { /** Enable print UART1 **/ gpio_set_uart_tx(GPIO_B, GPIO_PIN_6); gpio_set_uart_rx(GPIO_B, GPIO_PIN_7); uart_enable(UART_1, UART1_PRINT_BAUDRATE); boot_success("Starting UART_1 at %d\n", UART1_PRINT_BAUDRATE); /* testing */ gpio_set_uart_tx(GPIO_A, GPIO_PIN_2); gpio_set_uart_rx(GPIO_A, GPIO_PIN_3); uart_enable(UART_2,VN200_BAUDRATE); boot_success("Starting UART_2 at %d\n", VN200_BAUDRATE); gpio_set_uart_tx(GPIO_C, GPIO_PIN_10); gpio_set_uart_rx(GPIO_C, GPIO_PIN_11); uart_enable(UART_3, DATALINK_BAUDRATE); boot_success("Starting UART_3 at %d\n", DATALINK_BAUDRATE); gpio_set_uart_tx(GPIO_A, GPIO_PIN_0); gpio_set_uart_rx(GPIO_A, GPIO_PIN_1); uart_enable(UART_4, VN200_BAUDRATE); boot_success("Starting UART_4 at %d\n", VN200_BAUDRATE); gpio_set_uart_tx(GPIO_C, GPIO_PIN_12); gpio_set_uart_rx(GPIO_D, GPIO_PIN_2); uart_enable(UART_5, VN200_BAUDRATE); boot_success("Starting UART_5 at %d\n",VN200_BAUDRATE); }
void usbuart_init(void) { UART_PIN_SETUP(); periph_clock_enable(USBUART_CLK); __asm__("nop"); __asm__("nop"); __asm__("nop"); uart_disable(USBUART); /* Setup UART parameters. */ uart_clock_from_sysclk(USBUART); uart_set_baudrate(USBUART, 38400); uart_set_databits(USBUART, 8); uart_set_stopbits(USBUART, 1); uart_set_parity(USBUART, UART_PARITY_NONE); // Enable FIFO uart_enable_fifo(USBUART); // Set FIFO interrupt trigger levels to 1/8 full for RX buffer and // 7/8 empty (1/8 full) for TX buffer uart_set_fifo_trigger_levels(USBUART, UART_FIFO_RX_TRIG_1_8, UART_FIFO_TX_TRIG_7_8); uart_clear_interrupt_flag(USBUART, UART_INT_RX | UART_INT_RT); /* Enable interrupts */ uart_enable_interrupts(UART0, UART_INT_RX| UART_INT_RT); /* Finally enable the USART. */ uart_enable(USBUART); //nvic_set_priority(USBUSART_IRQ, IRQ_PRI_USBUSART); nvic_enable_irq(USBUART_IRQ); }
static void uart_setup(void) { u32 pins; /* Enable GPIOA in run mode. */ periph_clock_enable(RCC_GPIOA); /* Configure PA0 and PA1 as alternate function pins */ pins = GPIO0 | GPIO1; GPIO_AFSEL(GPIOA) |= pins; GPIO_DEN(GPIOA) |= pins; /* PA0 and PA1 are muxed to UART0 during power on, by default */ /* Enable the UART clock */ periph_clock_enable(RCC_UART0); /* We need a brief delay before we can access UART config registers */ __asm__("nop"); /* Disable the UART while we mess with its setings */ uart_disable(UART0); /* Configure the UART clock source as precision internal oscillator */ uart_clock_from_piosc(UART0); /* Set communication parameters */ uart_set_baudrate(UART0, 921600); uart_set_databits(UART0, 8); uart_set_parity(UART0, UART_PARITY_NONE); uart_set_stopbits(UART0, 1); /* Now that we're done messing with the settings, enable the UART */ uart_enable(UART0); }
/* * Initiate USCI_A1 to 9,600 BR, 8 bit, 1 stop, no parity, LSB 1st * and enables interrupts. */ void uart_init(void) { // USCI_A1 init according to the 2xx user guide section 15.3.1 UCA1CTL1 |= UCSWRST; // set USCI reset UCA1CTL0 = UCMODE_0; // set UART mode, 8 bit, 1 stop, no parity, lsb 1st UCA1CTL1 = UCSSEL_2|UCSWRST; // Source clock is SMCLK (=8MHz) // Baud rate UCA1BR0 = 0x41 ; // 9,600 UCA1BR1 = 0x03 ; UCA1MCTL = UCBRS_2 ; // modulation to adjust to the clock freq // ports UART_DIR |= UART_TX_BIT; // Set TX bit as output UART_DIR &= ~UART_RX_BIT; // Set RX bit as input UART_SEL |= (UART_TX_BIT|UART_RX_BIT); // Set Tx/Rx bits as primary function UCA1CTL1 &= ~UCSWRST; // clear reset bit uartRxNextIn = 0; uartRxNextOut = 0; bUartRxValid = 1; uartTxNextIn = 0; uartTxNextOut = 0; bUartTxClear = 1; uart_enable(); }
int main() { // Initialize the platform platform_init(); //fiteco_lib_gwt_opennode_power_select(FITECO_GWT_OPENNODE_POWER__OFF); /* compatibility with HiKoB */ if (uart_external == NULL) uart_external = uart_print; else uart_enable(uart_external, 500000); // Start the soft timer soft_timer_init(); //set the open node power to off and charge the battery //fiteco_lib_gwt_opennode_power_select(FITECO_GWT_OPENNODE_POWER__MAIN); fiteco_lib_gwt_opennode_power_select(FITECO_GWT_OPENNODE_POWER__OFF); fiteco_lib_gwt_battery_charge_enable(); fiteco_lib_gwt_opennode_power_select(FITECO_GWT_OPENNODE_POWER__MAIN); cn_i2c_start(); //initialize the led, red off, green on leds_off(LEDS_MASK); leds_on(GREEN_LED); uart_set_rx_handler(uart_print, char_rx, NULL); // Run platform_run(); return 0; }
static void update_host_wake_locked(int host_wake) { if (host_wake == bt_lpm.host_wake) return; bt_lpm.host_wake = host_wake; if (host_wake) { wake_lock(&bt_lpm.wake_lock); if (!host_wake_uart_enabled) { WARN_ON(!bt_lpm.tty_dev); uart_enable(bt_lpm.tty_dev); } } else { if (host_wake_uart_enabled) { WARN_ON(!bt_lpm.tty_dev); uart_disable(bt_lpm.tty_dev); } /* * Take a timed wakelock, so that upper layers can take it. * The chipset deasserts the hostwake lock, when there is no * more data to send. */ wake_lock_timeout(&bt_lpm.wake_lock, HZ/2); } host_wake_uart_enabled = host_wake; }
void measure_rpm() { while(uart_tx_active == 1){} // wait for pending uart transmission to finish uart_disable(); measure_channel_rpm(0); // channel 1 measure_channel_rpm(1); // channel 2 measure_channel_rpm(2); // channel 3 //measure_channel_rpm(3); // channel 4 uart_enable(); }
void uart_set_baudrate(unsigned long baud) { uart_disable(); // Set the baud rate // BRG = freq/( baud * 16) U0BR = FREQ/((unsigned long)baud * 16UL); baudrate = baud; uart_enable(); }
void uart_set_bits(const char *value) { uart_disable(); if(strcmp(value, UART_BIT7) == 0) { U0CTL0 &= ~UART_TWO_STOP; } else if(strcmp(value, UART_BIT8) == 0) { U0CTL0 |= UART_TWO_STOP; } uart_enable(); }
int main(void) { pin_init(); uart_init(); uart_set_rx_callback(&my_rx_callback); uart_enable(); sei(); while(1) { uart_send_data(ch_cycles, 4*CH_NUM); uart_send_data(ch_rpm, 2*CH_NUM); measure_rpm(); _delay_ms(1000); } }
/* * early system init of muxing and clocks. */ void s_init(void) { #ifdef CONFIG_SPL_BUILD /* * Save the boot parameters passed from romcode. * We cannot delay the saving further than this, * to prevent overwrites. */ #ifdef CONFIG_SPL_BUILD save_omap_boot_params(); #endif /* WDT1 is already running when the bootloader gets control * Disable it to avoid "random" resets */ wdt_disable(); /* Enable timer */ timer_init(); /* Setup the PLLs and the clocks for the peripherals */ pll_init(); /* Enable RTC32K clock */ rtc32k_enable(); /* Set UART pins */ enable_uart0_pin_mux(); /* Set MMC pins */ enable_mmc1_pin_mux(); /* Set Ethernet pins */ enable_enet_pin_mux(); /* Enable UART */ uart_enable(); gd = &gdata; preloader_console_init(); config_dmm(&evm_lisa_map_regs); config_ddr(0, 0, &evm_ddr2_data, &evm_ddr2_cctrl_data, &evm_ddr2_emif0_regs, 0); config_ddr(0, 0, &evm_ddr2_data, &evm_ddr2_cctrl_data, &evm_ddr2_emif1_regs, 1); #endif }
int glue_set_line_coding_cb(uint32_t baud, uint8_t databits, enum usb_cdc_line_coding_bParityType cdc_parity, enum usb_cdc_line_coding_bCharFormat cdc_stopbits) { enum uart_parity parity; uint8_t uart_stopbits; if (databits < 5 || databits > 8) return 0; switch (cdc_parity) { case USB_CDC_NO_PARITY: parity = UART_PARITY_NONE; break; case USB_CDC_ODD_PARITY: parity = UART_PARITY_ODD; break; case USB_CDC_EVEN_PARITY: parity = UART_PARITY_EVEN; break; default: return 0; } switch (cdc_stopbits) { case USB_CDC_1_STOP_BITS: uart_stopbits = 1; break; case USB_CDC_2_STOP_BITS: uart_stopbits = 2; break; default: return 0; } /* Disable the UART while we mess with its settings */ uart_disable(UART1); /* Set communication parameters */ uart_set_baudrate(UART1, baud); uart_set_databits(UART1, databits); uart_set_parity(UART1, parity); uart_set_stopbits(UART1, uart_stopbits); /* Back to work. */ uart_enable(UART1); return 1; }
void uart_set_parity(const char *value) { uart_disable(); if(strcmp(value, UART_EVEN) == 0) { U0CTL0 |= UART_PARITY_EN; U0CTL0 &= ~UART_PARITY_ODD; } else if(strcmp(value, UART_ODD) == 0) { U0CTL0 |= UART_PARITY_EN | UART_PARITY_ODD; } else if(strcmp(value, UART_NONE) == 0) { U0CTL0 &= ~UART_PARITY_EN; } uart_enable(); }
void sam_debug_early_init(void) { pmc_enable_periph_clk(ID_UART); pmc_enable_periph_clk(ID_PIOA); pio_set_peripheral(PIOA, PIO_PERIPH_A, PIO_PA8); pio_set_peripheral(PIOA, PIO_PERIPH_A, PIO_PA9); sam_uart_opt_t opt; opt.ul_mck = 84000000; opt.ul_baudrate = 115200; opt.ul_mode = UART_MR_PAR_NO | UART_MR_CHMODE_NORMAL; NVIC_DisableIRQ(UART_IRQn); uart_init(UART, &opt); uart_enable(UART); }
//------------------------------------------------------------------------------ // // ComSlip_Init // //------------------------------------------------------------------------------ void ComSlip_Init() { // init to idle state, no rx-buffer avaliable ComSlip.RxState = SLIPDEC_IDLE_STATE; ComSlip.RxIndex = 0; ComSlip.RxBuffer = 0; ComSlip.RxBufferSize = 0; // Init Uart Interfaces //LDDUsart_Init(); // Register ComSlip_ProcessRxByte at LDDUART //LDDUsart_RegisterClient(ComSlip_ProcessRxByte); //lora = uart_init(1, 115200, 4); lora = uart_init(0, 115200, 0); uart_enable(lora); uart_set_rx_interrupt_callback(lora, &ComSlip_ProcessRxByte); uart_rx_interrupt_enable(lora); }
static void set_wake_locked(int wake) { bt_lpm.wake = wake; if (!wake) wake_unlock(&bt_lpm.wake_lock); if (!wake_uart_enabled && wake) { WARN_ON(!bt_lpm.tty_dev); uart_enable(bt_lpm.tty_dev); } gpio_set_value(bt_lpm.gpio_wake, wake); if (wake_uart_enabled && !wake) { WARN_ON(!bt_lpm.tty_dev); uart_disable(bt_lpm.tty_dev); } wake_uart_enabled = wake; }
void platform_drivers_setup() { // Set base address and AHB bit for all GPIO ports gpio_enable(GPIO_A); gpio_enable(GPIO_B); gpio_enable(GPIO_C); gpio_enable(GPIO_D); // Enable the AFIO rcc_apb_enable(RCC_APB_BUS_AFIO, RCC_APB_BIT_AFIO); // Start the TIM3 at ~32kHz timer_enable(TIM_3); timer_select_internal_clock(TIM_3, (rcc_sysclk_get_clock_frequency( RCC_SYSCLK_CLOCK_PCLK1_TIM) / 32768) - 1); timer_start(TIM_3, 0xFFFF, NULL, NULL); // Enable the print uart gpio_set_uart_tx(GPIO_A, GPIO_PIN_9); gpio_set_uart_rx(GPIO_A, GPIO_PIN_10); uart_enable(UART_1, PLATFORM_UART_PRINT_BAUDRATE); // Configure the DMA for the SPIs dma_enable(DMA_1_CH4); dma_enable(DMA_1_CH5); // Configure the SPI 2 gpio_set_spi_clk(GPIO_B, GPIO_PIN_13); gpio_set_spi_miso(GPIO_B, GPIO_PIN_14); gpio_set_spi_mosi(GPIO_B, GPIO_PIN_15); spi_set_dma(SPI_2, DMA_1_CH4, DMA_1_CH5); spi_enable(SPI_2, 4000000, SPI_CLOCK_MODE_IDLE_LOW_RISING); // Configure the I2C 1 gpio_set_i2c_scl(GPIO_B, GPIO_PIN_6); gpio_set_i2c_sda(GPIO_B, GPIO_PIN_7); i2c_enable(I2C_1, I2C_CLOCK_MODE_FAST); // Force inclusion of EXTI exti_set_handler(EXTI_LINE_Px0, NULL, NULL); }
void traceswo_init(void) { periph_clock_enable(RCC_GPIOD); periph_clock_enable(TRACEUART_CLK); __asm__("nop"); __asm__("nop"); __asm__("nop"); gpio_mode_setup(SWO_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, SWO_PIN); gpio_set_af(SWO_PORT, 1, SWO_PIN); /* U2RX */ uart_disable(TRACEUART); /* Setup UART parameters. */ uart_clock_from_sysclk(TRACEUART); uart_set_baudrate(TRACEUART, 800000); uart_set_databits(TRACEUART, 8); uart_set_stopbits(TRACEUART, 1); uart_set_parity(TRACEUART, UART_PARITY_NONE); // Enable FIFO uart_enable_fifo(TRACEUART); // Set FIFO interrupt trigger levels to 4/8 full for RX buffer and // 7/8 empty (1/8 full) for TX buffer uart_set_fifo_trigger_levels(TRACEUART, UART_FIFO_RX_TRIG_1_2, UART_FIFO_TX_TRIG_7_8); uart_clear_interrupt_flag(TRACEUART, UART_INT_RX | UART_INT_RT); /* Enable interrupts */ uart_enable_interrupts(TRACEUART, UART_INT_RX | UART_INT_RT); /* Finally enable the USART. */ uart_enable(TRACEUART); nvic_set_priority(TRACEUART_IRQ, 0); nvic_enable_irq(TRACEUART_IRQ); /* Un-stall USB endpoint */ usbd_ep_stall_set(usbdev, 0x85, 0); gpio_mode_setup(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO3); }
int main() { // Initialize the platform platform_init(); /* compatibility with HiKoB */ if (uart_external == NULL) uart_external = uart_print; else uart_enable(uart_external, 500000); // Start the soft timer soft_timer_init(); // Start the serial lib iotlab_serial_start(500000); // Start the application libs cn_control_start(); cn_consumption_start(); cn_radio_start(); /* map i2c start stop to dc start/stop */ cn_control_config(cn_i2c_stop, cn_i2c_start); cn_autotest_start(); cn_logger_reset(); //set the open node power to off and charge the battery fiteco_lib_gwt_opennode_power_select(FITECO_GWT_OPENNODE_POWER__OFF); fiteco_lib_gwt_battery_charge_enable(); //initialize the led, red off, green on leds_off(LEDS_MASK); leds_on(GREEN_LED); // Run platform_run(); return 0; }
void initUART(void) { // Stop watchdog timer //GPRS initiering P3SEL |= BIT4+BIT5; // Chosen bit 5.6 and 5.7 @port 56 and 57 UCA0CTL1|= UCSWRST; //Have to set ths flag to be able to initiate&modify other registers UCSWRST=1 NOW. UCA0CTL0 &= ~UCSYNC; // 0 UART mode selected contrary to SPI mode UCA0CTL1 |=UCSSEL1; //CLK=SMCK chosen //UCA0BR0 = 0x41; //9600 baudrate //UCA0BR1 = 0x3; UCA0BR0 = 0xA0; //19200 baudrate for GPRS Sim900 setup UCA0BR1 = 0x01; // UCA1STAT|=UCLISTEN; //Internal feedback TX to RX UCA0MCTL|=UCBRS_6; //Set modulation control register to 0x04 and =8mhz 9600bds UCA0CTL1 &= ~UCSWRST; uart_enable(); }
static void uart_setup(void) { /* Enable GPIOA in run mode. */ periph_clock_enable(RCC_GPIOA); /* Mux PA0 and PA1 to UART0 (alternate function 1) */ gpio_set_af(GPIOA, 1, GPIO0 | GPIO1); /* Enable the UART clock */ periph_clock_enable(RCC_UART0); /* We need a brief delay before we can access UART config registers */ __asm__("nop"); /* Disable the UART while we mess with its setings */ uart_disable(UART0); /* Configure the UART clock source as precision internal oscillator */ uart_clock_from_piosc(UART0); /* Set communication parameters */ uart_set_baudrate(UART0, 921600); uart_set_databits(UART0, 8); uart_set_parity(UART0, UART_PARITY_NONE); uart_set_stopbits(UART0, 1); /* Now that we're done messing with the settings, enable the UART */ uart_enable(UART0); }
int main(void) { int i, j, k, l; unsigned button[3]; unsigned steps[3]; unsigned hz; /*------------------------------------------------------------- * First things first: Start the watchdog */ fido_setup(0x1000); /*------------------------------------------------------------- * Setup GPIO */ LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 6); // GPIO LPC_SYSCON->PRESETCTRL &= ~(1 << 10); // GPIO reset LPC_SYSCON->PRESETCTRL |= (1 << 10); LPC_IOCON->PIO0_0 = 0 | (1 << 3) // Pull down | (1 << 5) // Hysteresis ; LPC_IOCON->PIO0_1 = 0 | (2 << 3) // Pull up | (1 << 5) // Hysteresis ; LPC_IOCON->PIO0_2 = 0 | (2 << 3) // Pull up | (1 << 5) // Hysteresis ; LPC_IOCON->PIO0_3 = 0 | (2 << 3) // Pull up | (1 << 5) // Hysteresis ; LPC_IOCON->PIO0_5 = 0 | (2 << 3) // Pull up | (1 << 5) // Hysteresis ; /*------------------------------------------------------------- * Provide a chance to enter the boot-loader */ check_bootloader(); /*------------------------------------------------------------- * Enable UART for startup-debugging */ uart0Init(115200); uart_enable(); /*------------------------------------------------------------- * Start timer */ mrtInit(__SYSTEM_CLOCK/1000); /*------------------------------------------------------------- * Enable reset pin */ LPC_SWM->PINENABLE0 = ~(1 << 6); // PIO0_5 RESET_EN /*------------------------------------------------------------- * Hello World */ welcome(); /*------------------------------------------------------------- * Detect pin-configuration by counting edges on the two possible * possible clock inputs. * * If neither is active the watch-dog will trigger. */ do { /* Measure input frequency on PIO0_1 and PIO0_2 */ for (i = 1; i < 3; i++) { sct_setup(i); k = LPC_SCT->COUNT_U; mrtDelay(100); l = LPC_SCT->COUNT_U; hz = 10 * (l-k); printf("Rate PIO0_%d = %u\r\n", i, hz); if (hz > 1000) break; } } while (hz < 1000); /*------------------------------------------------------------- * Configure counter */ mrtDelay(100); printf("Using PIO0_%d\r\n", i); mrtDelay(100); uart_disable(); button[0] = 1<<(3-i); steps[0] = 1; button[1] = 1<<3; steps[1] = 60; button[2] = 1<<5; steps[2] = 3600; if (i == 1) { LPC_SWM->PINENABLE0 &= ~(1 << 7); // Enable CLKIN LPC_SYSCON->MAINCLKSEL = 0x1; // PLL input LPC_SYSCON->MAINCLKUEN = 0x0; LPC_SYSCON->MAINCLKUEN = 0x1; LPC_SYSCON->SYSPLLCLKSEL = 0x3; // CLKIN LPC_SYSCON->SYSPLLCLKUEN = 0x0; LPC_SYSCON->SYSPLLCLKUEN = 0x1; LPC_SYSCON->SYSAHBCLKDIV = 1; sct_setup(0xff); mrtInit(FREQ/1000); /* Calibrated to look like 0x00 at 115200 bps */ pulse_lo = 29; pulse_hi = 10; } else { sct_setup(2); } sct_output(4); /*------------------------------------------------------------- * Until the clock is set, have it run 11 times too fast */ while (1) { fido_pat(); if (!(LPC_GPIO_PORT->PIN0 & button[0])) break; if (!(LPC_GPIO_PORT->PIN0 & button[1])) break; if (!(LPC_GPIO_PORT->PIN0 & button[2])) break; mrtDelay(100); run_pulse(); } LPC_SWM->PINENABLE0 |= (1 << 6); // Disable RESET j = 0; while(1) { if (j == 0 && LPC_SCT->COUNT_U < 10000) { fido_pat(); j = 1; } if (j == 1 && LPC_SCT->COUNT_U > 10000) { j = 0; } for (i = 0; i < 3; i++) { if (LPC_GPIO_PORT->PIN0 & button[i]) continue; fido_pat(); for(k = 0; k < steps[i]; k++) run_pulse(); if (i > 0) { /* * Min/Hour button release * If you hold them for 10+ seconds * The watch-dog bites */ for(k = 0; k < 1000; k++) { if (LPC_GPIO_PORT->PIN0 & button[i]) continue; k = 0; } continue; } /* Check if the Sec button is held for >1s */ mrt_counter = 0; for(k = 0; k < 1000; k++) { if (LPC_GPIO_PORT->PIN0 & button[i]) break; if (mrt_counter > 1000) break; k = 0; } if (k == 1000) continue; /* Stop counter */ sct_stop(); /* * Restart counter on button release * or sync input */ for(k = 0; k < 1000; k++) { if (LPC_GPIO_PORT->PIN0 & button[i]) break; l = LPC_GPIO_PORT->PIN0 & (1<<0); if (l) k = 0; } l = (1 << 0) | button[i]; while (!(LPC_GPIO_PORT->PIN0 & l)) continue; /* * Calibrated for falling edge = PPI rising edge * PPSO comes 164ns after PPS1 */ LPC_SCT->COUNT_U = FREQ - 366; LPC_SCT->CTRL_L &= ~(1 << 2); // Start for(k = 0; k < 1000; k++) { if (LPC_GPIO_PORT->PIN0 & button[i]) continue; k = 0; } } } }
void msg_enableRx(void) { uart_enable(); rf_setMode(RF_MODE_RECEIVING); }
/* Start the GPS listener. * Once started, it will update the appropriate fields in the Data * struct as GPS data is received. */ void gps_init(void){ uart_enable(GPS_UART, GPS_BAUD, 1, 0); }