mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
19610: drivers/periph/rtc: improve doc on rtc_set_alarm r=maribu a=maribu ### Contribution description - point out behavior on denormalized time stamps - use errno codes to indicate errors (and adapt the few instances of actual error handling to use them) 19670: cpu/stm32: stm32f4 BRR from BSRR r=maribu a=kfessel ### Contribution description sometimes one wants to save one instruction :) just write the bits we need to write. ### Testing procedure tests/periph/gpio_ll tests this ### Issues/PRs references `@maribu` might know some reference maybe #19407 19678: gnrc_sixlowpan_iphc: fix NULL pointer dereference r=maribu a=miri64 19679: gnrc_sixlowpan_frag_sfr: fix ARQ scheduler race-condition r=maribu a=miri64 19680: gnrc_sixlowpan_frag_rb: fix OOB write in _rbuf_add r=maribu a=miri64 19681: sys/xtimer: improve documentation r=maribu a=maribu ### Contribution description - Add a warning that xtimer is deprecated, so that new code hopefully starts using ztimer - Add a hint that `ztimer_xtimer_compat` can be used even after `xtimer` is gone Co-authored-by: Marian Buschsieweke <marian.buschsieweke@ovgu.de> Co-authored-by: Karl Fessel <karl.fessel@ovgu.de> Co-authored-by: Martine Lenders <m.lenders@fu-berlin.de>
This commit is contained in:
commit
00b5bc12a2
@ -22,13 +22,14 @@
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <err.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "periph/rtc.h"
|
||||
#include "cpu.h"
|
||||
#include "periph/rtc.h"
|
||||
#include "timex.h"
|
||||
#include "ztimer.h"
|
||||
|
||||
@ -206,11 +207,11 @@ int rtc_set_alarm(struct tm *time, rtc_alarm_cb_t cb, void *arg)
|
||||
{
|
||||
if (!_native_rtc_initialized) {
|
||||
warnx("rtc_set_alarm: not initialized");
|
||||
return -1;
|
||||
return -EIO;
|
||||
}
|
||||
if (!_native_rtc_powered) {
|
||||
warnx("rtc_set_alarm: not powered on");
|
||||
return -1;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
struct tm now;
|
||||
|
@ -20,6 +20,7 @@
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "cpu.h"
|
||||
@ -104,7 +105,7 @@ int rtc_set_alarm(struct tm *time, rtc_alarm_cb_t cb, void *arg)
|
||||
if (ts <= RTC->SEC) {
|
||||
/* The requested time is in the past at the time of executing this
|
||||
* instruction, so we return invalid time. */
|
||||
return -2;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* If the requested time arrives (SEC_INT should have fired) before we get
|
||||
|
@ -26,8 +26,10 @@
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "pm_layered.h"
|
||||
#include "periph/rtc.h"
|
||||
#include "periph/rtt.h"
|
||||
@ -611,7 +613,7 @@ int rtc_set_alarm(struct tm *time, rtc_alarm_cb_t cb, void *arg)
|
||||
|
||||
if ((time->tm_year < reference_year) ||
|
||||
(time->tm_year > (reference_year + 63))) {
|
||||
return -2;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* make sure that preceding changes have been applied */
|
||||
|
@ -77,7 +77,9 @@ static inline void gpio_ll_clear(gpio_port_t port, uword_t mask)
|
||||
#if defined(GPIO_BRR_BR0) && !defined(CPU_FAM_STM32F4)
|
||||
p->BRR = mask;
|
||||
#else
|
||||
p->BSRR = mask << 16;
|
||||
/* The first half-word sets GPIOs, the second half-world clears GPIOs */
|
||||
volatile uint16_t *brr = (volatile uint16_t *)&(p->BSRR);
|
||||
brr[1] = (uint16_t)mask;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -113,9 +113,14 @@ int rtc_get_time_ms(struct tm *time, uint16_t *ms);
|
||||
* @param[in] cb Callback executed when alarm is hit.
|
||||
* @param[in] arg Argument passed to callback when alarm is hit.
|
||||
*
|
||||
* @return 0 for success
|
||||
* @return -2 invalid `time` parameter
|
||||
* @return -1 other errors
|
||||
* @note The driver must be prepared to work with denormalized time values
|
||||
* (e.g. seconds > 60). The driver may normalize the value, or just
|
||||
* keep it denormalized. In either case, the timeout should occur at
|
||||
* the equivalent normalized time.
|
||||
*
|
||||
* @retval 0 success
|
||||
* @return -EINVAL @p time was invalid (e.g. in the past, out of range)
|
||||
* @return <0 other error (negative errno code to indicate cause)
|
||||
*/
|
||||
int rtc_set_alarm(struct tm *time, rtc_alarm_cb_t cb, void *arg);
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
@ -8,11 +8,11 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup sys_xtimer Timers
|
||||
* @ingroup sys
|
||||
* @brief Provides a high level timer module to register
|
||||
* timers, get current system time, and let a thread sleep for
|
||||
* a certain amount of time.
|
||||
* @defgroup sys_xtimer xtimer high level timer abstraction layer (deprecated)
|
||||
* @ingroup sys
|
||||
* @brief Provides a high level timer module to register
|
||||
* timers, get current system time, and let a thread sleep for
|
||||
* a certain amount of time.
|
||||
*
|
||||
* The implementation takes one low-level timer and multiplexes it.
|
||||
*
|
||||
@ -20,6 +20,19 @@
|
||||
* number of active timers. The reason for this is that multiplexing is
|
||||
* realized by next-first singly linked lists.
|
||||
*
|
||||
* @deprecated xtimer has been deprecated in favor of the @ref sys_ztimer
|
||||
* @note With @ref sys_ztimer_xtimer_compat a compatibility wrapper is
|
||||
* provided that in the vast majority of cases can function as a
|
||||
* drop-in replacement. This compatibility wrapper is expected to
|
||||
* replace `xtimer` in the near future and ensure that code still
|
||||
* depending on the `xtimer` API continues to function.
|
||||
* @details Note that at least for long running timers, using
|
||||
* @ref sys_ztimer instead of the compatibility layer can yield
|
||||
* lower clock drift and lower power consumption compared to
|
||||
* using the compatibility layer. For details on how to achieve
|
||||
* lower clock drift and lower power consumption please consult the
|
||||
* @ref sys_ztimer documentation.
|
||||
*
|
||||
* @{
|
||||
* @file
|
||||
* @brief xtimer interface definitions
|
||||
|
@ -461,6 +461,19 @@ static int _rbuf_add(gnrc_netif_hdr_t *netif_hdr, gnrc_pktsnip_t *pkt,
|
||||
else if (IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_SFR) &&
|
||||
sixlowpan_sfr_rfrag_is(pkt->data)) {
|
||||
entry.super->datagram_size--;
|
||||
/* Check, if fragment is still small enough to fit datagram size.
|
||||
* `offset` is 0, as this is the first fragment so it does not have to be added
|
||||
* here. */
|
||||
if (frag_size > entry.super->datagram_size) {
|
||||
DEBUG_PUTS(
|
||||
"6lo rfrag: fragment too big for resulting datagram, "
|
||||
"discarding datagram\n"
|
||||
);
|
||||
gnrc_pktbuf_release(entry.rbuf->pkt);
|
||||
gnrc_pktbuf_release(pkt);
|
||||
gnrc_sixlowpan_frag_rb_remove(entry.rbuf);
|
||||
return RBUF_ADD_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -506,7 +506,6 @@ void gnrc_sixlowpan_frag_sfr_arq_timeout(gnrc_sixlowpan_frag_fb_t *fbuf)
|
||||
int error_no = ETIMEDOUT; /* assume time out for fbuf->pkt */
|
||||
|
||||
DEBUG("6lo sfr: ARQ timeout for datagram %u\n", fbuf->tag);
|
||||
fbuf->sfr.arq_timeout_event.msg.content.ptr = NULL;
|
||||
if (IS_ACTIVE(CONFIG_GNRC_SIXLOWPAN_SFR_MOCK_ARQ_TIMER)) {
|
||||
/* mock-up to emulate time having passed beyond (1us) the ARQ timeout */
|
||||
now -= (fbuf->sfr.arq_timeout * US_PER_MS) + 1;
|
||||
@ -681,7 +680,6 @@ static void _clean_slate_datagram(gnrc_sixlowpan_frag_fb_t *fbuf)
|
||||
/* remove potentially scheduled timers for this datagram */
|
||||
evtimer_del((evtimer_t *)(&_arq_timer),
|
||||
&fbuf->sfr.arq_timeout_event.event);
|
||||
fbuf->sfr.arq_timeout_event.event.next = NULL;
|
||||
if (gnrc_sixlowpan_frag_sfr_congure_snd_has_inter_frame_gap()) {
|
||||
for (clist_node_t *node = clist_lpop(&_frame_queue);
|
||||
node != NULL; node = clist_lpop(&_frame_queue)) {
|
||||
@ -1708,13 +1706,26 @@ static void _sched_next_frame(gnrc_sixlowpan_frag_fb_t *fbuf)
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool _arq_scheduled(gnrc_sixlowpan_frag_fb_t *fbuf)
|
||||
{
|
||||
evtimer_event_t *ptr = _arq_timer.events;
|
||||
evtimer_event_t *event = &fbuf->sfr.arq_timeout_event.event;
|
||||
while (ptr) {
|
||||
if (ptr == event) {
|
||||
return true;
|
||||
}
|
||||
ptr = ptr->next;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void _sched_arq_timeout(gnrc_sixlowpan_frag_fb_t *fbuf, uint32_t offset)
|
||||
{
|
||||
if (IS_ACTIVE(CONFIG_GNRC_SIXLOWPAN_SFR_MOCK_ARQ_TIMER)) {
|
||||
/* mock does not need to be scheduled */
|
||||
return;
|
||||
}
|
||||
if (fbuf->sfr.arq_timeout_event.msg.content.ptr != NULL) {
|
||||
if (_arq_scheduled(fbuf)) {
|
||||
DEBUG("6lo sfr: ARQ timeout for datagram %u already scheduled\n",
|
||||
(uint8_t)fbuf->tag);
|
||||
return;
|
||||
@ -1804,7 +1815,6 @@ static void _handle_ack(gnrc_netif_hdr_t *netif_hdr, gnrc_pktsnip_t *pkt,
|
||||
DEBUG("6lo sfr: cancelling ARQ timeout\n");
|
||||
evtimer_del((evtimer_t *)(&_arq_timer),
|
||||
&fbuf->sfr.arq_timeout_event.event);
|
||||
fbuf->sfr.arq_timeout_event.msg.content.ptr = NULL;
|
||||
if ((unaligned_get_u32(hdr->bitmap) == _null_bitmap.u32)) {
|
||||
/* ACK indicates the reassembling endpoint canceled reassembly
|
||||
*/
|
||||
|
@ -1074,12 +1074,18 @@ static size_t _iphc_ipv6_encode(gnrc_pktsnip_t *pkt,
|
||||
uint8_t *iphc_hdr)
|
||||
{
|
||||
gnrc_sixlowpan_ctx_t *src_ctx = NULL, *dst_ctx = NULL;
|
||||
ipv6_hdr_t *ipv6_hdr = pkt->next->data;
|
||||
ipv6_hdr_t *ipv6_hdr;
|
||||
bool addr_comp = false;
|
||||
uint16_t inline_pos = SIXLOWPAN_IPHC_HDR_LEN;
|
||||
|
||||
assert(iface != NULL);
|
||||
|
||||
if (pkt->next == NULL) {
|
||||
DEBUG("6lo iphc: packet missing header\n");
|
||||
return 0;
|
||||
}
|
||||
ipv6_hdr = pkt->next->data;
|
||||
|
||||
/* set initial dispatch value*/
|
||||
iphc_hdr[IPHC1_IDX] = SIXLOWPAN_IPHC1_DISP;
|
||||
iphc_hdr[IPHC2_IDX] = 0;
|
||||
@ -1742,6 +1748,14 @@ void gnrc_sixlowpan_iphc_send(gnrc_pktsnip_t *pkt, void *ctx, unsigned page)
|
||||
gnrc_sixlowpan_multiplex_by_size(tmp, orig_datagram_size, netif, page);
|
||||
}
|
||||
else {
|
||||
if (IS_USED(MODULE_GNRC_SIXLOWPAN_FRAG_MINFWD)) {
|
||||
gnrc_sixlowpan_frag_fb_t *fb = ctx;
|
||||
|
||||
if (fb->pkt == pkt) {
|
||||
/* free provided fragmentation buffer */
|
||||
fb->pkt = NULL;
|
||||
}
|
||||
}
|
||||
gnrc_pktbuf_release(pkt);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user