runtime/xenomai.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Sun, 06 Jan 2019 01:22:46 +0300
changeset 2499 68f4f2d4516b
parent 2015 4eeefc6a13fd
child 3750 f62625418bff
permissions -rw-r--r--
use pregenerated CRC32 lookup tables for retain on Win32 and GNU/Linux

This code could be possible reused on low-end targets with limited RAM.

code to generate lookup table:
[---------------------------------------------------------------------]

/* CRC lookup table and initial state. */
uint32_t crc32_table[256];

/* Generate CRC32 lookup table. */
void GenerateCRC32Table(void)
{
unsigned int i, j;
/* Use CRC-32-IEEE 802.3 polynomial 0x04C11DB7 (bit reflected). */
uint32_t poly = 0xEDB88320;

for (i = 0; i <= 0xFF; i++)
{
uint32_t c = i;
for (j = 0 ; j < 8 ; j++)
c = (c & 1) ? (c >> 1 ) ^ poly : (c >> 1);
crc32_table[i] = c;
}
}

void main(void)
{
GenerateCRC32Table();
int j=0;
for(int i=0; i<256; i++) {
printf("0x%08X, ", crc32_table[i]);
if (++j >= 8) {
j = 0;
printf("\n");
}
}
}
[---------------------------------------------------------------------]
2015
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
     1
#!/usr/bin/env python
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
     2
# -*- coding: utf-8 -*-
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
     3
#
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
     4
# See COPYING.Runtime file for copyrights details.
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
     5
#
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
     6
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
     7
from __future__ import absolute_import
2000
9fa2f8ede5d6 Fixed random segfault happening when loading new PLC in runtime, when using Xenonai.
Edouard Tisserant
parents:
diff changeset
     8
from ctypes import CDLL, RTLD_GLOBAL, pointer, c_int, POINTER, c_char, create_string_buffer
2015
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
     9
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
    10
2000
9fa2f8ede5d6 Fixed random segfault happening when loading new PLC in runtime, when using Xenonai.
Edouard Tisserant
parents:
diff changeset
    11
def TryPreloadXenomai():
9fa2f8ede5d6 Fixed random segfault happening when loading new PLC in runtime, when using Xenonai.
Edouard Tisserant
parents:
diff changeset
    12
    """
9fa2f8ede5d6 Fixed random segfault happening when loading new PLC in runtime, when using Xenonai.
Edouard Tisserant
parents:
diff changeset
    13
    Xenomai 3 (at least for version <= 3.0.6) do not handle properly dlclose
9fa2f8ede5d6 Fixed random segfault happening when loading new PLC in runtime, when using Xenonai.
Edouard Tisserant
parents:
diff changeset
    14
    of shared objects whose dlopen did trigger xenomai_init.
2015
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
    15
    As a workaround, this pre-loads xenomai libraries that need to be
2000
9fa2f8ede5d6 Fixed random segfault happening when loading new PLC in runtime, when using Xenonai.
Edouard Tisserant
parents:
diff changeset
    16
    initialized and call xenomai_init once for all.
2015
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
    17
2000
9fa2f8ede5d6 Fixed random segfault happening when loading new PLC in runtime, when using Xenonai.
Edouard Tisserant
parents:
diff changeset
    18
    Xenomai auto init of libs MUST be disabled (see --auto-init-solib in xeno-config)
9fa2f8ede5d6 Fixed random segfault happening when loading new PLC in runtime, when using Xenonai.
Edouard Tisserant
parents:
diff changeset
    19
    """
9fa2f8ede5d6 Fixed random segfault happening when loading new PLC in runtime, when using Xenonai.
Edouard Tisserant
parents:
diff changeset
    20
    try:
9fa2f8ede5d6 Fixed random segfault happening when loading new PLC in runtime, when using Xenonai.
Edouard Tisserant
parents:
diff changeset
    21
        for name in ["cobalt", "modechk", "copperplate", "alchemy"]:
9fa2f8ede5d6 Fixed random segfault happening when loading new PLC in runtime, when using Xenonai.
Edouard Tisserant
parents:
diff changeset
    22
            globals()[name] = CDLL("lib"+name+".so", mode=RTLD_GLOBAL)
2015
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
    23
        cobalt.xenomai_init(pointer(c_int(0)), pointer((POINTER(c_char)*2)(create_string_buffer("prog_name"), None)))
4eeefc6a13fd Fix codestyle
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2000
diff changeset
    24
    except Exception:
2000
9fa2f8ede5d6 Fixed random segfault happening when loading new PLC in runtime, when using Xenonai.
Edouard Tisserant
parents:
diff changeset
    25
        pass