mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Formatting the C/C++ files
This commit is contained in:
@@ -1,14 +1,13 @@
|
||||
// BSP mapping functions
|
||||
|
||||
#include <IRQ.h>
|
||||
#include "BSP.h"
|
||||
#include "I2C_Wrapper.hpp"
|
||||
#include "Model_Config.h"
|
||||
#include "Pins.h"
|
||||
#include "Setup.h"
|
||||
#include "history.hpp"
|
||||
#include "Pins.h"
|
||||
#include "main.hpp"
|
||||
#include "history.hpp"
|
||||
#include "Model_Config.h"
|
||||
#include "I2C_Wrapper.hpp"
|
||||
#include <IRQ.h>
|
||||
volatile uint16_t PWMSafetyTimer = 0;
|
||||
volatile uint8_t pendingPWM = 0;
|
||||
|
||||
@@ -22,9 +21,7 @@ static bool fastPWM;
|
||||
|
||||
// 2 second filter (ADC is PID_TIM_HZ Hz)
|
||||
history<uint16_t, PID_TIM_HZ> rawTempFilter = {{0}, 0, 0};
|
||||
void resetWatchdog() {
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
}
|
||||
void resetWatchdog() { HAL_IWDG_Refresh(&hiwdg); }
|
||||
#ifdef TEMP_NTC
|
||||
// Lookup table for the NTC
|
||||
// Stored as ADCReading,Temp in degC
|
||||
@@ -333,21 +330,11 @@ void unstick_I2C() {
|
||||
HAL_I2C_Init(&hi2c1);
|
||||
}
|
||||
|
||||
uint8_t getButtonA() {
|
||||
return HAL_GPIO_ReadPin(KEY_A_GPIO_Port, KEY_A_Pin) == GPIO_PIN_RESET ? 1 : 0;
|
||||
}
|
||||
uint8_t getButtonB() {
|
||||
return HAL_GPIO_ReadPin(KEY_B_GPIO_Port, KEY_B_Pin) == GPIO_PIN_RESET ? 1 : 0;
|
||||
}
|
||||
uint8_t getButtonA() { return HAL_GPIO_ReadPin(KEY_A_GPIO_Port, KEY_A_Pin) == GPIO_PIN_RESET ? 1 : 0; }
|
||||
uint8_t getButtonB() { return HAL_GPIO_ReadPin(KEY_B_GPIO_Port, KEY_B_Pin) == GPIO_PIN_RESET ? 1 : 0; }
|
||||
|
||||
void BSPInit(void) {
|
||||
switchToFastPWM();
|
||||
}
|
||||
void BSPInit(void) { switchToFastPWM(); }
|
||||
|
||||
void reboot() {
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
void reboot() { NVIC_SystemReset(); }
|
||||
|
||||
void delay_ms(uint16_t count) {
|
||||
HAL_Delay(count);
|
||||
}
|
||||
void delay_ms(uint16_t count) { HAL_Delay(count); }
|
||||
|
||||
@@ -17,13 +17,11 @@ void FRToSI2C::CpltCallback() {
|
||||
}
|
||||
}
|
||||
|
||||
bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
|
||||
uint8_t *pData, uint16_t Size) {
|
||||
bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData, uint16_t Size) {
|
||||
|
||||
if (!lock())
|
||||
return false;
|
||||
if (HAL_I2C_Mem_Read(&hi2c1, DevAddress, MemAddress, I2C_MEMADD_SIZE_8BIT,
|
||||
pData, Size, 500) != HAL_OK) {
|
||||
if (HAL_I2C_Mem_Read(&hi2c1, DevAddress, MemAddress, I2C_MEMADD_SIZE_8BIT, pData, Size, 500) != HAL_OK) {
|
||||
|
||||
I2C_Unstick();
|
||||
unlock();
|
||||
@@ -33,22 +31,18 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
|
||||
unlock();
|
||||
return true;
|
||||
}
|
||||
bool FRToSI2C::I2C_RegisterWrite(uint8_t address, uint8_t reg, uint8_t data) {
|
||||
return Mem_Write(address, reg, &data, 1);
|
||||
}
|
||||
bool FRToSI2C::I2C_RegisterWrite(uint8_t address, uint8_t reg, uint8_t data) { return Mem_Write(address, reg, &data, 1); }
|
||||
|
||||
uint8_t FRToSI2C::I2C_RegisterRead(uint8_t add, uint8_t reg) {
|
||||
uint8_t tx_data[1];
|
||||
Mem_Read(add, reg, tx_data, 1);
|
||||
return tx_data[0];
|
||||
}
|
||||
bool FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
|
||||
uint8_t *pData, uint16_t Size) {
|
||||
bool FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData, uint16_t Size) {
|
||||
|
||||
if (!lock())
|
||||
return false;
|
||||
if (HAL_I2C_Mem_Write(&hi2c1, DevAddress, MemAddress, I2C_MEMADD_SIZE_8BIT,
|
||||
pData, Size, 500) != HAL_OK) {
|
||||
if (HAL_I2C_Mem_Write(&hi2c1, DevAddress, MemAddress, I2C_MEMADD_SIZE_8BIT, pData, Size, 500) != HAL_OK) {
|
||||
|
||||
I2C_Unstick();
|
||||
unlock();
|
||||
@@ -62,8 +56,7 @@ bool FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
|
||||
bool FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
|
||||
if (!lock())
|
||||
return false;
|
||||
if (HAL_I2C_Master_Transmit_DMA(&hi2c1, DevAddress, pData, Size)
|
||||
!= HAL_OK) {
|
||||
if (HAL_I2C_Master_Transmit_DMA(&hi2c1, DevAddress, pData, Size) != HAL_OK) {
|
||||
I2C_Unstick();
|
||||
unlock();
|
||||
return false;
|
||||
@@ -75,29 +68,20 @@ bool FRToSI2C::probe(uint16_t DevAddress) {
|
||||
if (!lock())
|
||||
return false;
|
||||
uint8_t buffer[1];
|
||||
bool worked = HAL_I2C_Mem_Read(&hi2c1, DevAddress, 0x0F,
|
||||
I2C_MEMADD_SIZE_8BIT, buffer, 1, 1000) == HAL_OK;
|
||||
bool worked = HAL_I2C_Mem_Read(&hi2c1, DevAddress, 0x0F, I2C_MEMADD_SIZE_8BIT, buffer, 1, 1000) == HAL_OK;
|
||||
unlock();
|
||||
return worked;
|
||||
}
|
||||
|
||||
void FRToSI2C::I2C_Unstick() {
|
||||
unstick_I2C();
|
||||
}
|
||||
void FRToSI2C::I2C_Unstick() { unstick_I2C(); }
|
||||
|
||||
void FRToSI2C::unlock() {
|
||||
xSemaphoreGive(I2CSemaphore);
|
||||
}
|
||||
void FRToSI2C::unlock() { xSemaphoreGive(I2CSemaphore); }
|
||||
|
||||
bool FRToSI2C::lock() {
|
||||
return xSemaphoreTake(I2CSemaphore, (TickType_t)50) == pdTRUE;
|
||||
}
|
||||
bool FRToSI2C::lock() { return xSemaphoreTake(I2CSemaphore, (TickType_t)50) == pdTRUE; }
|
||||
|
||||
bool FRToSI2C::writeRegistersBulk(const uint8_t address,
|
||||
const I2C_REG *registers, const uint8_t registersLength) {
|
||||
bool FRToSI2C::writeRegistersBulk(const uint8_t address, const I2C_REG *registers, const uint8_t registersLength) {
|
||||
for (int index = 0; index < registersLength; index++) {
|
||||
if (!I2C_RegisterWrite(address, registers[index].reg,
|
||||
registers[index].val)) {
|
||||
if (!I2C_RegisterWrite(address, registers[index].reg, registers[index].val)) {
|
||||
return false;
|
||||
}
|
||||
if (registers[index].pause_ms)
|
||||
|
||||
@@ -16,32 +16,17 @@ void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef *hadc) {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
if (hadc == &hadc1) {
|
||||
if (pidTaskNotification) {
|
||||
vTaskNotifyGiveFromISR(pidTaskNotification,
|
||||
&xHigherPriorityTaskWoken);
|
||||
vTaskNotifyGiveFromISR(pidTaskNotification, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
}
|
||||
}
|
||||
void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
|
||||
FRToSI2C::CpltCallback();
|
||||
}
|
||||
void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
|
||||
FRToSI2C::CpltCallback();
|
||||
}
|
||||
void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
|
||||
FRToSI2C::CpltCallback();
|
||||
}
|
||||
void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c __unused) {
|
||||
|
||||
FRToSI2C::CpltCallback();
|
||||
}
|
||||
void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
|
||||
|
||||
FRToSI2C::CpltCallback();
|
||||
}
|
||||
void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c __unused) {
|
||||
FRToSI2C::CpltCallback();
|
||||
}
|
||||
void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c __unused) { FRToSI2C::CpltCallback(); }
|
||||
void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c __unused) { FRToSI2C::CpltCallback(); }
|
||||
void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c __unused) { FRToSI2C::CpltCallback(); }
|
||||
void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c __unused) { FRToSI2C::CpltCallback(); }
|
||||
void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c __unused) { FRToSI2C::CpltCallback(); }
|
||||
void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c __unused) { FRToSI2C::CpltCallback(); }
|
||||
|
||||
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
|
||||
(void)GPIO_Pin;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include "BSP.h"
|
||||
#include "BSP_Power.h"
|
||||
#include "Model_Config.h"
|
||||
#include "Pins.h"
|
||||
#include "QC3.h"
|
||||
#include "Settings.h"
|
||||
#include "Pins.h"
|
||||
#include "fusbpd.h"
|
||||
#include "Model_Config.h"
|
||||
#include "policy_engine.h"
|
||||
#include "int_n.h"
|
||||
#include "policy_engine.h"
|
||||
bool FUSB302_present = false;
|
||||
|
||||
void power_check() {
|
||||
@@ -46,4 +46,3 @@ bool getIsPoweredByDCIN() {
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
* Author: Ralim
|
||||
*/
|
||||
#include "BSP.h"
|
||||
#include "Model_Config.h"
|
||||
#include "Pins.h"
|
||||
#include "QC3.h"
|
||||
#include "Settings.h"
|
||||
#include "stm32f1xx_hal.h"
|
||||
#include "Model_Config.h"
|
||||
#ifdef POW_QC
|
||||
void QC_DPlusZero_Six() {
|
||||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET); // pull down D+
|
||||
@@ -66,9 +66,7 @@ void QC_Post_Probe_En() {
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
}
|
||||
|
||||
uint8_t QC_DM_PulledDown() {
|
||||
return HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_11) == GPIO_PIN_RESET ? 1 : 0;
|
||||
}
|
||||
uint8_t QC_DM_PulledDown() { return HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_11) == GPIO_PIN_RESET ? 1 : 0; }
|
||||
#endif
|
||||
void QC_resync() {
|
||||
#ifdef POW_QC
|
||||
|
||||
@@ -75,8 +75,7 @@ void SystemClock_Config(void) {
|
||||
|
||||
/**Initializes the CPU, AHB and APB busses clocks
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType =
|
||||
RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSI;
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSI;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
RCC_OscInitStruct.HSICalibrationValue = 16;
|
||||
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
||||
@@ -87,20 +86,17 @@ void SystemClock_Config(void) {
|
||||
|
||||
/**Initializes the CPU, AHB and APB busses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK |
|
||||
RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV16; // TIM
|
||||
// 2,3,4,5,6,7,12,13,14
|
||||
RCC_ClkInitStruct.APB2CLKDivider =
|
||||
RCC_HCLK_DIV1; // 64 mhz to some peripherals and adc
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; // 64 mhz to some peripherals and adc
|
||||
|
||||
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
|
||||
|
||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
|
||||
PeriphClkInit.AdcClockSelection =
|
||||
RCC_ADCPCLK2_DIV6; // 6 or 8 are the only non overclocked options
|
||||
PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6; // 6 or 8 are the only non overclocked options
|
||||
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
|
||||
|
||||
/**Configure the Systick interrupt time
|
||||
@@ -300,8 +296,7 @@ static void MX_TIM3_Init(void) {
|
||||
HAL_GPIO_Init(PWM_Out_GPIO_Port, &GPIO_InitStruct);
|
||||
#ifdef MODEL_TS100
|
||||
// Remap TIM3_CH1 to be on PB4
|
||||
__HAL_AFIO_REMAP_TIM3_PARTIAL()
|
||||
;
|
||||
__HAL_AFIO_REMAP_TIM3_PARTIAL();
|
||||
#else
|
||||
// No re-map required
|
||||
#endif
|
||||
@@ -370,8 +365,7 @@ static void MX_TIM2_Init(void) {
|
||||
*/
|
||||
static void MX_DMA_Init(void) {
|
||||
/* DMA controller clock enable */
|
||||
__HAL_RCC_DMA1_CLK_ENABLE()
|
||||
;
|
||||
__HAL_RCC_DMA1_CLK_ENABLE();
|
||||
|
||||
/* DMA interrupt init */
|
||||
/* DMA1_Channel1_IRQn interrupt configuration */
|
||||
@@ -399,12 +393,9 @@ static void MX_GPIO_Init(void) {
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE()
|
||||
;
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE()
|
||||
;
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE()
|
||||
;
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_RESET);
|
||||
@@ -414,26 +405,21 @@ static void MX_GPIO_Init(void) {
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
||||
/*Configure peripheral I/O remapping */
|
||||
__HAL_AFIO_REMAP_PD01_ENABLE()
|
||||
;
|
||||
__HAL_AFIO_REMAP_PD01_ENABLE();
|
||||
//^ remap XTAL so that pins can be analog (all input buffers off).
|
||||
// reduces power consumption
|
||||
|
||||
/*
|
||||
* Configure All pins as analog by default
|
||||
*/
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 |
|
||||
GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 |
|
||||
GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_15;
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_15;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 |
|
||||
#ifdef MODEL_TS100
|
||||
GPIO_PIN_3 |
|
||||
#endif
|
||||
GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 |
|
||||
GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 |
|
||||
GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
|
||||
GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
#ifdef MODEL_TS100
|
||||
@@ -479,7 +465,5 @@ static void MX_GPIO_Init(void) {
|
||||
HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_SET);
|
||||
}
|
||||
#ifdef USE_FULL_ASSERT
|
||||
void assert_failed(uint8_t* file, uint32_t line){
|
||||
asm("bkpt");
|
||||
}
|
||||
void assert_failed(uint8_t *file, uint32_t line) { asm("bkpt"); }
|
||||
#endif
|
||||
|
||||
@@ -75,10 +75,7 @@
|
||||
#define __STM32F1xx_HAL_VERSION_SUB1 (0x01U) /*!< [23:16] sub1 version */
|
||||
#define __STM32F1xx_HAL_VERSION_SUB2 (0x03U) /*!< [15:8] sub2 version */
|
||||
#define __STM32F1xx_HAL_VERSION_RC (0x00U) /*!< [7:0] release candidate */
|
||||
#define __STM32F1xx_HAL_VERSION ((__STM32F1xx_HAL_VERSION_MAIN << 24)\
|
||||
|(__STM32F1xx_HAL_VERSION_SUB1 << 16)\
|
||||
|(__STM32F1xx_HAL_VERSION_SUB2 << 8 )\
|
||||
|(__STM32F1xx_HAL_VERSION_RC))
|
||||
#define __STM32F1xx_HAL_VERSION ((__STM32F1xx_HAL_VERSION_MAIN << 24) | (__STM32F1xx_HAL_VERSION_SUB1 << 16) | (__STM32F1xx_HAL_VERSION_SUB2 << 8) | (__STM32F1xx_HAL_VERSION_RC))
|
||||
|
||||
#define IDCODE_DEVID_MASK 0x00000FFFU
|
||||
|
||||
@@ -155,14 +152,11 @@ HAL_TickFreqTypeDef uwTickFreq = HAL_TICK_FREQ_DEFAULT; /* 1KHz */
|
||||
* to have correct HAL operation.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_Init(void)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_Init(void) {
|
||||
/* Configure Flash prefetch */
|
||||
#if (PREFETCH_ENABLE != 0)
|
||||
#if defined(STM32F101x6) || defined(STM32F101xB) || defined(STM32F101xE) || defined(STM32F101xG) || \
|
||||
defined(STM32F102x6) || defined(STM32F102xB) || \
|
||||
defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || \
|
||||
defined(STM32F105xC) || defined(STM32F107xC)
|
||||
#if defined(STM32F101x6) || defined(STM32F101xB) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6) || defined(STM32F103xB) \
|
||||
|| defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC)
|
||||
|
||||
/* Prefetch buffer is not available on value line devices */
|
||||
__HAL_FLASH_PREFETCH_BUFFER_ENABLE();
|
||||
@@ -188,8 +182,7 @@ HAL_StatusTypeDef HAL_Init(void)
|
||||
* @note This function is optional.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DeInit(void)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_DeInit(void) {
|
||||
/* Reset of all peripherals */
|
||||
__HAL_RCC_APB1_FORCE_RESET();
|
||||
__HAL_RCC_APB1_RELEASE_RESET();
|
||||
@@ -213,8 +206,7 @@ HAL_StatusTypeDef HAL_DeInit(void)
|
||||
* @brief Initialize the MSP.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_MspInit(void)
|
||||
{
|
||||
__weak void HAL_MspInit(void) {
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_MspInit could be implemented in the user file
|
||||
*/
|
||||
@@ -224,8 +216,7 @@ __weak void HAL_MspInit(void)
|
||||
* @brief DeInitializes the MSP.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_MspDeInit(void)
|
||||
{
|
||||
__weak void HAL_MspDeInit(void) {
|
||||
/* NOTE : This function should not be modified, when the callback is needed,
|
||||
the HAL_MspDeInit could be implemented in the user file
|
||||
*/
|
||||
@@ -247,22 +238,17 @@ __weak void HAL_MspDeInit(void)
|
||||
* @param TickPriority Tick interrupt priority.
|
||||
* @retval HAL status
|
||||
*/
|
||||
__weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
||||
{
|
||||
__weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) {
|
||||
/* Configure the SysTick to have interrupt in 1ms time basis*/
|
||||
if (HAL_SYSTICK_Config(SystemCoreClock / (1000U / uwTickFreq)) > 0U)
|
||||
{
|
||||
if (HAL_SYSTICK_Config(SystemCoreClock / (1000U / uwTickFreq)) > 0U) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Configure the SysTick IRQ priority */
|
||||
if (TickPriority < (1UL << __NVIC_PRIO_BITS))
|
||||
{
|
||||
if (TickPriority < (1UL << __NVIC_PRIO_BITS)) {
|
||||
HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
|
||||
uwTickPrio = TickPriority;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
@@ -306,10 +292,7 @@ __weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
||||
* implementations in user file.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_IncTick(void)
|
||||
{
|
||||
uwTick += uwTickFreq;
|
||||
}
|
||||
__weak void HAL_IncTick(void) { uwTick += uwTickFreq; }
|
||||
|
||||
/**
|
||||
* @brief Provides a tick value in millisecond.
|
||||
@@ -317,31 +300,23 @@ __weak void HAL_IncTick(void)
|
||||
* implementations in user file.
|
||||
* @retval tick value
|
||||
*/
|
||||
__weak uint32_t HAL_GetTick(void)
|
||||
{
|
||||
return uwTick;
|
||||
}
|
||||
__weak uint32_t HAL_GetTick(void) { return uwTick; }
|
||||
|
||||
/**
|
||||
* @brief This function returns a tick priority.
|
||||
* @retval tick priority
|
||||
*/
|
||||
uint32_t HAL_GetTickPrio(void)
|
||||
{
|
||||
return uwTickPrio;
|
||||
}
|
||||
uint32_t HAL_GetTickPrio(void) { return uwTickPrio; }
|
||||
|
||||
/**
|
||||
* @brief Set new tick Freq.
|
||||
* @retval Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq) {
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
assert_param(IS_TICKFREQ(Freq));
|
||||
|
||||
if (uwTickFreq != Freq)
|
||||
{
|
||||
if (uwTickFreq != Freq) {
|
||||
uwTickFreq = Freq;
|
||||
|
||||
/* Apply the new tick Freq */
|
||||
@@ -355,10 +330,7 @@ HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq)
|
||||
* @brief Return tick frequency.
|
||||
* @retval tick period in Hz
|
||||
*/
|
||||
HAL_TickFreqTypeDef HAL_GetTickFreq(void)
|
||||
{
|
||||
return uwTickFreq;
|
||||
}
|
||||
HAL_TickFreqTypeDef HAL_GetTickFreq(void) { return uwTickFreq; }
|
||||
|
||||
/**
|
||||
* @brief This function provides minimum delay (in milliseconds) based
|
||||
@@ -371,20 +343,16 @@ HAL_TickFreqTypeDef HAL_GetTickFreq(void)
|
||||
* @param Delay specifies the delay time length, in milliseconds.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_Delay(uint32_t Delay)
|
||||
{
|
||||
__weak void HAL_Delay(uint32_t Delay) {
|
||||
uint32_t tickstart = HAL_GetTick();
|
||||
uint32_t wait = Delay;
|
||||
|
||||
/* Add a freq to guarantee minimum wait */
|
||||
if (wait < HAL_MAX_DELAY)
|
||||
{
|
||||
if (wait < HAL_MAX_DELAY) {
|
||||
wait += (uint32_t)(uwTickFreq);
|
||||
}
|
||||
|
||||
while ((HAL_GetTick() - tickstart) < wait)
|
||||
{
|
||||
}
|
||||
while ((HAL_GetTick() - tickstart) < wait) {}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -397,8 +365,7 @@ __weak void HAL_Delay(uint32_t Delay)
|
||||
* implementations in user file.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_SuspendTick(void)
|
||||
{
|
||||
__weak void HAL_SuspendTick(void) {
|
||||
/* Disable SysTick Interrupt */
|
||||
CLEAR_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
|
||||
}
|
||||
@@ -413,8 +380,7 @@ __weak void HAL_SuspendTick(void)
|
||||
* implementations in user file.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_ResumeTick(void)
|
||||
{
|
||||
__weak void HAL_ResumeTick(void) {
|
||||
/* Enable SysTick Interrupt */
|
||||
SET_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
|
||||
}
|
||||
@@ -423,10 +389,7 @@ __weak void HAL_ResumeTick(void)
|
||||
* @brief Returns the HAL revision
|
||||
* @retval version 0xXYZR (8bits for each decimal, R for RC)
|
||||
*/
|
||||
uint32_t HAL_GetHalVersion(void)
|
||||
{
|
||||
return __STM32F1xx_HAL_VERSION;
|
||||
}
|
||||
uint32_t HAL_GetHalVersion(void) { return __STM32F1xx_HAL_VERSION; }
|
||||
|
||||
/**
|
||||
* @brief Returns the device revision identifier.
|
||||
@@ -439,10 +402,7 @@ uint32_t HAL_GetHalVersion(void)
|
||||
* Refer to errata sheet of these devices for more details.
|
||||
* @retval Device revision identifier
|
||||
*/
|
||||
uint32_t HAL_GetREVID(void)
|
||||
{
|
||||
return ((DBGMCU->IDCODE) >> DBGMCU_IDCODE_REV_ID_Pos);
|
||||
}
|
||||
uint32_t HAL_GetREVID(void) { return ((DBGMCU->IDCODE) >> DBGMCU_IDCODE_REV_ID_Pos); }
|
||||
|
||||
/**
|
||||
* @brief Returns the device identifier.
|
||||
@@ -455,19 +415,13 @@ uint32_t HAL_GetREVID(void)
|
||||
* Refer to errata sheet of these devices for more details.
|
||||
* @retval Device identifier
|
||||
*/
|
||||
uint32_t HAL_GetDEVID(void)
|
||||
{
|
||||
return ((DBGMCU->IDCODE) & IDCODE_DEVID_MASK);
|
||||
}
|
||||
uint32_t HAL_GetDEVID(void) { return ((DBGMCU->IDCODE) & IDCODE_DEVID_MASK); }
|
||||
|
||||
/**
|
||||
* @brief Enable the Debug Module during SLEEP mode
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_DBGMCU_EnableDBGSleepMode(void)
|
||||
{
|
||||
SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
|
||||
}
|
||||
void HAL_DBGMCU_EnableDBGSleepMode(void) { SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP); }
|
||||
|
||||
/**
|
||||
* @brief Disable the Debug Module during SLEEP mode
|
||||
@@ -480,10 +434,7 @@ void HAL_DBGMCU_EnableDBGSleepMode(void)
|
||||
* Refer to errata sheet of these devices for more details.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_DBGMCU_DisableDBGSleepMode(void)
|
||||
{
|
||||
CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
|
||||
}
|
||||
void HAL_DBGMCU_DisableDBGSleepMode(void) { CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP); }
|
||||
|
||||
/**
|
||||
* @brief Enable the Debug Module during STOP mode
|
||||
@@ -510,10 +461,7 @@ void HAL_DBGMCU_DisableDBGSleepMode(void)
|
||||
* Refer to errata sheet of these devices for more details.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_DBGMCU_EnableDBGStopMode(void)
|
||||
{
|
||||
SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
|
||||
}
|
||||
void HAL_DBGMCU_EnableDBGStopMode(void) { SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP); }
|
||||
|
||||
/**
|
||||
* @brief Disable the Debug Module during STOP mode
|
||||
@@ -526,10 +474,7 @@ void HAL_DBGMCU_EnableDBGStopMode(void)
|
||||
* Refer to errata sheet of these devices for more details.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_DBGMCU_DisableDBGStopMode(void)
|
||||
{
|
||||
CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
|
||||
}
|
||||
void HAL_DBGMCU_DisableDBGStopMode(void) { CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP); }
|
||||
|
||||
/**
|
||||
* @brief Enable the Debug Module during STANDBY mode
|
||||
@@ -542,10 +487,7 @@ void HAL_DBGMCU_DisableDBGStopMode(void)
|
||||
* Refer to errata sheet of these devices for more details.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_DBGMCU_EnableDBGStandbyMode(void)
|
||||
{
|
||||
SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
|
||||
}
|
||||
void HAL_DBGMCU_EnableDBGStandbyMode(void) { SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY); }
|
||||
|
||||
/**
|
||||
* @brief Disable the Debug Module during STANDBY mode
|
||||
@@ -558,18 +500,14 @@ void HAL_DBGMCU_EnableDBGStandbyMode(void)
|
||||
* Refer to errata sheet of these devices for more details.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_DBGMCU_DisableDBGStandbyMode(void)
|
||||
{
|
||||
CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
|
||||
}
|
||||
void HAL_DBGMCU_DisableDBGStandbyMode(void) { CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY); }
|
||||
|
||||
/**
|
||||
* @brief Return the unique device identifier (UID based on 96 bits)
|
||||
* @param UID pointer to 3 words array.
|
||||
* @retval Device identifier
|
||||
*/
|
||||
void HAL_GetUID(uint32_t *UID)
|
||||
{
|
||||
void HAL_GetUID(uint32_t *UID) {
|
||||
UID[0] = (uint32_t)(READ_REG(*((uint32_t *)UID_BASE)));
|
||||
UID[1] = (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE + 4U))));
|
||||
UID[2] = (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE + 8U))));
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -139,8 +139,7 @@
|
||||
* @param hadc: ADC handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef *hadc) {
|
||||
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
||||
uint32_t tickstart;
|
||||
__IO uint32_t wait_loop_index = 0U;
|
||||
@@ -159,22 +158,16 @@ HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc)
|
||||
tmp_hal_status = ADC_ConversionStop_Disable(hadc);
|
||||
|
||||
/* Check if ADC is effectively disabled */
|
||||
if (tmp_hal_status == HAL_OK)
|
||||
{
|
||||
if (tmp_hal_status == HAL_OK) {
|
||||
/* Set ADC state */
|
||||
ADC_STATE_CLR_SET(hadc->State,
|
||||
HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
|
||||
HAL_ADC_STATE_BUSY_INTERNAL);
|
||||
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY, HAL_ADC_STATE_BUSY_INTERNAL);
|
||||
|
||||
/* Hardware prerequisite: delay before starting the calibration. */
|
||||
/* - Computation of CPU clock cycles corresponding to ADC clock cycles. */
|
||||
/* - Wait for the expected ADC clock cycles delay */
|
||||
wait_loop_index = ((SystemCoreClock
|
||||
/ HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_ADC))
|
||||
* ADC_PRECALIBRATION_DELAY_ADCCLOCKCYCLES );
|
||||
wait_loop_index = ((SystemCoreClock / HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_ADC)) * ADC_PRECALIBRATION_DELAY_ADCCLOCKCYCLES);
|
||||
|
||||
while(wait_loop_index != 0U)
|
||||
{
|
||||
while (wait_loop_index != 0U) {
|
||||
wait_loop_index--;
|
||||
}
|
||||
|
||||
@@ -187,14 +180,10 @@ HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc)
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait for calibration reset completion */
|
||||
while(HAL_IS_BIT_SET(hadc->Instance->CR2, ADC_CR2_RSTCAL))
|
||||
{
|
||||
if((HAL_GetTick() - tickstart) > ADC_CALIBRATION_TIMEOUT)
|
||||
{
|
||||
while (HAL_IS_BIT_SET(hadc->Instance->CR2, ADC_CR2_RSTCAL)) {
|
||||
if ((HAL_GetTick() - tickstart) > ADC_CALIBRATION_TIMEOUT) {
|
||||
/* Update ADC state machine to error */
|
||||
ADC_STATE_CLR_SET(hadc->State,
|
||||
HAL_ADC_STATE_BUSY_INTERNAL,
|
||||
HAL_ADC_STATE_ERROR_INTERNAL);
|
||||
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_BUSY_INTERNAL, HAL_ADC_STATE_ERROR_INTERNAL);
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hadc);
|
||||
@@ -203,21 +192,16 @@ HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* 4. Start ADC calibration */
|
||||
SET_BIT(hadc->Instance->CR2, ADC_CR2_CAL);
|
||||
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait for calibration completion */
|
||||
while(HAL_IS_BIT_SET(hadc->Instance->CR2, ADC_CR2_CAL))
|
||||
{
|
||||
if((HAL_GetTick() - tickstart) > ADC_CALIBRATION_TIMEOUT)
|
||||
{
|
||||
while (HAL_IS_BIT_SET(hadc->Instance->CR2, ADC_CR2_CAL)) {
|
||||
if ((HAL_GetTick() - tickstart) > ADC_CALIBRATION_TIMEOUT) {
|
||||
/* Update ADC state machine to error */
|
||||
ADC_STATE_CLR_SET(hadc->State,
|
||||
HAL_ADC_STATE_BUSY_INTERNAL,
|
||||
HAL_ADC_STATE_ERROR_INTERNAL);
|
||||
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_BUSY_INTERNAL, HAL_ADC_STATE_ERROR_INTERNAL);
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hadc);
|
||||
@@ -227,9 +211,7 @@ HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc)
|
||||
}
|
||||
|
||||
/* Set ADC state */
|
||||
ADC_STATE_CLR_SET(hadc->State,
|
||||
HAL_ADC_STATE_BUSY_INTERNAL,
|
||||
HAL_ADC_STATE_READY);
|
||||
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_BUSY_INTERNAL, HAL_ADC_STATE_READY);
|
||||
}
|
||||
|
||||
/* Process unlocked */
|
||||
@@ -245,8 +227,7 @@ HAL_StatusTypeDef HAL_ADCEx_Calibration_Start(ADC_HandleTypeDef* hadc)
|
||||
* @param hadc: ADC handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef *hadc) {
|
||||
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
||||
|
||||
/* Check the parameters */
|
||||
@@ -259,23 +240,17 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc)
|
||||
tmp_hal_status = ADC_Enable(hadc);
|
||||
|
||||
/* Start conversion if ADC is effectively enabled */
|
||||
if (tmp_hal_status == HAL_OK)
|
||||
{
|
||||
if (tmp_hal_status == HAL_OK) {
|
||||
/* Set ADC state */
|
||||
/* - Clear state bitfield related to injected group conversion results */
|
||||
/* - Set state bitfield related to injected operation */
|
||||
ADC_STATE_CLR_SET(hadc->State,
|
||||
HAL_ADC_STATE_READY | HAL_ADC_STATE_INJ_EOC,
|
||||
HAL_ADC_STATE_INJ_BUSY);
|
||||
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_READY | HAL_ADC_STATE_INJ_EOC, HAL_ADC_STATE_INJ_BUSY);
|
||||
|
||||
/* Case of independent mode or multimode (for devices with several ADCs): */
|
||||
/* Set multimode state. */
|
||||
if (ADC_NONMULTIMODE_OR_MULTIMODEMASTER(hadc))
|
||||
{
|
||||
if (ADC_NONMULTIMODE_OR_MULTIMODEMASTER(hadc)) {
|
||||
CLEAR_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
SET_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
|
||||
}
|
||||
|
||||
@@ -283,8 +258,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc)
|
||||
/* Note: On this device, there is no ADC error code fields related to */
|
||||
/* conversions on group injected only. In case of conversion on */
|
||||
/* going on group regular, no error code is reset. */
|
||||
if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_REG_BUSY))
|
||||
{
|
||||
if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_REG_BUSY)) {
|
||||
/* Reset ADC all error code fields */
|
||||
ADC_CLEAR_ERRORCODE(hadc);
|
||||
}
|
||||
@@ -307,23 +281,16 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc)
|
||||
/* Case of multimode enabled (for devices with several ADCs): if ADC is */
|
||||
/* slave, ADC is enabled only (conversion is not started). If ADC is */
|
||||
/* master, ADC is enabled and conversion is started. */
|
||||
if (HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO))
|
||||
{
|
||||
if (ADC_IS_SOFTWARE_START_INJECTED(hadc) &&
|
||||
ADC_NONMULTIMODE_OR_MULTIMODEMASTER(hadc) )
|
||||
{
|
||||
if (HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO)) {
|
||||
if (ADC_IS_SOFTWARE_START_INJECTED(hadc) && ADC_NONMULTIMODE_OR_MULTIMODEMASTER(hadc)) {
|
||||
/* Start ADC conversion on injected group with SW start */
|
||||
SET_BIT(hadc->Instance->CR2, (ADC_CR2_JSWSTART | ADC_CR2_JEXTTRIG));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Start ADC conversion on injected group with external trigger */
|
||||
SET_BIT(hadc->Instance->CR2, ADC_CR2_JEXTTRIG);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hadc);
|
||||
}
|
||||
@@ -344,8 +311,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart(ADC_HandleTypeDef* hadc)
|
||||
* @param hadc: ADC handle
|
||||
* @retval None
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef *hadc) {
|
||||
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
||||
|
||||
/* Check the parameters */
|
||||
@@ -360,24 +326,17 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc)
|
||||
/* continue (injected and regular groups stop conversion and ADC disable */
|
||||
/* are common) */
|
||||
/* - In case of auto-injection mode, HAL_ADC_Stop must be used. */
|
||||
if(((hadc->State & HAL_ADC_STATE_REG_BUSY) == RESET) &&
|
||||
HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO) )
|
||||
{
|
||||
if (((hadc->State & HAL_ADC_STATE_REG_BUSY) == RESET) && HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO)) {
|
||||
/* Stop potential conversion on going, on regular and injected groups */
|
||||
/* Disable ADC peripheral */
|
||||
tmp_hal_status = ADC_ConversionStop_Disable(hadc);
|
||||
|
||||
/* Check if ADC is effectively disabled */
|
||||
if (tmp_hal_status == HAL_OK)
|
||||
{
|
||||
if (tmp_hal_status == HAL_OK) {
|
||||
/* Set ADC state */
|
||||
ADC_STATE_CLR_SET(hadc->State,
|
||||
HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
|
||||
HAL_ADC_STATE_READY);
|
||||
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY, HAL_ADC_STATE_READY);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Update ADC state machine to error */
|
||||
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
|
||||
|
||||
@@ -397,8 +356,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStop(ADC_HandleTypeDef* hadc)
|
||||
* @param Timeout: Timeout value in millisecond.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, uint32_t Timeout)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef *hadc, uint32_t Timeout) {
|
||||
uint32_t tickstart;
|
||||
|
||||
/* Variables for polling in case of scan mode enabled and polling for each */
|
||||
@@ -428,16 +386,12 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, u
|
||||
/* settings, conversion time range can be from 28 to 32256 CPU cycles). */
|
||||
/* As flag JEOC is not set after each conversion, no timeout status can */
|
||||
/* be set. */
|
||||
if ((hadc->Instance->JSQR & ADC_JSQR_JL) == RESET)
|
||||
{
|
||||
if ((hadc->Instance->JSQR & ADC_JSQR_JL) == RESET) {
|
||||
/* Wait until End of Conversion flag is raised */
|
||||
while(HAL_IS_BIT_CLR(hadc->Instance->SR, ADC_FLAG_JEOC))
|
||||
{
|
||||
while (HAL_IS_BIT_CLR(hadc->Instance->SR, ADC_FLAG_JEOC)) {
|
||||
/* Check if timeout is disabled (set to infinite wait) */
|
||||
if(Timeout != HAL_MAX_DELAY)
|
||||
{
|
||||
if((Timeout == 0U) || ((HAL_GetTick() - tickstart ) > Timeout))
|
||||
{
|
||||
if (Timeout != HAL_MAX_DELAY) {
|
||||
if ((Timeout == 0U) || ((HAL_GetTick() - tickstart) > Timeout)) {
|
||||
/* Update ADC state machine to timeout */
|
||||
SET_BIT(hadc->State, HAL_ADC_STATE_TIMEOUT);
|
||||
|
||||
@@ -448,24 +402,17 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, u
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Replace polling by wait for maximum conversion time */
|
||||
/* - Computation of CPU clock cycles corresponding to ADC clock cycles */
|
||||
/* and ADC maximum conversion cycles on all channels. */
|
||||
/* - Wait for the expected ADC clock cycles delay */
|
||||
Conversion_Timeout_CPU_cycles_max = ((SystemCoreClock
|
||||
/ HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_ADC))
|
||||
* ADC_CONVCYCLES_MAX_RANGE(hadc) );
|
||||
Conversion_Timeout_CPU_cycles_max = ((SystemCoreClock / HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_ADC)) * ADC_CONVCYCLES_MAX_RANGE(hadc));
|
||||
|
||||
while(Conversion_Timeout_CPU_cycles < Conversion_Timeout_CPU_cycles_max)
|
||||
{
|
||||
while (Conversion_Timeout_CPU_cycles < Conversion_Timeout_CPU_cycles_max) {
|
||||
/* Check if timeout is disabled (set to infinite wait) */
|
||||
if(Timeout != HAL_MAX_DELAY)
|
||||
{
|
||||
if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
|
||||
{
|
||||
if (Timeout != HAL_MAX_DELAY) {
|
||||
if ((Timeout == 0) || ((HAL_GetTick() - tickstart) > Timeout)) {
|
||||
/* Update ADC state machine to timeout */
|
||||
SET_BIT(hadc->State, HAL_ADC_STATE_TIMEOUT);
|
||||
|
||||
@@ -490,16 +437,11 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, u
|
||||
/* Determine whether any further conversion upcoming on group injected */
|
||||
/* by external trigger or by automatic injected conversion */
|
||||
/* from group regular. */
|
||||
if(ADC_IS_SOFTWARE_START_INJECTED(hadc) ||
|
||||
(HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO) &&
|
||||
(ADC_IS_SOFTWARE_START_REGULAR(hadc) &&
|
||||
(hadc->Init.ContinuousConvMode == DISABLE) ) ) )
|
||||
{
|
||||
if (ADC_IS_SOFTWARE_START_INJECTED(hadc) || (HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO) && (ADC_IS_SOFTWARE_START_REGULAR(hadc) && (hadc->Init.ContinuousConvMode == DISABLE)))) {
|
||||
/* Set ADC state */
|
||||
CLEAR_BIT(hadc->State, HAL_ADC_STATE_INJ_BUSY);
|
||||
|
||||
if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_REG_BUSY))
|
||||
{
|
||||
if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_REG_BUSY)) {
|
||||
SET_BIT(hadc->State, HAL_ADC_STATE_READY);
|
||||
}
|
||||
}
|
||||
@@ -515,8 +457,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedPollForConversion(ADC_HandleTypeDef* hadc, u
|
||||
* @param hadc: ADC handle
|
||||
* @retval HAL status.
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef *hadc) {
|
||||
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
||||
|
||||
/* Check the parameters */
|
||||
@@ -529,23 +470,17 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc)
|
||||
tmp_hal_status = ADC_Enable(hadc);
|
||||
|
||||
/* Start conversion if ADC is effectively enabled */
|
||||
if (tmp_hal_status == HAL_OK)
|
||||
{
|
||||
if (tmp_hal_status == HAL_OK) {
|
||||
/* Set ADC state */
|
||||
/* - Clear state bitfield related to injected group conversion results */
|
||||
/* - Set state bitfield related to injected operation */
|
||||
ADC_STATE_CLR_SET(hadc->State,
|
||||
HAL_ADC_STATE_READY | HAL_ADC_STATE_INJ_EOC,
|
||||
HAL_ADC_STATE_INJ_BUSY);
|
||||
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_READY | HAL_ADC_STATE_INJ_EOC, HAL_ADC_STATE_INJ_BUSY);
|
||||
|
||||
/* Case of independent mode or multimode (for devices with several ADCs): */
|
||||
/* Set multimode state. */
|
||||
if (ADC_NONMULTIMODE_OR_MULTIMODEMASTER(hadc))
|
||||
{
|
||||
if (ADC_NONMULTIMODE_OR_MULTIMODEMASTER(hadc)) {
|
||||
CLEAR_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
SET_BIT(hadc->State, HAL_ADC_STATE_MULTIMODE_SLAVE);
|
||||
}
|
||||
|
||||
@@ -553,8 +488,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc)
|
||||
/* Note: On this device, there is no ADC error code fields related to */
|
||||
/* conversions on group injected only. In case of conversion on */
|
||||
/* going on group regular, no error code is reset. */
|
||||
if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_REG_BUSY))
|
||||
{
|
||||
if (HAL_IS_BIT_CLR(hadc->State, HAL_ADC_STATE_REG_BUSY)) {
|
||||
/* Reset ADC all error code fields */
|
||||
ADC_CLEAR_ERRORCODE(hadc);
|
||||
}
|
||||
@@ -577,23 +511,16 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc)
|
||||
/* trigger event. */
|
||||
/* If automatic injected conversion is enabled, conversion will start */
|
||||
/* after next regular group conversion. */
|
||||
if (HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO))
|
||||
{
|
||||
if (ADC_IS_SOFTWARE_START_INJECTED(hadc) &&
|
||||
ADC_NONMULTIMODE_OR_MULTIMODEMASTER(hadc) )
|
||||
{
|
||||
if (HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO)) {
|
||||
if (ADC_IS_SOFTWARE_START_INJECTED(hadc) && ADC_NONMULTIMODE_OR_MULTIMODEMASTER(hadc)) {
|
||||
/* Start ADC conversion on injected group with SW start */
|
||||
SET_BIT(hadc->Instance->CR2, (ADC_CR2_JSWSTART | ADC_CR2_JEXTTRIG));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Start ADC conversion on injected group with external trigger */
|
||||
SET_BIT(hadc->Instance->CR2, ADC_CR2_JEXTTRIG);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hadc);
|
||||
}
|
||||
@@ -614,8 +541,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStart_IT(ADC_HandleTypeDef* hadc)
|
||||
* @param hadc: ADC handle
|
||||
* @retval None
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef *hadc) {
|
||||
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
||||
|
||||
/* Check the parameters */
|
||||
@@ -630,27 +556,20 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc)
|
||||
/* continue (injected and regular groups stop conversion and ADC disable */
|
||||
/* are common) */
|
||||
/* - In case of auto-injection mode, HAL_ADC_Stop must be used. */
|
||||
if(((hadc->State & HAL_ADC_STATE_REG_BUSY) == RESET) &&
|
||||
HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO) )
|
||||
{
|
||||
if (((hadc->State & HAL_ADC_STATE_REG_BUSY) == RESET) && HAL_IS_BIT_CLR(hadc->Instance->CR1, ADC_CR1_JAUTO)) {
|
||||
/* Stop potential conversion on going, on regular and injected groups */
|
||||
/* Disable ADC peripheral */
|
||||
tmp_hal_status = ADC_ConversionStop_Disable(hadc);
|
||||
|
||||
/* Check if ADC is effectively disabled */
|
||||
if (tmp_hal_status == HAL_OK)
|
||||
{
|
||||
if (tmp_hal_status == HAL_OK) {
|
||||
/* Disable ADC end of conversion interrupt for injected channels */
|
||||
__HAL_ADC_DISABLE_IT(hadc, ADC_IT_JEOC);
|
||||
|
||||
/* Set ADC state */
|
||||
ADC_STATE_CLR_SET(hadc->State,
|
||||
HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
|
||||
HAL_ADC_STATE_READY);
|
||||
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY, HAL_ADC_STATE_READY);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Update ADC state machine to error */
|
||||
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
|
||||
|
||||
@@ -683,8 +602,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedStop_IT(ADC_HandleTypeDef* hadc)
|
||||
* @param Length: The length of data to be transferred from ADC peripheral to memory.
|
||||
* @retval None
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t* pData, uint32_t Length)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef *hadc, uint32_t *pData, uint32_t Length) {
|
||||
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
||||
ADC_HandleTypeDef tmphadcSlave;
|
||||
|
||||
@@ -702,8 +620,7 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t
|
||||
/* conversion trigger ADC_SOFTWARE_START. */
|
||||
/* Note: External trigger of ADC slave must be enabled, it is already done */
|
||||
/* into function "HAL_ADC_Init()". */
|
||||
if(!ADC_IS_SOFTWARE_START_REGULAR(&tmphadcSlave))
|
||||
{
|
||||
if (!ADC_IS_SOFTWARE_START_REGULAR(&tmphadcSlave)) {
|
||||
/* Update ADC state machine to error */
|
||||
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
|
||||
|
||||
@@ -716,25 +633,20 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t
|
||||
/* Enable the ADC peripherals: master and slave (in case if not already */
|
||||
/* enabled previously) */
|
||||
tmp_hal_status = ADC_Enable(hadc);
|
||||
if (tmp_hal_status == HAL_OK)
|
||||
{
|
||||
if (tmp_hal_status == HAL_OK) {
|
||||
tmp_hal_status = ADC_Enable(&tmphadcSlave);
|
||||
}
|
||||
|
||||
/* Start conversion if all ADCs of multimode are effectively enabled */
|
||||
if (tmp_hal_status == HAL_OK)
|
||||
{
|
||||
if (tmp_hal_status == HAL_OK) {
|
||||
/* Set ADC state (ADC master) */
|
||||
/* - Clear state bitfield related to regular group conversion results */
|
||||
/* - Set state bitfield related to regular operation */
|
||||
ADC_STATE_CLR_SET(hadc->State,
|
||||
HAL_ADC_STATE_READY | HAL_ADC_STATE_REG_EOC | HAL_ADC_STATE_MULTIMODE_SLAVE,
|
||||
HAL_ADC_STATE_REG_BUSY);
|
||||
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_READY | HAL_ADC_STATE_REG_EOC | HAL_ADC_STATE_MULTIMODE_SLAVE, HAL_ADC_STATE_REG_BUSY);
|
||||
|
||||
/* If conversions on group regular are also triggering group injected, */
|
||||
/* update ADC state. */
|
||||
if (READ_BIT(hadc->Instance->CR1, ADC_CR1_JAUTO) != RESET)
|
||||
{
|
||||
if (READ_BIT(hadc->Instance->CR1, ADC_CR1_JAUTO) != RESET) {
|
||||
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_INJ_EOC, HAL_ADC_STATE_INJ_BUSY);
|
||||
}
|
||||
|
||||
@@ -746,7 +658,6 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t
|
||||
/* Set ADC error code to none */
|
||||
ADC_CLEAR_ERRORCODE(hadc);
|
||||
|
||||
|
||||
/* Set the DMA transfer complete callback */
|
||||
hadc->DMA_Handle->XferCpltCallback = ADC_DMAConvCplt;
|
||||
|
||||
@@ -756,7 +667,6 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t
|
||||
/* Set the DMA error callback */
|
||||
hadc->DMA_Handle->XferErrorCallback = ADC_DMAError;
|
||||
|
||||
|
||||
/* Manage ADC and DMA start: ADC overrun interruption, DMA start, ADC */
|
||||
/* start (in case of SW start): */
|
||||
|
||||
@@ -775,19 +685,14 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t
|
||||
/* trigger event. */
|
||||
/* Note: Alternate trigger for single conversion could be to force an */
|
||||
/* additional set of bit ADON "hadc->Instance->CR2 |= ADC_CR2_ADON;"*/
|
||||
if (ADC_IS_SOFTWARE_START_REGULAR(hadc))
|
||||
{
|
||||
if (ADC_IS_SOFTWARE_START_REGULAR(hadc)) {
|
||||
/* Start ADC conversion on regular group with SW start */
|
||||
SET_BIT(hadc->Instance->CR2, (ADC_CR2_SWSTART | ADC_CR2_EXTTRIG));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Start ADC conversion on regular group with external trigger */
|
||||
SET_BIT(hadc->Instance->CR2, ADC_CR2_EXTTRIG);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hadc);
|
||||
}
|
||||
@@ -809,8 +714,7 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStart_DMA(ADC_HandleTypeDef* hadc, uint32_t
|
||||
* @param hadc: ADC handle of ADC master (handle of ADC slave must not be used)
|
||||
* @retval None
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef* hadc)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef *hadc) {
|
||||
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
||||
ADC_HandleTypeDef tmphadcSlave;
|
||||
|
||||
@@ -820,14 +724,12 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef* hadc)
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hadc);
|
||||
|
||||
|
||||
/* Stop potential conversion on going, on regular and injected groups */
|
||||
/* Disable ADC master peripheral */
|
||||
tmp_hal_status = ADC_ConversionStop_Disable(hadc);
|
||||
|
||||
/* Check if ADC is effectively disabled */
|
||||
if(tmp_hal_status == HAL_OK)
|
||||
{
|
||||
if (tmp_hal_status == HAL_OK) {
|
||||
/* Set a temporary handle of the ADC slave associated to the ADC master */
|
||||
ADC_MULTI_SLAVE(hadc, &tmphadcSlave);
|
||||
|
||||
@@ -835,8 +737,7 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef* hadc)
|
||||
tmp_hal_status = ADC_ConversionStop_Disable(&tmphadcSlave);
|
||||
|
||||
/* Check if ADC is effectively disabled */
|
||||
if(tmp_hal_status != HAL_OK)
|
||||
{
|
||||
if (tmp_hal_status != HAL_OK) {
|
||||
/* Update ADC state machine to error */
|
||||
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_INTERNAL);
|
||||
|
||||
@@ -857,9 +758,7 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef* hadc)
|
||||
tmp_hal_status = HAL_DMA_Abort(hadc->DMA_Handle);
|
||||
|
||||
/* Change ADC state (ADC master) */
|
||||
ADC_STATE_CLR_SET(hadc->State,
|
||||
HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY,
|
||||
HAL_ADC_STATE_READY);
|
||||
ADC_STATE_CLR_SET(hadc->State, HAL_ADC_STATE_REG_BUSY | HAL_ADC_STATE_INJ_BUSY, HAL_ADC_STATE_READY);
|
||||
}
|
||||
|
||||
/* Process unlocked */
|
||||
@@ -898,8 +797,7 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeStop_DMA(ADC_HandleTypeDef* hadc)
|
||||
* @arg ADC_INJECTED_RANK_4: Injected Channel4 selected
|
||||
* @retval ADC group injected conversion data
|
||||
*/
|
||||
uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef* hadc, uint32_t InjectedRank)
|
||||
{
|
||||
uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef *hadc, uint32_t InjectedRank) {
|
||||
uint32_t tmp_jdr = 0U;
|
||||
|
||||
/* Check the parameters */
|
||||
@@ -907,8 +805,7 @@ uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef* hadc, uint32_t InjectedRa
|
||||
assert_param(IS_ADC_INJECTED_RANK(InjectedRank));
|
||||
|
||||
/* Get ADC converted value */
|
||||
switch(InjectedRank)
|
||||
{
|
||||
switch (InjectedRank) {
|
||||
case ADC_INJECTED_RANK_4:
|
||||
tmp_jdr = hadc->Instance->JDR4;
|
||||
break;
|
||||
@@ -935,8 +832,7 @@ uint32_t HAL_ADCEx_InjectedGetValue(ADC_HandleTypeDef* hadc, uint32_t InjectedRa
|
||||
* @param hadc: ADC handle of ADC master (handle of ADC slave must not be used)
|
||||
* @retval The converted data value.
|
||||
*/
|
||||
uint32_t HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef* hadc)
|
||||
{
|
||||
uint32_t HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef *hadc) {
|
||||
uint32_t tmpDR = 0U;
|
||||
|
||||
/* Check the parameters */
|
||||
@@ -952,8 +848,7 @@ uint32_t HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef* hadc)
|
||||
/* only if ADC1 DMA mode is enabled. */
|
||||
tmpDR = hadc->Instance->DR;
|
||||
|
||||
if (HAL_IS_BIT_CLR(ADC1->CR2, ADC_CR2_DMA))
|
||||
{
|
||||
if (HAL_IS_BIT_CLR(ADC1->CR2, ADC_CR2_DMA)) {
|
||||
tmpDR |= (ADC2->DR << 16U);
|
||||
}
|
||||
|
||||
@@ -967,8 +862,7 @@ uint32_t HAL_ADCEx_MultiModeGetValue(ADC_HandleTypeDef* hadc)
|
||||
* @param hadc: ADC handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc)
|
||||
{
|
||||
__weak void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef *hadc) {
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(hadc);
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
@@ -1009,8 +903,7 @@ __weak void HAL_ADCEx_InjectedConvCpltCallback(ADC_HandleTypeDef* hadc)
|
||||
* injected group.
|
||||
* @retval None
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_InjectionConfTypeDef* sConfigInjected)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef *hadc, ADC_InjectionConfTypeDef *sConfigInjected) {
|
||||
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
||||
__IO uint32_t wait_loop_index = 0U;
|
||||
|
||||
@@ -1022,8 +915,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_I
|
||||
assert_param(IS_ADC_EXTTRIGINJEC(sConfigInjected->ExternalTrigInjecConv));
|
||||
assert_param(IS_ADC_RANGE(sConfigInjected->InjectedOffset));
|
||||
|
||||
if(hadc->Init.ScanConvMode != ADC_SCAN_DISABLE)
|
||||
{
|
||||
if (hadc->Init.ScanConvMode != ADC_SCAN_DISABLE) {
|
||||
assert_param(IS_ADC_INJECTED_RANK(sConfigInjected->InjectedRank));
|
||||
assert_param(IS_ADC_INJECTED_NB_CONV(sConfigInjected->InjectedNbrOfConversion));
|
||||
assert_param(IS_FUNCTIONAL_STATE(sConfigInjected->InjectedDiscontinuousConvMode));
|
||||
@@ -1071,31 +963,20 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_I
|
||||
/* Since injected channels rank conv. order depends on total number of */
|
||||
/* injected conversions, selected rank must be below or equal to total */
|
||||
/* number of injected conversions to be updated. */
|
||||
if (sConfigInjected->InjectedRank <= sConfigInjected->InjectedNbrOfConversion)
|
||||
{
|
||||
if (sConfigInjected->InjectedRank <= sConfigInjected->InjectedNbrOfConversion) {
|
||||
/* Clear the old SQx bits for the selected rank */
|
||||
/* Set the SQx bits for the selected rank */
|
||||
MODIFY_REG(hadc->Instance->JSQR,
|
||||
|
||||
ADC_JSQR_JL |
|
||||
ADC_JSQR_RK_JL(ADC_JSQR_JSQ1,
|
||||
sConfigInjected->InjectedRank,
|
||||
sConfigInjected->InjectedNbrOfConversion) ,
|
||||
ADC_JSQR_JL | ADC_JSQR_RK_JL(ADC_JSQR_JSQ1, sConfigInjected->InjectedRank, sConfigInjected->InjectedNbrOfConversion),
|
||||
|
||||
ADC_JSQR_JL_SHIFT(sConfigInjected->InjectedNbrOfConversion) |
|
||||
ADC_JSQR_RK_JL(sConfigInjected->InjectedChannel,
|
||||
sConfigInjected->InjectedRank,
|
||||
sConfigInjected->InjectedNbrOfConversion) );
|
||||
}
|
||||
else
|
||||
{
|
||||
ADC_JSQR_JL_SHIFT(sConfigInjected->InjectedNbrOfConversion)
|
||||
| ADC_JSQR_RK_JL(sConfigInjected->InjectedChannel, sConfigInjected->InjectedRank, sConfigInjected->InjectedNbrOfConversion));
|
||||
} else {
|
||||
/* Clear the old SQx bits for the selected rank */
|
||||
MODIFY_REG(hadc->Instance->JSQR,
|
||||
|
||||
ADC_JSQR_JL |
|
||||
ADC_JSQR_RK_JL(ADC_JSQR_JSQ1,
|
||||
sConfigInjected->InjectedRank,
|
||||
sConfigInjected->InjectedNbrOfConversion) ,
|
||||
ADC_JSQR_JL | ADC_JSQR_RK_JL(ADC_JSQR_JSQ1, sConfigInjected->InjectedRank, sConfigInjected->InjectedNbrOfConversion),
|
||||
|
||||
0x00000000U);
|
||||
}
|
||||
@@ -1110,29 +991,20 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_I
|
||||
/* - Injected discontinuous mode */
|
||||
/* Note: In case of ADC already enabled, caution to not launch an unwanted */
|
||||
/* conversion while modifying register CR2 by writing 1 to bit ADON. */
|
||||
if (ADC_IS_ENABLE(hadc) == RESET)
|
||||
{
|
||||
MODIFY_REG(hadc->Instance->CR2 ,
|
||||
ADC_CR2_JEXTSEL |
|
||||
ADC_CR2_ADON ,
|
||||
ADC_CFGR_JEXTSEL(hadc, sConfigInjected->ExternalTrigInjecConv) );
|
||||
if (ADC_IS_ENABLE(hadc) == RESET) {
|
||||
MODIFY_REG(hadc->Instance->CR2, ADC_CR2_JEXTSEL | ADC_CR2_ADON, ADC_CFGR_JEXTSEL(hadc, sConfigInjected->ExternalTrigInjecConv));
|
||||
}
|
||||
|
||||
|
||||
/* Configuration of injected group */
|
||||
/* - Automatic injected conversion */
|
||||
/* - Injected discontinuous mode */
|
||||
|
||||
/* Automatic injected conversion can be enabled if injected group */
|
||||
/* external triggers are disabled. */
|
||||
if (sConfigInjected->AutoInjectedConv == ENABLE)
|
||||
{
|
||||
if (sConfigInjected->ExternalTrigInjecConv == ADC_INJECTED_SOFTWARE_START)
|
||||
{
|
||||
if (sConfigInjected->AutoInjectedConv == ENABLE) {
|
||||
if (sConfigInjected->ExternalTrigInjecConv == ADC_INJECTED_SOFTWARE_START) {
|
||||
SET_BIT(hadc->Instance->CR1, ADC_CR1_JAUTO);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Update ADC state machine to error */
|
||||
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
|
||||
|
||||
@@ -1142,14 +1014,10 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_I
|
||||
|
||||
/* Injected discontinuous can be enabled only if auto-injected mode is */
|
||||
/* disabled. */
|
||||
if (sConfigInjected->InjectedDiscontinuousConvMode == ENABLE)
|
||||
{
|
||||
if (sConfigInjected->AutoInjectedConv == DISABLE)
|
||||
{
|
||||
if (sConfigInjected->InjectedDiscontinuousConvMode == ENABLE) {
|
||||
if (sConfigInjected->AutoInjectedConv == DISABLE) {
|
||||
SET_BIT(hadc->Instance->CR1, ADC_CR1_JDISCEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Update ADC state machine to error */
|
||||
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
|
||||
|
||||
@@ -1157,88 +1025,61 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_I
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* InjectedChannel sampling time configuration */
|
||||
/* For channels 10 to 17 */
|
||||
if (sConfigInjected->InjectedChannel >= ADC_CHANNEL_10)
|
||||
if (sConfigInjected->InjectedChannel >= ADC_CHANNEL_10) {
|
||||
MODIFY_REG(hadc->Instance->SMPR1, ADC_SMPR1(ADC_SMPR1_SMP10, sConfigInjected->InjectedChannel), ADC_SMPR1(sConfigInjected->InjectedSamplingTime, sConfigInjected->InjectedChannel));
|
||||
} else /* For channels 0 to 9 */
|
||||
{
|
||||
MODIFY_REG(hadc->Instance->SMPR1 ,
|
||||
ADC_SMPR1(ADC_SMPR1_SMP10, sConfigInjected->InjectedChannel) ,
|
||||
ADC_SMPR1(sConfigInjected->InjectedSamplingTime, sConfigInjected->InjectedChannel) );
|
||||
}
|
||||
else /* For channels 0 to 9 */
|
||||
{
|
||||
MODIFY_REG(hadc->Instance->SMPR2 ,
|
||||
ADC_SMPR2(ADC_SMPR2_SMP0, sConfigInjected->InjectedChannel) ,
|
||||
ADC_SMPR2(sConfigInjected->InjectedSamplingTime, sConfigInjected->InjectedChannel) );
|
||||
MODIFY_REG(hadc->Instance->SMPR2, ADC_SMPR2(ADC_SMPR2_SMP0, sConfigInjected->InjectedChannel), ADC_SMPR2(sConfigInjected->InjectedSamplingTime, sConfigInjected->InjectedChannel));
|
||||
}
|
||||
|
||||
/* If ADC1 InjectedChannel_16 or InjectedChannel_17 is selected, enable Temperature sensor */
|
||||
/* and VREFINT measurement path. */
|
||||
if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR) ||
|
||||
(sConfigInjected->InjectedChannel == ADC_CHANNEL_VREFINT) )
|
||||
{
|
||||
if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR) || (sConfigInjected->InjectedChannel == ADC_CHANNEL_VREFINT)) {
|
||||
SET_BIT(hadc->Instance->CR2, ADC_CR2_TSVREFE);
|
||||
}
|
||||
|
||||
|
||||
/* Configure the offset: offset enable/disable, InjectedChannel, offset value */
|
||||
switch(sConfigInjected->InjectedRank)
|
||||
{
|
||||
switch (sConfigInjected->InjectedRank) {
|
||||
case 1:
|
||||
/* Set injected channel 1 offset */
|
||||
MODIFY_REG(hadc->Instance->JOFR1,
|
||||
ADC_JOFR1_JOFFSET1,
|
||||
sConfigInjected->InjectedOffset);
|
||||
MODIFY_REG(hadc->Instance->JOFR1, ADC_JOFR1_JOFFSET1, sConfigInjected->InjectedOffset);
|
||||
break;
|
||||
case 2:
|
||||
/* Set injected channel 2 offset */
|
||||
MODIFY_REG(hadc->Instance->JOFR2,
|
||||
ADC_JOFR2_JOFFSET2,
|
||||
sConfigInjected->InjectedOffset);
|
||||
MODIFY_REG(hadc->Instance->JOFR2, ADC_JOFR2_JOFFSET2, sConfigInjected->InjectedOffset);
|
||||
break;
|
||||
case 3:
|
||||
/* Set injected channel 3 offset */
|
||||
MODIFY_REG(hadc->Instance->JOFR3,
|
||||
ADC_JOFR3_JOFFSET3,
|
||||
sConfigInjected->InjectedOffset);
|
||||
MODIFY_REG(hadc->Instance->JOFR3, ADC_JOFR3_JOFFSET3, sConfigInjected->InjectedOffset);
|
||||
break;
|
||||
case 4:
|
||||
default:
|
||||
MODIFY_REG(hadc->Instance->JOFR4,
|
||||
ADC_JOFR4_JOFFSET4,
|
||||
sConfigInjected->InjectedOffset);
|
||||
MODIFY_REG(hadc->Instance->JOFR4, ADC_JOFR4_JOFFSET4, sConfigInjected->InjectedOffset);
|
||||
break;
|
||||
}
|
||||
|
||||
/* If ADC1 Channel_16 or Channel_17 is selected, enable Temperature sensor */
|
||||
/* and VREFINT measurement path. */
|
||||
if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR) ||
|
||||
(sConfigInjected->InjectedChannel == ADC_CHANNEL_VREFINT) )
|
||||
{
|
||||
if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR) || (sConfigInjected->InjectedChannel == ADC_CHANNEL_VREFINT)) {
|
||||
/* For STM32F1 devices with several ADC: Only ADC1 can access internal */
|
||||
/* measurement channels (VrefInt/TempSensor). If these channels are */
|
||||
/* intended to be set on other ADC instances, an error is reported. */
|
||||
if (hadc->Instance == ADC1)
|
||||
{
|
||||
if (READ_BIT(hadc->Instance->CR2, ADC_CR2_TSVREFE) == RESET)
|
||||
{
|
||||
if (hadc->Instance == ADC1) {
|
||||
if (READ_BIT(hadc->Instance->CR2, ADC_CR2_TSVREFE) == RESET) {
|
||||
SET_BIT(hadc->Instance->CR2, ADC_CR2_TSVREFE);
|
||||
|
||||
if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR))
|
||||
{
|
||||
if ((sConfigInjected->InjectedChannel == ADC_CHANNEL_TEMPSENSOR)) {
|
||||
/* Delay for temperature sensor stabilization time */
|
||||
/* Compute number of CPU cycles to wait for */
|
||||
wait_loop_index = (ADC_TEMPSENSOR_DELAY_US * (SystemCoreClock / 1000000U));
|
||||
while(wait_loop_index != 0U)
|
||||
{
|
||||
while (wait_loop_index != 0U) {
|
||||
wait_loop_index--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Update ADC state machine to error */
|
||||
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
|
||||
|
||||
@@ -1270,8 +1111,7 @@ HAL_StatusTypeDef HAL_ADCEx_InjectedConfigChannel(ADC_HandleTypeDef* hadc, ADC_I
|
||||
* @param multimode: Structure of ADC multimode configuration
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef* hadc, ADC_MultiModeTypeDef* multimode)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef *hadc, ADC_MultiModeTypeDef *multimode) {
|
||||
HAL_StatusTypeDef tmp_hal_status = HAL_OK;
|
||||
ADC_HandleTypeDef tmphadcSlave;
|
||||
|
||||
@@ -1293,25 +1133,18 @@ HAL_StatusTypeDef HAL_ADCEx_MultiModeConfigChannel(ADC_HandleTypeDef* hadc, ADC_
|
||||
/* - Multimode mode selection */
|
||||
/* To optimize code, all multimode settings can be set when both ADCs of */
|
||||
/* the common group are in state: disabled. */
|
||||
if ((ADC_IS_ENABLE(hadc) == RESET) &&
|
||||
(ADC_IS_ENABLE(&tmphadcSlave) == RESET) &&
|
||||
(IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance)) )
|
||||
{
|
||||
MODIFY_REG(hadc->Instance->CR1,
|
||||
ADC_CR1_DUALMOD ,
|
||||
multimode->Mode );
|
||||
if ((ADC_IS_ENABLE(hadc) == RESET) && (ADC_IS_ENABLE(&tmphadcSlave) == RESET) && (IS_ADC_MULTIMODE_MASTER_INSTANCE(hadc->Instance))) {
|
||||
MODIFY_REG(hadc->Instance->CR1, ADC_CR1_DUALMOD, multimode->Mode);
|
||||
}
|
||||
/* If one of the ADC sharing the same common group is enabled, no update */
|
||||
/* could be done on neither of the multimode structure parameters. */
|
||||
else
|
||||
{
|
||||
else {
|
||||
/* Update ADC state machine to error */
|
||||
SET_BIT(hadc->State, HAL_ADC_STATE_ERROR_CONFIG);
|
||||
|
||||
tmp_hal_status = HAL_ERROR;
|
||||
}
|
||||
|
||||
|
||||
/* Process unlocked */
|
||||
__HAL_UNLOCK(hadc);
|
||||
|
||||
|
||||
@@ -120,7 +120,6 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup CORTEX_Exported_Functions_Group1 Initialization and de-initialization functions
|
||||
* @brief Initialization and Configuration functions
|
||||
*
|
||||
@@ -136,7 +135,6 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets the priority grouping field (preemption priority and subpriority)
|
||||
* using the required unlock sequence.
|
||||
@@ -156,8 +154,7 @@
|
||||
* The pending IRQ priority will be managed only by the subpriority.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
|
||||
{
|
||||
void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));
|
||||
|
||||
@@ -178,8 +175,7 @@ void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
|
||||
* A lower priority value indicates a higher priority.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
|
||||
{
|
||||
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority) {
|
||||
uint32_t prioritygroup = 0x00U;
|
||||
|
||||
/* Check the parameters */
|
||||
@@ -200,8 +196,7 @@ void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t Sub
|
||||
* (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h))
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
|
||||
|
||||
@@ -216,8 +211,7 @@ void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
|
||||
* (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h))
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_NVIC_DisableIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
void HAL_NVIC_DisableIRQ(IRQn_Type IRQn) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
|
||||
|
||||
@@ -229,8 +223,7 @@ void HAL_NVIC_DisableIRQ(IRQn_Type IRQn)
|
||||
* @brief Initiates a system reset request to reset the MCU.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_NVIC_SystemReset(void)
|
||||
{
|
||||
void HAL_NVIC_SystemReset(void) {
|
||||
/* System Reset */
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
@@ -242,10 +235,7 @@ void HAL_NVIC_SystemReset(void)
|
||||
* @retval status: - 0 Function succeeded.
|
||||
* - 1 Function failed.
|
||||
*/
|
||||
uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb)
|
||||
{
|
||||
return SysTick_Config(TicksNumb);
|
||||
}
|
||||
uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb) { return SysTick_Config(TicksNumb); }
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -271,8 +261,7 @@ uint32_t HAL_SYSTICK_Config(uint32_t TicksNumb)
|
||||
* @brief Disables the MPU
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_MPU_Disable(void)
|
||||
{
|
||||
void HAL_MPU_Disable(void) {
|
||||
/* Make sure outstanding transfers are done */
|
||||
__DMB();
|
||||
|
||||
@@ -294,8 +283,7 @@ void HAL_MPU_Disable(void)
|
||||
* @arg MPU_HFNMI_PRIVDEF
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_MPU_Enable(uint32_t MPU_Control)
|
||||
{
|
||||
void HAL_MPU_Enable(uint32_t MPU_Control) {
|
||||
/* Enable the MPU */
|
||||
MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
|
||||
|
||||
@@ -313,8 +301,7 @@ void HAL_MPU_Enable(uint32_t MPU_Control)
|
||||
* the initialization and configuration information.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init)
|
||||
{
|
||||
void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_MPU_REGION_NUMBER(MPU_Init->Number));
|
||||
assert_param(IS_MPU_REGION_ENABLE(MPU_Init->Enable));
|
||||
@@ -322,8 +309,7 @@ void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init)
|
||||
/* Set the Region number */
|
||||
MPU->RNR = MPU_Init->Number;
|
||||
|
||||
if ((MPU_Init->Enable) != RESET)
|
||||
{
|
||||
if ((MPU_Init->Enable) != RESET) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_MPU_INSTRUCTION_ACCESS(MPU_Init->DisableExec));
|
||||
assert_param(IS_MPU_REGION_PERMISSION_ATTRIBUTE(MPU_Init->AccessPermission));
|
||||
@@ -335,18 +321,10 @@ void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init)
|
||||
assert_param(IS_MPU_REGION_SIZE(MPU_Init->Size));
|
||||
|
||||
MPU->RBAR = MPU_Init->BaseAddress;
|
||||
MPU->RASR = ((uint32_t)MPU_Init->DisableExec << MPU_RASR_XN_Pos) |
|
||||
((uint32_t)MPU_Init->AccessPermission << MPU_RASR_AP_Pos) |
|
||||
((uint32_t)MPU_Init->TypeExtField << MPU_RASR_TEX_Pos) |
|
||||
((uint32_t)MPU_Init->IsShareable << MPU_RASR_S_Pos) |
|
||||
((uint32_t)MPU_Init->IsCacheable << MPU_RASR_C_Pos) |
|
||||
((uint32_t)MPU_Init->IsBufferable << MPU_RASR_B_Pos) |
|
||||
((uint32_t)MPU_Init->SubRegionDisable << MPU_RASR_SRD_Pos) |
|
||||
((uint32_t)MPU_Init->Size << MPU_RASR_SIZE_Pos) |
|
||||
((uint32_t)MPU_Init->Enable << MPU_RASR_ENABLE_Pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
MPU->RASR = ((uint32_t)MPU_Init->DisableExec << MPU_RASR_XN_Pos) | ((uint32_t)MPU_Init->AccessPermission << MPU_RASR_AP_Pos) | ((uint32_t)MPU_Init->TypeExtField << MPU_RASR_TEX_Pos)
|
||||
| ((uint32_t)MPU_Init->IsShareable << MPU_RASR_S_Pos) | ((uint32_t)MPU_Init->IsCacheable << MPU_RASR_C_Pos) | ((uint32_t)MPU_Init->IsBufferable << MPU_RASR_B_Pos)
|
||||
| ((uint32_t)MPU_Init->SubRegionDisable << MPU_RASR_SRD_Pos) | ((uint32_t)MPU_Init->Size << MPU_RASR_SIZE_Pos) | ((uint32_t)MPU_Init->Enable << MPU_RASR_ENABLE_Pos);
|
||||
} else {
|
||||
MPU->RBAR = 0x00U;
|
||||
MPU->RASR = 0x00U;
|
||||
}
|
||||
@@ -357,8 +335,7 @@ void HAL_MPU_ConfigRegion(MPU_Region_InitTypeDef *MPU_Init)
|
||||
* @brief Gets the priority grouping field from the NVIC Interrupt Controller.
|
||||
* @retval Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field)
|
||||
*/
|
||||
uint32_t HAL_NVIC_GetPriorityGrouping(void)
|
||||
{
|
||||
uint32_t HAL_NVIC_GetPriorityGrouping(void) {
|
||||
/* Get the PRIGROUP[10:8] field value */
|
||||
return NVIC_GetPriorityGrouping();
|
||||
}
|
||||
@@ -384,8 +361,7 @@ uint32_t HAL_NVIC_GetPriorityGrouping(void)
|
||||
* @param pSubPriority: Pointer on the Subpriority value (starting from 0).
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_NVIC_GetPriority(IRQn_Type IRQn, uint32_t PriorityGroup, uint32_t *pPreemptPriority, uint32_t *pSubPriority)
|
||||
{
|
||||
void HAL_NVIC_GetPriority(IRQn_Type IRQn, uint32_t PriorityGroup, uint32_t *pPreemptPriority, uint32_t *pSubPriority) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));
|
||||
/* Get priority for Cortex-M system or device specific interrupts */
|
||||
@@ -399,8 +375,7 @@ void HAL_NVIC_GetPriority(IRQn_Type IRQn, uint32_t PriorityGroup, uint32_t *pPre
|
||||
* (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h))
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
|
||||
|
||||
@@ -417,8 +392,7 @@ void HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn)
|
||||
* @retval status: - 0 Interrupt status is not pending.
|
||||
* - 1 Interrupt status is pending.
|
||||
*/
|
||||
uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
|
||||
|
||||
@@ -433,8 +407,7 @@ uint32_t HAL_NVIC_GetPendingIRQ(IRQn_Type IRQn)
|
||||
* (For the complete STM32 Devices IRQ Channels list, please refer to the appropriate CMSIS device file (stm32f10xxx.h))
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn)
|
||||
{
|
||||
void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
|
||||
|
||||
@@ -450,8 +423,7 @@ void HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn)
|
||||
* @retval status: - 0 Interrupt status is not pending.
|
||||
* - 1 Interrupt status is pending.
|
||||
*/
|
||||
uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn)
|
||||
{
|
||||
uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_NVIC_DEVICE_IRQ(IRQn));
|
||||
|
||||
@@ -467,16 +439,12 @@ uint32_t HAL_NVIC_GetActive(IRQn_Type IRQn)
|
||||
* @arg SYSTICK_CLKSOURCE_HCLK: AHB clock selected as SysTick clock source.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource)
|
||||
{
|
||||
void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_SYSTICK_CLK_SOURCE(CLKSource));
|
||||
if (CLKSource == SYSTICK_CLKSOURCE_HCLK)
|
||||
{
|
||||
if (CLKSource == SYSTICK_CLKSOURCE_HCLK) {
|
||||
SysTick->CTRL |= SYSTICK_CLKSOURCE_HCLK;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
SysTick->CTRL &= ~SYSTICK_CLKSOURCE_HCLK;
|
||||
}
|
||||
}
|
||||
@@ -485,17 +453,13 @@ void HAL_SYSTICK_CLKSourceConfig(uint32_t CLKSource)
|
||||
* @brief This function handles SYSTICK interrupt request.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_SYSTICK_IRQHandler(void)
|
||||
{
|
||||
HAL_SYSTICK_Callback();
|
||||
}
|
||||
void HAL_SYSTICK_IRQHandler(void) { HAL_SYSTICK_Callback(); }
|
||||
|
||||
/**
|
||||
* @brief SYSTICK callback.
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_SYSTICK_Callback(void)
|
||||
{
|
||||
__weak void HAL_SYSTICK_Callback(void) {
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_SYSTICK_Callback could be implemented in the user file
|
||||
*/
|
||||
|
||||
@@ -156,13 +156,11 @@ static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t
|
||||
* the configuration information for the specified DMA Channel.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma) {
|
||||
uint32_t tmp = 0U;
|
||||
|
||||
/* Check the DMA handle allocation */
|
||||
if(hdma == NULL)
|
||||
{
|
||||
if (hdma == NULL) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
@@ -178,14 +176,11 @@ HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma)
|
||||
|
||||
#if defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F100xE) || defined(STM32F105xC) || defined(STM32F107xC)
|
||||
/* calculation of the channel index */
|
||||
if ((uint32_t)(hdma->Instance) < (uint32_t)(DMA2_Channel1))
|
||||
{
|
||||
if ((uint32_t)(hdma->Instance) < (uint32_t)(DMA2_Channel1)) {
|
||||
/* DMA1 */
|
||||
hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA1_Channel1) / ((uint32_t)DMA1_Channel2 - (uint32_t)DMA1_Channel1)) << 2;
|
||||
hdma->DmaBaseAddress = DMA1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* DMA2 */
|
||||
hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA2_Channel1) / ((uint32_t)DMA2_Channel2 - (uint32_t)DMA2_Channel1)) << 2;
|
||||
hdma->DmaBaseAddress = DMA2;
|
||||
@@ -203,15 +198,10 @@ HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma)
|
||||
tmp = hdma->Instance->CCR;
|
||||
|
||||
/* Clear PL, MSIZE, PSIZE, MINC, PINC, CIRC and DIR bits */
|
||||
tmp &= ((uint32_t)~(DMA_CCR_PL | DMA_CCR_MSIZE | DMA_CCR_PSIZE | \
|
||||
DMA_CCR_MINC | DMA_CCR_PINC | DMA_CCR_CIRC | \
|
||||
DMA_CCR_DIR));
|
||||
tmp &= ((uint32_t) ~(DMA_CCR_PL | DMA_CCR_MSIZE | DMA_CCR_PSIZE | DMA_CCR_MINC | DMA_CCR_PINC | DMA_CCR_CIRC | DMA_CCR_DIR));
|
||||
|
||||
/* Prepare the DMA Channel configuration */
|
||||
tmp |= hdma->Init.Direction |
|
||||
hdma->Init.PeriphInc | hdma->Init.MemInc |
|
||||
hdma->Init.PeriphDataAlignment | hdma->Init.MemDataAlignment |
|
||||
hdma->Init.Mode | hdma->Init.Priority;
|
||||
tmp |= hdma->Init.Direction | hdma->Init.PeriphInc | hdma->Init.MemInc | hdma->Init.PeriphDataAlignment | hdma->Init.MemDataAlignment | hdma->Init.Mode | hdma->Init.Priority;
|
||||
|
||||
/* Write to DMA Channel CR register */
|
||||
hdma->Instance->CCR = tmp;
|
||||
@@ -233,11 +223,9 @@ HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma)
|
||||
* the configuration information for the specified DMA Channel.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma) {
|
||||
/* Check the DMA handle allocation */
|
||||
if(hdma == NULL)
|
||||
{
|
||||
if (hdma == NULL) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
@@ -261,14 +249,11 @@ HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma)
|
||||
|
||||
#if defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F100xE) || defined(STM32F105xC) || defined(STM32F107xC)
|
||||
/* calculation of the channel index */
|
||||
if ((uint32_t)(hdma->Instance) < (uint32_t)(DMA2_Channel1))
|
||||
{
|
||||
if ((uint32_t)(hdma->Instance) < (uint32_t)(DMA2_Channel1)) {
|
||||
/* DMA1 */
|
||||
hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA1_Channel1) / ((uint32_t)DMA1_Channel2 - (uint32_t)DMA1_Channel1)) << 2;
|
||||
hdma->DmaBaseAddress = DMA1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* DMA2 */
|
||||
hdma->ChannelIndex = (((uint32_t)hdma->Instance - (uint32_t)DMA2_Channel1) / ((uint32_t)DMA2_Channel2 - (uint32_t)DMA2_Channel1)) << 2;
|
||||
hdma->DmaBaseAddress = DMA2;
|
||||
@@ -332,8 +317,7 @@ HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma)
|
||||
* @param DataLength: The length of data to be transferred from source to destination
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DMA_Start(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_DMA_Start(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength) {
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check the parameters */
|
||||
@@ -342,8 +326,7 @@ HAL_StatusTypeDef HAL_DMA_Start(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, ui
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hdma);
|
||||
|
||||
if(HAL_DMA_STATE_READY == hdma->State)
|
||||
{
|
||||
if (HAL_DMA_STATE_READY == hdma->State) {
|
||||
/* Change DMA peripheral state */
|
||||
hdma->State = HAL_DMA_STATE_BUSY;
|
||||
hdma->ErrorCode = HAL_DMA_ERROR_NONE;
|
||||
@@ -356,9 +339,7 @@ HAL_StatusTypeDef HAL_DMA_Start(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, ui
|
||||
|
||||
/* Enable the Peripheral */
|
||||
__HAL_DMA_ENABLE(hdma);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hdma);
|
||||
status = HAL_BUSY;
|
||||
@@ -375,8 +356,7 @@ HAL_StatusTypeDef HAL_DMA_Start(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, ui
|
||||
* @param DataLength: The length of data to be transferred from source to destination
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength) {
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check the parameters */
|
||||
@@ -385,8 +365,7 @@ HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress,
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hdma);
|
||||
|
||||
if(HAL_DMA_STATE_READY == hdma->State)
|
||||
{
|
||||
if (HAL_DMA_STATE_READY == hdma->State) {
|
||||
/* Change DMA peripheral state */
|
||||
hdma->State = HAL_DMA_STATE_BUSY;
|
||||
hdma->ErrorCode = HAL_DMA_ERROR_NONE;
|
||||
@@ -399,21 +378,16 @@ HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress,
|
||||
|
||||
/* Enable the transfer complete interrupt */
|
||||
/* Enable the transfer Error interrupt */
|
||||
if(NULL != hdma->XferHalfCpltCallback)
|
||||
{
|
||||
if (NULL != hdma->XferHalfCpltCallback) {
|
||||
/* Enable the Half transfer complete interrupt as well */
|
||||
__HAL_DMA_ENABLE_IT(hdma, (DMA_IT_TC | DMA_IT_HT | DMA_IT_TE));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
__HAL_DMA_DISABLE_IT(hdma, DMA_IT_HT);
|
||||
__HAL_DMA_ENABLE_IT(hdma, (DMA_IT_TC | DMA_IT_TE));
|
||||
}
|
||||
/* Enable the Peripheral */
|
||||
__HAL_DMA_ENABLE(hdma);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hdma);
|
||||
|
||||
@@ -429,8 +403,7 @@ HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress,
|
||||
* the configuration information for the specified DMA Channel.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma) {
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Disable DMA IT */
|
||||
@@ -457,19 +430,15 @@ HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
|
||||
* the configuration information for the specified DMA Channel.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma) {
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
if(HAL_DMA_STATE_BUSY != hdma->State)
|
||||
{
|
||||
if (HAL_DMA_STATE_BUSY != hdma->State) {
|
||||
/* no transfer ongoing */
|
||||
hdma->ErrorCode = HAL_DMA_ERROR_NO_XFER;
|
||||
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Disable DMA IT */
|
||||
__HAL_DMA_DISABLE_IT(hdma, (DMA_IT_TC | DMA_IT_HT | DMA_IT_TE));
|
||||
|
||||
@@ -486,8 +455,7 @@ HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
|
||||
__HAL_UNLOCK(hdma);
|
||||
|
||||
/* Call User Abort callback */
|
||||
if(hdma->XferAbortCallback != NULL)
|
||||
{
|
||||
if (hdma->XferAbortCallback != NULL) {
|
||||
hdma->XferAbortCallback(hdma);
|
||||
}
|
||||
}
|
||||
@@ -502,13 +470,11 @@ HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
|
||||
* @param Timeout: Timeout duration.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t CompleteLevel, uint32_t Timeout)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t CompleteLevel, uint32_t Timeout) {
|
||||
uint32_t temp;
|
||||
uint32_t tickstart = 0U;
|
||||
|
||||
if(HAL_DMA_STATE_BUSY != hdma->State)
|
||||
{
|
||||
if (HAL_DMA_STATE_BUSY != hdma->State) {
|
||||
/* no transfer ongoing */
|
||||
hdma->ErrorCode = HAL_DMA_ERROR_NO_XFER;
|
||||
__HAL_UNLOCK(hdma);
|
||||
@@ -516,20 +482,16 @@ HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t Comp
|
||||
}
|
||||
|
||||
/* Polling mode not supported in circular mode */
|
||||
if (RESET != (hdma->Instance->CCR & DMA_CCR_CIRC))
|
||||
{
|
||||
if (RESET != (hdma->Instance->CCR & DMA_CCR_CIRC)) {
|
||||
hdma->ErrorCode = HAL_DMA_ERROR_NOT_SUPPORTED;
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
/* Get the level transfer complete flag */
|
||||
if(CompleteLevel == HAL_DMA_FULL_TRANSFER)
|
||||
{
|
||||
if (CompleteLevel == HAL_DMA_FULL_TRANSFER) {
|
||||
/* Transfer Complete flag */
|
||||
temp = __HAL_DMA_GET_TC_FLAG_INDEX(hdma);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Half Transfer Complete flag */
|
||||
temp = __HAL_DMA_GET_HT_FLAG_INDEX(hdma);
|
||||
}
|
||||
@@ -537,10 +499,8 @@ HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t Comp
|
||||
/* Get tick */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
while(__HAL_DMA_GET_FLAG(hdma, temp) == RESET)
|
||||
{
|
||||
if((__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)) != RESET))
|
||||
{
|
||||
while (__HAL_DMA_GET_FLAG(hdma, temp) == RESET) {
|
||||
if ((__HAL_DMA_GET_FLAG(hdma, __HAL_DMA_GET_TE_FLAG_INDEX(hdma)) != RESET)) {
|
||||
/* When a DMA transfer error occurs */
|
||||
/* A hardware clear of its EN bits is performed */
|
||||
/* Clear all flags */
|
||||
@@ -558,10 +518,8 @@ HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t Comp
|
||||
return HAL_ERROR;
|
||||
}
|
||||
/* Check for the Timeout */
|
||||
if(Timeout != HAL_MAX_DELAY)
|
||||
{
|
||||
if((Timeout == 0U) || ((HAL_GetTick() - tickstart) > Timeout))
|
||||
{
|
||||
if (Timeout != HAL_MAX_DELAY) {
|
||||
if ((Timeout == 0U) || ((HAL_GetTick() - tickstart) > Timeout)) {
|
||||
/* Update error code */
|
||||
SET_BIT(hdma->ErrorCode, HAL_DMA_ERROR_TIMEOUT);
|
||||
|
||||
@@ -576,17 +534,14 @@ HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t Comp
|
||||
}
|
||||
}
|
||||
|
||||
if(CompleteLevel == HAL_DMA_FULL_TRANSFER)
|
||||
{
|
||||
if (CompleteLevel == HAL_DMA_FULL_TRANSFER) {
|
||||
/* Clear the transfer complete flag */
|
||||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_TC_FLAG_INDEX(hdma));
|
||||
|
||||
/* The selected Channelx EN bit is cleared (DMA is disabled and
|
||||
all transfers are complete) */
|
||||
hdma->State = HAL_DMA_STATE_READY;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Clear the half transfer complete flag */
|
||||
__HAL_DMA_CLEAR_FLAG(hdma, __HAL_DMA_GET_HT_FLAG_INDEX(hdma));
|
||||
}
|
||||
@@ -603,17 +558,14 @@ HAL_StatusTypeDef HAL_DMA_PollForTransfer(DMA_HandleTypeDef *hdma, uint32_t Comp
|
||||
* the configuration information for the specified DMA Channel.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma)
|
||||
{
|
||||
void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma) {
|
||||
uint32_t flag_it = hdma->DmaBaseAddress->ISR;
|
||||
uint32_t source_it = hdma->Instance->CCR;
|
||||
|
||||
/* Half Transfer Complete Interrupt management ******************************/
|
||||
if (((flag_it & (DMA_FLAG_HT1 << hdma->ChannelIndex)) != RESET) && ((source_it & DMA_IT_HT) != RESET))
|
||||
{
|
||||
if (((flag_it & (DMA_FLAG_HT1 << hdma->ChannelIndex)) != RESET) && ((source_it & DMA_IT_HT) != RESET)) {
|
||||
/* Disable the half transfer interrupt if the DMA mode is not CIRCULAR */
|
||||
if((hdma->Instance->CCR & DMA_CCR_CIRC) == 0U)
|
||||
{
|
||||
if ((hdma->Instance->CCR & DMA_CCR_CIRC) == 0U) {
|
||||
/* Disable the half transfer interrupt */
|
||||
__HAL_DMA_DISABLE_IT(hdma, DMA_IT_HT);
|
||||
}
|
||||
@@ -623,18 +575,15 @@ void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma)
|
||||
/* DMA peripheral state is not updated in Half Transfer */
|
||||
/* but in Transfer Complete case */
|
||||
|
||||
if(hdma->XferHalfCpltCallback != NULL)
|
||||
{
|
||||
if (hdma->XferHalfCpltCallback != NULL) {
|
||||
/* Half transfer callback */
|
||||
hdma->XferHalfCpltCallback(hdma);
|
||||
}
|
||||
}
|
||||
|
||||
/* Transfer Complete Interrupt management ***********************************/
|
||||
else if (((flag_it & (DMA_FLAG_TC1 << hdma->ChannelIndex)) != RESET) && ((source_it & DMA_IT_TC) != RESET))
|
||||
{
|
||||
if((hdma->Instance->CCR & DMA_CCR_CIRC) == 0U)
|
||||
{
|
||||
else if (((flag_it & (DMA_FLAG_TC1 << hdma->ChannelIndex)) != RESET) && ((source_it & DMA_IT_TC) != RESET)) {
|
||||
if ((hdma->Instance->CCR & DMA_CCR_CIRC) == 0U) {
|
||||
/* Disable the transfer complete and error interrupt */
|
||||
__HAL_DMA_DISABLE_IT(hdma, DMA_IT_TE | DMA_IT_TC);
|
||||
|
||||
@@ -647,16 +596,14 @@ void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma)
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hdma);
|
||||
|
||||
if(hdma->XferCpltCallback != NULL)
|
||||
{
|
||||
if (hdma->XferCpltCallback != NULL) {
|
||||
/* Transfer complete callback */
|
||||
hdma->XferCpltCallback(hdma);
|
||||
}
|
||||
}
|
||||
|
||||
/* Transfer Error Interrupt management **************************************/
|
||||
else if (( RESET != (flag_it & (DMA_FLAG_TE1 << hdma->ChannelIndex))) && (RESET != (source_it & DMA_IT_TE)))
|
||||
{
|
||||
else if ((RESET != (flag_it & (DMA_FLAG_TE1 << hdma->ChannelIndex))) && (RESET != (source_it & DMA_IT_TE))) {
|
||||
/* When a DMA transfer error occurs */
|
||||
/* A hardware clear of its EN bits is performed */
|
||||
/* Disable ALL DMA IT */
|
||||
@@ -674,8 +621,7 @@ void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma)
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(hdma);
|
||||
|
||||
if (hdma->XferErrorCallback != NULL)
|
||||
{
|
||||
if (hdma->XferErrorCallback != NULL) {
|
||||
/* Transfer error callback */
|
||||
hdma->XferErrorCallback(hdma);
|
||||
}
|
||||
@@ -693,17 +639,14 @@ void HAL_DMA_IRQHandler(DMA_HandleTypeDef *hdma)
|
||||
* a DMA_HandleTypeDef structure as parameter.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DMA_RegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID, void (* pCallback)( DMA_HandleTypeDef * _hdma))
|
||||
{
|
||||
HAL_StatusTypeDef HAL_DMA_RegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID, void (*pCallback)(DMA_HandleTypeDef *_hdma)) {
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hdma);
|
||||
|
||||
if(HAL_DMA_STATE_READY == hdma->State)
|
||||
{
|
||||
switch (CallbackID)
|
||||
{
|
||||
if (HAL_DMA_STATE_READY == hdma->State) {
|
||||
switch (CallbackID) {
|
||||
case HAL_DMA_XFER_CPLT_CB_ID:
|
||||
hdma->XferCpltCallback = pCallback;
|
||||
break;
|
||||
@@ -724,9 +667,7 @@ HAL_StatusTypeDef HAL_DMA_RegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_Call
|
||||
status = HAL_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
@@ -744,17 +685,14 @@ HAL_StatusTypeDef HAL_DMA_RegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_Call
|
||||
* a HAL_DMA_CallbackIDTypeDef ENUM as parameter.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_DMA_UnRegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_DMA_UnRegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_CallbackIDTypeDef CallbackID) {
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Process locked */
|
||||
__HAL_LOCK(hdma);
|
||||
|
||||
if(HAL_DMA_STATE_READY == hdma->State)
|
||||
{
|
||||
switch (CallbackID)
|
||||
{
|
||||
if (HAL_DMA_STATE_READY == hdma->State) {
|
||||
switch (CallbackID) {
|
||||
case HAL_DMA_XFER_CPLT_CB_ID:
|
||||
hdma->XferCpltCallback = NULL;
|
||||
break;
|
||||
@@ -782,9 +720,7 @@ HAL_StatusTypeDef HAL_DMA_UnRegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_Ca
|
||||
status = HAL_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
|
||||
@@ -820,8 +756,7 @@ HAL_StatusTypeDef HAL_DMA_UnRegisterCallback(DMA_HandleTypeDef *hdma, HAL_DMA_Ca
|
||||
* the configuration information for the specified DMA Channel.
|
||||
* @retval HAL state
|
||||
*/
|
||||
HAL_DMA_StateTypeDef HAL_DMA_GetState(DMA_HandleTypeDef *hdma)
|
||||
{
|
||||
HAL_DMA_StateTypeDef HAL_DMA_GetState(DMA_HandleTypeDef *hdma) {
|
||||
/* Return DMA handle state */
|
||||
return hdma->State;
|
||||
}
|
||||
@@ -832,10 +767,7 @@ HAL_DMA_StateTypeDef HAL_DMA_GetState(DMA_HandleTypeDef *hdma)
|
||||
* the configuration information for the specified DMA Channel.
|
||||
* @retval DMA Error Code
|
||||
*/
|
||||
uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma)
|
||||
{
|
||||
return hdma->ErrorCode;
|
||||
}
|
||||
uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma) { return hdma->ErrorCode; }
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -858,8 +790,7 @@ uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma)
|
||||
* @param DataLength: The length of data to be transferred from source to destination
|
||||
* @retval HAL status
|
||||
*/
|
||||
static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
|
||||
{
|
||||
static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength) {
|
||||
/* Clear all flags */
|
||||
hdma->DmaBaseAddress->IFCR = (DMA_ISR_GIF1 << hdma->ChannelIndex);
|
||||
|
||||
@@ -867,8 +798,7 @@ static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t
|
||||
hdma->Instance->CNDTR = DataLength;
|
||||
|
||||
/* Memory to Peripheral */
|
||||
if((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH)
|
||||
{
|
||||
if ((hdma->Init.Direction) == DMA_MEMORY_TO_PERIPH) {
|
||||
/* Configure DMA Channel destination address */
|
||||
hdma->Instance->CPAR = DstAddress;
|
||||
|
||||
@@ -876,8 +806,7 @@ static void DMA_SetConfig(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t
|
||||
hdma->Instance->CMAR = SrcAddress;
|
||||
}
|
||||
/* Peripheral to Memory */
|
||||
else
|
||||
{
|
||||
else {
|
||||
/* Configure DMA Channel source address */
|
||||
hdma->Instance->CPAR = SrcAddress;
|
||||
|
||||
|
||||
@@ -181,8 +181,7 @@ extern void FLASH_PageErase(uint32_t PageAddress);
|
||||
*
|
||||
* @retval HAL_StatusTypeDef HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint64_t Data) {
|
||||
HAL_StatusTypeDef status = HAL_ERROR;
|
||||
uint8_t index = 0;
|
||||
uint8_t nbiterations = 0;
|
||||
@@ -195,45 +194,34 @@ HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint
|
||||
assert_param(IS_FLASH_PROGRAM_ADDRESS(Address));
|
||||
|
||||
#if defined(FLASH_BANK2_END)
|
||||
if(Address <= FLASH_BANK1_END)
|
||||
{
|
||||
if (Address <= FLASH_BANK1_END) {
|
||||
#endif /* FLASH_BANK2_END */
|
||||
/* Wait for last operation to be completed */
|
||||
status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
|
||||
#if defined(FLASH_BANK2_END)
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Wait for last operation to be completed */
|
||||
status = FLASH_WaitForLastOperationBank2(FLASH_TIMEOUT_VALUE);
|
||||
}
|
||||
#endif /* FLASH_BANK2_END */
|
||||
|
||||
if(status == HAL_OK)
|
||||
{
|
||||
if(TypeProgram == FLASH_TYPEPROGRAM_HALFWORD)
|
||||
{
|
||||
if (status == HAL_OK) {
|
||||
if (TypeProgram == FLASH_TYPEPROGRAM_HALFWORD) {
|
||||
/* Program halfword (16-bit) at a specified address. */
|
||||
nbiterations = 1U;
|
||||
}
|
||||
else if(TypeProgram == FLASH_TYPEPROGRAM_WORD)
|
||||
{
|
||||
} else if (TypeProgram == FLASH_TYPEPROGRAM_WORD) {
|
||||
/* Program word (32-bit = 2*16-bit) at a specified address. */
|
||||
nbiterations = 2U;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Program double word (64-bit = 4*16-bit) at a specified address. */
|
||||
nbiterations = 4U;
|
||||
}
|
||||
|
||||
for (index = 0U; index < nbiterations; index++)
|
||||
{
|
||||
for (index = 0U; index < nbiterations; index++) {
|
||||
FLASH_Program_HalfWord((Address + (2U * index)), (uint16_t)(Data >> (16U * index)));
|
||||
|
||||
#if defined(FLASH_BANK2_END)
|
||||
if(Address <= FLASH_BANK1_END)
|
||||
{
|
||||
if (Address <= FLASH_BANK1_END) {
|
||||
#endif /* FLASH_BANK2_END */
|
||||
/* Wait for last operation to be completed */
|
||||
status = FLASH_WaitForLastOperation(FLASH_TIMEOUT_VALUE);
|
||||
@@ -241,9 +229,7 @@ HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint
|
||||
/* If the program operation is completed, disable the PG Bit */
|
||||
CLEAR_BIT(FLASH->CR, FLASH_CR_PG);
|
||||
#if defined(FLASH_BANK2_END)
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Wait for last operation to be completed */
|
||||
status = FLASH_WaitForLastOperationBank2(FLASH_TIMEOUT_VALUE);
|
||||
|
||||
@@ -252,8 +238,7 @@ HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint
|
||||
}
|
||||
#endif /* FLASH_BANK2_END */
|
||||
/* In case of error, stop programation procedure */
|
||||
if (status != HAL_OK)
|
||||
{
|
||||
if (status != HAL_OK) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -280,8 +265,7 @@ HAL_StatusTypeDef HAL_FLASH_Program(uint32_t TypeProgram, uint32_t Address, uint
|
||||
*
|
||||
* @retval HAL_StatusTypeDef HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, uint64_t Data) {
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Process Locked */
|
||||
@@ -293,18 +277,15 @@ HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, u
|
||||
|
||||
#if defined(FLASH_BANK2_END)
|
||||
/* If procedure already ongoing, reject the next one */
|
||||
if (pFlash.ProcedureOnGoing != FLASH_PROC_NONE)
|
||||
{
|
||||
if (pFlash.ProcedureOnGoing != FLASH_PROC_NONE) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if(Address <= FLASH_BANK1_END)
|
||||
{
|
||||
if (Address <= FLASH_BANK1_END) {
|
||||
/* Enable End of FLASH Operation and Error source interrupts */
|
||||
__HAL_FLASH_ENABLE_IT(FLASH_IT_EOP_BANK1 | FLASH_IT_ERR_BANK1);
|
||||
|
||||
}else
|
||||
{
|
||||
} else {
|
||||
/* Enable End of FLASH Operation and Error source interrupts */
|
||||
__HAL_FLASH_ENABLE_IT(FLASH_IT_EOP_BANK2 | FLASH_IT_ERR_BANK2);
|
||||
}
|
||||
@@ -316,20 +297,15 @@ HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, u
|
||||
pFlash.Address = Address;
|
||||
pFlash.Data = Data;
|
||||
|
||||
if(TypeProgram == FLASH_TYPEPROGRAM_HALFWORD)
|
||||
{
|
||||
if (TypeProgram == FLASH_TYPEPROGRAM_HALFWORD) {
|
||||
pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMHALFWORD;
|
||||
/* Program halfword (16-bit) at a specified address. */
|
||||
pFlash.DataRemaining = 1U;
|
||||
}
|
||||
else if(TypeProgram == FLASH_TYPEPROGRAM_WORD)
|
||||
{
|
||||
} else if (TypeProgram == FLASH_TYPEPROGRAM_WORD) {
|
||||
pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMWORD;
|
||||
/* Program word (32-bit : 2*16-bit) at a specified address. */
|
||||
pFlash.DataRemaining = 2U;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
pFlash.ProcedureOnGoing = FLASH_PROC_PROGRAMDOUBLEWORD;
|
||||
/* Program double word (64-bit : 4*16-bit) at a specified address. */
|
||||
pFlash.DataRemaining = 4U;
|
||||
@@ -345,14 +321,12 @@ HAL_StatusTypeDef HAL_FLASH_Program_IT(uint32_t TypeProgram, uint32_t Address, u
|
||||
* @brief This function handles FLASH interrupt request.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_FLASH_IRQHandler(void)
|
||||
{
|
||||
void HAL_FLASH_IRQHandler(void) {
|
||||
uint32_t addresstmp = 0U;
|
||||
|
||||
/* Check FLASH operation error flags */
|
||||
#if defined(FLASH_BANK2_END)
|
||||
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK1) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK1) || \
|
||||
(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK2) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK2)))
|
||||
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK1) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK1) || (__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK2) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK2)))
|
||||
#else
|
||||
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR))
|
||||
#endif /* FLASH_BANK2_END */
|
||||
@@ -374,28 +348,23 @@ void HAL_FLASH_IRQHandler(void)
|
||||
|
||||
/* Check FLASH End of Operation flag */
|
||||
#if defined(FLASH_BANK2_END)
|
||||
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP_BANK1))
|
||||
{
|
||||
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP_BANK1)) {
|
||||
/* Clear FLASH End of Operation pending bit */
|
||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP_BANK1);
|
||||
#else
|
||||
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP))
|
||||
{
|
||||
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP)) {
|
||||
/* Clear FLASH End of Operation pending bit */
|
||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
|
||||
#endif /* FLASH_BANK2_END */
|
||||
|
||||
/* Process can continue only if no error detected */
|
||||
if(pFlash.ProcedureOnGoing != FLASH_PROC_NONE)
|
||||
{
|
||||
if(pFlash.ProcedureOnGoing == FLASH_PROC_PAGEERASE)
|
||||
{
|
||||
if (pFlash.ProcedureOnGoing != FLASH_PROC_NONE) {
|
||||
if (pFlash.ProcedureOnGoing == FLASH_PROC_PAGEERASE) {
|
||||
/* Nb of pages to erased can be decreased */
|
||||
pFlash.DataRemaining--;
|
||||
|
||||
/* Check if there are still pages to erase */
|
||||
if(pFlash.DataRemaining != 0U)
|
||||
{
|
||||
if (pFlash.DataRemaining != 0U) {
|
||||
addresstmp = pFlash.Address;
|
||||
/*Indicate user which sector has been erased */
|
||||
HAL_FLASH_EndOfOperationCallback(addresstmp);
|
||||
@@ -408,9 +377,7 @@ void HAL_FLASH_IRQHandler(void)
|
||||
CLEAR_BIT(FLASH->CR, FLASH_CR_PER);
|
||||
|
||||
FLASH_PageErase(addresstmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* No more pages to Erase, user callback can be called. */
|
||||
/* Reset Sector and stop Erase pages procedure */
|
||||
pFlash.Address = addresstmp = 0xFFFFFFFFU;
|
||||
@@ -418,16 +385,13 @@ void HAL_FLASH_IRQHandler(void)
|
||||
/* FLASH EOP interrupt user callback */
|
||||
HAL_FLASH_EndOfOperationCallback(addresstmp);
|
||||
}
|
||||
}
|
||||
else if(pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE)
|
||||
{
|
||||
} else if (pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE) {
|
||||
/* Operation is completed, disable the MER Bit */
|
||||
CLEAR_BIT(FLASH->CR, FLASH_CR_MER);
|
||||
|
||||
#if defined(FLASH_BANK2_END)
|
||||
/* Stop Mass Erase procedure if no pending mass erase on other bank */
|
||||
if (HAL_IS_BIT_CLR(FLASH->CR2, FLASH_CR2_MER))
|
||||
{
|
||||
if (HAL_IS_BIT_CLR(FLASH->CR2, FLASH_CR2_MER)) {
|
||||
#endif /* FLASH_BANK2_END */
|
||||
/* MassErase ended. Return the selected bank */
|
||||
/* FLASH EOP interrupt user callback */
|
||||
@@ -439,14 +403,12 @@ void HAL_FLASH_IRQHandler(void)
|
||||
#if defined(FLASH_BANK2_END)
|
||||
}
|
||||
#endif /* FLASH_BANK2_END */
|
||||
else
|
||||
{
|
||||
else {
|
||||
/* Nb of 16-bit data to program can be decreased */
|
||||
pFlash.DataRemaining--;
|
||||
|
||||
/* Check if there are still 16-bit data to program */
|
||||
if(pFlash.DataRemaining != 0U)
|
||||
{
|
||||
if (pFlash.DataRemaining != 0U) {
|
||||
/* Increment address to 16-bit */
|
||||
pFlash.Address += 2U;
|
||||
addresstmp = pFlash.Address;
|
||||
@@ -459,21 +421,14 @@ void HAL_FLASH_IRQHandler(void)
|
||||
|
||||
/*Program halfword (16-bit) at a specified address.*/
|
||||
FLASH_Program_HalfWord(addresstmp, (uint16_t)pFlash.Data);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Program ended. Return the selected address */
|
||||
/* FLASH EOP interrupt user callback */
|
||||
if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMHALFWORD)
|
||||
{
|
||||
if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMHALFWORD) {
|
||||
HAL_FLASH_EndOfOperationCallback(pFlash.Address);
|
||||
}
|
||||
else if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMWORD)
|
||||
{
|
||||
} else if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMWORD) {
|
||||
HAL_FLASH_EndOfOperationCallback(pFlash.Address - 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
HAL_FLASH_EndOfOperationCallback(pFlash.Address - 6U);
|
||||
}
|
||||
|
||||
@@ -487,22 +442,18 @@ void HAL_FLASH_IRQHandler(void)
|
||||
|
||||
#if defined(FLASH_BANK2_END)
|
||||
/* Check FLASH End of Operation flag */
|
||||
if(__HAL_FLASH_GET_FLAG( FLASH_FLAG_EOP_BANK2))
|
||||
{
|
||||
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP_BANK2)) {
|
||||
/* Clear FLASH End of Operation pending bit */
|
||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP_BANK2);
|
||||
|
||||
/* Process can continue only if no error detected */
|
||||
if(pFlash.ProcedureOnGoing != FLASH_PROC_NONE)
|
||||
{
|
||||
if(pFlash.ProcedureOnGoing == FLASH_PROC_PAGEERASE)
|
||||
{
|
||||
if (pFlash.ProcedureOnGoing != FLASH_PROC_NONE) {
|
||||
if (pFlash.ProcedureOnGoing == FLASH_PROC_PAGEERASE) {
|
||||
/* Nb of pages to erased can be decreased */
|
||||
pFlash.DataRemaining--;
|
||||
|
||||
/* Check if there are still pages to erase*/
|
||||
if(pFlash.DataRemaining != 0U)
|
||||
{
|
||||
if (pFlash.DataRemaining != 0U) {
|
||||
/* Indicate user which page address has been erased*/
|
||||
HAL_FLASH_EndOfOperationCallback(pFlash.Address);
|
||||
|
||||
@@ -514,9 +465,7 @@ void HAL_FLASH_IRQHandler(void)
|
||||
CLEAR_BIT(FLASH->CR2, FLASH_CR2_PER);
|
||||
|
||||
FLASH_PageErase(addresstmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/*No more pages to Erase*/
|
||||
|
||||
/*Reset Address and stop Erase pages procedure*/
|
||||
@@ -526,29 +475,23 @@ void HAL_FLASH_IRQHandler(void)
|
||||
/* FLASH EOP interrupt user callback */
|
||||
HAL_FLASH_EndOfOperationCallback(pFlash.Address);
|
||||
}
|
||||
}
|
||||
else if(pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE)
|
||||
{
|
||||
} else if (pFlash.ProcedureOnGoing == FLASH_PROC_MASSERASE) {
|
||||
/* Operation is completed, disable the MER Bit */
|
||||
CLEAR_BIT(FLASH->CR2, FLASH_CR2_MER);
|
||||
|
||||
if (HAL_IS_BIT_CLR(FLASH->CR, FLASH_CR_MER))
|
||||
{
|
||||
if (HAL_IS_BIT_CLR(FLASH->CR, FLASH_CR_MER)) {
|
||||
/* MassErase ended. Return the selected bank*/
|
||||
/* FLASH EOP interrupt user callback */
|
||||
HAL_FLASH_EndOfOperationCallback(0U);
|
||||
|
||||
pFlash.ProcedureOnGoing = FLASH_PROC_NONE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Nb of 16-bit data to program can be decreased */
|
||||
pFlash.DataRemaining--;
|
||||
|
||||
/* Check if there are still 16-bit data to program */
|
||||
if(pFlash.DataRemaining != 0U)
|
||||
{
|
||||
if (pFlash.DataRemaining != 0U) {
|
||||
/* Increment address to 16-bit */
|
||||
pFlash.Address += 2U;
|
||||
addresstmp = pFlash.Address;
|
||||
@@ -561,21 +504,14 @@ void HAL_FLASH_IRQHandler(void)
|
||||
|
||||
/*Program halfword (16-bit) at a specified address.*/
|
||||
FLASH_Program_HalfWord(addresstmp, (uint16_t)pFlash.Data);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/*Program ended. Return the selected address*/
|
||||
/* FLASH EOP interrupt user callback */
|
||||
if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMHALFWORD)
|
||||
{
|
||||
if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMHALFWORD) {
|
||||
HAL_FLASH_EndOfOperationCallback(pFlash.Address);
|
||||
}
|
||||
else if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMWORD)
|
||||
{
|
||||
} else if (pFlash.ProcedureOnGoing == FLASH_PROC_PROGRAMWORD) {
|
||||
HAL_FLASH_EndOfOperationCallback(pFlash.Address - 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
HAL_FLASH_EndOfOperationCallback(pFlash.Address - 6U);
|
||||
}
|
||||
|
||||
@@ -588,8 +524,7 @@ void HAL_FLASH_IRQHandler(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
if(pFlash.ProcedureOnGoing == FLASH_PROC_NONE)
|
||||
{
|
||||
if (pFlash.ProcedureOnGoing == FLASH_PROC_NONE) {
|
||||
#if defined(FLASH_BANK2_END)
|
||||
/* Operation is completed, disable the PG, PER and MER Bits for both bank */
|
||||
CLEAR_BIT(FLASH->CR, (FLASH_CR_PG | FLASH_CR_PER | FLASH_CR_MER));
|
||||
@@ -619,8 +554,7 @@ void HAL_FLASH_IRQHandler(void)
|
||||
* - Program: Address which was selected for data program
|
||||
* @retval none
|
||||
*/
|
||||
__weak void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue)
|
||||
{
|
||||
__weak void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue) {
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(ReturnValue);
|
||||
|
||||
@@ -637,8 +571,7 @@ __weak void HAL_FLASH_EndOfOperationCallback(uint32_t ReturnValue)
|
||||
* - Program: Address which was selected for data program
|
||||
* @retval none
|
||||
*/
|
||||
__weak void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue)
|
||||
{
|
||||
__weak void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue) {
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(ReturnValue);
|
||||
|
||||
@@ -670,32 +603,27 @@ __weak void HAL_FLASH_OperationErrorCallback(uint32_t ReturnValue)
|
||||
* @brief Unlock the FLASH control register access
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_FLASH_Unlock(void)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_FLASH_Unlock(void) {
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
if(READ_BIT(FLASH->CR, FLASH_CR_LOCK) != RESET)
|
||||
{
|
||||
if (READ_BIT(FLASH->CR, FLASH_CR_LOCK) != RESET) {
|
||||
/* Authorize the FLASH Registers access */
|
||||
WRITE_REG(FLASH->KEYR, FLASH_KEY1);
|
||||
WRITE_REG(FLASH->KEYR, FLASH_KEY2);
|
||||
|
||||
/* Verify Flash is unlocked */
|
||||
if(READ_BIT(FLASH->CR, FLASH_CR_LOCK) != RESET)
|
||||
{
|
||||
if (READ_BIT(FLASH->CR, FLASH_CR_LOCK) != RESET) {
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
}
|
||||
#if defined(FLASH_BANK2_END)
|
||||
if(READ_BIT(FLASH->CR2, FLASH_CR2_LOCK) != RESET)
|
||||
{
|
||||
if (READ_BIT(FLASH->CR2, FLASH_CR2_LOCK) != RESET) {
|
||||
/* Authorize the FLASH BANK2 Registers access */
|
||||
WRITE_REG(FLASH->KEYR2, FLASH_KEY1);
|
||||
WRITE_REG(FLASH->KEYR2, FLASH_KEY2);
|
||||
|
||||
/* Verify Flash BANK2 is unlocked */
|
||||
if(READ_BIT(FLASH->CR2, FLASH_CR2_LOCK) != RESET)
|
||||
{
|
||||
if (READ_BIT(FLASH->CR2, FLASH_CR2_LOCK) != RESET) {
|
||||
status = HAL_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -708,8 +636,7 @@ HAL_StatusTypeDef HAL_FLASH_Unlock(void)
|
||||
* @brief Locks the FLASH control register access
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_FLASH_Lock(void)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_FLASH_Lock(void) {
|
||||
/* Set the LOCK Bit to lock the FLASH Registers access */
|
||||
SET_BIT(FLASH->CR, FLASH_CR_LOCK);
|
||||
|
||||
@@ -725,16 +652,12 @@ HAL_StatusTypeDef HAL_FLASH_Lock(void)
|
||||
* @brief Unlock the FLASH Option Control Registers access.
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void)
|
||||
{
|
||||
if (HAL_IS_BIT_CLR(FLASH->CR, FLASH_CR_OPTWRE))
|
||||
{
|
||||
HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void) {
|
||||
if (HAL_IS_BIT_CLR(FLASH->CR, FLASH_CR_OPTWRE)) {
|
||||
/* Authorizes the Option Byte register programming */
|
||||
WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY1);
|
||||
WRITE_REG(FLASH->OPTKEYR, FLASH_OPTKEY2);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
@@ -745,8 +668,7 @@ HAL_StatusTypeDef HAL_FLASH_OB_Unlock(void)
|
||||
* @brief Lock the FLASH Option Control Registers access.
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_FLASH_OB_Lock(void)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_FLASH_OB_Lock(void) {
|
||||
/* Clear the OPTWRE Bit to lock the FLASH Option Byte Registers access */
|
||||
CLEAR_BIT(FLASH->CR, FLASH_CR_OPTWRE);
|
||||
|
||||
@@ -758,8 +680,7 @@ HAL_StatusTypeDef HAL_FLASH_OB_Lock(void)
|
||||
* @note This function will reset automatically the MCU.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_FLASH_OB_Launch(void)
|
||||
{
|
||||
void HAL_FLASH_OB_Launch(void) {
|
||||
/* Initiates a system reset request to launch the option byte loading */
|
||||
HAL_NVIC_SystemReset();
|
||||
}
|
||||
@@ -787,10 +708,7 @@ void HAL_FLASH_OB_Launch(void)
|
||||
* @retval FLASH_ErrorCode The returned value can be:
|
||||
* @ref FLASH_Error_Codes
|
||||
*/
|
||||
uint32_t HAL_FLASH_GetError(void)
|
||||
{
|
||||
return pFlash.ErrorCode;
|
||||
}
|
||||
uint32_t HAL_FLASH_GetError(void) { return pFlash.ErrorCode; }
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -810,21 +728,17 @@ uint32_t HAL_FLASH_GetError(void)
|
||||
* @param Data specify the data to be programmed.
|
||||
* @retval None
|
||||
*/
|
||||
static void FLASH_Program_HalfWord(uint32_t Address, uint16_t Data)
|
||||
{
|
||||
static void FLASH_Program_HalfWord(uint32_t Address, uint16_t Data) {
|
||||
/* Clean the error context */
|
||||
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
||||
|
||||
#if defined(FLASH_BANK2_END)
|
||||
if(Address <= FLASH_BANK1_END)
|
||||
{
|
||||
if (Address <= FLASH_BANK1_END) {
|
||||
#endif /* FLASH_BANK2_END */
|
||||
/* Proceed to program the new data */
|
||||
SET_BIT(FLASH->CR, FLASH_CR_PG);
|
||||
#if defined(FLASH_BANK2_END)
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Proceed to program the new data */
|
||||
SET_BIT(FLASH->CR2, FLASH_CR2_PG);
|
||||
}
|
||||
@@ -839,36 +753,28 @@ static void FLASH_Program_HalfWord(uint32_t Address, uint16_t Data)
|
||||
* @param Timeout maximum flash operation timeout
|
||||
* @retval HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
|
||||
{
|
||||
HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout) {
|
||||
/* Wait for the FLASH operation to complete by polling on BUSY flag to be reset.
|
||||
Even if the FLASH operation fails, the BUSY flag will be reset and an error
|
||||
flag will be set */
|
||||
|
||||
uint32_t tickstart = HAL_GetTick();
|
||||
|
||||
while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY))
|
||||
{
|
||||
if (Timeout != HAL_MAX_DELAY)
|
||||
{
|
||||
if((Timeout == 0U) || ((HAL_GetTick()-tickstart) > Timeout))
|
||||
{
|
||||
while (__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY)) {
|
||||
if (Timeout != HAL_MAX_DELAY) {
|
||||
if ((Timeout == 0U) || ((HAL_GetTick() - tickstart) > Timeout)) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check FLASH End of Operation flag */
|
||||
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP))
|
||||
{
|
||||
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP)) {
|
||||
/* Clear FLASH End of Operation pending bit */
|
||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
|
||||
}
|
||||
|
||||
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) ||
|
||||
__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR) ||
|
||||
__HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR))
|
||||
{
|
||||
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR)) {
|
||||
/*Save the error code*/
|
||||
FLASH_SetErrorCode();
|
||||
return HAL_ERROR;
|
||||
@@ -884,34 +790,28 @@ HAL_StatusTypeDef FLASH_WaitForLastOperation(uint32_t Timeout)
|
||||
* @param Timeout maximum flash operation timeout
|
||||
* @retval HAL_StatusTypeDef HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef FLASH_WaitForLastOperationBank2(uint32_t Timeout)
|
||||
{
|
||||
HAL_StatusTypeDef FLASH_WaitForLastOperationBank2(uint32_t Timeout) {
|
||||
/* Wait for the FLASH BANK2 operation to complete by polling on BUSY flag to be reset.
|
||||
Even if the FLASH BANK2 operation fails, the BUSY flag will be reset and an error
|
||||
flag will be set */
|
||||
|
||||
uint32_t tickstart = HAL_GetTick();
|
||||
|
||||
while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY_BANK2))
|
||||
{
|
||||
if (Timeout != HAL_MAX_DELAY)
|
||||
{
|
||||
if((Timeout == 0U) || ((HAL_GetTick()-tickstart) > Timeout))
|
||||
{
|
||||
while (__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY_BANK2)) {
|
||||
if (Timeout != HAL_MAX_DELAY) {
|
||||
if ((Timeout == 0U) || ((HAL_GetTick() - tickstart) > Timeout)) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check FLASH End of Operation flag */
|
||||
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP_BANK2))
|
||||
{
|
||||
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_EOP_BANK2)) {
|
||||
/* Clear FLASH End of Operation pending bit */
|
||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP_BANK2);
|
||||
}
|
||||
|
||||
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK2) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK2))
|
||||
{
|
||||
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_WRPERR_BANK2) || __HAL_FLASH_GET_FLAG(FLASH_FLAG_PGERR_BANK2)) {
|
||||
/*Save the error code*/
|
||||
FLASH_SetErrorCode();
|
||||
return HAL_ERROR;
|
||||
@@ -919,7 +819,6 @@ HAL_StatusTypeDef FLASH_WaitForLastOperationBank2(uint32_t Timeout)
|
||||
|
||||
/* If there is an error flag set */
|
||||
return HAL_OK;
|
||||
|
||||
}
|
||||
#endif /* FLASH_BANK2_END */
|
||||
|
||||
@@ -927,8 +826,7 @@ HAL_StatusTypeDef FLASH_WaitForLastOperationBank2(uint32_t Timeout)
|
||||
* @brief Set the specific FLASH error flag.
|
||||
* @retval None
|
||||
*/
|
||||
static void FLASH_SetErrorCode(void)
|
||||
{
|
||||
static void FLASH_SetErrorCode(void) {
|
||||
uint32_t flags = 0U;
|
||||
|
||||
#if defined(FLASH_BANK2_END)
|
||||
@@ -957,8 +855,7 @@ static void FLASH_SetErrorCode(void)
|
||||
flags |= FLASH_FLAG_PGERR;
|
||||
#endif /* FLASH_BANK2_END */
|
||||
}
|
||||
if(__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR))
|
||||
{
|
||||
if (__HAL_FLASH_GET_FLAG(FLASH_FLAG_OPTVERR)) {
|
||||
pFlash.ErrorCode |= HAL_FLASH_ERROR_OPTV;
|
||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
|
||||
}
|
||||
|
||||
@@ -156,7 +156,6 @@ static uint8_t FLASH_OB_GetUser(void);
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Perform a mass erase or erase the specified FLASH memory pages
|
||||
* @note To correctly run this function, the @ref HAL_FLASH_Unlock() function
|
||||
@@ -172,8 +171,7 @@ static uint8_t FLASH_OB_GetUser(void);
|
||||
*
|
||||
* @retval HAL_StatusTypeDef HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t *PageError) {
|
||||
HAL_StatusTypeDef status = HAL_ERROR;
|
||||
uint32_t address = 0U;
|
||||
|
||||
@@ -183,23 +181,17 @@ HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t
|
||||
/* Check the parameters */
|
||||
assert_param(IS_FLASH_TYPEERASE(pEraseInit->TypeErase));
|
||||
|
||||
if (pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE)
|
||||
{
|
||||
if (pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE) {
|
||||
#if defined(FLASH_BANK2_END)
|
||||
if (pEraseInit->Banks == FLASH_BANK_BOTH)
|
||||
{
|
||||
if (pEraseInit->Banks == FLASH_BANK_BOTH) {
|
||||
/* Mass Erase requested for Bank1 and Bank2 */
|
||||
/* Wait for last operation to be completed */
|
||||
if ((FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) && \
|
||||
(FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK))
|
||||
{
|
||||
if ((FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) && (FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK)) {
|
||||
/*Mass erase to be done*/
|
||||
FLASH_MassErase(FLASH_BANK_BOTH);
|
||||
|
||||
/* Wait for last operation to be completed */
|
||||
if ((FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) && \
|
||||
(FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK))
|
||||
{
|
||||
if ((FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) && (FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK)) {
|
||||
status = HAL_OK;
|
||||
}
|
||||
|
||||
@@ -207,13 +199,10 @@ HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t
|
||||
CLEAR_BIT(FLASH->CR, FLASH_CR_MER);
|
||||
CLEAR_BIT(FLASH->CR2, FLASH_CR2_MER);
|
||||
}
|
||||
}
|
||||
else if (pEraseInit->Banks == FLASH_BANK_2)
|
||||
{
|
||||
} else if (pEraseInit->Banks == FLASH_BANK_2) {
|
||||
/* Mass Erase requested for Bank2 */
|
||||
/* Wait for last operation to be completed */
|
||||
if (FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK)
|
||||
{
|
||||
if (FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) {
|
||||
/*Mass erase to be done*/
|
||||
FLASH_MassErase(FLASH_BANK_2);
|
||||
|
||||
@@ -223,14 +212,12 @@ HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t
|
||||
/* If the erase operation is completed, disable the MER Bit */
|
||||
CLEAR_BIT(FLASH->CR2, FLASH_CR2_MER);
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
#endif /* FLASH_BANK2_END */
|
||||
{
|
||||
/* Mass Erase requested for Bank1 */
|
||||
/* Wait for last operation to be completed */
|
||||
if (FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK)
|
||||
{
|
||||
if (FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) {
|
||||
/*Mass erase to be done*/
|
||||
FLASH_MassErase(FLASH_BANK_1);
|
||||
|
||||
@@ -241,9 +228,7 @@ HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t
|
||||
CLEAR_BIT(FLASH->CR, FLASH_CR_MER);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Page Erase is requested */
|
||||
/* Check the parameters */
|
||||
assert_param(IS_FLASH_PROGRAM_ADDRESS(pEraseInit->PageAddress));
|
||||
@@ -251,19 +236,14 @@ HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t
|
||||
|
||||
#if defined(FLASH_BANK2_END)
|
||||
/* Page Erase requested on address located on bank2 */
|
||||
if(pEraseInit->PageAddress > FLASH_BANK1_END)
|
||||
{
|
||||
if (pEraseInit->PageAddress > FLASH_BANK1_END) {
|
||||
/* Wait for last operation to be completed */
|
||||
if (FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK)
|
||||
{
|
||||
if (FLASH_WaitForLastOperationBank2((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) {
|
||||
/*Initialization of PageError variable*/
|
||||
*PageError = 0xFFFFFFFFU;
|
||||
|
||||
/* Erase by page by page to be done*/
|
||||
for(address = pEraseInit->PageAddress;
|
||||
address < (pEraseInit->PageAddress + (pEraseInit->NbPages)*FLASH_PAGE_SIZE);
|
||||
address += FLASH_PAGE_SIZE)
|
||||
{
|
||||
for (address = pEraseInit->PageAddress; address < (pEraseInit->PageAddress + (pEraseInit->NbPages) * FLASH_PAGE_SIZE); address += FLASH_PAGE_SIZE) {
|
||||
FLASH_PageErase(address);
|
||||
|
||||
/* Wait for last operation to be completed */
|
||||
@@ -272,30 +252,24 @@ HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t
|
||||
/* If the erase operation is completed, disable the PER Bit */
|
||||
CLEAR_BIT(FLASH->CR2, FLASH_CR2_PER);
|
||||
|
||||
if (status != HAL_OK)
|
||||
{
|
||||
if (status != HAL_OK) {
|
||||
/* In case of error, stop erase procedure and return the faulty address */
|
||||
*PageError = address;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
#endif /* FLASH_BANK2_END */
|
||||
{
|
||||
/* Page Erase requested on address located on bank1 */
|
||||
/* Wait for last operation to be completed */
|
||||
if (FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK)
|
||||
{
|
||||
if (FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK) {
|
||||
/*Initialization of PageError variable*/
|
||||
*PageError = 0xFFFFFFFFU;
|
||||
|
||||
/* Erase page by page to be done*/
|
||||
for(address = pEraseInit->PageAddress;
|
||||
address < ((pEraseInit->NbPages * FLASH_PAGE_SIZE) + pEraseInit->PageAddress);
|
||||
address += FLASH_PAGE_SIZE)
|
||||
{
|
||||
for (address = pEraseInit->PageAddress; address < ((pEraseInit->NbPages * FLASH_PAGE_SIZE) + pEraseInit->PageAddress); address += FLASH_PAGE_SIZE) {
|
||||
FLASH_PageErase(address);
|
||||
|
||||
/* Wait for last operation to be completed */
|
||||
@@ -304,8 +278,7 @@ HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t
|
||||
/* If the erase operation is completed, disable the PER Bit */
|
||||
CLEAR_BIT(FLASH->CR, FLASH_CR_PER);
|
||||
|
||||
if (status != HAL_OK)
|
||||
{
|
||||
if (status != HAL_OK) {
|
||||
/* In case of error, stop erase procedure and return the faulty address */
|
||||
*PageError = address;
|
||||
break;
|
||||
@@ -332,16 +305,14 @@ HAL_StatusTypeDef HAL_FLASHEx_Erase(FLASH_EraseInitTypeDef *pEraseInit, uint32_t
|
||||
*
|
||||
* @retval HAL_StatusTypeDef HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit) {
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Process Locked */
|
||||
__HAL_LOCK(&pFlash);
|
||||
|
||||
/* If procedure already ongoing, reject the next one */
|
||||
if (pFlash.ProcedureOnGoing != FLASH_PROC_NONE)
|
||||
{
|
||||
if (pFlash.ProcedureOnGoing != FLASH_PROC_NONE) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
@@ -356,14 +327,11 @@ HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit)
|
||||
__HAL_FLASH_ENABLE_IT(FLASH_IT_EOP_BANK2 | FLASH_IT_ERR_BANK2);
|
||||
|
||||
#endif
|
||||
if (pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE)
|
||||
{
|
||||
if (pEraseInit->TypeErase == FLASH_TYPEERASE_MASSERASE) {
|
||||
/*Mass erase to be done*/
|
||||
pFlash.ProcedureOnGoing = FLASH_PROC_MASSERASE;
|
||||
FLASH_MassErase(pEraseInit->Banks);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Erase by page to be done*/
|
||||
|
||||
/* Check the parameters */
|
||||
@@ -410,8 +378,7 @@ HAL_StatusTypeDef HAL_FLASHEx_Erase_IT(FLASH_EraseInitTypeDef *pEraseInit)
|
||||
* @retval HAL status
|
||||
*/
|
||||
|
||||
HAL_StatusTypeDef HAL_FLASHEx_OBErase(void)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_FLASHEx_OBErase(void) {
|
||||
uint8_t rdptmp = OB_RDP_LEVEL_0;
|
||||
HAL_StatusTypeDef status = HAL_ERROR;
|
||||
|
||||
@@ -421,8 +388,7 @@ HAL_StatusTypeDef HAL_FLASHEx_OBErase(void)
|
||||
/* Wait for last operation to be completed */
|
||||
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
|
||||
|
||||
if(status == HAL_OK)
|
||||
{
|
||||
if (status == HAL_OK) {
|
||||
/* Clean the error context */
|
||||
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
||||
|
||||
@@ -436,8 +402,7 @@ HAL_StatusTypeDef HAL_FLASHEx_OBErase(void)
|
||||
/* If the erase operation is completed, disable the OPTER Bit */
|
||||
CLEAR_BIT(FLASH->CR, FLASH_CR_OPTER);
|
||||
|
||||
if(status == HAL_OK)
|
||||
{
|
||||
if (status == HAL_OK) {
|
||||
/* Restore the last read protection Option Byte value */
|
||||
status = FLASH_OB_RDP_LevelConfig(rdptmp);
|
||||
}
|
||||
@@ -459,8 +424,7 @@ HAL_StatusTypeDef HAL_FLASHEx_OBErase(void)
|
||||
*
|
||||
* @retval HAL_StatusTypeDef HAL Status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit) {
|
||||
HAL_StatusTypeDef status = HAL_ERROR;
|
||||
|
||||
/* Process Locked */
|
||||
@@ -470,21 +434,16 @@ HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit)
|
||||
assert_param(IS_OPTIONBYTE(pOBInit->OptionType));
|
||||
|
||||
/* Write protection configuration */
|
||||
if((pOBInit->OptionType & OPTIONBYTE_WRP) == OPTIONBYTE_WRP)
|
||||
{
|
||||
if ((pOBInit->OptionType & OPTIONBYTE_WRP) == OPTIONBYTE_WRP) {
|
||||
assert_param(IS_WRPSTATE(pOBInit->WRPState));
|
||||
if (pOBInit->WRPState == OB_WRPSTATE_ENABLE)
|
||||
{
|
||||
if (pOBInit->WRPState == OB_WRPSTATE_ENABLE) {
|
||||
/* Enable of Write protection on the selected page */
|
||||
status = FLASH_OB_EnableWRP(pOBInit->WRPPage);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Disable of Write protection on the selected page */
|
||||
status = FLASH_OB_DisableWRP(pOBInit->WRPPage);
|
||||
}
|
||||
if (status != HAL_OK)
|
||||
{
|
||||
if (status != HAL_OK) {
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(&pFlash);
|
||||
return status;
|
||||
@@ -492,11 +451,9 @@ HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit)
|
||||
}
|
||||
|
||||
/* Read protection configuration */
|
||||
if((pOBInit->OptionType & OPTIONBYTE_RDP) == OPTIONBYTE_RDP)
|
||||
{
|
||||
if ((pOBInit->OptionType & OPTIONBYTE_RDP) == OPTIONBYTE_RDP) {
|
||||
status = FLASH_OB_RDP_LevelConfig(pOBInit->RDPLevel);
|
||||
if (status != HAL_OK)
|
||||
{
|
||||
if (status != HAL_OK) {
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(&pFlash);
|
||||
return status;
|
||||
@@ -504,11 +461,9 @@ HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit)
|
||||
}
|
||||
|
||||
/* USER configuration */
|
||||
if((pOBInit->OptionType & OPTIONBYTE_USER) == OPTIONBYTE_USER)
|
||||
{
|
||||
if ((pOBInit->OptionType & OPTIONBYTE_USER) == OPTIONBYTE_USER) {
|
||||
status = FLASH_OB_UserConfig(pOBInit->USERConfig);
|
||||
if (status != HAL_OK)
|
||||
{
|
||||
if (status != HAL_OK) {
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(&pFlash);
|
||||
return status;
|
||||
@@ -516,11 +471,9 @@ HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit)
|
||||
}
|
||||
|
||||
/* DATA configuration*/
|
||||
if((pOBInit->OptionType & OPTIONBYTE_DATA) == OPTIONBYTE_DATA)
|
||||
{
|
||||
if ((pOBInit->OptionType & OPTIONBYTE_DATA) == OPTIONBYTE_DATA) {
|
||||
status = FLASH_OB_ProgramData(pOBInit->DATAAddress, pOBInit->DATAData);
|
||||
if (status != HAL_OK)
|
||||
{
|
||||
if (status != HAL_OK) {
|
||||
/* Process Unlocked */
|
||||
__HAL_UNLOCK(&pFlash);
|
||||
return status;
|
||||
@@ -540,8 +493,7 @@ HAL_StatusTypeDef HAL_FLASHEx_OBProgram(FLASH_OBProgramInitTypeDef *pOBInit)
|
||||
*
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit)
|
||||
{
|
||||
void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit) {
|
||||
pOBInit->OptionType = OPTIONBYTE_WRP | OPTIONBYTE_RDP | OPTIONBYTE_USER;
|
||||
|
||||
/*Get WRP*/
|
||||
@@ -562,17 +514,13 @@ void HAL_FLASHEx_OBGetConfig(FLASH_OBProgramInitTypeDef *pOBInit)
|
||||
* @arg @ref OB_DATA_ADDRESS_DATA1
|
||||
* @retval Value programmed in USER data
|
||||
*/
|
||||
uint32_t HAL_FLASHEx_OBGetUserData(uint32_t DATAAdress)
|
||||
{
|
||||
uint32_t HAL_FLASHEx_OBGetUserData(uint32_t DATAAdress) {
|
||||
uint32_t value = 0;
|
||||
|
||||
if (DATAAdress == OB_DATA_ADDRESS_DATA0)
|
||||
{
|
||||
if (DATAAdress == OB_DATA_ADDRESS_DATA0) {
|
||||
/* Get value programmed in OB USER Data0 */
|
||||
value = READ_BIT(FLASH->OBR, FLASH_OBR_DATA0) >> FLASH_POSITION_OB_USERDATA0_BIT;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Get value programmed in OB USER Data1 */
|
||||
value = READ_BIT(FLASH->OBR, FLASH_OBR_DATA1) >> FLASH_POSITION_OB_USERDATA1_BIT;
|
||||
}
|
||||
@@ -608,8 +556,7 @@ uint32_t HAL_FLASHEx_OBGetUserData(uint32_t DATAAdress)
|
||||
*
|
||||
* @retval None
|
||||
*/
|
||||
static void FLASH_MassErase(uint32_t Banks)
|
||||
{
|
||||
static void FLASH_MassErase(uint32_t Banks) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_FLASH_BANK(Banks));
|
||||
|
||||
@@ -617,22 +564,17 @@ static void FLASH_MassErase(uint32_t Banks)
|
||||
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
||||
|
||||
#if defined(FLASH_BANK2_END)
|
||||
if(Banks == FLASH_BANK_BOTH)
|
||||
{
|
||||
if (Banks == FLASH_BANK_BOTH) {
|
||||
/* bank1 & bank2 will be erased*/
|
||||
SET_BIT(FLASH->CR, FLASH_CR_MER);
|
||||
SET_BIT(FLASH->CR2, FLASH_CR2_MER);
|
||||
SET_BIT(FLASH->CR, FLASH_CR_STRT);
|
||||
SET_BIT(FLASH->CR2, FLASH_CR2_STRT);
|
||||
}
|
||||
else if(Banks == FLASH_BANK_2)
|
||||
{
|
||||
} else if (Banks == FLASH_BANK_2) {
|
||||
/*Only bank2 will be erased*/
|
||||
SET_BIT(FLASH->CR2, FLASH_CR2_MER);
|
||||
SET_BIT(FLASH->CR2, FLASH_CR2_STRT);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
#endif /* FLASH_BANK2_END */
|
||||
#if !defined(FLASH_BANK2_END)
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
@@ -657,8 +599,7 @@ static void FLASH_MassErase(uint32_t Banks)
|
||||
* The value of this parameter depend on device used within the same series
|
||||
* @retval HAL status
|
||||
*/
|
||||
static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage)
|
||||
{
|
||||
static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage) {
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
uint16_t WRP0_Data = 0xFFFF;
|
||||
#if defined(FLASH_WRP1_WRP1)
|
||||
@@ -709,21 +650,18 @@ static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage)
|
||||
/* Wait for last operation to be completed */
|
||||
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
|
||||
|
||||
if(status == HAL_OK)
|
||||
{
|
||||
if (status == HAL_OK) {
|
||||
/* Clean the error context */
|
||||
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
||||
|
||||
/* To be able to write again option byte, need to perform a option byte erase */
|
||||
status = HAL_FLASHEx_OBErase();
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
if (status == HAL_OK) {
|
||||
/* Enable write protection */
|
||||
SET_BIT(FLASH->CR, FLASH_CR_OPTPG);
|
||||
|
||||
#if defined(FLASH_WRP0_WRP0)
|
||||
if(WRP0_Data != 0xFFU)
|
||||
{
|
||||
if (WRP0_Data != 0xFFU) {
|
||||
OB->WRP0 &= WRP0_Data;
|
||||
|
||||
/* Wait for last operation to be completed */
|
||||
@@ -732,8 +670,7 @@ static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage)
|
||||
#endif /* FLASH_WRP0_WRP0 */
|
||||
|
||||
#if defined(FLASH_WRP1_WRP1)
|
||||
if((status == HAL_OK) && (WRP1_Data != 0xFFU))
|
||||
{
|
||||
if ((status == HAL_OK) && (WRP1_Data != 0xFFU)) {
|
||||
OB->WRP1 &= WRP1_Data;
|
||||
|
||||
/* Wait for last operation to be completed */
|
||||
@@ -742,8 +679,7 @@ static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage)
|
||||
#endif /* FLASH_WRP1_WRP1 */
|
||||
|
||||
#if defined(FLASH_WRP2_WRP2)
|
||||
if((status == HAL_OK) && (WRP2_Data != 0xFFU))
|
||||
{
|
||||
if ((status == HAL_OK) && (WRP2_Data != 0xFFU)) {
|
||||
OB->WRP2 &= WRP2_Data;
|
||||
|
||||
/* Wait for last operation to be completed */
|
||||
@@ -752,8 +688,7 @@ static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage)
|
||||
#endif /* FLASH_WRP2_WRP2 */
|
||||
|
||||
#if defined(FLASH_WRP3_WRP3)
|
||||
if((status == HAL_OK) && (WRP3_Data != 0xFFU))
|
||||
{
|
||||
if ((status == HAL_OK) && (WRP3_Data != 0xFFU)) {
|
||||
OB->WRP3 &= WRP3_Data;
|
||||
|
||||
/* Wait for last operation to be completed */
|
||||
@@ -780,8 +715,7 @@ static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WriteProtectPage)
|
||||
* The value of this parameter depend on device used within the same series
|
||||
* @retval HAL status
|
||||
*/
|
||||
static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage)
|
||||
{
|
||||
static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage) {
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
uint16_t WRP0_Data = 0xFFFF;
|
||||
#if defined(FLASH_WRP1_WRP1)
|
||||
@@ -829,24 +763,20 @@ static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage)
|
||||
WRP3_Data = (uint16_t)((WriteProtectPage & OB_WRP_PAGES48TO127MASK) >> 24U);
|
||||
#endif /* OB_WRP_PAGES96TO127MASK */
|
||||
|
||||
|
||||
/* Wait for last operation to be completed */
|
||||
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
|
||||
|
||||
if(status == HAL_OK)
|
||||
{
|
||||
if (status == HAL_OK) {
|
||||
/* Clean the error context */
|
||||
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
||||
|
||||
/* To be able to write again option byte, need to perform a option byte erase */
|
||||
status = HAL_FLASHEx_OBErase();
|
||||
if (status == HAL_OK)
|
||||
{
|
||||
if (status == HAL_OK) {
|
||||
SET_BIT(FLASH->CR, FLASH_CR_OPTPG);
|
||||
|
||||
#if defined(FLASH_WRP0_WRP0)
|
||||
if(WRP0_Data != 0xFFU)
|
||||
{
|
||||
if (WRP0_Data != 0xFFU) {
|
||||
OB->WRP0 |= WRP0_Data;
|
||||
|
||||
/* Wait for last operation to be completed */
|
||||
@@ -855,8 +785,7 @@ static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage)
|
||||
#endif /* FLASH_WRP0_WRP0 */
|
||||
|
||||
#if defined(FLASH_WRP1_WRP1)
|
||||
if((status == HAL_OK) && (WRP1_Data != 0xFFU))
|
||||
{
|
||||
if ((status == HAL_OK) && (WRP1_Data != 0xFFU)) {
|
||||
OB->WRP1 |= WRP1_Data;
|
||||
|
||||
/* Wait for last operation to be completed */
|
||||
@@ -865,8 +794,7 @@ static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage)
|
||||
#endif /* FLASH_WRP1_WRP1 */
|
||||
|
||||
#if defined(FLASH_WRP2_WRP2)
|
||||
if((status == HAL_OK) && (WRP2_Data != 0xFFU))
|
||||
{
|
||||
if ((status == HAL_OK) && (WRP2_Data != 0xFFU)) {
|
||||
OB->WRP2 |= WRP2_Data;
|
||||
|
||||
/* Wait for last operation to be completed */
|
||||
@@ -875,8 +803,7 @@ static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage)
|
||||
#endif /* FLASH_WRP2_WRP2 */
|
||||
|
||||
#if defined(FLASH_WRP3_WRP3)
|
||||
if((status == HAL_OK) && (WRP3_Data != 0xFFU))
|
||||
{
|
||||
if ((status == HAL_OK) && (WRP3_Data != 0xFFU)) {
|
||||
OB->WRP3 |= WRP3_Data;
|
||||
|
||||
/* Wait for last operation to be completed */
|
||||
@@ -899,8 +826,7 @@ static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WriteProtectPage)
|
||||
* @arg @ref OB_RDP_LEVEL_1 Read protection of the memory
|
||||
* @retval HAL status
|
||||
*/
|
||||
static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel)
|
||||
{
|
||||
static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel) {
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check the parameters */
|
||||
@@ -909,8 +835,7 @@ static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel)
|
||||
/* Wait for last operation to be completed */
|
||||
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
|
||||
|
||||
if(status == HAL_OK)
|
||||
{
|
||||
if (status == HAL_OK) {
|
||||
/* Clean the error context */
|
||||
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
||||
|
||||
@@ -924,8 +849,7 @@ static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel)
|
||||
/* If the erase operation is completed, disable the OPTER Bit */
|
||||
CLEAR_BIT(FLASH->CR, FLASH_CR_OPTER);
|
||||
|
||||
if(status == HAL_OK)
|
||||
{
|
||||
if (status == HAL_OK) {
|
||||
/* Enable the Option Bytes Programming operation */
|
||||
SET_BIT(FLASH->CR, FLASH_CR_OPTPG);
|
||||
|
||||
@@ -950,8 +874,7 @@ static HAL_StatusTypeDef FLASH_OB_RDP_LevelConfig(uint8_t ReadProtectLevel)
|
||||
* And BFBF2(Bit5) for STM32F101xG and STM32F103xG .
|
||||
* @retval HAL status
|
||||
*/
|
||||
static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t UserConfig)
|
||||
{
|
||||
static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t UserConfig) {
|
||||
HAL_StatusTypeDef status = HAL_OK;
|
||||
|
||||
/* Check the parameters */
|
||||
@@ -965,8 +888,7 @@ static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t UserConfig)
|
||||
/* Wait for last operation to be completed */
|
||||
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
|
||||
|
||||
if(status == HAL_OK)
|
||||
{
|
||||
if (status == HAL_OK) {
|
||||
/* Clean the error context */
|
||||
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
||||
|
||||
@@ -1001,8 +923,7 @@ static HAL_StatusTypeDef FLASH_OB_UserConfig(uint8_t UserConfig)
|
||||
* @param Data specifies the data to be programmed.
|
||||
* @retval HAL status
|
||||
*/
|
||||
static HAL_StatusTypeDef FLASH_OB_ProgramData(uint32_t Address, uint8_t Data)
|
||||
{
|
||||
static HAL_StatusTypeDef FLASH_OB_ProgramData(uint32_t Address, uint8_t Data) {
|
||||
HAL_StatusTypeDef status = HAL_ERROR;
|
||||
|
||||
/* Check the parameters */
|
||||
@@ -1011,8 +932,7 @@ static HAL_StatusTypeDef FLASH_OB_ProgramData(uint32_t Address, uint8_t Data)
|
||||
/* Wait for last operation to be completed */
|
||||
status = FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE);
|
||||
|
||||
if(status == HAL_OK)
|
||||
{
|
||||
if (status == HAL_OK) {
|
||||
/* Clean the error context */
|
||||
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
||||
|
||||
@@ -1034,8 +954,7 @@ static HAL_StatusTypeDef FLASH_OB_ProgramData(uint32_t Address, uint8_t Data)
|
||||
* @brief Return the FLASH Write Protection Option Bytes value.
|
||||
* @retval The FLASH Write Protection Option Bytes value
|
||||
*/
|
||||
static uint32_t FLASH_OB_GetWRP(void)
|
||||
{
|
||||
static uint32_t FLASH_OB_GetWRP(void) {
|
||||
/* Return the FLASH write protection Register value */
|
||||
return (uint32_t)(READ_REG(FLASH->WRPR));
|
||||
}
|
||||
@@ -1047,20 +966,16 @@ static uint32_t FLASH_OB_GetWRP(void)
|
||||
* @arg @ref OB_RDP_LEVEL_0 No protection
|
||||
* @arg @ref OB_RDP_LEVEL_1 Read protection of the memory
|
||||
*/
|
||||
static uint32_t FLASH_OB_GetRDP(void)
|
||||
{
|
||||
static uint32_t FLASH_OB_GetRDP(void) {
|
||||
uint32_t readstatus = OB_RDP_LEVEL_0;
|
||||
uint32_t tmp_reg = 0U;
|
||||
|
||||
/* Read RDP level bits */
|
||||
tmp_reg = READ_BIT(FLASH->OBR, FLASH_OBR_RDPRT);
|
||||
|
||||
if (tmp_reg == FLASH_OBR_RDPRT)
|
||||
{
|
||||
if (tmp_reg == FLASH_OBR_RDPRT) {
|
||||
readstatus = OB_RDP_LEVEL_1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
readstatus = OB_RDP_LEVEL_0;
|
||||
}
|
||||
|
||||
@@ -1073,8 +988,7 @@ static uint32_t FLASH_OB_GetRDP(void)
|
||||
* FLASH_OBR_nRST_STOP(Bit3),FLASH_OBR_nRST_STDBY(Bit4).
|
||||
* And FLASH_OBR_BFB2(Bit5) for STM32F101xG and STM32F103xG .
|
||||
*/
|
||||
static uint8_t FLASH_OB_GetUser(void)
|
||||
{
|
||||
static uint8_t FLASH_OB_GetUser(void) {
|
||||
/* Return the User Option Byte */
|
||||
return (uint8_t)((READ_REG(FLASH->OBR) & FLASH_OBR_USER) >> FLASH_POSITION_IWDGSW_BIT);
|
||||
}
|
||||
@@ -1102,21 +1016,17 @@ static uint8_t FLASH_OB_GetUser(void)
|
||||
*
|
||||
* @retval None
|
||||
*/
|
||||
void FLASH_PageErase(uint32_t PageAddress)
|
||||
{
|
||||
void FLASH_PageErase(uint32_t PageAddress) {
|
||||
/* Clean the error context */
|
||||
pFlash.ErrorCode = HAL_FLASH_ERROR_NONE;
|
||||
|
||||
#if defined(FLASH_BANK2_END)
|
||||
if(PageAddress > FLASH_BANK1_END)
|
||||
{
|
||||
if (PageAddress > FLASH_BANK1_END) {
|
||||
/* Proceed to erase the page */
|
||||
SET_BIT(FLASH->CR2, FLASH_CR2_PER);
|
||||
WRITE_REG(FLASH->AR2, PageAddress);
|
||||
SET_BIT(FLASH->CR2, FLASH_CR2_STRT);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
#endif /* FLASH_BANK2_END */
|
||||
/* Proceed to erase the page */
|
||||
SET_BIT(FLASH->CR, FLASH_CR_PER);
|
||||
|
||||
@@ -183,7 +183,6 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initializes the GPIOx peripheral according to the specified parameters in the GPIO_Init.
|
||||
* @param GPIOx: where x can be (A..G depending on device used) to select the GPIO peripheral
|
||||
@@ -191,8 +190,7 @@
|
||||
* the configuration information for the specified GPIO peripheral.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
|
||||
{
|
||||
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init) {
|
||||
uint32_t position;
|
||||
uint32_t ioposition = 0x00U;
|
||||
uint32_t iocurrent = 0x00U;
|
||||
@@ -207,22 +205,19 @@ void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
|
||||
assert_param(IS_GPIO_MODE(GPIO_Init->Mode));
|
||||
|
||||
/* Configure the port pins */
|
||||
for (position = 0U; position < GPIO_NUMBER; position++)
|
||||
{
|
||||
for (position = 0U; position < GPIO_NUMBER; position++) {
|
||||
/* Get the IO position */
|
||||
ioposition = (0x01U << position);
|
||||
|
||||
/* Get the current IO position */
|
||||
iocurrent = (uint32_t)(GPIO_Init->Pin) & ioposition;
|
||||
|
||||
if (iocurrent == ioposition)
|
||||
{
|
||||
if (iocurrent == ioposition) {
|
||||
/* Check the Alternate function parameters */
|
||||
assert_param(IS_GPIO_AF_INSTANCE(GPIOx));
|
||||
|
||||
/* Based on the required mode, filling config variable with MODEy[1:0] and CNFy[3:2] corresponding bits */
|
||||
switch (GPIO_Init->Mode)
|
||||
{
|
||||
switch (GPIO_Init->Mode) {
|
||||
/* If we are configuring the pin in OUTPUT push-pull mode */
|
||||
case GPIO_MODE_OUTPUT_PP:
|
||||
/* Check the GPIO speed parameter */
|
||||
@@ -261,18 +256,14 @@ void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
|
||||
case GPIO_MODE_EVT_RISING_FALLING:
|
||||
/* Check the GPIO pull parameter */
|
||||
assert_param(IS_GPIO_PULL(GPIO_Init->Pull));
|
||||
if (GPIO_Init->Pull == GPIO_NOPULL)
|
||||
{
|
||||
if (GPIO_Init->Pull == GPIO_NOPULL) {
|
||||
config = GPIO_CR_MODE_INPUT + GPIO_CR_CNF_INPUT_FLOATING;
|
||||
}
|
||||
else if (GPIO_Init->Pull == GPIO_PULLUP)
|
||||
{
|
||||
} else if (GPIO_Init->Pull == GPIO_PULLUP) {
|
||||
config = GPIO_CR_MODE_INPUT + GPIO_CR_CNF_INPUT_PU_PD;
|
||||
|
||||
/* Set the corresponding ODR bit */
|
||||
GPIOx->BSRR = ioposition;
|
||||
}
|
||||
else /* GPIO_PULLDOWN */
|
||||
} else /* GPIO_PULLDOWN */
|
||||
{
|
||||
config = GPIO_CR_MODE_INPUT + GPIO_CR_CNF_INPUT_PU_PD;
|
||||
|
||||
@@ -301,8 +292,7 @@ void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
|
||||
|
||||
/*--------------------- EXTI Mode Configuration ------------------------*/
|
||||
/* Configure the External Interrupt or event for the current IO */
|
||||
if ((GPIO_Init->Mode & EXTI_MODE) == EXTI_MODE)
|
||||
{
|
||||
if ((GPIO_Init->Mode & EXTI_MODE) == EXTI_MODE) {
|
||||
/* Enable AFIO Clock */
|
||||
__HAL_RCC_AFIO_CLK_ENABLE();
|
||||
temp = AFIO->EXTICR[position >> 2U];
|
||||
@@ -310,44 +300,31 @@ void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
|
||||
SET_BIT(temp, (GPIO_GET_INDEX(GPIOx)) << (4U * (position & 0x03U)));
|
||||
AFIO->EXTICR[position >> 2U] = temp;
|
||||
|
||||
|
||||
/* Configure the interrupt mask */
|
||||
if ((GPIO_Init->Mode & GPIO_MODE_IT) == GPIO_MODE_IT)
|
||||
{
|
||||
if ((GPIO_Init->Mode & GPIO_MODE_IT) == GPIO_MODE_IT) {
|
||||
SET_BIT(EXTI->IMR, iocurrent);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
CLEAR_BIT(EXTI->IMR, iocurrent);
|
||||
}
|
||||
|
||||
/* Configure the event mask */
|
||||
if ((GPIO_Init->Mode & GPIO_MODE_EVT) == GPIO_MODE_EVT)
|
||||
{
|
||||
if ((GPIO_Init->Mode & GPIO_MODE_EVT) == GPIO_MODE_EVT) {
|
||||
SET_BIT(EXTI->EMR, iocurrent);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
CLEAR_BIT(EXTI->EMR, iocurrent);
|
||||
}
|
||||
|
||||
/* Enable or disable the rising trigger */
|
||||
if ((GPIO_Init->Mode & RISING_EDGE) == RISING_EDGE)
|
||||
{
|
||||
if ((GPIO_Init->Mode & RISING_EDGE) == RISING_EDGE) {
|
||||
SET_BIT(EXTI->RTSR, iocurrent);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
CLEAR_BIT(EXTI->RTSR, iocurrent);
|
||||
}
|
||||
|
||||
/* Enable or disable the falling trigger */
|
||||
if ((GPIO_Init->Mode & FALLING_EDGE) == FALLING_EDGE)
|
||||
{
|
||||
if ((GPIO_Init->Mode & FALLING_EDGE) == FALLING_EDGE) {
|
||||
SET_BIT(EXTI->FTSR, iocurrent);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
CLEAR_BIT(EXTI->FTSR, iocurrent);
|
||||
}
|
||||
}
|
||||
@@ -362,8 +339,7 @@ void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
|
||||
* This parameter can be one of GPIO_PIN_x where x can be (0..15).
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
|
||||
{
|
||||
void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin) {
|
||||
uint32_t position = 0x00U;
|
||||
uint32_t iocurrent = 0x00U;
|
||||
uint32_t tmp = 0x00U;
|
||||
@@ -375,13 +351,11 @@ void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
|
||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||
|
||||
/* Configure the port pins */
|
||||
while ((GPIO_Pin >> position) != 0U)
|
||||
{
|
||||
while ((GPIO_Pin >> position) != 0U) {
|
||||
/* Get current io position */
|
||||
iocurrent = (GPIO_Pin) & (1U << position);
|
||||
|
||||
if (iocurrent)
|
||||
{
|
||||
if (iocurrent) {
|
||||
/*------------------------- GPIO Mode Configuration --------------------*/
|
||||
/* Check if the current bit belongs to first half or last half of the pin count number
|
||||
in order to address CRH or CRL register */
|
||||
@@ -399,8 +373,7 @@ void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
|
||||
|
||||
tmp = AFIO->EXTICR[position >> 2U];
|
||||
tmp &= 0x0FU << (4U * (position & 0x03U));
|
||||
if (tmp == (GPIO_GET_INDEX(GPIOx) << (4U * (position & 0x03U))))
|
||||
{
|
||||
if (tmp == (GPIO_GET_INDEX(GPIOx) << (4U * (position & 0x03U)))) {
|
||||
tmp = 0x0FU << (4U * (position & 0x03U));
|
||||
CLEAR_BIT(AFIO->EXTICR[position >> 2U], tmp);
|
||||
|
||||
@@ -443,19 +416,15 @@ void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
|
||||
* This parameter can be GPIO_PIN_x where x can be (0..15).
|
||||
* @retval The input port pin value.
|
||||
*/
|
||||
GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
|
||||
{
|
||||
GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin) {
|
||||
GPIO_PinState bitstatus;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||
|
||||
if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)GPIO_PIN_RESET)
|
||||
{
|
||||
if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)GPIO_PIN_RESET) {
|
||||
bitstatus = GPIO_PIN_SET;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
bitstatus = GPIO_PIN_RESET;
|
||||
}
|
||||
return bitstatus;
|
||||
@@ -477,18 +446,14 @@ GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
|
||||
* @arg GPIO_PIN_SET: to set the port pin
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
|
||||
{
|
||||
void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||
assert_param(IS_GPIO_PIN_ACTION(PinState));
|
||||
|
||||
if (PinState != GPIO_PIN_RESET)
|
||||
{
|
||||
if (PinState != GPIO_PIN_RESET) {
|
||||
GPIOx->BSRR = GPIO_Pin;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
GPIOx->BSRR = (uint32_t)GPIO_Pin << 16U;
|
||||
}
|
||||
}
|
||||
@@ -499,8 +464,7 @@ void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState Pin
|
||||
* @param GPIO_Pin: Specifies the pins to be toggled.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
|
||||
{
|
||||
void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
||||
|
||||
@@ -517,8 +481,7 @@ void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
|
||||
* This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
|
||||
* @retval None
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin) {
|
||||
__IO uint32_t tmp = GPIO_LCKR_LCKK;
|
||||
|
||||
/* Check the parameters */
|
||||
@@ -536,12 +499,9 @@ HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
|
||||
/* Read LCKK bit*/
|
||||
tmp = GPIOx->LCKR;
|
||||
|
||||
if ((uint32_t)(GPIOx->LCKR & GPIO_LCKR_LCKK))
|
||||
{
|
||||
if ((uint32_t)(GPIOx->LCKR & GPIO_LCKR_LCKK)) {
|
||||
return HAL_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -551,11 +511,9 @@ HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
|
||||
* @param GPIO_Pin: Specifies the pins connected EXTI line
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
|
||||
{
|
||||
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin) {
|
||||
/* EXTI line interrupt detected */
|
||||
if (__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != RESET)
|
||||
{
|
||||
if (__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != RESET) {
|
||||
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
|
||||
HAL_GPIO_EXTI_Callback(GPIO_Pin);
|
||||
}
|
||||
@@ -566,8 +524,7 @@ void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
|
||||
* @param GPIO_Pin: Specifies the pins connected EXTI line
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
||||
{
|
||||
__weak void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(GPIO_Pin);
|
||||
/* NOTE: This function Should not be modified, when the callback is needed,
|
||||
|
||||
@@ -94,8 +94,7 @@
|
||||
* This parameter can be a value of @ref GPIOEx_EVENTOUT_PIN.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_GPIOEx_ConfigEventout(uint32_t GPIO_PortSource, uint32_t GPIO_PinSource)
|
||||
{
|
||||
void HAL_GPIOEx_ConfigEventout(uint32_t GPIO_PortSource, uint32_t GPIO_PinSource) {
|
||||
/* Verify the parameters */
|
||||
assert_param(IS_AFIO_EVENTOUT_PORT(GPIO_PortSource));
|
||||
assert_param(IS_AFIO_EVENTOUT_PIN(GPIO_PinSource));
|
||||
@@ -108,19 +107,13 @@ void HAL_GPIOEx_ConfigEventout(uint32_t GPIO_PortSource, uint32_t GPIO_PinSource
|
||||
* @brief Enables the Event Output.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_GPIOEx_EnableEventout(void)
|
||||
{
|
||||
SET_BIT(AFIO->EVCR, AFIO_EVCR_EVOE);
|
||||
}
|
||||
void HAL_GPIOEx_EnableEventout(void) { SET_BIT(AFIO->EVCR, AFIO_EVCR_EVOE); }
|
||||
|
||||
/**
|
||||
* @brief Disables the Event Output.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_GPIOEx_DisableEventout(void)
|
||||
{
|
||||
CLEAR_BIT(AFIO->EVCR, AFIO_EVCR_EVOE);
|
||||
}
|
||||
void HAL_GPIOEx_DisableEventout(void) { CLEAR_BIT(AFIO->EVCR, AFIO_EVCR_EVOE); }
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -159,13 +159,11 @@
|
||||
* the configuration information for the specified IWDG module.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg) {
|
||||
uint32_t tickstart;
|
||||
|
||||
/* Check the IWDG handle allocation */
|
||||
if (hiwdg == NULL)
|
||||
{
|
||||
if (hiwdg == NULL) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
@@ -188,10 +186,8 @@ HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg)
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait for register to be updated */
|
||||
while (hiwdg->Instance->SR != RESET)
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) > HAL_IWDG_DEFAULT_TIMEOUT)
|
||||
{
|
||||
while (hiwdg->Instance->SR != RESET) {
|
||||
if ((HAL_GetTick() - tickstart) > HAL_IWDG_DEFAULT_TIMEOUT) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
@@ -227,8 +223,7 @@ HAL_StatusTypeDef HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg)
|
||||
* the configuration information for the specified IWDG module.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg) {
|
||||
/* Reload IWDG counter with value defined in the reload register */
|
||||
__HAL_IWDG_RELOAD_COUNTER(hiwdg);
|
||||
|
||||
|
||||
@@ -71,7 +71,6 @@
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup PWR_register_alias_address PWR Register alias address
|
||||
* @{
|
||||
*/
|
||||
@@ -130,8 +129,7 @@ static void PWR_OverloadWfe(void);
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
__NOINLINE
|
||||
static void PWR_OverloadWfe(void)
|
||||
{
|
||||
static void PWR_OverloadWfe(void) {
|
||||
__asm volatile("wfe");
|
||||
__asm volatile("nop");
|
||||
}
|
||||
@@ -140,7 +138,6 @@ static void PWR_OverloadWfe(void)
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup PWR_Exported_Functions PWR Exported Functions
|
||||
* @{
|
||||
*/
|
||||
@@ -169,8 +166,7 @@ static void PWR_OverloadWfe(void)
|
||||
* @brief Deinitializes the PWR peripheral registers to their default reset values.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_DeInit(void)
|
||||
{
|
||||
void HAL_PWR_DeInit(void) {
|
||||
__HAL_RCC_PWR_FORCE_RESET();
|
||||
__HAL_RCC_PWR_RELEASE_RESET();
|
||||
}
|
||||
@@ -182,8 +178,7 @@ void HAL_PWR_DeInit(void)
|
||||
* Backup Domain Access should be kept enabled.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_EnableBkUpAccess(void)
|
||||
{
|
||||
void HAL_PWR_EnableBkUpAccess(void) {
|
||||
/* Enable access to RTC and backup registers */
|
||||
*(__IO uint32_t *)CR_DBP_BB = (uint32_t)ENABLE;
|
||||
}
|
||||
@@ -195,8 +190,7 @@ void HAL_PWR_EnableBkUpAccess(void)
|
||||
* Backup Domain Access should be kept enabled.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_DisableBkUpAccess(void)
|
||||
{
|
||||
void HAL_PWR_DisableBkUpAccess(void) {
|
||||
/* Disable access to RTC and backup registers */
|
||||
*(__IO uint32_t *)CR_DBP_BB = (uint32_t)DISABLE;
|
||||
}
|
||||
@@ -329,8 +323,7 @@ void HAL_PWR_DisableBkUpAccess(void)
|
||||
* detection level.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD)
|
||||
{
|
||||
void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_PWR_PVD_LEVEL(sConfigPVD->PVDLevel));
|
||||
assert_param(IS_PWR_PVD_MODE(sConfigPVD->Mode));
|
||||
@@ -345,25 +338,21 @@ void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD)
|
||||
__HAL_PWR_PVD_EXTI_DISABLE_RISING_EDGE();
|
||||
|
||||
/* Configure interrupt mode */
|
||||
if((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT)
|
||||
{
|
||||
if ((sConfigPVD->Mode & PVD_MODE_IT) == PVD_MODE_IT) {
|
||||
__HAL_PWR_PVD_EXTI_ENABLE_IT();
|
||||
}
|
||||
|
||||
/* Configure event mode */
|
||||
if((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT)
|
||||
{
|
||||
if ((sConfigPVD->Mode & PVD_MODE_EVT) == PVD_MODE_EVT) {
|
||||
__HAL_PWR_PVD_EXTI_ENABLE_EVENT();
|
||||
}
|
||||
|
||||
/* Configure the edge */
|
||||
if((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE)
|
||||
{
|
||||
if ((sConfigPVD->Mode & PVD_RISING_EDGE) == PVD_RISING_EDGE) {
|
||||
__HAL_PWR_PVD_EXTI_ENABLE_RISING_EDGE();
|
||||
}
|
||||
|
||||
if((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE)
|
||||
{
|
||||
if ((sConfigPVD->Mode & PVD_FALLING_EDGE) == PVD_FALLING_EDGE) {
|
||||
__HAL_PWR_PVD_EXTI_ENABLE_FALLING_EDGE();
|
||||
}
|
||||
}
|
||||
@@ -372,8 +361,7 @@ void HAL_PWR_ConfigPVD(PWR_PVDTypeDef *sConfigPVD)
|
||||
* @brief Enables the Power Voltage Detector(PVD).
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_EnablePVD(void)
|
||||
{
|
||||
void HAL_PWR_EnablePVD(void) {
|
||||
/* Enable the power voltage detector */
|
||||
*(__IO uint32_t *)CR_PVDE_BB = (uint32_t)ENABLE;
|
||||
}
|
||||
@@ -382,8 +370,7 @@ void HAL_PWR_EnablePVD(void)
|
||||
* @brief Disables the Power Voltage Detector(PVD).
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_DisablePVD(void)
|
||||
{
|
||||
void HAL_PWR_DisablePVD(void) {
|
||||
/* Disable the power voltage detector */
|
||||
*(__IO uint32_t *)CR_PVDE_BB = (uint32_t)DISABLE;
|
||||
}
|
||||
@@ -395,8 +382,7 @@ void HAL_PWR_DisablePVD(void)
|
||||
* @arg PWR_WAKEUP_PIN1
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx)
|
||||
{
|
||||
void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx) {
|
||||
/* Check the parameter */
|
||||
assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
|
||||
/* Enable the EWUPx pin */
|
||||
@@ -410,8 +396,7 @@ void HAL_PWR_EnableWakeUpPin(uint32_t WakeUpPinx)
|
||||
* @arg PWR_WAKEUP_PIN1
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx)
|
||||
{
|
||||
void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx) {
|
||||
/* Check the parameter */
|
||||
assert_param(IS_PWR_WAKEUP_PIN(WakeUpPinx));
|
||||
/* Disable the EWUPx pin */
|
||||
@@ -430,8 +415,7 @@ void HAL_PWR_DisableWakeUpPin(uint32_t WakeUpPinx)
|
||||
* @arg PWR_SLEEPENTRY_WFE: enter SLEEP mode with WFE instruction
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry)
|
||||
{
|
||||
void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry) {
|
||||
/* Check the parameters */
|
||||
/* No check on Regulator because parameter not used in SLEEP mode */
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
@@ -443,13 +427,10 @@ void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry)
|
||||
CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
|
||||
|
||||
/* Select SLEEP mode entry -------------------------------------------------*/
|
||||
if(SLEEPEntry == PWR_SLEEPENTRY_WFI)
|
||||
{
|
||||
if (SLEEPEntry == PWR_SLEEPENTRY_WFI) {
|
||||
/* Request Wait For Interrupt */
|
||||
__WFI();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Request Wait For Event */
|
||||
__SEV();
|
||||
__WFE();
|
||||
@@ -476,8 +457,7 @@ void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry)
|
||||
* @arg PWR_STOPENTRY_WFE: Enter Stop mode with WFE instruction
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
|
||||
{
|
||||
void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_PWR_REGULATOR(Regulator));
|
||||
assert_param(IS_PWR_STOP_ENTRY(STOPEntry));
|
||||
@@ -492,13 +472,10 @@ void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
|
||||
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
|
||||
|
||||
/* Select Stop mode entry --------------------------------------------------*/
|
||||
if(STOPEntry == PWR_STOPENTRY_WFI)
|
||||
{
|
||||
if (STOPEntry == PWR_STOPENTRY_WFI) {
|
||||
/* Request Wait For Interrupt */
|
||||
__WFI();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Request Wait For Event */
|
||||
__SEV();
|
||||
PWR_OverloadWfe(); /* WFE redefine locally */
|
||||
@@ -516,8 +493,7 @@ void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
|
||||
* - WKUP pin (PA0) if enabled.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_EnterSTANDBYMode(void)
|
||||
{
|
||||
void HAL_PWR_EnterSTANDBYMode(void) {
|
||||
/* Select Standby mode */
|
||||
SET_BIT(PWR->CR, PWR_CR_PDDS);
|
||||
|
||||
@@ -532,7 +508,6 @@ void HAL_PWR_EnterSTANDBYMode(void)
|
||||
__WFI();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Indicates Sleep-On-Exit when returning from Handler mode to Thread mode.
|
||||
* @note Set SLEEPONEXIT bit of SCR register. When this bit is set, the processor
|
||||
@@ -541,63 +516,52 @@ void HAL_PWR_EnterSTANDBYMode(void)
|
||||
* interruptions handling.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_EnableSleepOnExit(void)
|
||||
{
|
||||
void HAL_PWR_EnableSleepOnExit(void) {
|
||||
/* Set SLEEPONEXIT bit of Cortex System Control Register */
|
||||
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Disables Sleep-On-Exit feature when returning from Handler mode to Thread mode.
|
||||
* @note Clears SLEEPONEXIT bit of SCR register. When this bit is set, the processor
|
||||
* re-enters SLEEP mode when an interruption handling is over.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_DisableSleepOnExit(void)
|
||||
{
|
||||
void HAL_PWR_DisableSleepOnExit(void) {
|
||||
/* Clear SLEEPONEXIT bit of Cortex System Control Register */
|
||||
CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPONEXIT_Msk));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enables CORTEX M3 SEVONPEND bit.
|
||||
* @note Sets SEVONPEND bit of SCR register. When this bit is set, this causes
|
||||
* WFE to wake up when an interrupt moves from inactive to pended.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_EnableSEVOnPend(void)
|
||||
{
|
||||
void HAL_PWR_EnableSEVOnPend(void) {
|
||||
/* Set SEVONPEND bit of Cortex System Control Register */
|
||||
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Disables CORTEX M3 SEVONPEND bit.
|
||||
* @note Clears SEVONPEND bit of SCR register. When this bit is set, this causes
|
||||
* WFE to wake up when an interrupt moves from inactive to pended.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_DisableSEVOnPend(void)
|
||||
{
|
||||
void HAL_PWR_DisableSEVOnPend(void) {
|
||||
/* Clear SEVONPEND bit of Cortex System Control Register */
|
||||
CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SEVONPEND_Msk));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function handles the PWR PVD interrupt request.
|
||||
* @note This API should be called under the PVD_IRQHandler().
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_PWR_PVD_IRQHandler(void)
|
||||
{
|
||||
void HAL_PWR_PVD_IRQHandler(void) {
|
||||
/* Check PWR exti flag */
|
||||
if(__HAL_PWR_PVD_EXTI_GET_FLAG() != RESET)
|
||||
{
|
||||
if (__HAL_PWR_PVD_EXTI_GET_FLAG() != RESET) {
|
||||
/* PWR PVD interrupt user callback */
|
||||
HAL_PWR_PVDCallback();
|
||||
|
||||
@@ -610,8 +574,7 @@ void HAL_PWR_PVD_IRQHandler(void)
|
||||
* @brief PWR PVD interrupt callback
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_PWR_PVDCallback(void)
|
||||
{
|
||||
__weak void HAL_PWR_PVDCallback(void) {
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_PWR_PVDCallback could be implemented in the user file
|
||||
*/
|
||||
|
||||
@@ -215,8 +215,7 @@ static void RCC_Delay(uint32_t mdelay);
|
||||
* - LSI, LSE and RTC clocks
|
||||
* @retval HAL_StatusTypeDef
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_RCC_DeInit(void)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_RCC_DeInit(void) {
|
||||
uint32_t tickstart;
|
||||
|
||||
/* Get Start Tick */
|
||||
@@ -226,10 +225,8 @@ HAL_StatusTypeDef HAL_RCC_DeInit(void)
|
||||
SET_BIT(RCC->CR, RCC_CR_HSION);
|
||||
|
||||
/* Wait till HSI is ready */
|
||||
while (READ_BIT(RCC->CR, RCC_CR_HSIRDY) == RESET)
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) > HSI_TIMEOUT_VALUE)
|
||||
{
|
||||
while (READ_BIT(RCC->CR, RCC_CR_HSIRDY) == RESET) {
|
||||
if ((HAL_GetTick() - tickstart) > HSI_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
@@ -244,10 +241,8 @@ HAL_StatusTypeDef HAL_RCC_DeInit(void)
|
||||
CLEAR_REG(RCC->CFGR);
|
||||
|
||||
/* Wait till clock switch is ready */
|
||||
while (READ_BIT(RCC->CFGR, RCC_CFGR_SWS) != RESET)
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) > CLOCKSWITCH_TIMEOUT_VALUE)
|
||||
{
|
||||
while (READ_BIT(RCC->CFGR, RCC_CFGR_SWS) != RESET) {
|
||||
if ((HAL_GetTick() - tickstart) > CLOCKSWITCH_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
@@ -256,8 +251,7 @@ HAL_StatusTypeDef HAL_RCC_DeInit(void)
|
||||
SystemCoreClock = HSI_VALUE;
|
||||
|
||||
/* Adapt Systick interrupt period */
|
||||
if(HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK)
|
||||
{
|
||||
if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
@@ -268,10 +262,8 @@ HAL_StatusTypeDef HAL_RCC_DeInit(void)
|
||||
CLEAR_BIT(RCC->CR, RCC_CR_PLLON);
|
||||
|
||||
/* Wait till PLL is disabled */
|
||||
while (READ_BIT(RCC->CR, RCC_CR_PLLRDY) != RESET)
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) > PLL_TIMEOUT_VALUE)
|
||||
{
|
||||
while (READ_BIT(RCC->CR, RCC_CR_PLLRDY) != RESET) {
|
||||
if ((HAL_GetTick() - tickstart) > PLL_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
@@ -286,10 +278,8 @@ HAL_StatusTypeDef HAL_RCC_DeInit(void)
|
||||
CLEAR_BIT(RCC->CR, RCC_CR_HSEON | RCC_CR_CSSON);
|
||||
|
||||
/* Wait till HSE is disabled */
|
||||
while (READ_BIT(RCC->CR, RCC_CR_HSERDY) != RESET)
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) > HSE_TIMEOUT_VALUE)
|
||||
{
|
||||
while (READ_BIT(RCC->CR, RCC_CR_HSERDY) != RESET) {
|
||||
if ((HAL_GetTick() - tickstart) > HSE_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
@@ -305,10 +295,8 @@ HAL_StatusTypeDef HAL_RCC_DeInit(void)
|
||||
CLEAR_BIT(RCC->CR, RCC_CR_PLL2ON);
|
||||
|
||||
/* Wait till PLL2 is disabled */
|
||||
while (READ_BIT(RCC->CR, RCC_CR_PLL2RDY) != RESET)
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) > PLL2_TIMEOUT_VALUE)
|
||||
{
|
||||
while (READ_BIT(RCC->CR, RCC_CR_PLL2RDY) != RESET) {
|
||||
if ((HAL_GetTick() - tickstart) > PLL2_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
@@ -322,10 +310,8 @@ HAL_StatusTypeDef HAL_RCC_DeInit(void)
|
||||
CLEAR_BIT(RCC->CR, RCC_CR_PLL3ON);
|
||||
|
||||
/* Wait till PLL3 is disabled */
|
||||
while (READ_BIT(RCC->CR, RCC_CR_PLL3RDY) != RESET)
|
||||
{
|
||||
if ((HAL_GetTick() - tickstart) > PLLI2S_TIMEOUT_VALUE)
|
||||
{
|
||||
while (READ_BIT(RCC->CR, RCC_CR_PLL3RDY) != RESET) {
|
||||
if ((HAL_GetTick() - tickstart) > PLLI2S_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
@@ -360,8 +346,7 @@ HAL_StatusTypeDef HAL_RCC_DeInit(void)
|
||||
* first and then HSE On or HSE Bypass.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct) {
|
||||
uint32_t tickstart = 0U;
|
||||
|
||||
/* Check the parameters */
|
||||
@@ -370,33 +355,26 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
||||
|
||||
/*------------------------------- HSE Configuration ------------------------*/
|
||||
/*----------------------------- HSI Configuration --------------------------*/
|
||||
if(((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI)
|
||||
{
|
||||
if (((RCC_OscInitStruct->OscillatorType) & RCC_OSCILLATORTYPE_HSI) == RCC_OSCILLATORTYPE_HSI) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_RCC_HSI(RCC_OscInitStruct->HSIState));
|
||||
assert_param(IS_RCC_CALIBRATION_VALUE(RCC_OscInitStruct->HSICalibrationValue));
|
||||
|
||||
/* Check if HSI is used as system clock or as PLL source when PLL is selected as system clock */
|
||||
if ((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_HSI)
|
||||
|| ((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK) && (__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSI_DIV2)))
|
||||
{
|
||||
|| ((__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK) && (__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSI_DIV2))) {
|
||||
/* When HSI is used as system clock it will not disabled */
|
||||
if((__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != RESET) && (RCC_OscInitStruct->HSIState != RCC_HSI_ON))
|
||||
{
|
||||
if ((__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != RESET) && (RCC_OscInitStruct->HSIState != RCC_HSI_ON)) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
/* Otherwise, just the calibration is allowed */
|
||||
else
|
||||
{
|
||||
else {
|
||||
/* Adjusts the Internal High Speed oscillator (HSI) calibration value.*/
|
||||
__HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->HSICalibrationValue);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Check the HSI State */
|
||||
if(RCC_OscInitStruct->HSIState != RCC_HSI_OFF)
|
||||
{
|
||||
if (RCC_OscInitStruct->HSIState != RCC_HSI_OFF) {
|
||||
/* Enable the Internal High Speed oscillator (HSI). */
|
||||
__HAL_RCC_HSI_ENABLE();
|
||||
|
||||
@@ -404,19 +382,15 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait till HSI is ready */
|
||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == RESET)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart ) > HSI_TIMEOUT_VALUE)
|
||||
{
|
||||
while (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == RESET) {
|
||||
if ((HAL_GetTick() - tickstart) > HSI_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
/* Adjusts the Internal High Speed oscillator (HSI) calibration value.*/
|
||||
__HAL_RCC_HSI_CALIBRATIONVALUE_ADJUST(RCC_OscInitStruct->HSICalibrationValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Disable the Internal High Speed oscillator (HSI). */
|
||||
__HAL_RCC_HSI_DISABLE();
|
||||
|
||||
@@ -424,10 +398,8 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait till HSI is disabled */
|
||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != RESET)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart ) > HSI_TIMEOUT_VALUE)
|
||||
{
|
||||
while (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) != RESET) {
|
||||
if ((HAL_GetTick() - tickstart) > HSI_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
@@ -438,34 +410,25 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
||||
|
||||
/*------------------------------ LSE Configuration -------------------------*/
|
||||
|
||||
|
||||
#if defined(RCC_CR_PLL2ON)
|
||||
/*-------------------------------- PLL2 Configuration -----------------------*/
|
||||
/* Check the parameters */
|
||||
assert_param(IS_RCC_PLL2(RCC_OscInitStruct->PLL2.PLL2State));
|
||||
if ((RCC_OscInitStruct->PLL2.PLL2State) != RCC_PLL2_NONE)
|
||||
{
|
||||
if ((RCC_OscInitStruct->PLL2.PLL2State) != RCC_PLL2_NONE) {
|
||||
/* This bit can not be cleared if the PLL2 clock is used indirectly as system
|
||||
clock (i.e. it is used as PLL clock entry that is used as system clock). */
|
||||
if((__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSE) && \
|
||||
(__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK) && \
|
||||
((READ_BIT(RCC->CFGR2,RCC_CFGR2_PREDIV1SRC)) == RCC_CFGR2_PREDIV1SRC_PLL2))
|
||||
{
|
||||
if ((__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSE) && (__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK)
|
||||
&& ((READ_BIT(RCC->CFGR2, RCC_CFGR2_PREDIV1SRC)) == RCC_CFGR2_PREDIV1SRC_PLL2)) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
if((RCC_OscInitStruct->PLL2.PLL2State) == RCC_PLL2_ON)
|
||||
{
|
||||
} else {
|
||||
if ((RCC_OscInitStruct->PLL2.PLL2State) == RCC_PLL2_ON) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_RCC_PLL2_MUL(RCC_OscInitStruct->PLL2.PLL2MUL));
|
||||
assert_param(IS_RCC_HSE_PREDIV2(RCC_OscInitStruct->PLL2.HSEPrediv2Value));
|
||||
|
||||
/* Prediv2 can be written only when the PLLI2S is disabled. */
|
||||
/* Return an error only if new value is different from the programmed value */
|
||||
if (HAL_IS_BIT_SET(RCC->CR,RCC_CR_PLL3ON) && \
|
||||
(__HAL_RCC_HSE_GET_PREDIV2() != RCC_OscInitStruct->PLL2.HSEPrediv2Value))
|
||||
{
|
||||
if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3ON) && (__HAL_RCC_HSE_GET_PREDIV2() != RCC_OscInitStruct->PLL2.HSEPrediv2Value)) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
@@ -476,10 +439,8 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait till PLL2 is disabled */
|
||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) != RESET)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart ) > PLL2_TIMEOUT_VALUE)
|
||||
{
|
||||
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) != RESET) {
|
||||
if ((HAL_GetTick() - tickstart) > PLL2_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
@@ -497,16 +458,12 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait till PLL2 is ready */
|
||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) == RESET)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart ) > PLL2_TIMEOUT_VALUE)
|
||||
{
|
||||
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) == RESET) {
|
||||
if ((HAL_GetTick() - tickstart) > PLL2_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Set PREDIV1 source to HSE */
|
||||
CLEAR_BIT(RCC->CFGR2, RCC_CFGR2_PREDIV1SRC);
|
||||
|
||||
@@ -517,10 +474,8 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait till PLL2 is disabled */
|
||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) != RESET)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart ) > PLL2_TIMEOUT_VALUE)
|
||||
{
|
||||
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) != RESET) {
|
||||
if ((HAL_GetTick() - tickstart) > PLL2_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
@@ -532,13 +487,10 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
||||
/*-------------------------------- PLL Configuration -----------------------*/
|
||||
/* Check the parameters */
|
||||
assert_param(IS_RCC_PLL(RCC_OscInitStruct->PLL.PLLState));
|
||||
if ((RCC_OscInitStruct->PLL.PLLState) != RCC_PLL_NONE)
|
||||
{
|
||||
if ((RCC_OscInitStruct->PLL.PLLState) != RCC_PLL_NONE) {
|
||||
/* Check if the PLL is used as system clock or not */
|
||||
if(__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_PLLCLK)
|
||||
{
|
||||
if((RCC_OscInitStruct->PLL.PLLState) == RCC_PLL_ON)
|
||||
{
|
||||
if (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_PLLCLK) {
|
||||
if ((RCC_OscInitStruct->PLL.PLLState) == RCC_PLL_ON) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_RCC_PLLSOURCE(RCC_OscInitStruct->PLL.PLLSource));
|
||||
assert_param(IS_RCC_PLL_MUL(RCC_OscInitStruct->PLL.PLLMUL));
|
||||
@@ -550,18 +502,15 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait till PLL is disabled */
|
||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
|
||||
{
|
||||
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET) {
|
||||
if ((HAL_GetTick() - tickstart) > PLL_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
/* Configure the HSE prediv factor --------------------------------*/
|
||||
/* It can be written only when the PLL is disabled. Not used in PLL source is different than HSE */
|
||||
if(RCC_OscInitStruct->PLL.PLLSource == RCC_PLLSOURCE_HSE)
|
||||
{
|
||||
if (RCC_OscInitStruct->PLL.PLLSource == RCC_PLLSOURCE_HSE) {
|
||||
/* Check the parameter */
|
||||
assert_param(IS_RCC_HSE_PREDIV(RCC_OscInitStruct->HSEPredivValue));
|
||||
#if defined(RCC_CFGR2_PREDIV1SRC)
|
||||
@@ -576,8 +525,7 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
||||
}
|
||||
|
||||
/* Configure the main PLL clock source and multiplication factors. */
|
||||
__HAL_RCC_PLL_CONFIG(RCC_OscInitStruct->PLL.PLLSource,
|
||||
RCC_OscInitStruct->PLL.PLLMUL);
|
||||
__HAL_RCC_PLL_CONFIG(RCC_OscInitStruct->PLL.PLLSource, RCC_OscInitStruct->PLL.PLLMUL);
|
||||
/* Enable the main PLL. */
|
||||
__HAL_RCC_PLL_ENABLE();
|
||||
|
||||
@@ -585,16 +533,12 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait till PLL is ready */
|
||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
|
||||
{
|
||||
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET) {
|
||||
if ((HAL_GetTick() - tickstart) > PLL_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Disable the main PLL. */
|
||||
__HAL_RCC_PLL_DISABLE();
|
||||
|
||||
@@ -602,17 +546,13 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait till PLL is disabled */
|
||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart ) > PLL_TIMEOUT_VALUE)
|
||||
{
|
||||
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) != RESET) {
|
||||
if ((HAL_GetTick() - tickstart) > PLL_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -643,8 +583,7 @@ HAL_StatusTypeDef HAL_RCC_OscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
||||
* currently used as system clock source.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t FLatency) {
|
||||
uint32_t tickstart = 0U;
|
||||
|
||||
/* Check the parameters */
|
||||
@@ -658,32 +597,27 @@ HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, ui
|
||||
|
||||
#if defined(FLASH_ACR_LATENCY)
|
||||
/* Increasing the number of wait states because of higher CPU frequency */
|
||||
if(FLatency > (FLASH->ACR & FLASH_ACR_LATENCY))
|
||||
{
|
||||
if (FLatency > (FLASH->ACR & FLASH_ACR_LATENCY)) {
|
||||
/* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
|
||||
__HAL_FLASH_SET_LATENCY(FLatency);
|
||||
|
||||
/* Check that the new number of wait states is taken into account to access the Flash
|
||||
memory by reading the FLASH_ACR register */
|
||||
if((FLASH->ACR & FLASH_ACR_LATENCY) != FLatency)
|
||||
{
|
||||
if ((FLASH->ACR & FLASH_ACR_LATENCY) != FLatency) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* FLASH_ACR_LATENCY */
|
||||
/*-------------------------- HCLK Configuration --------------------------*/
|
||||
if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_HCLK) == RCC_CLOCKTYPE_HCLK)
|
||||
{
|
||||
if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_HCLK) == RCC_CLOCKTYPE_HCLK) {
|
||||
/* Set the highest APBx dividers in order to ensure that we do not go through
|
||||
a non-spec phase whatever we decrease or increase HCLK. */
|
||||
if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1)
|
||||
{
|
||||
if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1) {
|
||||
MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE1, RCC_HCLK_DIV16);
|
||||
}
|
||||
|
||||
if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK2) == RCC_CLOCKTYPE_PCLK2)
|
||||
{
|
||||
if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK2) == RCC_CLOCKTYPE_PCLK2) {
|
||||
MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE2, (RCC_HCLK_DIV16 << 3));
|
||||
}
|
||||
|
||||
@@ -693,34 +627,27 @@ HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, ui
|
||||
}
|
||||
|
||||
/*------------------------- SYSCLK Configuration ---------------------------*/
|
||||
if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_SYSCLK) == RCC_CLOCKTYPE_SYSCLK)
|
||||
{
|
||||
if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_SYSCLK) == RCC_CLOCKTYPE_SYSCLK) {
|
||||
assert_param(IS_RCC_SYSCLKSOURCE(RCC_ClkInitStruct->SYSCLKSource));
|
||||
|
||||
/* HSE is selected as System Clock Source */
|
||||
if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_HSE)
|
||||
{
|
||||
if (RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_HSE) {
|
||||
/* Check the HSE ready flag */
|
||||
if(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET)
|
||||
{
|
||||
if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
/* PLL is selected as System Clock Source */
|
||||
else if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_PLLCLK)
|
||||
{
|
||||
else if (RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_PLLCLK) {
|
||||
/* Check the PLL ready flag */
|
||||
if(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET)
|
||||
{
|
||||
if (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
/* HSI is selected as System Clock Source */
|
||||
else
|
||||
{
|
||||
else {
|
||||
/* Check the HSI ready flag */
|
||||
if(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == RESET)
|
||||
{
|
||||
if (__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == RESET) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -729,32 +656,21 @@ HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, ui
|
||||
/* Get Start Tick */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_HSE)
|
||||
{
|
||||
while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_HSE)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart ) > CLOCKSWITCH_TIMEOUT_VALUE)
|
||||
{
|
||||
if (RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_HSE) {
|
||||
while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_HSE) {
|
||||
if ((HAL_GetTick() - tickstart) > CLOCKSWITCH_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_PLLCLK)
|
||||
{
|
||||
while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_PLLCLK)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart ) > CLOCKSWITCH_TIMEOUT_VALUE)
|
||||
{
|
||||
} else if (RCC_ClkInitStruct->SYSCLKSource == RCC_SYSCLKSOURCE_PLLCLK) {
|
||||
while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_PLLCLK) {
|
||||
if ((HAL_GetTick() - tickstart) > CLOCKSWITCH_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_HSI)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart ) > CLOCKSWITCH_TIMEOUT_VALUE)
|
||||
{
|
||||
} else {
|
||||
while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_HSI) {
|
||||
if ((HAL_GetTick() - tickstart) > CLOCKSWITCH_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
@@ -762,30 +678,26 @@ HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, ui
|
||||
}
|
||||
#if defined(FLASH_ACR_LATENCY)
|
||||
/* Decreasing the number of wait states because of lower CPU frequency */
|
||||
if(FLatency < (FLASH->ACR & FLASH_ACR_LATENCY))
|
||||
{
|
||||
if (FLatency < (FLASH->ACR & FLASH_ACR_LATENCY)) {
|
||||
/* Program the new number of wait states to the LATENCY bits in the FLASH_ACR register */
|
||||
__HAL_FLASH_SET_LATENCY(FLatency);
|
||||
|
||||
/* Check that the new number of wait states is taken into account to access the Flash
|
||||
memory by reading the FLASH_ACR register */
|
||||
if((FLASH->ACR & FLASH_ACR_LATENCY) != FLatency)
|
||||
{
|
||||
if ((FLASH->ACR & FLASH_ACR_LATENCY) != FLatency) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
#endif /* FLASH_ACR_LATENCY */
|
||||
|
||||
/*-------------------------- PCLK1 Configuration ---------------------------*/
|
||||
if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1)
|
||||
{
|
||||
if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK1) == RCC_CLOCKTYPE_PCLK1) {
|
||||
assert_param(IS_RCC_PCLK(RCC_ClkInitStruct->APB1CLKDivider));
|
||||
MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE1, RCC_ClkInitStruct->APB1CLKDivider);
|
||||
}
|
||||
|
||||
/*-------------------------- PCLK2 Configuration ---------------------------*/
|
||||
if(((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK2) == RCC_CLOCKTYPE_PCLK2)
|
||||
{
|
||||
if (((RCC_ClkInitStruct->ClockType) & RCC_CLOCKTYPE_PCLK2) == RCC_CLOCKTYPE_PCLK2) {
|
||||
assert_param(IS_RCC_PCLK(RCC_ClkInitStruct->APB2CLKDivider));
|
||||
MODIFY_REG(RCC->CFGR, RCC_CFGR_PPRE2, ((RCC_ClkInitStruct->APB2CLKDivider) << 3));
|
||||
}
|
||||
@@ -849,8 +761,7 @@ HAL_StatusTypeDef HAL_RCC_ClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, ui
|
||||
* @arg @ref RCC_MCODIV_1 no division applied to MCO clock
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv)
|
||||
{
|
||||
void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_MCODiv) {
|
||||
GPIO_InitTypeDef gpio = {0U};
|
||||
|
||||
/* Check the parameters */
|
||||
@@ -886,19 +797,13 @@ void HAL_RCC_MCOConfig(uint32_t RCC_MCOx, uint32_t RCC_MCOSource, uint32_t RCC_M
|
||||
* the Cortex-M3 NMI (Non-Maskable Interrupt) exception vector.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_RCC_EnableCSS(void)
|
||||
{
|
||||
*(__IO uint32_t *) RCC_CR_CSSON_BB = (uint32_t)ENABLE;
|
||||
}
|
||||
void HAL_RCC_EnableCSS(void) { *(__IO uint32_t *)RCC_CR_CSSON_BB = (uint32_t)ENABLE; }
|
||||
|
||||
/**
|
||||
* @brief Disables the Clock Security System.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_RCC_DisableCSS(void)
|
||||
{
|
||||
*(__IO uint32_t *) RCC_CR_CSSON_BB = (uint32_t)DISABLE;
|
||||
}
|
||||
void HAL_RCC_DisableCSS(void) { *(__IO uint32_t *)RCC_CR_CSSON_BB = (uint32_t)DISABLE; }
|
||||
|
||||
/**
|
||||
* @brief Returns the SYSCLK frequency
|
||||
@@ -929,8 +834,7 @@ void HAL_RCC_DisableCSS(void)
|
||||
*
|
||||
* @retval SYSCLK frequency
|
||||
*/
|
||||
uint32_t HAL_RCC_GetSysClockFreq(void)
|
||||
{
|
||||
uint32_t HAL_RCC_GetSysClockFreq(void) {
|
||||
#if defined(RCC_CFGR2_PREDIV1SRC)
|
||||
const uint8_t aPLLMULFactorTable[14] = {0, 0, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 13};
|
||||
const uint8_t aPredivFactorTable[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
|
||||
@@ -952,8 +856,7 @@ uint32_t HAL_RCC_GetSysClockFreq(void)
|
||||
tmpreg = RCC->CFGR;
|
||||
|
||||
/* Get SYSCLK source -------------------------------------------------------*/
|
||||
switch (tmpreg & RCC_CFGR_SWS)
|
||||
{
|
||||
switch (tmpreg & RCC_CFGR_SWS) {
|
||||
case RCC_SYSCLKSOURCE_STATUS_HSE: /* HSE used as system clock */
|
||||
{
|
||||
sysclockfreq = HSE_VALUE;
|
||||
@@ -962,8 +865,7 @@ uint32_t HAL_RCC_GetSysClockFreq(void)
|
||||
case RCC_SYSCLKSOURCE_STATUS_PLLCLK: /* PLL used as system clock */
|
||||
{
|
||||
pllmul = aPLLMULFactorTable[(uint32_t)(tmpreg & RCC_CFGR_PLLMULL) >> RCC_CFGR_PLLMULL_Pos];
|
||||
if ((tmpreg & RCC_CFGR_PLLSRC) != RCC_PLLSOURCE_HSI_DIV2)
|
||||
{
|
||||
if ((tmpreg & RCC_CFGR_PLLSRC) != RCC_PLLSOURCE_HSI_DIV2) {
|
||||
#if defined(RCC_CFGR2_PREDIV1)
|
||||
prediv = aPredivFactorTable[(uint32_t)(RCC->CFGR2 & RCC_CFGR2_PREDIV1) >> RCC_CFGR2_PREDIV1_Pos];
|
||||
#else
|
||||
@@ -971,33 +873,27 @@ uint32_t HAL_RCC_GetSysClockFreq(void)
|
||||
#endif /*RCC_CFGR2_PREDIV1*/
|
||||
#if defined(RCC_CFGR2_PREDIV1SRC)
|
||||
|
||||
if(HAL_IS_BIT_SET(RCC->CFGR2, RCC_CFGR2_PREDIV1SRC))
|
||||
{
|
||||
if (HAL_IS_BIT_SET(RCC->CFGR2, RCC_CFGR2_PREDIV1SRC)) {
|
||||
/* PLL2 selected as Prediv1 source */
|
||||
/* PLLCLK = PLL2CLK / PREDIV1 * PLLMUL with PLL2CLK = HSE/PREDIV2 * PLL2MUL */
|
||||
prediv2 = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> RCC_CFGR2_PREDIV2_Pos) + 1;
|
||||
pll2mul = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> RCC_CFGR2_PLL2MUL_Pos) + 2;
|
||||
pllclk = (uint32_t)(((uint64_t)HSE_VALUE * (uint64_t)pll2mul * (uint64_t)pllmul) / ((uint64_t)prediv2 * (uint64_t)prediv));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* HSE used as PLL clock source : PLLCLK = HSE/PREDIV1 * PLLMUL */
|
||||
pllclk = (uint32_t)((HSE_VALUE * pllmul) / prediv);
|
||||
}
|
||||
|
||||
/* If PLLMUL was set to 13 means that it was to cover the case PLLMUL 6.5 (avoid using float) */
|
||||
/* In this case need to divide pllclk by 2 */
|
||||
if (pllmul == aPLLMULFactorTable[(uint32_t)(RCC_CFGR_PLLMULL6_5) >> RCC_CFGR_PLLMULL_Pos])
|
||||
{
|
||||
if (pllmul == aPLLMULFactorTable[(uint32_t)(RCC_CFGR_PLLMULL6_5) >> RCC_CFGR_PLLMULL_Pos]) {
|
||||
pllclk = pllclk / 2;
|
||||
}
|
||||
#else
|
||||
/* HSE used as PLL clock source : PLLCLK = HSE/PREDIV1 * PLLMUL */
|
||||
pllclk = (uint32_t)((HSE_VALUE * pllmul) / prediv);
|
||||
#endif /*RCC_CFGR2_PREDIV1SRC*/
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* HSI used as PLL clock source : PLLCLK = HSI/2 * PLLMUL */
|
||||
pllclk = (uint32_t)((HSI_VALUE >> 1) * pllmul);
|
||||
}
|
||||
@@ -1023,10 +919,7 @@ uint32_t HAL_RCC_GetSysClockFreq(void)
|
||||
* and updated within this function
|
||||
* @retval HCLK frequency
|
||||
*/
|
||||
uint32_t HAL_RCC_GetHCLKFreq(void)
|
||||
{
|
||||
return SystemCoreClock;
|
||||
}
|
||||
uint32_t HAL_RCC_GetHCLKFreq(void) { return SystemCoreClock; }
|
||||
|
||||
/**
|
||||
* @brief Returns the PCLK1 frequency
|
||||
@@ -1034,8 +927,7 @@ uint32_t HAL_RCC_GetHCLKFreq(void)
|
||||
* right PCLK1 value. Otherwise, any configuration based on this function will be incorrect.
|
||||
* @retval PCLK1 frequency
|
||||
*/
|
||||
uint32_t HAL_RCC_GetPCLK1Freq(void)
|
||||
{
|
||||
uint32_t HAL_RCC_GetPCLK1Freq(void) {
|
||||
/* Get HCLK source and Compute PCLK1 frequency ---------------------------*/
|
||||
return (HAL_RCC_GetHCLKFreq() >> APBPrescTable[(RCC->CFGR & RCC_CFGR_PPRE1) >> RCC_CFGR_PPRE1_Pos]);
|
||||
}
|
||||
@@ -1046,8 +938,7 @@ uint32_t HAL_RCC_GetPCLK1Freq(void)
|
||||
* right PCLK2 value. Otherwise, any configuration based on this function will be incorrect.
|
||||
* @retval PCLK2 frequency
|
||||
*/
|
||||
uint32_t HAL_RCC_GetPCLK2Freq(void)
|
||||
{
|
||||
uint32_t HAL_RCC_GetPCLK2Freq(void) {
|
||||
/* Get HCLK source and Compute PCLK2 frequency ---------------------------*/
|
||||
return (HAL_RCC_GetHCLKFreq() >> APBPrescTable[(RCC->CFGR & RCC_CFGR_PPRE2) >> RCC_CFGR_PPRE2_Pos]);
|
||||
}
|
||||
@@ -1059,14 +950,12 @@ uint32_t HAL_RCC_GetPCLK2Freq(void)
|
||||
* will be configured.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
||||
{
|
||||
void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct) {
|
||||
/* Check the parameters */
|
||||
assert_param(RCC_OscInitStruct != NULL);
|
||||
|
||||
/* Set all possible values for the Oscillator type parameter ---------------*/
|
||||
RCC_OscInitStruct->OscillatorType = RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_HSI \
|
||||
| RCC_OSCILLATORTYPE_LSE | RCC_OSCILLATORTYPE_LSI;
|
||||
RCC_OscInitStruct->OscillatorType = RCC_OSCILLATORTYPE_HSE | RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_LSE | RCC_OSCILLATORTYPE_LSI;
|
||||
|
||||
#if defined(RCC_CFGR2_PREDIV1SRC)
|
||||
/* Get the Prediv1 source --------------------------------------------------*/
|
||||
@@ -1074,76 +963,53 @@ void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
||||
#endif /* RCC_CFGR2_PREDIV1SRC */
|
||||
|
||||
/* Get the HSE configuration -----------------------------------------------*/
|
||||
if((RCC->CR &RCC_CR_HSEBYP) == RCC_CR_HSEBYP)
|
||||
{
|
||||
if ((RCC->CR & RCC_CR_HSEBYP) == RCC_CR_HSEBYP) {
|
||||
RCC_OscInitStruct->HSEState = RCC_HSE_BYPASS;
|
||||
}
|
||||
else if((RCC->CR &RCC_CR_HSEON) == RCC_CR_HSEON)
|
||||
{
|
||||
} else if ((RCC->CR & RCC_CR_HSEON) == RCC_CR_HSEON) {
|
||||
RCC_OscInitStruct->HSEState = RCC_HSE_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
RCC_OscInitStruct->HSEState = RCC_HSE_OFF;
|
||||
}
|
||||
RCC_OscInitStruct->HSEPredivValue = __HAL_RCC_HSE_GET_PREDIV();
|
||||
|
||||
/* Get the HSI configuration -----------------------------------------------*/
|
||||
if((RCC->CR &RCC_CR_HSION) == RCC_CR_HSION)
|
||||
{
|
||||
if ((RCC->CR & RCC_CR_HSION) == RCC_CR_HSION) {
|
||||
RCC_OscInitStruct->HSIState = RCC_HSI_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
RCC_OscInitStruct->HSIState = RCC_HSI_OFF;
|
||||
}
|
||||
|
||||
RCC_OscInitStruct->HSICalibrationValue = (uint32_t)((RCC->CR & RCC_CR_HSITRIM) >> RCC_CR_HSITRIM_Pos);
|
||||
|
||||
/* Get the LSE configuration -----------------------------------------------*/
|
||||
if((RCC->BDCR &RCC_BDCR_LSEBYP) == RCC_BDCR_LSEBYP)
|
||||
{
|
||||
if ((RCC->BDCR & RCC_BDCR_LSEBYP) == RCC_BDCR_LSEBYP) {
|
||||
RCC_OscInitStruct->LSEState = RCC_LSE_BYPASS;
|
||||
}
|
||||
else if((RCC->BDCR &RCC_BDCR_LSEON) == RCC_BDCR_LSEON)
|
||||
{
|
||||
} else if ((RCC->BDCR & RCC_BDCR_LSEON) == RCC_BDCR_LSEON) {
|
||||
RCC_OscInitStruct->LSEState = RCC_LSE_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
RCC_OscInitStruct->LSEState = RCC_LSE_OFF;
|
||||
}
|
||||
|
||||
/* Get the LSI configuration -----------------------------------------------*/
|
||||
if((RCC->CSR &RCC_CSR_LSION) == RCC_CSR_LSION)
|
||||
{
|
||||
if ((RCC->CSR & RCC_CSR_LSION) == RCC_CSR_LSION) {
|
||||
RCC_OscInitStruct->LSIState = RCC_LSI_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
RCC_OscInitStruct->LSIState = RCC_LSI_OFF;
|
||||
}
|
||||
|
||||
|
||||
/* Get the PLL configuration -----------------------------------------------*/
|
||||
if((RCC->CR &RCC_CR_PLLON) == RCC_CR_PLLON)
|
||||
{
|
||||
if ((RCC->CR & RCC_CR_PLLON) == RCC_CR_PLLON) {
|
||||
RCC_OscInitStruct->PLL.PLLState = RCC_PLL_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
RCC_OscInitStruct->PLL.PLLState = RCC_PLL_OFF;
|
||||
}
|
||||
RCC_OscInitStruct->PLL.PLLSource = (uint32_t)(RCC->CFGR & RCC_CFGR_PLLSRC);
|
||||
RCC_OscInitStruct->PLL.PLLMUL = (uint32_t)(RCC->CFGR & RCC_CFGR_PLLMULL);
|
||||
#if defined(RCC_CR_PLL2ON)
|
||||
/* Get the PLL2 configuration -----------------------------------------------*/
|
||||
if((RCC->CR &RCC_CR_PLL2ON) == RCC_CR_PLL2ON)
|
||||
{
|
||||
if ((RCC->CR & RCC_CR_PLL2ON) == RCC_CR_PLL2ON) {
|
||||
RCC_OscInitStruct->PLL2.PLL2State = RCC_PLL2_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
RCC_OscInitStruct->PLL2.PLL2State = RCC_PLL2_OFF;
|
||||
}
|
||||
RCC_OscInitStruct->PLL2.HSEPrediv2Value = __HAL_RCC_HSE_GET_PREDIV2();
|
||||
@@ -1159,8 +1025,7 @@ void HAL_RCC_GetOscConfig(RCC_OscInitTypeDef *RCC_OscInitStruct)
|
||||
* @param pFLatency Pointer on the Flash Latency.
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency)
|
||||
{
|
||||
void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency) {
|
||||
/* Check the parameters */
|
||||
assert_param(RCC_ClkInitStruct != NULL);
|
||||
assert_param(pFLatency != NULL);
|
||||
@@ -1194,11 +1059,9 @@ void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pF
|
||||
* @note This API should be called under the NMI_Handler().
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_RCC_NMI_IRQHandler(void)
|
||||
{
|
||||
void HAL_RCC_NMI_IRQHandler(void) {
|
||||
/* Check RCC CSSF flag */
|
||||
if(__HAL_RCC_GET_IT(RCC_IT_CSS))
|
||||
{
|
||||
if (__HAL_RCC_GET_IT(RCC_IT_CSS)) {
|
||||
/* RCC Clock Security System interrupt user callback */
|
||||
HAL_RCC_CSSCallback();
|
||||
|
||||
@@ -1212,22 +1075,18 @@ void HAL_RCC_NMI_IRQHandler(void)
|
||||
* @param mdelay: specifies the delay time length, in milliseconds.
|
||||
* @retval None
|
||||
*/
|
||||
static void RCC_Delay(uint32_t mdelay)
|
||||
{
|
||||
static void RCC_Delay(uint32_t mdelay) {
|
||||
__IO uint32_t Delay = mdelay * (SystemCoreClock / 8U / 1000U);
|
||||
do
|
||||
{
|
||||
do {
|
||||
__NOP();
|
||||
}
|
||||
while (Delay --);
|
||||
} while (Delay--);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief RCC Clock Security System interrupt callback
|
||||
* @retval none
|
||||
*/
|
||||
__weak void HAL_RCC_CSSCallback(void)
|
||||
{
|
||||
__weak void HAL_RCC_CSSCallback(void) {
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
the HAL_RCC_CSSCallback could be implemented in the user file
|
||||
*/
|
||||
|
||||
@@ -113,8 +113,7 @@
|
||||
*
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit) {
|
||||
uint32_t tickstart = 0U, temp_reg = 0U;
|
||||
#if defined(STM32F105xC) || defined(STM32F107xC)
|
||||
uint32_t pllactive = 0U;
|
||||
@@ -124,8 +123,7 @@ HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClk
|
||||
assert_param(IS_RCC_PERIPHCLOCK(PeriphClkInit->PeriphClockSelection));
|
||||
|
||||
/*------------------------------- RTC/LCD Configuration ------------------------*/
|
||||
if ((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC))
|
||||
{
|
||||
if ((((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_RTC) == RCC_PERIPHCLK_RTC)) {
|
||||
/* check for RTC Parameters used to output RTCCLK */
|
||||
assert_param(IS_RCC_RTCCLKSOURCE(PeriphClkInit->RTCClockSelection));
|
||||
|
||||
@@ -134,24 +132,20 @@ HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClk
|
||||
/* As soon as function is called to change RTC clock source, activation of the
|
||||
power domain is done. */
|
||||
/* Requires to enable write access to Backup Domain of necessary */
|
||||
if(__HAL_RCC_PWR_IS_CLK_DISABLED())
|
||||
{
|
||||
if (__HAL_RCC_PWR_IS_CLK_DISABLED()) {
|
||||
__HAL_RCC_PWR_CLK_ENABLE();
|
||||
pwrclkchanged = SET;
|
||||
}
|
||||
|
||||
if(HAL_IS_BIT_CLR(PWR->CR, PWR_CR_DBP))
|
||||
{
|
||||
if (HAL_IS_BIT_CLR(PWR->CR, PWR_CR_DBP)) {
|
||||
/* Enable write access to Backup domain */
|
||||
SET_BIT(PWR->CR, PWR_CR_DBP);
|
||||
|
||||
/* Wait for Backup domain Write protection disable */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
while(HAL_IS_BIT_CLR(PWR->CR, PWR_CR_DBP))
|
||||
{
|
||||
if((HAL_GetTick() - tickstart) > RCC_DBP_TIMEOUT_VALUE)
|
||||
{
|
||||
while (HAL_IS_BIT_CLR(PWR->CR, PWR_CR_DBP)) {
|
||||
if ((HAL_GetTick() - tickstart) > RCC_DBP_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
@@ -159,8 +153,7 @@ HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClk
|
||||
|
||||
/* Reset the Backup domain only if the RTC Clock source selection is modified from reset value */
|
||||
temp_reg = (RCC->BDCR & RCC_BDCR_RTCSEL);
|
||||
if((temp_reg != 0x00000000U) && (temp_reg != (PeriphClkInit->RTCClockSelection & RCC_BDCR_RTCSEL)))
|
||||
{
|
||||
if ((temp_reg != 0x00000000U) && (temp_reg != (PeriphClkInit->RTCClockSelection & RCC_BDCR_RTCSEL))) {
|
||||
/* Store the content of BDCR register before the reset of Backup Domain */
|
||||
temp_reg = (RCC->BDCR & ~(RCC_BDCR_RTCSEL));
|
||||
/* RTC Clock selection can be changed only if the Backup Domain is reset */
|
||||
@@ -170,16 +163,13 @@ HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClk
|
||||
RCC->BDCR = temp_reg;
|
||||
|
||||
/* Wait for LSERDY if LSE was enabled */
|
||||
if (HAL_IS_BIT_SET(temp_reg, RCC_BDCR_LSEON))
|
||||
{
|
||||
if (HAL_IS_BIT_SET(temp_reg, RCC_BDCR_LSEON)) {
|
||||
/* Get Start Tick */
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait till LSE is ready */
|
||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart) > RCC_LSE_TIMEOUT_VALUE)
|
||||
{
|
||||
while (__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET) {
|
||||
if ((HAL_GetTick() - tickstart) > RCC_LSE_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
@@ -188,15 +178,13 @@ HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClk
|
||||
__HAL_RCC_RTC_CONFIG(PeriphClkInit->RTCClockSelection);
|
||||
|
||||
/* Require to disable power clock if necessary */
|
||||
if(pwrclkchanged == SET)
|
||||
{
|
||||
if (pwrclkchanged == SET) {
|
||||
__HAL_RCC_PWR_CLK_DISABLE();
|
||||
}
|
||||
}
|
||||
|
||||
/*------------------------------ ADC clock Configuration ------------------*/
|
||||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC)
|
||||
{
|
||||
if (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_ADC) == RCC_PERIPHCLK_ADC) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_RCC_ADCPLLCLK_DIV(PeriphClkInit->AdcClockSelection));
|
||||
|
||||
@@ -206,8 +194,7 @@ HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClk
|
||||
|
||||
#if defined(STM32F105xC) || defined(STM32F107xC)
|
||||
/*------------------------------ I2S2 Configuration ------------------------*/
|
||||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S2) == RCC_PERIPHCLK_I2S2)
|
||||
{
|
||||
if (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S2) == RCC_PERIPHCLK_I2S2) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_RCC_I2S2CLKSOURCE(PeriphClkInit->I2s2ClockSelection));
|
||||
|
||||
@@ -216,8 +203,7 @@ HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClk
|
||||
}
|
||||
|
||||
/*------------------------------ I2S3 Configuration ------------------------*/
|
||||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S3) == RCC_PERIPHCLK_I2S3)
|
||||
{
|
||||
if (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_I2S3) == RCC_PERIPHCLK_I2S3) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_RCC_I2S3CLKSOURCE(PeriphClkInit->I2s3ClockSelection));
|
||||
|
||||
@@ -227,27 +213,22 @@ HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClk
|
||||
|
||||
/*------------------------------ PLL I2S Configuration ----------------------*/
|
||||
/* Check that PLLI2S need to be enabled */
|
||||
if (HAL_IS_BIT_SET(RCC->CFGR2, RCC_CFGR2_I2S2SRC) || HAL_IS_BIT_SET(RCC->CFGR2, RCC_CFGR2_I2S3SRC))
|
||||
{
|
||||
if (HAL_IS_BIT_SET(RCC->CFGR2, RCC_CFGR2_I2S2SRC) || HAL_IS_BIT_SET(RCC->CFGR2, RCC_CFGR2_I2S3SRC)) {
|
||||
/* Update flag to indicate that PLL I2S should be active */
|
||||
pllactive = 1;
|
||||
}
|
||||
|
||||
/* Check if PLL I2S need to be enabled */
|
||||
if (pllactive == 1)
|
||||
{
|
||||
if (pllactive == 1) {
|
||||
/* Enable PLL I2S only if not active */
|
||||
if (HAL_IS_BIT_CLR(RCC->CR, RCC_CR_PLL3ON))
|
||||
{
|
||||
if (HAL_IS_BIT_CLR(RCC->CR, RCC_CR_PLL3ON)) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_RCC_PLLI2S_MUL(PeriphClkInit->PLLI2S.PLLI2SMUL));
|
||||
assert_param(IS_RCC_HSE_PREDIV2(PeriphClkInit->PLLI2S.HSEPrediv2Value));
|
||||
|
||||
/* Prediv2 can be written only when the PLL2 is disabled. */
|
||||
/* Return an error only if new value is different from the programmed value */
|
||||
if (HAL_IS_BIT_SET(RCC->CR,RCC_CR_PLL2ON) && \
|
||||
(__HAL_RCC_HSE_GET_PREDIV2() != PeriphClkInit->PLLI2S.HSEPrediv2Value))
|
||||
{
|
||||
if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL2ON) && (__HAL_RCC_HSE_GET_PREDIV2() != PeriphClkInit->PLLI2S.HSEPrediv2Value)) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
@@ -264,31 +245,23 @@ HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClk
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait till PLLI2S is ready */
|
||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) == RESET)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart ) > PLLI2S_TIMEOUT_VALUE)
|
||||
{
|
||||
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) == RESET) {
|
||||
if ((HAL_GetTick() - tickstart) > PLLI2S_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Return an error only if user wants to change the PLLI2SMUL whereas PLLI2S is active */
|
||||
if (READ_BIT(RCC->CFGR2, RCC_CFGR2_PLL3MUL) != PeriphClkInit->PLLI2S.PLLI2SMUL)
|
||||
{
|
||||
if (READ_BIT(RCC->CFGR2, RCC_CFGR2_PLL3MUL) != PeriphClkInit->PLLI2S.PLLI2SMUL) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* STM32F105xC || STM32F107xC */
|
||||
|
||||
#if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6)\
|
||||
|| defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG)\
|
||||
|| defined(STM32F105xC) || defined(STM32F107xC)
|
||||
#if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC)
|
||||
/*------------------------------ USB clock Configuration ------------------*/
|
||||
if(((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USB) == RCC_PERIPHCLK_USB)
|
||||
{
|
||||
if (((PeriphClkInit->PeriphClockSelection) & RCC_PERIPHCLK_USB) == RCC_PERIPHCLK_USB) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_RCC_USBPLLCLK_DIV(PeriphClkInit->UsbClockSelection));
|
||||
|
||||
@@ -307,8 +280,7 @@ HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClk
|
||||
* returns the configuration information for the Extended Peripherals clocks(RTC, I2S, ADC clocks).
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
|
||||
{
|
||||
void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit) {
|
||||
uint32_t srcclk = 0U;
|
||||
|
||||
/* Set all possible values for the extended clock type parameter------------*/
|
||||
@@ -345,9 +317,7 @@ void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
|
||||
|
||||
#endif /* STM32F103xE || STM32F103xG */
|
||||
|
||||
#if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6)\
|
||||
|| defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG)\
|
||||
|| defined(STM32F105xC) || defined(STM32F107xC)
|
||||
#if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC)
|
||||
/* Get the USB clock configuration -----------------------------------------*/
|
||||
PeriphClkInit->PeriphClockSelection |= RCC_PERIPHCLK_USB;
|
||||
PeriphClkInit->UsbClockSelection = __HAL_RCC_GET_USB_SOURCE();
|
||||
@@ -400,8 +370,7 @@ void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
|
||||
@endif
|
||||
* @retval Frequency in Hz (0: means that no available frequency for the peripheral)
|
||||
*/
|
||||
uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
|
||||
{
|
||||
uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk) {
|
||||
#if defined(STM32F105xC) || defined(STM32F107xC)
|
||||
const uint8_t aPLLMULFactorTable[14] = {0, 0, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 13};
|
||||
const uint8_t aPredivFactorTable[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
|
||||
@@ -409,8 +378,7 @@ uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
|
||||
uint32_t prediv1 = 0U, pllclk = 0U, pllmul = 0U;
|
||||
uint32_t pll2mul = 0U, pll3mul = 0U, prediv2 = 0U;
|
||||
#endif /* STM32F105xC || STM32F107xC */
|
||||
#if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6) || \
|
||||
defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||
#if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG)
|
||||
const uint8_t aPLLMULFactorTable[16] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 16};
|
||||
const uint8_t aPredivFactorTable[2] = {1, 2};
|
||||
|
||||
@@ -421,60 +389,46 @@ uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
|
||||
/* Check the parameters */
|
||||
assert_param(IS_RCC_PERIPHCLOCK(PeriphClk));
|
||||
|
||||
switch (PeriphClk)
|
||||
{
|
||||
#if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6)\
|
||||
|| defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG)\
|
||||
|| defined(STM32F105xC) || defined(STM32F107xC)
|
||||
case RCC_PERIPHCLK_USB:
|
||||
{
|
||||
switch (PeriphClk) {
|
||||
#if defined(STM32F102x6) || defined(STM32F102xB) || defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC)
|
||||
case RCC_PERIPHCLK_USB: {
|
||||
/* Get RCC configuration ------------------------------------------------------*/
|
||||
temp_reg = RCC->CFGR;
|
||||
|
||||
/* Check if PLL is enabled */
|
||||
if (HAL_IS_BIT_SET(RCC->CR,RCC_CR_PLLON))
|
||||
{
|
||||
if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLLON)) {
|
||||
pllmul = aPLLMULFactorTable[(uint32_t)(temp_reg & RCC_CFGR_PLLMULL) >> RCC_CFGR_PLLMULL_Pos];
|
||||
if ((temp_reg & RCC_CFGR_PLLSRC) != RCC_PLLSOURCE_HSI_DIV2)
|
||||
{
|
||||
#if defined(STM32F105xC) || defined(STM32F107xC) || defined(STM32F100xB)\
|
||||
|| defined(STM32F100xE)
|
||||
if ((temp_reg & RCC_CFGR_PLLSRC) != RCC_PLLSOURCE_HSI_DIV2) {
|
||||
#if defined(STM32F105xC) || defined(STM32F107xC) || defined(STM32F100xB) || defined(STM32F100xE)
|
||||
prediv1 = aPredivFactorTable[(uint32_t)(RCC->CFGR2 & RCC_CFGR2_PREDIV1) >> RCC_CFGR2_PREDIV1_Pos];
|
||||
#else
|
||||
prediv1 = aPredivFactorTable[(uint32_t)(RCC->CFGR & RCC_CFGR_PLLXTPRE) >> RCC_CFGR_PLLXTPRE_Pos];
|
||||
#endif /* STM32F105xC || STM32F107xC || STM32F100xB || STM32F100xE */
|
||||
|
||||
#if defined(STM32F105xC) || defined(STM32F107xC)
|
||||
if(HAL_IS_BIT_SET(RCC->CFGR2, RCC_CFGR2_PREDIV1SRC))
|
||||
{
|
||||
if (HAL_IS_BIT_SET(RCC->CFGR2, RCC_CFGR2_PREDIV1SRC)) {
|
||||
/* PLL2 selected as Prediv1 source */
|
||||
/* PLLCLK = PLL2CLK / PREDIV1 * PLLMUL with PLL2CLK = HSE/PREDIV2 * PLL2MUL */
|
||||
prediv2 = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> RCC_CFGR2_PREDIV2_Pos) + 1;
|
||||
pll2mul = ((RCC->CFGR2 & RCC_CFGR2_PLL2MUL) >> RCC_CFGR2_PLL2MUL_Pos) + 2;
|
||||
pllclk = (uint32_t)((((HSE_VALUE / prediv2) * pll2mul) / prediv1) * pllmul);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* HSE used as PLL clock source : PLLCLK = HSE/PREDIV1 * PLLMUL */
|
||||
pllclk = (uint32_t)((HSE_VALUE / prediv1) * pllmul);
|
||||
}
|
||||
|
||||
/* If PLLMUL was set to 13 means that it was to cover the case PLLMUL 6.5 (avoid using float) */
|
||||
/* In this case need to divide pllclk by 2 */
|
||||
if (pllmul == aPLLMULFactorTable[(uint32_t)(RCC_CFGR_PLLMULL6_5) >> RCC_CFGR_PLLMULL_Pos])
|
||||
{
|
||||
if (pllmul == aPLLMULFactorTable[(uint32_t)(RCC_CFGR_PLLMULL6_5) >> RCC_CFGR_PLLMULL_Pos]) {
|
||||
pllclk = pllclk / 2;
|
||||
}
|
||||
#else
|
||||
if ((temp_reg & RCC_CFGR_PLLSRC) != RCC_PLLSOURCE_HSI_DIV2)
|
||||
{
|
||||
if ((temp_reg & RCC_CFGR_PLLSRC) != RCC_PLLSOURCE_HSI_DIV2) {
|
||||
/* HSE used as PLL clock source : PLLCLK = HSE/PREDIV1 * PLLMUL */
|
||||
pllclk = (uint32_t)((HSE_VALUE / prediv1) * pllmul);
|
||||
}
|
||||
#endif /* STM32F105xC || STM32F107xC */
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* HSI used as PLL clock source : PLLCLK = HSI/2 * PLLMUL */
|
||||
pllclk = (uint32_t)((HSI_VALUE >> 1) * pllmul);
|
||||
}
|
||||
@@ -482,25 +436,19 @@ uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
|
||||
/* Calcul of the USB frequency*/
|
||||
#if defined(STM32F105xC) || defined(STM32F107xC)
|
||||
/* USBCLK = PLLVCO = (2 x PLLCLK) / USB prescaler */
|
||||
if (__HAL_RCC_GET_USB_SOURCE() == RCC_USBCLKSOURCE_PLL_DIV2)
|
||||
{
|
||||
if (__HAL_RCC_GET_USB_SOURCE() == RCC_USBCLKSOURCE_PLL_DIV2) {
|
||||
/* Prescaler of 2 selected for USB */
|
||||
frequency = pllclk;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Prescaler of 3 selected for USB */
|
||||
frequency = (2 * pllclk) / 3;
|
||||
}
|
||||
#else
|
||||
/* USBCLK = PLLCLK / USB prescaler */
|
||||
if (__HAL_RCC_GET_USB_SOURCE() == RCC_USBCLKSOURCE_PLL)
|
||||
{
|
||||
if (__HAL_RCC_GET_USB_SOURCE() == RCC_USBCLKSOURCE_PLL) {
|
||||
/* No prescaler selected for USB */
|
||||
frequency = pllclk;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Prescaler of 1.5 selected for USB */
|
||||
frequency = (pllclk * 2) / 3;
|
||||
}
|
||||
@@ -510,22 +458,17 @@ uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
|
||||
}
|
||||
#endif /* STM32F102x6 || STM32F102xB || STM32F103x6 || STM32F103xB || STM32F103xE || STM32F103xG || STM32F105xC || STM32F107xC */
|
||||
#if defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC)
|
||||
case RCC_PERIPHCLK_I2S2:
|
||||
{
|
||||
case RCC_PERIPHCLK_I2S2: {
|
||||
#if defined(STM32F103xE) || defined(STM32F103xG)
|
||||
/* SYSCLK used as source clock for I2S2 */
|
||||
frequency = HAL_RCC_GetSysClockFreq();
|
||||
#else
|
||||
if (__HAL_RCC_GET_I2S2_SOURCE() == RCC_I2S2CLKSOURCE_SYSCLK)
|
||||
{
|
||||
if (__HAL_RCC_GET_I2S2_SOURCE() == RCC_I2S2CLKSOURCE_SYSCLK) {
|
||||
/* SYSCLK used as source clock for I2S2 */
|
||||
frequency = HAL_RCC_GetSysClockFreq();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Check if PLLI2S is enabled */
|
||||
if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3ON))
|
||||
{
|
||||
if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3ON)) {
|
||||
/* PLLI2SVCO = 2 * PLLI2SCLK = 2 * (HSE/PREDIV2 * PLL3MUL) */
|
||||
prediv2 = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> RCC_CFGR2_PREDIV2_Pos) + 1;
|
||||
pll3mul = ((RCC->CFGR2 & RCC_CFGR2_PLL3MUL) >> RCC_CFGR2_PLL3MUL_Pos) + 2;
|
||||
@@ -535,22 +478,17 @@ uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
|
||||
#endif /* STM32F103xE || STM32F103xG */
|
||||
break;
|
||||
}
|
||||
case RCC_PERIPHCLK_I2S3:
|
||||
{
|
||||
case RCC_PERIPHCLK_I2S3: {
|
||||
#if defined(STM32F103xE) || defined(STM32F103xG)
|
||||
/* SYSCLK used as source clock for I2S3 */
|
||||
frequency = HAL_RCC_GetSysClockFreq();
|
||||
#else
|
||||
if (__HAL_RCC_GET_I2S3_SOURCE() == RCC_I2S3CLKSOURCE_SYSCLK)
|
||||
{
|
||||
if (__HAL_RCC_GET_I2S3_SOURCE() == RCC_I2S3CLKSOURCE_SYSCLK) {
|
||||
/* SYSCLK used as source clock for I2S3 */
|
||||
frequency = HAL_RCC_GetSysClockFreq();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Check if PLLI2S is enabled */
|
||||
if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3ON))
|
||||
{
|
||||
if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3ON)) {
|
||||
/* PLLI2SVCO = 2 * PLLI2SCLK = 2 * (HSE/PREDIV2 * PLL3MUL) */
|
||||
prediv2 = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> RCC_CFGR2_PREDIV2_Pos) + 1;
|
||||
pll3mul = ((RCC->CFGR2 & RCC_CFGR2_PLL3MUL) >> RCC_CFGR2_PLL3MUL_Pos) + 2;
|
||||
@@ -561,39 +499,31 @@ uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
|
||||
break;
|
||||
}
|
||||
#endif /* STM32F103xE || STM32F103xG || STM32F105xC || STM32F107xC */
|
||||
case RCC_PERIPHCLK_RTC:
|
||||
{
|
||||
case RCC_PERIPHCLK_RTC: {
|
||||
/* Get RCC BDCR configuration ------------------------------------------------------*/
|
||||
temp_reg = RCC->BDCR;
|
||||
|
||||
/* Check if LSE is ready if RTC clock selection is LSE */
|
||||
if (((temp_reg & RCC_BDCR_RTCSEL) == RCC_RTCCLKSOURCE_LSE) && (HAL_IS_BIT_SET(temp_reg, RCC_BDCR_LSERDY)))
|
||||
{
|
||||
if (((temp_reg & RCC_BDCR_RTCSEL) == RCC_RTCCLKSOURCE_LSE) && (HAL_IS_BIT_SET(temp_reg, RCC_BDCR_LSERDY))) {
|
||||
frequency = LSE_VALUE;
|
||||
}
|
||||
/* Check if LSI is ready if RTC clock selection is LSI */
|
||||
else if (((temp_reg & RCC_BDCR_RTCSEL) == RCC_RTCCLKSOURCE_LSI) && (HAL_IS_BIT_SET(RCC->CSR, RCC_CSR_LSIRDY)))
|
||||
{
|
||||
else if (((temp_reg & RCC_BDCR_RTCSEL) == RCC_RTCCLKSOURCE_LSI) && (HAL_IS_BIT_SET(RCC->CSR, RCC_CSR_LSIRDY))) {
|
||||
frequency = LSI_VALUE;
|
||||
}
|
||||
else if (((temp_reg & RCC_BDCR_RTCSEL) == RCC_RTCCLKSOURCE_HSE_DIV128) && (HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY)))
|
||||
{
|
||||
} else if (((temp_reg & RCC_BDCR_RTCSEL) == RCC_RTCCLKSOURCE_HSE_DIV128) && (HAL_IS_BIT_SET(RCC->CR, RCC_CR_HSERDY))) {
|
||||
frequency = HSE_VALUE / 128U;
|
||||
}
|
||||
/* Clock not enabled for RTC*/
|
||||
else
|
||||
{
|
||||
else {
|
||||
frequency = 0U;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RCC_PERIPHCLK_ADC:
|
||||
{
|
||||
case RCC_PERIPHCLK_ADC: {
|
||||
frequency = HAL_RCC_GetPCLK2Freq() / (((__HAL_RCC_GET_ADC_SOURCE() >> RCC_CFGR_ADCPRE_Pos) + 1) * 2);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -626,22 +556,18 @@ uint32_t HAL_RCCEx_GetPeriphCLKFreq(uint32_t PeriphClk)
|
||||
* @note The PLLI2S configuration not modified if used by I2S2 or I2S3 Interface.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_RCCEx_EnablePLLI2S(RCC_PLLI2SInitTypeDef *PLLI2SInit)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_RCCEx_EnablePLLI2S(RCC_PLLI2SInitTypeDef *PLLI2SInit) {
|
||||
uint32_t tickstart = 0U;
|
||||
|
||||
/* Check that PLL I2S has not been already enabled by I2S2 or I2S3*/
|
||||
if (HAL_IS_BIT_CLR(RCC->CFGR2, RCC_CFGR2_I2S2SRC) && HAL_IS_BIT_CLR(RCC->CFGR2, RCC_CFGR2_I2S3SRC))
|
||||
{
|
||||
if (HAL_IS_BIT_CLR(RCC->CFGR2, RCC_CFGR2_I2S2SRC) && HAL_IS_BIT_CLR(RCC->CFGR2, RCC_CFGR2_I2S3SRC)) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_RCC_PLLI2S_MUL(PLLI2SInit->PLLI2SMUL));
|
||||
assert_param(IS_RCC_HSE_PREDIV2(PLLI2SInit->HSEPrediv2Value));
|
||||
|
||||
/* Prediv2 can be written only when the PLL2 is disabled. */
|
||||
/* Return an error only if new value is different from the programmed value */
|
||||
if (HAL_IS_BIT_SET(RCC->CR,RCC_CR_PLL2ON) && \
|
||||
(__HAL_RCC_HSE_GET_PREDIV2() != PLLI2SInit->HSEPrediv2Value))
|
||||
{
|
||||
if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL2ON) && (__HAL_RCC_HSE_GET_PREDIV2() != PLLI2SInit->HSEPrediv2Value)) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
@@ -652,10 +578,8 @@ HAL_StatusTypeDef HAL_RCCEx_EnablePLLI2S(RCC_PLLI2SInitTypeDef *PLLI2SInit)
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait till PLLI2S is ready */
|
||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) != RESET)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart ) > PLLI2S_TIMEOUT_VALUE)
|
||||
{
|
||||
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) != RESET) {
|
||||
if ((HAL_GetTick() - tickstart) > PLLI2S_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
@@ -663,7 +587,6 @@ HAL_StatusTypeDef HAL_RCCEx_EnablePLLI2S(RCC_PLLI2SInitTypeDef *PLLI2SInit)
|
||||
/* Configure the HSE prediv2 factor --------------------------------*/
|
||||
__HAL_RCC_HSE_PREDIV2_CONFIG(PLLI2SInit->HSEPrediv2Value);
|
||||
|
||||
|
||||
/* Configure the main PLLI2S multiplication factors. */
|
||||
__HAL_RCC_PLLI2S_CONFIG(PLLI2SInit->PLLI2SMUL);
|
||||
|
||||
@@ -674,16 +597,12 @@ HAL_StatusTypeDef HAL_RCCEx_EnablePLLI2S(RCC_PLLI2SInitTypeDef *PLLI2SInit)
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait till PLLI2S is ready */
|
||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) == RESET)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart ) > PLLI2S_TIMEOUT_VALUE)
|
||||
{
|
||||
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) == RESET) {
|
||||
if ((HAL_GetTick() - tickstart) > PLLI2S_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* PLLI2S cannot be modified as already used by I2S2 or I2S3 */
|
||||
return HAL_ERROR;
|
||||
}
|
||||
@@ -696,13 +615,11 @@ HAL_StatusTypeDef HAL_RCCEx_EnablePLLI2S(RCC_PLLI2SInitTypeDef *PLLI2SInit)
|
||||
* @note PLLI2S is not disabled if used by I2S2 or I2S3 Interface.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_RCCEx_DisablePLLI2S(void)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_RCCEx_DisablePLLI2S(void) {
|
||||
uint32_t tickstart = 0U;
|
||||
|
||||
/* Disable PLL I2S as not requested by I2S2 or I2S3*/
|
||||
if (HAL_IS_BIT_CLR(RCC->CFGR2, RCC_CFGR2_I2S2SRC) && HAL_IS_BIT_CLR(RCC->CFGR2, RCC_CFGR2_I2S3SRC))
|
||||
{
|
||||
if (HAL_IS_BIT_CLR(RCC->CFGR2, RCC_CFGR2_I2S2SRC) && HAL_IS_BIT_CLR(RCC->CFGR2, RCC_CFGR2_I2S3SRC)) {
|
||||
/* Disable the main PLLI2S. */
|
||||
__HAL_RCC_PLLI2S_DISABLE();
|
||||
|
||||
@@ -710,16 +627,12 @@ HAL_StatusTypeDef HAL_RCCEx_DisablePLLI2S(void)
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait till PLLI2S is ready */
|
||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) != RESET)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart ) > PLLI2S_TIMEOUT_VALUE)
|
||||
{
|
||||
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLLI2SRDY) != RESET) {
|
||||
if ((HAL_GetTick() - tickstart) > PLLI2S_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* PLLI2S is currently used by I2S2 or I2S3. Cannot be disabled.*/
|
||||
return HAL_ERROR;
|
||||
}
|
||||
@@ -752,29 +665,22 @@ HAL_StatusTypeDef HAL_RCCEx_DisablePLLI2S(void)
|
||||
* @note The PLL2 configuration not modified if used indirectly as system clock.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_RCCEx_EnablePLL2(RCC_PLL2InitTypeDef *PLL2Init)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_RCCEx_EnablePLL2(RCC_PLL2InitTypeDef *PLL2Init) {
|
||||
uint32_t tickstart = 0U;
|
||||
|
||||
/* This bit can not be cleared if the PLL2 clock is used indirectly as system
|
||||
clock (i.e. it is used as PLL clock entry that is used as system clock). */
|
||||
if((__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSE) && \
|
||||
(__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK) && \
|
||||
((READ_BIT(RCC->CFGR2,RCC_CFGR2_PREDIV1SRC)) == RCC_CFGR2_PREDIV1SRC_PLL2))
|
||||
{
|
||||
if ((__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSE) && (__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK)
|
||||
&& ((READ_BIT(RCC->CFGR2, RCC_CFGR2_PREDIV1SRC)) == RCC_CFGR2_PREDIV1SRC_PLL2)) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_RCC_PLL2_MUL(PLL2Init->PLL2MUL));
|
||||
assert_param(IS_RCC_HSE_PREDIV2(PLL2Init->HSEPrediv2Value));
|
||||
|
||||
/* Prediv2 can be written only when the PLLI2S is disabled. */
|
||||
/* Return an error only if new value is different from the programmed value */
|
||||
if (HAL_IS_BIT_SET(RCC->CR,RCC_CR_PLL3ON) && \
|
||||
(__HAL_RCC_HSE_GET_PREDIV2() != PLL2Init->HSEPrediv2Value))
|
||||
{
|
||||
if (HAL_IS_BIT_SET(RCC->CR, RCC_CR_PLL3ON) && (__HAL_RCC_HSE_GET_PREDIV2() != PLL2Init->HSEPrediv2Value)) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
@@ -785,10 +691,8 @@ HAL_StatusTypeDef HAL_RCCEx_EnablePLL2(RCC_PLL2InitTypeDef *PLL2Init)
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait till PLL2 is disabled */
|
||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) != RESET)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart ) > PLL2_TIMEOUT_VALUE)
|
||||
{
|
||||
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) != RESET) {
|
||||
if ((HAL_GetTick() - tickstart) > PLL2_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
@@ -806,10 +710,8 @@ HAL_StatusTypeDef HAL_RCCEx_EnablePLL2(RCC_PLL2InitTypeDef *PLL2Init)
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait till PLL2 is ready */
|
||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) == RESET)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart ) > PLL2_TIMEOUT_VALUE)
|
||||
{
|
||||
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) == RESET) {
|
||||
if ((HAL_GetTick() - tickstart) > PLL2_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
@@ -823,20 +725,15 @@ HAL_StatusTypeDef HAL_RCCEx_EnablePLL2(RCC_PLL2InitTypeDef *PLL2Init)
|
||||
* @note PLL2 is not disabled if used indirectly as system clock.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_RCCEx_DisablePLL2(void)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_RCCEx_DisablePLL2(void) {
|
||||
uint32_t tickstart = 0U;
|
||||
|
||||
/* This bit can not be cleared if the PLL2 clock is used indirectly as system
|
||||
clock (i.e. it is used as PLL clock entry that is used as system clock). */
|
||||
if((__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSE) && \
|
||||
(__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK) && \
|
||||
((READ_BIT(RCC->CFGR2,RCC_CFGR2_PREDIV1SRC)) == RCC_CFGR2_PREDIV1SRC_PLL2))
|
||||
{
|
||||
if ((__HAL_RCC_GET_PLL_OSCSOURCE() == RCC_PLLSOURCE_HSE) && (__HAL_RCC_GET_SYSCLK_SOURCE() == RCC_SYSCLKSOURCE_STATUS_PLLCLK)
|
||||
&& ((READ_BIT(RCC->CFGR2, RCC_CFGR2_PREDIV1SRC)) == RCC_CFGR2_PREDIV1SRC_PLL2)) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Disable the main PLL2. */
|
||||
__HAL_RCC_PLL2_DISABLE();
|
||||
|
||||
@@ -844,10 +741,8 @@ HAL_StatusTypeDef HAL_RCCEx_DisablePLL2(void)
|
||||
tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait till PLL2 is disabled */
|
||||
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) != RESET)
|
||||
{
|
||||
if((HAL_GetTick() - tickstart ) > PLL2_TIMEOUT_VALUE)
|
||||
{
|
||||
while (__HAL_RCC_GET_FLAG(RCC_FLAG_PLL2RDY) != RESET) {
|
||||
if ((HAL_GetTick() - tickstart) > PLL2_TIMEOUT_VALUE) {
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
}
|
||||
@@ -876,4 +771,3 @@ HAL_StatusTypeDef HAL_RCCEx_DisablePLL2(void)
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -114,9 +114,7 @@
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
|
||||
#if defined (STM32F100xB) || defined (STM32F100xE) || \
|
||||
defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F103xE) || defined (STM32F103xG) || \
|
||||
defined (STM32F105xC) || defined (STM32F107xC)
|
||||
#if defined(STM32F100xB) || defined(STM32F100xE) || defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC)
|
||||
/** @defgroup TIMEx_Private_Functions TIMEx Private Functions
|
||||
* @{
|
||||
*/
|
||||
@@ -134,7 +132,6 @@ static void TIM_CCxNChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t Cha
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup TIMEx_Exported_Functions_Group1 Timer Hall Sensor functions
|
||||
* @brief Timer Hall Sensor functions
|
||||
*
|
||||
@@ -162,13 +159,11 @@ static void TIM_CCxNChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t Cha
|
||||
* @param sConfig : TIM Hall Sensor configuration structure
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSensor_InitTypeDef* sConfig)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSensor_InitTypeDef *sConfig) {
|
||||
TIM_OC_InitTypeDef OC_Config;
|
||||
|
||||
/* Check the TIM handle allocation */
|
||||
if(htim == NULL)
|
||||
{
|
||||
if (htim == NULL) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
@@ -180,8 +175,7 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSen
|
||||
assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler));
|
||||
assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter));
|
||||
|
||||
if(htim->State == HAL_TIM_STATE_RESET)
|
||||
{
|
||||
if (htim->State == HAL_TIM_STATE_RESET) {
|
||||
/* Allocate lock resource and initialize it */
|
||||
htim->Lock = HAL_UNLOCKED;
|
||||
|
||||
@@ -241,8 +235,7 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSen
|
||||
* @param htim : TIM Hall Sensor handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_INSTANCE(htim->Instance));
|
||||
|
||||
@@ -268,8 +261,7 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim)
|
||||
* @param htim : TIM handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
__weak void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim) {
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(htim);
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
@@ -282,8 +274,7 @@ __weak void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim)
|
||||
* @param htim : TIM handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
__weak void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim) {
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(htim);
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
@@ -296,8 +287,7 @@ __weak void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim)
|
||||
* @param htim : TIM Hall Sensor handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
|
||||
|
||||
@@ -317,8 +307,7 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim)
|
||||
* @param htim : TIM Hall Sensor handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
|
||||
|
||||
@@ -338,8 +327,7 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim)
|
||||
* @param htim : TIM Hall Sensor handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
|
||||
|
||||
@@ -362,8 +350,7 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim)
|
||||
* @param htim : TIM handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
|
||||
|
||||
@@ -388,23 +375,16 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim)
|
||||
* @param Length : The length of data to be transferred from TIM peripheral to memory.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
|
||||
|
||||
if((htim->State == HAL_TIM_STATE_BUSY))
|
||||
{
|
||||
if ((htim->State == HAL_TIM_STATE_BUSY)) {
|
||||
return HAL_BUSY;
|
||||
}
|
||||
else if((htim->State == HAL_TIM_STATE_READY))
|
||||
{
|
||||
if(((uint32_t)pData == 0U) && (Length > 0U))
|
||||
{
|
||||
} else if ((htim->State == HAL_TIM_STATE_READY)) {
|
||||
if (((uint32_t)pData == 0U) && (Length > 0U)) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
htim->State = HAL_TIM_STATE_BUSY;
|
||||
}
|
||||
}
|
||||
@@ -435,8 +415,7 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32
|
||||
* @param htim : TIM handle
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
|
||||
|
||||
@@ -444,7 +423,6 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim)
|
||||
(in the Hall Sensor Interface the 3 possible channels that are used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
|
||||
TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
|
||||
|
||||
|
||||
/* Disable the capture compare Interrupts 1 event */
|
||||
__HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
|
||||
|
||||
@@ -459,9 +437,7 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim)
|
||||
* @}
|
||||
*/
|
||||
|
||||
#if defined (STM32F100xB) || defined (STM32F100xE) || \
|
||||
defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F103xE) || defined (STM32F103xG) || \
|
||||
defined (STM32F105xC) || defined (STM32F107xC)
|
||||
#if defined(STM32F100xB) || defined(STM32F100xE) || defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC)
|
||||
|
||||
/** @defgroup TIMEx_Exported_Functions_Group2 Timer Complementary Output Compare functions
|
||||
* @brief Timer Complementary Output Compare functions
|
||||
@@ -494,8 +470,7 @@ HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim)
|
||||
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
||||
|
||||
@@ -523,8 +498,7 @@ HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
|
||||
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
||||
|
||||
@@ -552,33 +526,25 @@ HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
|
||||
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
||||
|
||||
switch (Channel)
|
||||
{
|
||||
case TIM_CHANNEL_1:
|
||||
{
|
||||
switch (Channel) {
|
||||
case TIM_CHANNEL_1: {
|
||||
/* Enable the TIM Output Compare interrupt */
|
||||
__HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case TIM_CHANNEL_2:
|
||||
{
|
||||
case TIM_CHANNEL_2: {
|
||||
/* Enable the TIM Output Compare interrupt */
|
||||
__HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case TIM_CHANNEL_3:
|
||||
{
|
||||
case TIM_CHANNEL_3: {
|
||||
/* Enable the TIM Output Compare interrupt */
|
||||
__HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
default:
|
||||
break;
|
||||
@@ -611,35 +577,27 @@ HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Chann
|
||||
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) {
|
||||
uint32_t tmpccer = 0U;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
||||
|
||||
switch (Channel)
|
||||
{
|
||||
case TIM_CHANNEL_1:
|
||||
{
|
||||
switch (Channel) {
|
||||
case TIM_CHANNEL_1: {
|
||||
/* Disable the TIM Output Compare interrupt */
|
||||
__HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case TIM_CHANNEL_2:
|
||||
{
|
||||
case TIM_CHANNEL_2: {
|
||||
/* Disable the TIM Output Compare interrupt */
|
||||
__HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case TIM_CHANNEL_3:
|
||||
{
|
||||
case TIM_CHANNEL_3: {
|
||||
/* Disable the TIM Output Compare interrupt */
|
||||
__HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
default:
|
||||
break;
|
||||
@@ -650,8 +608,7 @@ HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channe
|
||||
|
||||
/* Disable the TIM Break interrupt (only if no more channel is active) */
|
||||
tmpccer = htim->Instance->CCER;
|
||||
if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == RESET)
|
||||
{
|
||||
if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == RESET) {
|
||||
__HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK);
|
||||
}
|
||||
|
||||
@@ -678,30 +635,21 @@ HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channe
|
||||
* @param Length : The length of data to be transferred from memory to TIM peripheral
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
||||
|
||||
if((htim->State == HAL_TIM_STATE_BUSY))
|
||||
{
|
||||
if ((htim->State == HAL_TIM_STATE_BUSY)) {
|
||||
return HAL_BUSY;
|
||||
}
|
||||
else if((htim->State == HAL_TIM_STATE_READY))
|
||||
{
|
||||
if(((uint32_t)pData == 0U) && (Length > 0U))
|
||||
{
|
||||
} else if ((htim->State == HAL_TIM_STATE_READY)) {
|
||||
if (((uint32_t)pData == 0U) && (Length > 0U)) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
htim->State = HAL_TIM_STATE_BUSY;
|
||||
}
|
||||
}
|
||||
switch (Channel)
|
||||
{
|
||||
case TIM_CHANNEL_1:
|
||||
{
|
||||
switch (Channel) {
|
||||
case TIM_CHANNEL_1: {
|
||||
/* Set the DMA Period elapsed callback */
|
||||
htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
|
||||
|
||||
@@ -713,11 +661,9 @@ HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Chan
|
||||
|
||||
/* Enable the TIM Output Compare DMA request */
|
||||
__HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case TIM_CHANNEL_2:
|
||||
{
|
||||
case TIM_CHANNEL_2: {
|
||||
/* Set the DMA Period elapsed callback */
|
||||
htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
|
||||
|
||||
@@ -729,11 +675,9 @@ HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Chan
|
||||
|
||||
/* Enable the TIM Output Compare DMA request */
|
||||
__HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case TIM_CHANNEL_3:
|
||||
{
|
||||
case TIM_CHANNEL_3: {
|
||||
/* Set the DMA Period elapsed callback */
|
||||
htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
|
||||
|
||||
@@ -745,8 +689,7 @@ HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Chan
|
||||
|
||||
/* Enable the TIM Output Compare DMA request */
|
||||
__HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
default:
|
||||
break;
|
||||
@@ -776,33 +719,25 @@ HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Chan
|
||||
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
||||
|
||||
switch (Channel)
|
||||
{
|
||||
case TIM_CHANNEL_1:
|
||||
{
|
||||
switch (Channel) {
|
||||
case TIM_CHANNEL_1: {
|
||||
/* Disable the TIM Output Compare DMA request */
|
||||
__HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case TIM_CHANNEL_2:
|
||||
{
|
||||
case TIM_CHANNEL_2: {
|
||||
/* Disable the TIM Output Compare DMA request */
|
||||
__HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case TIM_CHANNEL_3:
|
||||
{
|
||||
case TIM_CHANNEL_3: {
|
||||
/* Disable the TIM Output Compare DMA request */
|
||||
__HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
default:
|
||||
break;
|
||||
@@ -868,8 +803,7 @@ HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Chann
|
||||
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
||||
|
||||
@@ -896,8 +830,7 @@ HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel
|
||||
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
||||
|
||||
@@ -925,33 +858,25 @@ HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
|
||||
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
||||
|
||||
switch (Channel)
|
||||
{
|
||||
case TIM_CHANNEL_1:
|
||||
{
|
||||
switch (Channel) {
|
||||
case TIM_CHANNEL_1: {
|
||||
/* Enable the TIM Capture/Compare 1 interrupt */
|
||||
__HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case TIM_CHANNEL_2:
|
||||
{
|
||||
case TIM_CHANNEL_2: {
|
||||
/* Enable the TIM Capture/Compare 2 interrupt */
|
||||
__HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case TIM_CHANNEL_3:
|
||||
{
|
||||
case TIM_CHANNEL_3: {
|
||||
/* Enable the TIM Capture/Compare 3 interrupt */
|
||||
__HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
default:
|
||||
break;
|
||||
@@ -984,35 +909,27 @@ HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Chan
|
||||
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) {
|
||||
uint32_t tmpccer = 0U;
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
||||
|
||||
switch (Channel)
|
||||
{
|
||||
case TIM_CHANNEL_1:
|
||||
{
|
||||
switch (Channel) {
|
||||
case TIM_CHANNEL_1: {
|
||||
/* Disable the TIM Capture/Compare 1 interrupt */
|
||||
__HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case TIM_CHANNEL_2:
|
||||
{
|
||||
case TIM_CHANNEL_2: {
|
||||
/* Disable the TIM Capture/Compare 2 interrupt */
|
||||
__HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case TIM_CHANNEL_3:
|
||||
{
|
||||
case TIM_CHANNEL_3: {
|
||||
/* Disable the TIM Capture/Compare 3 interrupt */
|
||||
__HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
default:
|
||||
break;
|
||||
@@ -1023,8 +940,7 @@ HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Chann
|
||||
|
||||
/* Disable the TIM Break interrupt (only if no more channel is active) */
|
||||
tmpccer = htim->Instance->CCER;
|
||||
if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == RESET)
|
||||
{
|
||||
if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == RESET) {
|
||||
__HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK);
|
||||
}
|
||||
|
||||
@@ -1051,30 +967,21 @@ HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Chann
|
||||
* @param Length : The length of data to be transferred from memory to TIM peripheral
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
||||
|
||||
if((htim->State == HAL_TIM_STATE_BUSY))
|
||||
{
|
||||
if ((htim->State == HAL_TIM_STATE_BUSY)) {
|
||||
return HAL_BUSY;
|
||||
}
|
||||
else if((htim->State == HAL_TIM_STATE_READY))
|
||||
{
|
||||
if(((uint32_t)pData == 0U) && (Length > 0U))
|
||||
{
|
||||
} else if ((htim->State == HAL_TIM_STATE_READY)) {
|
||||
if (((uint32_t)pData == 0U) && (Length > 0U)) {
|
||||
return HAL_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
htim->State = HAL_TIM_STATE_BUSY;
|
||||
}
|
||||
}
|
||||
switch (Channel)
|
||||
{
|
||||
case TIM_CHANNEL_1:
|
||||
{
|
||||
switch (Channel) {
|
||||
case TIM_CHANNEL_1: {
|
||||
/* Set the DMA Period elapsed callback */
|
||||
htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
|
||||
|
||||
@@ -1086,11 +993,9 @@ HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Cha
|
||||
|
||||
/* Enable the TIM Capture/Compare 1 DMA request */
|
||||
__HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case TIM_CHANNEL_2:
|
||||
{
|
||||
case TIM_CHANNEL_2: {
|
||||
/* Set the DMA Period elapsed callback */
|
||||
htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
|
||||
|
||||
@@ -1102,11 +1007,9 @@ HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Cha
|
||||
|
||||
/* Enable the TIM Capture/Compare 2 DMA request */
|
||||
__HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case TIM_CHANNEL_3:
|
||||
{
|
||||
case TIM_CHANNEL_3: {
|
||||
/* Set the DMA Period elapsed callback */
|
||||
htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
|
||||
|
||||
@@ -1118,8 +1021,7 @@ HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Cha
|
||||
|
||||
/* Enable the TIM Capture/Compare 3 DMA request */
|
||||
__HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
default:
|
||||
break;
|
||||
@@ -1149,33 +1051,25 @@ HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Cha
|
||||
* @arg TIM_CHANNEL_3: TIM Channel 3 selected
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
|
||||
|
||||
switch (Channel)
|
||||
{
|
||||
case TIM_CHANNEL_1:
|
||||
{
|
||||
switch (Channel) {
|
||||
case TIM_CHANNEL_1: {
|
||||
/* Disable the TIM Capture/Compare 1 DMA request */
|
||||
__HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case TIM_CHANNEL_2:
|
||||
{
|
||||
case TIM_CHANNEL_2: {
|
||||
/* Disable the TIM Capture/Compare 2 DMA request */
|
||||
__HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case TIM_CHANNEL_3:
|
||||
{
|
||||
case TIM_CHANNEL_3: {
|
||||
/* Disable the TIM Capture/Compare 3 DMA request */
|
||||
__HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
default:
|
||||
break;
|
||||
@@ -1229,8 +1123,7 @@ HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Chan
|
||||
* @arg TIM_CHANNEL_2: TIM Channel 2 selected
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
|
||||
|
||||
@@ -1254,8 +1147,7 @@ HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t Ou
|
||||
* @arg TIM_CHANNEL_2: TIM Channel 2 selected
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel) {
|
||||
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
|
||||
@@ -1283,8 +1175,7 @@ HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t Out
|
||||
* @arg TIM_CHANNEL_2: TIM Channel 2 selected
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
|
||||
|
||||
@@ -1314,8 +1205,7 @@ HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t
|
||||
* @arg TIM_CHANNEL_2: TIM Channel 2 selected
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
|
||||
|
||||
@@ -1363,9 +1253,7 @@ HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t
|
||||
* @{
|
||||
*/
|
||||
|
||||
#if defined (STM32F100xB) || defined (STM32F100xE) || \
|
||||
defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F103xE) || defined (STM32F103xG) || \
|
||||
defined (STM32F105xC) || defined (STM32F107xC)
|
||||
#if defined(STM32F100xB) || defined(STM32F100xE) || defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC)
|
||||
|
||||
/**
|
||||
* @brief Configure the TIM commutation event sequence.
|
||||
@@ -1389,17 +1277,14 @@ HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t
|
||||
* @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
|
||||
assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
|
||||
|
||||
__HAL_LOCK(htim);
|
||||
|
||||
if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
|
||||
(InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
|
||||
{
|
||||
if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) || (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3)) {
|
||||
/* Select the Input trigger */
|
||||
htim->Instance->SMCR &= ~TIM_SMCR_TS;
|
||||
htim->Instance->SMCR |= InputTrigger;
|
||||
@@ -1438,17 +1323,14 @@ HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent(TIM_HandleTypeDef *htim, uint
|
||||
* @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_IT(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_IT(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
|
||||
assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
|
||||
|
||||
__HAL_LOCK(htim);
|
||||
|
||||
if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
|
||||
(InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
|
||||
{
|
||||
if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) || (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3)) {
|
||||
/* Select the Input trigger */
|
||||
htim->Instance->SMCR &= ~TIM_SMCR_TS;
|
||||
htim->Instance->SMCR |= InputTrigger;
|
||||
@@ -1491,17 +1373,14 @@ HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_IT(TIM_HandleTypeDef *htim, u
|
||||
* @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_DMA(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_DMA(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
|
||||
assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
|
||||
|
||||
__HAL_LOCK(htim);
|
||||
|
||||
if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
|
||||
(InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
|
||||
{
|
||||
if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) || (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3)) {
|
||||
/* Select the Input trigger */
|
||||
htim->Instance->SMCR &= ~TIM_SMCR_TS;
|
||||
htim->Instance->SMCR |= InputTrigger;
|
||||
@@ -1535,9 +1414,7 @@ HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_DMA(TIM_HandleTypeDef *htim,
|
||||
* contains the BDTR Register configuration information for the TIM peripheral.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim,
|
||||
TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim, TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig) {
|
||||
uint32_t tmpbdtr = 0U;
|
||||
|
||||
/* Check the parameters */
|
||||
@@ -1586,8 +1463,7 @@ HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim,
|
||||
* mode.
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim, TIM_MasterConfigTypeDef * sMasterConfig)
|
||||
{
|
||||
HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim, TIM_MasterConfigTypeDef *sMasterConfig) {
|
||||
/* Check the parameters */
|
||||
assert_param(IS_TIM_MASTER_INSTANCE(htim->Instance));
|
||||
assert_param(IS_TIM_TRGO_SOURCE(sMasterConfig->MasterOutputTrigger));
|
||||
@@ -1639,8 +1515,7 @@ HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim,
|
||||
* @param htim : TIM handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_TIMEx_CommutationCallback(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
__weak void HAL_TIMEx_CommutationCallback(TIM_HandleTypeDef *htim) {
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(htim);
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
@@ -1653,8 +1528,7 @@ __weak void HAL_TIMEx_CommutationCallback(TIM_HandleTypeDef *htim)
|
||||
* @param htim : TIM handle
|
||||
* @retval None
|
||||
*/
|
||||
__weak void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
__weak void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim) {
|
||||
/* Prevent unused argument(s) compilation warning */
|
||||
UNUSED(htim);
|
||||
/* NOTE : This function Should not be modified, when the callback is needed,
|
||||
@@ -1667,8 +1541,7 @@ __weak void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim)
|
||||
* @param hdma : pointer to DMA handle.
|
||||
* @retval None
|
||||
*/
|
||||
void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma)
|
||||
{
|
||||
void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma) {
|
||||
TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
|
||||
|
||||
htim->State = HAL_TIM_STATE_READY;
|
||||
@@ -1680,9 +1553,7 @@ void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma)
|
||||
* @}
|
||||
*/
|
||||
|
||||
#if defined (STM32F100xB) || defined (STM32F100xE) || \
|
||||
defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F103xE) || defined (STM32F103xG) || \
|
||||
defined (STM32F105xC) || defined (STM32F107xC)
|
||||
#if defined(STM32F100xB) || defined(STM32F100xE) || defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC)
|
||||
|
||||
/** @defgroup TIMEx_Exported_Functions_Group7 Extension Peripheral State functions
|
||||
* @brief Extension Peripheral State functions
|
||||
@@ -1704,10 +1575,7 @@ void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma)
|
||||
* @param htim : TIM Hall Sensor handle
|
||||
* @retval HAL state
|
||||
*/
|
||||
HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
return htim->State;
|
||||
}
|
||||
HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim) { return htim->State; }
|
||||
|
||||
/**
|
||||
* @}
|
||||
@@ -1720,9 +1588,7 @@ HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim)
|
||||
* @}
|
||||
*/
|
||||
|
||||
#if defined (STM32F100xB) || defined (STM32F100xE) || \
|
||||
defined (STM32F103x6) || defined (STM32F103xB) || defined (STM32F103xE) || defined (STM32F103xG) || \
|
||||
defined (STM32F105xC) || defined (STM32F107xC)
|
||||
#if defined(STM32F100xB) || defined(STM32F100xE) || defined(STM32F103x6) || defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F103xG) || defined(STM32F105xC) || defined(STM32F107xC)
|
||||
|
||||
/** @addtogroup TIMEx_Private_Functions
|
||||
* @{
|
||||
@@ -1740,8 +1606,7 @@ HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim)
|
||||
* This parameter can be: TIM_CCxN_ENABLE or TIM_CCxN_Disable.
|
||||
* @retval None
|
||||
*/
|
||||
static void TIM_CCxNChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelNState)
|
||||
{
|
||||
static void TIM_CCxNChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelNState) {
|
||||
uint32_t tmp = 0U;
|
||||
|
||||
tmp = TIM_CCER_CC1NE << Channel;
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
* Author: Ralim
|
||||
*/
|
||||
|
||||
#include "BSP_Flash.h"
|
||||
#include "BSP.h"
|
||||
#include "string.h"
|
||||
#include "BSP_Flash.h"
|
||||
#include "stm32f1xx_hal.h"
|
||||
#include "string.h"
|
||||
|
||||
static uint16_t settings_page[512] __attribute__((section(".settings_page")));
|
||||
|
||||
@@ -20,8 +20,7 @@ uint8_t flash_save_buffer(const uint8_t *buffer, const uint16_t length) {
|
||||
pEraseInit.PageAddress = (uint32_t)settings_page;
|
||||
uint32_t failingAddress = 0;
|
||||
resetWatchdog();
|
||||
__HAL_FLASH_CLEAR_FLAG(
|
||||
FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR | FLASH_FLAG_BSY);
|
||||
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR | FLASH_FLAG_BSY);
|
||||
HAL_FLASH_Unlock();
|
||||
HAL_Delay(1);
|
||||
resetWatchdog();
|
||||
@@ -33,14 +32,10 @@ uint8_t flash_save_buffer(const uint8_t *buffer, const uint16_t length) {
|
||||
HAL_FLASH_Unlock();
|
||||
for (uint8_t i = 0; i < (length / 2); i++) {
|
||||
resetWatchdog();
|
||||
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD,
|
||||
(uint32_t) &settings_page[i], data[i]);
|
||||
HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, (uint32_t)&settings_page[i], data[i]);
|
||||
}
|
||||
HAL_FLASH_Lock();
|
||||
return 1;
|
||||
}
|
||||
|
||||
void flash_read_buffer(uint8_t *buffer, const uint16_t length) {
|
||||
|
||||
memcpy(buffer, settings_page, length);
|
||||
}
|
||||
void flash_read_buffer(uint8_t *buffer, const uint16_t length) { memcpy(buffer, settings_page, length); }
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
#include "Model_Config.h"
|
||||
#ifdef POW_PD
|
||||
#include "BSP.h"
|
||||
#include "fusb302b.h"
|
||||
#include "I2CBB.hpp"
|
||||
#include <pd.h>
|
||||
#include "fusb302b.h"
|
||||
#include "int_n.h"
|
||||
#include <pd.h>
|
||||
/*
|
||||
* Read a single byte from the FUSB302B
|
||||
*
|
||||
@@ -45,9 +45,7 @@ static uint8_t fusb_read_byte(uint8_t addr) {
|
||||
* size: The number of bytes to read
|
||||
* buf: The buffer into which data will be read
|
||||
*/
|
||||
static bool fusb_read_buf(uint8_t addr, uint8_t size, uint8_t *buf) {
|
||||
return I2CBB::Mem_Read(FUSB302B_ADDR, addr, buf, size);
|
||||
}
|
||||
static bool fusb_read_buf(uint8_t addr, uint8_t size, uint8_t *buf) { return I2CBB::Mem_Read(FUSB302B_ADDR, addr, buf, size); }
|
||||
|
||||
/*
|
||||
* Write a single byte to the FUSB302B
|
||||
@@ -56,9 +54,7 @@ static bool fusb_read_buf(uint8_t addr, uint8_t size, uint8_t *buf) {
|
||||
* addr: The memory address to which we will write
|
||||
* byte: The value to write
|
||||
*/
|
||||
static bool fusb_write_byte(uint8_t addr, uint8_t byte) {
|
||||
return I2CBB::Mem_Write(FUSB302B_ADDR, addr, (uint8_t*) &byte, 1);
|
||||
}
|
||||
static bool fusb_write_byte(uint8_t addr, uint8_t byte) { return I2CBB::Mem_Write(FUSB302B_ADDR, addr, (uint8_t *)&byte, 1); }
|
||||
|
||||
/*
|
||||
* Write multiple bytes to the FUSB302B
|
||||
@@ -68,26 +64,15 @@ static bool fusb_write_byte(uint8_t addr, uint8_t byte) {
|
||||
* size: The number of bytes to write
|
||||
* buf: The buffer to write
|
||||
*/
|
||||
static bool fusb_write_buf(uint8_t addr, uint8_t size, const uint8_t *buf) {
|
||||
return I2CBB::Mem_Write(FUSB302B_ADDR, addr, buf, size);
|
||||
}
|
||||
static bool fusb_write_buf(uint8_t addr, uint8_t size, const uint8_t *buf) { return I2CBB::Mem_Write(FUSB302B_ADDR, addr, buf, size); }
|
||||
|
||||
void fusb_send_message(const union pd_msg *msg) {
|
||||
if (!I2CBB::lock2()) {
|
||||
return;
|
||||
}
|
||||
/* Token sequences for the FUSB302B */
|
||||
static uint8_t sop_seq[5] = {
|
||||
FUSB_FIFO_TX_SOP1,
|
||||
FUSB_FIFO_TX_SOP1,
|
||||
FUSB_FIFO_TX_SOP1,
|
||||
FUSB_FIFO_TX_SOP2,
|
||||
FUSB_FIFO_TX_PACKSYM };
|
||||
static const uint8_t eop_seq[4] = {
|
||||
FUSB_FIFO_TX_JAM_CRC,
|
||||
FUSB_FIFO_TX_EOP,
|
||||
FUSB_FIFO_TX_TXOFF,
|
||||
FUSB_FIFO_TX_TXON };
|
||||
static uint8_t sop_seq[5] = {FUSB_FIFO_TX_SOP1, FUSB_FIFO_TX_SOP1, FUSB_FIFO_TX_SOP1, FUSB_FIFO_TX_SOP2, FUSB_FIFO_TX_PACKSYM};
|
||||
static const uint8_t eop_seq[4] = {FUSB_FIFO_TX_JAM_CRC, FUSB_FIFO_TX_EOP, FUSB_FIFO_TX_TXOFF, FUSB_FIFO_TX_TXON};
|
||||
|
||||
/* Take the I2C2 mutex now so there can't be a race condition on sop_seq */
|
||||
/* Get the length of the message: a two-octet header plus NUMOBJ four-octet
|
||||
@@ -103,7 +88,6 @@ void fusb_send_message(const union pd_msg *msg) {
|
||||
fusb_write_buf(FUSB_FIFOS, 4, eop_seq);
|
||||
|
||||
I2CBB::unlock2();
|
||||
|
||||
}
|
||||
|
||||
uint8_t fusb_read_message(union pd_msg *msg) {
|
||||
@@ -169,8 +153,7 @@ bool fusb_setup() {
|
||||
// set defaults
|
||||
fusb_write_byte(FUSB_CONTROL2, 0x00);
|
||||
/* Flush the RX buffer */
|
||||
fusb_write_byte( FUSB_CONTROL1,
|
||||
FUSB_CONTROL1_RX_FLUSH);
|
||||
fusb_write_byte(FUSB_CONTROL1, FUSB_CONTROL1_RX_FLUSH);
|
||||
|
||||
/* Measure CC1 */
|
||||
fusb_write_byte(FUSB_SWITCHES0, 0x07);
|
||||
@@ -215,7 +198,6 @@ void fusb_get_status(union fusb_status *status) {
|
||||
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
|
||||
I2CBB::unlock2();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
enum fusb_typec_current fusb_get_typec_current() {
|
||||
@@ -225,8 +207,7 @@ enum fusb_typec_current fusb_get_typec_current() {
|
||||
}
|
||||
}
|
||||
/* Read the BC_LVL into a variable */
|
||||
enum fusb_typec_current bc_lvl = (enum fusb_typec_current) (fusb_read_byte(
|
||||
FUSB_STATUS0) & FUSB_STATUS0_BC_LVL);
|
||||
enum fusb_typec_current bc_lvl = (enum fusb_typec_current)(fusb_read_byte(FUSB_STATUS0) & FUSB_STATUS0_BC_LVL);
|
||||
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
|
||||
I2CBB::unlock2();
|
||||
}
|
||||
|
||||
@@ -23,4 +23,3 @@ uint8_t showBootLogoIfavailable() {
|
||||
OLED::refresh();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -163,8 +163,7 @@ static UBaseType_t uxCriticalNesting = 0xaaaaaaaa;
|
||||
#if (configASSERT_DEFINED == 1)
|
||||
static uint8_t ucMaxSysCallPriority = 0;
|
||||
static uint32_t ulMaxPRIGROUPValue = 0;
|
||||
static const volatile uint8_t *const pcInterruptPriorityRegisters =
|
||||
(const volatile uint8_t* const ) portNVIC_IP_REGISTERS_OFFSET_16;
|
||||
static const volatile uint8_t *const pcInterruptPriorityRegisters = (const volatile uint8_t *const)portNVIC_IP_REGISTERS_OFFSET_16;
|
||||
#endif /* configASSERT_DEFINED */
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
@@ -172,8 +171,7 @@ static const volatile uint8_t *const pcInterruptPriorityRegisters =
|
||||
/*
|
||||
* See header file for description.
|
||||
*/
|
||||
StackType_t* pxPortInitialiseStack(StackType_t *pxTopOfStack,
|
||||
TaskFunction_t pxCode, void *pvParameters) {
|
||||
StackType_t *pxPortInitialiseStack(StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters) {
|
||||
/* Simulate the stack frame as it would be created by a context switch
|
||||
interrupt. */
|
||||
pxTopOfStack--; /* Offset added to account for the way the MCU uses the stack on entry/exit of interrupts. */
|
||||
@@ -214,8 +212,7 @@ static void prvTaskExitError(void) {
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vPortSVCHandler(void) {
|
||||
__asm volatile (
|
||||
" ldr r3, pxCurrentTCBConst2 \n" /* Restore the context. */
|
||||
__asm volatile(" ldr r3, pxCurrentTCBConst2 \n" /* Restore the context. */
|
||||
" ldr r1, [r3] \n" /* Use pxCurrentTCBConst to get the pxCurrentTCB address. */
|
||||
" ldr r0, [r1] \n" /* The first item in pxCurrentTCB is the task top of stack. */
|
||||
" ldmia r0!, {r4-r11} \n" /* Pop the registers that are not automatically saved on exception entry and the critical nesting count. */
|
||||
@@ -227,14 +224,12 @@ void vPortSVCHandler(void) {
|
||||
" bx r14 \n"
|
||||
" \n"
|
||||
" .align 4 \n"
|
||||
"pxCurrentTCBConst2: .word pxCurrentTCB \n"
|
||||
);
|
||||
"pxCurrentTCBConst2: .word pxCurrentTCB \n");
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvPortStartFirstTask(void) {
|
||||
__asm volatile(
|
||||
" ldr r0, =0xE000ED08 \n" /* Use the NVIC offset register to locate the stack. */
|
||||
__asm volatile(" ldr r0, =0xE000ED08 \n" /* Use the NVIC offset register to locate the stack. */
|
||||
" ldr r0, [r0] \n"
|
||||
" ldr r0, [r0] \n"
|
||||
" msr msp, r0 \n" /* Set the msp back to the start of the stack. */
|
||||
@@ -243,8 +238,7 @@ static void prvPortStartFirstTask(void) {
|
||||
" dsb \n"
|
||||
" isb \n"
|
||||
" svc 0 \n" /* System call to start first task. */
|
||||
" nop \n"
|
||||
);
|
||||
" nop \n");
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
@@ -259,9 +253,7 @@ BaseType_t xPortStartScheduler(void) {
|
||||
#if (configASSERT_DEFINED == 1)
|
||||
{
|
||||
volatile uint32_t ulOriginalPriority;
|
||||
volatile uint8_t *const pucFirstUserPriorityRegister =
|
||||
(volatile uint8_t* const ) ( portNVIC_IP_REGISTERS_OFFSET_16
|
||||
+ portFIRST_USER_INTERRUPT_NUMBER);
|
||||
volatile uint8_t *const pucFirstUserPriorityRegister = (volatile uint8_t *const)(portNVIC_IP_REGISTERS_OFFSET_16 + portFIRST_USER_INTERRUPT_NUMBER);
|
||||
volatile uint8_t ucMaxPriorityValue;
|
||||
|
||||
/* Determine the maximum priority from which ISR safe FreeRTOS API
|
||||
@@ -280,8 +272,7 @@ BaseType_t xPortStartScheduler(void) {
|
||||
ucMaxPriorityValue = *pucFirstUserPriorityRegister;
|
||||
|
||||
/* Use the same mask on the maximum system call priority. */
|
||||
ucMaxSysCallPriority = configMAX_SYSCALL_INTERRUPT_PRIORITY
|
||||
& ucMaxPriorityValue;
|
||||
ucMaxSysCallPriority = configMAX_SYSCALL_INTERRUPT_PRIORITY & ucMaxPriorityValue;
|
||||
|
||||
/* Calculate the maximum acceptable priority group value for the number
|
||||
of bits read back. */
|
||||
@@ -382,9 +373,7 @@ void vPortExitCritical(void) {
|
||||
void xPortPendSVHandler(void) {
|
||||
/* This is a naked function. */
|
||||
|
||||
__asm volatile
|
||||
(
|
||||
" mrs r0, psp \n"
|
||||
__asm volatile(" mrs r0, psp \n"
|
||||
" isb \n"
|
||||
" \n"
|
||||
" ldr r3, pxCurrentTCBConst \n" /* Get the location of the current TCB. */
|
||||
@@ -409,9 +398,7 @@ void xPortPendSVHandler(void) {
|
||||
" bx r14 \n"
|
||||
" \n"
|
||||
" .align 4 \n"
|
||||
"pxCurrentTCBConst: .word pxCurrentTCB \n"
|
||||
::"i"(configMAX_SYSCALL_INTERRUPT_PRIORITY)
|
||||
);
|
||||
"pxCurrentTCBConst: .word pxCurrentTCB \n" ::"i"(configMAX_SYSCALL_INTERRUPT_PRIORITY));
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
@@ -435,14 +422,12 @@ void xPortSysTickHandler(void) {
|
||||
|
||||
#if (configUSE_TICKLESS_IDLE == 1)
|
||||
|
||||
__attribute__((weak)) void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )
|
||||
{
|
||||
__attribute__((weak)) void vPortSuppressTicksAndSleep(TickType_t xExpectedIdleTime) {
|
||||
uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements;
|
||||
TickType_t xModifiableIdleTime;
|
||||
|
||||
/* Make sure the SysTick reload value does not overflow the counter. */
|
||||
if( xExpectedIdleTime > xMaximumPossibleSuppressedTicks )
|
||||
{
|
||||
if (xExpectedIdleTime > xMaximumPossibleSuppressedTicks) {
|
||||
xExpectedIdleTime = xMaximumPossibleSuppressedTicks;
|
||||
}
|
||||
|
||||
@@ -456,8 +441,7 @@ void xPortSysTickHandler(void) {
|
||||
tick periods. -1 is used because this code will execute part way
|
||||
through one of the tick periods. */
|
||||
ulReloadValue = portNVIC_SYSTICK_CURRENT_VALUE_REG + (ulTimerCountsForOneTick * (xExpectedIdleTime - 1UL));
|
||||
if( ulReloadValue > ulStoppedTimerCompensation )
|
||||
{
|
||||
if (ulReloadValue > ulStoppedTimerCompensation) {
|
||||
ulReloadValue -= ulStoppedTimerCompensation;
|
||||
}
|
||||
|
||||
@@ -469,8 +453,7 @@ void xPortSysTickHandler(void) {
|
||||
|
||||
/* If a context switch is pending or a task is waiting for the scheduler
|
||||
to be unsuspended then abandon the low power entry. */
|
||||
if( eTaskConfirmSleepModeStatus() == eAbortSleep )
|
||||
{
|
||||
if (eTaskConfirmSleepModeStatus() == eAbortSleep) {
|
||||
/* Restart from whatever is left in the count register to complete
|
||||
this tick period. */
|
||||
portNVIC_SYSTICK_LOAD_REG = portNVIC_SYSTICK_CURRENT_VALUE_REG;
|
||||
@@ -485,9 +468,7 @@ void xPortSysTickHandler(void) {
|
||||
/* Re-enable interrupts - see comments above the cpsid instruction()
|
||||
above. */
|
||||
__asm volatile("cpsie i" ::: "memory");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Set the new reload value. */
|
||||
portNVIC_SYSTICK_LOAD_REG = ulReloadValue;
|
||||
|
||||
@@ -505,8 +486,7 @@ void xPortSysTickHandler(void) {
|
||||
time variable must remain unmodified, so a copy is taken. */
|
||||
xModifiableIdleTime = xExpectedIdleTime;
|
||||
configPRE_SLEEP_PROCESSING(xModifiableIdleTime);
|
||||
if( xModifiableIdleTime > 0 )
|
||||
{
|
||||
if (xModifiableIdleTime > 0) {
|
||||
__asm volatile("dsb" ::: "memory");
|
||||
__asm volatile("wfi");
|
||||
__asm volatile("isb");
|
||||
@@ -542,8 +522,7 @@ void xPortSysTickHandler(void) {
|
||||
correct for the entire expected idle time) or if the SysTick is yet
|
||||
to count to zero (in which case an interrupt other than the SysTick
|
||||
must have brought the system out of sleep mode). */
|
||||
if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
|
||||
{
|
||||
if ((portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT) != 0) {
|
||||
uint32_t ulCalculatedLoadValue;
|
||||
|
||||
/* The tick interrupt is already pending, and the SysTick count
|
||||
@@ -555,8 +534,7 @@ void xPortSysTickHandler(void) {
|
||||
/* Don't allow a tiny value, or values that have somehow
|
||||
underflowed because the post sleep hook did something
|
||||
that took too long. */
|
||||
if( ( ulCalculatedLoadValue < ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) )
|
||||
{
|
||||
if ((ulCalculatedLoadValue < ulStoppedTimerCompensation) || (ulCalculatedLoadValue > ulTimerCountsForOneTick)) {
|
||||
ulCalculatedLoadValue = (ulTimerCountsForOneTick - 1UL);
|
||||
}
|
||||
|
||||
@@ -566,9 +544,7 @@ void xPortSysTickHandler(void) {
|
||||
function exits, the tick value maintained by the tick is stepped
|
||||
forward by one less than the time spent waiting. */
|
||||
ulCompleteTickPeriods = xExpectedIdleTime - 1UL;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Something other than the tick interrupt ended the sleep.
|
||||
Work out how long the sleep lasted rounded to complete tick
|
||||
periods (not the ulReload value which accounted for part
|
||||
@@ -619,10 +595,8 @@ __attribute__(( weak )) void vPortSetupTimerInterrupt(void) {
|
||||
portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
|
||||
|
||||
/* Configure SysTick to interrupt at the requested rate. */
|
||||
portNVIC_SYSTICK_LOAD_REG = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ)
|
||||
- 1UL;
|
||||
portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT
|
||||
| portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT);
|
||||
portNVIC_SYSTICK_LOAD_REG = (configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ) - 1UL;
|
||||
portNVIC_SYSTICK_CTRL_REG = (portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT);
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
@@ -679,9 +653,7 @@ void vPortValidateInterruptPriority(void) {
|
||||
scheduler. Note however that some vendor specific peripheral libraries
|
||||
assume a non-zero priority group setting, in which cases using a value
|
||||
of zero will result in unpredictable behaviour. */
|
||||
configASSERT(
|
||||
( portAIRCR_REG & portPRIORITY_GROUP_MASK) <= ulMaxPRIGROUPValue);
|
||||
configASSERT((portAIRCR_REG & portPRIORITY_GROUP_MASK) <= ulMaxPRIGROUPValue);
|
||||
}
|
||||
|
||||
#endif /* configASSERT_DEFINED */
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#include "BSP.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "I2C_Wrapper.hpp"
|
||||
#include "QC3.h"
|
||||
#include "Settings.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "fusbpd.h"
|
||||
#include "main.hpp"
|
||||
#include "power.hpp"
|
||||
#include "stdlib.h"
|
||||
#include "task.h"
|
||||
#include "I2C_Wrapper.hpp"
|
||||
#include "fusbpd.h"
|
||||
|
||||
// Initialisation to be performed with scheduler active
|
||||
void postRToSInit() {
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
* Author: Ralim
|
||||
*/
|
||||
|
||||
#include <I2C_Wrapper.hpp>
|
||||
#include "BSP.h"
|
||||
#include "Setup.h"
|
||||
#include "Pins.h"
|
||||
#include "I2CBB.hpp"
|
||||
#include "fusbpd.h"
|
||||
#include "Model_Config.h"
|
||||
#include "Pins.h"
|
||||
#include "Setup.h"
|
||||
#include "fusbpd.h"
|
||||
#include <I2C_Wrapper.hpp>
|
||||
void preRToSInit() {
|
||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick.
|
||||
*/
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
#include "Pins.h"
|
||||
#include "stm32f1xx_hal.h"
|
||||
#include "Setup.h"
|
||||
#include "stm32f1xx_hal.h"
|
||||
/**
|
||||
* Initializes the Global MSP.
|
||||
*/
|
||||
void HAL_MspInit(void) {
|
||||
__HAL_RCC_AFIO_CLK_ENABLE()
|
||||
;
|
||||
__HAL_RCC_AFIO_CLK_ENABLE();
|
||||
|
||||
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
|
||||
|
||||
@@ -25,15 +24,13 @@ void HAL_MspInit(void) {
|
||||
HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0);
|
||||
/* SysTick_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);
|
||||
|
||||
}
|
||||
|
||||
void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc) {
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct;
|
||||
if (hadc->Instance == ADC1) {
|
||||
__HAL_RCC_ADC1_CLK_ENABLE()
|
||||
;
|
||||
__HAL_RCC_ADC1_CLK_ENABLE();
|
||||
|
||||
/* ADC1 DMA Init */
|
||||
/* ADC1 Init */
|
||||
@@ -53,8 +50,7 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc) {
|
||||
HAL_NVIC_SetPriority(ADC1_2_IRQn, 15, 0);
|
||||
HAL_NVIC_EnableIRQ(ADC1_2_IRQn);
|
||||
} else {
|
||||
__HAL_RCC_ADC2_CLK_ENABLE()
|
||||
;
|
||||
__HAL_RCC_ADC2_CLK_ENABLE();
|
||||
|
||||
/**ADC2 GPIO Configuration
|
||||
PB0 ------> ADC2_IN8
|
||||
@@ -74,7 +70,6 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc) {
|
||||
HAL_NVIC_SetPriority(ADC1_2_IRQn, 15, 0);
|
||||
HAL_NVIC_EnableIRQ(ADC1_2_IRQn);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c) {
|
||||
@@ -91,8 +86,7 @@ void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c) {
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_I2C1_CLK_ENABLE()
|
||||
;
|
||||
__HAL_RCC_I2C1_CLK_ENABLE();
|
||||
/* I2C1 DMA Init */
|
||||
/* I2C1_RX Init */
|
||||
hdma_i2c1_rx.Instance = DMA1_Channel7;
|
||||
@@ -125,17 +119,14 @@ void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c) {
|
||||
HAL_NVIC_EnableIRQ(I2C1_EV_IRQn);
|
||||
HAL_NVIC_SetPriority(I2C1_ER_IRQn, 15, 0);
|
||||
HAL_NVIC_EnableIRQ(I2C1_ER_IRQn);
|
||||
|
||||
}
|
||||
|
||||
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim_base) {
|
||||
if (htim_base->Instance == TIM3) {
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_TIM3_CLK_ENABLE()
|
||||
;
|
||||
__HAL_RCC_TIM3_CLK_ENABLE();
|
||||
} else if (htim_base->Instance == TIM2) {
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_TIM2_CLK_ENABLE()
|
||||
;
|
||||
__HAL_RCC_TIM2_CLK_ENABLE();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// This is the stock standard STM interrupt file full of handlers
|
||||
#include "stm32f1xx_hal.h"
|
||||
#include "stm32f1xx.h"
|
||||
#include "stm32f1xx_it.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "Setup.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "stm32f1xx.h"
|
||||
#include "stm32f1xx_hal.h"
|
||||
|
||||
extern TIM_HandleTypeDef htim1; // used for the systick
|
||||
|
||||
@@ -11,32 +11,24 @@ extern TIM_HandleTypeDef htim1; //used for the systick
|
||||
/* Cortex-M3 Processor Interruption and Exception Handlers */
|
||||
/******************************************************************************/
|
||||
|
||||
void NMI_Handler(void) {
|
||||
}
|
||||
void NMI_Handler(void) {}
|
||||
|
||||
// We have the assembly for a breakpoint trigger here to halt the system when a debugger is connected
|
||||
// Hardfault handler, often a screwup in the code
|
||||
void HardFault_Handler(void) {
|
||||
}
|
||||
void HardFault_Handler(void) {}
|
||||
|
||||
// Memory management unit had an error
|
||||
void MemManage_Handler(void) {
|
||||
}
|
||||
void MemManage_Handler(void) {}
|
||||
|
||||
// Prefetcher or busfault occured
|
||||
void BusFault_Handler(void) {
|
||||
}
|
||||
void BusFault_Handler(void) {}
|
||||
|
||||
void UsageFault_Handler(void) {
|
||||
}
|
||||
void UsageFault_Handler(void) {}
|
||||
|
||||
void DebugMon_Handler(void) {
|
||||
}
|
||||
void DebugMon_Handler(void) {}
|
||||
|
||||
// Systick is used by FreeRTOS tick
|
||||
void SysTick_Handler(void) {
|
||||
osSystickHandler();
|
||||
}
|
||||
void SysTick_Handler(void) { osSystickHandler(); }
|
||||
|
||||
/******************************************************************************/
|
||||
/* STM32F1xx Peripheral Interrupt Handlers */
|
||||
@@ -46,42 +38,22 @@ void SysTick_Handler(void) {
|
||||
/******************************************************************************/
|
||||
|
||||
// DMA used to move the ADC readings into system ram
|
||||
void DMA1_Channel1_IRQHandler(void) {
|
||||
HAL_DMA_IRQHandler(&hdma_adc1);
|
||||
}
|
||||
void DMA1_Channel1_IRQHandler(void) { HAL_DMA_IRQHandler(&hdma_adc1); }
|
||||
// ADC interrupt used for DMA
|
||||
void ADC1_2_IRQHandler(void) {
|
||||
HAL_ADC_IRQHandler(&hadc1);
|
||||
}
|
||||
void ADC1_2_IRQHandler(void) { HAL_ADC_IRQHandler(&hadc1); }
|
||||
|
||||
// Timer 1 has overflowed, used for HAL ticks
|
||||
void TIM1_UP_IRQHandler(void) {
|
||||
HAL_TIM_IRQHandler(&htim1);
|
||||
}
|
||||
void TIM1_UP_IRQHandler(void) { HAL_TIM_IRQHandler(&htim1); }
|
||||
// Timer 3 is used for the PWM output to the tip
|
||||
void TIM3_IRQHandler(void) {
|
||||
HAL_TIM_IRQHandler(&htim3);
|
||||
}
|
||||
void TIM3_IRQHandler(void) { HAL_TIM_IRQHandler(&htim3); }
|
||||
|
||||
// Timer 2 is used for co-ordination of PWM & ADC
|
||||
void TIM2_IRQHandler(void) {
|
||||
HAL_TIM_IRQHandler(&htim2);
|
||||
}
|
||||
void TIM2_IRQHandler(void) { HAL_TIM_IRQHandler(&htim2); }
|
||||
|
||||
void I2C1_EV_IRQHandler(void) {
|
||||
HAL_I2C_EV_IRQHandler(&hi2c1);
|
||||
}
|
||||
void I2C1_ER_IRQHandler(void) {
|
||||
HAL_I2C_ER_IRQHandler(&hi2c1);
|
||||
}
|
||||
void I2C1_EV_IRQHandler(void) { HAL_I2C_EV_IRQHandler(&hi2c1); }
|
||||
void I2C1_ER_IRQHandler(void) { HAL_I2C_ER_IRQHandler(&hi2c1); }
|
||||
|
||||
void DMA1_Channel6_IRQHandler(void) {
|
||||
HAL_DMA_IRQHandler(&hdma_i2c1_tx);
|
||||
}
|
||||
void DMA1_Channel6_IRQHandler(void) { HAL_DMA_IRQHandler(&hdma_i2c1_tx); }
|
||||
|
||||
void DMA1_Channel7_IRQHandler(void) {
|
||||
HAL_DMA_IRQHandler(&hdma_i2c1_rx);
|
||||
}
|
||||
void EXTI9_5_IRQHandler(void) {
|
||||
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_9);
|
||||
}
|
||||
void DMA1_Channel7_IRQHandler(void) { HAL_DMA_IRQHandler(&hdma_i2c1_rx); }
|
||||
void EXTI9_5_IRQHandler(void) { HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_9); }
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
#include "stm32f1xx.h"
|
||||
|
||||
#if !defined(HSI_VALUE)
|
||||
#define HSI_VALUE 8000000U /*!< Default value of the Internal oscillator in Hz.
|
||||
#define HSI_VALUE \
|
||||
8000000U /*!< Default value of the Internal oscillator in Hz. \
|
||||
This value can be provided and adapted by the user application. */
|
||||
#endif /* HSI_VALUE */
|
||||
|
||||
@@ -13,7 +14,8 @@
|
||||
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
|
||||
|
||||
#ifndef VECT_TAB_OFFSET
|
||||
#define VECT_TAB_OFFSET 0x00004000U /*!< Vector Table base offset field.
|
||||
#define VECT_TAB_OFFSET \
|
||||
0x00004000U /*!< Vector Table base offset field. \
|
||||
This value must be a multiple of 0x200. */
|
||||
// We offset this by 0x4000 to because of the bootloader
|
||||
#endif
|
||||
@@ -27,8 +29,7 @@
|
||||
uint32_t SystemCoreClock = 64000000U; /*!< System Clock Frequency (Core Clock) */
|
||||
#endif
|
||||
|
||||
const uint8_t AHBPrescTable[16U] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7,
|
||||
8, 9 };
|
||||
const uint8_t AHBPrescTable[16U] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
|
||||
const uint8_t APBPrescTable[8U] = {0, 0, 0, 0, 1, 2, 3, 4};
|
||||
|
||||
/**
|
||||
@@ -178,34 +179,25 @@ void SystemCoreClockUpdate(void) {
|
||||
#else
|
||||
pllmull = pllmull >> 18U;
|
||||
|
||||
if (pllmull != 0x0DU)
|
||||
{
|
||||
if (pllmull != 0x0DU) {
|
||||
pllmull += 2U;
|
||||
}
|
||||
else
|
||||
{ /* PLL multiplication factor = PLL input clock * 6.5 */
|
||||
} else { /* PLL multiplication factor = PLL input clock * 6.5 */
|
||||
pllmull = 13U / 2U;
|
||||
}
|
||||
|
||||
if (pllsource == 0x00U)
|
||||
{
|
||||
if (pllsource == 0x00U) {
|
||||
/* HSI oscillator clock divided by 2 selected as PLL clock entry */
|
||||
SystemCoreClock = (HSI_VALUE >> 1U) * pllmull;
|
||||
}
|
||||
else
|
||||
{/* PREDIV1 selected as PLL clock entry */
|
||||
} else { /* PREDIV1 selected as PLL clock entry */
|
||||
|
||||
/* Get PREDIV1 clock source and division factor */
|
||||
prediv1source = RCC->CFGR2 & RCC_CFGR2_PREDIV1SRC;
|
||||
prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1U;
|
||||
|
||||
if (prediv1source == 0U)
|
||||
{
|
||||
if (prediv1source == 0U) {
|
||||
/* HSE oscillator clock selected as PREDIV1 clock entry */
|
||||
SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull;
|
||||
}
|
||||
else
|
||||
{/* PLL2 clock selected as PREDIV1 clock entry */
|
||||
} else { /* PLL2 clock selected as PREDIV1 clock entry */
|
||||
|
||||
/* Get PREDIV2 division factor and PLL2 multiplication factor */
|
||||
prediv2factor = ((RCC->CFGR2 & RCC_CFGR2_PREDIV2) >> 4U) + 1U;
|
||||
@@ -245,8 +237,7 @@ void SystemCoreClockUpdate(void) {
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void SystemInit_ExtMemCtl(void)
|
||||
{
|
||||
void SystemInit_ExtMemCtl(void) {
|
||||
__IO uint32_t tmpreg;
|
||||
/*!< FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is
|
||||
required, then adjust the Register Addresses */
|
||||
|
||||
@@ -20,7 +20,8 @@ bool BMA223::detect() {
|
||||
return false;
|
||||
}
|
||||
|
||||
static const FRToSI2C::I2C_REG i2c_registers[] = { //
|
||||
static const FRToSI2C::I2C_REG i2c_registers[] = {
|
||||
//
|
||||
//
|
||||
{BMA223_PMU_RANGE, 0b00000011, 0}, // 2G range
|
||||
{BMA223_PMU_BW, 0b00001101, 0}, // 250Hz filter
|
||||
@@ -44,7 +45,6 @@ bool BMA223::initalize() {
|
||||
// Theta blocking is set to 0b10
|
||||
|
||||
return FRToSI2C::writeRegistersBulk(BMA223_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
||||
|
||||
}
|
||||
|
||||
void BMA223::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
||||
@@ -60,5 +60,4 @@ void BMA223::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
||||
x = sensorData[1] << 6;
|
||||
y = sensorData[3] << 6;
|
||||
z = sensorData[5] << 6;
|
||||
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
* Created on: 29 May 2020
|
||||
* Author: Ralim
|
||||
*/
|
||||
#include <Buttons.hpp>
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "gui.hpp"
|
||||
#include "task.h"
|
||||
#include <Buttons.hpp>
|
||||
uint32_t lastButtonTime = 0;
|
||||
|
||||
ButtonState getButtonState() {
|
||||
|
||||
@@ -6,15 +6,15 @@
|
||||
*/
|
||||
#include "Model_Config.h"
|
||||
#ifdef POW_PD
|
||||
#include <fusbpd.h>
|
||||
#include <pd.h>
|
||||
#include "BSP.h"
|
||||
#include "I2CBB.hpp"
|
||||
#include "fusb302b.h"
|
||||
#include "int_n.h"
|
||||
#include "policy_engine.h"
|
||||
#include "protocol_rx.h"
|
||||
#include "protocol_tx.h"
|
||||
#include "int_n.h"
|
||||
#include <fusbpd.h>
|
||||
#include <pd.h>
|
||||
|
||||
void fusb302_start_processing() {
|
||||
/* Initialize the FUSB302B */
|
||||
|
||||
@@ -16,16 +16,14 @@
|
||||
*/
|
||||
|
||||
#include "int_n.h"
|
||||
#include "fusbpd.h"
|
||||
#include <pd.h>
|
||||
#include "BSP.h"
|
||||
#include "fusb302b.h"
|
||||
#include "protocol_rx.h"
|
||||
#include "protocol_tx.h"
|
||||
#include "fusbpd.h"
|
||||
#include "policy_engine.h"
|
||||
#include "protocol_rx.h"
|
||||
#include "protocol_tx.h"
|
||||
#include "task.h"
|
||||
#include "BSP.h"
|
||||
#include <pd.h>
|
||||
|
||||
osThreadId InterruptHandler::TaskHandle = NULL;
|
||||
uint32_t InterruptHandler::TaskBuffer[InterruptHandler::TaskStackSize];
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
*/
|
||||
|
||||
#include "policy_engine.h"
|
||||
#include <stdbool.h>
|
||||
#include "int_n.h"
|
||||
#include <pd.h>
|
||||
#include "protocol_tx.h"
|
||||
#include "fusb302b.h"
|
||||
#include "int_n.h"
|
||||
#include "protocol_tx.h"
|
||||
#include <pd.h>
|
||||
#include <stdbool.h>
|
||||
bool PolicyEngine::pdNegotiationComplete;
|
||||
int PolicyEngine::current_voltage_mv;
|
||||
int PolicyEngine::_requested_voltage;
|
||||
@@ -39,17 +39,14 @@ union pd_msg PolicyEngine::tempMessage;
|
||||
union pd_msg PolicyEngine::_last_dpm_request;
|
||||
PolicyEngine::policy_engine_state PolicyEngine::state = PESinkStartup;
|
||||
StaticQueue_t PolicyEngine::xStaticQueue;
|
||||
uint8_t PolicyEngine::ucQueueStorageArea[PDB_MSG_POOL_SIZE
|
||||
* sizeof(union pd_msg)];
|
||||
uint8_t PolicyEngine::ucQueueStorageArea[PDB_MSG_POOL_SIZE * sizeof(union pd_msg)];
|
||||
QueueHandle_t PolicyEngine::messagesWaiting = NULL;
|
||||
EventGroupHandle_t PolicyEngine::xEventGroupHandle = NULL;
|
||||
StaticEventGroup_t PolicyEngine::xCreatedEventGroup;
|
||||
void PolicyEngine::init() {
|
||||
messagesWaiting = xQueueCreateStatic(PDB_MSG_POOL_SIZE,
|
||||
sizeof(union pd_msg), ucQueueStorageArea, &xStaticQueue);
|
||||
messagesWaiting = xQueueCreateStatic(PDB_MSG_POOL_SIZE, sizeof(union pd_msg), ucQueueStorageArea, &xStaticQueue);
|
||||
// Create static thread at PDB_PRIO_PE priority
|
||||
osThreadStaticDef(PolEng, pe_task, PDB_PRIO_PE, 0, TaskStackSize,
|
||||
TaskBuffer, &TaskControlBlock);
|
||||
osThreadStaticDef(PolEng, pe_task, PDB_PRIO_PE, 0, TaskStackSize, TaskBuffer, &TaskControlBlock);
|
||||
TaskHandle = osThreadCreate(osThread(PolEng), NULL);
|
||||
xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup);
|
||||
}
|
||||
@@ -161,8 +158,7 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_wait_cap() {
|
||||
if (readMessage()) {
|
||||
evt = PDB_EVT_PE_MSG_RX_PEND;
|
||||
} else {
|
||||
evt = waitForEvent(
|
||||
PDB_EVT_PE_MSG_RX | PDB_EVT_PE_I_OVRTEMP | PDB_EVT_PE_RESET,
|
||||
evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_I_OVRTEMP | PDB_EVT_PE_RESET,
|
||||
// Wait for cap timeout
|
||||
PD_T_TYPEC_SINK_WAIT_CAP);
|
||||
}
|
||||
@@ -184,8 +180,7 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_wait_cap() {
|
||||
/* Get the message */
|
||||
while ((evt & PDB_EVT_PE_MSG_RX_PEND) || readMessage() == true) {
|
||||
/* If we got a Source_Capabilities message, read it. */
|
||||
if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOURCE_CAPABILITIES
|
||||
&& PD_NUMOBJ_GET(&tempMessage) > 0) {
|
||||
if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOURCE_CAPABILITIES && PD_NUMOBJ_GET(&tempMessage) > 0) {
|
||||
/* First, determine what PD revision we're using */
|
||||
if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_1_0) {
|
||||
/* If the other end is using at least version 3.0, we'll
|
||||
@@ -204,7 +199,6 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_wait_cap() {
|
||||
evt = 0;
|
||||
}
|
||||
return PESinkWaitCap; // wait for more messages?
|
||||
|
||||
}
|
||||
|
||||
/* If we failed to get a message, send a hard reset */
|
||||
@@ -220,8 +214,7 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_eval_cap() {
|
||||
_pps_index = 8;
|
||||
/* Search for the first PPS APDO */
|
||||
for (int8_t i = 0; i < PD_NUMOBJ_GET(&tempMessage); i++) {
|
||||
if ((tempMessage.obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_AUGMENTED
|
||||
&& (tempMessage.obj[i] & PD_APDO_TYPE) == PD_APDO_TYPE_PPS) {
|
||||
if ((tempMessage.obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_AUGMENTED && (tempMessage.obj[i] & PD_APDO_TYPE) == PD_APDO_TYPE_PPS) {
|
||||
_pps_index = i + 1;
|
||||
break;
|
||||
}
|
||||
@@ -245,10 +238,8 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_select_cap() {
|
||||
waitForEvent(0xFFFF, 0); // clear pending
|
||||
ProtocolTransmit::pushMessage(&_last_dpm_request);
|
||||
// Send indication that there is a message pending
|
||||
ProtocolTransmit::notify(
|
||||
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||
eventmask_t evt = waitForEvent(
|
||||
PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
||||
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||
eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
||||
/* If we got reset signaling, transition to default */
|
||||
if (evt & PDB_EVT_PE_RESET || evt == 0) {
|
||||
return PESinkTransitionDefault;
|
||||
@@ -259,8 +250,7 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_select_cap() {
|
||||
}
|
||||
|
||||
/* Wait for a response */
|
||||
evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET,
|
||||
PD_T_SENDER_RESPONSE);
|
||||
evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET, PD_T_SENDER_RESPONSE);
|
||||
/* If we got reset signaling, transition to default */
|
||||
if (evt & PDB_EVT_PE_RESET) {
|
||||
return PESinkTransitionDefault;
|
||||
@@ -274,18 +264,14 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_select_cap() {
|
||||
if (messageWaiting()) {
|
||||
readMessage();
|
||||
/* If the source accepted our request, wait for the new power */
|
||||
if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_ACCEPT
|
||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_ACCEPT && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
|
||||
return PESinkTransitionSink;
|
||||
/* If the message was a Soft_Reset, do the soft reset procedure */
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET
|
||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
return PESinkSoftReset;
|
||||
/* If the message was Wait or Reject */
|
||||
} else if ((PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_REJECT
|
||||
|| PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_WAIT)
|
||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
} else if ((PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_REJECT || PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_WAIT) && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
/* If we don't have an explicit contract, wait for capabilities */
|
||||
if (!_explicit_contract) {
|
||||
return PESinkWaitCap;
|
||||
@@ -302,8 +288,7 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_select_cap() {
|
||||
|
||||
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_transition_sink() {
|
||||
/* Wait for the PS_RDY message */
|
||||
eventmask_t evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET,
|
||||
PD_T_PS_TRANSITION);
|
||||
eventmask_t evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET, PD_T_PS_TRANSITION);
|
||||
/* If we got reset signaling, transition to default */
|
||||
if (evt & PDB_EVT_PE_RESET) {
|
||||
return PESinkTransitionDefault;
|
||||
@@ -317,8 +302,7 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_transition_sink() {
|
||||
if (messageWaiting()) {
|
||||
readMessage();
|
||||
/* If we got a PS_RDY, handle it */
|
||||
if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PS_RDY
|
||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PS_RDY && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
/* We just finished negotiating an explicit contract */
|
||||
_explicit_contract = true;
|
||||
|
||||
@@ -344,8 +328,7 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_ready() {
|
||||
eventmask_t evt;
|
||||
|
||||
/* Wait for an event */
|
||||
evt = waitForEvent(
|
||||
PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET | PDB_EVT_PE_I_OVRTEMP);
|
||||
evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET | PDB_EVT_PE_I_OVRTEMP);
|
||||
|
||||
/* If we got reset signaling, transition to default */
|
||||
if (evt & PDB_EVT_PE_RESET) {
|
||||
@@ -362,83 +345,65 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_ready() {
|
||||
if (messageWaiting()) {
|
||||
readMessage();
|
||||
/* Ignore vendor-defined messages */
|
||||
if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_VENDOR_DEFINED
|
||||
&& PD_NUMOBJ_GET(&tempMessage) > 0) {
|
||||
if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_VENDOR_DEFINED && PD_NUMOBJ_GET(&tempMessage) > 0) {
|
||||
|
||||
return PESinkReady;
|
||||
/* Ignore Ping messages */
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PING
|
||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PING && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
|
||||
return PESinkReady;
|
||||
/* DR_Swap messages are not supported */
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_DR_SWAP
|
||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_DR_SWAP && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
|
||||
return PESinkSendNotSupported;
|
||||
/* Get_Source_Cap messages are not supported */
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GET_SOURCE_CAP
|
||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GET_SOURCE_CAP && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
|
||||
return PESinkSendNotSupported;
|
||||
/* PR_Swap messages are not supported */
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PR_SWAP
|
||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_PR_SWAP && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
|
||||
return PESinkSendNotSupported;
|
||||
/* VCONN_Swap messages are not supported */
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_VCONN_SWAP
|
||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_VCONN_SWAP && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
|
||||
return PESinkSendNotSupported;
|
||||
/* Request messages are not supported */
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_REQUEST
|
||||
&& PD_NUMOBJ_GET(&tempMessage) > 0) {
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_REQUEST && PD_NUMOBJ_GET(&tempMessage) > 0) {
|
||||
|
||||
return PESinkSendNotSupported;
|
||||
/* Sink_Capabilities messages are not supported */
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage)
|
||||
== PD_MSGTYPE_SINK_CAPABILITIES
|
||||
&& PD_NUMOBJ_GET(&tempMessage) > 0) {
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SINK_CAPABILITIES && PD_NUMOBJ_GET(&tempMessage) > 0) {
|
||||
|
||||
return PESinkSendNotSupported;
|
||||
/* Handle GotoMin messages */
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GOTOMIN
|
||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GOTOMIN && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
/* GiveBack is not supported */
|
||||
return PESinkSendNotSupported;
|
||||
|
||||
/* Evaluate new Source_Capabilities */
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage)
|
||||
== PD_MSGTYPE_SOURCE_CAPABILITIES
|
||||
&& PD_NUMOBJ_GET(&tempMessage) > 0) {
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOURCE_CAPABILITIES && PD_NUMOBJ_GET(&tempMessage) > 0) {
|
||||
/* Don't free the message: we need to keep the
|
||||
* Source_Capabilities message so we can evaluate it. */
|
||||
return PESinkEvalCap;
|
||||
/* Give sink capabilities when asked */
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GET_SINK_CAP
|
||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_GET_SINK_CAP && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
|
||||
return PESinkGiveSinkCap;
|
||||
/* If the message was a Soft_Reset, do the soft reset procedure */
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET
|
||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
|
||||
return PESinkSoftReset;
|
||||
/* PD 3.0 messges */
|
||||
} else if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0) {
|
||||
/* If the message is a multi-chunk extended message, let it
|
||||
* time out. */
|
||||
if ((tempMessage.hdr & PD_HDR_EXT)
|
||||
&& (PD_DATA_SIZE_GET(&tempMessage)
|
||||
> PD_MAX_EXT_MSG_LEGACY_LEN)) {
|
||||
if ((tempMessage.hdr & PD_HDR_EXT) && (PD_DATA_SIZE_GET(&tempMessage) > PD_MAX_EXT_MSG_LEGACY_LEN)) {
|
||||
|
||||
return PESinkChunkReceived;
|
||||
/* Tell the DPM a message we sent got a response of
|
||||
* Not_Supported. */
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage)
|
||||
== PD_MSGTYPE_NOT_SUPPORTED
|
||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_NOT_SUPPORTED && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
|
||||
return PESinkNotSupportedReceived;
|
||||
/* If we got an unknown message, send a soft reset */
|
||||
@@ -461,14 +426,11 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_get_source_cap() {
|
||||
/* Get a message object */
|
||||
union pd_msg *get_source_cap = &tempMessage;
|
||||
/* Make a Get_Source_Cap message */
|
||||
get_source_cap->hdr = hdr_template | PD_MSGTYPE_GET_SOURCE_CAP
|
||||
| PD_NUMOBJ(0);
|
||||
get_source_cap->hdr = hdr_template | PD_MSGTYPE_GET_SOURCE_CAP | PD_NUMOBJ(0);
|
||||
/* Transmit the Get_Source_Cap */
|
||||
ProtocolTransmit::pushMessage(get_source_cap);
|
||||
ProtocolTransmit::notify(
|
||||
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||
eventmask_t evt = waitForEvent(
|
||||
PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
||||
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||
eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
||||
/* Free the sent message */
|
||||
/* If we got reset signaling, transition to default */
|
||||
if (evt & PDB_EVT_PE_RESET) {
|
||||
@@ -490,10 +452,8 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_give_sink_cap() {
|
||||
|
||||
/* Transmit our capabilities */
|
||||
ProtocolTransmit::pushMessage(snk_cap);
|
||||
ProtocolTransmit::notify(
|
||||
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||
eventmask_t evt = waitForEvent(
|
||||
PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
||||
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||
eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
||||
|
||||
/* Free the Sink_Capabilities message */
|
||||
|
||||
@@ -546,10 +506,8 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_soft_reset() {
|
||||
accept.hdr = hdr_template | PD_MSGTYPE_ACCEPT | PD_NUMOBJ(0);
|
||||
/* Transmit the Accept */
|
||||
ProtocolTransmit::pushMessage(&accept);
|
||||
ProtocolTransmit::notify(
|
||||
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||
eventmask_t evt = waitForEvent(
|
||||
PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
||||
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||
eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
||||
/* Free the sent message */
|
||||
|
||||
/* If we got reset signaling, transition to default */
|
||||
@@ -574,10 +532,8 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_send_soft_reset() {
|
||||
softrst->hdr = hdr_template | PD_MSGTYPE_SOFT_RESET | PD_NUMOBJ(0);
|
||||
/* Transmit the soft reset */
|
||||
ProtocolTransmit::pushMessage(softrst);
|
||||
ProtocolTransmit::notify(
|
||||
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||
eventmask_t evt = waitForEvent(
|
||||
PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
||||
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||
eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
||||
/* If we got reset signaling, transition to default */
|
||||
if (evt & PDB_EVT_PE_RESET) {
|
||||
return PESinkTransitionDefault;
|
||||
@@ -588,8 +544,7 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_send_soft_reset() {
|
||||
}
|
||||
|
||||
/* Wait for a response */
|
||||
evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET,
|
||||
PD_T_SENDER_RESPONSE);
|
||||
evt = waitForEvent(PDB_EVT_PE_MSG_RX | PDB_EVT_PE_RESET, PD_T_SENDER_RESPONSE);
|
||||
/* If we got reset signaling, transition to default */
|
||||
if (evt & PDB_EVT_PE_RESET) {
|
||||
return PESinkTransitionDefault;
|
||||
@@ -603,13 +558,11 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_send_soft_reset() {
|
||||
if (messageWaiting()) {
|
||||
readMessage();
|
||||
/* If the source accepted our soft reset, wait for capabilities. */
|
||||
if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_ACCEPT
|
||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_ACCEPT && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
|
||||
return PESinkWaitCap;
|
||||
/* If the message was a Soft_Reset, do the soft reset procedure */
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET
|
||||
&& PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
} else if (PD_MSGTYPE_GET(&tempMessage) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&tempMessage) == 0) {
|
||||
|
||||
return PESinkSoftReset;
|
||||
/* Otherwise, send a hard reset */
|
||||
@@ -630,16 +583,13 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_send_not_supported() {
|
||||
not_supported->hdr = hdr_template | PD_MSGTYPE_REJECT | PD_NUMOBJ(0);
|
||||
} else if ((hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0) {
|
||||
/* Make a Not_Supported message */
|
||||
not_supported->hdr = hdr_template | PD_MSGTYPE_NOT_SUPPORTED
|
||||
| PD_NUMOBJ(0);
|
||||
not_supported->hdr = hdr_template | PD_MSGTYPE_NOT_SUPPORTED | PD_NUMOBJ(0);
|
||||
}
|
||||
|
||||
/* Transmit the message */
|
||||
ProtocolTransmit::pushMessage(not_supported);
|
||||
ProtocolTransmit::notify(
|
||||
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||
eventmask_t evt = waitForEvent(
|
||||
PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
||||
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||
eventmask_t evt = waitForEvent(PDB_EVT_PE_TX_DONE | PDB_EVT_PE_TX_ERR | PDB_EVT_PE_RESET);
|
||||
|
||||
/* If we got reset signaling, transition to default */
|
||||
if (evt & PDB_EVT_PE_RESET) {
|
||||
@@ -656,8 +606,7 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_send_not_supported() {
|
||||
PolicyEngine::policy_engine_state PolicyEngine::pe_sink_chunk_received() {
|
||||
|
||||
/* Wait for tChunkingNotSupported */
|
||||
eventmask_t evt = waitForEvent(PDB_EVT_PE_RESET,
|
||||
PD_T_CHUNKING_NOT_SUPPORTED);
|
||||
eventmask_t evt = waitForEvent(PDB_EVT_PE_RESET, PD_T_CHUNKING_NOT_SUPPORTED);
|
||||
/* If we got reset signaling, transition to default */
|
||||
if (evt & PDB_EVT_PE_RESET) {
|
||||
return PESinkTransitionDefault;
|
||||
@@ -680,13 +629,6 @@ PolicyEngine::policy_engine_state PolicyEngine::pe_sink_source_unresponsive() {
|
||||
return PESinkSourceUnresponsive;
|
||||
}
|
||||
|
||||
uint32_t PolicyEngine::waitForEvent(uint32_t mask, TickType_t ticksToWait) {
|
||||
return xEventGroupWaitBits(xEventGroupHandle, mask, mask, pdFALSE,
|
||||
ticksToWait);
|
||||
|
||||
}
|
||||
|
||||
bool PolicyEngine::isPD3_0() {
|
||||
return (hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0;
|
||||
}
|
||||
uint32_t PolicyEngine::waitForEvent(uint32_t mask, TickType_t ticksToWait) { return xEventGroupWaitBits(xEventGroupHandle, mask, mask, pdFALSE, ticksToWait); }
|
||||
|
||||
bool PolicyEngine::isPD3_0() { return (hdr_template & PD_HDR_SPECREV) == PD_SPECREV_3_0; }
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
* Created on: 14 Jun 2020
|
||||
* Author: Ralim
|
||||
*/
|
||||
#include "BSP_PD.h"
|
||||
#include "pd.h"
|
||||
#include "policy_engine.h"
|
||||
#include "BSP_PD.h"
|
||||
/* The current draw when the output is disabled */
|
||||
#define DPM_MIN_CURRENT PD_MA2PDI(50)
|
||||
/*
|
||||
@@ -43,47 +43,36 @@ static int8_t dpm_get_range_fixed_pdo_index(const union pd_msg *caps) {
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
bool PolicyEngine::pdbs_dpm_evaluate_capability(
|
||||
const union pd_msg *capabilities, union pd_msg *request) {
|
||||
bool PolicyEngine::pdbs_dpm_evaluate_capability(const union pd_msg *capabilities, union pd_msg *request) {
|
||||
|
||||
/* Get the number of PDOs */
|
||||
uint8_t numobj = PD_NUMOBJ_GET(capabilities);
|
||||
|
||||
/* Get whether or not the power supply is constrained */
|
||||
_unconstrained_power =
|
||||
capabilities->obj[0] & PD_PDO_SRC_FIXED_UNCONSTRAINED;
|
||||
_unconstrained_power = capabilities->obj[0] & PD_PDO_SRC_FIXED_UNCONSTRAINED;
|
||||
|
||||
/* Make sure we have configuration */
|
||||
/* Look at the PDOs to see if one matches our desires */
|
||||
// Look against USB_PD_Desired_Levels to select in order of preference
|
||||
for (uint8_t desiredLevel = 0; desiredLevel < USB_PD_Desired_Levels_Len;
|
||||
desiredLevel++) {
|
||||
for (uint8_t desiredLevel = 0; desiredLevel < USB_PD_Desired_Levels_Len; desiredLevel++) {
|
||||
for (uint8_t i = 0; i < numobj; i++) {
|
||||
/* If we have a fixed PDO, its V equals our desired V, and its I is
|
||||
* at least our desired I */
|
||||
if ((capabilities->obj[i] & PD_PDO_TYPE) == PD_PDO_TYPE_FIXED) {
|
||||
// This is a fixed PDO entry
|
||||
int voltage = PD_PDV2MV(
|
||||
PD_PDO_SRC_FIXED_VOLTAGE_GET(capabilities->obj[i]));
|
||||
int current = PD_PDO_SRC_FIXED_CURRENT_GET(
|
||||
capabilities->obj[i]);
|
||||
uint16_t desiredVoltage = USB_PD_Desired_Levels[(desiredLevel
|
||||
* 2) + 0];
|
||||
uint16_t desiredminCurrent = USB_PD_Desired_Levels[(desiredLevel
|
||||
* 2) + 1];
|
||||
int voltage = PD_PDV2MV(PD_PDO_SRC_FIXED_VOLTAGE_GET(capabilities->obj[i]));
|
||||
int current = PD_PDO_SRC_FIXED_CURRENT_GET(capabilities->obj[i]);
|
||||
uint16_t desiredVoltage = USB_PD_Desired_Levels[(desiredLevel * 2) + 0];
|
||||
uint16_t desiredminCurrent = USB_PD_Desired_Levels[(desiredLevel * 2) + 1];
|
||||
// As pd stores current in 10mA increments, divide by 10
|
||||
desiredminCurrent /= 10;
|
||||
if (voltage == desiredVoltage) {
|
||||
if (current >= desiredminCurrent) {
|
||||
/* We got what we wanted, so build a request for that */
|
||||
request->hdr = hdr_template | PD_MSGTYPE_REQUEST
|
||||
| PD_NUMOBJ(1);
|
||||
request->hdr = hdr_template | PD_MSGTYPE_REQUEST | PD_NUMOBJ(1);
|
||||
|
||||
/* GiveBack disabled */
|
||||
request->obj[0] =
|
||||
PD_RDO_FV_MAX_CURRENT_SET(
|
||||
current) | PD_RDO_FV_CURRENT_SET(current)
|
||||
| PD_RDO_NO_USB_SUSPEND | PD_RDO_OBJPOS_SET(i + 1);
|
||||
request->obj[0] = PD_RDO_FV_MAX_CURRENT_SET(current) | PD_RDO_FV_CURRENT_SET(current) | PD_RDO_NO_USB_SUSPEND | PD_RDO_OBJPOS_SET(i + 1);
|
||||
// We support usb comms (ish)
|
||||
request->obj[0] |= PD_RDO_USB_COMMS;
|
||||
|
||||
@@ -94,16 +83,12 @@ bool PolicyEngine::pdbs_dpm_evaluate_capability(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* Nothing matched (or no configuration), so get 5 V at low current */
|
||||
request->hdr = hdr_template | PD_MSGTYPE_REQUEST | PD_NUMOBJ(1);
|
||||
request->obj[0] =
|
||||
PD_RDO_FV_MAX_CURRENT_SET(
|
||||
DPM_MIN_CURRENT) | PD_RDO_FV_CURRENT_SET(DPM_MIN_CURRENT) | PD_RDO_NO_USB_SUSPEND
|
||||
| PD_RDO_OBJPOS_SET(1);
|
||||
request->obj[0] = PD_RDO_FV_MAX_CURRENT_SET(DPM_MIN_CURRENT) | PD_RDO_FV_CURRENT_SET(DPM_MIN_CURRENT) | PD_RDO_NO_USB_SUSPEND | PD_RDO_OBJPOS_SET(1);
|
||||
/* If the output is enabled and we got here, it must be a capability
|
||||
* mismatch. */
|
||||
if (pdNegotiationComplete) {
|
||||
@@ -124,18 +109,13 @@ void PolicyEngine::pdbs_dpm_get_sink_capability(union pd_msg *cap) {
|
||||
/* If we have no configuration or want something other than 5 V, add a PDO
|
||||
* for vSafe5V */
|
||||
/* Minimum current, 5 V, and higher capability. */
|
||||
cap->obj[numobj++] =
|
||||
PD_PDO_TYPE_FIXED
|
||||
| PD_PDO_SNK_FIXED_VOLTAGE_SET(
|
||||
PD_MV2PDV(5000)) | PD_PDO_SNK_FIXED_CURRENT_SET(DPM_MIN_CURRENT);
|
||||
cap->obj[numobj++] = PD_PDO_TYPE_FIXED | PD_PDO_SNK_FIXED_VOLTAGE_SET(PD_MV2PDV(5000)) | PD_PDO_SNK_FIXED_CURRENT_SET(DPM_MIN_CURRENT);
|
||||
|
||||
/* Get the current we want */
|
||||
uint16_t current = USB_PD_Desired_Levels[1] / 10; // In centi-amps
|
||||
uint16_t voltage = USB_PD_Desired_Levels[0]; // in mv
|
||||
/* Add a PDO for the desired power. */
|
||||
cap->obj[numobj++] = PD_PDO_TYPE_FIXED
|
||||
| PD_PDO_SNK_FIXED_VOLTAGE_SET(
|
||||
PD_MV2PDV(voltage)) | PD_PDO_SNK_FIXED_CURRENT_SET(current);
|
||||
cap->obj[numobj++] = PD_PDO_TYPE_FIXED | PD_PDO_SNK_FIXED_VOLTAGE_SET(PD_MV2PDV(voltage)) | PD_PDO_SNK_FIXED_CURRENT_SET(current);
|
||||
|
||||
/* Get the PDO from the voltage range */
|
||||
int8_t i = dpm_get_range_fixed_pdo_index(cap);
|
||||
@@ -152,20 +132,13 @@ void PolicyEngine::pdbs_dpm_get_sink_capability(union pd_msg *cap) {
|
||||
|
||||
/* If the range PDO is a different voltage than the preferred
|
||||
* voltage, add it to the array. */
|
||||
if (i
|
||||
> 0&& PD_PDO_SRC_FIXED_VOLTAGE_GET(cap->obj[i]) != PD_MV2PDV(voltage)) {
|
||||
cap->obj[numobj++] =
|
||||
PD_PDO_TYPE_FIXED
|
||||
| PD_PDO_SNK_FIXED_VOLTAGE_SET(
|
||||
PD_PDO_SRC_FIXED_VOLTAGE_GET(cap->obj[i])) | PD_PDO_SNK_FIXED_CURRENT_SET(
|
||||
PD_PDO_SRC_FIXED_CURRENT_GET(cap->obj[i]));
|
||||
if (i > 0 && PD_PDO_SRC_FIXED_VOLTAGE_GET(cap->obj[i]) != PD_MV2PDV(voltage)) {
|
||||
cap->obj[numobj++] = PD_PDO_TYPE_FIXED | PD_PDO_SNK_FIXED_VOLTAGE_SET(PD_PDO_SRC_FIXED_VOLTAGE_GET(cap->obj[i])) | PD_PDO_SNK_FIXED_CURRENT_SET(PD_PDO_SRC_FIXED_CURRENT_GET(cap->obj[i]));
|
||||
}
|
||||
|
||||
/* If we have three PDOs at this point, make sure the last two are
|
||||
* sorted by voltage. */
|
||||
if (numobj == 3
|
||||
&& (cap->obj[1] & PD_PDO_SNK_FIXED_VOLTAGE)
|
||||
> (cap->obj[2] & PD_PDO_SNK_FIXED_VOLTAGE)) {
|
||||
if (numobj == 3 && (cap->obj[1] & PD_PDO_SNK_FIXED_VOLTAGE) > (cap->obj[2] & PD_PDO_SNK_FIXED_VOLTAGE)) {
|
||||
cap->obj[1] ^= cap->obj[2];
|
||||
cap->obj[2] ^= cap->obj[1];
|
||||
cap->obj[1] ^= cap->obj[2];
|
||||
@@ -183,8 +156,7 @@ void PolicyEngine::pdbs_dpm_get_sink_capability(union pd_msg *cap) {
|
||||
cap->hdr = hdr_template | PD_MSGTYPE_SINK_CAPABILITIES | PD_NUMOBJ(numobj);
|
||||
}
|
||||
|
||||
bool PolicyEngine::pdbs_dpm_evaluate_typec_current(
|
||||
enum fusb_typec_current tcc) {
|
||||
bool PolicyEngine::pdbs_dpm_evaluate_typec_current(enum fusb_typec_current tcc) {
|
||||
(void)tcc;
|
||||
// This is for evaluating 5V static current advertised by resistors
|
||||
/* We don't control the voltage anymore; it will always be 5 V. */
|
||||
@@ -208,17 +180,11 @@ void PolicyEngine::pdbs_dpm_transition_requested() {
|
||||
pdNegotiationComplete = true;
|
||||
}
|
||||
|
||||
void PolicyEngine::handleMessage(union pd_msg *msg) {
|
||||
xQueueSend(messagesWaiting, msg, 100);
|
||||
}
|
||||
void PolicyEngine::handleMessage(union pd_msg *msg) { xQueueSend(messagesWaiting, msg, 100); }
|
||||
|
||||
bool PolicyEngine::messageWaiting() {
|
||||
return uxQueueMessagesWaiting(messagesWaiting) > 0;
|
||||
}
|
||||
bool PolicyEngine::messageWaiting() { return uxQueueMessagesWaiting(messagesWaiting) > 0; }
|
||||
|
||||
bool PolicyEngine::readMessage() {
|
||||
return xQueueReceive(messagesWaiting, &tempMessage, 0) == pdTRUE;
|
||||
}
|
||||
bool PolicyEngine::readMessage() { return xQueueReceive(messagesWaiting, &tempMessage, 0) == pdTRUE; }
|
||||
|
||||
void PolicyEngine::pdbs_dpm_transition_typec() {
|
||||
// This means PD failed, so we either have a dump 5V only type C or a QC charger
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
|
||||
#include "protocol_rx.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "string.h"
|
||||
#include <pd.h>
|
||||
#include "fusb302b.h"
|
||||
#include "policy_engine.h"
|
||||
#include "protocol_tx.h"
|
||||
#include "fusb302b.h"
|
||||
#include "string.h"
|
||||
#include <pd.h>
|
||||
#include <stdlib.h>
|
||||
osThreadId ProtocolReceive::TaskHandle = NULL;
|
||||
EventGroupHandle_t ProtocolReceive::xEventGroupHandle = NULL;
|
||||
StaticEventGroup_t ProtocolReceive::xCreatedEventGroup;
|
||||
@@ -37,8 +37,7 @@ uint8_t ProtocolReceive::_tx_messageidcounter;
|
||||
ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_wait_phy() {
|
||||
/* Wait for an event */
|
||||
_rx_messageid = 0;
|
||||
eventmask_t evt = waitForEvent(
|
||||
PDB_EVT_PRLRX_RESET | PDB_EVT_PRLRX_I_GCRCSENT | PDB_EVT_PRLRX_I_RXPEND);
|
||||
eventmask_t evt = waitForEvent(PDB_EVT_PRLRX_RESET | PDB_EVT_PRLRX_I_GCRCSENT | PDB_EVT_PRLRX_I_RXPEND);
|
||||
|
||||
/* If we got a reset event, reset */
|
||||
if (evt & PDB_EVT_PRLRX_RESET) {
|
||||
@@ -54,8 +53,7 @@ ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_wait_phy() {
|
||||
/* Read the message */
|
||||
fusb_read_message(_rx_message);
|
||||
/* If it's a Soft_Reset, go to the soft reset state */
|
||||
if (PD_MSGTYPE_GET(_rx_message) == PD_MSGTYPE_SOFT_RESET
|
||||
&& PD_NUMOBJ_GET(_rx_message) == 0) {
|
||||
if (PD_MSGTYPE_GET(_rx_message) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(_rx_message) == 0) {
|
||||
return PRLRxReset;
|
||||
} else {
|
||||
/* Otherwise, check the message ID */
|
||||
@@ -83,8 +81,7 @@ ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_reset() {
|
||||
_rx_messageid = -1;
|
||||
|
||||
/* TX transitions to its reset state */
|
||||
ProtocolTransmit::notify(
|
||||
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_RESET);
|
||||
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_RESET);
|
||||
taskYIELD();
|
||||
|
||||
/* If we got a RESET signal, reset the machine */
|
||||
@@ -124,8 +121,7 @@ ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_check_messageid(
|
||||
ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_store_messageid() {
|
||||
/* Tell ProtocolTX to discard the message being transmitted */
|
||||
|
||||
ProtocolTransmit::notify(
|
||||
ProtocolTransmit::Notifications::PDB_EVT_PRLTX_DISCARD);
|
||||
ProtocolTransmit::notify(ProtocolTransmit::Notifications::PDB_EVT_PRLTX_DISCARD);
|
||||
|
||||
/* Update the stored MessageID */
|
||||
_rx_messageid = PD_MESSAGEID_GET(&tempMessage);
|
||||
@@ -141,8 +137,7 @@ ProtocolReceive::protocol_rx_state ProtocolReceive::protocol_rx_store_messageid(
|
||||
}
|
||||
|
||||
void ProtocolReceive::init() {
|
||||
osThreadStaticDef(protRX, thread, PDB_PRIO_PRL, 0, TaskStackSize,
|
||||
TaskBuffer, &TaskControlBlock);
|
||||
osThreadStaticDef(protRX, thread, PDB_PRIO_PRL, 0, TaskStackSize, TaskBuffer, &TaskControlBlock);
|
||||
xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup);
|
||||
TaskHandle = osThreadCreate(osThread(protRX), NULL);
|
||||
}
|
||||
@@ -182,8 +177,7 @@ void ProtocolReceive::notify(uint32_t notification) {
|
||||
|
||||
uint32_t ProtocolReceive::waitForEvent(uint32_t mask, TickType_t ticksToWait) {
|
||||
if (xEventGroupHandle != NULL) {
|
||||
return xEventGroupWaitBits(xEventGroupHandle, mask, mask,
|
||||
pdFALSE, ticksToWait);
|
||||
return xEventGroupWaitBits(xEventGroupHandle, mask, mask, pdFALSE, ticksToWait);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -16,19 +16,18 @@
|
||||
*/
|
||||
|
||||
#include "protocol_tx.h"
|
||||
#include <pd.h>
|
||||
#include "policy_engine.h"
|
||||
#include "protocol_rx.h"
|
||||
#include "fusb302b.h"
|
||||
#include "fusbpd.h"
|
||||
#include "policy_engine.h"
|
||||
#include "protocol_rx.h"
|
||||
#include <pd.h>
|
||||
|
||||
osThreadId ProtocolTransmit::TaskHandle = NULL;
|
||||
uint32_t ProtocolTransmit::TaskBuffer[ProtocolTransmit::TaskStackSize];
|
||||
osStaticThreadDef_t ProtocolTransmit::TaskControlBlock;
|
||||
StaticQueue_t ProtocolTransmit::xStaticQueue;
|
||||
bool ProtocolTransmit::messageSending = false;
|
||||
uint8_t ProtocolTransmit::ucQueueStorageArea[PDB_MSG_POOL_SIZE
|
||||
* sizeof(union pd_msg)];
|
||||
uint8_t ProtocolTransmit::ucQueueStorageArea[PDB_MSG_POOL_SIZE * sizeof(union pd_msg)];
|
||||
QueueHandle_t ProtocolTransmit::messagesWaiting = NULL;
|
||||
uint8_t ProtocolTransmit::_tx_messageidcounter;
|
||||
union pd_msg ProtocolTransmit::temp_msg;
|
||||
@@ -61,10 +60,7 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_phy_reset() {
|
||||
*/
|
||||
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_wait_message() {
|
||||
/* Wait for an event */
|
||||
ProtocolTransmit::Notifications evt = waitForEvent(
|
||||
(uint32_t) Notifications::PDB_EVT_PRLTX_RESET
|
||||
| (uint32_t) Notifications::PDB_EVT_PRLTX_DISCARD
|
||||
| (uint32_t) Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||
ProtocolTransmit::Notifications evt = waitForEvent((uint32_t)Notifications::PDB_EVT_PRLTX_RESET | (uint32_t)Notifications::PDB_EVT_PRLTX_DISCARD | (uint32_t)Notifications::PDB_EVT_PRLTX_MSG_TX);
|
||||
|
||||
if ((uint32_t)evt & (uint32_t)Notifications::PDB_EVT_PRLTX_RESET) {
|
||||
return PRLTxPHYReset;
|
||||
@@ -76,8 +72,7 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_wait_message()
|
||||
getMessage();
|
||||
|
||||
/* If it's a Soft_Reset, reset the TX layer first */
|
||||
if (PD_MSGTYPE_GET(&temp_msg) == PD_MSGTYPE_SOFT_RESET
|
||||
&& PD_NUMOBJ_GET(&(temp_msg)) == 0) {
|
||||
if (PD_MSGTYPE_GET(&temp_msg) == PD_MSGTYPE_SOFT_RESET && PD_NUMOBJ_GET(&(temp_msg)) == 0) {
|
||||
return PRLTxReset;
|
||||
/* Otherwise, just send the message */
|
||||
} else {
|
||||
@@ -133,10 +128,7 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_construct_mess
|
||||
ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_wait_response() {
|
||||
/* Wait for an event. There is no need to run CRCReceiveTimer, since the
|
||||
* FUSB302B handles that as part of its retry mechanism. */
|
||||
ProtocolTransmit::Notifications evt = waitForEvent(
|
||||
(uint32_t) Notifications::PDB_EVT_PRLTX_RESET
|
||||
| (uint32_t) Notifications::PDB_EVT_PRLTX_DISCARD
|
||||
| (uint32_t) Notifications::PDB_EVT_PRLTX_I_TXSENT
|
||||
ProtocolTransmit::Notifications evt = waitForEvent((uint32_t)Notifications::PDB_EVT_PRLTX_RESET | (uint32_t)Notifications::PDB_EVT_PRLTX_DISCARD | (uint32_t)Notifications::PDB_EVT_PRLTX_I_TXSENT
|
||||
| (uint32_t)Notifications::PDB_EVT_PRLTX_I_RETRYFAIL);
|
||||
|
||||
if ((uint32_t)evt & (uint32_t)Notifications::PDB_EVT_PRLTX_RESET) {
|
||||
@@ -169,9 +161,7 @@ ProtocolTransmit::protocol_tx_state ProtocolTransmit::protocol_tx_match_messagei
|
||||
fusb_read_message(&goodcrc);
|
||||
|
||||
/* Check that the message is correct */
|
||||
if (PD_MSGTYPE_GET(&goodcrc) == PD_MSGTYPE_GOODCRC
|
||||
&& PD_NUMOBJ_GET(&goodcrc) == 0
|
||||
&& PD_MESSAGEID_GET(&goodcrc) == _tx_messageidcounter) {
|
||||
if (PD_MSGTYPE_GET(&goodcrc) == PD_MSGTYPE_GOODCRC && PD_NUMOBJ_GET(&goodcrc) == 0 && PD_MESSAGEID_GET(&goodcrc) == _tx_messageidcounter) {
|
||||
return PRLTxMessageSent;
|
||||
} else {
|
||||
return PRLTxTransmissionError;
|
||||
@@ -258,11 +248,9 @@ void ProtocolTransmit::notify(ProtocolTransmit::Notifications notification) {
|
||||
}
|
||||
|
||||
void ProtocolTransmit::init() {
|
||||
messagesWaiting = xQueueCreateStatic(PDB_MSG_POOL_SIZE,
|
||||
sizeof(union pd_msg), ucQueueStorageArea, &xStaticQueue);
|
||||
messagesWaiting = xQueueCreateStatic(PDB_MSG_POOL_SIZE, sizeof(union pd_msg), ucQueueStorageArea, &xStaticQueue);
|
||||
|
||||
osThreadStaticDef(pd_txTask, thread, PDB_PRIO_PRL, 0, TaskStackSize,
|
||||
TaskBuffer, &TaskControlBlock);
|
||||
osThreadStaticDef(pd_txTask, thread, PDB_PRIO_PRL, 0, TaskStackSize, TaskBuffer, &TaskControlBlock);
|
||||
TaskHandle = osThreadCreate(osThread(pd_txTask), NULL);
|
||||
xEventGroupHandle = xEventGroupCreateStatic(&xCreatedEventGroup);
|
||||
}
|
||||
@@ -287,12 +275,9 @@ void ProtocolTransmit::getMessage() {
|
||||
}
|
||||
}
|
||||
|
||||
ProtocolTransmit::Notifications ProtocolTransmit::waitForEvent(uint32_t mask,
|
||||
TickType_t ticksToWait) {
|
||||
ProtocolTransmit::Notifications ProtocolTransmit::waitForEvent(uint32_t mask, TickType_t ticksToWait) {
|
||||
if (xEventGroupHandle) {
|
||||
return (Notifications) xEventGroupWaitBits(xEventGroupHandle, mask,
|
||||
mask,
|
||||
pdFALSE, ticksToWait);
|
||||
return (Notifications)xEventGroupWaitBits(xEventGroupHandle, mask, mask, pdFALSE, ticksToWait);
|
||||
}
|
||||
return (Notifications)0;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
*/
|
||||
#include "Model_Config.h"
|
||||
#ifdef I2C_SOFT
|
||||
#include <I2CBB.hpp>
|
||||
#include "FreeRTOS.h"
|
||||
#include <I2CBB.hpp>
|
||||
SemaphoreHandle_t I2CBB::I2CSemaphore = NULL;
|
||||
StaticSemaphore_t I2CBB::xSemaphoreBuffer;
|
||||
SemaphoreHandle_t I2CBB::I2CSemaphore2 = NULL;
|
||||
@@ -32,7 +32,6 @@ void I2CBB::init() {
|
||||
I2CSemaphore2 = xSemaphoreCreateMutexStatic(&xSemaphoreBuffer2);
|
||||
unlock();
|
||||
unlock2();
|
||||
|
||||
}
|
||||
|
||||
bool I2CBB::probe(uint8_t address) {
|
||||
@@ -45,8 +44,7 @@ bool I2CBB::probe(uint8_t address) {
|
||||
return ack;
|
||||
}
|
||||
|
||||
bool I2CBB::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData,
|
||||
uint16_t Size) {
|
||||
bool I2CBB::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData, uint16_t Size) {
|
||||
if (!lock())
|
||||
return false;
|
||||
start();
|
||||
@@ -82,8 +80,7 @@ bool I2CBB::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool I2CBB::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
|
||||
const uint8_t *pData, uint16_t Size) {
|
||||
bool I2CBB::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, const uint8_t *pData, uint16_t Size) {
|
||||
if (!lock())
|
||||
return false;
|
||||
start();
|
||||
@@ -140,7 +137,6 @@ void I2CBB::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
|
||||
}
|
||||
stop();
|
||||
unlock();
|
||||
|
||||
}
|
||||
|
||||
void I2CBB::Receive(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
|
||||
@@ -162,8 +158,7 @@ void I2CBB::Receive(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
|
||||
unlock();
|
||||
}
|
||||
|
||||
void I2CBB::TransmitReceive(uint16_t DevAddress, uint8_t *pData_tx,
|
||||
uint16_t Size_tx, uint8_t *pData_rx, uint16_t Size_rx) {
|
||||
void I2CBB::TransmitReceive(uint16_t DevAddress, uint8_t *pData_tx, uint16_t Size_tx, uint8_t *pData_rx, uint16_t Size_rx) {
|
||||
if (Size_tx == 0 && Size_rx == 0)
|
||||
return;
|
||||
if (lock() == false)
|
||||
@@ -273,9 +268,7 @@ uint8_t I2CBB::read_bit() {
|
||||
return b;
|
||||
}
|
||||
|
||||
void I2CBB::unlock() {
|
||||
xSemaphoreGive(I2CSemaphore);
|
||||
}
|
||||
void I2CBB::unlock() { xSemaphoreGive(I2CSemaphore); }
|
||||
|
||||
bool I2CBB::lock() {
|
||||
if (I2CSemaphore == NULL) {
|
||||
@@ -298,9 +291,7 @@ void I2CBB::write_bit(uint8_t val) {
|
||||
SOFT_SCL_LOW();
|
||||
}
|
||||
|
||||
void I2CBB::unlock2() {
|
||||
xSemaphoreGive(I2CSemaphore2);
|
||||
}
|
||||
void I2CBB::unlock2() { xSemaphoreGive(I2CSemaphore2); }
|
||||
|
||||
bool I2CBB::lock2() {
|
||||
if (I2CSemaphore2 == NULL) {
|
||||
|
||||
@@ -24,9 +24,7 @@ static const FRToSI2C::I2C_REG i2c_registers[] = { { LIS_CTRL_REG1, 0x17, 0 }, /
|
||||
{LIS_INT1_THS, 0x28, 0}, //
|
||||
{LIS_INT1_DURATION, 64, 0}};
|
||||
|
||||
bool LIS2DH12::initalize() {
|
||||
return FRToSI2C::writeRegistersBulk(LIS2DH_I2C_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
||||
}
|
||||
bool LIS2DH12::initalize() { return FRToSI2C::writeRegistersBulk(LIS2DH_I2C_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0])); }
|
||||
|
||||
void LIS2DH12::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
||||
std::array<int16_t, 3> sensorData;
|
||||
@@ -38,6 +36,4 @@ void LIS2DH12::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
||||
z = sensorData[2];
|
||||
}
|
||||
|
||||
bool LIS2DH12::detect() {
|
||||
return FRToSI2C::probe(LIS2DH_I2C_ADDRESS);
|
||||
}
|
||||
bool LIS2DH12::detect() { return FRToSI2C::probe(LIS2DH_I2C_ADDRESS); }
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
#include "MMA8652FC.hpp"
|
||||
#include "cmsis_os.h"
|
||||
|
||||
|
||||
static const FRToSI2C::I2C_REG i2c_registers[] = { { CTRL_REG2, 0, 0 }, //Normal mode
|
||||
static const FRToSI2C::I2C_REG i2c_registers[] = {
|
||||
{CTRL_REG2, 0, 0}, // Normal mode
|
||||
{CTRL_REG2, 0x40, 2}, // Reset all registers to POR values
|
||||
{FF_MT_CFG_REG, 0x78, 0}, // Enable motion detection for X, Y, Z axis, latch disabled
|
||||
{PL_CFG_REG, 0x40, 0}, // Enable the orientation detection
|
||||
@@ -26,15 +26,11 @@ static const FRToSI2C::I2C_REG i2c_registers[] = { { CTRL_REG2, 0, 0 }, //Nor
|
||||
{CTRL_REG1, 0x19, 0} // ODR=12 Hz, Active mode
|
||||
};
|
||||
|
||||
bool MMA8652FC::initalize() {
|
||||
return FRToSI2C::writeRegistersBulk(MMA8652FC_I2C_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
||||
|
||||
}
|
||||
bool MMA8652FC::initalize() { return FRToSI2C::writeRegistersBulk(MMA8652FC_I2C_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0])); }
|
||||
|
||||
Orientation MMA8652FC::getOrientation() {
|
||||
// First read the PL_STATUS register
|
||||
uint8_t plStatus = FRToSI2C::I2C_RegisterRead(MMA8652FC_I2C_ADDRESS,
|
||||
PL_STATUS_REG);
|
||||
uint8_t plStatus = FRToSI2C::I2C_RegisterRead(MMA8652FC_I2C_ADDRESS, PL_STATUS_REG);
|
||||
if ((plStatus & 0b10000000) == 0b10000000) {
|
||||
plStatus >>= 1; // We don't need the up/down bit
|
||||
plStatus &= 0x03; // mask to the two lower bits
|
||||
@@ -58,6 +54,4 @@ void MMA8652FC::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
||||
z = static_cast<int16_t>(__builtin_bswap16(*reinterpret_cast<uint16_t *>(&sensorData[2])));
|
||||
}
|
||||
|
||||
bool MMA8652FC::detect() {
|
||||
return FRToSI2C::probe(MMA8652FC_I2C_ADDRESS);
|
||||
}
|
||||
bool MMA8652FC::detect() { return FRToSI2C::probe(MMA8652FC_I2C_ADDRESS); }
|
||||
|
||||
@@ -5,14 +5,13 @@
|
||||
* Author: Ralim
|
||||
*/
|
||||
|
||||
#include <MSA301.h>
|
||||
#include "MSA301_defines.h"
|
||||
#include <MSA301.h>
|
||||
#define MSA301_I2C_ADDRESS 0x4C
|
||||
bool MSA301::detect() {
|
||||
return FRToSI2C::probe(MSA301_I2C_ADDRESS);
|
||||
}
|
||||
bool MSA301::detect() { return FRToSI2C::probe(MSA301_I2C_ADDRESS); }
|
||||
|
||||
static const FRToSI2C::I2C_REG i2c_registers[] = { //
|
||||
static const FRToSI2C::I2C_REG i2c_registers[] = {
|
||||
//
|
||||
//
|
||||
{MSA301_REG_ODR, 0b00001000, 1}, // X/Y/Z enabled @ 250Hz
|
||||
{MSA301_REG_POWERMODE, 0b0001001, 1}, // Normal mode
|
||||
@@ -22,9 +21,7 @@ static const FRToSI2C::I2C_REG i2c_registers[] = { //
|
||||
|
||||
};
|
||||
|
||||
bool MSA301::initalize() {
|
||||
return FRToSI2C::writeRegistersBulk(MSA301_I2C_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
||||
}
|
||||
bool MSA301::initalize() { return FRToSI2C::writeRegistersBulk(MSA301_I2C_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0])); }
|
||||
|
||||
Orientation MSA301::getOrientation() {
|
||||
uint8_t temp = 0;
|
||||
@@ -46,5 +43,4 @@ void MSA301::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
||||
x = int16_t(((int16_t)temp[1]) << 8 | temp[0]) >> 2;
|
||||
y = int16_t(((int16_t)temp[3]) << 8 | temp[2]) >> 2;
|
||||
z = int16_t(((int16_t)temp[5]) << 8 | temp[4]) >> 2;
|
||||
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
* Author: Ben V. Brown
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <OLED.hpp>
|
||||
#include <stdlib.h>
|
||||
#include "../../configuration.h"
|
||||
#include "Translation.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "../../configuration.h"
|
||||
#include <OLED.hpp>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
const uint8_t *OLED::currentFont; // Pointer to the current font used for
|
||||
// rendering to the buffer
|
||||
@@ -69,9 +69,7 @@ const uint8_t REFRESH_COMMANDS[17] = { 0x80, 0xAF, 0x80, 0x21, 0x80, 0x20, 0x80,
|
||||
* Returns a new percentage value with ease in and ease out.
|
||||
* Original floating point formula: t * t * (3.0f - 2.0f * t);
|
||||
*/
|
||||
static uint8_t easeInOutTiming(uint8_t t) {
|
||||
return t * t * (300 - 2 * t) / 10000;
|
||||
}
|
||||
static uint8_t easeInOutTiming(uint8_t t) { return t * t * (300 - 2 * t) / 10000; }
|
||||
|
||||
/*
|
||||
* Returns the value between a and b, using a percentage value t.
|
||||
@@ -79,9 +77,7 @@ static uint8_t easeInOutTiming(uint8_t t) {
|
||||
* @param b The value associated with 100%
|
||||
* @param t The percentage [0..<100]
|
||||
*/
|
||||
static uint8_t lerp(uint8_t a, uint8_t b, uint8_t t) {
|
||||
return a + t * (b - a) / 100;
|
||||
}
|
||||
static uint8_t lerp(uint8_t a, uint8_t b, uint8_t t) { return a + t * (b - a) / 100; }
|
||||
|
||||
void OLED::initialize() {
|
||||
cursor_x = cursor_y = 0;
|
||||
@@ -192,10 +188,8 @@ void OLED::transitionSecondaryFramebuffer(bool forwardNavigation) {
|
||||
|
||||
offset = progress;
|
||||
|
||||
memmove(&firstStripPtr[oldStart], &firstStripPtr[oldPrevious],
|
||||
OLED_WIDTH - progress);
|
||||
memmove(&secondStripPtr[oldStart], &secondStripPtr[oldPrevious],
|
||||
OLED_WIDTH - progress);
|
||||
memmove(&firstStripPtr[oldStart], &firstStripPtr[oldPrevious], OLED_WIDTH - progress);
|
||||
memmove(&secondStripPtr[oldStart], &secondStripPtr[oldPrevious], OLED_WIDTH - progress);
|
||||
|
||||
memmove(&firstStripPtr[newStart], &firstBackStripPtr[newEnd], progress);
|
||||
memmove(&secondStripPtr[newStart], &secondBackStripPtr[newEnd], progress);
|
||||
@@ -484,6 +478,4 @@ void OLED::drawHeatSymbol(uint8_t state) {
|
||||
drawFilledRect(cursor_x_temp, 0, cursor_x_temp + 12, 2 + (8 - state), true);
|
||||
}
|
||||
|
||||
bool OLED::isInitDone() {
|
||||
return initDone;
|
||||
}
|
||||
bool OLED::isInitDone() { return initDone; }
|
||||
|
||||
@@ -21,7 +21,8 @@ bool SC7A20::detect() {
|
||||
return false;
|
||||
}
|
||||
|
||||
static const FRToSI2C::I2C_REG i2c_registers[] = { //
|
||||
static const FRToSI2C::I2C_REG i2c_registers[] = {
|
||||
//
|
||||
//
|
||||
{SC7A20_CTRL_REG1, 0b01100111, 0}, // 200Hz, XYZ enabled
|
||||
{SC7A20_CTRL_REG2, 0b00000000, 0}, // Setup filter to 0x00 ??
|
||||
@@ -50,7 +51,6 @@ bool SC7A20::initalize() {
|
||||
// Theta blocking is set to 0b10
|
||||
|
||||
return FRToSI2C::writeRegistersBulk(SC7A20_ADDRESS, i2c_registers, sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
||||
|
||||
}
|
||||
|
||||
void SC7A20::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
||||
@@ -65,5 +65,4 @@ void SC7A20::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
||||
x = sensorData[0];
|
||||
y = sensorData[1];
|
||||
z = sensorData[2];
|
||||
|
||||
}
|
||||
|
||||
@@ -10,13 +10,10 @@
|
||||
* This class is licensed as MIT to match this code base
|
||||
*/
|
||||
|
||||
#include <Si7210.h>
|
||||
#include "Si7210_defines.h"
|
||||
#include "I2C_Wrapper.hpp"
|
||||
bool Si7210::detect() {
|
||||
return FRToSI2C::wakePart(SI7210_ADDRESS);
|
||||
|
||||
}
|
||||
#include "Si7210_defines.h"
|
||||
#include <Si7210.h>
|
||||
bool Si7210::detect() { return FRToSI2C::wakePart(SI7210_ADDRESS); }
|
||||
|
||||
bool Si7210::init() {
|
||||
// Turn on auto increment and sanity check ID
|
||||
@@ -57,7 +54,6 @@ bool Si7210::init() {
|
||||
return false;
|
||||
|
||||
return true; // start_periodic_measurement();
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -84,9 +80,7 @@ bool Si7210::write_reg(const uint8_t reg, const uint8_t mask, const uint8_t val)
|
||||
return FRToSI2C::Mem_Write(SI7210_ADDRESS, reg, &temp, 1);
|
||||
}
|
||||
|
||||
bool Si7210::read_reg(const uint8_t reg, uint8_t* val) {
|
||||
return FRToSI2C::Mem_Read(SI7210_ADDRESS, reg, val, 1);
|
||||
}
|
||||
bool Si7210::read_reg(const uint8_t reg, uint8_t *val) { return FRToSI2C::Mem_Read(SI7210_ADDRESS, reg, val, 1); }
|
||||
|
||||
bool Si7210::start_periodic_measurement() {
|
||||
/* Enable periodic wakeup */
|
||||
@@ -96,7 +90,6 @@ bool Si7210::start_periodic_measurement() {
|
||||
/* Start measurement */
|
||||
/* Change to ~STOP_MASK with STOP_MASK */
|
||||
return write_reg(SI7210_POWER_CTRL, MEAS_MASK | USESTORE_MASK, 0);
|
||||
|
||||
}
|
||||
|
||||
bool Si7210::get_field_strength(int16_t *field) {
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
*/
|
||||
|
||||
#include "TipThermoModel.h"
|
||||
#include "Settings.h"
|
||||
#include "BSP.h"
|
||||
#include "power.hpp"
|
||||
#include "../../configuration.h"
|
||||
#include "BSP.h"
|
||||
#include "Settings.h"
|
||||
#include "main.hpp"
|
||||
#include "power.hpp"
|
||||
/*
|
||||
* The hardware is laid out as a non-inverting op-amp
|
||||
* There is a pullup of 39k(TS100) from the +ve input to 3.9V (1M pulup on TS100)
|
||||
@@ -52,13 +52,9 @@ uint32_t TipThermoModel::convertTipRawADCTouV(uint16_t rawADC) {
|
||||
return valueuV;
|
||||
}
|
||||
|
||||
uint32_t TipThermoModel::convertTipRawADCToDegC(uint16_t rawADC) {
|
||||
return convertuVToDegC(convertTipRawADCTouV(rawADC));
|
||||
}
|
||||
uint32_t TipThermoModel::convertTipRawADCToDegC(uint16_t rawADC) { return convertuVToDegC(convertTipRawADCTouV(rawADC)); }
|
||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||
uint32_t TipThermoModel::convertTipRawADCToDegF(uint16_t rawADC) {
|
||||
return convertuVToDegF(convertTipRawADCTouV(rawADC));
|
||||
}
|
||||
uint32_t TipThermoModel::convertTipRawADCToDegF(uint16_t rawADC) { return convertuVToDegF(convertTipRawADCTouV(rawADC)); }
|
||||
#endif
|
||||
|
||||
// Table that is designed to be walked to find the best sample for the lookup
|
||||
@@ -68,11 +64,10 @@ uint32_t TipThermoModel::convertTipRawADCToDegF(uint16_t rawADC) {
|
||||
// [x2, y2] = point 2
|
||||
// x = input value
|
||||
// output is x's interpolated y value
|
||||
int32_t LinearInterpolate(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x) {
|
||||
return y1 + (((((x - x1) * 1000) / (x2 - x1)) * (y2 - y1))) / 1000;
|
||||
}
|
||||
int32_t LinearInterpolate(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x) { return y1 + (((((x - x1) * 1000) / (x2 - x1)) * (y2 - y1))) / 1000; }
|
||||
#ifdef TEMP_uV_LOOKUP_HAKKO
|
||||
const uint16_t uVtoDegC[] = { //
|
||||
const uint16_t uVtoDegC[] = {
|
||||
//
|
||||
//
|
||||
0, 0, //
|
||||
266, 10, //
|
||||
@@ -131,7 +126,8 @@ const uint16_t uVtoDegC[] = { //
|
||||
|
||||
#ifdef TEMP_uV_LOOKUP_TS80
|
||||
|
||||
const uint16_t uVtoDegC[] = { //
|
||||
const uint16_t uVtoDegC[] = {
|
||||
//
|
||||
//
|
||||
530, 0, //
|
||||
1282, 10, //
|
||||
@@ -201,9 +197,7 @@ uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) {
|
||||
}
|
||||
|
||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||
uint32_t TipThermoModel::convertuVToDegF(uint32_t tipuVDelta) {
|
||||
return convertCtoF(convertuVToDegC(tipuVDelta));
|
||||
}
|
||||
uint32_t TipThermoModel::convertuVToDegF(uint32_t tipuVDelta) { return convertCtoF(convertuVToDegC(tipuVDelta)); }
|
||||
|
||||
uint32_t TipThermoModel::convertCtoF(uint32_t degC) {
|
||||
//(Y °C × 9/5) + 32 =Y°F
|
||||
|
||||
@@ -7,25 +7,20 @@
|
||||
|
||||
#include "FreeRTOSHooks.h"
|
||||
#include "BSP.h"
|
||||
void vApplicationIdleHook(void) {
|
||||
resetWatchdog();
|
||||
}
|
||||
void vApplicationIdleHook(void) { resetWatchdog(); }
|
||||
|
||||
/* USER CODE BEGIN GET_IDLE_TASK_MEMORY */
|
||||
static StaticTask_t xIdleTaskTCBBuffer;
|
||||
static StackType_t xIdleStack[configMINIMAL_STACK_SIZE];
|
||||
|
||||
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer,
|
||||
StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize) {
|
||||
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize) {
|
||||
*ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer;
|
||||
*ppxIdleTaskStackBuffer = &xIdleStack[0];
|
||||
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
|
||||
/* place for user code */
|
||||
}
|
||||
|
||||
|
||||
void vApplicationStackOverflowHook(TaskHandle_t *pxTask,
|
||||
signed portCHAR *pcTaskName) {
|
||||
void vApplicationStackOverflowHook(TaskHandle_t *pxTask, signed portCHAR *pcTaskName) {
|
||||
(void)pxTask;
|
||||
(void)pcTaskName;
|
||||
|
||||
|
||||
@@ -175,9 +175,6 @@ void startQC(uint16_t divisor) {
|
||||
QCTries++;
|
||||
QCMode = QCState::NO_QC;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool hasQCNegotiated() {
|
||||
return QCMode == QCState::QC_3 || QCMode == QCState::QC_2;
|
||||
}
|
||||
bool hasQCNegotiated() { return QCMode == QCState::QC_3 || QCMode == QCState::QC_2; }
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
*/
|
||||
|
||||
#include "Settings.h"
|
||||
#include "Setup.h"
|
||||
#include "../../configuration.h"
|
||||
#include "BSP.h"
|
||||
#include "Setup.h"
|
||||
|
||||
#include "string.h"
|
||||
volatile systemSettingsType systemSettings;
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
*/
|
||||
|
||||
#include "gui.hpp"
|
||||
#include "../../configuration.h"
|
||||
#include "Buttons.hpp"
|
||||
#include "TipThermoModel.h"
|
||||
#include "Translation.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "main.hpp"
|
||||
#include "TipThermoModel.h"
|
||||
#include "string.h"
|
||||
#include "unit.h"
|
||||
#include "../../configuration.h"
|
||||
#include "Buttons.hpp"
|
||||
|
||||
void gui_Menu(const menuitem *menu);
|
||||
|
||||
@@ -169,8 +169,7 @@ const menuitem UIMenu[] = {
|
||||
* Reverse Temp change buttons + -
|
||||
*/
|
||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||
{ (const char *)SettingsDescriptions[5], settings_setTempF,
|
||||
settings_displayTempF}, /* Temperature units*/
|
||||
{(const char *)SettingsDescriptions[5], settings_setTempF, settings_displayTempF}, /* Temperature units*/
|
||||
#endif
|
||||
{(const char *)SettingsDescriptions[7], settings_setDisplayRotation, settings_displayDisplayRotation}, /*Display Rotation*/
|
||||
{(const char *)SettingsDescriptions[10], settings_setCoolingBlinkEnabled, settings_displayCoolingBlinkEnabled}, /*Cooling blink warning*/
|
||||
@@ -343,14 +342,12 @@ static void settings_displayQCInputV(void) {
|
||||
static bool settings_setSleepTemp(void) {
|
||||
// If in C, 10 deg, if in F 20 deg
|
||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||
if (systemSettings.temperatureInF)
|
||||
{
|
||||
if (systemSettings.temperatureInF) {
|
||||
systemSettings.SleepTemp += 20;
|
||||
if (systemSettings.SleepTemp > 580)
|
||||
systemSettings.SleepTemp = 60;
|
||||
return systemSettings.SleepTemp == 580;
|
||||
}
|
||||
else
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
systemSettings.SleepTemp += 10;
|
||||
@@ -409,20 +406,15 @@ static void settings_displayShutdownTime(void) {
|
||||
}
|
||||
}
|
||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||
static bool settings_setTempF(void)
|
||||
{
|
||||
static bool settings_setTempF(void) {
|
||||
systemSettings.temperatureInF = !systemSettings.temperatureInF;
|
||||
if (systemSettings.temperatureInF)
|
||||
{
|
||||
if (systemSettings.temperatureInF) {
|
||||
// Change sleep, boost and soldering temps to the F equiv
|
||||
// C to F == F= ( (C*9) +160)/5
|
||||
systemSettings.BoostTemp = ((systemSettings.BoostTemp * 9) + 160) / 5;
|
||||
systemSettings.SolderingTemp =
|
||||
((systemSettings.SolderingTemp * 9) + 160) / 5;
|
||||
systemSettings.SolderingTemp = ((systemSettings.SolderingTemp * 9) + 160) / 5;
|
||||
systemSettings.SleepTemp = ((systemSettings.SleepTemp * 9) + 160) / 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Change sleep, boost and soldering temps to the C equiv
|
||||
// F->C == C = ((F-32)*5)/9
|
||||
systemSettings.BoostTemp = ((systemSettings.BoostTemp - 32) * 5) / 9;
|
||||
@@ -439,8 +431,7 @@ static bool settings_setTempF(void)
|
||||
return false;
|
||||
}
|
||||
|
||||
static void settings_displayTempF(void)
|
||||
{
|
||||
static void settings_displayTempF(void) {
|
||||
printShortDescription(5, 7);
|
||||
|
||||
OLED::print((systemSettings.temperatureInF) ? SymbolDegF : SymbolDegC);
|
||||
@@ -550,24 +541,18 @@ static void settings_displayDisplayRotation(void) {
|
||||
|
||||
static bool settings_setBoostTemp(void) {
|
||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||
if (systemSettings.temperatureInF)
|
||||
{
|
||||
if (systemSettings.BoostTemp == 0)
|
||||
{
|
||||
if (systemSettings.temperatureInF) {
|
||||
if (systemSettings.BoostTemp == 0) {
|
||||
systemSettings.BoostTemp = 480; // loop back at 480
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
systemSettings.BoostTemp += 20; // Go up 20F at a time
|
||||
}
|
||||
|
||||
if (systemSettings.BoostTemp > 850)
|
||||
{
|
||||
if (systemSettings.BoostTemp > 850) {
|
||||
systemSettings.BoostTemp = 0; // jump to off
|
||||
}
|
||||
return systemSettings.BoostTemp == 840;
|
||||
}
|
||||
else
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if (systemSettings.BoostTemp == 0) {
|
||||
@@ -669,9 +654,7 @@ static bool settings_setResetSettings(void) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static void settings_displayResetSettings(void) {
|
||||
printShortDescription(12, 7);
|
||||
}
|
||||
static void settings_displayResetSettings(void) { printShortDescription(12, 7); }
|
||||
|
||||
static void setTipOffset() {
|
||||
systemSettings.CalibrationOffset = 0;
|
||||
@@ -714,9 +697,7 @@ static bool settings_setCalibrate(void) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static void settings_displayCalibrate(void) {
|
||||
printShortDescription(11, 5);
|
||||
}
|
||||
static void settings_displayCalibrate(void) { printShortDescription(11, 5); }
|
||||
|
||||
static bool settings_setCalibrateVIN(void) {
|
||||
// Jump to the voltage calibration subscreen
|
||||
@@ -759,12 +740,9 @@ static bool settings_setCalibrateVIN(void) {
|
||||
|
||||
// Cap to sensible values
|
||||
#if defined(MODEL_TS80) + defined(MODEL_TS80P) > 0
|
||||
if (systemSettings.voltageDiv < 500)
|
||||
{
|
||||
if (systemSettings.voltageDiv < 500) {
|
||||
systemSettings.voltageDiv = 500;
|
||||
}
|
||||
else if (systemSettings.voltageDiv > 900)
|
||||
{
|
||||
} else if (systemSettings.voltageDiv > 900) {
|
||||
systemSettings.voltageDiv = 900;
|
||||
}
|
||||
#else
|
||||
@@ -916,33 +894,23 @@ static void displayMenu(size_t index) {
|
||||
OLED::drawArea(96 - 16 - 2, 0, 16, 16, (&SettingsMenuIcons[(16 * 2) * index]));
|
||||
}
|
||||
|
||||
static void settings_displayCalibrateVIN(void) {
|
||||
printShortDescription(13, 5);
|
||||
}
|
||||
static void settings_displaySolderingMenu(void) {
|
||||
displayMenu(0);
|
||||
}
|
||||
static void settings_displayCalibrateVIN(void) { printShortDescription(13, 5); }
|
||||
static void settings_displaySolderingMenu(void) { displayMenu(0); }
|
||||
static bool settings_enterSolderingMenu(void) {
|
||||
gui_Menu(solderingMenu);
|
||||
return false;
|
||||
}
|
||||
static void settings_displayPowerMenu(void) {
|
||||
displayMenu(1);
|
||||
}
|
||||
static void settings_displayPowerMenu(void) { displayMenu(1); }
|
||||
static bool settings_enterPowerMenu(void) {
|
||||
gui_Menu(PowerMenu);
|
||||
return false;
|
||||
}
|
||||
static void settings_displayUIMenu(void) {
|
||||
displayMenu(2);
|
||||
}
|
||||
static void settings_displayUIMenu(void) { displayMenu(2); }
|
||||
static bool settings_enterUIMenu(void) {
|
||||
gui_Menu(UIMenu);
|
||||
return false;
|
||||
}
|
||||
static void settings_displayAdvancedMenu(void) {
|
||||
displayMenu(3);
|
||||
}
|
||||
static void settings_displayAdvancedMenu(void) { displayMenu(3); }
|
||||
static bool settings_enterAdvancedMenu(void) {
|
||||
gui_Menu(advancedMenu);
|
||||
return false;
|
||||
@@ -1004,8 +972,7 @@ void gui_Menu(const menuitem *menu) {
|
||||
if (descriptionStart == 0)
|
||||
descriptionStart = xTaskGetTickCount();
|
||||
// lower the value - higher the speed
|
||||
int16_t descriptionWidth =
|
||||
FONT_12_WIDTH * (strlen(menu[currentScreen].description) + 7);
|
||||
int16_t descriptionWidth = FONT_12_WIDTH * (strlen(menu[currentScreen].description) + 7);
|
||||
int16_t descriptionOffset = ((xTaskGetTickCount() - descriptionStart) / (systemSettings.descriptionScrollSpeed == 1 ? 10 : 20));
|
||||
descriptionOffset %= descriptionWidth; // Roll around at the end
|
||||
if (lastOffset != descriptionOffset) {
|
||||
@@ -1060,8 +1027,7 @@ void gui_Menu(const menuitem *menu) {
|
||||
descriptionStart = 0;
|
||||
break;
|
||||
case BUTTON_F_LONG:
|
||||
if ((int) (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration) >
|
||||
PRESS_ACCEL_INTERVAL_MAX) {
|
||||
if ((int)(xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration) > PRESS_ACCEL_INTERVAL_MAX) {
|
||||
if ((lastValue = menu[currentScreen].incrementHandler()))
|
||||
autoRepeatTimer = 1000;
|
||||
else
|
||||
@@ -1075,8 +1041,7 @@ void gui_Menu(const menuitem *menu) {
|
||||
}
|
||||
break;
|
||||
case BUTTON_B_LONG:
|
||||
if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration >
|
||||
PRESS_ACCEL_INTERVAL_MAX) {
|
||||
if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > PRESS_ACCEL_INTERVAL_MAX) {
|
||||
currentScreen++;
|
||||
autoRepeatTimer = xTaskGetTickCount();
|
||||
descriptionStart = 0;
|
||||
@@ -1089,10 +1054,8 @@ void gui_Menu(const menuitem *menu) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration) <
|
||||
PRESS_ACCEL_INTERVAL_MIN) {
|
||||
autoRepeatAcceleration =
|
||||
PRESS_ACCEL_INTERVAL_MAX - PRESS_ACCEL_INTERVAL_MIN;
|
||||
if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration) < PRESS_ACCEL_INTERVAL_MIN) {
|
||||
autoRepeatAcceleration = PRESS_ACCEL_INTERVAL_MAX - PRESS_ACCEL_INTERVAL_MIN;
|
||||
}
|
||||
|
||||
if (lcdRefresh) {
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
*/
|
||||
|
||||
#include "BSP.h"
|
||||
#include <main.hpp>
|
||||
#include "LIS2DH12.hpp"
|
||||
#include <MMA8652FC.hpp>
|
||||
#include <power.hpp>
|
||||
#include "Settings.h"
|
||||
#include "cmsis_os.h"
|
||||
#include <MMA8652FC.hpp>
|
||||
#include <main.hpp>
|
||||
#include <power.hpp>
|
||||
uint8_t DetectedAccelerometerVersion = 0;
|
||||
bool settingsWereReset = false;
|
||||
// FreeRTOS variables
|
||||
@@ -66,6 +66,5 @@ int main(void) {
|
||||
/* Start scheduler */
|
||||
osKernelStart();
|
||||
/* We should never get here as control is now taken by the scheduler */
|
||||
for (;;) {
|
||||
}
|
||||
for (;;) {}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
* Authors: Ben V. Brown, David Hilton <- Mostly David
|
||||
*/
|
||||
|
||||
#include <power.hpp>
|
||||
#include <Settings.h>
|
||||
#include <BSP.h>
|
||||
#include <Settings.h>
|
||||
#include <power.hpp>
|
||||
|
||||
static int32_t PWMToX10Watts(uint8_t pwm, uint8_t sample);
|
||||
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
/* Includes */
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/times.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
/* Functions */
|
||||
void initialise_monitor_handles() {
|
||||
}
|
||||
|
||||
int _getpid(void) {
|
||||
return 1;
|
||||
}
|
||||
void initialise_monitor_handles() {}
|
||||
|
||||
int _getpid(void) { return 1; }
|
||||
|
||||
@@ -200,8 +200,7 @@ static void gui_solderingTempAdjust() {
|
||||
return;
|
||||
break;
|
||||
case BUTTON_B_LONG:
|
||||
if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration >
|
||||
PRESS_ACCEL_INTERVAL_MAX) {
|
||||
if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > PRESS_ACCEL_INTERVAL_MAX) {
|
||||
if (systemSettings.ReverseButtonTempChangeEnabled) {
|
||||
systemSettings.SolderingTemp += systemSettings.TempChangeLongStep;
|
||||
} else
|
||||
@@ -218,8 +217,7 @@ static void gui_solderingTempAdjust() {
|
||||
systemSettings.SolderingTemp -= systemSettings.TempChangeShortStep;
|
||||
break;
|
||||
case BUTTON_F_LONG:
|
||||
if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration >
|
||||
PRESS_ACCEL_INTERVAL_MAX) {
|
||||
if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > PRESS_ACCEL_INTERVAL_MAX) {
|
||||
if (systemSettings.ReverseButtonTempChangeEnabled) {
|
||||
systemSettings.SolderingTemp -= systemSettings.TempChangeLongStep;
|
||||
} else
|
||||
@@ -237,10 +235,8 @@ static void gui_solderingTempAdjust() {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration) <
|
||||
PRESS_ACCEL_INTERVAL_MIN) {
|
||||
autoRepeatAcceleration =
|
||||
PRESS_ACCEL_INTERVAL_MAX - PRESS_ACCEL_INTERVAL_MIN;
|
||||
if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration) < PRESS_ACCEL_INTERVAL_MIN) {
|
||||
autoRepeatAcceleration = PRESS_ACCEL_INTERVAL_MAX - PRESS_ACCEL_INTERVAL_MIN;
|
||||
}
|
||||
// constrain between 10-450 C
|
||||
#ifdef ENABLED_FAHRENHEIT_SUPPORT
|
||||
@@ -531,8 +527,7 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
|
||||
if (oldTemp != systemSettings.SolderingTemp) {
|
||||
saveSettings(); // only save on change
|
||||
}
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
case BUTTON_BOTH_LONG:
|
||||
if (systemSettings.lockingMode != 0) {
|
||||
// Lock buttons
|
||||
@@ -871,8 +866,7 @@ void startGUITask(void const *argument __unused) {
|
||||
// This is zero cost really as state is only changed on display updates
|
||||
OLED::setDisplayState(OLED::DisplayState::ON);
|
||||
|
||||
if ((tipTemp < 50) && systemSettings.sensitivity && (((xTaskGetTickCount() - lastMovementTime) >
|
||||
MOVEMENT_INACTIVITY_TIME) && ((xTaskGetTickCount() - lastButtonTime) > BUTTON_INACTIVITY_TIME))) {
|
||||
if ((tipTemp < 50) && systemSettings.sensitivity && (((xTaskGetTickCount() - lastMovementTime) > MOVEMENT_INACTIVITY_TIME) && ((xTaskGetTickCount() - lastButtonTime) > BUTTON_INACTIVITY_TIME))) {
|
||||
OLED::setDisplayState(OLED::DisplayState::OFF);
|
||||
}
|
||||
uint16_t tipDisconnectedThres = TipThermoModel::getTipMaxInC() - 5;
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
#include "BMA223.hpp"
|
||||
#include "SC7A20.hpp"
|
||||
#include "BSP.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "I2C_Wrapper.hpp"
|
||||
@@ -14,6 +13,7 @@
|
||||
#include "MMA8652FC.hpp"
|
||||
#include "MSA301.h"
|
||||
#include "QC3.h"
|
||||
#include "SC7A20.hpp"
|
||||
#include "Settings.h"
|
||||
#include "TipThermoModel.h"
|
||||
#include "cmsis_os.h"
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
* Author: Ralim
|
||||
*/
|
||||
|
||||
#include "main.hpp"
|
||||
#include "BSP.h"
|
||||
#include "power.hpp"
|
||||
#include "history.hpp"
|
||||
#include "FreeRTOS.h"
|
||||
#include "Settings.h"
|
||||
#include "TipThermoModel.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "history.hpp"
|
||||
#include "main.hpp"
|
||||
#include "power.hpp"
|
||||
#include "task.h"
|
||||
#include "Settings.h"
|
||||
static TickType_t powerPulseRate = 10000;
|
||||
static TickType_t powerPulseDuration = 250;
|
||||
TaskHandle_t pidTaskNotification = NULL;
|
||||
@@ -89,21 +89,17 @@ void startPIDTask(void const *argument __unused) {
|
||||
// and counters extra power if the iron is no longer losing temp.
|
||||
// basically: temp - lastTemp
|
||||
// Unfortunately, our temp signal is too noisy to really help.
|
||||
|
||||
}
|
||||
// If the user turns on the option of using an occasional pulse to keep the power bank on
|
||||
if (systemSettings.KeepAwakePulse) {
|
||||
|
||||
if (xTaskGetTickCount() - lastPowerPulseStart
|
||||
> powerPulseRate) {
|
||||
if (xTaskGetTickCount() - lastPowerPulseStart > powerPulseRate) {
|
||||
lastPowerPulseStart = xTaskGetTickCount();
|
||||
lastPowerPulseEnd = lastPowerPulseStart
|
||||
+ powerPulseDuration;
|
||||
lastPowerPulseEnd = lastPowerPulseStart + powerPulseDuration;
|
||||
}
|
||||
|
||||
// If current PID is less than the pulse level, check if we want to constrain to the pulse as the floor
|
||||
if (x10WattsOut < systemSettings.KeepAwakePulse
|
||||
&& xTaskGetTickCount() < lastPowerPulseEnd) {
|
||||
if (x10WattsOut < systemSettings.KeepAwakePulse && xTaskGetTickCount() < lastPowerPulseEnd) {
|
||||
x10WattsOut = systemSettings.KeepAwakePulse;
|
||||
}
|
||||
}
|
||||
@@ -112,8 +108,7 @@ void startPIDTask(void const *argument __unused) {
|
||||
if (getTipRawTemp(0) > (0x7FFF - 150)) {
|
||||
x10WattsOut = 0;
|
||||
}
|
||||
if (systemSettings.powerLimit
|
||||
&& x10WattsOut > (systemSettings.powerLimit * 10)) {
|
||||
if (systemSettings.powerLimit && x10WattsOut > (systemSettings.powerLimit * 10)) {
|
||||
setTipX10Watts(systemSettings.powerLimit * 10);
|
||||
} else {
|
||||
setTipX10Watts(x10WattsOut);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -25,9 +25,9 @@
|
||||
* 1 tab == 4 spaces!
|
||||
*/
|
||||
|
||||
#include "croutine.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "croutine.h"
|
||||
|
||||
/* Remove the whole file is co-routines are not being used. */
|
||||
#if (configUSE_CO_ROUTINES != 0)
|
||||
@@ -40,14 +40,14 @@
|
||||
#define static
|
||||
#endif
|
||||
|
||||
|
||||
/* Lists for ready and blocked co-routines. --------------------*/
|
||||
static List_t pxReadyCoRoutineLists[configMAX_CO_ROUTINE_PRIORITIES]; /*< Prioritised ready co-routines. */
|
||||
static List_t xDelayedCoRoutineList1; /*< Delayed co-routines. */
|
||||
static List_t xDelayedCoRoutineList2; /*< Delayed co-routines (two lists are used - one for delays that have overflowed the current tick count. */
|
||||
static List_t *pxDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used. */
|
||||
static List_t *pxOverflowDelayedCoRoutineList; /*< Points to the delayed co-routine list currently being used to hold co-routines that have overflowed the current tick count. */
|
||||
static List_t xPendingReadyCoRoutineList; /*< Holds co-routines that have been readied by an external event. They cannot be added directly to the ready lists as the ready lists cannot be accessed by interrupts. */
|
||||
static List_t xPendingReadyCoRoutineList; /*< Holds co-routines that have been readied by an external event. They cannot be added directly to the ready lists as the ready lists cannot be accessed by
|
||||
interrupts. */
|
||||
|
||||
/* Other file private variables. --------------------------------*/
|
||||
CRCB_t * pxCurrentCoRoutine = NULL;
|
||||
@@ -66,8 +66,7 @@ static TickType_t xCoRoutineTickCount = 0, xLastTickCount = 0, xPassedTicks = 0;
|
||||
*/
|
||||
#define prvAddCoRoutineToReadyQueue(pxCRCB) \
|
||||
{ \
|
||||
if( pxCRCB->uxPriority > uxTopCoRoutineReadyPriority ) \
|
||||
{ \
|
||||
if (pxCRCB->uxPriority > uxTopCoRoutineReadyPriority) { \
|
||||
uxTopCoRoutineReadyPriority = pxCRCB->uxPriority; \
|
||||
} \
|
||||
vListInsertEnd((List_t *)&(pxReadyCoRoutineLists[pxCRCB->uxPriority]), &(pxCRCB->xGenericListItem)); \
|
||||
@@ -99,26 +98,22 @@ static void prvCheckDelayedList( void );
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
BaseType_t xCoRoutineCreate( crCOROUTINE_CODE pxCoRoutineCode, UBaseType_t uxPriority, UBaseType_t uxIndex )
|
||||
{
|
||||
BaseType_t xCoRoutineCreate(crCOROUTINE_CODE pxCoRoutineCode, UBaseType_t uxPriority, UBaseType_t uxIndex) {
|
||||
BaseType_t xReturn;
|
||||
CRCB_t * pxCoRoutine;
|
||||
|
||||
/* Allocate the memory that will store the co-routine control block. */
|
||||
pxCoRoutine = (CRCB_t *)pvPortMalloc(sizeof(CRCB_t));
|
||||
if( pxCoRoutine )
|
||||
{
|
||||
if (pxCoRoutine) {
|
||||
/* If pxCurrentCoRoutine is NULL then this is the first co-routine to
|
||||
be created and the co-routine data structures need initialising. */
|
||||
if( pxCurrentCoRoutine == NULL )
|
||||
{
|
||||
if (pxCurrentCoRoutine == NULL) {
|
||||
pxCurrentCoRoutine = pxCoRoutine;
|
||||
prvInitialiseCoRoutineLists();
|
||||
}
|
||||
|
||||
/* Check the priority is within limits. */
|
||||
if( uxPriority >= configMAX_CO_ROUTINE_PRIORITIES )
|
||||
{
|
||||
if (uxPriority >= configMAX_CO_ROUTINE_PRIORITIES) {
|
||||
uxPriority = configMAX_CO_ROUTINE_PRIORITIES - 1;
|
||||
}
|
||||
|
||||
@@ -146,9 +141,7 @@ CRCB_t *pxCoRoutine;
|
||||
prvAddCoRoutineToReadyQueue(pxCoRoutine);
|
||||
|
||||
xReturn = pdPASS;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
xReturn = errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY;
|
||||
}
|
||||
|
||||
@@ -156,8 +149,7 @@ CRCB_t *pxCoRoutine;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vCoRoutineAddToDelayedList( TickType_t xTicksToDelay, List_t *pxEventList )
|
||||
{
|
||||
void vCoRoutineAddToDelayedList(TickType_t xTicksToDelay, List_t *pxEventList) {
|
||||
TickType_t xTimeToWake;
|
||||
|
||||
/* Calculate the time to wake - this may overflow but this is
|
||||
@@ -172,21 +164,17 @@ TickType_t xTimeToWake;
|
||||
/* The list item will be inserted in wake time order. */
|
||||
listSET_LIST_ITEM_VALUE(&(pxCurrentCoRoutine->xGenericListItem), xTimeToWake);
|
||||
|
||||
if( xTimeToWake < xCoRoutineTickCount )
|
||||
{
|
||||
if (xTimeToWake < xCoRoutineTickCount) {
|
||||
/* Wake time has overflowed. Place this item in the
|
||||
overflow list. */
|
||||
vListInsert((List_t *)pxOverflowDelayedCoRoutineList, (ListItem_t *)&(pxCurrentCoRoutine->xGenericListItem));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* The wake time has not overflowed, so we can use the
|
||||
current block list. */
|
||||
vListInsert((List_t *)pxDelayedCoRoutineList, (ListItem_t *)&(pxCurrentCoRoutine->xGenericListItem));
|
||||
}
|
||||
|
||||
if( pxEventList )
|
||||
{
|
||||
if (pxEventList) {
|
||||
/* Also add the co-routine to an event list. If this is done then the
|
||||
function must be called with interrupts disabled. */
|
||||
vListInsert(pxEventList, &(pxCurrentCoRoutine->xEventListItem));
|
||||
@@ -194,13 +182,11 @@ TickType_t xTimeToWake;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvCheckPendingReadyList( void )
|
||||
{
|
||||
static void prvCheckPendingReadyList(void) {
|
||||
/* Are there any co-routines waiting to get moved to the ready list? These
|
||||
are co-routines that have been readied by an ISR. The ISR cannot access
|
||||
the ready lists itself. */
|
||||
while( listLIST_IS_EMPTY( &xPendingReadyCoRoutineList ) == pdFALSE )
|
||||
{
|
||||
while (listLIST_IS_EMPTY(&xPendingReadyCoRoutineList) == pdFALSE) {
|
||||
CRCB_t *pxUnblockedCRCB;
|
||||
|
||||
/* The pending ready list can be accessed by an ISR. */
|
||||
@@ -217,19 +203,16 @@ static void prvCheckPendingReadyList( void )
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvCheckDelayedList( void )
|
||||
{
|
||||
static void prvCheckDelayedList(void) {
|
||||
CRCB_t *pxCRCB;
|
||||
|
||||
xPassedTicks = xTaskGetTickCount() - xLastTickCount;
|
||||
while( xPassedTicks )
|
||||
{
|
||||
while (xPassedTicks) {
|
||||
xCoRoutineTickCount++;
|
||||
xPassedTicks--;
|
||||
|
||||
/* If the tick count has overflowed we need to swap the ready lists. */
|
||||
if( xCoRoutineTickCount == 0 )
|
||||
{
|
||||
if (xCoRoutineTickCount == 0) {
|
||||
List_t *pxTemp;
|
||||
|
||||
/* Tick count has overflowed so we need to swap the delay lists. If there are
|
||||
@@ -240,12 +223,10 @@ CRCB_t *pxCRCB;
|
||||
}
|
||||
|
||||
/* See if this tick has made a timeout expire. */
|
||||
while( listLIST_IS_EMPTY( pxDelayedCoRoutineList ) == pdFALSE )
|
||||
{
|
||||
while (listLIST_IS_EMPTY(pxDelayedCoRoutineList) == pdFALSE) {
|
||||
pxCRCB = (CRCB_t *)listGET_OWNER_OF_HEAD_ENTRY(pxDelayedCoRoutineList);
|
||||
|
||||
if( xCoRoutineTickCount < listGET_LIST_ITEM_VALUE( &( pxCRCB->xGenericListItem ) ) )
|
||||
{
|
||||
if (xCoRoutineTickCount < listGET_LIST_ITEM_VALUE(&(pxCRCB->xGenericListItem))) {
|
||||
/* Timeout not yet expired. */
|
||||
break;
|
||||
}
|
||||
@@ -260,8 +241,7 @@ CRCB_t *pxCRCB;
|
||||
(void)uxListRemove(&(pxCRCB->xGenericListItem));
|
||||
|
||||
/* Is the co-routine waiting on an event also? */
|
||||
if( pxCRCB->xEventListItem.pxContainer )
|
||||
{
|
||||
if (pxCRCB->xEventListItem.pxContainer) {
|
||||
(void)uxListRemove(&(pxCRCB->xEventListItem));
|
||||
}
|
||||
}
|
||||
@@ -275,8 +255,7 @@ CRCB_t *pxCRCB;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vCoRoutineSchedule( void )
|
||||
{
|
||||
void vCoRoutineSchedule(void) {
|
||||
/* See if any co-routines readied by events need moving to the ready lists. */
|
||||
prvCheckPendingReadyList();
|
||||
|
||||
@@ -284,10 +263,8 @@ void vCoRoutineSchedule( void )
|
||||
prvCheckDelayedList();
|
||||
|
||||
/* Find the highest priority queue that contains ready co-routines. */
|
||||
while( listLIST_IS_EMPTY( &( pxReadyCoRoutineLists[ uxTopCoRoutineReadyPriority ] ) ) )
|
||||
{
|
||||
if( uxTopCoRoutineReadyPriority == 0 )
|
||||
{
|
||||
while (listLIST_IS_EMPTY(&(pxReadyCoRoutineLists[uxTopCoRoutineReadyPriority]))) {
|
||||
if (uxTopCoRoutineReadyPriority == 0) {
|
||||
/* No more co-routines to check. */
|
||||
return;
|
||||
}
|
||||
@@ -305,12 +282,10 @@ void vCoRoutineSchedule( void )
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvInitialiseCoRoutineLists( void )
|
||||
{
|
||||
static void prvInitialiseCoRoutineLists(void) {
|
||||
UBaseType_t uxPriority;
|
||||
|
||||
for( uxPriority = 0; uxPriority < configMAX_CO_ROUTINE_PRIORITIES; uxPriority++ )
|
||||
{
|
||||
for (uxPriority = 0; uxPriority < configMAX_CO_ROUTINE_PRIORITIES; uxPriority++) {
|
||||
vListInitialise((List_t *)&(pxReadyCoRoutineLists[uxPriority]));
|
||||
}
|
||||
|
||||
@@ -325,8 +300,7 @@ UBaseType_t uxPriority;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
BaseType_t xCoRoutineRemoveFromEventList( const List_t *pxEventList )
|
||||
{
|
||||
BaseType_t xCoRoutineRemoveFromEventList(const List_t *pxEventList) {
|
||||
CRCB_t * pxUnblockedCRCB;
|
||||
BaseType_t xReturn;
|
||||
|
||||
@@ -337,12 +311,9 @@ BaseType_t xReturn;
|
||||
(void)uxListRemove(&(pxUnblockedCRCB->xEventListItem));
|
||||
vListInsertEnd((List_t *)&(xPendingReadyCoRoutineList), &(pxUnblockedCRCB->xEventListItem));
|
||||
|
||||
if( pxUnblockedCRCB->uxPriority >= pxCurrentCoRoutine->uxPriority )
|
||||
{
|
||||
if (pxUnblockedCRCB->uxPriority >= pxCurrentCoRoutine->uxPriority) {
|
||||
xReturn = pdTRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
xReturn = pdFALSE;
|
||||
}
|
||||
|
||||
@@ -350,4 +321,3 @@ BaseType_t xReturn;
|
||||
}
|
||||
|
||||
#endif /* configUSE_CO_ROUTINES == 0 */
|
||||
|
||||
|
||||
@@ -35,9 +35,9 @@ task.h is included from an application file. */
|
||||
|
||||
/* FreeRTOS includes. */
|
||||
#include "FreeRTOS.h"
|
||||
#include "event_groups.h"
|
||||
#include "task.h"
|
||||
#include "timers.h"
|
||||
#include "event_groups.h"
|
||||
|
||||
/* Lint e961, e750 and e9021 are suppressed as a MISRA exception justified
|
||||
because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined
|
||||
@@ -60,8 +60,7 @@ taskEVENT_LIST_ITEM_VALUE_IN_USE definition. */
|
||||
#define eventEVENT_BITS_CONTROL_BYTES 0xff000000UL
|
||||
#endif
|
||||
|
||||
typedef struct EventGroupDef_t
|
||||
{
|
||||
typedef struct EventGroupDef_t {
|
||||
EventBits_t uxEventBits;
|
||||
List_t xTasksWaitingForBits; /*< List of tasks waiting for a bit to be set. */
|
||||
|
||||
@@ -90,8 +89,7 @@ static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, co
|
||||
|
||||
#if (configSUPPORT_STATIC_ALLOCATION == 1)
|
||||
|
||||
EventGroupHandle_t xEventGroupCreateStatic( StaticEventGroup_t *pxEventGroupBuffer )
|
||||
{
|
||||
EventGroupHandle_t xEventGroupCreateStatic(StaticEventGroup_t *pxEventGroupBuffer) {
|
||||
EventGroup_t *pxEventBits;
|
||||
|
||||
/* A StaticEventGroup_t object must be provided. */
|
||||
@@ -108,10 +106,10 @@ static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, co
|
||||
#endif /* configASSERT_DEFINED */
|
||||
|
||||
/* The user has provided a statically allocated event group - use it. */
|
||||
pxEventBits = ( EventGroup_t * ) pxEventGroupBuffer; /*lint !e740 !e9087 EventGroup_t and StaticEventGroup_t are deliberately aliased for data hiding purposes and guaranteed to have the same size and alignment requirement - checked by configASSERT(). */
|
||||
pxEventBits = (EventGroup_t *)pxEventGroupBuffer; /*lint !e740 !e9087 EventGroup_t and StaticEventGroup_t are deliberately aliased for data hiding purposes and guaranteed to have the same size and
|
||||
alignment requirement - checked by configASSERT(). */
|
||||
|
||||
if( pxEventBits != NULL )
|
||||
{
|
||||
if (pxEventBits != NULL) {
|
||||
pxEventBits->uxEventBits = 0;
|
||||
vListInitialise(&(pxEventBits->xTasksWaitingForBits));
|
||||
|
||||
@@ -125,9 +123,7 @@ static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, co
|
||||
#endif /* configSUPPORT_DYNAMIC_ALLOCATION */
|
||||
|
||||
traceEVENT_GROUP_CREATE(pxEventBits);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* xEventGroupCreateStatic should only ever be called with
|
||||
pxEventGroupBuffer pointing to a pre-allocated (compile time
|
||||
allocated) StaticEventGroup_t variable. */
|
||||
@@ -142,8 +138,7 @@ static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, co
|
||||
|
||||
#if (configSUPPORT_DYNAMIC_ALLOCATION == 1)
|
||||
|
||||
EventGroupHandle_t xEventGroupCreate( void )
|
||||
{
|
||||
EventGroupHandle_t xEventGroupCreate(void) {
|
||||
EventGroup_t *pxEventBits;
|
||||
|
||||
/* Allocate the event group. Justification for MISRA deviation as
|
||||
@@ -161,8 +156,7 @@ static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, co
|
||||
of each individual read. */
|
||||
pxEventBits = (EventGroup_t *)pvPortMalloc(sizeof(EventGroup_t)); /*lint !e9087 !e9079 see comment above. */
|
||||
|
||||
if( pxEventBits != NULL )
|
||||
{
|
||||
if (pxEventBits != NULL) {
|
||||
pxEventBits->uxEventBits = 0;
|
||||
vListInitialise(&(pxEventBits->xTasksWaitingForBits));
|
||||
|
||||
@@ -176,9 +170,7 @@ static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, co
|
||||
#endif /* configSUPPORT_STATIC_ALLOCATION */
|
||||
|
||||
traceEVENT_GROUP_CREATE(pxEventBits);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
traceEVENT_GROUP_CREATE_FAILED(); /*lint !e9063 Else branch only exists to allow tracing and does not generate code if trace macros are not defined. */
|
||||
}
|
||||
|
||||
@@ -188,8 +180,7 @@ static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, co
|
||||
#endif /* configSUPPORT_DYNAMIC_ALLOCATION */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, const EventBits_t uxBitsToWaitFor, TickType_t xTicksToWait )
|
||||
{
|
||||
EventBits_t xEventGroupSync(EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, const EventBits_t uxBitsToWaitFor, TickType_t xTicksToWait) {
|
||||
EventBits_t uxOriginalBitValue, uxReturn;
|
||||
EventGroup_t *pxEventBits = xEventGroup;
|
||||
BaseType_t xAlreadyYielded;
|
||||
@@ -198,9 +189,7 @@ BaseType_t xTimeoutOccurred = pdFALSE;
|
||||
configASSERT((uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES) == 0);
|
||||
configASSERT(uxBitsToWaitFor != 0);
|
||||
#if ((INCLUDE_xTaskGetSchedulerState == 1) || (configUSE_TIMERS == 1))
|
||||
{
|
||||
configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
|
||||
}
|
||||
{ configASSERT(!((xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED) && (xTicksToWait != 0))); }
|
||||
#endif
|
||||
|
||||
vTaskSuspendAll();
|
||||
@@ -209,8 +198,7 @@ BaseType_t xTimeoutOccurred = pdFALSE;
|
||||
|
||||
(void)xEventGroupSetBits(xEventGroup, uxBitsToSet);
|
||||
|
||||
if( ( ( uxOriginalBitValue | uxBitsToSet ) & uxBitsToWaitFor ) == uxBitsToWaitFor )
|
||||
{
|
||||
if (((uxOriginalBitValue | uxBitsToSet) & uxBitsToWaitFor) == uxBitsToWaitFor) {
|
||||
/* All the rendezvous bits are now set - no need to block. */
|
||||
uxReturn = (uxOriginalBitValue | uxBitsToSet);
|
||||
|
||||
@@ -219,11 +207,8 @@ BaseType_t xTimeoutOccurred = pdFALSE;
|
||||
pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
|
||||
|
||||
xTicksToWait = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( xTicksToWait != ( TickType_t ) 0 )
|
||||
{
|
||||
} else {
|
||||
if (xTicksToWait != (TickType_t)0) {
|
||||
traceEVENT_GROUP_SYNC_BLOCK(xEventGroup, uxBitsToSet, uxBitsToWaitFor);
|
||||
|
||||
/* Store the bits that the calling task is waiting for in the
|
||||
@@ -236,9 +221,7 @@ BaseType_t xTimeoutOccurred = pdFALSE;
|
||||
warning about uxReturn being returned without being set if the
|
||||
assignment is omitted. */
|
||||
uxReturn = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* The rendezvous bits were not set, but no block time was
|
||||
specified - just return the current event bit value. */
|
||||
uxReturn = pxEventBits->uxEventBits;
|
||||
@@ -248,14 +231,10 @@ BaseType_t xTimeoutOccurred = pdFALSE;
|
||||
}
|
||||
xAlreadyYielded = xTaskResumeAll();
|
||||
|
||||
if( xTicksToWait != ( TickType_t ) 0 )
|
||||
{
|
||||
if( xAlreadyYielded == pdFALSE )
|
||||
{
|
||||
if (xTicksToWait != (TickType_t)0) {
|
||||
if (xAlreadyYielded == pdFALSE) {
|
||||
portYIELD_WITHIN_API();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
|
||||
@@ -265,8 +244,7 @@ BaseType_t xTimeoutOccurred = pdFALSE;
|
||||
event list item, and they should now be retrieved then cleared. */
|
||||
uxReturn = uxTaskResetEventItemValue();
|
||||
|
||||
if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 )
|
||||
{
|
||||
if ((uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET) == (EventBits_t)0) {
|
||||
/* The task timed out, just return the current event bit value. */
|
||||
taskENTER_CRITICAL();
|
||||
{
|
||||
@@ -276,21 +254,16 @@ BaseType_t xTimeoutOccurred = pdFALSE;
|
||||
bits it was waiting for were set, it is possible that since it
|
||||
unblocked another task has set the bits. If this is the case
|
||||
then it needs to clear the bits before exiting. */
|
||||
if( ( uxReturn & uxBitsToWaitFor ) == uxBitsToWaitFor )
|
||||
{
|
||||
if ((uxReturn & uxBitsToWaitFor) == uxBitsToWaitFor) {
|
||||
pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
|
||||
xTimeoutOccurred = pdTRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* The task unblocked because the bits were set. */
|
||||
}
|
||||
|
||||
@@ -308,8 +281,7 @@ BaseType_t xTimeoutOccurred = pdFALSE;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, const BaseType_t xClearOnExit, const BaseType_t xWaitForAllBits, TickType_t xTicksToWait )
|
||||
{
|
||||
EventBits_t xEventGroupWaitBits(EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, const BaseType_t xClearOnExit, const BaseType_t xWaitForAllBits, TickType_t xTicksToWait) {
|
||||
EventGroup_t *pxEventBits = xEventGroup;
|
||||
EventBits_t uxReturn, uxControlBits = 0;
|
||||
BaseType_t xWaitConditionMet, xAlreadyYielded;
|
||||
@@ -321,9 +293,7 @@ BaseType_t xTimeoutOccurred = pdFALSE;
|
||||
configASSERT((uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES) == 0);
|
||||
configASSERT(uxBitsToWaitFor != 0);
|
||||
#if ((INCLUDE_xTaskGetSchedulerState == 1) || (configUSE_TIMERS == 1))
|
||||
{
|
||||
configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
|
||||
}
|
||||
{ configASSERT(!((xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED) && (xTicksToWait != 0))); }
|
||||
#endif
|
||||
|
||||
vTaskSuspendAll();
|
||||
@@ -333,51 +303,37 @@ BaseType_t xTimeoutOccurred = pdFALSE;
|
||||
/* Check to see if the wait condition is already met or not. */
|
||||
xWaitConditionMet = prvTestWaitCondition(uxCurrentEventBits, uxBitsToWaitFor, xWaitForAllBits);
|
||||
|
||||
if( xWaitConditionMet != pdFALSE )
|
||||
{
|
||||
if (xWaitConditionMet != pdFALSE) {
|
||||
/* The wait condition has already been met so there is no need to
|
||||
block. */
|
||||
uxReturn = uxCurrentEventBits;
|
||||
xTicksToWait = (TickType_t)0;
|
||||
|
||||
/* Clear the wait bits if requested to do so. */
|
||||
if( xClearOnExit != pdFALSE )
|
||||
{
|
||||
if (xClearOnExit != pdFALSE) {
|
||||
pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
}
|
||||
else if( xTicksToWait == ( TickType_t ) 0 )
|
||||
{
|
||||
} else if (xTicksToWait == (TickType_t)0) {
|
||||
/* The wait condition has not been met, but no block time was
|
||||
specified, so just return the current value. */
|
||||
uxReturn = uxCurrentEventBits;
|
||||
xTimeoutOccurred = pdTRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* The task is going to block to wait for its required bits to be
|
||||
set. uxControlBits are used to remember the specified behaviour of
|
||||
this call to xEventGroupWaitBits() - for use when the event bits
|
||||
unblock the task. */
|
||||
if( xClearOnExit != pdFALSE )
|
||||
{
|
||||
if (xClearOnExit != pdFALSE) {
|
||||
uxControlBits |= eventCLEAR_EVENTS_ON_EXIT_BIT;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
|
||||
if( xWaitForAllBits != pdFALSE )
|
||||
{
|
||||
if (xWaitForAllBits != pdFALSE) {
|
||||
uxControlBits |= eventWAIT_FOR_ALL_BITS;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
|
||||
@@ -396,14 +352,10 @@ BaseType_t xTimeoutOccurred = pdFALSE;
|
||||
}
|
||||
xAlreadyYielded = xTaskResumeAll();
|
||||
|
||||
if( xTicksToWait != ( TickType_t ) 0 )
|
||||
{
|
||||
if( xAlreadyYielded == pdFALSE )
|
||||
{
|
||||
if (xTicksToWait != (TickType_t)0) {
|
||||
if (xAlreadyYielded == pdFALSE) {
|
||||
portYIELD_WITHIN_API();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
|
||||
@@ -413,8 +365,7 @@ BaseType_t xTimeoutOccurred = pdFALSE;
|
||||
event list item, and they should now be retrieved then cleared. */
|
||||
uxReturn = uxTaskResetEventItemValue();
|
||||
|
||||
if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 )
|
||||
{
|
||||
if ((uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET) == (EventBits_t)0) {
|
||||
taskENTER_CRITICAL();
|
||||
{
|
||||
/* The task timed out, just return the current event bit value. */
|
||||
@@ -422,27 +373,19 @@ BaseType_t xTimeoutOccurred = pdFALSE;
|
||||
|
||||
/* It is possible that the event bits were updated between this
|
||||
task leaving the Blocked state and running again. */
|
||||
if( prvTestWaitCondition( uxReturn, uxBitsToWaitFor, xWaitForAllBits ) != pdFALSE )
|
||||
{
|
||||
if( xClearOnExit != pdFALSE )
|
||||
{
|
||||
if (prvTestWaitCondition(uxReturn, uxBitsToWaitFor, xWaitForAllBits) != pdFALSE) {
|
||||
if (xClearOnExit != pdFALSE) {
|
||||
pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
xTimeoutOccurred = pdTRUE;
|
||||
}
|
||||
taskEXIT_CRITICAL();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* The task unblocked because the bits were set. */
|
||||
}
|
||||
|
||||
@@ -458,8 +401,7 @@ BaseType_t xTimeoutOccurred = pdFALSE;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear )
|
||||
{
|
||||
EventBits_t xEventGroupClearBits(EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear) {
|
||||
EventGroup_t *pxEventBits = xEventGroup;
|
||||
EventBits_t uxReturn;
|
||||
|
||||
@@ -487,12 +429,12 @@ EventBits_t uxReturn;
|
||||
|
||||
#if ((configUSE_TRACE_FACILITY == 1) && (INCLUDE_xTimerPendFunctionCall == 1) && (configUSE_TIMERS == 1))
|
||||
|
||||
BaseType_t xEventGroupClearBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear )
|
||||
{
|
||||
BaseType_t xEventGroupClearBitsFromISR(EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear) {
|
||||
BaseType_t xReturn;
|
||||
|
||||
traceEVENT_GROUP_CLEAR_BITS_FROM_ISR(xEventGroup, uxBitsToClear);
|
||||
xReturn = xTimerPendFunctionCallFromISR( vEventGroupClearBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToClear, NULL ); /*lint !e9087 Can't avoid cast to void* as a generic callback function not specific to this use case. Callback casts back to original type so safe. */
|
||||
xReturn = xTimerPendFunctionCallFromISR(vEventGroupClearBitsCallback, (void *)xEventGroup, (uint32_t)uxBitsToClear,
|
||||
NULL); /*lint !e9087 Can't avoid cast to void* as a generic callback function not specific to this use case. Callback casts back to original type so safe. */
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
@@ -500,24 +442,20 @@ EventBits_t uxReturn;
|
||||
#endif
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup )
|
||||
{
|
||||
EventBits_t xEventGroupGetBitsFromISR(EventGroupHandle_t xEventGroup) {
|
||||
UBaseType_t uxSavedInterruptStatus;
|
||||
EventGroup_t const *const pxEventBits = xEventGroup;
|
||||
EventBits_t uxReturn;
|
||||
|
||||
uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
|
||||
{
|
||||
uxReturn = pxEventBits->uxEventBits;
|
||||
}
|
||||
{ uxReturn = pxEventBits->uxEventBits; }
|
||||
portCLEAR_INTERRUPT_MASK_FROM_ISR(uxSavedInterruptStatus);
|
||||
|
||||
return uxReturn;
|
||||
} /*lint !e818 EventGroupHandle_t is a typedef used in other functions to so can't be pointer to const. */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
EventBits_t xEventGroupSetBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet )
|
||||
{
|
||||
EventBits_t xEventGroupSetBits(EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet) {
|
||||
ListItem_t * pxListItem, *pxNext;
|
||||
ListItem_t const *pxListEnd;
|
||||
List_t const * pxList;
|
||||
@@ -542,8 +480,7 @@ BaseType_t xMatchFound = pdFALSE;
|
||||
pxEventBits->uxEventBits |= uxBitsToSet;
|
||||
|
||||
/* See if the new bit value should unblock any tasks. */
|
||||
while( pxListItem != pxListEnd )
|
||||
{
|
||||
while (pxListItem != pxListEnd) {
|
||||
pxNext = listGET_NEXT(pxListItem);
|
||||
uxBitsWaitedFor = listGET_LIST_ITEM_VALUE(pxListItem);
|
||||
xMatchFound = pdFALSE;
|
||||
@@ -552,37 +489,25 @@ BaseType_t xMatchFound = pdFALSE;
|
||||
uxControlBits = uxBitsWaitedFor & eventEVENT_BITS_CONTROL_BYTES;
|
||||
uxBitsWaitedFor &= ~eventEVENT_BITS_CONTROL_BYTES;
|
||||
|
||||
if( ( uxControlBits & eventWAIT_FOR_ALL_BITS ) == ( EventBits_t ) 0 )
|
||||
{
|
||||
if ((uxControlBits & eventWAIT_FOR_ALL_BITS) == (EventBits_t)0) {
|
||||
/* Just looking for single bit being set. */
|
||||
if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) != ( EventBits_t ) 0 )
|
||||
{
|
||||
if ((uxBitsWaitedFor & pxEventBits->uxEventBits) != (EventBits_t)0) {
|
||||
xMatchFound = pdTRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
}
|
||||
else if( ( uxBitsWaitedFor & pxEventBits->uxEventBits ) == uxBitsWaitedFor )
|
||||
{
|
||||
} else if ((uxBitsWaitedFor & pxEventBits->uxEventBits) == uxBitsWaitedFor) {
|
||||
/* All bits are set. */
|
||||
xMatchFound = pdTRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Need all bits to be set, but not all the bits were set. */
|
||||
}
|
||||
|
||||
if( xMatchFound != pdFALSE )
|
||||
{
|
||||
if (xMatchFound != pdFALSE) {
|
||||
/* The bits match. Should the bits be cleared on exit? */
|
||||
if( ( uxControlBits & eventCLEAR_EVENTS_ON_EXIT_BIT ) != ( EventBits_t ) 0 )
|
||||
{
|
||||
if ((uxControlBits & eventCLEAR_EVENTS_ON_EXIT_BIT) != (EventBits_t)0) {
|
||||
uxBitsToClear |= uxBitsWaitedFor;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
|
||||
@@ -610,8 +535,7 @@ BaseType_t xMatchFound = pdFALSE;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vEventGroupDelete( EventGroupHandle_t xEventGroup )
|
||||
{
|
||||
void vEventGroupDelete(EventGroupHandle_t xEventGroup) {
|
||||
EventGroup_t *pxEventBits = xEventGroup;
|
||||
const List_t *pxTasksWaitingForBits = &(pxEventBits->xTasksWaitingForBits);
|
||||
|
||||
@@ -619,8 +543,7 @@ const List_t *pxTasksWaitingForBits = &( pxEventBits->xTasksWaitingForBits );
|
||||
{
|
||||
traceEVENT_GROUP_DELETE(xEventGroup);
|
||||
|
||||
while( listCURRENT_LIST_LENGTH( pxTasksWaitingForBits ) > ( UBaseType_t ) 0 )
|
||||
{
|
||||
while (listCURRENT_LIST_LENGTH(pxTasksWaitingForBits) > (UBaseType_t)0) {
|
||||
/* Unblock the task, returning 0 as the event list is being deleted
|
||||
and cannot therefore have any bits set. */
|
||||
configASSERT(pxTasksWaitingForBits->xListEnd.pxNext != (const ListItem_t *)&(pxTasksWaitingForBits->xListEnd));
|
||||
@@ -637,12 +560,9 @@ const List_t *pxTasksWaitingForBits = &( pxEventBits->xTasksWaitingForBits );
|
||||
{
|
||||
/* The event group could have been allocated statically or
|
||||
dynamically, so check before attempting to free the memory. */
|
||||
if( pxEventBits->ucStaticallyAllocated == ( uint8_t ) pdFALSE )
|
||||
{
|
||||
if (pxEventBits->ucStaticallyAllocated == (uint8_t)pdFALSE) {
|
||||
vPortFree(pxEventBits);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
}
|
||||
@@ -654,47 +574,35 @@ const List_t *pxTasksWaitingForBits = &( pxEventBits->xTasksWaitingForBits );
|
||||
|
||||
/* For internal use only - execute a 'set bits' command that was pended from
|
||||
an interrupt. */
|
||||
void vEventGroupSetBitsCallback( void *pvEventGroup, const uint32_t ulBitsToSet )
|
||||
{
|
||||
void vEventGroupSetBitsCallback(void *pvEventGroup, const uint32_t ulBitsToSet) {
|
||||
(void)xEventGroupSetBits(pvEventGroup, (EventBits_t)ulBitsToSet); /*lint !e9079 Can't avoid cast to void* as a generic timer callback prototype. Callback casts back to original type so safe. */
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* For internal use only - execute a 'clear bits' command that was pended from
|
||||
an interrupt. */
|
||||
void vEventGroupClearBitsCallback( void *pvEventGroup, const uint32_t ulBitsToClear )
|
||||
{
|
||||
void vEventGroupClearBitsCallback(void *pvEventGroup, const uint32_t ulBitsToClear) {
|
||||
(void)xEventGroupClearBits(pvEventGroup, (EventBits_t)ulBitsToClear); /*lint !e9079 Can't avoid cast to void* as a generic timer callback prototype. Callback casts back to original type so safe. */
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static BaseType_t prvTestWaitCondition( const EventBits_t uxCurrentEventBits, const EventBits_t uxBitsToWaitFor, const BaseType_t xWaitForAllBits )
|
||||
{
|
||||
static BaseType_t prvTestWaitCondition(const EventBits_t uxCurrentEventBits, const EventBits_t uxBitsToWaitFor, const BaseType_t xWaitForAllBits) {
|
||||
BaseType_t xWaitConditionMet = pdFALSE;
|
||||
|
||||
if( xWaitForAllBits == pdFALSE )
|
||||
{
|
||||
if (xWaitForAllBits == pdFALSE) {
|
||||
/* Task only has to wait for one bit within uxBitsToWaitFor to be
|
||||
set. Is one already set? */
|
||||
if( ( uxCurrentEventBits & uxBitsToWaitFor ) != ( EventBits_t ) 0 )
|
||||
{
|
||||
if ((uxCurrentEventBits & uxBitsToWaitFor) != (EventBits_t)0) {
|
||||
xWaitConditionMet = pdTRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Task has to wait for all the bits in uxBitsToWaitFor to be set.
|
||||
Are they set already? */
|
||||
if( ( uxCurrentEventBits & uxBitsToWaitFor ) == uxBitsToWaitFor )
|
||||
{
|
||||
if ((uxCurrentEventBits & uxBitsToWaitFor) == uxBitsToWaitFor) {
|
||||
xWaitConditionMet = pdTRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
}
|
||||
@@ -705,12 +613,13 @@ BaseType_t xWaitConditionMet = pdFALSE;
|
||||
|
||||
#if ((configUSE_TRACE_FACILITY == 1) && (INCLUDE_xTimerPendFunctionCall == 1) && (configUSE_TIMERS == 1))
|
||||
|
||||
BaseType_t xEventGroupSetBitsFromISR( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken )
|
||||
{
|
||||
BaseType_t xEventGroupSetBitsFromISR(EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken) {
|
||||
BaseType_t xReturn;
|
||||
|
||||
traceEVENT_GROUP_SET_BITS_FROM_ISR(xEventGroup, uxBitsToSet);
|
||||
xReturn = xTimerPendFunctionCallFromISR( vEventGroupSetBitsCallback, ( void * ) xEventGroup, ( uint32_t ) uxBitsToSet, pxHigherPriorityTaskWoken ); /*lint !e9087 Can't avoid cast to void* as a generic callback function not specific to this use case. Callback casts back to original type so safe. */
|
||||
xReturn = xTimerPendFunctionCallFromISR(
|
||||
vEventGroupSetBitsCallback, (void *)xEventGroup, (uint32_t)uxBitsToSet,
|
||||
pxHigherPriorityTaskWoken); /*lint !e9087 Can't avoid cast to void* as a generic callback function not specific to this use case. Callback casts back to original type so safe. */
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
@@ -720,17 +629,14 @@ BaseType_t xWaitConditionMet = pdFALSE;
|
||||
|
||||
#if (configUSE_TRACE_FACILITY == 1)
|
||||
|
||||
UBaseType_t uxEventGroupGetNumber( void* xEventGroup )
|
||||
{
|
||||
UBaseType_t uxEventGroupGetNumber(void *xEventGroup) {
|
||||
UBaseType_t xReturn;
|
||||
EventGroup_t const *pxEventBits = ( EventGroup_t * ) xEventGroup; /*lint !e9087 !e9079 EventGroupHandle_t is a pointer to an EventGroup_t, but EventGroupHandle_t is kept opaque outside of this file for data hiding purposes. */
|
||||
EventGroup_t const *pxEventBits
|
||||
= (EventGroup_t *)xEventGroup; /*lint !e9087 !e9079 EventGroupHandle_t is a pointer to an EventGroup_t, but EventGroupHandle_t is kept opaque outside of this file for data hiding purposes. */
|
||||
|
||||
if( xEventGroup == NULL )
|
||||
{
|
||||
if (xEventGroup == NULL) {
|
||||
xReturn = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
xReturn = pxEventBits->uxEventGroupNumber;
|
||||
}
|
||||
|
||||
@@ -742,12 +648,10 @@ BaseType_t xWaitConditionMet = pdFALSE;
|
||||
|
||||
#if (configUSE_TRACE_FACILITY == 1)
|
||||
|
||||
void vEventGroupSetNumber( void * xEventGroup, UBaseType_t uxEventGroupNumber )
|
||||
{
|
||||
( ( EventGroup_t * ) xEventGroup )->uxEventGroupNumber = uxEventGroupNumber; /*lint !e9087 !e9079 EventGroupHandle_t is a pointer to an EventGroup_t, but EventGroupHandle_t is kept opaque outside of this file for data hiding purposes. */
|
||||
void vEventGroupSetNumber(void *xEventGroup, UBaseType_t uxEventGroupNumber) {
|
||||
((EventGroup_t *)xEventGroup)->uxEventGroupNumber
|
||||
= uxEventGroupNumber; /*lint !e9087 !e9079 EventGroupHandle_t is a pointer to an EventGroup_t, but EventGroupHandle_t is kept opaque outside of this file for data hiding purposes. */
|
||||
}
|
||||
|
||||
#endif /* configUSE_TRACE_FACILITY */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
@@ -25,17 +25,15 @@
|
||||
* 1 tab == 4 spaces!
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "FreeRTOS.h"
|
||||
#include "list.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
/*-----------------------------------------------------------
|
||||
* PUBLIC LIST API documented in list.h
|
||||
*----------------------------------------------------------*/
|
||||
|
||||
void vListInitialise( List_t * const pxList )
|
||||
{
|
||||
void vListInitialise(List_t *const pxList) {
|
||||
/* The list structure contains a list item which is used to mark the
|
||||
end of the list. To initialise the list the list end is inserted
|
||||
as the only list entry. */
|
||||
@@ -59,8 +57,7 @@ void vListInitialise( List_t * const pxList )
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vListInitialiseItem( ListItem_t * const pxItem )
|
||||
{
|
||||
void vListInitialiseItem(ListItem_t *const pxItem) {
|
||||
/* Make sure the list item is not recorded as being on a list. */
|
||||
pxItem->pxContainer = NULL;
|
||||
|
||||
@@ -71,8 +68,7 @@ void vListInitialiseItem( ListItem_t * const pxItem )
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem )
|
||||
{
|
||||
void vListInsertEnd(List_t *const pxList, ListItem_t *const pxNewListItem) {
|
||||
ListItem_t *const pxIndex = pxList->pxIndex;
|
||||
|
||||
/* Only effective when configASSERT() is also defined, these tests may catch
|
||||
@@ -100,8 +96,7 @@ ListItem_t * const pxIndex = pxList->pxIndex;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vListInsert( List_t * const pxList, ListItem_t * const pxNewListItem )
|
||||
{
|
||||
void vListInsert(List_t *const pxList, ListItem_t *const pxNewListItem) {
|
||||
ListItem_t * pxIterator;
|
||||
const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;
|
||||
|
||||
@@ -119,12 +114,9 @@ const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;
|
||||
share of the CPU. However, if the xItemValue is the same as the back marker
|
||||
the iteration loop below will not end. Therefore the value is checked
|
||||
first, and the algorithm slightly modified if necessary. */
|
||||
if( xValueOfInsertion == portMAX_DELAY )
|
||||
{
|
||||
if (xValueOfInsertion == portMAX_DELAY) {
|
||||
pxIterator = pxList->xListEnd.pxPrevious;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* *** NOTE ***********************************************************
|
||||
If you find your application is crashing here then likely causes are
|
||||
listed below. In addition see https://www.freertos.org/FAQHelp.html for
|
||||
@@ -147,7 +139,10 @@ const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;
|
||||
before vTaskStartScheduler() has been called?).
|
||||
**********************************************************************/
|
||||
|
||||
for( pxIterator = ( ListItem_t * ) &( pxList->xListEnd ); pxIterator->pxNext->xItemValue <= xValueOfInsertion; pxIterator = pxIterator->pxNext ) /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. *//*lint !e440 The iterator moves to a different value, not xValueOfInsertion. */
|
||||
for (pxIterator = (ListItem_t *)&(pxList->xListEnd); pxIterator->pxNext->xItemValue <= xValueOfInsertion;
|
||||
pxIterator
|
||||
= pxIterator->pxNext) /*lint !e826 !e740 !e9087 The mini list structure is used as the list end to save RAM. This is checked and valid. */ /*lint !e440 The iterator moves to a
|
||||
different value, not xValueOfInsertion. */
|
||||
{
|
||||
/* There is nothing to do here, just iterating to the wanted
|
||||
insertion position. */
|
||||
@@ -167,8 +162,7 @@ const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
UBaseType_t uxListRemove( ListItem_t * const pxItemToRemove )
|
||||
{
|
||||
UBaseType_t uxListRemove(ListItem_t *const pxItemToRemove) {
|
||||
/* The list item knows which list it is in. Obtain the list from the list
|
||||
item. */
|
||||
List_t *const pxList = pxItemToRemove->pxContainer;
|
||||
@@ -180,12 +174,9 @@ List_t * const pxList = pxItemToRemove->pxContainer;
|
||||
mtCOVERAGE_TEST_DELAY();
|
||||
|
||||
/* Make sure the index is left pointing to a valid item. */
|
||||
if( pxList->pxIndex == pxItemToRemove )
|
||||
{
|
||||
if (pxList->pxIndex == pxItemToRemove) {
|
||||
pxList->pxIndex = pxItemToRemove->pxPrevious;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
|
||||
@@ -195,4 +186,3 @@ List_t * const pxList = pxItemToRemove->pxContainer;
|
||||
return pxList->uxNumberOfItems;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
||||
1225
source/Middlewares/Third_Party/FreeRTOS/Source/queue.c
vendored
1225
source/Middlewares/Third_Party/FreeRTOS/Source/queue.c
vendored
File diff suppressed because it is too large
Load Diff
1848
source/Middlewares/Third_Party/FreeRTOS/Source/tasks.c
vendored
1848
source/Middlewares/Third_Party/FreeRTOS/Source/tasks.c
vendored
File diff suppressed because it is too large
Load Diff
@@ -34,8 +34,8 @@ task.h is included from an application file. */
|
||||
#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "queue.h"
|
||||
#include "task.h"
|
||||
#include "timers.h"
|
||||
|
||||
#if (INCLUDE_xTimerPendFunctionCall == 1) && (configUSE_TIMERS == 0)
|
||||
@@ -48,7 +48,6 @@ for the header files above, but not in this file, in order to generate the
|
||||
correct privileged Vs unprivileged linkage and placement. */
|
||||
#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e9021 !e961 !e750. */
|
||||
|
||||
|
||||
/* This entire source file will be skipped if the application is not configured
|
||||
to include software timer functionality. This #if is closed at the very bottom
|
||||
of this file. If you want to include software timer functionality then ensure
|
||||
@@ -72,7 +71,8 @@ defining trmTIMER_SERVICE_TASK_NAME in FreeRTOSConfig.h. */
|
||||
/* The definition of the timers themselves. */
|
||||
typedef struct tmrTimerControl /* The old naming convention is used to prevent breaking kernel aware debuggers. */
|
||||
{
|
||||
const char *pcTimerName; /*<< Text name. This is not used by the kernel, it is included simply to make debugging easier. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
|
||||
const char *pcTimerName;
|
||||
/*<< Text name. This is not used by the kernel, it is included simply to make debugging easier. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
|
||||
ListItem_t xTimerListItem; /*<< Standard linked list item as used by all kernel features for event management. */
|
||||
TickType_t xTimerPeriodInTicks; /*<< How quickly and often the timer expires. */
|
||||
void * pvTimerID; /*<< An ID to identify the timer. This allows the timer to be identified when the same callback is used for multiple timers. */
|
||||
@@ -92,15 +92,12 @@ Two types of message can be queued - messages that manipulate a software timer,
|
||||
and messages that request the execution of a non-timer related callback. The
|
||||
two message types are defined in two separate structures, xTimerParametersType
|
||||
and xCallbackParametersType respectively. */
|
||||
typedef struct tmrTimerParameters
|
||||
{
|
||||
typedef struct tmrTimerParameters {
|
||||
TickType_t xMessageValue; /*<< An optional value used by a subset of commands, for example, when changing the period of a timer. */
|
||||
Timer_t * pxTimer; /*<< The timer to which the command will be applied. */
|
||||
} TimerParameter_t;
|
||||
|
||||
|
||||
typedef struct tmrCallbackParameters
|
||||
{
|
||||
typedef struct tmrCallbackParameters {
|
||||
PendedFunction_t pxCallbackFunction; /* << The callback function to execute. */
|
||||
void * pvParameter1; /* << The value that will be used as the callback functions first parameter. */
|
||||
uint32_t ulParameter2; /* << The value that will be used as the callback functions second parameter. */
|
||||
@@ -108,11 +105,9 @@ typedef struct tmrCallbackParameters
|
||||
|
||||
/* The structure that contains the two message types, along with an identifier
|
||||
that is used to determine which message type is valid. */
|
||||
typedef struct tmrTimerQueueMessage
|
||||
{
|
||||
typedef struct tmrTimerQueueMessage {
|
||||
BaseType_t xMessageID; /*<< The command being sent to the timer service task. */
|
||||
union
|
||||
{
|
||||
union {
|
||||
TimerParameter_t xTimerParameters;
|
||||
|
||||
/* Don't include xCallbackParameters if it is not going to be used as
|
||||
@@ -217,15 +212,11 @@ static void prvProcessTimerOrBlockTask( const TickType_t xNextExpireTime, BaseTy
|
||||
* dynamically to fill in the structure's members.
|
||||
*/
|
||||
static void prvInitialiseNewTimer(const char *const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
|
||||
const TickType_t xTimerPeriodInTicks,
|
||||
const UBaseType_t uxAutoReload,
|
||||
void * const pvTimerID,
|
||||
TimerCallbackFunction_t pxCallbackFunction,
|
||||
const TickType_t xTimerPeriodInTicks, const UBaseType_t uxAutoReload, void *const pvTimerID, TimerCallbackFunction_t pxCallbackFunction,
|
||||
Timer_t *pxNewTimer) PRIVILEGED_FUNCTION;
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
BaseType_t xTimerCreateTimerTask( void )
|
||||
{
|
||||
BaseType_t xTimerCreateTimerTask(void) {
|
||||
BaseType_t xReturn = pdFAIL;
|
||||
|
||||
/* This function is called when the scheduler is started if
|
||||
@@ -234,8 +225,7 @@ BaseType_t xReturn = pdFAIL;
|
||||
been created then the initialisation will already have been performed. */
|
||||
prvCheckForValidListAndQueue();
|
||||
|
||||
if( xTimerQueue != NULL )
|
||||
{
|
||||
if (xTimerQueue != NULL) {
|
||||
#if (configSUPPORT_STATIC_ALLOCATION == 1)
|
||||
{
|
||||
StaticTask_t *pxTimerTaskTCBBuffer = NULL;
|
||||
@@ -243,32 +233,17 @@ BaseType_t xReturn = pdFAIL;
|
||||
uint32_t ulTimerTaskStackSize;
|
||||
|
||||
vApplicationGetTimerTaskMemory(&pxTimerTaskTCBBuffer, &pxTimerTaskStackBuffer, &ulTimerTaskStackSize);
|
||||
xTimerTaskHandle = xTaskCreateStatic( prvTimerTask,
|
||||
configTIMER_SERVICE_TASK_NAME,
|
||||
ulTimerTaskStackSize,
|
||||
NULL,
|
||||
( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT,
|
||||
pxTimerTaskStackBuffer,
|
||||
pxTimerTaskTCBBuffer );
|
||||
xTimerTaskHandle = xTaskCreateStatic(prvTimerTask, configTIMER_SERVICE_TASK_NAME, ulTimerTaskStackSize, NULL, ((UBaseType_t)configTIMER_TASK_PRIORITY) | portPRIVILEGE_BIT,
|
||||
pxTimerTaskStackBuffer, pxTimerTaskTCBBuffer);
|
||||
|
||||
if( xTimerTaskHandle != NULL )
|
||||
{
|
||||
if (xTimerTaskHandle != NULL) {
|
||||
xReturn = pdPASS;
|
||||
}
|
||||
}
|
||||
#else
|
||||
{
|
||||
xReturn = xTaskCreate( prvTimerTask,
|
||||
configTIMER_SERVICE_TASK_NAME,
|
||||
configTIMER_TASK_STACK_DEPTH,
|
||||
NULL,
|
||||
( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT,
|
||||
&xTimerTaskHandle );
|
||||
}
|
||||
{ xReturn = xTaskCreate(prvTimerTask, configTIMER_SERVICE_TASK_NAME, configTIMER_TASK_STACK_DEPTH, NULL, ((UBaseType_t)configTIMER_TASK_PRIORITY) | portPRIVILEGE_BIT, &xTimerTaskHandle); }
|
||||
#endif /* configSUPPORT_STATIC_ALLOCATION */
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
|
||||
@@ -280,17 +255,13 @@ BaseType_t xReturn = pdFAIL;
|
||||
#if (configSUPPORT_DYNAMIC_ALLOCATION == 1)
|
||||
|
||||
TimerHandle_t xTimerCreate(const char *const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
|
||||
const TickType_t xTimerPeriodInTicks,
|
||||
const UBaseType_t uxAutoReload,
|
||||
void * const pvTimerID,
|
||||
TimerCallbackFunction_t pxCallbackFunction )
|
||||
{
|
||||
const TickType_t xTimerPeriodInTicks, const UBaseType_t uxAutoReload, void *const pvTimerID, TimerCallbackFunction_t pxCallbackFunction) {
|
||||
Timer_t *pxNewTimer;
|
||||
|
||||
pxNewTimer = ( Timer_t * ) pvPortMalloc( sizeof( Timer_t ) ); /*lint !e9087 !e9079 All values returned by pvPortMalloc() have at least the alignment required by the MCU's stack, and the first member of Timer_t is always a pointer to the timer's mame. */
|
||||
pxNewTimer = (Timer_t *)pvPortMalloc(sizeof(Timer_t)); /*lint !e9087 !e9079 All values returned by pvPortMalloc() have at least the alignment required by the MCU's stack, and the first member of
|
||||
Timer_t is always a pointer to the timer's mame. */
|
||||
|
||||
if( pxNewTimer != NULL )
|
||||
{
|
||||
if (pxNewTimer != NULL) {
|
||||
/* Status is thus far zero as the timer is not created statically
|
||||
and has not been started. The auto-reload bit may get set in
|
||||
prvInitialiseNewTimer. */
|
||||
@@ -307,12 +278,8 @@ BaseType_t xReturn = pdFAIL;
|
||||
#if (configSUPPORT_STATIC_ALLOCATION == 1)
|
||||
|
||||
TimerHandle_t xTimerCreateStatic(const char *const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
|
||||
const TickType_t xTimerPeriodInTicks,
|
||||
const UBaseType_t uxAutoReload,
|
||||
void * const pvTimerID,
|
||||
TimerCallbackFunction_t pxCallbackFunction,
|
||||
StaticTimer_t *pxTimerBuffer )
|
||||
{
|
||||
const TickType_t xTimerPeriodInTicks, const UBaseType_t uxAutoReload, void *const pvTimerID, TimerCallbackFunction_t pxCallbackFunction,
|
||||
StaticTimer_t *pxTimerBuffer) {
|
||||
Timer_t *pxNewTimer;
|
||||
|
||||
#if (configASSERT_DEFINED == 1)
|
||||
@@ -330,8 +297,7 @@ BaseType_t xReturn = pdFAIL;
|
||||
configASSERT(pxTimerBuffer);
|
||||
pxNewTimer = (Timer_t *)pxTimerBuffer; /*lint !e740 !e9087 StaticTimer_t is a pointer to a Timer_t, so guaranteed to be aligned and sized correctly (checked by an assert()), so this is safe. */
|
||||
|
||||
if( pxNewTimer != NULL )
|
||||
{
|
||||
if (pxNewTimer != NULL) {
|
||||
/* Timers can be created statically or dynamically so note this
|
||||
timer was created statically in case it is later deleted. The
|
||||
auto-reload bit may get set in prvInitialiseNewTimer(). */
|
||||
@@ -347,17 +313,11 @@ BaseType_t xReturn = pdFAIL;
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvInitialiseNewTimer(const char *const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
|
||||
const TickType_t xTimerPeriodInTicks,
|
||||
const UBaseType_t uxAutoReload,
|
||||
void * const pvTimerID,
|
||||
TimerCallbackFunction_t pxCallbackFunction,
|
||||
Timer_t *pxNewTimer )
|
||||
{
|
||||
const TickType_t xTimerPeriodInTicks, const UBaseType_t uxAutoReload, void *const pvTimerID, TimerCallbackFunction_t pxCallbackFunction, Timer_t *pxNewTimer) {
|
||||
/* 0 is not a valid value for xTimerPeriodInTicks. */
|
||||
configASSERT((xTimerPeriodInTicks > 0));
|
||||
|
||||
if( pxNewTimer != NULL )
|
||||
{
|
||||
if (pxNewTimer != NULL) {
|
||||
/* Ensure the infrastructure used by the timer service task has been
|
||||
created/initialised. */
|
||||
prvCheckForValidListAndQueue();
|
||||
@@ -369,8 +329,7 @@ static void prvInitialiseNewTimer( const char * const pcTimerName, /*lint !e97
|
||||
pxNewTimer->pvTimerID = pvTimerID;
|
||||
pxNewTimer->pxCallbackFunction = pxCallbackFunction;
|
||||
vListInitialiseItem(&(pxNewTimer->xTimerListItem));
|
||||
if( uxAutoReload != pdFALSE )
|
||||
{
|
||||
if (uxAutoReload != pdFALSE) {
|
||||
pxNewTimer->ucStatus |= tmrSTATUS_IS_AUTORELOAD;
|
||||
}
|
||||
traceTIMER_CREATE(pxNewTimer);
|
||||
@@ -378,8 +337,7 @@ static void prvInitialiseNewTimer( const char * const pcTimerName, /*lint !e97
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
BaseType_t xTimerGenericCommand( TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t * const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait )
|
||||
{
|
||||
BaseType_t xTimerGenericCommand(TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t *const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait) {
|
||||
BaseType_t xReturn = pdFAIL;
|
||||
DaemonTaskMessage_t xMessage;
|
||||
|
||||
@@ -387,33 +345,24 @@ DaemonTaskMessage_t xMessage;
|
||||
|
||||
/* Send a message to the timer service task to perform a particular action
|
||||
on a particular timer definition. */
|
||||
if( xTimerQueue != NULL )
|
||||
{
|
||||
if (xTimerQueue != NULL) {
|
||||
/* Send a command to the timer service task to start the xTimer timer. */
|
||||
xMessage.xMessageID = xCommandID;
|
||||
xMessage.u.xTimerParameters.xMessageValue = xOptionalValue;
|
||||
xMessage.u.xTimerParameters.pxTimer = xTimer;
|
||||
|
||||
if( xCommandID < tmrFIRST_FROM_ISR_COMMAND )
|
||||
{
|
||||
if( xTaskGetSchedulerState() == taskSCHEDULER_RUNNING )
|
||||
{
|
||||
if (xCommandID < tmrFIRST_FROM_ISR_COMMAND) {
|
||||
if (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) {
|
||||
xReturn = xQueueSendToBack(xTimerQueue, &xMessage, xTicksToWait);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
xReturn = xQueueSendToBack(xTimerQueue, &xMessage, tmrNO_DELAY);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
xReturn = xQueueSendToBackFromISR(xTimerQueue, &xMessage, pxHigherPriorityTaskWoken);
|
||||
}
|
||||
|
||||
traceTIMER_COMMAND_SEND(xTimer, xCommandID, xOptionalValue, xReturn);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
|
||||
@@ -421,8 +370,7 @@ DaemonTaskMessage_t xMessage;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
TaskHandle_t xTimerGetTimerDaemonTaskHandle( void )
|
||||
{
|
||||
TaskHandle_t xTimerGetTimerDaemonTaskHandle(void) {
|
||||
/* If xTimerGetTimerDaemonTaskHandle() is called before the scheduler has been
|
||||
started, then xTimerTaskHandle will be NULL. */
|
||||
configASSERT((xTimerTaskHandle != NULL));
|
||||
@@ -430,8 +378,7 @@ TaskHandle_t xTimerGetTimerDaemonTaskHandle( void )
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
TickType_t xTimerGetPeriod( TimerHandle_t xTimer )
|
||||
{
|
||||
TickType_t xTimerGetPeriod(TimerHandle_t xTimer) {
|
||||
Timer_t *pxTimer = xTimer;
|
||||
|
||||
configASSERT(xTimer);
|
||||
@@ -439,19 +386,15 @@ Timer_t *pxTimer = xTimer;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vTimerSetReloadMode( TimerHandle_t xTimer, const UBaseType_t uxAutoReload )
|
||||
{
|
||||
void vTimerSetReloadMode(TimerHandle_t xTimer, const UBaseType_t uxAutoReload) {
|
||||
Timer_t *pxTimer = xTimer;
|
||||
|
||||
configASSERT(xTimer);
|
||||
taskENTER_CRITICAL();
|
||||
{
|
||||
if( uxAutoReload != pdFALSE )
|
||||
{
|
||||
if (uxAutoReload != pdFALSE) {
|
||||
pxTimer->ucStatus |= tmrSTATUS_IS_AUTORELOAD;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
pxTimer->ucStatus &= ~tmrSTATUS_IS_AUTORELOAD;
|
||||
}
|
||||
}
|
||||
@@ -459,21 +402,17 @@ Timer_t * pxTimer = xTimer;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
UBaseType_t uxTimerGetReloadMode( TimerHandle_t xTimer )
|
||||
{
|
||||
UBaseType_t uxTimerGetReloadMode(TimerHandle_t xTimer) {
|
||||
Timer_t * pxTimer = xTimer;
|
||||
UBaseType_t uxReturn;
|
||||
|
||||
configASSERT(xTimer);
|
||||
taskENTER_CRITICAL();
|
||||
{
|
||||
if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) == 0 )
|
||||
{
|
||||
if ((pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD) == 0) {
|
||||
/* Not an auto-reload timer. */
|
||||
uxReturn = (UBaseType_t)pdFALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Is an auto-reload timer. */
|
||||
uxReturn = (UBaseType_t)pdTRUE;
|
||||
}
|
||||
@@ -484,8 +423,7 @@ UBaseType_t uxReturn;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer )
|
||||
{
|
||||
TickType_t xTimerGetExpiryTime(TimerHandle_t xTimer) {
|
||||
Timer_t * pxTimer = xTimer;
|
||||
TickType_t xReturn;
|
||||
|
||||
@@ -504,10 +442,10 @@ Timer_t *pxTimer = xTimer;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvProcessExpiredTimer( const TickType_t xNextExpireTime, const TickType_t xTimeNow )
|
||||
{
|
||||
static void prvProcessExpiredTimer(const TickType_t xNextExpireTime, const TickType_t xTimeNow) {
|
||||
BaseType_t xResult;
|
||||
Timer_t * const pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList ); /*lint !e9087 !e9079 void * is used as this macro is used with tasks and co-routines too. Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */
|
||||
Timer_t *const pxTimer = (Timer_t *)listGET_OWNER_OF_HEAD_ENTRY(pxCurrentTimerList); /*lint !e9087 !e9079 void * is used as this macro is used with tasks and co-routines too. Alignment is known
|
||||
to be fine as the type of the pointer stored and retrieved is the same. */
|
||||
|
||||
/* Remove the timer from the list of active timers. A check has already
|
||||
been performed to ensure the list is not empty. */
|
||||
@@ -516,26 +454,20 @@ Timer_t * const pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTi
|
||||
|
||||
/* If the timer is an auto-reload timer then calculate the next
|
||||
expiry time and re-insert the timer in the list of active timers. */
|
||||
if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0 )
|
||||
{
|
||||
if ((pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD) != 0) {
|
||||
/* The timer is inserted into a list using a time relative to anything
|
||||
other than the current time. It will therefore be inserted into the
|
||||
correct list relative to the time this task thinks it is now. */
|
||||
if( prvInsertTimerInActiveList( pxTimer, ( xNextExpireTime + pxTimer->xTimerPeriodInTicks ), xTimeNow, xNextExpireTime ) != pdFALSE )
|
||||
{
|
||||
if (prvInsertTimerInActiveList(pxTimer, (xNextExpireTime + pxTimer->xTimerPeriodInTicks), xTimeNow, xNextExpireTime) != pdFALSE) {
|
||||
/* The timer expired before it was added to the active timer
|
||||
list. Reload it now. */
|
||||
xResult = xTimerGenericCommand(pxTimer, tmrCOMMAND_START_DONT_TRACE, xNextExpireTime, NULL, tmrNO_DELAY);
|
||||
configASSERT(xResult);
|
||||
(void)xResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
pxTimer->ucStatus &= ~tmrSTATUS_IS_ACTIVE;
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
@@ -545,8 +477,7 @@ Timer_t * const pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTi
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static portTASK_FUNCTION( prvTimerTask, pvParameters )
|
||||
{
|
||||
static portTASK_FUNCTION(prvTimerTask, pvParameters) {
|
||||
TickType_t xNextExpireTime;
|
||||
BaseType_t xListWasEmpty;
|
||||
|
||||
@@ -565,8 +496,7 @@ BaseType_t xListWasEmpty;
|
||||
}
|
||||
#endif /* configUSE_DAEMON_TASK_STARTUP_HOOK */
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
for (;;) {
|
||||
/* Query the timers list to see if it contains any timers, and if so,
|
||||
obtain the time at which the next timer will expire. */
|
||||
xNextExpireTime = prvGetNextExpireTime(&xListWasEmpty);
|
||||
@@ -581,8 +511,7 @@ BaseType_t xListWasEmpty;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvProcessTimerOrBlockTask( const TickType_t xNextExpireTime, BaseType_t xListWasEmpty )
|
||||
{
|
||||
static void prvProcessTimerOrBlockTask(const TickType_t xNextExpireTime, BaseType_t xListWasEmpty) {
|
||||
TickType_t xTimeNow;
|
||||
BaseType_t xTimerListsWereSwitched;
|
||||
|
||||
@@ -594,24 +523,19 @@ BaseType_t xTimerListsWereSwitched;
|
||||
when the lists were switched will have been processed within the
|
||||
prvSampleTimeNow() function. */
|
||||
xTimeNow = prvSampleTimeNow(&xTimerListsWereSwitched);
|
||||
if( xTimerListsWereSwitched == pdFALSE )
|
||||
{
|
||||
if (xTimerListsWereSwitched == pdFALSE) {
|
||||
/* The tick count has not overflowed, has the timer expired? */
|
||||
if( ( xListWasEmpty == pdFALSE ) && ( xNextExpireTime <= xTimeNow ) )
|
||||
{
|
||||
if ((xListWasEmpty == pdFALSE) && (xNextExpireTime <= xTimeNow)) {
|
||||
(void)xTaskResumeAll();
|
||||
prvProcessExpiredTimer(xNextExpireTime, xTimeNow);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* The tick count has not overflowed, and the next expire
|
||||
time has not been reached yet. This task should therefore
|
||||
block to wait for the next expire time or a command to be
|
||||
received - whichever comes first. The following line cannot
|
||||
be reached unless xNextExpireTime > xTimeNow, except in the
|
||||
case when the current timer list is empty. */
|
||||
if( xListWasEmpty != pdFALSE )
|
||||
{
|
||||
if (xListWasEmpty != pdFALSE) {
|
||||
/* The current timer list is empty - is the overflow list
|
||||
also empty? */
|
||||
xListWasEmpty = listLIST_IS_EMPTY(pxOverflowTimerList);
|
||||
@@ -619,30 +543,24 @@ BaseType_t xTimerListsWereSwitched;
|
||||
|
||||
vQueueWaitForMessageRestricted(xTimerQueue, (xNextExpireTime - xTimeNow), xListWasEmpty);
|
||||
|
||||
if( xTaskResumeAll() == pdFALSE )
|
||||
{
|
||||
if (xTaskResumeAll() == pdFALSE) {
|
||||
/* Yield to wait for either a command to arrive, or the
|
||||
block time to expire. If a command arrived between the
|
||||
critical section being exited and this yield then the yield
|
||||
will not cause the task to block. */
|
||||
portYIELD_WITHIN_API();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
(void)xTaskResumeAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static TickType_t prvGetNextExpireTime( BaseType_t * const pxListWasEmpty )
|
||||
{
|
||||
static TickType_t prvGetNextExpireTime(BaseType_t *const pxListWasEmpty) {
|
||||
TickType_t xNextExpireTime;
|
||||
|
||||
/* Timers are listed in expiry time order, with the head of the list
|
||||
@@ -653,12 +571,9 @@ TickType_t xNextExpireTime;
|
||||
timer lists will be switched and the next expiry time can be
|
||||
re-assessed. */
|
||||
*pxListWasEmpty = listLIST_IS_EMPTY(pxCurrentTimerList);
|
||||
if( *pxListWasEmpty == pdFALSE )
|
||||
{
|
||||
if (*pxListWasEmpty == pdFALSE) {
|
||||
xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY(pxCurrentTimerList);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* Ensure the task unblocks when the tick count rolls over. */
|
||||
xNextExpireTime = (TickType_t)0U;
|
||||
}
|
||||
@@ -667,20 +582,16 @@ TickType_t xNextExpireTime;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static TickType_t prvSampleTimeNow( BaseType_t * const pxTimerListsWereSwitched )
|
||||
{
|
||||
static TickType_t prvSampleTimeNow(BaseType_t *const pxTimerListsWereSwitched) {
|
||||
TickType_t xTimeNow;
|
||||
PRIVILEGED_DATA static TickType_t xLastTime = (TickType_t)0U; /*lint !e956 Variable is only accessible to one task. */
|
||||
|
||||
xTimeNow = xTaskGetTickCount();
|
||||
|
||||
if( xTimeNow < xLastTime )
|
||||
{
|
||||
if (xTimeNow < xLastTime) {
|
||||
prvSwitchTimerLists();
|
||||
*pxTimerListsWereSwitched = pdTRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
*pxTimerListsWereSwitched = pdFALSE;
|
||||
}
|
||||
|
||||
@@ -690,15 +601,13 @@ PRIVILEGED_DATA static TickType_t xLastTime = ( TickType_t ) 0U; /*lint !e956 Va
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static BaseType_t prvInsertTimerInActiveList( Timer_t * const pxTimer, const TickType_t xNextExpiryTime, const TickType_t xTimeNow, const TickType_t xCommandTime )
|
||||
{
|
||||
static BaseType_t prvInsertTimerInActiveList(Timer_t *const pxTimer, const TickType_t xNextExpiryTime, const TickType_t xTimeNow, const TickType_t xCommandTime) {
|
||||
BaseType_t xProcessTimerNow = pdFALSE;
|
||||
|
||||
listSET_LIST_ITEM_VALUE(&(pxTimer->xTimerListItem), xNextExpiryTime);
|
||||
listSET_LIST_ITEM_OWNER(&(pxTimer->xTimerListItem), pxTimer);
|
||||
|
||||
if( xNextExpiryTime <= xTimeNow )
|
||||
{
|
||||
if (xNextExpiryTime <= xTimeNow) {
|
||||
/* Has the expiry time elapsed between the command to start/reset a
|
||||
timer was issued, and the time the command was processed? */
|
||||
if (((TickType_t)(xTimeNow - xCommandTime)) >= pxTimer->xTimerPeriodInTicks) /*lint !e961 MISRA exception as the casts are only redundant for some ports. */
|
||||
@@ -706,23 +615,16 @@ BaseType_t xProcessTimerNow = pdFALSE;
|
||||
/* The time between a command being issued and the command being
|
||||
processed actually exceeds the timers period. */
|
||||
xProcessTimerNow = pdTRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
vListInsert(pxOverflowTimerList, &(pxTimer->xTimerListItem));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( ( xTimeNow < xCommandTime ) && ( xNextExpiryTime >= xCommandTime ) )
|
||||
{
|
||||
} else {
|
||||
if ((xTimeNow < xCommandTime) && (xNextExpiryTime >= xCommandTime)) {
|
||||
/* If, since the command was issued, the tick count has overflowed
|
||||
but the expiry time has not, then the timer must have already passed
|
||||
its expiry time and should be processed immediately. */
|
||||
xProcessTimerNow = pdTRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
vListInsert(pxCurrentTimerList, &(pxTimer->xTimerListItem));
|
||||
}
|
||||
}
|
||||
@@ -731,21 +633,20 @@ BaseType_t xProcessTimerNow = pdFALSE;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvProcessReceivedCommands( void )
|
||||
{
|
||||
static void prvProcessReceivedCommands(void) {
|
||||
DaemonTaskMessage_t xMessage;
|
||||
Timer_t * pxTimer;
|
||||
BaseType_t xTimerListsWereSwitched, xResult;
|
||||
TickType_t xTimeNow;
|
||||
|
||||
while( xQueueReceive( xTimerQueue, &xMessage, tmrNO_DELAY ) != pdFAIL ) /*lint !e603 xMessage does not have to be initialised as it is passed out, not in, and it is not used unless xQueueReceive() returns pdTRUE. */
|
||||
while (xQueueReceive(xTimerQueue, &xMessage, tmrNO_DELAY)
|
||||
!= pdFAIL) /*lint !e603 xMessage does not have to be initialised as it is passed out, not in, and it is not used unless xQueueReceive() returns pdTRUE. */
|
||||
{
|
||||
#if (INCLUDE_xTimerPendFunctionCall == 1)
|
||||
{
|
||||
/* Negative commands are pended function calls rather than timer
|
||||
commands. */
|
||||
if( xMessage.xMessageID < ( BaseType_t ) 0 )
|
||||
{
|
||||
if (xMessage.xMessageID < (BaseType_t)0) {
|
||||
const CallbackParameters_t *const pxCallback = &(xMessage.u.xCallbackParameters);
|
||||
|
||||
/* The timer uses the xCallbackParameters member to request a
|
||||
@@ -754,9 +655,7 @@ TickType_t xTimeNow;
|
||||
|
||||
/* Call the function. */
|
||||
pxCallback->pxCallbackFunction(pxCallback->pvParameter1, pxCallback->ulParameter2);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
}
|
||||
@@ -764,8 +663,7 @@ TickType_t xTimeNow;
|
||||
|
||||
/* Commands that are positive are timer commands rather than pended
|
||||
function calls. */
|
||||
if( xMessage.xMessageID >= ( BaseType_t ) 0 )
|
||||
{
|
||||
if (xMessage.xMessageID >= (BaseType_t)0) {
|
||||
/* The messages uses the xTimerParameters member to work on a
|
||||
software timer. */
|
||||
pxTimer = xMessage.u.xTimerParameters.pxTimer;
|
||||
@@ -774,9 +672,7 @@ TickType_t xTimeNow;
|
||||
{
|
||||
/* The timer is in a list, remove it. */
|
||||
(void)uxListRemove(&(pxTimer->xTimerListItem));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
|
||||
@@ -790,8 +686,7 @@ TickType_t xTimeNow;
|
||||
pre-empted the timer daemon task after the xTimeNow value was set). */
|
||||
xTimeNow = prvSampleTimeNow(&xTimerListsWereSwitched);
|
||||
|
||||
switch( xMessage.xMessageID )
|
||||
{
|
||||
switch (xMessage.xMessageID) {
|
||||
case tmrCOMMAND_START:
|
||||
case tmrCOMMAND_START_FROM_ISR:
|
||||
case tmrCOMMAND_RESET:
|
||||
@@ -799,26 +694,20 @@ TickType_t xTimeNow;
|
||||
case tmrCOMMAND_START_DONT_TRACE:
|
||||
/* Start or restart a timer. */
|
||||
pxTimer->ucStatus |= tmrSTATUS_IS_ACTIVE;
|
||||
if( prvInsertTimerInActiveList( pxTimer, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, xTimeNow, xMessage.u.xTimerParameters.xMessageValue ) != pdFALSE )
|
||||
{
|
||||
if (prvInsertTimerInActiveList(pxTimer, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, xTimeNow, xMessage.u.xTimerParameters.xMessageValue) != pdFALSE) {
|
||||
/* The timer expired before it was added to the active
|
||||
timer list. Process it now. */
|
||||
pxTimer->pxCallbackFunction((TimerHandle_t)pxTimer);
|
||||
traceTIMER_EXPIRED(pxTimer);
|
||||
|
||||
if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0 )
|
||||
{
|
||||
if ((pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD) != 0) {
|
||||
xResult = xTimerGenericCommand(pxTimer, tmrCOMMAND_START_DONT_TRACE, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, NULL, tmrNO_DELAY);
|
||||
configASSERT(xResult);
|
||||
(void)xResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
break;
|
||||
@@ -850,12 +739,9 @@ TickType_t xTimeNow;
|
||||
/* The timer has already been removed from the active list,
|
||||
just free up the memory if the memory was dynamically
|
||||
allocated. */
|
||||
if( ( pxTimer->ucStatus & tmrSTATUS_IS_STATICALLY_ALLOCATED ) == ( uint8_t ) 0 )
|
||||
{
|
||||
if ((pxTimer->ucStatus & tmrSTATUS_IS_STATICALLY_ALLOCATED) == (uint8_t)0) {
|
||||
vPortFree(pxTimer);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
pxTimer->ucStatus &= ~tmrSTATUS_IS_ACTIVE;
|
||||
}
|
||||
}
|
||||
@@ -879,8 +765,7 @@ TickType_t xTimeNow;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvSwitchTimerLists( void )
|
||||
{
|
||||
static void prvSwitchTimerLists(void) {
|
||||
TickType_t xNextExpireTime, xReloadTime;
|
||||
List_t * pxTemp;
|
||||
Timer_t * pxTimer;
|
||||
@@ -890,12 +775,12 @@ BaseType_t xResult;
|
||||
If there are any timers still referenced from the current timer list
|
||||
then they must have expired and should be processed before the lists
|
||||
are switched. */
|
||||
while( listLIST_IS_EMPTY( pxCurrentTimerList ) == pdFALSE )
|
||||
{
|
||||
while (listLIST_IS_EMPTY(pxCurrentTimerList) == pdFALSE) {
|
||||
xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY(pxCurrentTimerList);
|
||||
|
||||
/* Remove the timer from the list. */
|
||||
pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList ); /*lint !e9087 !e9079 void * is used as this macro is used with tasks and co-routines too. Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */
|
||||
pxTimer = (Timer_t *)listGET_OWNER_OF_HEAD_ENTRY(pxCurrentTimerList); /*lint !e9087 !e9079 void * is used as this macro is used with tasks and co-routines too. Alignment is known to be fine
|
||||
as the type of the pointer stored and retrieved is the same. */
|
||||
(void)uxListRemove(&(pxTimer->xTimerListItem));
|
||||
traceTIMER_EXPIRED(pxTimer);
|
||||
|
||||
@@ -904,8 +789,7 @@ BaseType_t xResult;
|
||||
have not yet been switched. */
|
||||
pxTimer->pxCallbackFunction((TimerHandle_t)pxTimer);
|
||||
|
||||
if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0 )
|
||||
{
|
||||
if ((pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD) != 0) {
|
||||
/* Calculate the reload value, and if the reload value results in
|
||||
the timer going into the same timer list then it has already expired
|
||||
and the timer should be re-inserted into the current list so it is
|
||||
@@ -913,21 +797,16 @@ BaseType_t xResult;
|
||||
to restart the timer to ensure it is only inserted into a list after
|
||||
the lists have been swapped. */
|
||||
xReloadTime = (xNextExpireTime + pxTimer->xTimerPeriodInTicks);
|
||||
if( xReloadTime > xNextExpireTime )
|
||||
{
|
||||
if (xReloadTime > xNextExpireTime) {
|
||||
listSET_LIST_ITEM_VALUE(&(pxTimer->xTimerListItem), xReloadTime);
|
||||
listSET_LIST_ITEM_OWNER(&(pxTimer->xTimerListItem), pxTimer);
|
||||
vListInsert(pxCurrentTimerList, &(pxTimer->xTimerListItem));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
xResult = xTimerGenericCommand(pxTimer, tmrCOMMAND_START_DONT_TRACE, xNextExpireTime, NULL, tmrNO_DELAY);
|
||||
configASSERT(xResult);
|
||||
(void)xResult;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
}
|
||||
@@ -938,15 +817,13 @@ BaseType_t xResult;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvCheckForValidListAndQueue( void )
|
||||
{
|
||||
static void prvCheckForValidListAndQueue(void) {
|
||||
/* Check that the list from which active timers are referenced, and the
|
||||
queue used to communicate with the timer service, have been
|
||||
initialised. */
|
||||
taskENTER_CRITICAL();
|
||||
{
|
||||
if( xTimerQueue == NULL )
|
||||
{
|
||||
if (xTimerQueue == NULL) {
|
||||
vListInitialise(&xActiveTimerList1);
|
||||
vListInitialise(&xActiveTimerList2);
|
||||
pxCurrentTimerList = &xActiveTimerList1;
|
||||
@@ -957,31 +834,25 @@ static void prvCheckForValidListAndQueue( void )
|
||||
/* The timer queue is allocated statically in case
|
||||
configSUPPORT_DYNAMIC_ALLOCATION is 0. */
|
||||
static StaticQueue_t xStaticTimerQueue; /*lint !e956 Ok to declare in this manner to prevent additional conditional compilation guards in other locations. */
|
||||
static uint8_t ucStaticTimerQueueStorage[ ( size_t ) configTIMER_QUEUE_LENGTH * sizeof( DaemonTaskMessage_t ) ]; /*lint !e956 Ok to declare in this manner to prevent additional conditional compilation guards in other locations. */
|
||||
static uint8_t ucStaticTimerQueueStorage[(size_t)configTIMER_QUEUE_LENGTH * sizeof(DaemonTaskMessage_t)]; /*lint !e956 Ok to declare in this manner to prevent additional conditional
|
||||
compilation guards in other locations. */
|
||||
|
||||
xTimerQueue = xQueueCreateStatic((UBaseType_t)configTIMER_QUEUE_LENGTH, (UBaseType_t)sizeof(DaemonTaskMessage_t), &(ucStaticTimerQueueStorage[0]), &xStaticTimerQueue);
|
||||
}
|
||||
#else
|
||||
{
|
||||
xTimerQueue = xQueueCreate( ( UBaseType_t ) configTIMER_QUEUE_LENGTH, sizeof( DaemonTaskMessage_t ) );
|
||||
}
|
||||
{ xTimerQueue = xQueueCreate((UBaseType_t)configTIMER_QUEUE_LENGTH, sizeof(DaemonTaskMessage_t)); }
|
||||
#endif
|
||||
|
||||
#if (configQUEUE_REGISTRY_SIZE > 0)
|
||||
{
|
||||
if( xTimerQueue != NULL )
|
||||
{
|
||||
if (xTimerQueue != NULL) {
|
||||
vQueueAddToRegistry(xTimerQueue, "TmrQ");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
}
|
||||
#endif /* configQUEUE_REGISTRY_SIZE */
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
mtCOVERAGE_TEST_MARKER();
|
||||
}
|
||||
}
|
||||
@@ -989,8 +860,7 @@ static void prvCheckForValidListAndQueue( void )
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer )
|
||||
{
|
||||
BaseType_t xTimerIsTimerActive(TimerHandle_t xTimer) {
|
||||
BaseType_t xReturn;
|
||||
Timer_t * pxTimer = xTimer;
|
||||
|
||||
@@ -999,12 +869,9 @@ Timer_t *pxTimer = xTimer;
|
||||
/* Is the timer in the list of active timers? */
|
||||
taskENTER_CRITICAL();
|
||||
{
|
||||
if( ( pxTimer->ucStatus & tmrSTATUS_IS_ACTIVE ) == 0 )
|
||||
{
|
||||
if ((pxTimer->ucStatus & tmrSTATUS_IS_ACTIVE) == 0) {
|
||||
xReturn = pdFALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
xReturn = pdTRUE;
|
||||
}
|
||||
}
|
||||
@@ -1014,41 +881,34 @@ Timer_t *pxTimer = xTimer;
|
||||
} /*lint !e818 Can't be pointer to const due to the typedef. */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void *pvTimerGetTimerID( const TimerHandle_t xTimer )
|
||||
{
|
||||
void *pvTimerGetTimerID(const TimerHandle_t xTimer) {
|
||||
Timer_t *const pxTimer = xTimer;
|
||||
void * pvReturn;
|
||||
|
||||
configASSERT(xTimer);
|
||||
|
||||
taskENTER_CRITICAL();
|
||||
{
|
||||
pvReturn = pxTimer->pvTimerID;
|
||||
}
|
||||
{ pvReturn = pxTimer->pvTimerID; }
|
||||
taskEXIT_CRITICAL();
|
||||
|
||||
return pvReturn;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID )
|
||||
{
|
||||
void vTimerSetTimerID(TimerHandle_t xTimer, void *pvNewID) {
|
||||
Timer_t *const pxTimer = xTimer;
|
||||
|
||||
configASSERT(xTimer);
|
||||
|
||||
taskENTER_CRITICAL();
|
||||
{
|
||||
pxTimer->pvTimerID = pvNewID;
|
||||
}
|
||||
{ pxTimer->pvTimerID = pvNewID; }
|
||||
taskEXIT_CRITICAL();
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#if (INCLUDE_xTimerPendFunctionCall == 1)
|
||||
|
||||
BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, BaseType_t *pxHigherPriorityTaskWoken )
|
||||
{
|
||||
BaseType_t xTimerPendFunctionCallFromISR(PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, BaseType_t *pxHigherPriorityTaskWoken) {
|
||||
DaemonTaskMessage_t xMessage;
|
||||
BaseType_t xReturn;
|
||||
|
||||
@@ -1071,8 +931,7 @@ Timer_t * const pxTimer = xTimer;
|
||||
|
||||
#if (INCLUDE_xTimerPendFunctionCall == 1)
|
||||
|
||||
BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, TickType_t xTicksToWait )
|
||||
{
|
||||
BaseType_t xTimerPendFunctionCall(PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, TickType_t xTicksToWait) {
|
||||
DaemonTaskMessage_t xMessage;
|
||||
BaseType_t xReturn;
|
||||
|
||||
@@ -1100,20 +959,14 @@ Timer_t * const pxTimer = xTimer;
|
||||
|
||||
#if (configUSE_TRACE_FACILITY == 1)
|
||||
|
||||
UBaseType_t uxTimerGetTimerNumber( TimerHandle_t xTimer )
|
||||
{
|
||||
return ( ( Timer_t * ) xTimer )->uxTimerNumber;
|
||||
}
|
||||
UBaseType_t uxTimerGetTimerNumber(TimerHandle_t xTimer) { return ((Timer_t *)xTimer)->uxTimerNumber; }
|
||||
|
||||
#endif /* configUSE_TRACE_FACILITY */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#if (configUSE_TRACE_FACILITY == 1)
|
||||
|
||||
void vTimerSetTimerNumber( TimerHandle_t xTimer, UBaseType_t uxTimerNumber )
|
||||
{
|
||||
( ( Timer_t * ) xTimer )->uxTimerNumber = uxTimerNumber;
|
||||
}
|
||||
void vTimerSetTimerNumber(TimerHandle_t xTimer, UBaseType_t uxTimerNumber) { ((Timer_t *)xTimer)->uxTimerNumber = uxTimerNumber; }
|
||||
|
||||
#endif /* configUSE_TRACE_FACILITY */
|
||||
/*-----------------------------------------------------------*/
|
||||
@@ -1122,6 +975,3 @@ Timer_t * const pxTimer = xTimer;
|
||||
to include software timer functionality. If you want to include software timer
|
||||
functionality then ensure configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */
|
||||
#endif /* configUSE_TIMERS == 1 */
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user