ZestCode
 
Loading...
Searching...
No Matches
vdml.h
Go to the documentation of this file.
1
13
14#pragma once
15
16#include <stdbool.h>
17#include <stdint.h>
18#include "vdml/registry.h"
19
20#ifdef __cplusplus
21#define v5_device_e_t pros::c::v5_device_e_t
22#endif
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
32#define VALIDATE_PORT_NO(PORT) ((PORT) >= 0 && (PORT) < NUM_V5_PORTS)
33
34#define VALIDATE_PORT_NO_INTERNAL(PORT) ((PORT) >= 0 && (PORT) < V5_MAX_DEVICE_PORTS)
35
51#define claim_port(port, device_type, error_code) \
52 if (registry_validate_binding(port, device_type) != 0) { \
53 return error_code; \
54 } \
55 v5_smart_device_s_t* device = registry_get_device(port); \
56 if (!port_mutex_take(port)) { \
57 errno = EACCES; \
58 return error_code; \
59 }
60
70#define claim_port_i(port, device_type) claim_port(port, device_type, PROS_ERR)
71
81#define claim_port_f(port, device_type) claim_port(port, device_type, PROS_ERR_F)
82
100int32_t claim_port_try(uint8_t port, v5_device_e_t type);
101
113#define return_port(port, rtn) \
114 port_mutex_give(port); \
115 return rtn;
116
120extern int32_t port_errors;
121
129void vdml_set_port_error(uint8_t port);
130
137void vdml_unset_port_error(uint8_t port);
138
148bool vdml_get_port_error(uint8_t port);
149
171int port_mutex_take(uint8_t port);
172
189int port_mutex_give(uint8_t port);
190
195
200
217int internal_port_mutex_take(uint8_t port);
218
235int internal_port_mutex_give(uint8_t port);
236
237#define V5_PORT_BATTERY 24
238#define V5_PORT_CONTROLLER_1 25
239#define V5_PORT_CONTROLLER_2 26
240
241#ifdef __cplusplus
242}
243#undef v5_device_e_t
244#endif
void port_mutex_take_all()
int32_t claim_port_try(uint8_t port, v5_device_e_t type)
void vdml_unset_port_error(uint8_t port)
int internal_port_mutex_give(uint8_t port)
int port_mutex_take(uint8_t port)
int32_t port_errors
bool vdml_get_port_error(uint8_t port)
void vdml_set_port_error(uint8_t port)
int port_mutex_give(uint8_t port)
void port_mutex_give_all()
int internal_port_mutex_take(uint8_t port)