xref: /aosp_15_r20/external/pigweed/pw_sync_freertos/public/pw_sync_freertos/config.h (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1 // Copyright 2021 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 // Configuration macros for the tokenizer module.
15 #pragma once
16 
17 #include "FreeRTOS.h"
18 
19 // Just like FreeRTOS Stream and Message Buffers, by default the optimized
20 // pw::sync::ThreadNotification uses the task notification at array index 0.
21 // This optimized backend is compatible with sharing the notification with
22 // Stream and Message Buffers and any other users which ONLY notify the task
23 // while the task is blocked and the task consumes the notification state
24 // before returning.
25 //
26 // The task's TCB uses a ucNotifyState which captures notification state even
27 // when the task is not waiting (taskNOT_WAITING_NOTIFICATION vs
28 // task_NOTIFICATION_RECEIVED). This notification state is used to determine
29 // whether the next task notification wait call should block, irrespective of
30 // the notification value. This means that one must ensure not just that
31 // the bits in the ulNotifiedValue are mutually exclusive, but also that the
32 // notification state is mutually exclusive!
33 #ifndef PW_SYNC_FREERTOS_CONFIG_THREAD_NOTIFICATION_INDEX
34 #define PW_SYNC_FREERTOS_CONFIG_THREAD_NOTIFICATION_INDEX 0
35 #endif  // PW_SYNC_FREERTOS_CONFIG_THREAD_NOTIFICATION_INDEX
36 
37 namespace pw::sync::freertos::config {
38 
39 inline constexpr UBaseType_t kThreadNotificationIndex =
40     PW_SYNC_FREERTOS_CONFIG_THREAD_NOTIFICATION_INDEX;
41 #ifdef configTASK_NOTIFICATION_ARRAY_ENTRIES
42 // Ensure the index fits within the FreeRTOS configuration of the task
43 // notification array.
44 static_assert(kThreadNotificationIndex < configTASK_NOTIFICATION_ARRAY_ENTRIES);
45 #else   // !defined(configTASK_NOTIFICATION_ARRAY_ENTRIES)
46 // This version of FreeRTOS does not support multiple task notifications, ensure
47 // the index is the default of 0.
48 static_assert(kThreadNotificationIndex == 0);
49 #endif  // configTASK_NOTIFICATION_ARRAY_ENTRIES
50 
51 }  // namespace pw::sync::freertos::config
52