1 /**
2 * @file lv_gpu_nxp_pxp_osa.c
3 *
4 */
5
6 /**
7 * MIT License
8 *
9 * Copyright (c) 2020 NXP
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights to
14 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15 * the Software, and to permit persons to whom the Software is furnished to do so,
16 * subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice (including the next paragraph)
19 * shall be included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 *
28 */
29
30 /*********************
31 * INCLUDES
32 *********************/
33
34 #include "lv_gpu_nxp_pxp_osa.h"
35 #if LV_USE_GPU_NXP_PXP && LV_USE_GPU_NXP_PXP_AUTO_INIT
36 #include "../misc/lv_log.h"
37
38
39 #include "lv_gpu_nxp_pxp.h"
40 #include "fsl_pxp.h"
41
42 #if defined(SDK_OS_FREE_RTOS)
43 #include "FreeRTOS.h"
44 #include "semphr.h"
45 #endif
46
47 /*********************
48 * DEFINES
49 *********************/
50
51 /**********************
52 * TYPEDEFS
53 **********************/
54
55 /**********************
56 * STATIC PROTOTYPES
57 **********************/
58 static lv_res_t _lv_gpu_nxp_pxp_interrupt_init(void);
59 static void _lv_gpu_nxp_pxp_interrupt_deinit(void);
60 static void _lv_gpu_nxp_pxp_run(void);
61
62 /**********************
63 * STATIC VARIABLES
64 **********************/
65
66 #if defined(SDK_OS_FREE_RTOS)
67 static SemaphoreHandle_t s_pxpIdle;
68 #else
69 static volatile bool s_pxpIdle;
70 #endif
71
72 /**********************
73 * MACROS
74 **********************/
75
76 /**********************
77 * GLOBAL FUNCTIONS
78 **********************/
79
80 /**
81 * PXP device interrupt handler. Used to check PXP task completion status.
82 */
PXP_IRQHandler(void)83 void PXP_IRQHandler(void)
84 {
85 #if defined(SDK_OS_FREE_RTOS)
86 BaseType_t taskAwake = pdFALSE;
87 #endif
88
89 if(kPXP_CompleteFlag & PXP_GetStatusFlags(LV_GPU_NXP_PXP_ID)) {
90 PXP_ClearStatusFlags(LV_GPU_NXP_PXP_ID, kPXP_CompleteFlag);
91 #if defined(SDK_OS_FREE_RTOS)
92 xSemaphoreGiveFromISR(s_pxpIdle, &taskAwake);
93 portYIELD_FROM_ISR(taskAwake);
94 #else
95 s_pxpIdle = true;
96 #endif
97
98 }
99 }
100
101 /**********************
102 * STATIC FUNCTIONS
103 **********************/
104
105 /**
106 * PXP interrupt initialization.
107 */
_lv_gpu_nxp_pxp_interrupt_init(void)108 static lv_res_t _lv_gpu_nxp_pxp_interrupt_init(void)
109 {
110 #if defined(SDK_OS_FREE_RTOS)
111 s_pxpIdle = xSemaphoreCreateBinary();
112 if(s_pxpIdle == NULL) {
113 return LV_RES_INV;
114 }
115
116 NVIC_SetPriority(LV_GPU_NXP_PXP_IRQ_ID, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 1);
117 #else
118 s_pxpIdle = true;
119 #endif
120
121 NVIC_EnableIRQ(LV_GPU_NXP_PXP_IRQ_ID);
122
123 return LV_RES_OK;
124 }
125
126 /**
127 * PXP interrupt de-initialization.
128 */
_lv_gpu_nxp_pxp_interrupt_deinit(void)129 static void _lv_gpu_nxp_pxp_interrupt_deinit(void)
130 {
131 NVIC_DisableIRQ(LV_GPU_NXP_PXP_IRQ_ID);
132 #if defined(SDK_OS_FREE_RTOS)
133 vSemaphoreDelete(s_pxpIdle);
134 #endif
135 }
136
137 /**
138 * Function to start PXP job. This function must wait for task complete.
139 */
_lv_gpu_nxp_pxp_run(void)140 static void _lv_gpu_nxp_pxp_run(void)
141 {
142 #if !defined(SDK_OS_FREE_RTOS)
143 s_pxpIdle = false;
144 #endif
145
146 PXP_EnableInterrupts(LV_GPU_NXP_PXP_ID, kPXP_CompleteInterruptEnable);
147 PXP_Start(LV_GPU_NXP_PXP_ID);
148
149 #if defined(SDK_OS_FREE_RTOS)
150 if(xSemaphoreTake(s_pxpIdle, portMAX_DELAY) != pdTRUE) {
151 LV_LOG_ERROR("xSemaphoreTake error. Task halted.");
152 for(; ;) ;
153 }
154 #else
155 while(s_pxpIdle == false) {
156 }
157 #endif
158 }
159
160 lv_nxp_pxp_cfg_t pxp_default_cfg = {
161 .pxp_interrupt_init = _lv_gpu_nxp_pxp_interrupt_init,
162 .pxp_interrupt_deinit = _lv_gpu_nxp_pxp_interrupt_deinit,
163 .pxp_run = _lv_gpu_nxp_pxp_run
164 };
165
166 #endif /*LV_USE_GPU_NXP_PXP && LV_USE_GPU_NXP_PXP_AUTO_INIT*/
167