summaryrefslogtreecommitdiff
path: root/include/usb_pd_timer.h
diff options
context:
space:
mode:
authorDawid Niedzwiecki <dn@semihalf.com>2022-03-02 14:34:04 +0100
committerCommit Bot <commit-bot@chromium.org>2022-03-10 12:24:10 +0000
commit31950eb9061587c09e8fd01f71f8c5cbb965a7be (patch)
treef084e969c2465b52a6144e81754fc577b5fd5aee /include/usb_pd_timer.h
parent149714923f920d1453027be638414f40538a3eda (diff)
downloadchrome-ec-31950eb9061587c09e8fd01f71f8c5cbb965a7be.tar.gz
usb_pd_timer: use atomic_*_bit functions
There are many atomic operations on the timer_active and timer_disabled variables. Change their type to atomic_t and use atomic_*_bit functions. It simplifies and unifies the bit operations. Also, the change saves memory 240-512B of FLASH depending on a board. BUG=b:208435177 TEST=zmake testall & make buildall & run faft_pd and make sure there is no regression BRANCH=none Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com> Change-Id: I880d07b2fe51b27bea1aacba884eacaede6476c6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3488374 Reviewed-by: Denis Brockus <dbrockus@chromium.org> Commit-Queue: Dawid Niedzwiecki <dawidn@google.com>
Diffstat (limited to 'include/usb_pd_timer.h')
-rw-r--r--include/usb_pd_timer.h44
1 files changed, 15 insertions, 29 deletions
diff --git a/include/usb_pd_timer.h b/include/usb_pd_timer.h
index 1ed268f14d..3a3f388b22 100644
--- a/include/usb_pd_timer.h
+++ b/include/usb_pd_timer.h
@@ -11,6 +11,7 @@
#include <stdbool.h>
#include "atomic.h"
+#include "atomic_bit.h"
/*
* List of all timers that will be managed by usb_pd_timer
@@ -333,43 +334,28 @@ void pd_timer_dump(int port);
/* exported: number of USB-C ports */
#define MAX_PD_PORTS CONFIG_USB_PD_PORT_MAX_COUNT
-/* exported: number of uint32_t fields for bit mask to all timers */
-#define TIMER_FIELD_NUM_UINT32S 2
/* PD timers have three possible states: Active, Inactive and Disabled */
/* exported: timer_active indicates if a timer is currently active */
-extern uint32_t timer_active[MAX_PD_PORTS][TIMER_FIELD_NUM_UINT32S];
+extern ATOMIC_DEFINE(timer_active, PD_TIMER_COUNT * MAX_PD_PORTS);
/* exported: timer_disabled indicates if a timer is currently disabled */
-extern uint32_t timer_disabled[MAX_PD_PORTS][TIMER_FIELD_NUM_UINT32S];
-
-/* exported: do not call directly, only for the defined macros */
-extern void pd_timer_atomic_op(
- atomic_val_t (*op)(atomic_t*, atomic_val_t),
- atomic_t *const timer_field, const uint64_t mask);
+extern ATOMIC_DEFINE(timer_disabled, PD_TIMER_COUNT * MAX_PD_PORTS);
/* exported: set/clear/check the current timer_active for a timer */
-#define PD_SET_ACTIVE(p, m) pd_timer_atomic_op( \
- atomic_or, \
- (atomic_t *)timer_active[p], \
- (m))
-#define PD_CLR_ACTIVE(p, m) pd_timer_atomic_op( \
- atomic_clear_bits, \
- (atomic_t *)timer_active[p], \
- (m))
-#define PD_CHK_ACTIVE(p, m) ((timer_active[p][0] & ((m) >> 32)) | \
- (timer_active[p][1] & (m)))
+#define PD_SET_ACTIVE(p, bit) \
+ atomic_set_bit(timer_active, (p) * PD_TIMER_COUNT + (bit))
+#define PD_CLR_ACTIVE(p, bit) \
+ atomic_clear_bit(timer_active, (p) * PD_TIMER_COUNT + (bit))
+#define PD_CHK_ACTIVE(p, bit) \
+ atomic_test_bit(timer_active, (p) * PD_TIMER_COUNT + (bit))
/* exported: set/clear/check the current timer_disabled for a timer */
-#define PD_SET_DISABLED(p, m) pd_timer_atomic_op( \
- atomic_or, \
- (atomic_t *)timer_disabled[p], \
- (m))
-#define PD_CLR_DISABLED(p, m) pd_timer_atomic_op( \
- atomic_clear_bits, \
- (atomic_t *)timer_disabled[p], \
- (m))
-#define PD_CHK_DISABLED(p, m) ((timer_disabled[p][0] & ((m) >> 32)) | \
- (timer_disabled[p][1] & (m)))
+#define PD_SET_DISABLED(p, bit) \
+ atomic_set_bit(timer_disabled, (p) * PD_TIMER_COUNT + (bit))
+#define PD_CLR_DISABLED(p, bit) \
+ atomic_clear_bit(timer_disabled, (p) * PD_TIMER_COUNT + (bit))
+#define PD_CHK_DISABLED(p, bit) \
+ atomic_test_bit(timer_disabled, (p) * PD_TIMER_COUNT + (bit))
#endif /* TEST_BUILD */