Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arch/pic32mz: Serial TIOCxBRK BSD-compatible BREAK support #8550

Merged
merged 1 commit into from
Feb 17, 2023

Conversation

hartmannathan
Copy link
Contributor

Summary

In the lower half UART driver for PIC32MZ architecture, adding the TIOCxBRK ioctl calls (TIOCSBRK and TIOCCBRK). These allow an application to transmit a BREAK (either hardware-native or BSD compatible).

This architecture does not support BSD-style BREAK in hardware so our implementation follows the precedent set in STM32, GD32, and Kinetis architectures: By default, if only PIC32MZ_UART_BREAKS is configured, we produce the hardware-native BREAK, which lasts for 12 bit lengths on this architecture; if, in addition, PIC32MZ_SERIALBRK_BSDCOMPAT is also configured, we generate a BSD-style BREAK by putting the TX pin in GPIO mode and driving it "manually" until told to stop.

Impact

When PIC32MZ_UART_BREAKS is activated, TIOCSBRK and TIOCCBRK ioctl calls are supported on PIC32MZ architectures. When PIC32MZ_SERIALBRK_BSDCOMPAT is also activated, the ioctl calls are BSD-compatible. When not activated, no effect.

Testing

Works on custom board.
nxstyle.

In the lower half UART driver for PIC32MZ architecture, adding the
TIOCxBRK ioctl calls, which allow an application to transmit a UART
line BREAK signal.

This architecture does not support BSD-style BREAK in hardware so our
implementation follows the precedent set in STM32, GD32, and Kinetis
architectures: By default, if only PIC32MZ_UART_BREAKS is configured,
we produce the hardware-native BREAK, which lasts for 12 bit lengths;
if, in addition, PIC32MZ_SERIALBRK_BSDCOMPAT is configured, we
generate a BSD-style BREAK by putting the TX pin in GPIO mode and
driving it low "manually" until told to stop.

* arch/mips/src/pic32mz/Kconfig
  (config PIC32MZ_UART_BREAKS): New. Appears as
   CONFIG_PIC32MZ_UART_BREAKS in code.
  (config PIC32MZ_SERIALBRK_BSDCOMPAT): New. Appears as
   CONFIG_PIC32MZ_SERIALBRK_BSDCOMPAT in code.

* arch/mips/src/pic32mz/hardware/pic32mz_pps.h
  (__PPS_OUTPUT_REGADDR_TO_GPIO, PPS_OUTPUT_REGADDR_TO_GPIO): New
   macros to automatically determine the GPIO port and pin from the
   corresponding PPS (Peripheral Pin Select) define. Since there is a
   one-to-one correspondence between PPS output mappings and a single
   port and pin, these macros avoid writing redundant pin mappings. We
   use this when switching the TX pin from UART to GPIO to generate
   the BREAK and we could use it in other peripheral drivers in the
   future to override hardware behavior.

* arch/mips/src/pic32mz/pic32mz_serial.c
  (struct up_dev_s): Add new field 'brk' to indicate line break in
   progress when built with PIC32MZ_UART_BREAKS. If generating BSD-
   compatible BREAKs, also add tx_gpio, tx_pps_reg, and tx_pps_val, to
   let us toggle the pin between UART and GPIO modes.
  (up_ioctl): Add cases for TIOCSBRK and TIOCCBRK to turn BREAK on and
   off, with both hardware-native and BSD-compatible implementations.
   This is similar to the STM32F7 implementation.
  (up_txint): Block enabling TX interrupt if line break in progress.
   This is similar to the STM32F7 implementation.
@xiaoxiang781216 xiaoxiang781216 merged commit 1d5c838 into apache:master Feb 17, 2023
@hartmannathan hartmannathan deleted the pic32mz-uart-break branch May 24, 2023 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants