nRF51 SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
main.c

Stand-alone DTM application for UART interface. More...

Macros

#define UART_TX_PIN   1
 
#define UART_RX_PIN   3
 
#define BITRATE   UART_BAUDRATE_BAUDRATE_Baud19200
 
#define MAX_ITERATIONS_NEEDED_FOR_NEXT_BYTE   21
 

Enumerations

enum  nrf_gpio_pin_pull_t {
  NRF_GPIO_PIN_NOPULL = GPIO_PIN_CNF_PULL_Disabled,
  NRF_GPIO_PIN_PULLDOWN = GPIO_PIN_CNF_PULL_Pulldown,
  NRF_GPIO_PIN_PULLUP = GPIO_PIN_CNF_PULL_Pullup,
  NRF_GPIO_PIN_NOPULL = GPIO_PIN_CNF_PULL_Disabled,
  NRF_GPIO_PIN_PULLDOWN = GPIO_PIN_CNF_PULL_Pulldown,
  NRF_GPIO_PIN_PULLUP = GPIO_PIN_CNF_PULL_Pullup
}
 Enumerator used for selecting the pin to be pulled down or up at the time of pin configuration. More...
 

Functions

static __INLINE void nrf_gpio_cfg_output (uint32_t pin_number)
 Function for configuration of pin to use for UART TX. More...
 
static __INLINE void nrf_gpio_cfg_input (uint32_t pin_number, nrf_gpio_pin_pull_t pull_config)
 Function for configuration of pin to use for UART RX. More...
 
static void uart_init (void)
 Function for UART initialization.
 
static uint32_t dtm_cmd_put (uint16_t command)
 Function for splitting UART command bit fields into separate command parameters for the DTM library. More...
 
int main (void)
 Function for application main entry. More...
 

Detailed Description

Macro Definition Documentation

#define UART_TX_PIN   1

Pin used for UART Transmit.

#define UART_RX_PIN   3

Pin used for UART Receive.

#define BITRATE   UART_BAUDRATE_BAUDRATE_Baud19200

Serial bitrate on the UART

#define MAX_ITERATIONS_NEEDED_FOR_NEXT_BYTE   21

Maximum iterations needed in the main loop between stop bit 1st byte and start bit 2nd byte. DTM standard allows 5000us delay between stop bit 1st byte and start bit 2nd byte. As the time is only known when a byte is received, then the time between between stop bit 1st byte and stop bit 2nd byte becomes: 5000us + transmission time of 2nd byte.

Byte transmission time is (Baud rate of 19200): 10bits * 1/19200 = approx. 520 us/byte (8 data bits + start & stop bit).

Loop time on polling UART register for received byte is defined in ble_dtm.c as: UART_POLL_CYCLE = 260 us

The max time between two bytes thus becomes (loop time: 260us / iteration): (5000us + 520us) / 260us / iteration = 21.2 iterations.

This is rounded down to 21.

Note
If UART bit rate is changed, this value should be recalculated as well.

Enumeration Type Documentation

Enumerator
NRF_GPIO_PIN_NOPULL 

Pin pullup resistor disabled.

NRF_GPIO_PIN_PULLDOWN 

Pin pulldown resistor enabled.

NRF_GPIO_PIN_PULLUP 

Pin pullup resistor enabled.

NRF_GPIO_PIN_NOPULL 

Pin pullup resistor disabled.

NRF_GPIO_PIN_PULLDOWN 

Pin pulldown resistor enabled.

NRF_GPIO_PIN_PULLUP 

Pin pullup resistor enabled.

Function Documentation

static __INLINE void nrf_gpio_cfg_output ( uint32_t  pin_number)
static
Parameters
[in]pin_numberThe pin to use as TX.
static __INLINE void nrf_gpio_cfg_input ( uint32_t  pin_number,
nrf_gpio_pin_pull_t  pull_config 
)
static
Parameters
[in]pin_numberThe pin to use as RX.
[in]pull_configConfiguration of pull resistor.
static uint32_t dtm_cmd_put ( uint16_t  command)
static
Parameters
[in]commandThe packed UART command.
Returns
result status from dtmlib.
int main ( void  )

This function serves as an adaptation layer between a 2-wire UART interface and the dtmlib. After initialization, DTM commands submitted through the UART are forwarded to dtmlib and events (i.e. results from the command) is reported back through the UART.