xref: /btstack/platform/embedded/hal_uart_dma.h (revision 2fca4dad957cd7b88f4657ed51e89c12615dda72)
1 /*
2  * Copyright (C) 2014 BlueKitchen GmbH
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the copyright holders nor the names of
14  *    contributors may be used to endorse or promote products derived
15  *    from this software without specific prior written permission.
16  * 4. Any redistribution, use, or modification is done solely for
17  *    personal benefit and not for any commercial purpose or for
18  *    monetary gain.
19  *
20  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
24  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * Please inquire about commercial licensing options at
34  * [email protected]
35  *
36  */
37 
38 /*
39  *  hal_uart_dma.h
40  *
41  *  Hardware abstraction layer that provides
42  *  - block wise IRQ-driven read/write
43  *  - baud control
44  *  - wake-up on CTS pulse (BTSTACK_UART_SLEEP_RTS_HIGH_WAKE_ON_CTS_PULSE)
45  *
46  * If HAVE_HAL_UART_DMA_SLEEP_MODES is defined, different sleeps modes can be provided and used
47  *
48  */
49 
50 #ifndef HAL_UART_DMA_H
51 #define HAL_UART_DMA_H
52 
53 #include <stdint.h>
54 
55 #if defined __cplusplus
56 extern "C" {
57 #endif
58 
59 /**
60  * @brief Init and open device
61  */
62 void hal_uart_dma_init(void);
63 
64 /**
65  * @brief Set callback for block received - can be called from ISR context
66  * @param callback
67  */
68 void hal_uart_dma_set_block_received( void (*callback)(void));
69 
70 /**
71  * @brief Set callback for block sent - can be called from ISR context
72  * @param callback
73  */
74 void hal_uart_dma_set_block_sent( void (*callback)(void));
75 
76 /**
77  * @brief Set baud rate
78  * @note During baud change, TX line should stay high and no data should be received on RX accidentally
79  * @param baudrate
80  */
81 int  hal_uart_dma_set_baud(uint32_t baud);
82 
83 #ifdef HAVE_UART_DMA_SET_FLOWCONTROL
84 /**
85  * @brief Set flowcontrol
86  * @param flowcontrol enabled
87  */
88 int  hal_uart_dma_set_flowcontrol(int flowcontrol);
89 #endif
90 
91 /**
92  * @brief Send block. When done, callback set by hal_uart_set_block_sent must be called
93  * @param buffer
94  * @param lengh
95  */
96 void hal_uart_dma_send_block(const uint8_t *buffer, uint16_t length);
97 
98 /**
99  * @brief Receive block. When done, callback set by hal_uart_dma_set_block_received must be called
100  * @param buffer
101  * @param lengh
102  */
103 void hal_uart_dma_receive_block(uint8_t *buffer, uint16_t len);
104 
105 /**
106  * @brief Set or clear callback for CSR pulse - can be called from ISR context
107  * @param csr_irq_handler or NULL to disable IRQ handler
108  */
109 void hal_uart_dma_set_csr_irq_handler( void (*csr_irq_handler)(void));
110 
111 /**
112  * @brief Set sleep mode
113  * @param block_received callback
114  */
115 void hal_uart_dma_set_sleep(uint8_t sleep);
116 
117 #ifdef HAVE_HAL_UART_DMA_SLEEP_MODES
118 
119 /**
120  * @brief Set callback for block received - can be called from ISR context
121  * @returns list of supported sleep modes
122  */
123 int  hal_uart_dma_get_supported_sleep_modes(void);
124 
125 /**
126  * @brief Set sleep mode
127  * @param sleep_mode
128  */
129 void hal_uart_dma_set_sleep_mode(btstack_uart_sleep_mode_t sleep_mode);
130 
131 #endif
132 
133 #if defined __cplusplus
134 }
135 #endif
136 #endif // HAL_UART_DMA_H
137