Merge branch 'raspi-support' of ssh://git.intern.spaceteamaachen.de:22222/ALPAKA/sta-core into raspi-support

This commit is contained in:
Dario 2023-08-14 21:08:23 +01:00
commit d1d43870f4
9 changed files with 60 additions and 51 deletions

View File

@ -75,7 +75,7 @@ namespace sta
/** /**
* @returns true if the interface has been aquired. * @returns true if the interface has been aquired.
*/ */
bool isAquired(); bool isAcquired();
private: private:
Mutex * mutex_; Mutex * mutex_;
bool acquired_ = false; bool acquired_ = false;

View File

@ -8,4 +8,4 @@
// #define STA_ASSERT_FORCE // #define STA_ASSERT_FORCE
#endif // STA_CONFIG_HPP #endif // STA_CONFIG_HPP

View File

@ -3,8 +3,13 @@
#include <sta/config.hpp> #include <sta/config.hpp>
#ifdef STA_PLATFORM_STM32 #ifdef STA_PLATFORM_STM32
# include <sta/devices/stm32/hal.hpp>
# ifdef HAL_ADC_MODULE_ENABLED
# define STA_STM32_ADC_ENABLED
# endif
#endif
#include <sta/devices/stm32/hal.hpp> #if defined(STA_STM32_ADC_ENABLED) || defined(DOXYGEN)
namespace sta namespace sta
{ {
@ -34,6 +39,6 @@ namespace sta
}; };
} // namespace sta } // namespace sta
#endif // STA_PLATFORM_STM32 #endif // STA_STM32_ADC_ENABLED
#endif // STA_CORE_STM32_ADC_HPP #endif // STA_CORE_STM32_ADC_HPP

View File

@ -30,7 +30,7 @@ namespace sta
void fill(uint8_t value, size_t count) override; void fill(uint8_t value, size_t count) override;
private: private:
I2C_HandleTypeDef * handle_; I2C_HandleTypeDef * handle_;
const uint32_t timeout_ = HAL_MAX_DELAY; const uint32_t timeout_ = 1000;
}; };
class STM32I2CDevice : public I2CDevice class STM32I2CDevice : public I2CDevice

View File

@ -25,7 +25,7 @@ namespace sta
void Device::transfer(uint8_t value) void Device::transfer(uint8_t value)
{ {
STA_ASSERT(intf_->isAquired()); STA_ASSERT(intf_->isAcquired());
STA_ASSERT(selected_); STA_ASSERT(selected_);
intf_->transfer(value); intf_->transfer(value);
@ -33,7 +33,7 @@ namespace sta
void Device::transfer16(uint16_t value) void Device::transfer16(uint16_t value)
{ {
STA_ASSERT(intf_->isAquired()); STA_ASSERT(intf_->isAcquired());
STA_ASSERT(selected_); STA_ASSERT(selected_);
intf_->transfer16(value); intf_->transfer16(value);
@ -41,7 +41,7 @@ namespace sta
void Device::transfer(const uint8_t * buffer, size_t size) void Device::transfer(const uint8_t * buffer, size_t size)
{ {
STA_ASSERT(intf_->isAquired()); STA_ASSERT(intf_->isAcquired());
STA_ASSERT(selected_); STA_ASSERT(selected_);
STA_ASSERT(buffer != nullptr); STA_ASSERT(buffer != nullptr);
@ -50,7 +50,7 @@ namespace sta
void Device::transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size) void Device::transfer(const uint8_t * txBuffer, uint8_t * rxBuffer, size_t size)
{ {
STA_ASSERT(intf_->isAquired()); STA_ASSERT(intf_->isAcquired());
STA_ASSERT(selected_); STA_ASSERT(selected_);
STA_ASSERT(txBuffer != nullptr); STA_ASSERT(txBuffer != nullptr);
STA_ASSERT(rxBuffer != nullptr); STA_ASSERT(rxBuffer != nullptr);
@ -60,7 +60,7 @@ namespace sta
void Device::receive(uint8_t * buffer, size_t size) void Device::receive(uint8_t * buffer, size_t size)
{ {
STA_ASSERT(intf_->isAquired()); STA_ASSERT(intf_->isAcquired());
STA_ASSERT(selected_); STA_ASSERT(selected_);
STA_ASSERT(buffer != nullptr); STA_ASSERT(buffer != nullptr);
@ -69,7 +69,7 @@ namespace sta
void Device::fill(uint8_t value, size_t count) void Device::fill(uint8_t value, size_t count)
{ {
STA_ASSERT(intf_->isAquired()); STA_ASSERT(intf_->isAcquired());
STA_ASSERT(selected_); STA_ASSERT(selected_);
intf_->fill(value, count); intf_->fill(value, count);

View File

@ -5,7 +5,7 @@
namespace sta namespace sta
{ {
Interface::Interface(Mutex * mutex) Interface::Interface(Mutex * mutex)
: mutex_{mutex} : mutex_{mutex}, acquired_{false}
{ {
STA_ASSERT(mutex != nullptr); STA_ASSERT(mutex != nullptr);
} }
@ -22,7 +22,7 @@ namespace sta
acquired_ = false; acquired_ = false;
} }
bool Interface::isAquired() bool Interface::isAcquired()
{ {
return acquired_; return acquired_;
} }

View File

@ -1,6 +1,6 @@
#include <sta/devices/stm32/adc.hpp> #include <sta/devices/stm32/adc.hpp>
#ifdef STA_PLATFORM_STM32 #ifdef STA_STM32_ADC_ENABLED
#include <sta/debug/assert.hpp> #include <sta/debug/assert.hpp>
@ -30,4 +30,4 @@ namespace sta
} }
} // namespace sta } // namespace sta
#endif // STA_PLATFORM_STM32 #endif // STA_STM32_ADC_ENABLED

View File

@ -3,7 +3,7 @@
#include <sta/debug/assert.hpp> #include <sta/debug/assert.hpp>
#include <cstring> #include <cstring>
#ifdef STA_PLATFORM_STM32 #ifdef STA_STM32_I2C_ENABLED
namespace sta namespace sta
{ {
@ -42,7 +42,7 @@ namespace sta
} else { } else {
if (master_) if (master_)
{ {
res = HAL_I2C_Slave_Transmit(handle_, reinterpret_cast<uint8_t *>(&value), 2, timeout_); res = HAL_I2C_Slave_Transmit_IT(handle_, reinterpret_cast<uint8_t *>(&value), 2);
} else { } else {
res = HAL_I2C_Slave_Transmit_IT(handle_, reinterpret_cast<uint8_t *>(&value), 2); res = HAL_I2C_Slave_Transmit_IT(handle_, reinterpret_cast<uint8_t *>(&value), 2);
} }
@ -93,7 +93,7 @@ namespace sta
HAL_StatusTypeDef res; HAL_StatusTypeDef res;
if (blocking_) { if (blocking_) {
if (!master_) { if (master_) {
res = HAL_I2C_Master_Receive(handle_, address_, buffer, size, timeout_); res = HAL_I2C_Master_Receive(handle_, address_, buffer, size, timeout_);
} else { } else {
res = HAL_I2C_Slave_Receive(handle_, buffer, size, timeout_); res = HAL_I2C_Slave_Receive(handle_, buffer, size, timeout_);
@ -129,4 +129,4 @@ namespace sta
} // namespace sta } // namespace sta
#endif // STA_PLATFORM_STM32 #endif // STA_STM32_I2C_ENABLED

View File

@ -1,4 +1,5 @@
#include <sta/devices/stm32/delay.hpp> #include <sta/devices/stm32/delay.hpp>
#ifdef STA_PLATFORM_STM32 #ifdef STA_PLATFORM_STM32
#include <sta/devices/stm32/hal.hpp> #include <sta/devices/stm32/hal.hpp>
@ -29,44 +30,47 @@ namespace sta
{ {
uint32_t gDelayUsMul = 1; uint32_t gDelayUsMul = 1;
bool isValidDelayUsTIM()
{
// Get PCLK multiplier for TIM clock
uint32_t pclkMul = 1;
switch (STA_STM32_DELAY_US_TIM.Init.ClockDivision)
{
case TIM_CLOCKDIVISION_DIV1:
pclkMul = 1;
break;
case TIM_CLOCKDIVISION_DIV2:
pclkMul = 2;
break;
case TIM_CLOCKDIVISION_DIV4:
pclkMul = 4;
break;
default:
STA_ASSERT(false);
STA_UNREACHABLE();
}
// Calculate TIM clock frequency
uint32_t clkFreq = pclkMul * STA_STM32_GET_HANDLE_PCLK_FREQ_FN(STA_STM32_DELAY_US_TIM)();
// Calculate update frequency based on prescaler value
uint32_t prescaler = (STA_STM32_DELAY_US_TIM.Init.Prescaler) ? STA_STM32_DELAY_US_TIM.Init.Prescaler : 1;
uint32_t updateFreq = clkFreq / prescaler;
gDelayUsMul = updateFreq / 1000000;
// TIM must have at least microsecond precision (>= 1 MHz frequency)
return (updateFreq >= 1000000);
}
void delayUs(uint32_t us) void delayUs(uint32_t us)
{ {
// Check if the specified timer is usable for microsecond delays.
STA_ASSERT(isValidDelayUsTIM());
__HAL_TIM_SET_COUNTER(&STA_STM32_DELAY_US_TIM, 0); __HAL_TIM_SET_COUNTER(&STA_STM32_DELAY_US_TIM, 0);
while (__HAL_TIM_GET_COUNTER(&STA_STM32_DELAY_US_TIM) < us * gDelayUsMul); while (__HAL_TIM_GET_COUNTER(&STA_STM32_DELAY_US_TIM) < us * gDelayUsMul);
} }
bool isValidDelayUsTIM()
{
// Get PCLK multiplier for TIM clock
uint32_t pclkMul = 1;
switch (STA_STM32_DELAY_US_TIM.Init.ClockDivision)
{
case TIM_CLOCKDIVISION_DIV1:
pclkMul = 1;
break;
case TIM_CLOCKDIVISION_DIV2:
pclkMul = 2;
break;
case TIM_CLOCKDIVISION_DIV4:
pclkMul = 4;
break;
default:
STA_ASSERT(false);
STA_UNREACHABLE();
}
// Calculate TIM clock frequency
uint32_t clkFreq = pclkMul * STA_STM32_GET_HANDLE_PCLK_FREQ_FN(STA_STM32_DELAY_US_TIM)();
// Calculate update frequency based on prescaler value
uint32_t prescaler = (STA_STM32_DELAY_US_TIM.Init.Prescaler) ? STA_STM32_DELAY_US_TIM.Init.Prescaler : 1;
uint32_t updateFreq = clkFreq / prescaler;
gDelayUsMul = updateFreq / 1000000;
// TIM must have at least microsecond precision (>= 1 MHz frequency)
return (updateFreq >= 1000000);
}
} // namespace sta } // namespace sta
#endif // STA_STM32_DELAY_US_TIM #endif // STA_STM32_DELAY_US_TIM