summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-09-24 14:16:35 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-09-24 14:16:35 -0600
commitd282266beb71bfb9b21cf00f3025c01df7dd8e4d (patch)
tree16e5bd9f909148f68e960bbba36b55e94ea22e5e
parentd559c50a98e65ce889411b46ab108b392907e0f0 (diff)
rename cr_chan to cr_rpc
-rw-r--r--coroutine.h6
-rw-r--r--coroutine_rpc.h (renamed from coroutine_chan.h)43
-rw-r--r--main.c6
-rw-r--r--usb_keyboard.c8
-rw-r--r--usb_keyboard.h4
5 files changed, 33 insertions, 34 deletions
diff --git a/coroutine.h b/coroutine.h
index d34ff2e..4b16b1f 100644
--- a/coroutine.h
+++ b/coroutine.h
@@ -17,8 +17,8 @@
* as normal C functions and do not forbid switch() blocks in
* coroutines.
*
- * See also: coroutine_chan.h is a request/response system built on
- * top of coroutine.{h,c}.
+ * See also: coroutine_rpc.h is a request/response system built on top
+ * of coroutine.{h,c}.
*/
#ifndef _COROUTINE_H_
#define _COROUTINE_H_
@@ -66,7 +66,7 @@ typedef size_t cid_t;
* Specifically, coroutine_add() and
* cr_{yield,pause_and_yield,exit,end}() are explicitly forbidden to
* call from within a coroutine before cr_begin() (note that the
- * cr_chan_*() macros call these functions).
+ * cr_rpc_*() macros call these functions).
*/
typedef void (*cr_fn_t)(void *args);
#define COROUTINE __attribute__ ((noreturn)) void
diff --git a/coroutine_chan.h b/coroutine_rpc.h
index 3dfccc5..00aa165 100644
--- a/coroutine_chan.h
+++ b/coroutine_rpc.h
@@ -1,25 +1,24 @@
-/* coroutine_chan.h - Simple request/response system for coroutine.{h,c}
+/* coroutine_rpc.h - Simple request/response system for coroutine.{h,c}
*
* Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
* SPDX-Licence-Identifier: AGPL-3.0-or-later
*/
/**
- * The cr_chan_* macros form a simple request/response channel
- * mechanism built on top of the cr_pause_and_yeild() and cr_unpause()
- * primitives.
+ * The cr_rpc_* macros form a simple request/response mechanism built
+ * on top of the cr_pause_and_yeild() and cr_unpause() primitives.
*/
-#ifndef _COROUTINE_CHAN_H_
-#define _COROUTINE_CHAN_H_
+#ifndef _COROUTINE_RPC_H_
+#define _COROUTINE_RPC_H_
#include "coroutine.h"
/**
- * cr_chan_t(req_t, resp_t) returns the type definition for a channel
- * on which the requester submits a value of type `req_t` and the
- * responder responds with a value of type `resp_t`.
+ * cr_rpc_t(req_t, resp_t) returns the type definition for a
+ * rcp-channel on which the requester submits a value of type `req_t`
+ * and the responder responds with a value of type `resp_t`.
*/
-#define cr_chan_t(req_t, resp_t) struct { \
+#define cr_rpc_t(req_t, resp_t) struct { \
cid_t requester; \
cid_t responder; \
req_t req; \
@@ -31,13 +30,13 @@
* having these functions take `void*`. */
/**
- * ch_chan_req(cr_chan_t(req_t, resp_t) *ch, resp_t *resp, req_t req)
+ * ch_rpc_req(cr_rpc_t(req_t, resp_t) *ch, resp_t *resp, req_t req)
* submits the `req` request to `ch` puts the response in `*resp_p`.
*
- * Blocks until the responder has called both cr_chan_recv_req() and
- * cr_chan_send_resp().
+ * Blocks until the responder has called both cr_rpc_recv_req() and
+ * cr_rpc_send_resp().
*/
-#define cr_chan_req(ch, _resp_p, _req) do { \
+#define cr_rpc_req(ch, _resp_p, _req) do { \
(ch)->requester = cr_getcid(); \
(ch)->req = (_req); \
if ((ch)->responder != 0) \
@@ -48,21 +47,21 @@
} while (0)
/**
- * cr_chan_have_req(cr_chan_t(req_t, resp_t) *ch) allows a responder
+ * cr_rpc_have_req(cr_rpc_t(req_t, resp_t) *ch) allows a responder
* to check whether or not there is a request waiting to be received
- * (with cr_chan_recv_req()) without blocking if there is not.
+ * (with cr_rpc_recv_req()) without blocking if there is not.
*
* Never blocks.
*/
-#define cr_chan_have_req(ch) ((ch)->requester != 0)
+#define cr_rpc_have_req(ch) ((ch)->requester != 0)
/**
- * cr_chan_recv_req(cr_chan_t(req_t, resp_t) *ch, req_t *req_p) reads
+ * cr_rpc_recv_req(cr_rpc_t(req_t, resp_t) *ch, req_t *req_p) reads
* a request from ch into `*req_p`.
*
* If there is not a pending request on `ch`, blocks until there is.
*/
-#define cr_chan_recv_req(ch, _req_p) do { \
+#define cr_rpc_recv_req(ch, _req_p) do { \
(ch)->responder = cr_getcid(); \
if ((ch)->requester == 0) \
cr_pause_and_yield(); \
@@ -70,16 +69,16 @@
} while (0)
/**
- * cr_chan_send_resp(cr_chan_t(req_t, resp_t) *ch, resp_t resp) sends
+ * cr_rpc_send_resp(cr_rpc_t(req_t, resp_t) *ch, resp_t resp) sends
* the reply to the most-recently-read request.
*
* Never blocks.
*/
-#define cr_chan_send_resp(ch, _resp) do { \
+#define cr_rpc_send_resp(ch, _resp) do { \
cr_unpause((ch)->requester); \
(ch)->responder = 0; \
(ch)->requester = 0; \
(ch)->resp = (_resp); \
} while (0)
-#endif /* _COROUTINE_CHAN_H_ */
+#endif /* _COROUTINE_RPC_H_ */
diff --git a/main.c b/main.c
index 30a6dfc..1fd9f8c 100644
--- a/main.c
+++ b/main.c
@@ -17,11 +17,11 @@
COROUTINE hello_world_cr(void *_chan) {
const char *msg = "Hello world!\n";
- usb_keyboard_chan_t *chan = _chan;
+ usb_keyboard_rpc_t *chan = _chan;
cr_begin();
for (size_t i = 0;; i = (i+1) % strlen(msg)) {
- cr_chan_req(chan, NULL, msg[i]);
+ cr_rpc_req(chan, NULL, msg[i]);
}
cr_end();
@@ -39,7 +39,7 @@ int main() {
/* set up coroutines */
coroutine_add(usb_common_cr, NULL);
- usb_keyboard_chan_t keyboard_chan = {0};
+ usb_keyboard_rpc_t keyboard_chan = {0};
coroutine_add(usb_keyboard_cr, &keyboard_chan);
coroutine_add(hello_world_cr, &keyboard_chan);
diff --git a/usb_keyboard.c b/usb_keyboard.c
index e6638ec..1989b35 100644
--- a/usb_keyboard.c
+++ b/usb_keyboard.c
@@ -43,7 +43,7 @@ void usb_keyboard_init() {
static uint8_t ascii2keycode[128][2] = { HID_ASCII_TO_KEYCODE };
COROUTINE usb_keyboard_cr(void *_chan) {
- usb_keyboard_chan_t *chan = _chan;
+ usb_keyboard_rpc_t *chan = _chan;
cr_begin();
uint8_t report_id = 0;
@@ -53,9 +53,9 @@ COROUTINE usb_keyboard_cr(void *_chan) {
while (!tud_hid_n_ready(kbd_ifc))
cr_yield();
- if (cr_chan_have_req(chan)) {
+ if (cr_rpc_have_req(chan)) {
uint32_t rune;
- cr_chan_recv_req(chan, &rune);
+ cr_rpc_recv_req(chan, &rune);
modifier = ascii2keycode[rune][0] ? KEYBOARD_MODIFIER_LEFTSHIFT : 0;
keycodes[0] = ascii2keycode[rune][1];
@@ -68,7 +68,7 @@ COROUTINE usb_keyboard_cr(void *_chan) {
keycodes[0] = 0;
tud_hid_n_keyboard_report(kbd_ifc, report_id, modifier, keycodes);
- cr_chan_send_resp(chan, 1);
+ cr_rpc_send_resp(chan, 1);
} else {
modifier = 0;
keycodes[0] = 0;
diff --git a/usb_keyboard.h b/usb_keyboard.h
index 656add8..6b65360 100644
--- a/usb_keyboard.h
+++ b/usb_keyboard.h
@@ -7,9 +7,9 @@
#ifndef _USB_KEYBOARD_H_
#define _USB_KEYBOARD_H_
-#include "coroutine_chan.h"
+#include "coroutine_rpc.h"
-typedef cr_chan_t(uint32_t, int) usb_keyboard_chan_t;
+typedef cr_rpc_t(uint32_t, int) usb_keyboard_rpc_t;
void usb_keyboard_init(void);
COROUTINE usb_keyboard_cr(void *arg);