amiro-os / modules / NUCLEO-F103RB / module.c @ 243fb4e2
History | View | Annotate | Download (8.76 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 | 4c72a54c | Thomas Schöpping | #include <amiroos.h> |
| 28 | f4da707a | Thomas Schöpping | |
| 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 | 4c72a54c | Thomas Schöpping | #if (BOARD_DW1000_CONNECTED == true) |
| 53 | deaaa47e | Cung Sang | |
| 54 | /*! SPI (high and low speed) configuration for DW1000 */
|
||
| 55 | 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 | /* CR1 */ 0, |
||
| 61 | /* CR2 */ 0, |
||
| 62 | }; |
||
| 63 | |||
| 64 | SPIConfig moduleHalSpiUwbLsConfig = {
|
||
| 65 | /* circular buffer mode */ false, |
||
| 66 | /* callback function pointer */ NULL, |
||
| 67 | /* chip select line port */ GPIOB,
|
||
| 68 | /* chip select line pad number */ GPIOB_PIN12,
|
||
| 69 | /* CR1 */ SPI_CR1_BR_1 | SPI_CR1_BR_0,
|
||
| 70 | /* CR2 */ 0, |
||
| 71 | }; |
||
| 72 | |||
| 73 | 4c72a54c | Thomas Schöpping | #endif /* (BOARD_DW1000_CONNECTED == true) */ |
| 74 | deaaa47e | Cung Sang | |
| 75 | f4da707a | Thomas Schöpping | /** @} */
|
| 76 | |||
| 77 | /*===========================================================================*/
|
||
| 78 | /**
|
||
| 79 | * @name GPIO definitions
|
||
| 80 | * @{
|
||
| 81 | */
|
||
| 82 | /*===========================================================================*/
|
||
| 83 | |||
| 84 | /**
|
||
| 85 | * @brief LED output signal GPIO.
|
||
| 86 | */
|
||
| 87 | static apalGpio_t _gpioLed = {
|
||
| 88 | 4c72a54c | Thomas Schöpping | /* line */ LINE_LED_GREEN,
|
| 89 | f4da707a | Thomas Schöpping | }; |
| 90 | ROMCONST apalControlGpio_t moduleGpioLed = {
|
||
| 91 | /* GPIO */ &_gpioLed,
|
||
| 92 | /* meta */ {
|
||
| 93 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
| 94 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
| 95 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
| 96 | }, |
||
| 97 | }; |
||
| 98 | |||
| 99 | 4c72a54c | Thomas Schöpping | #if (BOARD_DW1000_CONNECTED == true) |
| 100 | deaaa47e | Cung Sang | |
| 101 | /**
|
||
| 102 | * @brief DW1000 reset output signal GPIO.
|
||
| 103 | */
|
||
| 104 | static apalGpio_t _gpioDw1000Reset = {
|
||
| 105 | 3106e8cc | Thomas Schöpping | /* line */ PAL_LINE(GPIOA, GPIOA_ARD_A0),
|
| 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 | /**
|
||
| 118 | * @brief DW1000 interrrupt input signal GPIO.
|
||
| 119 | */
|
||
| 120 | static apalGpio_t _gpioDw1000Irqn = {
|
||
| 121 | 3106e8cc | Thomas Schöpping | /* line */ PAL_LINE(GPIOB, GPIOB_ARD_D6),
|
| 122 | deaaa47e | Cung Sang | }; |
| 123 | ROMCONST apalControlGpio_t moduleGpioDw1000Irqn = {
|
||
| 124 | /* GPIO */ &_gpioDw1000Irqn,
|
||
| 125 | /* meta */ {
|
||
| 126 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
| 127 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
| 128 | /* interrupt edge */ APAL_GPIO_EDGE_RISING,
|
||
| 129 | }, |
||
| 130 | }; |
||
| 131 | |||
| 132 | |||
| 133 | /**
|
||
| 134 | * @brief DW1000 SPI chip select output signal GPIO.
|
||
| 135 | */
|
||
| 136 | static apalGpio_t _gpioSpiChipSelect = {
|
||
| 137 | 3106e8cc | Thomas Schöpping | /* line */ PAL_LINE(GPIOB, GPIOB_PIN12),
|
| 138 | deaaa47e | Cung Sang | }; |
| 139 | ROMCONST apalControlGpio_t moduleGpioSpiChipSelect = {
|
||
| 140 | /* GPIO */ &_gpioSpiChipSelect,
|
||
| 141 | /* meta */ {
|
||
| 142 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
| 143 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
| 144 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
| 145 | }, |
||
| 146 | }; |
||
| 147 | |||
| 148 | 4c72a54c | Thomas Schöpping | #endif /* (BOARD_DW1000_CONNECTED == true) */ |
| 149 | deaaa47e | Cung Sang | |
| 150 | f4da707a | Thomas Schöpping | /**
|
| 151 | * @brief User button input signal GPIO.
|
||
| 152 | */
|
||
| 153 | static apalGpio_t _gpioUserButton = {
|
||
| 154 | 4c72a54c | Thomas Schöpping | /* line */ LINE_BUTTON,
|
| 155 | f4da707a | Thomas Schöpping | }; |
| 156 | ROMCONST apalControlGpio_t moduleGpioUserButton = {
|
||
| 157 | /* GPIO */ &_gpioUserButton,
|
||
| 158 | /* meta */ {
|
||
| 159 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
| 160 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
| 161 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
| 162 | }, |
||
| 163 | }; |
||
| 164 | |||
| 165 | /** @} */
|
||
| 166 | |||
| 167 | /*===========================================================================*/
|
||
| 168 | /**
|
||
| 169 | * @name AMiRo-OS core configurations
|
||
| 170 | * @{
|
||
| 171 | */
|
||
| 172 | /*===========================================================================*/
|
||
| 173 | |||
| 174 | #if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
||
| 175 | ROMCONST char* moduleShellPrompt = "NUCLEO-F103RB"; |
||
| 176 | 7de0cc90 | Thomas Schöpping | #endif /* (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) */ |
| 177 | f4da707a | Thomas Schöpping | |
| 178 | /** @} */
|
||
| 179 | |||
| 180 | /*===========================================================================*/
|
||
| 181 | /**
|
||
| 182 | * @name Startup Shutdown Synchronization Protocol (SSSP)
|
||
| 183 | * @{
|
||
| 184 | */
|
||
| 185 | /*===========================================================================*/
|
||
| 186 | |||
| 187 | 4c72a54c | Thomas Schöpping | /** @} */
|
| 188 | deaaa47e | Cung Sang | |
| 189 | /*===========================================================================*/
|
||
| 190 | /**
|
||
| 191 | * @name Hardware specific wrappers Functions
|
||
| 192 | * @{
|
||
| 193 | */
|
||
| 194 | /*===========================================================================*/
|
||
| 195 | |||
| 196 | 4c72a54c | Thomas Schöpping | #if (BOARD_DW1000_CONNECTED == true) |
| 197 | deaaa47e | Cung Sang | |
| 198 | /*! @brief TODO: Manual implementation of SPI configuration. Somehow, it is necessary in NUCLEO-F103RB */
|
||
| 199 | void dw1000_spi_init(void){ |
||
| 200 | palSetPadMode(GPIOB, GPIOB_PIN13, PAL_MODE_STM32_ALTERNATE_PUSHPULL); |
||
| 201 | palSetPadMode(GPIOB, GPIOB_PIN14, PAL_MODE_STM32_ALTERNATE_PUSHPULL); |
||
| 202 | palSetPadMode(GPIOB, GPIOB_PIN15, PAL_MODE_STM32_ALTERNATE_PUSHPULL); |
||
| 203 | 3106e8cc | Thomas Schöpping | palSetLineMode(moduleGpioSpiChipSelect.gpio->line, PAL_MODE_OUTPUT_PUSHPULL); |
| 204 | deaaa47e | Cung Sang | apalGpioWrite(moduleGpioSpiChipSelect.gpio, APAL_GPIO_LOW); |
| 205 | } |
||
| 206 | |||
| 207 | 4c72a54c | Thomas Schöpping | #endif /* (BOARD_DW1000_CONNECTED == true) */ |
| 208 | f4da707a | Thomas Schöpping | /** @} */
|
| 209 | |||
| 210 | /*===========================================================================*/
|
||
| 211 | /**
|
||
| 212 | * @name Low-level drivers
|
||
| 213 | * @{
|
||
| 214 | */
|
||
| 215 | /*===========================================================================*/
|
||
| 216 | |||
| 217 | 4c72a54c | Thomas Schöpping | LEDDriver moduleLldLed = {
|
| 218 | /* LED enable Gpio */ &moduleGpioLed,
|
||
| 219 | }; |
||
| 220 | |||
| 221 | ButtonDriver moduleLldUserButton = {
|
||
| 222 | /* Button Gpio */ &moduleGpioUserButton,
|
||
| 223 | }; |
||
| 224 | |||
| 225 | #if (BOARD_DW1000_CONNECTED == true) |
||
| 226 | deaaa47e | Cung Sang | |
| 227 | DW1000Driver moduleLldDw1000 = {
|
||
| 228 | /* SPI driver */ &MODULE_HAL_SPI_UWB,
|
||
| 229 | /* ext interrupt */ &moduleGpioDw1000Irqn,
|
||
| 230 | /* RESET DW1000 */ &moduleGpioDw1000Reset,
|
||
| 231 | }; |
||
| 232 | |||
| 233 | 4c72a54c | Thomas Schöpping | #endif /* (BOARD_DW1000_CONNECTED == true) */ |
| 234 | |||
| 235 | f4da707a | Thomas Schöpping | /** @} */
|
| 236 | |||
| 237 | /*===========================================================================*/
|
||
| 238 | /**
|
||
| 239 | 4c72a54c | Thomas Schöpping | * @name Tests
|
| 240 | f4da707a | Thomas Schöpping | * @{
|
| 241 | */
|
||
| 242 | /*===========================================================================*/
|
||
| 243 | #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
||
| 244 | |||
| 245 | 4c72a54c | Thomas Schöpping | /*
|
| 246 | * LED
|
||
| 247 | */
|
||
| 248 | #include <module_test_LED.h> |
||
| 249 | static int _testLedShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[]) |
||
| 250 | {
|
||
| 251 | return moduleTestLedShellCb(stream, argc, argv, NULL); |
||
| 252 | } |
||
| 253 | AOS_SHELL_COMMAND(moduleTestLedShellCmd, "test:LED", _testLedShellCmdCb);
|
||
| 254 | |||
| 255 | /*
|
||
| 256 | * User button
|
||
| 257 | */
|
||
| 258 | #include <module_test_button.h> |
||
| 259 | static int _testButtonShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[]) |
||
| 260 | {
|
||
| 261 | return moduleTestButtonShellCb(stream, argc, argv, NULL); |
||
| 262 | } |
||
| 263 | AOS_SHELL_COMMAND(moduleTestButtonShellCmd, "test:button", _testButtonShellCmdCb);
|
||
| 264 | |||
| 265 | #if (BOARD_DW1000_CONNECTED == true) || defined(__DOXYGEN__) |
||
| 266 | deaaa47e | Cung Sang | |
| 267 | /*
|
||
| 268 | * UwB Driver (DW1000)
|
||
| 269 | */
|
||
| 270 | static int _utShellCmdCb_Dw1000(BaseSequentialStream* stream, int argc, char* argv[]) |
||
| 271 | {
|
||
| 272 | (void)argc;
|
||
| 273 | (void)argv;
|
||
| 274 | aosUtRun(stream, &moduleUtAlldDw1000, NULL);
|
||
| 275 | return AOS_OK;
|
||
| 276 | } |
||
| 277 | aos_unittest_t moduleUtAlldDw1000 = {
|
||
| 278 | /* info */ "DW1000", |
||
| 279 | /* name */ "UWB System", |
||
| 280 | /* test function */ utAlldDw1000Func,
|
||
| 281 | /* shell command */ {
|
||
| 282 | /* name */ "unittest:Uwb", |
||
| 283 | /* callback */ _utShellCmdCb_Dw1000,
|
||
| 284 | /* next */ NULL, |
||
| 285 | }, |
||
| 286 | /* data */ &moduleLldDw1000,
|
||
| 287 | }; |
||
| 288 | 4c72a54c | Thomas Schöpping | #endif /* (BOARD_DW1000_CONNECTED == true) */ |
| 289 | |||
| 290 | /*
|
||
| 291 | * entire module
|
||
| 292 | */
|
||
| 293 | static int _testAllShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[]) |
||
| 294 | {
|
||
| 295 | (void)argc;
|
||
| 296 | (void)argv;
|
||
| 297 | |||
| 298 | int status = AOS_OK;
|
||
| 299 | char* targv[AMIROOS_CFG_SHELL_MAXARGS] = {NULL}; |
||
| 300 | aos_testresult_t result_test = {0, 0};
|
||
| 301 | aos_testresult_t result_total = {0, 0};
|
||
| 302 | |||
| 303 | /* LED */
|
||
| 304 | status |= moduleTestLedShellCb(stream, 0, targv, &result_test);
|
||
| 305 | result_total = aosTestResultAdd(result_total, result_test); |
||
| 306 | |||
| 307 | /* User button */
|
||
| 308 | status |= moduleTestButtonShellCb(stream, 0, targv, &result_test);
|
||
| 309 | result_total = aosTestResultAdd(result_total, result_test); |
||
| 310 | |||
| 311 | /* DW1000 */
|
||
| 312 | //TODO
|
||
| 313 | |||
| 314 | // print total result
|
||
| 315 | chprintf(stream, "\n");
|
||
| 316 | aosTestResultPrintSummary(stream, &result_total, "entire module");
|
||
| 317 | |||
| 318 | return status;
|
||
| 319 | } |
||
| 320 | AOS_SHELL_COMMAND(moduleTestAllShellCmd, "test:all", _testAllShellCmdCb);
|
||
| 321 | deaaa47e | Cung Sang | |
| 322 | 7de0cc90 | Thomas Schöpping | #endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */ |
| 323 | f4da707a | Thomas Schöpping | |
| 324 | /** @} */
|
||
| 325 | /** @} */ |