|
SAM4SD32 (SAM4S-EK2)
|
Receiver Transmitter (USART). More...
Macros | |
| #define | HIGH_FRQ_SAMPLE_DIV 16 |
| #define | ISO7816_T_0 0 |
| #define | ISO7816_T_1 1 |
| #define | LOW_FRQ_SAMPLE_DIV 8 |
| #define | MAX_CD_VALUE US_BRGR_CD_Msk |
| #define | MAX_TRAN_GUARD_TIME US_TTGR_TG_Msk |
| #define | MIN_CD_VALUE 0x01 |
| #define | MIN_CD_VALUE_SPI 0x04 |
| #define | US_WPMR_WPKEY_PASSWD US_WPMR_WPKEY(0x555341U) |
| #define | USART_PARITY_ERROR 5 |
Functions | |
| void | usart_disable_interrupt (Usart *p_usart, uint32_t ul_sources) |
| Disable USART interrupts. | |
| void | usart_disable_rx (Usart *p_usart) |
| Disable USART receiver. | |
| void | usart_disable_tx (Usart *p_usart) |
| Disable USART transmitter. | |
| void | usart_disable_writeprotect (Usart *p_usart) |
| Disable write protect of USART registers. | |
| void | usart_drive_DTR_pin_high (Usart *p_usart) |
| Drive the pin DTR to 1. | |
| void | usart_drive_DTR_pin_low (Usart *p_usart) |
| Drive the pin DTR to 0. | |
| void | usart_drive_RTS_pin_high (Usart *p_usart) |
| Drive the pin RTS to 1. | |
| void | usart_drive_RTS_pin_low (Usart *p_usart) |
| Drive the pin RTS to 0. | |
| void | usart_enable_interrupt (Usart *p_usart, uint32_t ul_sources) |
| Enable USART interrupts. | |
| void | usart_enable_rx (Usart *p_usart) |
| Enable USART receiver. | |
| void | usart_enable_tx (Usart *p_usart) |
| Enable USART transmitter. | |
| void | usart_enable_writeprotect (Usart *p_usart) |
| Enable write protect of USART registers. | |
| uint8_t | usart_get_error_number (Usart *p_usart) |
| Get the total number of errors that occur during an ISO7816 transfer. | |
| uint32_t | usart_get_interrupt_mask (Usart *p_usart) |
| Read USART interrupt mask. | |
| Pdc * | usart_get_pdc_base (Usart *p_usart) |
| Get USART PDC base address. | |
| uint32_t | usart_get_status (Usart *p_usart) |
| Get current status. | |
| uint32_t | usart_get_writeprotect_status (Usart *p_usart) |
| Get write protect status. | |
| uint32_t | usart_getchar (Usart *p_usart, uint32_t *c) |
| Read from USART Receive Holding Register. | |
| uint32_t | usart_init_hw_handshaking (Usart *p_usart, const sam_usart_opt_t *p_usart_opt, uint32_t ul_mck) |
| Configure USART to work in hardware handshaking mode. | |
| uint32_t | usart_init_irda (Usart *p_usart, const sam_usart_opt_t *p_usart_opt, uint32_t ul_mck) |
| Configure USART to work in IrDA mode. | |
| uint32_t | usart_init_iso7816 (Usart *p_usart, const usart_iso7816_opt_t *p_usart_opt, uint32_t ul_mck) |
| Configure USART to work in ISO7816 mode. | |
| uint32_t | usart_init_modem (Usart *p_usart, const sam_usart_opt_t *p_usart_opt, uint32_t ul_mck) |
| Configure USART to work in modem mode. | |
| uint32_t | usart_init_rs232 (Usart *p_usart, const sam_usart_opt_t *p_usart_opt, uint32_t ul_mck) |
| Configure USART to work in RS232 mode. | |
| uint32_t | usart_init_rs485 (Usart *p_usart, const sam_usart_opt_t *p_usart_opt, uint32_t ul_mck) |
| Configure USART to work in RS485 mode. | |
| uint32_t | usart_init_spi_master (Usart *p_usart, const usart_spi_opt_t *p_usart_opt, uint32_t ul_mck) |
| Configure USART to work in SPI mode and act as a master. | |
| uint32_t | usart_init_spi_slave (Usart *p_usart, const usart_spi_opt_t *p_usart_opt) |
| Configure USART to work in SPI mode and act as a slave. | |
| uint32_t | usart_init_sync_master (Usart *p_usart, const sam_usart_opt_t *p_usart_opt, uint32_t ul_mck) |
| Configure USART to work in SYNC mode and act as a master. | |
| uint32_t | usart_init_sync_slave (Usart *p_usart, const sam_usart_opt_t *p_usart_opt) |
| Configure USART to work in SYNC mode and act as a slave. | |
| uint32_t | usart_is_rx_buf_end (Usart *p_usart) |
| Check if one receive buffer is filled. | |
| uint32_t | usart_is_rx_buf_full (Usart *p_usart) |
| Check if both receive buffers are full. | |
| uint32_t | usart_is_rx_ready (Usart *p_usart) |
| Check if the received data are ready. | |
| uint32_t | usart_is_tx_buf_empty (Usart *p_usart) |
| Check if both transmit buffers are empty. | |
| uint32_t | usart_is_tx_buf_end (Usart *p_usart) |
| Check if one transmit buffer is empty. | |
| uint32_t | usart_is_tx_empty (Usart *p_usart) |
| Check if Transmit Holding Register is empty. | |
| uint32_t | usart_is_tx_ready (Usart *p_usart) |
| Check if Transmit is Ready. | |
| void | usart_man_disable_drift_compensation (Usart *p_usart) |
| Disable drift compensation. | |
| void | usart_man_enable_drift_compensation (Usart *p_usart) |
| Enable drift compensation. | |
| void | usart_man_set_rx_polarity (Usart *p_usart, uint8_t uc_polarity) |
| Configure the receiver Manchester polarity when the Manchester encode/decode is enabled. | |
| void | usart_man_set_rx_pre_len (Usart *p_usart, uint8_t uc_len) |
| Configure the detected receiver preamble length when the Manchester encode/decode is enabled. | |
| void | usart_man_set_rx_pre_pattern (Usart *p_usart, uint8_t uc_pattern) |
| Configure the detected receiver preamble pattern when the Manchester encode/decode is enabled, which should be 0 ~ 3. | |
| void | usart_man_set_tx_polarity (Usart *p_usart, uint8_t uc_polarity) |
| Configure the transmitter Manchester polarity when the Manchester encode/decode is enabled. | |
| void | usart_man_set_tx_pre_len (Usart *p_usart, uint8_t uc_len) |
| Configure the transmitter preamble length when the Manchester encode/decode is enabled. | |
| void | usart_man_set_tx_pre_pattern (Usart *p_usart, uint8_t uc_pattern) |
| Configure the transmitter preamble pattern when the Manchester encode/decode is enabled, which should be 0 ~ 3. | |
| uint32_t | usart_putchar (Usart *p_usart, uint32_t c) |
| Write to USART Transmit Holding Register. | |
| uint32_t | usart_read (Usart *p_usart, uint32_t *c) |
| Read from USART Receive Holding Register. | |
| void | usart_reset (Usart *p_usart) |
| Reset the USART and disable TX and RX. | |
| void | usart_reset_iterations (Usart *p_usart) |
| Reset the ITERATION in US_CSR when the ISO7816 mode is enabled. | |
| void | usart_reset_nack (Usart *p_usart) |
| Reset NACK in US_CSR. | |
| void | usart_reset_rx (Usart *p_usart) |
| Immediately stop and disable USART receiver. | |
| void | usart_reset_status (Usart *p_usart) |
| Reset status bits (PARE, OVER, MANERR, UNRE and PXBRK in US_CSR). | |
| void | usart_reset_tx (Usart *p_usart) |
| Immediately stop and disable USART transmitter. | |
| void | usart_restart_rx_timeout (Usart *p_usart) |
| Restart the receive timeout. | |
| uint32_t | usart_send_address (Usart *p_usart, uint32_t ul_addr) |
| In Multidrop mode only, the next character written to the US_THR is sent with the address bit set. | |
| uint32_t | usart_set_async_baudrate (Usart *p_usart, uint32_t baudrate, uint32_t ul_mck) |
| Calculate a clock divider(CD) and a fractional part (FP) for the USART asynchronous modes to generate a baudrate as close as possible to the baudrate set point. | |
| static uint32_t | usart_set_iso7816_clock (Usart *p_usart, uint32_t clock, uint32_t ul_mck) |
| Calculate a clock divider (CD) for the USART ISO7816 mode to generate an ISO7816 clock as close as possible to the clock set point. | |
| void | usart_set_rx_timeout (Usart *p_usart, uint32_t timeout) |
| Configure the receive timeout register. | |
| static uint32_t | usart_set_spi_master_baudrate (Usart *p_usart, uint32_t baudrate, uint32_t ul_mck) |
| Calculate a clock divider (CD) for the USART SPI master mode to generate a baud rate as close as possible to the baud rate set point. | |
| static void | usart_set_spi_slave_baudrate (Usart *p_usart) |
| Select the SCK pin as the source of baudrate for the USART SPI slave mode. | |
| static uint32_t | usart_set_sync_master_baudrate (Usart *p_usart, uint32_t baudrate, uint32_t ul_mck) |
| Calculate a clock divider for the USART synchronous master modes to generate a baudrate as close as possible to the baudrate set point. | |
| static void | usart_set_sync_slave_baudrate (Usart *p_usart) |
| Select the SCK pin as the source of baud rate for the USART synchronous slave modes. | |
| void | usart_set_tx_timeguard (Usart *p_usart, uint32_t timeguard) |
| Configure the transmit timeguard register. | |
| void | usart_spi_force_chip_select (Usart *p_usart) |
| Drive the slave select line NSS (RTS pin) to 0 in SPI master mode. | |
| void | usart_spi_release_chip_select (Usart *p_usart) |
| Drive the slave select line NSS (RTS pin) to 1 in SPI master mode. | |
| void | usart_start_rx_timeout (Usart *p_usart) |
| Start waiting for a character before clocking the timeout count. | |
| void | usart_start_tx_break (Usart *p_usart) |
| Start transmission of a break. | |
| void | usart_stop_tx_break (Usart *p_usart) |
| Stop transmission of a break. | |
| uint32_t | usart_write (Usart *p_usart, uint32_t c) |
| Write to USART Transmit Holding Register. | |
| void | usart_write_line (Usart *p_usart, const char *string) |
| Write one-line string through USART. | |
Receiver Transmitter (USART).
The Universal Synchronous Asynchronous Receiver Transceiver (USART) provides one full duplex universal synchronous asynchronous serial link. Data frame format is widely programmable (data length, parity, number of stop bits) to support a maximum of standards. The receiver implements parity error, framing error and overrun error detection. The receiver time-out enables handling variable-length frames and the transmitter timeguard facilitates communications with slow remote devices. Multidrop communications are also supported through address bit handling in reception and transmission. The driver supports the following modes: RS232, RS485, SPI, IrDA, ISO7816, MODEM, Hardware handshaking and LIN.
| #define HIGH_FRQ_SAMPLE_DIV 16 |
Definition at line 81 of file usart.c.
Referenced by usart_set_async_baudrate().
| #define ISO7816_T_0 0 |
Definition at line 91 of file usart.c.
Referenced by usart_init_iso7816().
| #define ISO7816_T_1 1 |
Definition at line 92 of file usart.c.
Referenced by usart_init_iso7816().
| #define LOW_FRQ_SAMPLE_DIV 8 |
Definition at line 82 of file usart.c.
Referenced by usart_set_async_baudrate().
| #define MAX_CD_VALUE US_BRGR_CD_Msk |
Definition at line 78 of file usart.c.
Referenced by usart_set_async_baudrate(), usart_set_iso7816_clock(), usart_set_spi_master_baudrate(), and usart_set_sync_master_baudrate().
| #define MAX_TRAN_GUARD_TIME US_TTGR_TG_Msk |
| #define US_WPMR_WPKEY_PASSWD US_WPMR_WPKEY(0x555341U) |
Definition at line 68 of file usart.c.
Referenced by usart_disable_writeprotect(), and usart_enable_writeprotect().
| void usart_disable_interrupt | ( | Usart * | p_usart, |
| uint32_t | ul_sources ) |
Disable USART interrupts.
| p_usart | Pointer to a USART peripheral. |
| ul_sources | Interrupt sources bit map. |
Definition at line 1480 of file usart.c.
References Usart::US_IDR.
| void usart_disable_rx | ( | Usart * | p_usart | ) |
Disable USART receiver.
| p_usart | Pointer to a USART instance. |
Definition at line 1436 of file usart.c.
References Usart::US_CR, and US_CR_RXDIS.
| void usart_disable_tx | ( | Usart * | p_usart | ) |
Disable USART transmitter.
| p_usart | Pointer to a USART instance. |
Definition at line 1394 of file usart.c.
References Usart::US_CR, and US_CR_TXDIS.
| void usart_disable_writeprotect | ( | Usart * | p_usart | ) |
Disable write protect of USART registers.
| p_usart | Pointer to a USART instance. |
Definition at line 1907 of file usart.c.
References Usart::US_WPMR, and US_WPMR_WPKEY_PASSWD.
Referenced by usart_reset().
| void usart_drive_DTR_pin_high | ( | Usart * | p_usart | ) |
Drive the pin DTR to 1.
| p_usart | Pointer to a USART instance. |
Definition at line 1602 of file usart.c.
References Usart::US_CR, and US_CR_DTRDIS.
Referenced by usart_reset().
| void usart_drive_DTR_pin_low | ( | Usart * | p_usart | ) |
Drive the pin DTR to 0.
| p_usart | Pointer to a USART instance. |
Definition at line 1592 of file usart.c.
References Usart::US_CR, and US_CR_DTREN.
| void usart_drive_RTS_pin_high | ( | Usart * | p_usart | ) |
Drive the pin RTS to 1.
| p_usart | Pointer to a USART instance. |
Definition at line 1624 of file usart.c.
References Usart::US_CR, and US_CR_RTSDIS.
Referenced by usart_reset().
| void usart_drive_RTS_pin_low | ( | Usart * | p_usart | ) |
Drive the pin RTS to 0.
| p_usart | Pointer to a USART instance. |
Definition at line 1614 of file usart.c.
References Usart::US_CR, and US_CR_RTSEN.
| void usart_enable_interrupt | ( | Usart * | p_usart, |
| uint32_t | ul_sources ) |
Enable USART interrupts.
| p_usart | Pointer to a USART peripheral. |
| ul_sources | Interrupt sources bit map. |
Definition at line 1469 of file usart.c.
References Usart::US_IER.
| void usart_enable_rx | ( | Usart * | p_usart | ) |
Enable USART receiver.
| p_usart | Pointer to a USART instance. |
Definition at line 1426 of file usart.c.
References Usart::US_CR, and US_CR_RXEN.
Referenced by usart_serial_init().
| void usart_enable_tx | ( | Usart * | p_usart | ) |
Enable USART transmitter.
| p_usart | Pointer to a USART instance. |
Definition at line 1384 of file usart.c.
References Usart::US_CR, and US_CR_TXEN.
Referenced by usart_serial_init().
| void usart_enable_writeprotect | ( | Usart * | p_usart | ) |
Enable write protect of USART registers.
| p_usart | Pointer to a USART instance. |
Definition at line 1897 of file usart.c.
References Usart::US_WPMR, US_WPMR_WPEN, and US_WPMR_WPKEY_PASSWD.
| uint8_t usart_get_error_number | ( | Usart * | p_usart | ) |
Get the total number of errors that occur during an ISO7816 transfer.
| p_usart | Pointer to a USART instance. |
Definition at line 699 of file usart.c.
References Usart::US_NER, and US_NER_NB_ERRORS_Msk.
| uint32_t usart_get_interrupt_mask | ( | Usart * | p_usart | ) |
Read USART interrupt mask.
| p_usart | Pointer to a USART peripheral. |
Definition at line 1492 of file usart.c.
References Usart::US_IMR.
| Pdc * usart_get_pdc_base | ( | Usart * | p_usart | ) |
Get USART PDC base address.
| p_usart | Pointer to a UART instance. |
Definition at line 1827 of file usart.c.
References PDC_USART0, PDC_USART1, USART0, and USART1.
| uint32_t usart_get_status | ( | Usart * | p_usart | ) |
Get current status.
| p_usart | Pointer to a USART instance. |
Definition at line 1504 of file usart.c.
References Usart::US_CSR.
| uint32_t usart_get_writeprotect_status | ( | Usart * | p_usart | ) |
Get write protect status.
| p_usart | Pointer to a USART instance. |
Definition at line 1920 of file usart.c.
References Usart::US_WPSR, US_WPSR_WPVS, US_WPSR_WPVSRC_Msk, and US_WPSR_WPVSRC_Pos.
| uint32_t usart_getchar | ( | Usart * | p_usart, |
| uint32_t * | c ) |
Read from USART Receive Holding Register.
Before reading user should check if rx is ready.
| p_usart | Pointer to a USART instance. |
| c | Pointer where the one-byte received data will be stored. |
| 0 | Data has been received. |
| 1 | on failure. |
Definition at line 1781 of file usart.c.
References Usart::US_CSR, US_CSR_RXRDY, Usart::US_RHR, and US_RHR_RXCHR_Msk.
| uint32_t usart_init_hw_handshaking | ( | Usart * | p_usart, |
| const sam_usart_opt_t * | p_usart_opt, | ||
| uint32_t | ul_mck ) |
Configure USART to work in hardware handshaking mode.
| p_usart | Pointer to a USART instance. |
| p_usart_opt | Pointer to sam_usart_opt_t instance. |
| ul_mck | USART module input clock frequency. |
| 0 | on success. |
| 1 | on failure. |
Definition at line 313 of file usart.c.
References Usart::US_MR, US_MR_USART_MODE_HW_HANDSHAKING, US_MR_USART_MODE_Msk, and usart_init_rs232().
| uint32_t usart_init_irda | ( | Usart * | p_usart, |
| const sam_usart_opt_t * | p_usart_opt, | ||
| uint32_t | ul_mck ) |
Configure USART to work in IrDA mode.
| p_usart | Pointer to a USART instance. |
| p_usart_opt | Pointer to sam_usart_opt_t instance. |
| ul_mck | USART module input clock frequency. |
| 0 | on success. |
| 1 | on failure. |
Definition at line 490 of file usart.c.
References sam_usart_opt_t::irda_filter, Usart::US_IF, Usart::US_MR, US_MR_USART_MODE_IRDA, US_MR_USART_MODE_Msk, and usart_init_rs232().
| uint32_t usart_init_iso7816 | ( | Usart * | p_usart, |
| const usart_iso7816_opt_t * | p_usart_opt, | ||
| uint32_t | ul_mck ) |
Configure USART to work in ISO7816 mode.
| p_usart | Pointer to a USART instance. |
| p_usart_opt | Pointer to sam_usart_opt_t instance. |
| ul_mck | USART module input clock frequency. |
| 0 | on success. |
| 1 | on failure. |
Definition at line 557 of file usart.c.
References usart_iso7816_opt_t::bit_order, usart_iso7816_opt_t::dis_suc_nack, usart_iso7816_opt_t::fidi_ratio, usart_iso7816_opt_t::inhibit_nack, usart_iso7816_opt_t::iso7816_hz, ISO7816_T_0, ISO7816_T_1, usart_iso7816_opt_t::max_iterations, usart_iso7816_opt_t::parity_type, usart_iso7816_opt_t::protocol_type, Usart::US_FIDI, Usart::US_MR, US_MR_DSNACK, US_MR_INACK, US_MR_MAX_ITERATION_Pos, US_MR_MSBF, US_MR_NBSTOP_1_BIT, US_MR_NBSTOP_2_BIT, US_MR_PAR_EVEN, US_MR_PAR_ODD, US_MR_USART_MODE_IS07816_T_0, US_MR_USART_MODE_IS07816_T_1, usart_reset(), and usart_set_iso7816_clock().
| uint32_t usart_init_modem | ( | Usart * | p_usart, |
| const sam_usart_opt_t * | p_usart_opt, | ||
| uint32_t | ul_mck ) |
Configure USART to work in modem mode.
| p_usart | Pointer to a USART instance. |
| p_usart_opt | Pointer to sam_usart_opt_t instance. |
| ul_mck | USART module input clock frequency. |
| 0 | on success. |
| 1 | on failure. |
Definition at line 342 of file usart.c.
References Usart::US_MR, US_MR_USART_MODE_MODEM, US_MR_USART_MODE_Msk, USART0, USART1, and usart_init_rs232().
| uint32_t usart_init_rs232 | ( | Usart * | p_usart, |
| const sam_usart_opt_t * | p_usart_opt, | ||
| uint32_t | ul_mck ) |
Configure USART to work in RS232 mode.
| p_usart | Pointer to a USART instance. |
| p_usart_opt | Pointer to sam_usart_opt_t instance. |
| ul_mck | USART module input clock frequency. |
| 0 | on success. |
| 1 | on failure. |
Definition at line 274 of file usart.c.
References sam_usart_opt_t::baudrate, sam_usart_opt_t::channel_mode, sam_usart_opt_t::char_length, sam_usart_opt_t::parity_type, sam_usart_opt_t::stop_bits, Usart::US_MR, US_MR_USART_MODE_NORMAL, usart_reset(), and usart_set_async_baudrate().
Referenced by usart_init_hw_handshaking(), usart_init_irda(), usart_init_modem(), usart_init_rs485(), and usart_serial_init().
| uint32_t usart_init_rs485 | ( | Usart * | p_usart, |
| const sam_usart_opt_t * | p_usart_opt, | ||
| uint32_t | ul_mck ) |
Configure USART to work in RS485 mode.
| p_usart | Pointer to a USART instance. |
| p_usart_opt | Pointer to sam_usart_opt_t instance. |
| ul_mck | USART module input clock frequency. |
| 0 | on success. |
| 1 | on failure. |
Definition at line 462 of file usart.c.
References Usart::US_MR, US_MR_USART_MODE_Msk, US_MR_USART_MODE_RS485, and usart_init_rs232().
| uint32_t usart_init_spi_master | ( | Usart * | p_usart, |
| const usart_spi_opt_t * | p_usart_opt, | ||
| uint32_t | ul_mck ) |
Configure USART to work in SPI mode and act as a master.
| p_usart | Pointer to a USART instance. |
| p_usart_opt | Pointer to sam_usart_opt_t instance. |
| ul_mck | USART module input clock frequency. |
| 0 | on success. |
| 1 | on failure. |
Definition at line 718 of file usart.c.
References usart_spi_opt_t::baudrate, usart_spi_opt_t::channel_mode, usart_spi_opt_t::char_length, usart_spi_opt_t::spi_mode, SPI_MODE_0, SPI_MODE_1, SPI_MODE_2, SPI_MODE_3, Usart::US_MR, US_MR_CLKO, US_MR_CPHA, US_MR_CPOL, US_MR_USART_MODE_SPI_MASTER, usart_reset(), and usart_set_spi_master_baudrate().
| uint32_t usart_init_spi_slave | ( | Usart * | p_usart, |
| const usart_spi_opt_t * | p_usart_opt ) |
Configure USART to work in SPI mode and act as a slave.
| p_usart | Pointer to a USART instance. |
| p_usart_opt | Pointer to sam_usart_opt_t instance. |
| 0 | on success. |
| 1 | on failure. |
Definition at line 782 of file usart.c.
References usart_spi_opt_t::channel_mode, usart_spi_opt_t::char_length, usart_spi_opt_t::spi_mode, SPI_MODE_0, SPI_MODE_1, SPI_MODE_2, SPI_MODE_3, Usart::US_MR, US_MR_CPHA, US_MR_CPOL, US_MR_USART_MODE_SPI_SLAVE, usart_reset(), and usart_set_spi_slave_baudrate().
| uint32_t usart_init_sync_master | ( | Usart * | p_usart, |
| const sam_usart_opt_t * | p_usart_opt, | ||
| uint32_t | ul_mck ) |
Configure USART to work in SYNC mode and act as a master.
| p_usart | Pointer to a USART instance. |
| p_usart_opt | Pointer to sam_usart_opt_t instance. |
| ul_mck | USART module input clock frequency. |
| 0 | on success. |
| 1 | on failure. |
Definition at line 386 of file usart.c.
References sam_usart_opt_t::baudrate, sam_usart_opt_t::channel_mode, sam_usart_opt_t::char_length, sam_usart_opt_t::parity_type, sam_usart_opt_t::stop_bits, Usart::US_MR, US_MR_CLKO, US_MR_USART_MODE_NORMAL, usart_reset(), and usart_set_sync_master_baudrate().
| uint32_t usart_init_sync_slave | ( | Usart * | p_usart, |
| const sam_usart_opt_t * | p_usart_opt ) |
Configure USART to work in SYNC mode and act as a slave.
| p_usart | Pointer to a USART instance. |
| p_usart_opt | Pointer to sam_usart_opt_t instance. |
| 0 | on success. |
| 1 | on failure. |
Definition at line 423 of file usart.c.
References sam_usart_opt_t::channel_mode, sam_usart_opt_t::char_length, sam_usart_opt_t::parity_type, sam_usart_opt_t::stop_bits, Usart::US_MR, US_MR_USART_MODE_NORMAL, usart_reset(), and usart_set_sync_slave_baudrate().
| uint32_t usart_is_rx_buf_end | ( | Usart * | p_usart | ) |
Check if one receive buffer is filled.
| p_usart | Pointer to a USART instance. |
| 1 | Receive is complete. |
| 0 | Receive is still pending. |
Definition at line 660 of file usart.c.
References Usart::US_CSR, and US_CSR_ENDRX.
| uint32_t usart_is_rx_buf_full | ( | Usart * | p_usart | ) |
Check if both receive buffers are full.
| p_usart | Pointer to a USART instance. |
| 1 | Receive buffers are full. |
| 0 | Receive buffers are not full. |
Definition at line 646 of file usart.c.
References Usart::US_CSR, and US_CSR_RXBUFF.
| uint32_t usart_is_rx_ready | ( | Usart * | p_usart | ) |
Check if the received data are ready.
Check if Data have been received and loaded into USART_RHR.
| p_usart | Pointer to a USART instance. |
| 1 | Some data has been received. |
| 0 | No data has been received. |
Definition at line 1688 of file usart.c.
References Usart::US_CSR, and US_CSR_RXRDY.
Referenced by usart_serial_is_rx_ready().
| uint32_t usart_is_tx_buf_empty | ( | Usart * | p_usart | ) |
Check if both transmit buffers are empty.
| p_usart | Pointer to a USART instance. |
| 1 | Transmit buffers are empty. |
| 0 | Transmit buffers are not empty. |
Definition at line 686 of file usart.c.
References Usart::US_CSR, and US_CSR_TXBUFE.
| uint32_t usart_is_tx_buf_end | ( | Usart * | p_usart | ) |
Check if one transmit buffer is empty.
| p_usart | Pointer to a USART instance. |
| 1 | Transmit is complete. |
| 0 | Transmit is still pending. |
Definition at line 673 of file usart.c.
References Usart::US_CSR, and US_CSR_ENDTX.
| uint32_t usart_is_tx_empty | ( | Usart * | p_usart | ) |
Check if Transmit Holding Register is empty.
Check if the last data written in USART_THR have been loaded in TSR and the last data loaded in TSR have been transmitted.
| p_usart | Pointer to a USART instance. |
| 1 | Transmitter is empty. |
| 0 | Transmitter is not empty. |
Definition at line 1674 of file usart.c.
References Usart::US_CSR, and US_CSR_TXEMPTY.
| uint32_t usart_is_tx_ready | ( | Usart * | p_usart | ) |
Check if Transmit is Ready.
Check if data have been loaded in USART_THR and are waiting to be loaded into the Transmit Shift Register (TSR).
| p_usart | Pointer to a USART instance. |
| 1 | No data is in the Transmit Holding Register. |
| 0 | There is data in the Transmit Holding Register. |
Definition at line 1659 of file usart.c.
References Usart::US_CSR, and US_CSR_TXRDY.
| void usart_man_disable_drift_compensation | ( | Usart * | p_usart | ) |
Disable drift compensation.
| p_usart | Pointer to a USART instance. |
Definition at line 2037 of file usart.c.
References Usart::US_MAN, and US_MAN_DRIFT.
| void usart_man_enable_drift_compensation | ( | Usart * | p_usart | ) |
Enable drift compensation.
| p_usart | Pointer to a USART instance. |
Definition at line 2027 of file usart.c.
References Usart::US_MAN, and US_MAN_DRIFT.
| void usart_man_set_rx_polarity | ( | Usart * | p_usart, |
| uint8_t | uc_polarity ) |
Configure the receiver Manchester polarity when the Manchester encode/decode is enabled.
| p_usart | Pointer to a USART instance. |
| uc_polarity | Indicate the receiver Manchester polarity, which should be 0 or 1. |
Definition at line 2014 of file usart.c.
References Usart::US_MAN, and US_MAN_RX_MPOL.
| void usart_man_set_rx_pre_len | ( | Usart * | p_usart, |
| uint8_t | uc_len ) |
Configure the detected receiver preamble length when the Manchester encode/decode is enabled.
| p_usart | Pointer to a USART instance. |
| uc_len | The detected receiver preamble length, which should be 0 ~ 15. |
Definition at line 1984 of file usart.c.
References Usart::US_MAN, US_MAN_RX_PL, and US_MAN_RX_PL_Msk.
| void usart_man_set_rx_pre_pattern | ( | Usart * | p_usart, |
| uint8_t | uc_pattern ) |
Configure the detected receiver preamble pattern when the Manchester encode/decode is enabled, which should be 0 ~ 3.
| p_usart | Pointer to a USART instance. |
| uc_pattern | 0 if the preamble is composed of '1's; 1 if the preamble is composed of '0's; 2 if the preamble is composed of '01's; 3 if the preamble is composed of '10's. |
Definition at line 2000 of file usart.c.
References Usart::US_MAN, US_MAN_RX_PP_Msk, and US_MAN_RX_PP_Pos.
| void usart_man_set_tx_polarity | ( | Usart * | p_usart, |
| uint8_t | uc_polarity ) |
Configure the transmitter Manchester polarity when the Manchester encode/decode is enabled.
| p_usart | Pointer to a USART instance. |
| uc_polarity | Indicate the transmitter Manchester polarity, which should be 0 or 1. |
Definition at line 1971 of file usart.c.
References Usart::US_MAN, and US_MAN_TX_MPOL.
| void usart_man_set_tx_pre_len | ( | Usart * | p_usart, |
| uint8_t | uc_len ) |
Configure the transmitter preamble length when the Manchester encode/decode is enabled.
| p_usart | Pointer to a USART instance. |
| uc_len | The transmitter preamble length, which should be 0 ~ 15. |
Definition at line 1941 of file usart.c.
References Usart::US_MAN, US_MAN_TX_PL, and US_MAN_TX_PL_Msk.
| void usart_man_set_tx_pre_pattern | ( | Usart * | p_usart, |
| uint8_t | uc_pattern ) |
Configure the transmitter preamble pattern when the Manchester encode/decode is enabled, which should be 0 ~ 3.
| p_usart | Pointer to a USART instance. |
| uc_pattern | 0 if the preamble is composed of '1's; 1 if the preamble is composed of '0's; 2 if the preamble is composed of '01's; 3 if the preamble is composed of '10's. |
Definition at line 1957 of file usart.c.
References Usart::US_MAN, US_MAN_TX_PP_Msk, and US_MAN_TX_PP_Pos.
| uint32_t usart_putchar | ( | Usart * | p_usart, |
| uint32_t | c ) |
Write to USART Transmit Holding Register.
| p_usart | Pointer to a USART instance. |
| c | Data to be sent. |
| 0 | on success. |
| 1 | on failure. |
Definition at line 1725 of file usart.c.
References Usart::US_CSR, US_CSR_TXRDY, Usart::US_THR, and US_THR_TXCHR.
Referenced by usart_write_line().
| uint32_t usart_read | ( | Usart * | p_usart, |
| uint32_t * | c ) |
Read from USART Receive Holding Register.
| p_usart | Pointer to a USART instance. |
| c | Pointer where the one-byte received data will be stored. |
| 0 | on success. |
| 1 | if no data is available or errors. |
Definition at line 1759 of file usart.c.
References Usart::US_CSR, US_CSR_RXRDY, Usart::US_RHR, and US_RHR_RXCHR_Msk.
Referenced by usart_serial_getchar().
| void usart_reset | ( | Usart * | p_usart | ) |
Reset the USART and disable TX and RX.
| p_usart | Pointer to a USART instance. |
Definition at line 240 of file usart.c.
References Usart::US_MR, Usart::US_RTOR, Usart::US_TTGR, usart_disable_writeprotect(), usart_drive_DTR_pin_high(), usart_drive_RTS_pin_high(), usart_reset_rx(), usart_reset_status(), and usart_reset_tx().
Referenced by usart_init_iso7816(), usart_init_rs232(), usart_init_spi_master(), usart_init_spi_slave(), usart_init_sync_master(), and usart_init_sync_slave().
| void usart_reset_iterations | ( | Usart * | p_usart | ) |
Reset the ITERATION in US_CSR when the ISO7816 mode is enabled.
| p_usart | Pointer to a USART instance. |
Definition at line 623 of file usart.c.
References Usart::US_CR, and US_CR_RSTIT.
| void usart_reset_nack | ( | Usart * | p_usart | ) |
Reset NACK in US_CSR.
| p_usart | Pointer to a USART instance. |
Definition at line 633 of file usart.c.
References Usart::US_CR, and US_CR_RSTNACK.
| void usart_reset_rx | ( | Usart * | p_usart | ) |
Immediately stop and disable USART receiver.
| p_usart | Pointer to a USART instance. |
Definition at line 1446 of file usart.c.
References Usart::US_CR, US_CR_RSTRX, and US_CR_RXDIS.
Referenced by usart_reset().
| void usart_reset_status | ( | Usart * | p_usart | ) |
Reset status bits (PARE, OVER, MANERR, UNRE and PXBRK in US_CSR).
| p_usart | Pointer to a USART instance. |
Definition at line 1514 of file usart.c.
References Usart::US_CR, and US_CR_RSTSTA.
Referenced by usart_reset().
| void usart_reset_tx | ( | Usart * | p_usart | ) |
Immediately stop and disable USART transmitter.
| p_usart | Pointer to a USART instance. |
Definition at line 1404 of file usart.c.
References Usart::US_CR, US_CR_RSTTX, and US_CR_TXDIS.
Referenced by usart_reset().
| void usart_restart_rx_timeout | ( | Usart * | p_usart | ) |
Restart the receive timeout.
| p_usart | Pointer to a USART instance. |
Definition at line 1580 of file usart.c.
References Usart::US_CR, and US_CR_RETTO.
| uint32_t usart_send_address | ( | Usart * | p_usart, |
| uint32_t | ul_addr ) |
In Multidrop mode only, the next character written to the US_THR is sent with the address bit set.
| p_usart | Pointer to a USART instance. |
| ul_addr | The address to be sent out. |
| 0 | on success. |
| 1 | on failure. |
Definition at line 1560 of file usart.c.
References Usart::US_CR, US_CR_SENDA, Usart::US_MR, US_MR_PAR_MULTIDROP, and usart_write().
| uint32_t usart_set_async_baudrate | ( | Usart * | p_usart, |
| uint32_t | baudrate, | ||
| uint32_t | ul_mck ) |
Calculate a clock divider(CD) and a fractional part (FP) for the USART asynchronous modes to generate a baudrate as close as possible to the baudrate set point.
| p_usart | Pointer to a USART instance. |
| baudrate | Baud rate set point. |
| ul_mck | USART module input clock frequency. |
| 0 | Baud rate is successfully initialized. |
| 1 | Baud rate set point is out of range for the given input clock frequency. |
Definition at line 111 of file usart.c.
References HIGH_FRQ_SAMPLE_DIV, LOW_FRQ_SAMPLE_DIV, MAX_CD_VALUE, Usart::US_BRGR, US_BRGR_CD_Pos, US_BRGR_FP_Pos, Usart::US_MR, and US_MR_OVER.
Referenced by usart_init_rs232().
|
static |
Calculate a clock divider (CD) for the USART ISO7816 mode to generate an ISO7816 clock as close as possible to the clock set point.
| p_usart | Pointer to a USART instance. |
| clock | ISO7816 clock set point. |
| ul_mck | USART module input clock frequency. |
| 0 | ISO7816 clock is successfully initialized. |
| 1 | ISO7816 clock set point is out of range for the given input clock frequency. |
Definition at line 524 of file usart.c.
References MAX_CD_VALUE, Usart::US_BRGR, US_BRGR_CD_Pos, Usart::US_MR, US_MR_CLKO, US_MR_OVER, US_MR_SYNC, US_MR_USCLKS_MCK, and US_MR_USCLKS_Msk.
Referenced by usart_init_iso7816().
| void usart_set_rx_timeout | ( | Usart * | p_usart, |
| uint32_t | timeout ) |
Configure the receive timeout register.
| p_usart | Pointer to a USART instance. |
| timeout | The value of receive timeout. |
Definition at line 1458 of file usart.c.
References Usart::US_RTOR.
|
static |
Calculate a clock divider (CD) for the USART SPI master mode to generate a baud rate as close as possible to the baud rate set point.
| p_usart | Pointer to a USART instance. |
| baudrate | Baud rate set point. |
| ul_mck | USART module input clock frequency. |
| 0 | Baud rate is successfully initialized. |
| 1 | Baud rate set point is out of range for the given input clock frequency. |
Definition at line 206 of file usart.c.
References MAX_CD_VALUE, Usart::US_BRGR, and US_BRGR_CD_Pos.
Referenced by usart_init_spi_master().
|
static |
Select the SCK pin as the source of baudrate for the USART SPI slave mode.
| p_usart | Pointer to a USART instance. |
Definition at line 229 of file usart.c.
References Usart::US_MR, US_MR_USCLKS_Msk, and US_MR_USCLKS_SCK.
Referenced by usart_init_spi_slave().
|
static |
Calculate a clock divider for the USART synchronous master modes to generate a baudrate as close as possible to the baudrate set point.
| p_usart | Pointer to a USART instance. |
| baudrate | Baud rate set point. |
| ul_mck | USART module input clock frequency. |
| 0 | Baud rate is successfully initialized. |
| 1 | Baud rate set point is out of range for the given input clock frequency. |
Definition at line 159 of file usart.c.
References MAX_CD_VALUE, Usart::US_BRGR, US_BRGR_CD_Pos, Usart::US_MR, US_MR_SYNC, US_MR_USCLKS_MCK, and US_MR_USCLKS_Msk.
Referenced by usart_init_sync_master().
|
static |
Select the SCK pin as the source of baud rate for the USART synchronous slave modes.
| p_usart | Pointer to a USART instance. |
Definition at line 185 of file usart.c.
References Usart::US_MR, US_MR_SYNC, US_MR_USCLKS_Msk, and US_MR_USCLKS_SCK.
Referenced by usart_init_sync_slave().
| void usart_set_tx_timeguard | ( | Usart * | p_usart, |
| uint32_t | timeguard ) |
Configure the transmit timeguard register.
| p_usart | Pointer to a USART instance. |
| timeguard | The value of transmit timeguard. |
Definition at line 1416 of file usart.c.
References Usart::US_TTGR.
| void usart_spi_force_chip_select | ( | Usart * | p_usart | ) |
Drive the slave select line NSS (RTS pin) to 0 in SPI master mode.
| p_usart | Pointer to a USART instance. |
Definition at line 1634 of file usart.c.
References Usart::US_CR, and US_CR_FCS.
| void usart_spi_release_chip_select | ( | Usart * | p_usart | ) |
Drive the slave select line NSS (RTS pin) to 1 in SPI master mode.
| p_usart | Pointer to a USART instance. |
Definition at line 1644 of file usart.c.
References Usart::US_CR, and US_CR_RCS.
| void usart_start_rx_timeout | ( | Usart * | p_usart | ) |
Start waiting for a character before clocking the timeout count.
Reset the status bit TIMEOUT in US_CSR.
| p_usart | Pointer to a USART instance. |
Definition at line 1545 of file usart.c.
References Usart::US_CR, and US_CR_STTTO.
| void usart_start_tx_break | ( | Usart * | p_usart | ) |
Start transmission of a break.
| p_usart | Pointer to a USART instance. |
Definition at line 1524 of file usart.c.
References Usart::US_CR, and US_CR_STTBRK.
| void usart_stop_tx_break | ( | Usart * | p_usart | ) |
Stop transmission of a break.
| p_usart | Pointer to a USART instance. |
Definition at line 1534 of file usart.c.
References Usart::US_CR, and US_CR_STPBRK.
| uint32_t usart_write | ( | Usart * | p_usart, |
| uint32_t | c ) |
Write to USART Transmit Holding Register.
| p_usart | Pointer to a USART instance. |
| c | Data to be sent. |
| 0 | on success. |
| 1 | on failure. |
Definition at line 1704 of file usart.c.
References Usart::US_CSR, US_CSR_TXRDY, Usart::US_THR, and US_THR_TXCHR.
Referenced by usart_send_address(), and usart_serial_putchar().
| void usart_write_line | ( | Usart * | p_usart, |
| const char * | string ) |
Write one-line string through USART.
| p_usart | Pointer to a USART instance. |
| string | Pointer to one-line string to be sent. |
Definition at line 1741 of file usart.c.
References usart_putchar().