XCORE SDK
XCORE Software Development Kit
rtos_gpio.h
1 // Copyright 2020-2021 XMOS LIMITED.
2 // This Software is subject to the terms of the XMOS Public Licence: Version 1.
3 
4 #ifndef RTOS_GPIO_H_
5 #define RTOS_GPIO_H_
6 
14 #include <xcore/port.h>
15 
16 #include "rtos_osal.h"
17 #include "rtos_driver_rpc.h"
18 
24 typedef enum {
25  rtos_gpio_port_none = -1,
26  rtos_gpio_port_1A,
27  rtos_gpio_port_1B,
28  rtos_gpio_port_1C,
29  rtos_gpio_port_1D,
30  rtos_gpio_port_1E,
31  rtos_gpio_port_1F,
32  rtos_gpio_port_1G,
33  rtos_gpio_port_1H,
34  rtos_gpio_port_1I,
35  rtos_gpio_port_1J,
36  rtos_gpio_port_1K,
37  rtos_gpio_port_1L,
38  rtos_gpio_port_1M,
39  rtos_gpio_port_1N,
40  rtos_gpio_port_1O,
41  rtos_gpio_port_1P,
42  rtos_gpio_port_4A,
43  rtos_gpio_port_4B,
44  rtos_gpio_port_4C,
45  rtos_gpio_port_4D,
46  rtos_gpio_port_4E,
47  rtos_gpio_port_4F,
48  rtos_gpio_port_8A,
49  rtos_gpio_port_8B,
50  rtos_gpio_port_8C,
51  rtos_gpio_port_8D,
52  rtos_gpio_port_16A,
53  rtos_gpio_port_16B,
54  rtos_gpio_port_16C,
55  rtos_gpio_port_16D,
56  rtos_gpio_port_32A,
57  rtos_gpio_port_32B,
60 
65 #define RTOS_GPIO_ISR_CALLBACK_ATTR __attribute__((fptrgroup("rtos_gpio_isr_cb_fptr_grp")))
66 
70 typedef struct rtos_gpio_struct rtos_gpio_t;
71 
86 typedef void (*rtos_gpio_isr_cb_t)(rtos_gpio_t *ctx, void *app_data, rtos_gpio_port_id_t port_id, uint32_t value);
87 
93 typedef struct {
95  void *isr_app_data;
96  int enabled;
97  rtos_gpio_port_id_t port_id;
98  rtos_gpio_t *ctx;
100 
107  rtos_driver_rpc_t *rpc_config;
108  chanend_t rpc_interrupt_c[RTOS_DRIVER_RPC_MAX_CLIENT_TILES];
109 
110  __attribute__((fptrgroup("rtos_gpio_port_enable_fptr_grp")))
111  void (*port_enable)(rtos_gpio_t *, rtos_gpio_port_id_t);
112 
113  __attribute__((fptrgroup("rtos_gpio_port_in_fptr_grp")))
114  uint32_t (*port_in)(rtos_gpio_t *, rtos_gpio_port_id_t);
115 
116  __attribute__((fptrgroup("rtos_gpio_port_out_fptr_grp")))
117  void (*port_out)(rtos_gpio_t *, rtos_gpio_port_id_t, uint32_t);
118 
119  __attribute__((fptrgroup("rtos_gpio_port_write_control_word_fptr_grp")))
120  void (*port_write_control_word)(rtos_gpio_t *, rtos_gpio_port_id_t, uint32_t);
121 
122  __attribute__((fptrgroup("rtos_gpio_isr_callback_set_fptr_grp")))
123  void (*isr_callback_set)(rtos_gpio_t *, rtos_gpio_port_id_t, rtos_gpio_isr_cb_t, void *);
124 
125  __attribute__((fptrgroup("rtos_gpio_interrupt_enable_fptr_grp")))
126  void (*interrupt_enable)(rtos_gpio_t *, rtos_gpio_port_id_t);
127 
128  __attribute__((fptrgroup("rtos_gpio_interrupt_disable_fptr_grp")))
129  void (*interrupt_disable)(rtos_gpio_t *, rtos_gpio_port_id_t);
130 
132 
133  rtos_osal_mutex_t lock; /* Only used by RPC client */
134 };
135 
136 #include "rtos_gpio_rpc.h"
137 
147 {
148  switch (p) {
149  case XS1_PORT_1A:
150  return rtos_gpio_port_1A;
151  case XS1_PORT_1B:
152  return rtos_gpio_port_1B;
153  case XS1_PORT_1C:
154  return rtos_gpio_port_1C;
155  case XS1_PORT_1D:
156  return rtos_gpio_port_1D;
157  case XS1_PORT_1E:
158  return rtos_gpio_port_1E;
159  case XS1_PORT_1F:
160  return rtos_gpio_port_1F;
161  case XS1_PORT_1G:
162  return rtos_gpio_port_1G;
163  case XS1_PORT_1H:
164  return rtos_gpio_port_1H;
165  case XS1_PORT_1I:
166  return rtos_gpio_port_1I;
167  case XS1_PORT_1J:
168  return rtos_gpio_port_1J;
169  case XS1_PORT_1K:
170  return rtos_gpio_port_1K;
171  case XS1_PORT_1L:
172  return rtos_gpio_port_1L;
173  case XS1_PORT_1M:
174  return rtos_gpio_port_1M;
175  case XS1_PORT_1N:
176  return rtos_gpio_port_1N;
177  case XS1_PORT_1O:
178  return rtos_gpio_port_1O;
179  case XS1_PORT_1P:
180  return rtos_gpio_port_1P;
181  case XS1_PORT_4A:
182  return rtos_gpio_port_4A;
183  case XS1_PORT_4B:
184  return rtos_gpio_port_4B;
185  case XS1_PORT_4C:
186  return rtos_gpio_port_4C;
187  case XS1_PORT_4D:
188  return rtos_gpio_port_4D;
189  case XS1_PORT_4E:
190  return rtos_gpio_port_4E;
191  case XS1_PORT_4F:
192  return rtos_gpio_port_4F;
193  case XS1_PORT_8A:
194  return rtos_gpio_port_8A;
195  case XS1_PORT_8B:
196  return rtos_gpio_port_8B;
197  case XS1_PORT_8C:
198  return rtos_gpio_port_8C;
199  case XS1_PORT_8D:
200  return rtos_gpio_port_8D;
201  case XS1_PORT_16A:
202  return rtos_gpio_port_16A;
203  case XS1_PORT_16B:
204  return rtos_gpio_port_16B;
205  case XS1_PORT_16C:
206  return rtos_gpio_port_16C;
207  case XS1_PORT_16D:
208  return rtos_gpio_port_16D;
209  case XS1_PORT_32A:
210  return rtos_gpio_port_32A;
211  case XS1_PORT_32B:
212  return rtos_gpio_port_32B;
213  default:
214  return rtos_gpio_port_none;
215  }
216 }
217 
235  rtos_gpio_t *ctx,
236  rtos_gpio_port_id_t port_id)
237 {
238  ctx->port_enable(ctx, port_id);
239 }
240 
249 inline uint32_t rtos_gpio_port_in(
250  rtos_gpio_t *ctx,
251  rtos_gpio_port_id_t port_id)
252 {
253  return ctx->port_in(ctx, port_id);
254 }
255 
263 inline void rtos_gpio_port_out(
264  rtos_gpio_t *ctx,
265  rtos_gpio_port_id_t port_id,
266  uint32_t value)
267 {
268  ctx->port_out(ctx, port_id, value);
269 }
270 
287  rtos_gpio_t *ctx,
288  rtos_gpio_port_id_t port_id,
290  void *app_data)
291 {
292  ctx->isr_callback_set(ctx, port_id, cb, app_data);
293 }
294 
303  rtos_gpio_t *ctx,
304  rtos_gpio_port_id_t port_id)
305 {
306  ctx->interrupt_enable(ctx, port_id);
307 }
308 
316  rtos_gpio_t *ctx,
317  rtos_gpio_port_id_t port_id)
318 {
319  ctx->interrupt_disable(ctx, port_id);
320 }
321 
332  rtos_gpio_t *ctx,
333  rtos_gpio_port_id_t port_id)
334 {
335  return ctx->port_write_control_word(ctx, port_id, XS1_SETC_DRIVE_DRIVE);
336 }
337 
347  rtos_gpio_t *ctx,
348  rtos_gpio_port_id_t port_id)
349 {
350  return ctx->port_write_control_word(ctx, port_id, XS1_SETC_DRIVE_PULL_UP);
351 }
352 
362  rtos_gpio_t *ctx,
363  rtos_gpio_port_id_t port_id)
364 {
365  return ctx->port_write_control_word(ctx, port_id, XS1_SETC_DRIVE_PULL_DOWN);
366 }
367 
375  rtos_gpio_t *ctx,
376  rtos_gpio_port_id_t port_id)
377 {
378  return ctx->port_write_control_word(ctx, port_id, XS1_SETC_DRIVE_DRIVE);
379 }
380 
388  rtos_gpio_t *ctx,
389  rtos_gpio_port_id_t port_id)
390 {
391  return ctx->port_write_control_word(ctx, port_id, XS1_SETC_DRIVE_PULL_UP);
392 }
393 
401  rtos_gpio_t *ctx,
402  rtos_gpio_port_id_t port_id)
403 {
404  return ctx->port_write_control_word(ctx, port_id, XS1_SETC_DRIVE_PULL_DOWN);
405 }
406 
415  rtos_gpio_t *ctx,
416  rtos_gpio_port_id_t port_id,
417  uint32_t value)
418 {
419  return ctx->port_write_control_word(ctx, port_id, value);
420 }
421 
434 void rtos_gpio_start(
435  rtos_gpio_t *ctx);
436 
446 void rtos_gpio_init(
447  rtos_gpio_t *ctx);
448 
451 #endif /* RTOS_GPIO_H_ */
void rtos_gpio_port_pull_down(rtos_gpio_t *ctx, rtos_gpio_port_id_t port_id)
Definition: rtos_gpio.h:400
void rtos_gpio_write_control_word(rtos_gpio_t *ctx, rtos_gpio_port_id_t port_id, uint32_t value)
Definition: rtos_gpio.h:414
uint32_t rtos_gpio_port_in(rtos_gpio_t *ctx, rtos_gpio_port_id_t port_id)
Definition: rtos_gpio.h:249
void rtos_gpio_port_pull_none(rtos_gpio_t *ctx, rtos_gpio_port_id_t port_id)
Definition: rtos_gpio.h:374
void rtos_gpio_port_enable(rtos_gpio_t *ctx, rtos_gpio_port_id_t port_id)
Definition: rtos_gpio.h:234
void rtos_gpio_interrupt_enable(rtos_gpio_t *ctx, rtos_gpio_port_id_t port_id)
Definition: rtos_gpio.h:302
void rtos_gpio_port_out(rtos_gpio_t *ctx, rtos_gpio_port_id_t port_id, uint32_t value)
Definition: rtos_gpio.h:263
void rtos_gpio_port_drive_low(rtos_gpio_t *ctx, rtos_gpio_port_id_t port_id)
Definition: rtos_gpio.h:346
void rtos_gpio_interrupt_disable(rtos_gpio_t *ctx, rtos_gpio_port_id_t port_id)
Definition: rtos_gpio.h:315
void rtos_gpio_port_drive(rtos_gpio_t *ctx, rtos_gpio_port_id_t port_id)
Definition: rtos_gpio.h:331
void rtos_gpio_port_pull_up(rtos_gpio_t *ctx, rtos_gpio_port_id_t port_id)
Definition: rtos_gpio.h:387
void rtos_gpio_isr_callback_set(rtos_gpio_t *ctx, rtos_gpio_port_id_t port_id, rtos_gpio_isr_cb_t cb, void *app_data)
Definition: rtos_gpio.h:286
void rtos_gpio_port_drive_high(rtos_gpio_t *ctx, rtos_gpio_port_id_t port_id)
Definition: rtos_gpio.h:361
rtos_gpio_port_id_t
Definition: rtos_gpio.h:24
void rtos_gpio_init(rtos_gpio_t *ctx)
Definition: rtos_gpio.c:178
void rtos_gpio_start(rtos_gpio_t *ctx)
Definition: rtos_gpio.c:170
#define RTOS_GPIO_ISR_CALLBACK_ATTR
Definition: rtos_gpio.h:65
void(* rtos_gpio_isr_cb_t)(rtos_gpio_t *ctx, void *app_data, rtos_gpio_port_id_t port_id, uint32_t value)
Definition: rtos_gpio.h:86
rtos_gpio_port_id_t rtos_gpio_port(port_t p)
Definition: rtos_gpio.h:146
@ RTOS_GPIO_TOTAL_PORT_CNT
Definition: rtos_gpio.h:58
Definition: rtos_driver_rpc.h:23
Definition: rtos_gpio.h:93
Definition: rtos_gpio.h:106