os.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 The Apache Software Foundation (ASF)
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * SPDX-FileContributor: 2019-2022 Espressif Systems (Shanghai) CO LTD
  7. */
  8. /*
  9. * Licensed to the Apache Software Foundation (ASF) under one
  10. * or more contributor license agreements. See the NOTICE file
  11. * distributed with this work for additional information
  12. * regarding copyright ownership. The ASF licenses this file
  13. * to you under the Apache License, Version 2.0 (the
  14. * "License"); you may not use this file except in compliance
  15. * with the License. You may obtain a copy of the License at
  16. *
  17. * http://www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing,
  20. * software distributed under the License is distributed on an
  21. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22. * KIND, either express or implied. See the License for the
  23. * specific language governing permissions and limitations
  24. * under the License.
  25. */
  26. #ifndef _OS_H
  27. #define _OS_H
  28. #include <assert.h>
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. #if !defined __cplusplus
  33. #define static_assert _Static_assert
  34. #endif
  35. #ifndef min
  36. #define min(a, b) ((a)<(b)?(a):(b))
  37. #endif
  38. #ifndef max
  39. #define max(a, b) ((a)>(b)?(a):(b))
  40. #endif
  41. #include "soc/soc_caps.h"
  42. #include "nimble/nimble_npl.h"
  43. #define OS_ALIGN(__n, __a) ( \
  44. (((__n) & ((__a) - 1)) == 0) ? \
  45. (__n) : \
  46. ((__n) + ((__a) - ((__n) & ((__a) - 1)))) \
  47. )
  48. #define OS_ALIGNMENT (BLE_NPL_OS_ALIGNMENT)
  49. typedef uint32_t os_sr_t;
  50. #define OS_ENTER_CRITICAL(_sr) (_sr = ble_npl_hw_enter_critical())
  51. #define OS_EXIT_CRITICAL(_sr) (ble_npl_hw_exit_critical(_sr))
  52. #define OS_ASSERT_CRITICAL() assert(ble_npl_hw_is_in_critical())
  53. /* Mynewt components (not abstracted in NPL) */
  54. #include "os/endian.h"
  55. #include "os/queue.h"
  56. #include "os/os_error.h"
  57. #include "os/os_mbuf.h"
  58. #include "os/os_mempool.h"
  59. #ifdef __cplusplus
  60. }
  61. #endif
  62. #endif /* _OS_H */