Yang Chen | 27dbef0 | 2023-12-08 20:36:52 +0800 | [diff] [blame] | 1 | #!/bin/bash -e |
| 2 | # shellcheck source=meta-facebook/meta-minerva/recipes-minerva/plat-tool/files/minerva-common-functions |
| 3 | # Select UART Mux: UART Mux for switching between MTIA blade 0~15 |
| 4 | # Usage: select-uart-mux <0-15> |
| 5 | source /usr/libexec/minerva-common-functions |
| 6 | |
| 7 | convert_decimal_to_binary() { |
| 8 | decimal=$1 |
| 9 | |
| 10 | binary="" |
| 11 | for ((i = 3; i >= 0; i--)); do |
| 12 | bit=$(( (decimal >> i) & 1 )) |
| 13 | binary="${binary}${bit}" |
| 14 | done |
| 15 | |
| 16 | echo "$binary" |
| 17 | } |
| 18 | |
| 19 | uart_mux_select() |
| 20 | { |
| 21 | local BLADE_INDEX=$1 |
| 22 | |
| 23 | if ((BLADE_INDEX >= 0)) && ((BLADE_INDEX < 16)); then |
| 24 | BINARY_INDEX=$(convert_decimal_to_binary "$BLADE_INDEX") |
| 25 | |
| 26 | set_gpio BLADE_UART_SEL0 "${BINARY_INDEX:3:1}" |
| 27 | set_gpio BLADE_UART_SEL1 "${BINARY_INDEX:2:1}" |
| 28 | set_gpio BLADE_UART_SEL2 "${BINARY_INDEX:1:1}" |
| 29 | set_gpio BLADE_UART_SEL3 "${BINARY_INDEX:0:1}" |
| 30 | else |
| 31 | logger -p user.info "uart_mux_select: unknow blade index ($BLADE_INDEX)" |
| 32 | return 1 |
| 33 | fi |
| 34 | |
| 35 | return 0 |
| 36 | } |
| 37 | |
| 38 | BLADE_INDEX=$1 |
| 39 | uart_mux_select "$BLADE_INDEX" |