Skip to content

Commit b1081ee

Browse files
committed
Update lp ticker wrapper
Create a dedicated header file for mbed_lp_ticker_wrapper along with adding the function lp_ticker_get_timeout_pending to tell if the a Timeout object is used by the lp ticker.
1 parent be215a3 commit b1081ee

File tree

3 files changed

+81
-19
lines changed

3 files changed

+81
-19
lines changed

hal/mbed_lp_ticker_api.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
* limitations under the License.
1515
*/
1616
#include "hal/lp_ticker_api.h"
17+
#include "hal/mbed_lp_ticker_wrapper.h"
1718

1819
#if DEVICE_LPTICKER
1920

20-
void lp_ticker_set_interrupt_wrapper(timestamp_t timestamp);
21-
2221
static ticker_event_queue_t events = { 0 };
2322

2423
static ticker_irq_handler_type irq_handler = ticker_irq_handler;

hal/mbed_lp_ticker_wrapper.cpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
#include "hal/lp_ticker_api.h"
16+
#include "hal/mbed_lp_ticker_wrapper.h"
1717

1818
#if DEVICE_LPTICKER && (LPTICKER_DELAY_TICKS > 0)
1919

@@ -104,22 +104,7 @@ static void set_interrupt_later()
104104
core_util_critical_section_exit();
105105
}
106106

107-
/**
108-
* Wrapper around lp_ticker_set_interrupt to prevent blocking
109-
*
110-
* Problems this function is solving:
111-
* 1. Interrupt may not fire if set earlier than LPTICKER_DELAY_TICKS low power clock cycles
112-
* 2. Setting the interrupt back-to-back will block
113-
*
114-
* This wrapper function prevents lp_ticker_set_interrupt from being called
115-
* back-to-back and blocking while the first write is in progress. This function
116-
* avoids that problem by scheduling a timeout event if the lp ticker is in the
117-
* middle of a write operation.
118-
*
119-
* @param timestamp Time to call ticker irq
120-
* @note this is a utility function and it's not required part of HAL implementation
121-
*/
122-
extern "C" void lp_ticker_set_interrupt_wrapper(timestamp_t timestamp)
107+
void lp_ticker_set_interrupt_wrapper(timestamp_t timestamp)
123108
{
124109
core_util_critical_section_enter();
125110

@@ -153,4 +138,15 @@ extern "C" void lp_ticker_set_interrupt_wrapper(timestamp_t timestamp)
153138
core_util_critical_section_exit();
154139
}
155140

141+
bool lp_ticker_get_timeout_pending()
142+
{
143+
core_util_critical_section_enter();
144+
145+
bool pending = timeout_pending;
146+
147+
core_util_critical_section_exit();
148+
149+
return pending;
150+
}
151+
156152
#endif

hal/mbed_lp_ticker_wrapper.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
2+
/** \addtogroup hal */
3+
/** @{*/
4+
/* mbed Microcontroller Library
5+
* Copyright (c) 2018 ARM Limited
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
#ifndef MBED_LP_TICKER_WRAPPER_H
20+
#define MBED_LP_TICKER_WRAPPER_H
21+
22+
#include "device.h"
23+
24+
#if DEVICE_LPTICKER && (LPTICKER_DELAY_TICKS > 0)
25+
26+
#include "hal/ticker_api.h"
27+
#include <stdbool.h>
28+
29+
#ifdef __cplusplus
30+
extern "C" {
31+
#endif
32+
33+
/**
34+
* Wrapper around lp_ticker_set_interrupt to prevent blocking
35+
*
36+
* Problems this function is solving:
37+
* 1. Interrupt may not fire if set earlier than LPTICKER_DELAY_TICKS low power clock cycles
38+
* 2. Setting the interrupt back-to-back will block
39+
*
40+
* This wrapper function prevents lp_ticker_set_interrupt from being called
41+
* back-to-back and blocking while the first write is in progress. This function
42+
* avoids that problem by scheduling a timeout event if the lp ticker is in the
43+
* middle of a write operation.
44+
*
45+
* @param timestamp Time to call ticker irq
46+
* @note this is a utility function and it's not required part of HAL implementation
47+
*/
48+
void lp_ticker_set_interrupt_wrapper(timestamp_t timestamp);
49+
50+
/**
51+
* Check if the Timer object used by the wrapper is active
52+
*
53+
* @return true if the Timer object is scheduled, false otherwise
54+
*/
55+
bool lp_ticker_get_timeout_pending();
56+
57+
/**@}*/
58+
59+
#ifdef __cplusplus
60+
}
61+
#endif
62+
63+
#endif
64+
65+
#endif
66+
67+
/** @}*/

0 commit comments

Comments
 (0)