amiro-os / modules / PowerManagement_1-1 / module.c @ f3b3fe09
History | View | Annotate | Download (38.727 KB)
| 1 | e545e620 | Thomas Schöpping | /*
|
|---|---|---|---|
| 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 | 53710ca3 | Marc Rothmann | /**
|
| 20 | acc97cbf | Thomas Schöpping | * @file
|
| 21 | 53710ca3 | Marc Rothmann | * @brief Structures and constant for the PowerManagement module.
|
| 22 | *
|
||
| 23 | * @addtogroup powermanagement_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 | ADCConversionGroup moduleHalAdcVsysConversionGroup = {
|
||
| 48 | /* buffer type */ true, |
||
| 49 | /* number of channels */ 1, |
||
| 50 | /* callback function */ NULL, |
||
| 51 | /* error callback */ NULL, |
||
| 52 | /* CR1 */ ADC_CR1_AWDEN | ADC_CR1_AWDIE,
|
||
| 53 | /* CR2 */ ADC_CR2_SWSTART | ADC_CR2_CONT,
|
||
| 54 | /* SMPR1 */ 0, |
||
| 55 | /* SMPR2 */ ADC_SMPR2_SMP_AN9(ADC_SAMPLE_480),
|
||
| 56 | /* HTR */ ADC_HTR_HT,
|
||
| 57 | /* LTR */ 0, |
||
| 58 | /* SQR1 */ ADC_SQR1_NUM_CH(1), |
||
| 59 | /* SQR2 */ 0, |
||
| 60 | /* SQR3 */ ADC_SQR3_SQ1_N(ADC_CHANNEL_IN9),
|
||
| 61 | }; |
||
| 62 | |||
| 63 | CANConfig moduleHalCanConfig = {
|
||
| 64 | /* mcr */ CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP,
|
||
| 65 | 933df08e | Thomas Schöpping | /* btr */ CAN_BTR_SJW(1) | CAN_BTR_TS2(3) | CAN_BTR_TS1(15) | CAN_BTR_BRP(1), |
| 66 | e545e620 | Thomas Schöpping | }; |
| 67 | |||
| 68 | I2CConfig moduleHalI2cProxPm18Pm33GaugeRearConfig = {
|
||
| 69 | /* I²C mode */ OPMODE_I2C,
|
||
| 70 | /* frequency */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL) |
||
| 71 | /* duty cycle */ FAST_DUTY_CYCLE_2,
|
||
| 72 | }; |
||
| 73 | |||
| 74 | I2CConfig moduleHalI2cProxPm42Pm50PmVddEepromTouchGaugeFrontConfig = {
|
||
| 75 | /* I²C mode */ OPMODE_I2C,
|
||
| 76 | /* frequency */ 400000, // TODO: replace with some macro (-> ChibiOS/HAL) |
||
| 77 | /* duty cycle */ FAST_DUTY_CYCLE_2,
|
||
| 78 | }; |
||
| 79 | |||
| 80 | PWMConfig moduleHalPwmBuzzerConfig = {
|
||
| 81 | /* frequency */ 1000000, |
||
| 82 | /* period */ 0, |
||
| 83 | /* callback */ NULL, |
||
| 84 | /* channel configurations */ {
|
||
| 85 | /* channel 0 */ {
|
||
| 86 | /* mode */ PWM_OUTPUT_DISABLED,
|
||
| 87 | /* callback */ NULL |
||
| 88 | }, |
||
| 89 | /* channel 1 */ {
|
||
| 90 | /* mode */ PWM_OUTPUT_ACTIVE_HIGH,
|
||
| 91 | /* callback */ NULL |
||
| 92 | }, |
||
| 93 | /* channel 2 */ {
|
||
| 94 | /* mode */ PWM_OUTPUT_DISABLED,
|
||
| 95 | /* callback */ NULL |
||
| 96 | }, |
||
| 97 | /* channel 3 */ {
|
||
| 98 | /* mode */ PWM_OUTPUT_DISABLED,
|
||
| 99 | /* callback */ NULL |
||
| 100 | }, |
||
| 101 | }, |
||
| 102 | /* TIM CR2 register */ 0, |
||
| 103 | #if STM32_PWM_USE_ADVANCED
|
||
| 104 | /* TIM BDTR register */ 0, |
||
| 105 | #endif
|
||
| 106 | /* TIM DIER register */ 0, |
||
| 107 | }; |
||
| 108 | |||
| 109 | SerialConfig moduleHalProgIfConfig = {
|
||
| 110 | /* bit rate */ 115200, |
||
| 111 | /* CR1 */ 0, |
||
| 112 | /* CR1 */ 0, |
||
| 113 | /* CR1 */ 0, |
||
| 114 | }; |
||
| 115 | |||
| 116 | /** @} */
|
||
| 117 | |||
| 118 | /*===========================================================================*/
|
||
| 119 | /**
|
||
| 120 | * @name GPIO definitions
|
||
| 121 | * @{
|
||
| 122 | */
|
||
| 123 | /*===========================================================================*/
|
||
| 124 | |||
| 125 | 1e5f7648 | Thomas Schöpping | /**
|
| 126 | * @brief SYS_REG_EN output signal GPIO.
|
||
| 127 | */
|
||
| 128 | static apalGpio_t _gpioSysRegEn = {
|
||
| 129 | e545e620 | Thomas Schöpping | /* port */ GPIOA,
|
| 130 | /* pad */ GPIOA_SYS_REG_EN,
|
||
| 131 | }; |
||
| 132 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleSysRegEn = {
|
| 133 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioSysRegEn,
|
| 134 | /* meta */ {
|
||
| 135 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
| 136 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
| 137 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
| 138 | }, |
||
| 139 | }; |
||
| 140 | e545e620 | Thomas Schöpping | |
| 141 | 1e5f7648 | Thomas Schöpping | /**
|
| 142 | * @brief IR_INT1 input signal GPIO.
|
||
| 143 | */
|
||
| 144 | static apalGpio_t _gpioIrInt1 = {
|
||
| 145 | e545e620 | Thomas Schöpping | /* port */ GPIOB,
|
| 146 | /* pad */ GPIOB_IR_INT1_N,
|
||
| 147 | }; |
||
| 148 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioIrInt1 = {
|
| 149 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioIrInt1,
|
| 150 | /* meta */ {
|
||
| 151 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
| 152 | /* active state */ (VCNL4020_LLD_INT_EDGE == APAL_GPIO_EDGE_RISING) ? APAL_GPIO_ACTIVE_HIGH : APAL_GPIO_ACTIVE_LOW,
|
||
| 153 | /* interrupt edge */ VCNL4020_LLD_INT_EDGE,
|
||
| 154 | }, |
||
| 155 | }; |
||
| 156 | e545e620 | Thomas Schöpping | |
| 157 | 1e5f7648 | Thomas Schöpping | /**
|
| 158 | * @brief POWER_EN output signal GPIO.
|
||
| 159 | */
|
||
| 160 | static apalGpio_t _gpioPowerEn = {
|
||
| 161 | e545e620 | Thomas Schöpping | /* port */ GPIOB,
|
| 162 | /* pad */ GPIOB_POWER_EN,
|
||
| 163 | }; |
||
| 164 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioPowerEn = {
|
| 165 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioPowerEn,
|
| 166 | /* meta */ {
|
||
| 167 | /* direction */ APAL_GPIO_DIRECTION_OUTPUT,
|
||
| 168 | /* active state */ APAL_GPIO_ACTIVE_HIGH,
|
||
| 169 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
| 170 | }, |
||
| 171 | }; |
||
| 172 | e545e620 | Thomas Schöpping | |
| 173 | 1e5f7648 | Thomas Schöpping | /**
|
| 174 | * @brief SYS_UART_DN bidirectional signal GPIO.
|
||
| 175 | */
|
||
| 176 | static apalGpio_t _gpioSysUartDn = {
|
||
| 177 | e545e620 | Thomas Schöpping | /* port */ GPIOB,
|
| 178 | /* pad */ GPIOB_SYS_UART_DN,
|
||
| 179 | }; |
||
| 180 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioSysUartDn = {
|
| 181 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioSysUartDn,
|
| 182 | /* meta */ {
|
||
| 183 | /* direction */ APAL_GPIO_DIRECTION_BIDIRECTIONAL,
|
||
| 184 | /* active state */ APAL_GPIO_ACTIVE_LOW,
|
||
| 185 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
| 186 | }, |
||
| 187 | }; |
||
| 188 | e545e620 | Thomas Schöpping | |
| 189 | 1e5f7648 | Thomas Schöpping | /**
|
| 190 | * @brief CHARGE_STAT2A input signal GPIO.
|
||
| 191 | */
|
||
| 192 | static apalGpio_t _gpioChargeStat2A = {
|
||
| 193 | e545e620 | Thomas Schöpping | /* port */ GPIOB,
|
| 194 | /* pad */ GPIOB_CHARGE_STAT2A,
|
||
| 195 | }; |
||
| 196 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioChargeStat2A = {
|
| 197 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioChargeStat2A,
|
| 198 | /* meta */ {
|
||
| 199 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
| 200 | /* active state */ BQ24103A_LLD_CHARGE_STATUS_GPIO_ACTIVE_STATE,
|
||
| 201 | /* interrupt edge */ APAL_GPIO_EDGE_NONE,
|
||
| 202 | }, |
||
| 203 | }; |
||
| 204 | e545e620 | Thomas Schöpping | |
| 205 | 1e5f7648 | Thomas Schöpping | /**
|
| 206 | * @brief GAUGE_BATLOW2 input signal GPIO.
|
||
| 207 | */
|
||
| 208 | static apalGpio_t _gpioGaugeBatLow2 = {
|
||
| 209 | e545e620 | Thomas Schöpping | /* port */ GPIOB,
|
| 210 | /* pad */ GPIOB_GAUGE_BATLOW2,
|
||
| 211 | }; |
||
| 212 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioGaugeBatLow2 = {
|
| 213 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioGaugeBatLow2,
|
| 214 | /* meta */ {
|
||
| 215 | /* direction */ APAL_GPIO_DIRECTION_INPUT,
|
||
| 216 | /* active state */ BQ27500_LLD_BATLOW_ACTIVE_STATE,
|
||
| 217 | /* interrupt edge */ APAL_GPIO_EDGE_BOTH,
|
||
| 218 | }, |
||
| 219 | }; |
||
| 220 | e545e620 | Thomas Schöpping | |
| 221 | 1e5f7648 | Thomas Schöpping | /**
|
| 222 | * @brief GAUGE_BATGD2 input signal GPIO.
|
||
| 223 | */
|
||
| 224 | static apalGpio_t _gpioGaugeBatGd2 = {
|
||
| 225 | e545e620 | Thomas Schöpping | /* port */ GPIOB,
|
| 226 | /* pad */ GPIOB_GAUGE_BATGD2_N,
|
||
| 227 | }; |
||
| 228 | acc97cbf | Thomas Schöpping | ROMCONST apalControlGpio_t moduleGpioGaugeBatGd2 = {
|
| 229 | 1e5f7648 | Thomas Schöpping | /* GPIO */ &_gpioGaugeBatGd2,
|
| 230 | /* meta */ {
|
||
| 231 |