amiro-os / modules / NUCLEO-F103RB / module.c @ 908b6fb4
History | View | Annotate | Download (7.61 KB)
| 1 | f4da707a | Thomas Schöpping | /*
|
|---|---|---|---|
| 2 | AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
||
| 3 | Copyright (C) 2016..2019 Thomas Schöpping et al.
|
||
| 4 | |||
| 5 | This program is free software: you can redistribute it and/or modify
|
||
| 6 | it under the terms of the GNU General Public License as published by
|
||
| 7 | the Free Software Foundation, either version 3 of the License, or
|
||
| 8 | (at your option) any later version.
|
||
| 9 | |||
| 10 | This program is distributed in the hope that it will be useful,
|
||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
| 13 | GNU General Public License for more details.
|
||
| 14 | |||
| 15 | You should have received a copy of the GNU General Public License
|
||
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
| 17 | */
|
||
| 18 | |||
| 19 | /**
|
||
| 20 | * @file
|
||
| 21 | * @brief Structures and constant for the NUCLEO-F103RB module.
|
||
| 22 | *
|
||
| 23 | * @addtogroup NUCLEO-F103RB_module
|
||
| 24 | * @{
|
||
| 25 | */
|
||
| 26 | |||
| 27 | #include "module.h" |
||
| 28 | |||
| 29 | /*===========================================================================*/
|
||
| 30 | /**
|
||
| 31 | * @name Module specific functions
|
||
| 32 | * @{
|
||
| 33 | */
|
||
| 34 | /*===========================================================================*/
|
||
| 35 | |||
| 36 | /** @} */
|
||
| 37 | |||
| 38 | /*===========================================================================*/
|
||
| 39 | /**
|
||
| 40 | * @name ChibiOS/HAL configuration
|
||
| 41 | * @{
|
||
| 42 | */
|
||
| 43 | /*===========================================================================*/
|
||
| 44 | |||
| 45 | SerialConfig moduleHalProgIfConfig = {
|
||
| 46 | /* bit rate */ 115200, |
||
| 47 | /* CR1 */ 0, |
||
| 48 | /* CR1 */ 0, |
||
| 49 | /* CR1 */ 0, |
||
| 50 | }; |
||
| 51 | |||
| 52 | 7de0cc90 | Thomas Schöpping | #if defined(AMIROLLD_CFG_DW1000)
|
| 53 | deaaa47e | Cung Sang | |
| 54 | 0ecf4119 | Cung Sang | /*! SPI (high speed) configuration for DW1000 */
|
| 55 | deaaa47e | Cung Sang | SPIConfig moduleHalSpiUwbHsConfig = {
|
| 56 | /* circular buffer mode */ false, |
||
| 57 | /* callback function pointer */ NULL, |
||
| 58 | /* chip select line port */ GPIOB,
|
||
| 59 | /* chip select line pad number */ GPIOB_PIN12,
|
||
| 60 | 0ecf4119 | Cung Sang | /* CR1 */ 0, // 32/2 Mbps |
| 61 | /* CR2 */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
|
||
| 62 | deaaa47e | Cung Sang | }; |
| 63 | |||
| 64 | 0ecf4119 | Cung Sang | /*! SPI (low speed) configuration for DW1000 */
|
| 65 | deaaa47e | Cung Sang | SPIConfig moduleHalSpiUwbLsConfig = {
|
| 66 | /* circular buffer mode */ false, |
||
| 67 | /* callback function pointer */ NULL, |
||
| 68 | /* chip select line port */ GPIOB,
|
||
| 69 | /* chip select line pad number */ GPIOB_PIN12,
|
||
| 70 | 0ecf4119 | Cung Sang | /* CR1 */ SPI_CR1_BR_1 | SPI_CR1_BR_0, // 32/16 Mbps |
| 71 | /* CR2 */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
|
||
| 72 | deaaa47e | Cung Sang | }; |
| 73 | |||
| 74 | 7de0cc90 | Thomas Schöpping | #endif /* defined(AMIROLLD_CFG_DW1000) */ |
| 75 | deaaa47e | Cung Sang | |
| 76 | f4da707a | Thomas Schöpping | /** @} */
|
| 77 | |||
| 78 | /*===========================================================================*/
|
||
| 79 | /**
|
||
| 80 | * @name GPIO definitions
|
||
| 81 | * @{
|
||
| 82 | */
|
||
| 83 | /*===========================================================================*/
|
||
| 84 | |||
| 85 | /**
|
||
| 86 | * @brief LED output signal GPIO.
|
||
| 87 | */
|
||
| 88 | static apalGpio_t _gpioLed = {
|
||
| 89 | 3106e8cc | Thomas Schöpping | /* line */ PAL_LINE(GPIOA, GPIOA_LED_GREEN),
|
| 90 | f4da707a | Thomas Schöpping | }; |
| 91 | ROMCONST apalControlGpio_t moduleGpioLed = {
|
||
| 92 | /* GPIO */ &_gpioLed,
|
||
| 93 | /* meta */ {
|
||
| 94 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
| 95 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
| 96 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
| 97 | }, |
||
| 98 | }; |
||
| 99 | |||
| 100 | 7de0cc90 | Thomas Schöpping | #if defined(AMIROLLD_CFG_DW1000)
|
| 101 | deaaa47e | Cung Sang | /**
|
| 102 | * @brief DW1000 reset output signal GPIO.
|
||
| 103 | */
|
||
| 104 | static apalGpio_t _gpioDw1000Reset = {
|
||
| 105 | 0ecf4119 | Cung Sang | /* line */ LINE_ARD_D15, // PAL_LINE(GPIOB, GPIOB_ARD_D15) |
| 106 | deaaa47e | Cung Sang | }; |
| 107 | ROMCONST apalControlGpio_t moduleGpioDw1000Reset = {
|
||
| 108 | /* GPIO */ &_gpioDw1000Reset,
|
||
| 109 | /* meta */ {
|
||
| 110 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
| 111 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
| 112 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
| 113 | }, |
||
| 114 | }; |
||
| 115 | |||
| 116 | /**
|
||
| 117 | * @brief DW1000 interrrupt input signal GPIO.
|
||
| 118 | */
|
||
| 119 | static apalGpio_t _gpioDw1000Irqn = {
|
||
| 120 | 0ecf4119 | Cung Sang | /* line */ LINE_ARD_D14, // PAL_LINE(GPIOB, GPIOB_ARD_D14) |
| 121 | deaaa47e | Cung Sang | }; |
| 122 | ROMCONST apalControlGpio_t moduleGpioDw1000Irqn = {
|
||
| 123 | /* GPIO */ &_gpioDw1000Irqn,
|
||
| 124 | /* meta */ {
|
||
| 125 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
| 126 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
| 127 | /* interrupt edge */ APAL_GPIO_EDGE_RISING,
|
||
| 128 | }, |
||
| 129 | }; |
||
| 130 | |||
| 131 | /**
|
||
| 132 | * @brief DW1000 SPI chip select output signal GPIO.
|
||
| 133 | */
|
||
| 134 | static apalGpio_t _gpioSpiChipSelect = {
|
||
| 135 | 3106e8cc | Thomas Schöpping | /* line */ PAL_LINE(GPIOB, GPIOB_PIN12),
|
| 136 | deaaa47e | Cung Sang | }; |
| 137 | ROMCONST apalControlGpio_t moduleGpioSpiChipSelect = {
|
||
| 138 | /* GPIO */ &_gpioSpiChipSelect,
|
||
| 139 | /* meta */ {
|
||
| 140 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
| 141 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
| 142 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
| 143 | }, |
||
| 144 | }; |
||
| 145 | |||
| 146 | 7de0cc90 | Thomas Schöpping | #endif /* defined(AMIROLLD_CFG_DW1000) */ |
| 147 | deaaa47e | Cung Sang | |
| 148 | f4da707a | Thomas Schöpping | /**
|
| 149 | * @brief User button input signal GPIO.
|
||
| 150 | */
|
||
| 151 | static apalGpio_t _gpioUserButton = {
|
||
| 152 | 3106e8cc | Thomas Schöpping | /* line */ PAL_LINE(GPIOC, GPIOC_BUTTON),
|
| 153 | f4da707a | Thomas Schöpping | }; |
| 154 | ROMCONST apalControlGpio_t moduleGpioUserButton = {
|
||
| 155 | /* GPIO */ &_gpioUserButton,
|
||
| 156 | /* meta */ {
|
||
| 157 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
| 158 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
| 159 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
| 160 | }, |
||
| 161 | }; |
||
| 162 | |||
| 163 | /** @} */
|
||
| 164 | |||
| 165 | /*===========================================================================*/
|
||
| 166 | /**
|
||
| 167 | * @name AMiRo-OS core configurations
|
||
| 168 | * @{
|
||
| 169 | */
|
||
| 170 | /*===========================================================================*/
|
||
| 171 | |||
| 172 | #if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
||
| 173 | ROMCONST char* moduleShellPrompt = "NUCLEO-F103RB"; |
||
| 174 | 7de0cc90 | Thomas Schöpping | #endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */ |
| 175 | f4da707a | Thomas Schöpping | |
| 176 | /** @} */
|
||
| 177 | |||
| 178 | /*===========================================================================*/
|
||
| 179 | /**
|
||
| 180 | * @name Startup Shutdown Synchronization Protocol (SSSP)
|
||
| 181 | * @{
|
||
| 182 | */
|
||
| 183 | /*===========================================================================*/
|
||
| 184 | |||
| 185 | deaaa47e | Cung Sang | |
| 186 | /*===========================================================================*/
|
||
| 187 | /**
|
||
| 188 | * @name Hardware specific wrappers Functions
|
||
| 189 | * @{
|
||
| 190 | */
|
||
| 191 | /*===========================================================================*/
|
||
| 192 | |||
| 193 | 7de0cc90 | Thomas Schöpping | #if defined(AMIROLLD_CFG_DW1000)
|
| 194 | deaaa47e | Cung Sang | |
| 195 | /*! @brief TODO: Manual implementation of SPI configuration. Somehow, it is necessary in NUCLEO-F103RB */
|
||
| 196 | void dw1000_spi_init(void){ |
||
| 197 | palSetPadMode(GPIOB, GPIOB_PIN13, PAL_MODE_STM32_ALTERNATE_PUSHPULL); |
||
| 198 | palSetPadMode(GPIOB, GPIOB_PIN14, PAL_MODE_STM32_ALTERNATE_PUSHPULL); |
||
| 199 | palSetPadMode(GPIOB, GPIOB_PIN15, PAL_MODE_STM32_ALTERNATE_PUSHPULL); |
||
| 200 | 3106e8cc | Thomas Schöpping | palSetLineMode(moduleGpioSpiChipSelect.gpio->line, PAL_MODE_OUTPUT_PUSHPULL); |
| 201 | deaaa47e | Cung Sang | apalGpioWrite(moduleGpioSpiChipSelect.gpio, APAL_GPIO_LOW); |
| 202 | } |
||
| 203 | |||
| 204 | 7de0cc90 | Thomas Schöpping | #endif /* defined(AMIROLLD_CFG_DW1000) */ |
| 205 | f4da707a | Thomas Schöpping | /** @} */
|
| 206 | |||
| 207 | /*===========================================================================*/
|
||
| 208 | /**
|
||
| 209 | * @name Low-level drivers
|
||
| 210 | * @{
|
||
| 211 | */
|
||
| 212 | /*===========================================================================*/
|
||
| 213 | |||
| 214 | 7de0cc90 | Thomas Schöpping | #if defined(AMIROLLD_CFG_DW1000)
|
| 215 | deaaa47e | Cung Sang | |
| 216 | DW1000Driver moduleLldDw1000 = {
|
||
| 217 | /* SPI driver */ &MODULE_HAL_SPI_UWB,
|
||
| 218 | /* ext interrupt */ &moduleGpioDw1000Irqn,
|
||
| 219 | /* RESET DW1000 */ &moduleGpioDw1000Reset,
|
||
| 220 | }; |
||
| 221 | |||
| 222 | 7de0cc90 | Thomas Schöpping | #endif /* defined(AMIROLLD_CFG_DW1000) */ |
| 223 | f4da707a | Thomas Schöpping | /** @} */
|
| 224 | |||
| 225 | /*===========================================================================*/
|
||
| 226 | /**
|
||
| 227 | * @name Unit tests (UT)
|
||
| 228 | * @{
|
||
| 229 | */
|
||
| 230 | /*===========================================================================*/
|
||
| 231 | #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
||
| 232 | |||
| 233 | 7de0cc90 | Thomas Schöpping | #if defined(AMIROLLD_CFG_DW1000)
|
| 234 | deaaa47e | Cung Sang | |
| 235 | /*
|
||
| 236 | * UwB Driver (DW1000)
|
||
| 237 | */
|
||
| 238 | static int _utShellCmdCb_Dw1000(BaseSequentialStream* stream, int argc, char* argv[]) |
||
| 239 | {
|
||
| 240 | (void)argc;
|
||
| 241 | (void)argv;
|
||
| 242 | 0ecf4119 | Cung Sang | ((ut_dw1000data_t*)moduleUtAlldDw1000.data)->dw1000d = &moduleLldDw1000; |
| 243 | deaaa47e | Cung Sang | aosUtRun(stream, &moduleUtAlldDw1000, NULL);
|
| 244 | return AOS_OK;
|
||
| 245 | } |
||
| 246 | 0ecf4119 | Cung Sang | static ut_dw1000data_t _utAlldDw1000Data = {
|
| 247 | /* dw1000d */ NULL, |
||
| 248 | }; |
||
| 249 | deaaa47e | Cung Sang | aos_unittest_t moduleUtAlldDw1000 = {
|
| 250 | /* info */ "DW1000", |
||
| 251 | /* name */ "UWB System", |
||
| 252 | /* test function */ utAlldDw1000Func,
|
||
| 253 | /* shell command */ {
|
||
| 254 | /* name */ "unittest:Uwb", |
||
| 255 | /* callback */ _utShellCmdCb_Dw1000,
|
||
| 256 | /* next */ NULL, |
||
| 257 | }, |
||
| 258 | 0ecf4119 | Cung Sang | /* data */ &_utAlldDw1000Data, // TODO: &moduleLldDw1000 |
| 259 | deaaa47e | Cung Sang | }; |
| 260 | 7de0cc90 | Thomas Schöpping | #endif /* defined(AMIROLLD_CFG_DW1000) */ |
| 261 | deaaa47e | Cung Sang | |
| 262 | 7de0cc90 | Thomas Schöpping | #endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */ |
| 263 | f4da707a | Thomas Schöpping | |
| 264 | /** @} */
|
||
| 265 | /** @} */ |