WIFI_API_20150524e
Diff: WIFI_Driver/nordic/simple_uart.c
- Revision:
- 0:a2de37bf5f3d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WIFI_Driver/nordic/simple_uart.c Tue Jun 09 06:04:13 2015 +0000 @@ -0,0 +1,112 @@ +/* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved. + * + * The information contained herein is property of Nordic Semiconductor ASA. + * Terms and conditions of usage are described in detail in NORDIC + * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. + * + * Licensees are granted free, non-transferable use of the information. NO + * WARRANTY of ANY KIND is provided. This heading must NOT be removed from + * the file. + * + */ + +#include <stdint.h> + +//#include "nrf.h" //command by Tsungta @12/12 when trying to porting on mbed online compilier +#include "simple_uart.h" +//#include "nrf_delay.h" +#include "nrf_gpio.h" + +extern uint8_t rx_isr; +extern uint8_t hif; +extern uint8_t udp_client_test; +uint8_t simple_uart_get(void) +{ + while (NRF_UART0->EVENTS_RXDRDY != 1 && rx_isr == 0 && hif == 0 && udp_client_test == 0) + { + // Wait for RXD data to be received + } + + NRF_UART0->EVENTS_RXDRDY = 0; + return (uint8_t)NRF_UART0->RXD; +} + +//bool simple_uart_get_with_timeout(int32_t timeout_ms, uint8_t *rx_data) +//{ +// bool ret = true; +// +// while (NRF_UART0->EVENTS_RXDRDY != 1) +// { +// if (timeout_ms-- >= 0) +// { +// // wait in 1ms chunk before checking for status +// nrf_delay_us(1000); +// } +// else +// { +// ret = false; +// break; +// } +// } // Wait for RXD data to be received +// +// if (timeout_ms >= 0) +// { +// // clear the event and set rx_data with received byte +// NRF_UART0->EVENTS_RXDRDY = 0; +// *rx_data = (uint8_t)NRF_UART0->RXD; +// } +// +// return ret; +//} + +void simple_uart_put(uint8_t cr) +{ + NRF_UART0->TXD = (uint8_t)cr; + + while (NRF_UART0->EVENTS_TXDRDY!=1) + { + // Wait for TXD data to be sent + } + + NRF_UART0->EVENTS_TXDRDY=0; +} + +void simple_uart_putstring(const uint8_t *str) +{ + uint_fast8_t i = 0; + uint8_t ch = str[i++]; + while (ch != '\0') + { + simple_uart_put(ch); + ch = str[i++]; + } +} + +void simple_uart_config( uint8_t rts_pin_number, + uint8_t txd_pin_number, + uint8_t cts_pin_number, + uint8_t rxd_pin_number, + bool hwfc) +{ + nrf_gpio_cfg_output(txd_pin_number); + nrf_gpio_cfg_input(rxd_pin_number, NRF_GPIO_PIN_NOPULL); + + NRF_UART0->PSELTXD = txd_pin_number; + NRF_UART0->PSELRXD = rxd_pin_number; + + if (hwfc) + { + nrf_gpio_cfg_output(rts_pin_number); + nrf_gpio_cfg_input(cts_pin_number, NRF_GPIO_PIN_NOPULL); + NRF_UART0->PSELCTS = cts_pin_number; + NRF_UART0->PSELRTS = rts_pin_number; + NRF_UART0->CONFIG = (UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos); + } + +// NRF_UART0->BAUDRATE = (UART_BAUDRATE_BAUDRATE_Baud38400 << UART_BAUDRATE_BAUDRATE_Pos); + NRF_UART0->BAUDRATE = (UART_BAUDRATE_BAUDRATE_Baud115200 << UART_BAUDRATE_BAUDRATE_Pos); + NRF_UART0->ENABLE = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos); + NRF_UART0->TASKS_STARTTX = 1; + NRF_UART0->TASKS_STARTRX = 1; + NRF_UART0->EVENTS_RXDRDY = 0; +}