amiro-os / modules / LightRing_1-0 / module.c @ ffbd63e4
History | View | Annotate | Download (9.555 KB)
| 1 | e545e620 | Thomas Schöpping | /*
|
|---|---|---|---|
| 2 | AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
||
| 3 | 84f0ce9e | Thomas Schöpping | Copyright (C) 2016..2019 Thomas Schöpping et al.
|
| 4 | e545e620 | Thomas Schöpping | |
| 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 | 27286ba5 | Thomas Schöpping | /**
|
| 20 | * @file
|
||
| 21 | * @brief Structures and constant for the LightRing v1.0 module.
|
||
| 22 | *
|
||
| 23 | * @addtogroup lightring_module
|
||
| 24 | * @{
|
||
| 25 | */
|
||
| 26 | |||
| 27 | e545e620 | Thomas Schöpping | #include "module.h" |
| 28 | |||
| 29 | 1e5f7648 | Thomas Schöpping | #include <amiroos.h> |
| 30 | |||
| 31 | e545e620 | Thomas Schöpping | /*===========================================================================*/
|
| 32 | /**
|
||
| 33 | * @name Module specific functions
|
||
| 34 | * @{
|
||
| 35 | */
|
||
| 36 | /*===========================================================================*/
|
||
| 37 | |||
| 38 | /** @} */
|
||
| 39 | |||
| 40 | /*===========================================================================*/
|
||
| 41 | /**
|
||
| 42 | * @name ChibiOS/HAL configuration
|
||
| 43 | * @{
|
||
| 44 | */
|
||
| 45 | /*===========================================================================*/
|
||
| 46 | |||
| 47 | CANConfig moduleHalCanConfig = {
|
||
| 48 | /* mcr */ CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
|
||
| 49 | /* btr */ CAN_BTR_SJW(1) | CAN_BTR_TS2(2) | CAN_BTR_TS1(13) | CAN_BTR_BRP(1), |
||
| 50 | }; |
||
| 51 | |||
| 52 | I2CConfig moduleHalI2cEepromConfig = {
|
||
| 53 | /* I²C mode */ OPMODE_I2C,
|
||
| 54 | /* frequency */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL) |
||
| 55 | /* duty cycle */ FAST_DUTY_CYCLE_2,
|
||
| 56 | }; |
||
| 57 | |||
| 58 | SerialConfig moduleHalProgIfConfig = {
|
||
| 59 | /* bit rate */ 115200, |
||
| 60 | /* CR1 */ 0, |
||
| 61 | /* CR1 */ 0, |
||
| 62 | /* CR1 */ 0, |
||
| 63 | }; |
||
| 64 | |||
| 65 | SPIConfig moduleHalSpiLightConfig = {
|
||
| 66 | 0128be0f | Marc Rothmann | /* circular buffer mode */ false, |
| 67 | e545e620 | Thomas Schöpping | /* callback function pointer */ NULL, |
| 68 | /* chip select line port */ GPIOC,
|
||
| 69 | /* chip select line pad number */ GPIOC_LIGHT_XLAT,
|
||
| 70 | /* CR1 */ SPI_CR1_BR_0 | SPI_CR1_BR_1,
|
||
| 71 | /* CR2 */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
|
||
| 72 | 22be62dc | Thomas Schöpping | }; |
| 73 | |||
| 74 | 02c29a8f | Thomas Schöpping | SPIConfig moduleHalSpiWlConfig = {
|
| 75 | 22be62dc | Thomas Schöpping | /* circular buffer mode */ false, |
| 76 | /* callback function pointer */ NULL, |
||
| 77 | /* chip select line port */ GPIOB,
|
||
| 78 | /* chip select line pad number */ GPIOB_WL_SS_N,
|
||
| 79 | 02c29a8f | Thomas Schöpping | /* CR1 */ SPI_CR1_BR_0,
|
| 80 | 22be62dc | Thomas Schöpping | /* CR2 */ SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN,
|
| 81 | e545e620 | Thomas Schöpping | }; |
| 82 | |||
| 83 | /*===========================================================================*/
|
||
| 84 | /**
|
||
| 85 | * @name GPIO definitions
|
||
| 86 | * @{
|
||
| 87 | */
|
||
| 88 | /*===========================================================================*/
|
||
| 89 | |||
| 90 | 1e5f7648 | Thomas Schöpping | /**
|
| 91 | * @brief LIGHT_BANK output signal GPIO.
|
||
| 92 | */
|
||
| 93 | static apalGpio_t _gpioLightBlank = {
|
||
| 94 | e545e620 | Thomas Schöpping | /* port */ GPIOA,
|
| 95 | /* pad */ GPIOA_LIGHT_BLANK,
|
||
| 96 | }; |
||
| 97 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioLightBlank = {
|
| 98 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioLightBlank,
|
| 99 | /* meta */ {
|
||
| 100 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
| 101 | /* active state */ TLC5947_LLD_BLANK_ACTIVE_STATE,
|
||
| 102 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
| 103 | }, |
||
| 104 | }; |
||
| 105 | e545e620 | Thomas Schöpping | |
| 106 | 1e5f7648 | Thomas Schöpping | /**
|
| 107 | * @brief LASER_EN output signal GPIO.
|
||
| 108 | */
|
||
| 109 | static apalGpio_t _gpioLaserEn = {
|
||
| 110 | e545e620 | Thomas Schöpping | /* port */ GPIOB,
|
| 111 | /* pad */ GPIOB_LASER_EN,
|
||
| 112 | }; |
||
| 113 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioLaserEn = {
|
| 114 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioLaserEn,
|
| 115 | /* meta */ {
|
||
| 116 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
| 117 | /* active state */ TPS2051B_LLD_ENABLE_ACTIVE_STATE,
|
||
| 118 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
| 119 | }, |
||
| 120 | }; |
||
| 121 | e545e620 | Thomas Schöpping | |
| 122 | 1e5f7648 | Thomas Schöpping | /**
|
| 123 | * @brief LASER_OC input signal GPIO.
|
||
| 124 | */
|
||
| 125 | static apalGpio_t _gpioLaserOc = {
|
||
| 126 | e545e620 | Thomas Schöpping | /* port */ GPIOB,
|
| 127 | /* pad */ GPIOB_LASER_OC_N,
|
||
| 128 | }; |
||
| 129 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioLaserOc = {
|
| 130 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioLaserOc,
|
| 131 | /* meta */ {
|
||
| 132 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
| 133 | /* active state */ TPS2051B_LLD_OVERCURRENT_ACTIVE_STATE,
|
||
| 134 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
| 135 | }, |
||
| 136 | }; |
||
| 137 | e545e620 | Thomas Schöpping | |
| 138 | 1e5f7648 | Thomas Schöpping | /**
|
| 139 | * @brief SYS_UART_DN bidirectional signal GPIO.
|
||
| 140 | */
|
||
| 141 | static apalGpio_t _gpioSysUartDn = {
|
||
| 142 | e545e620 | Thomas Schöpping | /* port */ GPIOB,
|
| 143 | /* pad */ GPIOB_SYS_UART_DN,
|
||
| 144 | }; |
||
| 145 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioSysUartDn = {
|
| 146 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioSysUartDn,
|
| 147 | /* meta */ {
|
||
| 148 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
| 149 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
| 150 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
| 151 | }, |
||
| 152 | }; |
||
| 153 | e545e620 | Thomas Schöpping | |
| 154 | 1e5f7648 | Thomas Schöpping | /**
|
| 155 | * @brief WL_GDO2 input signal GPIO.
|
||
| 156 | */
|
||
| 157 | static apalGpio_t _gpioWlGdo2 = {
|
||
| 158 | e545e620 | Thomas Schöpping | /* port */ GPIOB,
|
| 159 | /* pad */ GPIOB_WL_GDO2,
|
||
| 160 | }; |
||
| 161 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioWlGdo2 = {
|
| 162 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioWlGdo2,
|
| 163 | /* meta */ {
|
||
| 164 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
| 165 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
| 166 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
| 167 | }, |
||
| 168 | }; |
||
| 169 | e545e620 | Thomas Schöpping | |
| 170 | 1e5f7648 | Thomas Schöpping | /**
|
| 171 | * @brief WL_GDO0 input signal GPIO.
|
||
| 172 | */
|
||
| 173 | static apalGpio_t _gpioWlGdo0= {
|
||
| 174 | e545e620 | Thomas Schöpping | /* port */ GPIOB,
|
| 175 | /* pad */ GPIOB_WL_GDO0,
|
||
| 176 | }; |
||
| 177 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioWlGdo0 = {
|
| 178 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioWlGdo0,
|
| 179 | /* meta */ {
|
||
| 180 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
| 181 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
| 182 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
| 183 | }, |
||
| 184 | }; |
||
| 185 | e545e620 | Thomas Schöpping | |
| 186 | 1e5f7648 | Thomas Schöpping | /**
|
| 187 | * @brief LIGHT_XLAT output signal GPIO.
|
||
| 188 | */
|
||
| 189 | static apalGpio_t _gpioLightXlat = {
|
||
| 190 | e545e620 | Thomas Schöpping | /* port */ GPIOC,
|
| 191 | /* pad */ GPIOC_LIGHT_XLAT,
|
||
| 192 | }; |
||
| 193 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioLightXlat = {
|
| 194 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioLightXlat,
|
| 195 | /* meta */ {
|
||
| 196 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
| 197 | /* active state */ TLC5947_LLD_XLAT_ACTIVE_STATE,
|
||
| 198 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
| 199 | }, |
||
| 200 | }; |
||
| 201 | e545e620 | Thomas Schöpping | |
| 202 | 1e5f7648 | Thomas Schöpping | /**
|
| 203 | * @brief SYS_PD bidirectional signal GPIO.
|
||
| 204 | */
|
||
| 205 | static apalGpio_t _gpioSysPd = {
|
||
| 206 | e545e620 | Thomas Schöpping | /* port */ GPIOC,
|
| 207 | /* pad */ GPIOC_SYS_PD_N,
|
||
| 208 | }; |
||
| 209 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioSysPd = {
|
| 210 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioSysPd,
|
| 211 | /* meta */ {
|
||
| 212 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
| 213 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
| 214 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
| 215 | }, |
||
| 216 | }; |
||
| 217 | e545e620 | Thomas Schöpping | |
| 218 | 1e5f7648 | Thomas Schöpping | /**
|
| 219 | * @brief SYS_SYNC bidirectional signal GPIO.
|
||
| 220 | */
|
||
| 221 | static apalGpio_t _gpioSysSync = {
|
||
| 222 | e545e620 | Thomas Schöpping | /* port */ GPIOD,
|
| 223 | /* pad */ GPIOD_SYS_INT_N,
|
||
| 224 | }; |
||
| 225 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioSysSync = {
|
| 226 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioSysSync,
|
| 227 | /* meta */ {
|
||
| 228 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
| 229 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
| 230 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
| 231 | }, |
||
| 232 | }; |
||
| 233 | e545e620 | Thomas Schöpping | |
| 234 | /** @} */
|
||
| 235 | |||
| 236 | /*===========================================================================*/
|
||
| 237 | /**
|
||
| 238 | * @name AMiRo-OS core configurations
|
||
| 239 | * @{
|
||
| 240 | */
|
||
| 241 | /*===========================================================================*/
|
||
| 242 | |||
| 243 | 2dd2e257 | Thomas Schöpping | #if (AMIROOS_CFG_SHELL_ENABLE == true) || (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
| 244 | acc97cbf | Thomas Schöpping | ROMCONST char* moduleShellPrompt = "LightRing"; |
| 245 | 6b53f6bf | Thomas Schöpping | #endif
|
| 246 | |||
| 247 | /** @} */
|
||
| 248 | |||
| 249 | /*===========================================================================*/
|
||
| 250 | /**
|
||
| 251 | * @name Startup Shutdown Synchronization Protocol (SSSP)
|
||
| 252 | * @{
|
||
| 253 | */
|
||
| 254 | /*===========================================================================*/
|
||
| 255 | |||
| 256 | e545e620 | Thomas Schöpping | /** @} */
|
| 257 | |||
| 258 | /*===========================================================================*/
|
||
| 259 | /**
|
||
| 260 | * @name Low-level drivers
|
||
| 261 | * @{
|
||
| 262 | */
|
||
| 263 | /*===========================================================================*/
|
||
| 264 | |||
| 265 | AT24C01BNDriver moduleLldEeprom = {
|
||
| 266 | /* I2C driver */ &MODULE_HAL_I2C_EEPROM,
|
||
| 267 | /* I2C address */ 0x00u, |
||
| 268 | }; |
||
| 269 | |||
| 270 | TLC5947Driver moduleLldLedPwm = {
|
||
| 271 | /* SPI driver */ &MODULE_HAL_SPI_LIGHT,
|
||
| 272 | 1e5f7648 | Thomas Schöpping | /* BLANK signal GPIO */ &moduleGpioLightBlank,
|
| 273 | /* XLAT signal GPIO */ &moduleGpioLightXlat,
|
||
| 274 | e545e620 | Thomas Schöpping | }; |
| 275 | |||
| 276 | TPS2051BDriver moduleLldPowerSwitchLaser = {
|
||
| 277 | 1e5f7648 | Thomas Schöpping | /* laser enable GPIO */ &moduleGpioLaserEn,
|
| 278 | /* laser overcurrent GPIO */ &moduleGpioLaserOc,
|
||
| 279 | e545e620 | Thomas Schöpping | }; |
| 280 | |||
| 281 | /** @} */
|
||
| 282 | |||
| 283 | /*===========================================================================*/
|
||
| 284 | /**
|
||
| 285 | * @name Unit tests (UT)
|
||
| 286 | * @{
|
||
| 287 | */
|
||
| 288 | /*===========================================================================*/
|
||
| 289 | #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
||
| 290 | |||
| 291 | 8be006e0 | Thomas Schöpping | /*
|
| 292 | * EEPROM (AT24C01BN)
|
||
| 293 | */
|
||
| 294 | e545e620 | Thomas Schöpping | static int _utShellCmdCb_AlldAt24c01bn(BaseSequentialStream* stream, int argc, char* argv[]) |
| 295 | {
|
||
| 296 | (void)argc;
|
||
| 297 | (void)argv;
|
||
| 298 | aosUtRun(stream, &moduleUtAlldAt24c01bn, NULL);
|
||
| 299 | return AOS_OK;
|
||
| 300 | } |
||
| 301 | static ut_at24c01bndata_t _utAt24c01bnData = {
|
||
| 302 | /* driver */ &moduleLldEeprom,
|
||
| 303 | /* timeout */ MICROSECONDS_PER_SECOND,
|
||
| 304 | }; |
||
| 305 | aos_unittest_t moduleUtAlldAt24c01bn = {
|
||
| 306 | /* name */ "AT24C01BN-SH-B", |
||
| 307 | /* info */ "1kbit EEPROM", |
||
| 308 | /* test function */ utAlldAt24c01bnFunc,
|
||
| 309 | /* shell command */ {
|
||
| 310 | /* name */ "unittest:EEPROM", |
||
| 311 | /* callback */ _utShellCmdCb_AlldAt24c01bn,
|
||
| 312 | /* next */ NULL, |
||
| 313 | }, |
||
| 314 | /* data */ &_utAt24c01bnData,
|
||
| 315 | }; |
||
| 316 | |||
| 317 | 8be006e0 | Thomas Schöpping | /*
|
| 318 | * LED PWM driver (TLD5947)
|
||
| 319 | */
|
||
| 320 | e545e620 | Thomas Schöpping | static int _utShellCmdCb_Tlc5947(BaseSequentialStream* stream, int argc, char* argv[]) |
| 321 | {
|
||
| 322 | (void)argc;
|
||
| 323 | (void)argv;
|
||
| 324 | aosUtRun(stream, &moduleUtAlldTlc5947, NULL);
|
||
| 325 | return AOS_OK;
|
||
| 326 | } |
||
| 327 | aos_unittest_t moduleUtAlldTlc5947 = {
|
||
| 328 | /* info */ "TLC5947", |
||
| 329 | /* name */ "LED PWM driver", |
||
| 330 | /* test function */ utAlldTlc5947Func,
|
||
| 331 | /* shell command */ {
|
||
| 332 | /* name */ "unittest:Lights", |
||
| 333 | /* callback */ _utShellCmdCb_Tlc5947,
|
||
| 334 | /* next */ NULL, |
||
| 335 | }, |
||
| 336 | /* data */ &moduleLldLedPwm,
|
||
| 337 | }; |
||
| 338 | |||
| 339 | 8be006e0 | Thomas Schöpping | /*
|
| 340 | * power switch (Laser)
|
||
| 341 | */
|
||
| 342 | e545e620 | Thomas Schöpping | static int _utShellCmdCb_Tps2051bdbv(BaseSequentialStream* stream, int argc, char* argv[]) |
| 343 | {
|
||
| 344 | (void)argc;
|
||
| 345 | (void)argv;
|
||
| 346 | aosUtRun(stream,&moduleUtAlldTps2051bdbv, NULL);
|
||
| 347 | return AOS_OK;
|
||
| 348 | } |
||
| 349 | aos_unittest_t moduleUtAlldTps2051bdbv = {
|
||
| 350 | /* info */ "TPS2051BDBV", |
||
| 351 | /* name */ "current-limited power switch", |
||
| 352 | /* test function */ utAlldTps2051bdbvFunc,
|
||
| 353 | /* shell command */ {
|
||
| 354 | /* name */ "unittest:PowerSwitch", |
||
| 355 | /* callback */ _utShellCmdCb_Tps2051bdbv,
|
||
| 356 | /* next */ NULL, |
||
| 357 | }, |
||
| 358 | /* data */ &moduleLldPowerSwitchLaser,
|
||
| 359 | }; |
||
| 360 | |||
| 361 | #endif /* AMIROOS_CFG_TESTS_ENABLE == true */ |
||
| 362 | |||
| 363 | /** @} */ |