mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-22 20:03:34 +08:00
More warning fixes in the STM32 drvier, STM32 test project and the library core
This commit is contained in:
@@ -182,11 +182,11 @@ int CanIface::computeTimings(const uavcan::uint32_t target_bitrate, Timings& out
|
||||
|
||||
while (1)
|
||||
{
|
||||
prescaler = prescaler_bs / (1 + bs1 + bs2);
|
||||
prescaler = uavcan::uint16_t(prescaler_bs / unsigned(1 + bs1 + bs2));
|
||||
// Check result:
|
||||
if ((prescaler >= 1) && (prescaler <= 1024))
|
||||
{
|
||||
const uavcan::uint32_t current_bitrate = pclk / (prescaler * (1 + bs1 + bs2));
|
||||
const uavcan::uint32_t current_bitrate = pclk / (prescaler * unsigned(1 + bs1 + bs2));
|
||||
if (current_bitrate == target_bitrate)
|
||||
{
|
||||
break;
|
||||
@@ -209,10 +209,10 @@ int CanIface::computeTimings(const uavcan::uint32_t target_bitrate, Timings& out
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
out_timings.prescaler = prescaler - 1;
|
||||
out_timings.prescaler = uavcan::uint16_t(prescaler - 1U);
|
||||
out_timings.sjw = 1;
|
||||
out_timings.bs1 = bs1 - 1;
|
||||
out_timings.bs2 = bs2 - 1;
|
||||
out_timings.bs1 = uavcan::uint8_t(bs1 - 1);
|
||||
out_timings.bs2 = uavcan::uint8_t(bs2 - 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -365,10 +365,10 @@ int CanIface::init(uavcan::uint32_t bitrate)
|
||||
|
||||
can_->MCR = bxcan::MCR_ABOM | bxcan::MCR_AWUM | bxcan::MCR_INRQ; // RM page 648
|
||||
|
||||
can_->BTR = ((timings.sjw & 3) << 24) |
|
||||
((timings.bs1 & 15) << 16) |
|
||||
((timings.bs2 & 7) << 20) |
|
||||
(timings.prescaler & 1023);
|
||||
can_->BTR = ((timings.sjw & 3U) << 24) |
|
||||
((timings.bs1 & 15U) << 16) |
|
||||
((timings.bs2 & 7U) << 20) |
|
||||
(timings.prescaler & 1023U);
|
||||
|
||||
can_->IER = bxcan::IER_TMEIE | // TX mailbox empty
|
||||
bxcan::IER_FMPIE0 | // RX FIFO 0 is not empty
|
||||
@@ -419,7 +419,7 @@ leave:
|
||||
|
||||
void CanIface::pollErrorState()
|
||||
{
|
||||
const uavcan::uint8_t lec = (can_->ESR & bxcan::ESR_LEC_MASK) >> bxcan::ESR_LEC_SHIFT;
|
||||
const uavcan::uint8_t lec = uavcan::uint8_t((can_->ESR & bxcan::ESR_LEC_MASK) >> bxcan::ESR_LEC_SHIFT);
|
||||
if (lec != 0)
|
||||
{
|
||||
last_hw_error_code_ = lec;
|
||||
@@ -513,14 +513,14 @@ void CanIface::handleRxInterrupt(uavcan::uint8_t fifo_index, uavcan::uint64_t ut
|
||||
|
||||
frame.dlc = rf.RDTR & 15;
|
||||
|
||||
frame.data[0] = 0xFF & (rf.RDLR >> 0);
|
||||
frame.data[1] = 0xFF & (rf.RDLR >> 8);
|
||||
frame.data[2] = 0xFF & (rf.RDLR >> 16);
|
||||
frame.data[3] = 0xFF & (rf.RDLR >> 24);
|
||||
frame.data[4] = 0xFF & (rf.RDHR >> 0);
|
||||
frame.data[5] = 0xFF & (rf.RDHR >> 8);
|
||||
frame.data[6] = 0xFF & (rf.RDHR >> 16);
|
||||
frame.data[7] = 0xFF & (rf.RDHR >> 24);
|
||||
frame.data[0] = uavcan::uint8_t(0xFF & (rf.RDLR >> 0));
|
||||
frame.data[1] = uavcan::uint8_t(0xFF & (rf.RDLR >> 8));
|
||||
frame.data[2] = uavcan::uint8_t(0xFF & (rf.RDLR >> 16));
|
||||
frame.data[3] = uavcan::uint8_t(0xFF & (rf.RDLR >> 24));
|
||||
frame.data[4] = uavcan::uint8_t(0xFF & (rf.RDHR >> 0));
|
||||
frame.data[5] = uavcan::uint8_t(0xFF & (rf.RDHR >> 8));
|
||||
frame.data[6] = uavcan::uint8_t(0xFF & (rf.RDHR >> 16));
|
||||
frame.data[7] = uavcan::uint8_t(0xFF & (rf.RDHR >> 24));
|
||||
|
||||
*rfr_reg = bxcan::RFR_RFOM | bxcan::RFR_FOVR | bxcan::RFR_FULL; // Release FIFO entry we just read
|
||||
|
||||
|
||||
@@ -99,7 +99,9 @@ static uavcan::uint64_t sampleUtcFromCriticalSection()
|
||||
if (TIMX->SR & TIM_SR_UIF)
|
||||
{
|
||||
cnt = TIMX->CNT;
|
||||
time += USecPerOverflow + (utc_accumulated_correction_nsec + utc_correction_nsec_per_overflow) / 1000;
|
||||
const uavcan::int32_t add = uavcan::int32_t(USecPerOverflow) +
|
||||
(utc_accumulated_correction_nsec + utc_correction_nsec_per_overflow) / 1000;
|
||||
time = uavcan::uint64_t(uavcan::int64_t(time) + add);
|
||||
}
|
||||
return time + cnt;
|
||||
}
|
||||
@@ -156,9 +158,9 @@ static float lowpass(float xold, float xnew, float corner, float dt)
|
||||
static void updateRatePID(uavcan::UtcDuration adjustment)
|
||||
{
|
||||
const uavcan::MonotonicTime ts = getMonotonic();
|
||||
const float dt = (ts - prev_utc_adj_at).toUSec() / 1e6F;
|
||||
const float dt = float((ts - prev_utc_adj_at).toUSec()) / 1e6F;
|
||||
prev_utc_adj_at = ts;
|
||||
const float adj_usec = adjustment.toUSec();
|
||||
const float adj_usec = float(adjustment.toUSec());
|
||||
|
||||
/*
|
||||
* Target relative rate in PPM
|
||||
@@ -196,7 +198,7 @@ static void updateRatePID(uavcan::UtcDuration adjustment)
|
||||
total_rate_correction_ppm = uavcan::max(total_rate_correction_ppm, -utc_sync_params.max_rate_correction_ppm);
|
||||
total_rate_correction_ppm = uavcan::min(total_rate_correction_ppm, utc_sync_params.max_rate_correction_ppm);
|
||||
|
||||
utc_correction_nsec_per_overflow = (USecPerOverflow * 1000) * (total_rate_correction_ppm / 1e6F);
|
||||
utc_correction_nsec_per_overflow = uavcan::int32_t((USecPerOverflow * 1000) * (total_rate_correction_ppm / 1e6F));
|
||||
|
||||
// lowsyslog("$ adj=%f rel_rate=%f rel_rate_eint=%f tgt_rel_rate=%f ppm=%f\n",
|
||||
// adj_usec, utc_rel_rate_ppm, utc_rel_rate_error_integral, target_rel_rate_ppm, total_rate_correction_ppm);
|
||||
@@ -219,7 +221,7 @@ void adjustUtc(uavcan::UtcDuration adjustment)
|
||||
}
|
||||
else
|
||||
{
|
||||
time_utc += adj_usec;
|
||||
time_utc = uavcan::uint64_t(uavcan::int64_t(time_utc) + adj_usec);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,7 +247,7 @@ void adjustUtc(uavcan::UtcDuration adjustment)
|
||||
float getUtcRateCorrectionPPM()
|
||||
{
|
||||
MutexLocker mlocker(mutex);
|
||||
const float rate_correction_mult = utc_correction_nsec_per_overflow / float(USecPerOverflow * 1000);
|
||||
const float rate_correction_mult = float(utc_correction_nsec_per_overflow) / float(USecPerOverflow * 1000);
|
||||
return 1e6F * rate_correction_mult;
|
||||
}
|
||||
|
||||
@@ -320,7 +322,7 @@ UAVCAN_STM32_IRQ_HANDLER(TIMX_IRQHandler)
|
||||
utc_accumulated_correction_nsec += utc_correction_nsec_per_overflow;
|
||||
if (std::abs(utc_accumulated_correction_nsec) >= 1000)
|
||||
{
|
||||
time_utc += utc_accumulated_correction_nsec / 1000;
|
||||
time_utc = uavcan::uint64_t(uavcan::int64_t(time_utc) + utc_accumulated_correction_nsec / 1000);
|
||||
utc_accumulated_correction_nsec %= 1000;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user