nRF Connect SDK Bare Metal API 2.0.99
Loading...
Searching...
No Matches
bm_lpuarte.h
1/*
2 * Copyright (c) 2025 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
13#ifndef LPUARTE_H__
14#define LPUARTE_H__
15
16#include <stdint.h>
17#include <zephyr/sys/util.h>
18#include <nrfx_gpiote.h>
19#include <nrfx_uarte.h>
20#include <bm/bm_timer.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26/* States. */
28 /* RX is disabled. */
30 /* RX is in low power, idle state with pin detection armed. */
32 /* RX request is pending, receiver is in preparation. */
34 /* RX is in active state, receiver is running. */
36 /* RX is transitioning to from active idle state. */
38 /* RX is transitioning to off state. */
40};
41
42/* Low power uart structure. */
43struct bm_lpuarte {
44 /* Physical UART device instance */
45 nrfx_uarte_t *uarte_inst;
46 /* Request pin. */
47 nrfx_gpiote_pin_t req_pin;
48 /* Response pin. */
49 nrfx_gpiote_pin_t rdy_pin;
50 /* GPIOTE channel used by rdy pin. */
51 uint8_t rdy_ch;
52 /* Timer used for TX timeout. */
54 /* Current TX buffer. */
55 const uint8_t *tx_buf;
56 /* Length of TX data. */
57 size_t tx_len;
58 /* Set to true if physical transfer is started. */
60 /* Application callback. */
61 nrfx_uarte_event_handler_t callback;
62 /* RX state */
64};
65
66/* Configuration structured. */
68 /* Uarte instance. */
69 nrfx_uarte_t *uarte_inst;
70 /* Uarte instance configuration. */
71 nrfx_uarte_config_t uarte_cfg;
72 /* Request pin number. */
73 nrfx_gpiote_pin_t req_pin;
74 /* Ready pin number. */
75 nrfx_gpiote_pin_t rdy_pin;
76};
77
87int bm_lpuarte_init(struct bm_lpuarte *lpu, struct bm_lpuarte_config *lpu_cfg,
88 nrfx_uarte_event_handler_t event_handler);
89
95void bm_lpuarte_uninit(struct bm_lpuarte *lpu);
96
110int bm_lpuarte_tx(struct bm_lpuarte *lpu, const uint8_t *data, size_t length, int32_t timeout);
111
121
132int bm_lpuarte_tx_abort(struct bm_lpuarte *lpu, bool sync);
133
151
171int bm_lpuarte_rx_buffer_set(struct bm_lpuarte *lpu, uint8_t *data, size_t length);
172
196int bm_lpuarte_rx_abort(struct bm_lpuarte *lpu, bool sync);
197
198#ifdef __cplusplus
199}
200#endif
201
202#endif /* LPUARTE_H__ */
203
int bm_lpuarte_init(struct bm_lpuarte *lpu, struct bm_lpuarte_config *lpu_cfg, nrfx_uarte_event_handler_t event_handler)
Initialize LPUARTE driver instance.
int bm_lpuarte_tx_abort(struct bm_lpuarte *lpu, bool sync)
Abort transmission.
int bm_lpuarte_rx_buffer_set(struct bm_lpuarte *lpu, uint8_t *data, size_t length)
Provide reception buffer.
int bm_lpuarte_rx_abort(struct bm_lpuarte *lpu, bool sync)
Abort any ongoing reception.
int bm_lpuarte_tx(struct bm_lpuarte *lpu, const uint8_t *data, size_t length, int32_t timeout)
Send data over LPUARTE.
void bm_lpuarte_uninit(struct bm_lpuarte *lpu)
Deinitialize LPUARTE driver instance.
int bm_lpuarte_rx_enable(struct bm_lpuarte *lpu)
Enable the receiver.
bool bm_lpuarte_tx_in_progress(struct bm_lpuarte *lpu)
Check if TX is in progress.
bm_lpuarte_rx_state
Definition bm_lpuarte.h:27
@ RX_TO_OFF
Definition bm_lpuarte.h:39
@ RX_PREPARE
Definition bm_lpuarte.h:33
@ RX_OFF
Definition bm_lpuarte.h:29
@ RX_ACTIVE
Definition bm_lpuarte.h:35
@ RX_IDLE
Definition bm_lpuarte.h:31
@ RX_TO_IDLE
Definition bm_lpuarte.h:37
nrfx_gpiote_pin_t req_pin
Definition bm_lpuarte.h:73
nrfx_uarte_config_t uarte_cfg
Definition bm_lpuarte.h:71
nrfx_gpiote_pin_t rdy_pin
Definition bm_lpuarte.h:75
nrfx_uarte_t * uarte_inst
Definition bm_lpuarte.h:69
Definition bm_lpuarte.h:67
bool tx_active
Definition bm_lpuarte.h:59
struct bm_timer tx_timer
Definition bm_lpuarte.h:53
nrfx_uarte_event_handler_t callback
Definition bm_lpuarte.h:61
nrfx_uarte_t * uarte_inst
Definition bm_lpuarte.h:45
nrfx_gpiote_pin_t rdy_pin
Definition bm_lpuarte.h:49
const uint8_t * tx_buf
Definition bm_lpuarte.h:55
enum bm_lpuarte_rx_state rx_state
Definition bm_lpuarte.h:63
size_t tx_len
Definition bm_lpuarte.h:57
nrfx_gpiote_pin_t req_pin
Definition bm_lpuarte.h:47
uint8_t rdy_ch
Definition bm_lpuarte.h:51
Definition bm_lpuarte.h:43
Timer instance structure.
Definition bm_timer.h:71