WIFI_API_20150524e

Committer:
Marcomissyou
Date:
Tue Jun 09 06:04:13 2015 +0000
Revision:
0:a2de37bf5f3d
update to WIFI_API_20150524e

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Marcomissyou 0:a2de37bf5f3d 1 /* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
Marcomissyou 0:a2de37bf5f3d 2 *
Marcomissyou 0:a2de37bf5f3d 3 * The information contained herein is property of Nordic Semiconductor ASA.
Marcomissyou 0:a2de37bf5f3d 4 * Terms and conditions of usage are described in detail in NORDIC
Marcomissyou 0:a2de37bf5f3d 5 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
Marcomissyou 0:a2de37bf5f3d 6 *
Marcomissyou 0:a2de37bf5f3d 7 * Licensees are granted free, non-transferable use of the information. NO
Marcomissyou 0:a2de37bf5f3d 8 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
Marcomissyou 0:a2de37bf5f3d 9 * the file.
Marcomissyou 0:a2de37bf5f3d 10 *
Marcomissyou 0:a2de37bf5f3d 11 */
Marcomissyou 0:a2de37bf5f3d 12
Marcomissyou 0:a2de37bf5f3d 13 #include <stdint.h>
Marcomissyou 0:a2de37bf5f3d 14
Marcomissyou 0:a2de37bf5f3d 15 //#include "nrf.h" //command by Tsungta @12/12 when trying to porting on mbed online compilier
Marcomissyou 0:a2de37bf5f3d 16 #include "simple_uart.h"
Marcomissyou 0:a2de37bf5f3d 17 //#include "nrf_delay.h"
Marcomissyou 0:a2de37bf5f3d 18 #include "nrf_gpio.h"
Marcomissyou 0:a2de37bf5f3d 19
Marcomissyou 0:a2de37bf5f3d 20 extern uint8_t rx_isr;
Marcomissyou 0:a2de37bf5f3d 21 extern uint8_t hif;
Marcomissyou 0:a2de37bf5f3d 22 extern uint8_t udp_client_test;
Marcomissyou 0:a2de37bf5f3d 23 uint8_t simple_uart_get(void)
Marcomissyou 0:a2de37bf5f3d 24 {
Marcomissyou 0:a2de37bf5f3d 25 while (NRF_UART0->EVENTS_RXDRDY != 1 && rx_isr == 0 && hif == 0 && udp_client_test == 0)
Marcomissyou 0:a2de37bf5f3d 26 {
Marcomissyou 0:a2de37bf5f3d 27 // Wait for RXD data to be received
Marcomissyou 0:a2de37bf5f3d 28 }
Marcomissyou 0:a2de37bf5f3d 29
Marcomissyou 0:a2de37bf5f3d 30 NRF_UART0->EVENTS_RXDRDY = 0;
Marcomissyou 0:a2de37bf5f3d 31 return (uint8_t)NRF_UART0->RXD;
Marcomissyou 0:a2de37bf5f3d 32 }
Marcomissyou 0:a2de37bf5f3d 33
Marcomissyou 0:a2de37bf5f3d 34 //bool simple_uart_get_with_timeout(int32_t timeout_ms, uint8_t *rx_data)
Marcomissyou 0:a2de37bf5f3d 35 //{
Marcomissyou 0:a2de37bf5f3d 36 // bool ret = true;
Marcomissyou 0:a2de37bf5f3d 37 //
Marcomissyou 0:a2de37bf5f3d 38 // while (NRF_UART0->EVENTS_RXDRDY != 1)
Marcomissyou 0:a2de37bf5f3d 39 // {
Marcomissyou 0:a2de37bf5f3d 40 // if (timeout_ms-- >= 0)
Marcomissyou 0:a2de37bf5f3d 41 // {
Marcomissyou 0:a2de37bf5f3d 42 // // wait in 1ms chunk before checking for status
Marcomissyou 0:a2de37bf5f3d 43 // nrf_delay_us(1000);
Marcomissyou 0:a2de37bf5f3d 44 // }
Marcomissyou 0:a2de37bf5f3d 45 // else
Marcomissyou 0:a2de37bf5f3d 46 // {
Marcomissyou 0:a2de37bf5f3d 47 // ret = false;
Marcomissyou 0:a2de37bf5f3d 48 // break;
Marcomissyou 0:a2de37bf5f3d 49 // }
Marcomissyou 0:a2de37bf5f3d 50 // } // Wait for RXD data to be received
Marcomissyou 0:a2de37bf5f3d 51 //
Marcomissyou 0:a2de37bf5f3d 52 // if (timeout_ms >= 0)
Marcomissyou 0:a2de37bf5f3d 53 // {
Marcomissyou 0:a2de37bf5f3d 54 // // clear the event and set rx_data with received byte
Marcomissyou 0:a2de37bf5f3d 55 // NRF_UART0->EVENTS_RXDRDY = 0;
Marcomissyou 0:a2de37bf5f3d 56 // *rx_data = (uint8_t)NRF_UART0->RXD;
Marcomissyou 0:a2de37bf5f3d 57 // }
Marcomissyou 0:a2de37bf5f3d 58 //
Marcomissyou 0:a2de37bf5f3d 59 // return ret;
Marcomissyou 0:a2de37bf5f3d 60 //}
Marcomissyou 0:a2de37bf5f3d 61
Marcomissyou 0:a2de37bf5f3d 62 void simple_uart_put(uint8_t cr)
Marcomissyou 0:a2de37bf5f3d 63 {
Marcomissyou 0:a2de37bf5f3d 64 NRF_UART0->TXD = (uint8_t)cr;
Marcomissyou 0:a2de37bf5f3d 65
Marcomissyou 0:a2de37bf5f3d 66 while (NRF_UART0->EVENTS_TXDRDY!=1)
Marcomissyou 0:a2de37bf5f3d 67 {
Marcomissyou 0:a2de37bf5f3d 68 // Wait for TXD data to be sent
Marcomissyou 0:a2de37bf5f3d 69 }
Marcomissyou 0:a2de37bf5f3d 70
Marcomissyou 0:a2de37bf5f3d 71 NRF_UART0->EVENTS_TXDRDY=0;
Marcomissyou 0:a2de37bf5f3d 72 }
Marcomissyou 0:a2de37bf5f3d 73
Marcomissyou 0:a2de37bf5f3d 74 void simple_uart_putstring(const uint8_t *str)
Marcomissyou 0:a2de37bf5f3d 75 {
Marcomissyou 0:a2de37bf5f3d 76 uint_fast8_t i = 0;
Marcomissyou 0:a2de37bf5f3d 77 uint8_t ch = str[i++];
Marcomissyou 0:a2de37bf5f3d 78 while (ch != '\0')
Marcomissyou 0:a2de37bf5f3d 79 {
Marcomissyou 0:a2de37bf5f3d 80 simple_uart_put(ch);
Marcomissyou 0:a2de37bf5f3d 81 ch = str[i++];
Marcomissyou 0:a2de37bf5f3d 82 }
Marcomissyou 0:a2de37bf5f3d 83 }
Marcomissyou 0:a2de37bf5f3d 84
Marcomissyou 0:a2de37bf5f3d 85 void simple_uart_config( uint8_t rts_pin_number,
Marcomissyou 0:a2de37bf5f3d 86 uint8_t txd_pin_number,
Marcomissyou 0:a2de37bf5f3d 87 uint8_t cts_pin_number,
Marcomissyou 0:a2de37bf5f3d 88 uint8_t rxd_pin_number,
Marcomissyou 0:a2de37bf5f3d 89 bool hwfc)
Marcomissyou 0:a2de37bf5f3d 90 {
Marcomissyou 0:a2de37bf5f3d 91 nrf_gpio_cfg_output(txd_pin_number);
Marcomissyou 0:a2de37bf5f3d 92 nrf_gpio_cfg_input(rxd_pin_number, NRF_GPIO_PIN_NOPULL);
Marcomissyou 0:a2de37bf5f3d 93
Marcomissyou 0:a2de37bf5f3d 94 NRF_UART0->PSELTXD = txd_pin_number;
Marcomissyou 0:a2de37bf5f3d 95 NRF_UART0->PSELRXD = rxd_pin_number;
Marcomissyou 0:a2de37bf5f3d 96
Marcomissyou 0:a2de37bf5f3d 97 if (hwfc)
Marcomissyou 0:a2de37bf5f3d 98 {
Marcomissyou 0:a2de37bf5f3d 99 nrf_gpio_cfg_output(rts_pin_number);
Marcomissyou 0:a2de37bf5f3d 100 nrf_gpio_cfg_input(cts_pin_number, NRF_GPIO_PIN_NOPULL);
Marcomissyou 0:a2de37bf5f3d 101 NRF_UART0->PSELCTS = cts_pin_number;
Marcomissyou 0:a2de37bf5f3d 102 NRF_UART0->PSELRTS = rts_pin_number;
Marcomissyou 0:a2de37bf5f3d 103 NRF_UART0->CONFIG = (UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
Marcomissyou 0:a2de37bf5f3d 104 }
Marcomissyou 0:a2de37bf5f3d 105
Marcomissyou 0:a2de37bf5f3d 106 // NRF_UART0->BAUDRATE = (UART_BAUDRATE_BAUDRATE_Baud38400 << UART_BAUDRATE_BAUDRATE_Pos);
Marcomissyou 0:a2de37bf5f3d 107 NRF_UART0->BAUDRATE = (UART_BAUDRATE_BAUDRATE_Baud115200 << UART_BAUDRATE_BAUDRATE_Pos);
Marcomissyou 0:a2de37bf5f3d 108 NRF_UART0->ENABLE = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos);
Marcomissyou 0:a2de37bf5f3d 109 NRF_UART0->TASKS_STARTTX = 1;
Marcomissyou 0:a2de37bf5f3d 110 NRF_UART0->TASKS_STARTRX = 1;
Marcomissyou 0:a2de37bf5f3d 111 NRF_UART0->EVENTS_RXDRDY = 0;
Marcomissyou 0:a2de37bf5f3d 112 }