reset_lgw.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/sh
  2. # This script is intended to be used on SX1302 CoreCell platform, it performs
  3. # the following actions:
  4. # - export/unpexort GPIO23 and GPIO18 used to reset the SX1302 chip and to enable the LDOs
  5. # - export/unexport GPIO22 used to reset the optional SX1261 radio used for LBT/Spectral Scan
  6. #
  7. # Usage examples:
  8. # ./reset_lgw.sh stop
  9. # ./reset_lgw.sh start
  10. # GPIO mapping has to be adapted with HW
  11. #
  12. SX1302_RESET_PIN=53 # SX1302 reset
  13. #SX1302_POWER_EN_PIN=18 # SX1302 power enable
  14. #SX1261_RESET_PIN=22 # SX1261 reset (LBT / Spectral Scan)
  15. #AD5338R_RESET_PIN=13 # AD5338R reset (full-duplex CN490 reference design)
  16. WAIT_GPIO() {
  17. sleep 0.1
  18. }
  19. init() {
  20. # setup GPIOs
  21. echo "$SX1302_RESET_PIN" > /sys/class/gpio/export; WAIT_GPIO
  22. #echo "$SX1261_RESET_PIN" > /sys/class/gpio/export; WAIT_GPIO
  23. #echo "$SX1302_POWER_EN_PIN" > /sys/class/gpio/export; WAIT_GPIO
  24. #echo "$AD5338R_RESET_PIN" > /sys/class/gpio/export; WAIT_GPIO
  25. # set GPIOs as output
  26. echo "out" > /sys/class/gpio/gpio$SX1302_RESET_PIN/direction; WAIT_GPIO
  27. #echo "out" > /sys/class/gpio/gpio$SX1261_RESET_PIN/direction; WAIT_GPIO
  28. #echo "out" > /sys/class/gpio/gpio$SX1302_POWER_EN_PIN/direction; WAIT_GPIO
  29. #echo "out" > /sys/class/gpio/gpio$AD5338R_RESET_PIN/direction; WAIT_GPIO
  30. }
  31. reset() {
  32. echo "CoreCell reset through GPIO$SX1302_RESET_PIN..."
  33. #echo "SX1261 reset through GPIO$SX1302_RESET_PIN..."
  34. #echo "CoreCell power enable through GPIO$SX1302_POWER_EN_PIN..."
  35. #echo "CoreCell ADC reset through GPIO$AD5338R_RESET_PIN..."
  36. # write output for SX1302 CoreCell power_enable and reset
  37. #echo "1" > /sys/class/gpio/gpio$SX1302_POWER_EN_PIN/value; WAIT_GPIO
  38. echo "1" > /sys/class/gpio/gpio$SX1302_RESET_PIN/value; WAIT_GPIO
  39. echo "0" > /sys/class/gpio/gpio$SX1302_RESET_PIN/value; WAIT_GPIO
  40. #echo "0" > /sys/class/gpio/gpio$SX1261_RESET_PIN/value; WAIT_GPIO
  41. #echo "1" > /sys/class/gpio/gpio$SX1261_RESET_PIN/value; WAIT_GPIO
  42. #echo "0" > /sys/class/gpio/gpio$AD5338R_RESET_PIN/value; WAIT_GPIO
  43. #echo "1" > /sys/class/gpio/gpio$AD5338R_RESET_PIN/value; WAIT_GPIO
  44. }
  45. term() {
  46. # cleanup all GPIOs
  47. if [ -d /sys/class/gpio/gpio$SX1302_RESET_PIN ]
  48. then
  49. echo "$SX1302_RESET_PIN" > /sys/class/gpio/unexport; WAIT_GPIO
  50. fi
  51. #if [ -d /sys/class/gpio/gpio$SX1261_RESET_PIN ]
  52. #then
  53. # echo "$SX1261_RESET_PIN" > /sys/class/gpio/unexport; WAIT_GPIO
  54. #fi
  55. #if [ -d /sys/class/gpio/gpio$SX1302_POWER_EN_PIN ]
  56. #then
  57. # echo "$SX1302_POWER_EN_PIN" > /sys/class/gpio/unexport; WAIT_GPIO
  58. #fi
  59. #if [ -d /sys/class/gpio/gpio$AD5338R_RESET_PIN ]
  60. #then
  61. # echo "$AD5338R_RESET_PIN" > /sys/class/gpio/unexport; WAIT_GPIO
  62. #fi
  63. }
  64. case "$1" in
  65. start)
  66. term # just in case
  67. init
  68. reset
  69. ;;
  70. stop)
  71. reset
  72. term
  73. ;;
  74. *)
  75. echo "Usage: $0 {start|stop}"
  76. exit 1
  77. ;;
  78. esac
  79. exit 0