amiro-os / modules / LightRing_1-0 / module.h @ 53710ca3
History | View | Annotate | Download (10.081 KB)
| 1 |
/*
|
|---|---|
| 2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
| 3 |
Copyright (C) 2016..2018 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 LightRing module.
|
| 22 |
*
|
| 23 |
* @addtogroup lightring_module
|
| 24 |
* @{
|
| 25 |
*/
|
| 26 |
|
| 27 |
#ifndef _AMIROOS_MODULE_H_
|
| 28 |
#define _AMIROOS_MODULE_H_
|
| 29 |
|
| 30 |
/*===========================================================================*/
|
| 31 |
/**
|
| 32 |
* @name Module specific functions
|
| 33 |
* @{
|
| 34 |
*/
|
| 35 |
/*===========================================================================*/
|
| 36 |
|
| 37 |
/** @} */
|
| 38 |
|
| 39 |
/*===========================================================================*/
|
| 40 |
/**
|
| 41 |
* @name ChibiOS/HAL configuration
|
| 42 |
* @{
|
| 43 |
*/
|
| 44 |
/*===========================================================================*/
|
| 45 |
#include <hal.h> |
| 46 |
|
| 47 |
/**
|
| 48 |
* @brief CAN driver to use.
|
| 49 |
*/
|
| 50 |
#define MODULE_HAL_CAN CAND1
|
| 51 |
|
| 52 |
/**
|
| 53 |
* @brief Configuration for the CAN driver.
|
| 54 |
*/
|
| 55 |
extern CANConfig moduleHalCanConfig;
|
| 56 |
|
| 57 |
/**
|
| 58 |
* @brief I2C driver to access the EEPROM.
|
| 59 |
*/
|
| 60 |
#define MODULE_HAL_I2C_EEPROM I2CD2
|
| 61 |
|
| 62 |
/**
|
| 63 |
* @brief Configuration for the EEPROM I2C driver.
|
| 64 |
*/
|
| 65 |
extern I2CConfig moduleHalI2cEepromConfig;
|
| 66 |
|
| 67 |
/**
|
| 68 |
* @brief Serial driver of the programmer interface.
|
| 69 |
*/
|
| 70 |
#define MODULE_HAL_PROGIF SD1
|
| 71 |
|
| 72 |
/**
|
| 73 |
* @brief Configuration for the programmer serial interface driver.
|
| 74 |
*/
|
| 75 |
extern SerialConfig moduleHalProgIfConfig;
|
| 76 |
|
| 77 |
/**
|
| 78 |
* @brief SPI interface driver for the motion sensors (gyroscope and accelerometer).
|
| 79 |
*/
|
| 80 |
#define MODULE_HAL_SPI_LIGHT SPID1
|
| 81 |
|
| 82 |
/**
|
| 83 |
* @brief Configuration for the SPI interface driver to communicate with the LED driver.
|
| 84 |
*/
|
| 85 |
extern SPIConfig moduleHalSpiLightConfig;
|
| 86 |
|
| 87 |
/**
|
| 88 |
* @brief Real-Time Clock driver.
|
| 89 |
*/
|
| 90 |
#define MODULE_HAL_RTC RTCD1
|
| 91 |
|
| 92 |
/** @} */
|
| 93 |
|
| 94 |
/*===========================================================================*/
|
| 95 |
/**
|
| 96 |
* @name GPIO definitions
|
| 97 |
* @{
|
| 98 |
*/
|
| 99 |
/*===========================================================================*/
|
| 100 |
#include <amiro-lld.h> |
| 101 |
|
| 102 |
/**
|
| 103 |
* @brief LIGHT_BANK output signal GPIO.
|
| 104 |
*/
|
| 105 |
extern apalControlGpio_t moduleGpioLightBlank;
|
| 106 |
|
| 107 |
/**
|
| 108 |
* @brief LASER_EN output signal GPIO.
|
| 109 |
*/
|
| 110 |
extern apalControlGpio_t moduleGpioLaserEn;
|
| 111 |
|
| 112 |
/**
|
| 113 |
* @brief LASER_OC input signal GPIO.
|
| 114 |
*/
|
| 115 |
extern apalControlGpio_t moduleGpioLaserOc;
|
| 116 |
|
| 117 |
/**
|
| 118 |
* @brief SYS_UART_DN bidirectional signal GPIO.
|
| 119 |
*/
|
| 120 |
extern apalControlGpio_t moduleGpioSysUartDn;
|
| 121 |
|
| 122 |
/**
|
| 123 |
* @brief WL_GDO2 input signal GPIO.
|
| 124 |
*/
|
| 125 |
extern apalControlGpio_t moduleGpioWlGdo2;
|
| 126 |
|
| 127 |
/**
|
| 128 |
* @brief WL_GDO0 input signal GPIO.
|
| 129 |
*/
|
| 130 |
extern apalControlGpio_t moduleGpioWlGdo0;
|
| 131 |
|
| 132 |
/**
|
| 133 |
* @brief LIGHT_XLAT output signal GPIO.
|
| 134 |
*/
|
| 135 |
extern apalControlGpio_t moduleGpioLightXlat;
|
| 136 |
|
| 137 |
/**
|
| 138 |
* @brief SYS_PD bidirectional signal GPIO.
|
| 139 |
*/
|
| 140 |
extern apalControlGpio_t moduleGpioSysPd;
|
| 141 |
|
| 142 |
/**
|
| 143 |
* @brief SYS_SYNC bidirectional signal GPIO.
|
| 144 |
*/
|
| 145 |
extern apalControlGpio_t moduleGpioSysSync;
|
| 146 |
|
| 147 |
/** @} */
|
| 148 |
|
| 149 |
/*===========================================================================*/
|
| 150 |
/**
|
| 151 |
* @name AMiRo-OS core configurations
|
| 152 |
* @{
|
| 153 |
*/
|
| 154 |
/*===========================================================================*/
|
| 155 |
|
| 156 |
/**
|
| 157 |
* @brief Event flag to be set on a LASER_OC interrupt.
|
| 158 |
*/
|
| 159 |
#define MODULE_OS_IOEVENTFLAGS_LASEROC ((eventflags_t)1 << GPIOB_LASER_OC_N) |
| 160 |
|
| 161 |
/**
|
| 162 |
* @brief Event flag to be set on a SYS_UART_DN interrupt.
|
| 163 |
*/
|
| 164 |
#define MODULE_OS_IOEVENTFLAGS_SYSUARTDN ((eventflags_t)1 << GPIOB_SYS_UART_DN) |
| 165 |
|
| 166 |
/**
|
| 167 |
* @brief Event flag to be set on a WL_GDO2 interrupt.
|
| 168 |
*/
|
| 169 |
#define MODULE_OS_IOEVENTFLAGS_WLGDO2 ((eventflags_t)1 << GPIOB_WL_GDO2) |
| 170 |
|
| 171 |
/**
|
| 172 |
* @brief Event flag to be set on a WL_GDO0 interrupt.
|
| 173 |
*/
|
| 174 |
#define MODULE_OS_IOEVENTFLAGS_WLGDO0 ((eventflags_t)1 << GPIOB_WL_GDO0) |
| 175 |
|
| 176 |
/**
|
| 177 |
* @brief Event flag to be set on a SYS_PD interrupt.
|
| 178 |
*/
|
| 179 |
#define MODULE_OS_IOEVENTFLAGS_SYSPD ((eventflags_t)1 << GPIOC_SYS_PD_N) |
| 180 |
|
| 181 |
/**
|
| 182 |
* @brief Event flag to be set on a SYS_SYNC interrupt.
|
| 183 |
*/
|
| 184 |
#define MODULE_OS_IOEVENTFLAGS_SYSSYNC ((eventflags_t)1 << GPIOD_SYS_INT_N) |
| 185 |
|
| 186 |
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__) |
| 187 |
/**
|
| 188 |
* @brief Shell prompt text.
|
| 189 |
*/
|
| 190 |
extern const char* moduleShellPrompt; |
| 191 |
#endif
|
| 192 |
|
| 193 |
/**
|
| 194 |
* @brief Interrupt initialization macro.
|
| 195 |
* @note SSSP related interrupt signals are already initialized in 'aos_system.c'.
|
| 196 |
*/
|
| 197 |
#define MODULE_INIT_INTERRUPTS() { \
|
| 198 |
/* LASER_OC */ \
|
| 199 |
palSetPadCallback(moduleGpioLaserOc.gpio->port, moduleGpioLaserOc.gpio->pad, _intCallback, &moduleGpioLaserOc.gpio->pad); \ |
| 200 |
palEnablePadEvent(moduleGpioLaserOc.gpio->port, moduleGpioLaserOc.gpio->pad, APAL2CH_EDGE(moduleGpioLaserOc.meta.edge)); \ |
| 201 |
/* WL_GDO2 */ \
|
| 202 |
palSetPadCallback(moduleGpioWlGdo2.gpio->port, moduleGpioWlGdo2.gpio->pad, _intCallback, &moduleGpioWlGdo2.gpio->pad); \ |
| 203 |
palEnablePadEvent(moduleGpioWlGdo2.gpio->port, moduleGpioWlGdo2.gpio->pad, APAL2CH_EDGE(moduleGpioWlGdo2.meta.edge)); \ |
| 204 |
/* WL_GDO0 */ \
|
| 205 |
palSetPadCallback(moduleGpioWlGdo0.gpio->port, moduleGpioWlGdo0.gpio->pad, _intCallback, &moduleGpioWlGdo0.gpio->pad); \ |
| 206 |
/*palEnablePadEvent(moduleGpioWlGdo0.gpio->port, moduleGpioWlGdo0.gpio->pad, APAL2CH_EDGE(moduleGpioWlGdo0.meta.edge)); // this is broken for some reason*/ \
|
| 207 |
} |
| 208 |
|
| 209 |
/**
|
| 210 |
* @brief Unit test initialization hook.
|
| 211 |
*/
|
| 212 |
#define MODULE_INIT_TESTS() { \
|
| 213 |
/* add unit-test shell commands */ \
|
| 214 |
aosShellAddCommand(&aos.shell, &moduleUtAlldAt24c01bn.shellcmd); \ |
| 215 |
aosShellAddCommand(&aos.shell, &moduleUtAlldTlc5947.shellcmd); \ |
| 216 |
aosShellAddCommand(&aos.shell, &moduleUtAlldTps2051bdbv.shellcmd); \ |
| 217 |
} |
| 218 |
|
| 219 |
/**
|
| 220 |
* @brief Periphery communication interfaces initialization hook.
|
| 221 |
*/
|
| 222 |
#define MODULE_INIT_PERIPHERY_COMM() { \
|
| 223 |
/* serial driver */ \
|
| 224 |
sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig); \ |
| 225 |
/* I2C */ \
|
| 226 |
moduleHalI2cEepromConfig.clock_speed = (AT24C01BN_LLD_I2C_MAXFREQUENCY < moduleHalI2cEepromConfig.clock_speed) ? AT24C01BN_LLD_I2C_MAXFREQUENCY : moduleHalI2cEepromConfig.clock_speed; \ |
| 227 |
moduleHalI2cEepromConfig.duty_cycle = (moduleHalI2cEepromConfig.clock_speed <= 100000) ? STD_DUTY_CYCLE : FAST_DUTY_CYCLE_2; \
|
| 228 |
i2cStart(&MODULE_HAL_I2C_EEPROM, &moduleHalI2cEepromConfig); \ |
| 229 |
/* SPI */ \
|
| 230 |
spiStart(&MODULE_HAL_SPI_LIGHT, &moduleHalSpiLightConfig); \ |
| 231 |
} |
| 232 |
|
| 233 |
/**
|
| 234 |
* @brief Periphery communication interface deinitialization hook.
|
| 235 |
*/
|
| 236 |
#define MODULE_SHUTDOWN_PERIPHERY_COMM() { \
|
| 237 |
/* SPI */ \
|
| 238 |
spiStop(&MODULE_HAL_SPI_LIGHT); \ |
| 239 |
/* I2C */ \
|
| 240 |
i2cStop(&MODULE_HAL_I2C_EEPROM); \ |
| 241 |
/* don't stop the serial driver so messages can still be printed */ \
|
| 242 |
} |
| 243 |
|
| 244 |
/** @} */
|
| 245 |
|
| 246 |
/*===========================================================================*/
|
| 247 |
/**
|
| 248 |
* @name Startup Shutdown Synchronization Protocol (SSSP)
|
| 249 |
* @{
|
| 250 |
*/
|
| 251 |
/*===========================================================================*/
|
| 252 |
|
| 253 |
/**
|
| 254 |
* @brief PD signal GPIO.
|
| 255 |
*/
|
| 256 |
#define moduleSsspGpioPd moduleGpioSysPd
|
| 257 |
|
| 258 |
/**
|
| 259 |
* @brief SYNC signal GPIO.
|
| 260 |
*/
|
| 261 |
#define moduleSsspGpioSync moduleGpioSysSync
|
| 262 |
|
| 263 |
/**
|
| 264 |
* @brief DN signal GPIO.
|
| 265 |
*/
|
| 266 |
#define moduleSsspGpioDn moduleGpioSysUartDn
|
| 267 |
|
| 268 |
/**
|
| 269 |
* @brief Event flags for PD signal events.
|
| 270 |
*/
|
| 271 |
#define MODULE_SSSP_EVENTFLAGS_PD MODULE_OS_IOEVENTFLAGS_SYSPD
|
| 272 |
|
| 273 |
/**
|
| 274 |
* @brief Event flags for SYNC signal events.
|
| 275 |
*/
|
| 276 |
#define MODULE_SSSP_EVENTFLAGS_SYNC MODULE_OS_IOEVENTFLAGS_SYSSYNC
|
| 277 |
|
| 278 |
/**
|
| 279 |
* @brief Event flags for DN signal events.
|
| 280 |
*/
|
| 281 |
#define MODULE_SSSP_EVENTFLAGS_DN MODULE_OS_IOEVENTFLAGS_SYSUARTDN
|
| 282 |
|
| 283 |
/** @} */
|
| 284 |
|
| 285 |
/*===========================================================================*/
|
| 286 |
/**
|
| 287 |
* @name Low-level drivers
|
| 288 |
* @{
|
| 289 |
*/
|
| 290 |
/*===========================================================================*/
|
| 291 |
#include <alld_at24c01bn-sh-b.h> |
| 292 |
#include <alld_tlc5947.h> |
| 293 |
#include <alld_tps2051bdbv.h> |
| 294 |
|
| 295 |
/**
|
| 296 |
* @brief EEPROM driver.
|
| 297 |
*/
|
| 298 |
extern AT24C01BNDriver moduleLldEeprom;
|
| 299 |
|
| 300 |
/**
|
| 301 |
* @brief LED PWM driver.
|
| 302 |
*/
|
| 303 |
extern TLC5947Driver moduleLldLedPwm;
|
| 304 |
|
| 305 |
/**
|
| 306 |
* @brief Power switch driver for the laser supply power.
|
| 307 |
*/
|
| 308 |
extern TPS2051BDriver moduleLldPowerSwitchLaser;
|
| 309 |
|
| 310 |
/** @} */
|
| 311 |
|
| 312 |
/*===========================================================================*/
|
| 313 |
/**
|
| 314 |
* @name Unit tests (UT)
|
| 315 |
* @{
|
| 316 |
*/
|
| 317 |
/*===========================================================================*/
|
| 318 |
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__) |
| 319 |
#include <ut_alld_at24c01bn-sh-b.h> |
| 320 |
#include <ut_alld_tlc5947.h> |
| 321 |
#include <ut_alld_tps2051bdbv.h> |
| 322 |
|
| 323 |
/**
|
| 324 |
* @brief EEPROM unit test object.
|
| 325 |
*/
|
| 326 |
extern aos_unittest_t moduleUtAlldAt24c01bn;
|
| 327 |
|
| 328 |
/**
|
| 329 |
* @brief LED PWM driver unit test object.
|
| 330 |
*/
|
| 331 |
extern aos_unittest_t moduleUtAlldTlc5947;
|
| 332 |
|
| 333 |
/**
|
| 334 |
* @brief Current-limited power switch (Laser output)
|
| 335 |
*/
|
| 336 |
extern aos_unittest_t moduleUtAlldTps2051bdbv;
|
| 337 |
|
| 338 |
#endif /* AMIROOS_CFG_TESTS_ENABLE == true */ |
| 339 |
|
| 340 |
/** @} */
|
| 341 |
|
| 342 |
#endif /* _AMIROOS_MODULE_H_ */ |
| 343 |
|
| 344 |
/** @} */
|