Statistics
| Branch: | Tag: | Revision:

amiro-os / modules / PowerManagement_1-1 / module.c @ 9af9aaea

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