Skip to content

Commit d56d434

Browse files
[RPSDK-1389] Enable rpmsg-lite Zephyr for RT700 and RT600
Signed-off-by: Tomas Galbicka <tomas.galbicka@nxp.com>
1 parent 2fc18c7 commit d56d434

27 files changed

Lines changed: 1378 additions & 15 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- Added i.MX952 parts support
1414
- Added mcxl14x parts support
1515
- Added mcxw70 parts support
16+
- Zephyr rpmsg-lite samples add support for RT600 and RT700 DSP cores
1617

1718
### Changed
1819

lib/include/rpmsg_compiler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@
100100
#define MEM_BARRIER() __asm__ volatile("dsb sy" : : : "memory")
101101
#elif defined(__riscv)
102102
#define MEM_BARRIER() mb()
103+
#elif defined(__XTENSA__)
104+
#define MEM_BARRIER() __asm__ __volatile__("memw" : : : "memory")
103105
#else
104106
#define MEM_BARRIER() __asm__ volatile("dsb" : : : "memory")
105107
#endif
Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
/*
2+
* Copyright 2023-2024 NXP
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
#include <stdio.h>
7+
#include <string.h>
8+
9+
#include "rpmsg_platform.h"
10+
#include "rpmsg_env.h"
11+
#include <zephyr/drivers/ipm.h>
12+
13+
#if defined(RL_USE_ENVIRONMENT_CONTEXT) && (RL_USE_ENVIRONMENT_CONTEXT == 1)
14+
#error "This RPMsg-Lite port requires RL_USE_ENVIRONMENT_CONTEXT set to 0"
15+
#endif
16+
17+
static int32_t isr_counter = 0;
18+
static int32_t disable_counter = 0;
19+
static void *platform_lock;
20+
#if defined(RL_USE_STATIC_API) && (RL_USE_STATIC_API == 1)
21+
static LOCK_STATIC_CONTEXT platform_lock_static_ctxt;
22+
#endif
23+
static const struct device *const ipm_handle = DEVICE_DT_GET(DT_CHOSEN(zephyr_ipc));
24+
static unsigned int irq_key;
25+
26+
void platform_ipm_callback(const struct device *dev, void *context, uint32_t id, volatile void *data)
27+
{
28+
if (((*(uint32_t *)data) & 0x01) != 0UL)
29+
{
30+
env_isr(0);
31+
}
32+
if (((*(uint32_t *)data) & 0x02) != 0UL)
33+
{
34+
env_isr(1);
35+
}
36+
}
37+
38+
static void platform_global_isr_disable(void)
39+
{
40+
irq_key = irq_lock();
41+
}
42+
43+
static void platform_global_isr_enable(void)
44+
{
45+
irq_unlock(irq_key);
46+
}
47+
48+
int32_t platform_init_interrupt(uint32_t vector_id, void *isr_data)
49+
{
50+
/* Register ISR to environment layer */
51+
env_register_isr(vector_id, isr_data);
52+
53+
env_lock_mutex(platform_lock);
54+
55+
RL_ASSERT(0 <= isr_counter);
56+
57+
isr_counter++;
58+
59+
env_unlock_mutex(platform_lock);
60+
61+
return 0;
62+
}
63+
64+
int32_t platform_deinit_interrupt(uint32_t vector_id)
65+
{
66+
/* Prepare the MU Hardware */
67+
env_lock_mutex(platform_lock);
68+
69+
RL_ASSERT(0 < isr_counter);
70+
isr_counter--;
71+
if ((isr_counter == 0) && (ipm_handle != ((void *)0)))
72+
{
73+
ipm_set_enabled(ipm_handle, 0);
74+
}
75+
76+
/* Unregister ISR from environment layer */
77+
env_unregister_isr(vector_id);
78+
79+
env_unlock_mutex(platform_lock);
80+
81+
return 0;
82+
}
83+
84+
void platform_notify(uint32_t vector_id)
85+
{
86+
env_lock_mutex(platform_lock);
87+
uint32_t data = (1 << RL_GET_Q_ID(vector_id));
88+
RL_ASSERT(ipm_handle);
89+
ipm_send(ipm_handle, 0, 0, &data, sizeof(uint32_t));
90+
env_unlock_mutex(platform_lock);
91+
}
92+
93+
/**
94+
* platform_in_isr
95+
*
96+
* Return whether CPU is processing IRQ
97+
*
98+
* @return True for IRQ, false otherwise.
99+
*
100+
*/
101+
int32_t platform_in_isr(void)
102+
{
103+
return (0 != k_is_in_isr());
104+
}
105+
106+
/**
107+
* platform_interrupt_enable
108+
*
109+
* Enable peripheral-related interrupt
110+
*
111+
* @param vector_id Virtual vector ID that needs to be converted to IRQ number
112+
*
113+
* @return vector_id Return value is never checked.
114+
*
115+
*/
116+
int32_t platform_interrupt_enable(uint32_t vector_id)
117+
{
118+
RL_ASSERT(0 < disable_counter);
119+
120+
platform_global_isr_disable();
121+
disable_counter--;
122+
123+
if ((disable_counter == 0) && (ipm_handle != ((void *)0)))
124+
{
125+
ipm_set_enabled(ipm_handle, 1);
126+
}
127+
platform_global_isr_enable();
128+
return 0;
129+
}
130+
131+
/**
132+
* platform_interrupt_disable
133+
*
134+
* Disable peripheral-related interrupt.
135+
*
136+
* @param vector_id Virtual vector ID that needs to be converted to IRQ number
137+
*
138+
* @return vector_id Return value is never checked.
139+
*
140+
*/
141+
int32_t platform_interrupt_disable(uint32_t vector_id)
142+
{
143+
RL_ASSERT(0 <= disable_counter);
144+
145+
platform_global_isr_disable();
146+
/* virtqueues use the same NVIC vector
147+
if counter is set - the interrupts are disabled */
148+
if ((disable_counter == 0) && (ipm_handle != ((void *)0)))
149+
{
150+
ipm_set_enabled(ipm_handle, 0);
151+
}
152+
153+
disable_counter++;
154+
platform_global_isr_enable();
155+
return 0;
156+
}
157+
158+
/**
159+
* platform_map_mem_region
160+
*
161+
* Dummy implementation
162+
*
163+
*/
164+
void platform_map_mem_region(uint32_t vrt_addr, uint32_t phy_addr, uint32_t size, uint32_t flags)
165+
{
166+
}
167+
168+
/**
169+
* platform_cache_all_flush_invalidate
170+
*
171+
* Dummy implementation
172+
*
173+
*/
174+
void platform_cache_all_flush_invalidate(void)
175+
{
176+
}
177+
178+
/**
179+
* platform_cache_disable
180+
*
181+
* Dummy implementation
182+
*
183+
*/
184+
void platform_cache_disable(void)
185+
{
186+
}
187+
188+
/**
189+
* platform_cache_flush
190+
*
191+
* Empty implementation
192+
*
193+
*/
194+
void platform_cache_flush(void *data, uint32_t len)
195+
{
196+
}
197+
198+
/**
199+
* platform_cache_invalidate
200+
*
201+
* Empty implementation
202+
*
203+
*/
204+
void platform_cache_invalidate(void *data, uint32_t len)
205+
{
206+
}
207+
208+
/**
209+
* platform_vatopa
210+
*
211+
* Dummy implementation
212+
*
213+
*/
214+
uintptr_t platform_vatopa(void *addr)
215+
{
216+
return ((uintptr_t)(char *)addr);
217+
}
218+
219+
/**
220+
* platform_patova
221+
*
222+
* Dummy implementation
223+
*
224+
*/
225+
void *platform_patova(uintptr_t addr)
226+
{
227+
return ((void *)(char *)addr);
228+
}
229+
230+
/**
231+
* platform_init
232+
*
233+
* platform/environment init
234+
*/
235+
int32_t platform_init(void)
236+
{
237+
/* Get IPM device handle */
238+
if (!ipm_handle)
239+
{
240+
return -1;
241+
}
242+
243+
/* Register application callback with no context */
244+
ipm_register_callback(ipm_handle, platform_ipm_callback, ((void *)0));
245+
246+
/* Create lock used in multi-instanced RPMsg */
247+
#if defined(RL_USE_STATIC_API) && (RL_USE_STATIC_API == 1)
248+
if (0 != env_create_mutex(&platform_lock, 1, &platform_lock_static_ctxt))
249+
#else
250+
if (0 != env_create_mutex(&platform_lock, 1))
251+
#endif
252+
{
253+
return -1;
254+
}
255+
256+
return 0;
257+
}
258+
259+
/**
260+
* platform_deinit
261+
*
262+
* platform/environment deinit process
263+
*/
264+
int32_t platform_deinit(void)
265+
{
266+
/* Delete lock used in multi-instanced RPMsg */
267+
env_delete_mutex(platform_lock);
268+
platform_lock = ((void *)0);
269+
return 0;
270+
}

0 commit comments

Comments
 (0)