Arm-2D  
2D Image Processing Library for Cortex-M Processors
arm_2d_helper.h
1/*
2 * Copyright (C) 2022 Arm Limited or its affiliates. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19/* ----------------------------------------------------------------------
20 * Project: Arm-2D Library
21 * Title: #include "arm_2d_helper.h"
22 * Description: Public header file for the all helper services
23 *
24 * $Date: 17. June 2022
25 * $Revision: V.1.0.1
26 *
27 * Target Processor: Cortex-M cores
28 * -------------------------------------------------------------------- */
29
30#ifndef __ARM_2D_HELPER_H__
31#define __ARM_2D_HELPER_H__
32
33/*============================ INCLUDES ======================================*/
34#include "arm_2d.h"
35#include "./arm_2d_helper_pfb.h"
36#include "./arm_2d_helper_scene.h"
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42#if defined(__clang__)
43# pragma clang diagnostic push
44# pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
45# pragma clang diagnostic ignored "-Wunused-function"
46#endif
47
48
49/*!
50 * \addtogroup gHelper 7 Helper Services
51 * @{
52 */
53/*============================ MACROS ========================================*/
54/*============================ MACROFIED FUNCTIONS ===========================*/
55
56#define __declare_tile(__NAME) \
57 extern const arm_2d_tile_t __NAME;
58#define declare_tile(__NAME) __declare_tile(__NAME)
59
60#define __implement_tile(__NAME, __WIDTH, __HEIGHT, __TYPE, ...) \
61 ARM_NOINIT static __TYPE \
62 __NAME##Buffer[(__WIDTH) * (__HEIGHT)]; \
63 const arm_2d_tile_t __NAME = { \
64 .tRegion = { \
65 .tSize = {(__WIDTH), (__HEIGHT)}, \
66 }, \
67 .tInfo.bIsRoot = true, \
68 .pchBuffer = (uint8_t *)__NAME##Buffer, \
69 __VA_ARGS__ \
70 };
71
72#define implement_tile(__NAME, __WIDTH, __HEIGHT, __TYPE, ...) \
73 __implement_tile(__NAME, __WIDTH, __HEIGHT, __TYPE, ##__VA_ARGS__)
74
75#define get_tile_buffer_pixel_count(__NAME) \
76 (uint32_t)( (__NAME.tRegion.tSize.iWidth) \
77 * (__NAME.tRegion.tSize.iHeight))
78
79#define get_tile_buffer_size(__NAME, __TYPE) \
80 (get_2d_layer_buffer_pixel_count(__NAME) * sizeof(TYPE))
81
82
83
84#define __arm_2d_align_centre2(__region, __size) \
85 for (arm_2d_region_t __centre_region = { \
86 .tSize = (__size), \
87 .tLocation = { \
88 .iX = ((__region).tSize.iWidth - (__size).iWidth) >> 1,\
89 .iY = ((__region).tSize.iHeight - (__size).iHeight)>> 1,\
90 }, \
91 }, \
92 *ARM_CONNECT3(__ARM_USING_, __LINE__,_ptr) = NULL; \
93 ARM_CONNECT3(__ARM_USING_, __LINE__,_ptr)++ == NULL; \
94 )
95
96#define __arm_2d_align_centre3(__region, __width, __height) \
97 for (arm_2d_region_t __centre_region = { \
98 .tSize = { \
99 .iWidth = (__width), \
100 .iHeight = (__height), \
101 }, \
102 .tLocation = { \
103 .iX = ((__region).tSize.iWidth - (__width)) >> 1, \
104 .iY = ((__region).tSize.iHeight - (__height))>> 1, \
105 }, \
106 }, \
107 *ARM_CONNECT3(__ARM_USING_, __LINE__,_ptr) = NULL; \
108 ARM_CONNECT3(__ARM_USING_, __LINE__,_ptr)++ == NULL; \
109 arm_2d_op_wait_async(NULL) \
110 )
111
112#define arm_2d_align_centre(...) \
113 ARM_CONNECT2( __arm_2d_align_centre, \
114 __ARM_VA_NUM_ARGS(__VA_ARGS__))(__VA_ARGS__)
115
116/*============================ TYPES =========================================*/
117/*============================ GLOBAL VARIABLES ==============================*/
118/*============================ LOCAL VARIABLES ===============================*/
119/*============================ PROTOTYPES ====================================*/
120
121/*!
122 * \brief set an alarm with given period and check the status
123 *
124 * \param[in] wMS a time period in millisecond
125 *
126 * \return bool whether it is timeout
127 */
128__STATIC_INLINE bool arm_2d_helper_is_time_out(uint32_t wMS)
129{
130 int64_t lTimestamp = arm_2d_helper_get_system_timestamp();
131 static int64_t s_lTimestamp = 0;
132 if (0 == s_lTimestamp) {
133 s_lTimestamp = arm_2d_helper_convert_ms_to_ticks(wMS);
134 s_lTimestamp += lTimestamp;
135
136 return false;
137 }
138
139 if (lTimestamp >= s_lTimestamp) {
140 s_lTimestamp = arm_2d_helper_convert_ms_to_ticks(wMS) + lTimestamp;
141 return true;
142 }
143
144 return false;
145}
146
147/*! @} */
148
149#if defined(__clang__)
150# pragma clang diagnostic pop
151#endif
152
153#ifdef __cplusplus
154}
155#endif
156
157#endif