FSM thermostat
port_system.h
Go to the documentation of this file.
1 
8 #ifndef PORT_SYSTEM_H_
9 #define PORT_SYSTEM_H_
10 
11 /* Includes ------------------------------------------------------------------*/
12 /* Standard C includes */
13 #include <stdlib.h>
14 #include <stdint.h>
15 #include <stdbool.h>
16 
17 /* HW dependent includes */
18 #include "stm32f4xx.h"
19 
20 /* Defines and enums ----------------------------------------------------------*/
21 /* Defines */
22 #define BIT_POS_TO_MASK(x) (0x01 << (x))
23 #define BASE_MASK_TO_POS(m, p) ((m) << (p))
24 #define GET_PIN_IRQN(pin) (pin >= 10 ? EXTI15_10_IRQn : (pin >= 5 ? EXTI9_5_IRQn : (EXTI0_IRQn + pin)))
26 /* Microcontroller STM32F446RE */
27 /* Timer configuration */
28 #define RCC_HSI_CALIBRATION_DEFAULT 0x10U
29 #define TICK_FREQ_1KHZ 1U
30 #define NVIC_PRIORITY_GROUP_0 ((uint32_t)0x00000007)
32 #define NVIC_PRIORITY_GROUP_4 ((uint32_t)0x00000003)
35 /* Power */
36 #define POWER_REGULATOR_VOLTAGE_SCALE3 0x01
38 /* GPIOs */
39 #define HIGH true
40 #define LOW false
42 #define GPIO_MODE_IN 0x00
43 #define GPIO_MODE_OUT 0x01
44 #define GPIO_MODE_ALTERNATE 0x02
45 #define GPIO_MODE_ANALOG 0x03
47 #define GPIO_PUPDR_NOPULL 0x00
48 #define GPIO_PUPDR_PUP 0x01
49 #define GPIO_PUPDR_PDOWN 0x02
51 /* Interruption */
52 #define TRIGGER_RISING_EDGE 0x01U
53 #define TRIGGER_FALLING_EDGE 0x02U
54 #define TRIGGER_BOTH_EDGE (TRIGGER_RISING_EDGE | TRIGGER_FALLING_EDGE)
55 #define TRIGGER_ENABLE_EVENT_REQ 0x04U
56 #define TRIGGER_ENABLE_INTERR_REQ 0x08U
58 /* ADC */
59 #define ADC_VREF_MV 3300U
61 #define ADC_RESOLUTION_12B (0x00U << ADC_CR1_RES_Pos)
62 #define ADC_RESOLUTION_10B (0x01U << ADC_CR1_RES_Pos)
63 #define ADC_RESOLUTION_8B (0x02U << ADC_CR1_RES_Pos)
64 #define ADC_RESOLUTION_6B (0x03U << ADC_CR1_RES_Pos)
66 #define ADC_EOC_INTERRUPT_ENABLE (0x01U << ADC_CR1_EOCIE_Pos)
68 /* Function prototypes and explanation -------------------------------------------------*/
69 
88 size_t port_system_init(void);
89 
94 uint32_t port_system_get_millis(void);
95 
102 void port_system_set_millis(uint32_t ms);
103 
111 void port_system_delay_ms(uint32_t ms);
112 
123 void port_system_delay_until_ms(uint32_t *p_t, uint32_t ms);
124 
170 void port_system_gpio_config(GPIO_TypeDef *p_port, uint8_t pin, uint8_t mode, uint8_t pupd);
171 
195 void port_system_gpio_config_alternate(GPIO_TypeDef *p_port, uint8_t pin, uint8_t alternate);
196 
226 void port_system_gpio_config_exti(GPIO_TypeDef *p_port, uint8_t pin, uint32_t mode);
227 
237 void port_system_gpio_exti_enable(uint8_t pin, uint8_t priority, uint8_t subpriority);
238 
246 void port_system_gpio_exti_disable(uint8_t pin);
247 
285 void port_system_adc_single_ch_init(ADC_TypeDef *p_adc, uint8_t channel, uint32_t cr_mode);
286 
293 void port_system_adc_interrupt_enable(uint8_t priority, uint8_t subpriority);
294 
302 void port_system_adc_enable(ADC_TypeDef *p_adc);
303 
311 void port_system_adc_disable(ADC_TypeDef *p_adc);
312 
325 void port_system_adc_start_conversion(ADC_TypeDef *p_adc, uint8_t channel);
326 
327 #endif /* PORT_SYSTEM_H_ */
port_system_set_millis
void port_system_set_millis(uint32_t ms)
Sets the number of milliseconds since the system started.
Definition: port_system.c:130
port_system_gpio_exti_disable
void port_system_gpio_exti_disable(uint8_t pin)
Disable interrupts of a GPIO line (pin)
Definition: port_system.c:244
port_system_adc_enable
void port_system_adc_enable(ADC_TypeDef *p_adc)
Enable the ADC peripheral to work.
Definition: port_system.c:357
port_system_adc_start_conversion
void port_system_adc_start_conversion(ADC_TypeDef *p_adc, uint8_t channel)
Start the conversion of the ADC peripheral.
Definition: port_system.c:374
port_system_delay_ms
void port_system_delay_ms(uint32_t ms)
Wait for some milliseconds.
Definition: port_system.c:135
port_system_gpio_exti_enable
void port_system_gpio_exti_enable(uint8_t pin, uint8_t priority, uint8_t subpriority)
Enable interrupts of a GPIO line (pin)
Definition: port_system.c:238
port_system_adc_interrupt_enable
void port_system_adc_interrupt_enable(uint8_t priority, uint8_t subpriority)
Enable the ADC global interrupts in NVIC. ADC1, ADC2, and ADC3 share the same interrupt.
Definition: port_system.c:351
port_system_adc_single_ch_init
void port_system_adc_single_ch_init(ADC_TypeDef *p_adc, uint8_t channel, uint32_t cr_mode)
Configure the ADC peripheral for a single channel.
Definition: port_system.c:261
port_system_get_millis
uint32_t port_system_get_millis(void)
Get the count of the System tick in milliseconds.
Definition: port_system.c:125
port_system_gpio_config
void port_system_gpio_config(GPIO_TypeDef *p_port, uint8_t pin, uint8_t mode, uint8_t pupd)
Configure the mode and pull of a GPIO.
Definition: port_system.c:158
port_system_adc_disable
void port_system_adc_disable(ADC_TypeDef *p_adc)
Disable the ADC peripheral.
Definition: port_system.c:368
port_system_gpio_config_exti
void port_system_gpio_config_exti(GPIO_TypeDef *p_port, uint8_t pin, uint32_t mode)
Configure the external interruption or event of a GPIO.
Definition: port_system.c:181
port_system_delay_until_ms
void port_system_delay_until_ms(uint32_t *p_t, uint32_t ms)
Wait for some milliseconds from a time reference.
Definition: port_system.c:144
port_system_gpio_config_alternate
void port_system_gpio_config_alternate(GPIO_TypeDef *p_port, uint8_t pin, uint8_t alternate)
Configure the alternate function of a GPIO.
Definition: port_system.c:249
port_system_init
size_t port_system_init(void)
This function is based on the initialization of the HAL Library; it must be the first thing to be exe...
Definition: port_system.c:89