.. _BUILD:mcode: mcode backend ############# The mcode backend is available for all supported platforms and is also the simplest procedure, because it requires the fewest dependencies and configuration options. .. _BUILD:mcode:GNAT: GCC/GNAT: GNU/Linux or Windows (MinGW/MSYS2) ============================================ .. rubric:: Requirements * GCC (Gnu Compiler Collection) * GNAT (Ada compiler for GCC) GHDL is configured by ``configure`` and built by ``make``. * First, GHDL needs to be configured. It is common to specify a ``PREFIX`` (installation directory like ``/usr/local`` or ``/opt/ghdl``). Without any other option, ``configure`` selects `mcode` as the backend. * Next, ``make`` starts the compilation process. * Finally, ``make install`` installs GHDL into the installation directory specified by ``PREFIX``. .. HINT :: ON GNU/Linux, you may need super user privileges (``sudo ...``). .. rubric:: Example: .. code-block:: Bash $ cd $ mkdir build $ cd build $ ../configure --prefix=PREFIX $ make $ make install .. _BUILD:mcode:GNATGPL-Windows: GNAT GPL: Windows ================= .. rubric:: Requirements * GNAT GPL from http://libre.adacore.com * PowerShell 4 * PowerShell Community Extensions (PSCX) .. rubric:: `compile.ps1` .. code-block:: Commands Description -------------------------------------------------------------------- -Help Display the integrated help pages -Clean Clean up all files and directories -Compile Compile GHDL -Install Install all files into a directory (xcopy deployment) -Uninstall Uninstall all files from a directory -Update Update files in the installation directory -CreatePackage create an installer package Install options: -InstallPath Installation directory CreatePackage options: -Zip Create a zip-file for xcopy deployment buffered_object.c?id=e46cc2db8c4668b05ed873f57a54785ed56e2415'>diffstats
path: root/quantum/serial_link/protocol/triple_buffered_object.c
blob: e0c6d702a54c66125560adc608a0d447efd32378 (plain)
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
/*
The MIT License (MIT)

Copyright (c) 2016 Fred Sundvik

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#include "serial_link/protocol/triple_buffered_object.h"
#include "serial_link/system/serial_link.h"
#include <stdbool.h>
#include <stddef.h>

#define GET_READ_INDEX() object->state & 3
#define GET_WRITE_INDEX() (object->state >> 2) & 3
#define GET_SHARED_INDEX() (object->state >> 4) & 3
#define GET_DATA_AVAILABLE() (object->state >> 6) & 1

#define SET_READ_INDEX(i) object->state = ((object->state & ~3) | i)
#define SET_WRITE_INDEX(i) object->state = ((object->state & ~(3 << 2)) | (i << 2))
#define SET_SHARED_INDEX(i) object->state = ((object->state & ~(3 << 4)) | (i << 4))
#define SET_DATA_AVAILABLE(i) object->state = ((object->state & ~(1 << 6)) | (i << 6))

void triple_buffer_init(triple_buffer_object_t* object) {
    object->state = 0;
    SET_WRITE_INDEX(0);
    SET_READ_INDEX(1);
    SET_SHARED_INDEX(2);
    SET_DATA_AVAILABLE(0);
}

void* triple_buffer_read_internal(uint16_t object_size, triple_buffer_object_t* object) {
    serial_link_lock();
    if (GET_DATA_AVAILABLE()) {
        uint8_t shared_index = GET_SHARED_INDEX();
        uint8_t read_index   = GET_READ_INDEX();
        SET_READ_INDEX(shared_index);
        SET_SHARED_INDEX(read_index);
        SET_DATA_AVAILABLE(false);
        serial_link_unlock();
        return object->buffer + object_size * shared_index;
    } else {
        serial_link_unlock();
        return NULL;
    }
}

void* triple_buffer_begin_write_internal(uint16_t object_size, triple_buffer_object_t* object) {
    uint8_t write_index = GET_WRITE_INDEX();
    return object->buffer + object_size * write_index;
}

void triple_buffer_end_write_internal(triple_buffer_object_t* object) {
    serial_link_lock();
    uint8_t shared_index = GET_SHARED_INDEX();
    uint8_t write_index  = GET_WRITE_INDEX();
    SET_SHARED_INDEX(write_index);
    SET_WRITE_INDEX(shared_index);
    SET_DATA_AVAILABLE(true);
    serial_link_unlock();
}