Skip to content

Commit f56d725

Browse files
committed
Add openamp library + wrapper
1 parent b048e4b commit f56d725

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+151
-85
lines changed

cores/arduino/RPC.cpp

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#include "RPC.h"
2+
3+
int RPC::rpmsg_recv_service_callback(struct rpmsg_endpoint *ept, void *data,
4+
size_t len, uint32_t src, void *priv)
5+
{
6+
RPC* rpc = (RPC*)priv;
7+
service_request* s = ((service_request *) data);
8+
if (s->code == REQUEST_REBOOT) {
9+
NVIC_SystemReset();
10+
}
11+
return 0;
12+
}
13+
14+
int RPC::rpmsg_recv_raw_callback(struct rpmsg_endpoint *ept, void *data,
15+
size_t len, uint32_t src, void *priv)
16+
{
17+
RPC* rpc = (RPC*)priv;
18+
uint8_t* buf = (uint8_t*)data;
19+
for (int i=0; i<len; i++) {
20+
rpc->rx_buffer.store_char(buf[i]);
21+
}
22+
return 0;
23+
}
24+
25+
int RPC::begin() {
26+
27+
/*HW semaphore Clock enable*/
28+
__HAL_RCC_HSEM_CLK_ENABLE();
29+
/*HW semaphore Notification enable*/
30+
HAL_HSEM_ActivateNotification(__HAL_HSEM_SEMID_TO_MASK(HSEM_ID_0));
31+
32+
/* Inilitize the mailbox use notify the other core on new message */
33+
MAILBOX_Init();
34+
35+
/* Inilitize OpenAmp and libmetal libraries */
36+
if (MX_OPENAMP_Init(RPMSG_REMOTE, NULL) != 0) {
37+
return 0;
38+
}
39+
40+
rp_endpoints[0].priv = this;
41+
rp_endpoints[1].priv = this;
42+
43+
/* create a endpoint for rmpsg communication */
44+
int status = OPENAMP_create_endpoint(&rp_endpoints[0], "service", RPMSG_ADDR_ANY,
45+
rpmsg_recv_service_callback, NULL);
46+
if (status < 0)
47+
{
48+
return 0;
49+
}
50+
51+
/* create a endpoint for raw rmpsg communication */
52+
status = OPENAMP_create_endpoint(&rp_endpoints[1], "raw", RPMSG_ADDR_ANY,
53+
rpmsg_recv_raw_callback, NULL);
54+
if (status < 0)
55+
{
56+
return 0;
57+
}
58+
59+
eventThread = new rtos::Thread(osPriorityNormal);
60+
eventThread->start(callback(&eventQueue, &events::EventQueue::dispatch_forever));
61+
ticker.attach(eventQueue.event(&OPENAMP_check_for_message), 0.02f);
62+
63+
initialized = true;
64+
return 1;
65+
}
66+
67+
size_t RPC::write(const uint8_t* buf, size_t len) {
68+
OPENAMP_send(&rp_endpoints[1], buf, len);
69+
return len;
70+
}
71+
72+
size_t RPC::write(uint8_t c) {
73+
OPENAMP_send(&rp_endpoints[1], &c, 1);
74+
return 1;
75+
}
76+
77+
int RPC::request(service_request* s) {
78+
return OPENAMP_send(&rp_endpoints[0], s, sizeof(*s) + s->length);
79+
}
80+
81+
arduino::RPC RPC1;

cores/arduino/RPC.h

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#ifdef __cplusplus
2+
3+
#ifndef __ARDUINO_RPC_IMPLEMENTATION__
4+
#define __ARDUINO_RPC_IMPLEMENTATION__
5+
6+
#include "Arduino.h"
7+
8+
extern "C" {
9+
#define boolean boolean_t
10+
#include "openamp.h"
11+
#undef boolean
12+
#define boolean bool
13+
}
14+
15+
enum service_request_code_t {
16+
REQUEST_REBOOT = 0x7F7F7F7F,
17+
CALL_FUNCTION = 0x12345678,
18+
};
19+
20+
typedef struct _service_request {
21+
enum service_request_code_t code;
22+
size_t length;
23+
size_t parameters;
24+
uint8_t* data;
25+
} service_request;
26+
27+
namespace arduino {
28+
29+
class RPC : public Stream {
30+
public:
31+
RPC() {};
32+
int begin();
33+
void end() {};
34+
int available(void) {
35+
return rx_buffer.available();
36+
};
37+
int peek(void) {
38+
return rx_buffer.peek();
39+
}
40+
int read(void) {
41+
return rx_buffer.read_char();
42+
}
43+
void flush(void) {};
44+
size_t write(uint8_t c);
45+
size_t write(const uint8_t*, size_t);
46+
int request(service_request* s);
47+
using Print::write; // pull in write(str) and write(buf, size) from Print
48+
operator bool() {
49+
return initialized;
50+
}
51+
52+
private:
53+
RingBufferN<256> rx_buffer;
54+
bool initialized = false;
55+
struct rpmsg_endpoint rp_endpoints[4];
56+
static int rpmsg_recv_service_callback(struct rpmsg_endpoint *ept, void *data,
57+
size_t len, uint32_t src, void *priv);
58+
static int rpmsg_recv_raw_callback(struct rpmsg_endpoint *ept, void *data,
59+
size_t len, uint32_t src, void *priv);
60+
events::EventQueue eventQueue;
61+
mbed::Ticker ticker;
62+
rtos::Thread* eventThread;
63+
};
64+
}
65+
66+
extern arduino::RPC RPC1;
67+
68+
#endif
69+
#endif
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

libraries/OpenAMP/examples/BlinkOpenAMP/BlinkOpenAMP.ino

-85
This file was deleted.

variants/ENVIE_M4/includes.txt

+1
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,4 @@
259259
-iwithprefixbefore/mbed/cmsis/TARGET_CORTEX_M
260260
-iwithprefixbefore/mbed/cmsis
261261
-iwithprefixbefore/mbed
262+
-iwithprefixbefore/openamp

0 commit comments

Comments
 (0)