pros-sys 0.8.1

EFI for the PROS rust bindings
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
use core::ffi::*;

use crate::*;

pub type queue_t = *mut c_void;
pub type sem_t = *mut c_void;
/**
List of possible v5 devices

This list contains all current V5 Devices, and mirrors V5_DeviceType from the
api.
 */
pub type v5_device_e_t = u32;
pub const E_DEVICE_NONE: v5_device_e_t = 0;
pub const E_DEVICE_MOTOR: v5_device_e_t = 2;
pub const E_DEVICE_ROTATION: v5_device_e_t = 4;
pub const E_DEVICE_IMU: v5_device_e_t = 6;
pub const E_DEVICE_DISTANCE: v5_device_e_t = 7;
pub const E_DEVICE_RADIO: v5_device_e_t = 8;
pub const E_DEVICE_VISION: v5_device_e_t = 11;
pub const E_DEVICE_ADI: v5_device_e_t = 12;
pub const E_DEVICE_OPTICAL: v5_device_e_t = 16;
pub const E_DEVICE_GPS: v5_device_e_t = 20;
pub const E_DEVICE_SERIAL: v5_device_e_t = 129;
#[deprecated(note = "use E_DEVICE_SERIAL instead")]
pub const E_DEVICE_GENERIC: v5_device_e_t = E_DEVICE_SERIAL;
pub const E_DEVICE_UNDEFINED: v5_device_e_t = 255;
/**
Action macro to pass into serctl or fdctl that activates the stream
identifier.

When used with serctl, the extra argument must be the little endian
representation of the stream identifier (e.g. "sout" -> 0x74756f73)

Visit <https://pros.cs.purdue.edu/v5/tutorials/topical/filesystem.html#serial>
to learn more.
 */
pub const SERCTL_ACTIVATE: u32 = 10;
/**
Action macro to pass into serctl or fdctl that deactivates the stream
identifier.

When used with serctl, the extra argument must be the little endian
representation of the stream identifier (e.g. "sout" -> 0x74756f73)

Visit <https://pros.cs.purdue.edu/v5/tutorials/topical/filesystem.html#serial>
to learn more.
 */
pub const SERCTL_DEACTIVATE: u32 = 11;
/**
Action macro to pass into fdctl that enables blocking writes for the file

The extra argument is not used with this action, provide any value (e.g.
NULL) instead

Visit <https://pros.cs.purdue.edu/v5/tutorials/topical/filesystem.html#serial>
to learn more.
 */
pub const SERCTL_BLKWRITE: u32 = 12;
/**
Action macro to pass into fdctl that makes writes non-blocking for the file

The extra argument is not used with this action, provide any value (e.g.
NULL) instead

Visit <https://pros.cs.purdue.edu/v5/tutorials/topical/filesystem.html#serial>
to learn more.
 */
pub const SERCTL_NOBLKWRITE: u32 = 13;
/**
Action macro to pass into serctl that enables advanced stream multiplexing
capabilities

The extra argument is not used with this action, provide any value (e.g.
NULL) instead

Visit <https://pros.cs.purdue.edu/v5/tutorials/topical/filesystem.html#serial>
to learn more.
 */
pub const SERCTL_ENABLE_COBS: u32 = 14;
/**
Action macro to pass into serctl that disables advanced stream multiplexing
capabilities

The extra argument is not used with this action, provide any value (e.g.
NULL) instead

Visit <https://pros.cs.purdue.edu/v5/tutorials/topical/filesystem.html#serial>
to learn more.
 */
pub const SERCTL_DISABLE_COBS: u32 = 15;
/**
Action macro to check if there is data available from the Generic Serial
Device

The extra argument is not used with this action, provide any value (e.g.
NULL) instead
 */
pub const DEVCTL_FIONREAD: u32 = 16;
/**
Action macro to check if there is space available in the Generic Serial
Device's output buffer

The extra argument is not used with this action, provide any value (e.g.
NULL) instead
 */
pub const DEVCTL_FIONWRITE: u32 = 18;
/**
Action macro to set the Generic Serial Device's baudrate.

The extra argument is the baudrate.
 */
pub const DECTRL_SET_BAUDRATE: u32 = 17;

extern "C" {
    /**
    Unblocks a task in the Blocked state (e.g. waiting for a delay, on a
    semaphore, etc.).

    See <https://pros.cs.purdue.edu/v5/extended/multitasking.html#abort_delay> for
    details.
     */
    pub fn task_abort_delay(task: task_t) -> bool;
    /**
    Notify a task when a target task is being deleted.

    This function will configure the PROS kernel to call
    task_notify_ext(task_to_notify, value, action, NULL) when target_task is
    deleted.


    \param target_task
                   The task being watched for deletion
    \param task_to_notify
           The task to notify when target_task is deleted
    \param value
                   The value to supply to task_notify_ext
    \param notify_action
                    The action to supply to task_notify_ext
    */
    pub fn task_notify_when_deleting(
        target_task: task_t,
        task_to_notify: task_t,
        value: u32,
        notify_action: notify_action_e_t,
    );
    /**
    Creates a recursive mutex which can be locked recursively by the owner.

    See
    <https://pros.cs.purdue.edu/v5/extended/multitasking.html#recursive_mutexes>
    for details.

    \return A newly created recursive mutex.
     */
    pub fn mutex_recursive_create() -> mutex_t;
    /**
    Takes a recursive mutex.

    See
    <https://pros.cs.purdue.edu/v5/extended/multitasking.html#recursive_mutexes>
    for details.

    \param mutex
           A mutex handle created by mutex_recursive_create
    \param wait_time
           Amount of time to wait before timing out

    \return 1 if the mutex was obtained, 0 otherwise
     */
    pub fn mutex_recursive_take(mutex: mutex_t, timeout: u32) -> bool;
    /**
    Gives a recursive mutex.

    See
    <https://pros.cs.purdue.edu/v5/extended/multitasking.html#recursive_mutexes>
    for details.

    \param mutex
           A mutex handle created by mutex_recursive_create

    \return 1 if the mutex was obtained, 0 otherwise
     */
    pub fn mutex_recursive_give(mutex: mutex_t) -> bool;
    /**
    Returns a handle to the current owner of a mutex.

    See <https://pros.cs.purdue.edu/v5/extended/multitasking.html#extra> for
    details.

    \param mutex
           A mutex handle

    \return A handle to the current task that owns the mutex, or NULL if the
    mutex isn't owned.
     */
    pub fn mutex_get_owner(mutex: mutex_t) -> task_t;
    /**
    Creates a counting sempahore.

    See <https://pros.cs.purdue.edu/v5/tutorials/multitasking.html#semaphores> for
    details.

    \param max_count
           The maximum count value that can be reached.
    \param init_count
           The initial count value assigned to the new semaphore.

    \return A newly created semaphore. If an error occurred, NULL will be
    returned and errno can be checked for hints as to why sem_create failed.
    */
    pub fn sem_create(max_count: u32, init_count: u32) -> sem_t;
    /**
    Deletes a semaphore (or binary semaphore)

    See <https://pros.cs.purdue.edu/v5/extended/multitasking.html#semaphores> for
    details.

    \param sem
                  Semaphore to delete
    */
    pub fn sem_delete(sem: sem_t);
    /**
    Creates a binary semaphore.

    See
    <https://pros.cs.purdue.edu/v5/extended/multitasking#.htmlbinary_semaphores>
    for details.

    \return A newly created semaphore.
     */
    pub fn sem_binary_create() -> sem_t;
    /**
    Waits for the semaphore's value to be greater than 0. If the value is already
    greater than 0, this function immediately returns.

    See <https://pros.cs.purdue.edu/v5/tutorials/multitasking.html#semaphores> for
    details.

    \param sem
           Semaphore to wait on
    \param timeout
           Time to wait before the semaphore's becomes available. A timeout of 0
           can be used to poll the sempahore. TIMEOUT_MAX can be used to block
           indefinitely.

    \return True if the semaphore was successfully take, false otherwise. If
    false is returned, then errno is set with a hint about why the sempahore
    couldn't be taken.
     */
    pub fn sem_wait(sem: sem_t, timeout: u32) -> bool;
    /**
    Increments a semaphore's value.

    See <https://pros.cs.purdue.edu/v5/tutorials/multitasking.html#semaphores> for
    details.

    \param sem
           Semaphore to post

    \return True if the value was incremented, false otherwise. If false is
    returned, then errno is set with a hint about why the semaphore couldn't be
    taken.
     */
    pub fn sem_post(sem: sem_t) -> bool;
    /**
    Returns the current value of the semaphore.

    See <https://pros.cs.purdue.edu/v5/extended/multitasking.html#extra> for
    details.

    \param sem
           A semaphore handle

    \return The current value of the semaphore (e.g. the number of resources
    available)
     */
    pub fn sem_get_count(sem: sem_t) -> u32;
    /**
    Creates a queue.

    See <https://pros.cs.purdue.edu/v5/extended/multitasking.html#queues> for
    details.

    \param length
           The maximum number of items that the queue can contain.
    \param item_size
           The number of bytes each item in the queue will require.

    \return A handle to a newly created queue, or NULL if the queue cannot be
    created.
     */
    pub fn queue_create(length: u32, item_size: u32) -> queue_t;
    /**
    Posts an item to the front of a queue. The item is queued by copy, not by
    reference.

    See <https://pros.cs.purdue.edu/v5/extended/multitasking.html#queues> for
    details.

    \param queue
           The queue handle
    \param item
           A pointer to the item that will be placed on the queue.
    \param timeout
           Time to wait for space to become available. A timeout of 0 can be used
           to attempt to post without blocking. TIMEOUT_MAX can be used to block
           indefinitely.

    \return True if the item was preprended, false otherwise.
     */
    pub fn queue_prepend(queue: queue_t, item: *const c_void, timeout: u32) -> bool;
    /**
    Posts an item to the end of a queue. The item is queued by copy, not by
    reference.

    See <https://pros.cs.purdue.edu/v5/extended/multitasking.html#queues> for
    details.

    \param queue
           The queue handle
    \param item
           A pointer to the item that will be placed on the queue.
    \param timeout
           Time to wait for space to become available. A timeout of 0 can be used
           to attempt to post without blocking. TIMEOUT_MAX can be used to block
           indefinitely.

    \return True if the item was preprended, false otherwise.
     */
    pub fn queue_append(queue: queue_t, item: *const c_void, timeout: u32) -> bool;
    /**
    Receive an item from a queue without removing the item from the queue.

    See <https://pros.cs.purdue.edu/v5/extended/multitasking.html#queues> for
    details.

    \param queue
           The queue handle
    \param buffer
           Pointer to a buffer to which the received item will be copied
    \param timeout
           The maximum amount of time the task should block waiting for an item to receive should the queue be empty at
           the time of the call. TIMEOUT_MAX can be used to block indefinitely.

    \return True if an item was copied into the buffer, false otherwise.
     */
    pub fn queue_peek(queue: queue_t, buffer: *mut c_void, timeout: u32) -> bool;
    /**
    Receive an item from the queue.

    See <https://pros.cs.purdue.edu/v5/extended/multitasking.html#queues> for
    details.

    \param queue
           The queue handle
    \param buffer
           Pointer to a buffer to which the received item will be copied
    \param timeout
           The maximum amount of time the task should block
           waiting for an item to receive should the queue be empty at the time
           of the call. queue_recv() will return immediately if timeout
           is zero and the queue is empty.

    \return True if an item was copied into the buffer, false otherwise.
     */
    pub fn queue_recv(queue: queue_t, buffer: *mut c_void, timeout: u32) -> bool;
    /**
    Return the number of messages stored in a queue.

    See <https://pros.cs.purdue.edu/v5/extended/multitasking.html#queues> for
    details.

    \param queue
           The queue handle.

    \return The number of messages available in the queue.
     */
    pub fn queue_get_waiting(queue: queue_t) -> u32;
    /**
    Return the number of spaces left in a queue.

    See <https://pros.cs.purdue.edu/v5/extended/multitasking.html#queues> for
    details.

    \param queue
           The queue handle.

    \return The number of spaces available in the queue.
     */
    pub fn queue_get_available(queue: queue_t) -> u32;
    /**
    Delete a queue.

    See <https://pros.cs.purdue.edu/v5/extended/multitasking.html#queues> for
    details.

    \param queue
           Queue handle to delete
    */
    pub fn queue_delete(queue: queue_t);
    /**
    Resets a queue to an empty state

    \param queue
           Queue handle to reset
     */
    pub fn queue_reset(queue: queue_t);
    /**
    Registers a device in the given zero-indexed port

    Registers a device of the given type in the given port into the registry, if
    that type of device is detected to be plugged in to that port.

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (0-20), or a
    a different device than specified is plugged in.
    EADDRINUSE - The port is already registered to another device.

    \param port
           The port number to register the device
    \param device
           The type of device to register

    \return 1 upon success, PROS_ERR upon failure
     */
    pub fn registry_bind_port(port: u8, device_type: v5_device_e_t) -> c_int;
    /**
    Deregisters a devices from the given zero-indexed port

    Removes the device registed in the given port, if there is one.

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (0-20).

    \param port
           The port number to deregister

    \return 1 upon success, PROS_ERR upon failure
     */
    pub fn registry_unbind_port(port: u8) -> c_int;
    /*
    Returns the type of device registered to the zero-indexed port.

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (0-20).

    \param port
           The V5 port number from 0-20

    \return The type of device that is registered into the port (NOT what is
    plugged in)
     */
    pub fn registry_get_bound_type(port: u8) -> v5_device_e_t;
    /**
    Returns the type of the device plugged into the zero-indexed port.

    This function uses the following values of errno when an error state is
    reached:
    ENXIO - The given value is not within the range of V5 ports (0-20).

    \param port
           The V5 port number from 0-20

    \return The type of device that is plugged into the port (NOT what is
    registered)
     */
    pub fn registry_get_plugged_type(port: u8) -> v5_device_e_t;
    /**
    Control settings of the serial driver.

    \param action
                An action to perform on the serial driver. See the SERCTL_* macros for
                details on the different actions.
    \param extra_arg
                An argument to pass in based on the action
     */
    pub fn serctl(action: u32, extra_arg: *mut c_void) -> i32;
    /*
    Control settings of the microSD card driver.

    \param action
                An action to perform on the microSD card driver. See the USDCTL_* macros
         for details on the different actions.
    \param extra_arg
                   An argument to pass in based on the action
     */
    // Not yet implemented
    // pub fn usdctl(file: c_int, action: u32, extra_arg: *mut c_void) -> i32;
    /**
    Control settings of the way the file's driver treats the file

    \param file
                A valid file descriptor number
    \param action
                An action to perform on the file's driver. See the *CTL_* macros for
                details on the different actions. Note that the action passed in must
         match the correct driver (e.g. don't perform a SERCTL_* action on a
         microSD card file)
    \param extra_arg
                  An argument to pass in based on the action
     */
    pub fn fdctl(file: c_int, action: u32, extra_arg: *mut c_void) -> i32;

}