xref: /btstack/platform/embedded/hal_uart_dma.h (revision 2fca4dad957cd7b88f4657ed51e89c12615dda72)
1a705b1a2SMatthias Ringwald /*
2a705b1a2SMatthias Ringwald  * Copyright (C) 2014 BlueKitchen GmbH
3a705b1a2SMatthias Ringwald  *
4a705b1a2SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
5a705b1a2SMatthias Ringwald  * modification, are permitted provided that the following conditions
6a705b1a2SMatthias Ringwald  * are met:
7a705b1a2SMatthias Ringwald  *
8a705b1a2SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
9a705b1a2SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
10a705b1a2SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11a705b1a2SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
12a705b1a2SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
13a705b1a2SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
14a705b1a2SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
15a705b1a2SMatthias Ringwald  *    from this software without specific prior written permission.
16a705b1a2SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
17a705b1a2SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
18a705b1a2SMatthias Ringwald  *    monetary gain.
19a705b1a2SMatthias Ringwald  *
20a705b1a2SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21a705b1a2SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22a705b1a2SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23*2fca4dadSMilanka Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
24*2fca4dadSMilanka Ringwald  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25a705b1a2SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26a705b1a2SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27a705b1a2SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28a705b1a2SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29a705b1a2SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30a705b1a2SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31a705b1a2SMatthias Ringwald  * SUCH DAMAGE.
32a705b1a2SMatthias Ringwald  *
33a705b1a2SMatthias Ringwald  * Please inquire about commercial licensing options at
34a705b1a2SMatthias Ringwald  * [email protected]
35a705b1a2SMatthias Ringwald  *
36a705b1a2SMatthias Ringwald  */
37a705b1a2SMatthias Ringwald 
38a705b1a2SMatthias Ringwald /*
39a705b1a2SMatthias Ringwald  *  hal_uart_dma.h
40a705b1a2SMatthias Ringwald  *
41a705b1a2SMatthias Ringwald  *  Hardware abstraction layer that provides
42a705b1a2SMatthias Ringwald  *  - block wise IRQ-driven read/write
430489d9baSMatthias Ringwald  *  - baud control
440489d9baSMatthias Ringwald  *  - wake-up on CTS pulse (BTSTACK_UART_SLEEP_RTS_HIGH_WAKE_ON_CTS_PULSE)
450489d9baSMatthias Ringwald  *
460489d9baSMatthias Ringwald  * If HAVE_HAL_UART_DMA_SLEEP_MODES is defined, different sleeps modes can be provided and used
47a705b1a2SMatthias Ringwald  *
48a705b1a2SMatthias Ringwald  */
49a705b1a2SMatthias Ringwald 
5080e33422SMatthias Ringwald #ifndef HAL_UART_DMA_H
5180e33422SMatthias Ringwald #define HAL_UART_DMA_H
52a705b1a2SMatthias Ringwald 
53a705b1a2SMatthias Ringwald #include <stdint.h>
54a705b1a2SMatthias Ringwald 
55a705b1a2SMatthias Ringwald #if defined __cplusplus
56a705b1a2SMatthias Ringwald extern "C" {
57a705b1a2SMatthias Ringwald #endif
58a705b1a2SMatthias Ringwald 
590489d9baSMatthias Ringwald /**
600489d9baSMatthias Ringwald  * @brief Init and open device
610489d9baSMatthias Ringwald  */
62a705b1a2SMatthias Ringwald void hal_uart_dma_init(void);
630489d9baSMatthias Ringwald 
640489d9baSMatthias Ringwald /**
650489d9baSMatthias Ringwald  * @brief Set callback for block received - can be called from ISR context
660489d9baSMatthias Ringwald  * @param callback
670489d9baSMatthias Ringwald  */
680489d9baSMatthias Ringwald void hal_uart_dma_set_block_received( void (*callback)(void));
690489d9baSMatthias Ringwald 
700489d9baSMatthias Ringwald /**
710489d9baSMatthias Ringwald  * @brief Set callback for block sent - can be called from ISR context
720489d9baSMatthias Ringwald  * @param callback
730489d9baSMatthias Ringwald  */
740489d9baSMatthias Ringwald void hal_uart_dma_set_block_sent( void (*callback)(void));
750489d9baSMatthias Ringwald 
760489d9baSMatthias Ringwald /**
770489d9baSMatthias Ringwald  * @brief Set baud rate
780489d9baSMatthias Ringwald  * @note During baud change, TX line should stay high and no data should be received on RX accidentally
79f71711bbSMatthias Ringwald  * @param baudrate
800489d9baSMatthias Ringwald  */
81a705b1a2SMatthias Ringwald int  hal_uart_dma_set_baud(uint32_t baud);
820489d9baSMatthias Ringwald 
83f71711bbSMatthias Ringwald #ifdef HAVE_UART_DMA_SET_FLOWCONTROL
84f71711bbSMatthias Ringwald /**
85f71711bbSMatthias Ringwald  * @brief Set flowcontrol
86f71711bbSMatthias Ringwald  * @param flowcontrol enabled
87f71711bbSMatthias Ringwald  */
88346b607cSMatthias Ringwald int  hal_uart_dma_set_flowcontrol(int flowcontrol);
89f71711bbSMatthias Ringwald #endif
90f71711bbSMatthias Ringwald 
910489d9baSMatthias Ringwald /**
920489d9baSMatthias Ringwald  * @brief Send block. When done, callback set by hal_uart_set_block_sent must be called
930489d9baSMatthias Ringwald  * @param buffer
940489d9baSMatthias Ringwald  * @param lengh
950489d9baSMatthias Ringwald  */
96a705b1a2SMatthias Ringwald void hal_uart_dma_send_block(const uint8_t *buffer, uint16_t length);
970489d9baSMatthias Ringwald 
980489d9baSMatthias Ringwald /**
990489d9baSMatthias Ringwald  * @brief Receive block. When done, callback set by hal_uart_dma_set_block_received must be called
1000489d9baSMatthias Ringwald  * @param buffer
1010489d9baSMatthias Ringwald  * @param lengh
1020489d9baSMatthias Ringwald  */
103a705b1a2SMatthias Ringwald void hal_uart_dma_receive_block(uint8_t *buffer, uint16_t len);
1040489d9baSMatthias Ringwald 
1050489d9baSMatthias Ringwald /**
1060489d9baSMatthias Ringwald  * @brief Set or clear callback for CSR pulse - can be called from ISR context
1070489d9baSMatthias Ringwald  * @param csr_irq_handler or NULL to disable IRQ handler
1080489d9baSMatthias Ringwald  */
1090489d9baSMatthias Ringwald void hal_uart_dma_set_csr_irq_handler( void (*csr_irq_handler)(void));
1100489d9baSMatthias Ringwald 
1110489d9baSMatthias Ringwald /**
1120489d9baSMatthias Ringwald  * @brief Set sleep mode
1130489d9baSMatthias Ringwald  * @param block_received callback
1140489d9baSMatthias Ringwald  */
115a705b1a2SMatthias Ringwald void hal_uart_dma_set_sleep(uint8_t sleep);
116a705b1a2SMatthias Ringwald 
1170489d9baSMatthias Ringwald #ifdef HAVE_HAL_UART_DMA_SLEEP_MODES
1180489d9baSMatthias Ringwald 
1190489d9baSMatthias Ringwald /**
1200489d9baSMatthias Ringwald  * @brief Set callback for block received - can be called from ISR context
1210489d9baSMatthias Ringwald  * @returns list of supported sleep modes
1220489d9baSMatthias Ringwald  */
1230489d9baSMatthias Ringwald int  hal_uart_dma_get_supported_sleep_modes(void);
1240489d9baSMatthias Ringwald 
1250489d9baSMatthias Ringwald /**
1260489d9baSMatthias Ringwald  * @brief Set sleep mode
1270489d9baSMatthias Ringwald  * @param sleep_mode
1280489d9baSMatthias Ringwald  */
1290489d9baSMatthias Ringwald void hal_uart_dma_set_sleep_mode(btstack_uart_sleep_mode_t sleep_mode);
1300489d9baSMatthias Ringwald 
1310489d9baSMatthias Ringwald #endif
1320489d9baSMatthias Ringwald 
133a705b1a2SMatthias Ringwald #if defined __cplusplus
134a705b1a2SMatthias Ringwald }
135a705b1a2SMatthias Ringwald #endif
13680e33422SMatthias Ringwald #endif // HAL_UART_DMA_H
137