Skip to content

Instantly share code, notes, and snippets.

@royratcliffe
Last active May 12, 2025 19:59
Show Gist options
  • Save royratcliffe/dd3f529364aad72abb1e374a4ccca401 to your computer and use it in GitHub Desktop.
Save royratcliffe/dd3f529364aad72abb1e374a4ccca401 to your computer and use it in GitHub Desktop.
Infineon AURIX
# /etc/systemd/network/80-can.network
# sudo systemctl enable systemd-networkd
# https://www.freedesktop.org/software/systemd/man/latest/systemd.network.html
[Match]
Name=can*
[CAN]
# ip -d link show can0
BitRate=500K
# /etc/udev/rules.d/80-can.rules
ACTION=="add", SUBSYSTEM=="net", KERNEL=="can0", ATTR{tx_queue_len}="65536"
ACTION=="add", SUBSYSTEM=="net", KERNEL=="can1", ATTR{tx_queue_len}="65536"
<?xml version="1.0" encoding="UTF-8" standalone="no"?><templates><template autoinsert="false" context="org.eclipse.cdt.core.cHeader.contenttype_context" deleted="false" description="" enabled="true" id="com.infineon.aurix.tools.templates.c.header.1" name="ATV MC (RR) C Header Template">/* SPDX-License-Identifier: MIT */
/**********************************************************************************************************************
* \file ${file_name}
* \copyright 2025, Roy Ratcliffe, Northumberland, United Kingdom
*
* 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, sub-license, 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.
*********************************************************************************************************************/&#13;
&#13;
#ifndef ${include_guard_symbol}&#13;
#define ${include_guard_symbol}&#13;
&#13;
/*********************************************************************************************************************/&#13;
/*-----------------------------------------------------Includes------------------------------------------------------*/&#13;
/*********************************************************************************************************************/&#13;
&#13;
/*********************************************************************************************************************/&#13;
/*------------------------------------------------------Macros-------------------------------------------------------*/&#13;
/*********************************************************************************************************************/&#13;
&#13;
/*********************************************************************************************************************/&#13;
/*-------------------------------------------------Global variables--------------------------------------------------*/&#13;
/*********************************************************************************************************************/&#13;
&#13;
/*********************************************************************************************************************/&#13;
/*-------------------------------------------------Data Structures---------------------------------------------------*/&#13;
/*********************************************************************************************************************/&#13;
&#13;
/*********************************************************************************************************************/&#13;
/*--------------------------------------------Private Variables/Constants--------------------------------------------*/&#13;
/*********************************************************************************************************************/&#13;
&#13;
/*********************************************************************************************************************/&#13;
/*------------------------------------------------Function Prototypes------------------------------------------------*/&#13;
/*********************************************************************************************************************/&#13;
&#13;
#endif /* ${include_guard_symbol} */</template><template autoinsert="false" context="org.eclipse.cdt.core.cSource.contenttype_context" deleted="false" description="" enabled="true" id="com.infineon.aurix.tools.templates.c.source.1" name="ATV MC C (RR) Source Template">/* SPDX-License-Identifier: MIT */
/**********************************************************************************************************************
* \file ${file_name}
* \copyright 2025, Roy Ratcliffe, Northumberland, United Kingdom
*
* 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, sub-license, 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.
*********************************************************************************************************************/
${includes}
${declarations}
/*********************************************************************************************************************/
/*-----------------------------------------------------Includes------------------------------------------------------*/
/*********************************************************************************************************************/
/*********************************************************************************************************************/
/*------------------------------------------------------Macros-------------------------------------------------------*/
/*********************************************************************************************************************/
/*********************************************************************************************************************/
/*-------------------------------------------------Global variables--------------------------------------------------*/
/*********************************************************************************************************************/
/*********************************************************************************************************************/
/*--------------------------------------------Private Variables/Constants--------------------------------------------*/
/*********************************************************************************************************************/
/*********************************************************************************************************************/
/*------------------------------------------------Function Prototypes------------------------------------------------*/
/*********************************************************************************************************************/
/*********************************************************************************************************************/
/*---------------------------------------------Function Implementations----------------------------------------------*/
/*********************************************************************************************************************/
</template></templates>
/**********************************************************************************************************************
* \file Cpu.c
* \copyright 2024, Roy Ratcliffe, Northumberland, United Kingdom
*
* SPDX-License-Identifier: MIT
*
* 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 "Cpu.h"
/*********************************************************************************************************************/
/*-----------------------------------------------------Includes------------------------------------------------------*/
/*********************************************************************************************************************/
#include <IfxCpu.h>
/*********************************************************************************************************************/
/*------------------------------------------------------Macros-------------------------------------------------------*/
/*********************************************************************************************************************/
/*********************************************************************************************************************/
/*-------------------------------------------------Global variables--------------------------------------------------*/
/*********************************************************************************************************************/
/*********************************************************************************************************************/
/*--------------------------------------------Private Variables/Constants--------------------------------------------*/
/*********************************************************************************************************************/
static IfxCpu_syncEvent syncEvent IFX_ALIGN(sizeof(IfxCpu_syncEvent));
/*********************************************************************************************************************/
/*------------------------------------------------Function Prototypes------------------------------------------------*/
/*********************************************************************************************************************/
/*********************************************************************************************************************/
/*---------------------------------------------Function Implementations----------------------------------------------*/
/*********************************************************************************************************************/
boolean Cpu_emitAndWaitForSyncEvent(uint32 timeoutMilliSec) {
IfxCpu_emitEvent(&syncEvent);
return IfxCpu_waitEvent(&syncEvent, timeoutMilliSec);
}
/**********************************************************************************************************************
* \file Cpu.h
* \copyright 2024, Roy Ratcliffe, Northumberland, United Kingdom
*
* SPDX-License-Identifier: MIT
*
* 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.
*********************************************************************************************************************/
#ifndef CPU_H_
#define CPU_H_
/*********************************************************************************************************************/
/*-----------------------------------------------------Includes------------------------------------------------------*/
/*********************************************************************************************************************/
#include <Ifx_Types.h>
/*********************************************************************************************************************/
/*------------------------------------------------------Macros-------------------------------------------------------*/
/*********************************************************************************************************************/
/*********************************************************************************************************************/
/*-------------------------------------------------Global variables--------------------------------------------------*/
/*********************************************************************************************************************/
/*********************************************************************************************************************/
/*-------------------------------------------------Data Structures---------------------------------------------------*/
/*********************************************************************************************************************/
/*********************************************************************************************************************/
/*--------------------------------------------Private Variables/Constants--------------------------------------------*/
/*********************************************************************************************************************/
/*********************************************************************************************************************/
/*------------------------------------------------Function Prototypes------------------------------------------------*/
/*********************************************************************************************************************/
IFX_EXTERN boolean Cpu_emitAndWaitForSyncEvent(uint32 timeoutMilliSec);
#endif /* CPU_H_ */
/**********************************************************************************************************************
* \file div.h
* \copyright 2025, Roy Ratcliffe, Northumberland, United Kingdom
*
* SPDX-License-Identifier: MIT
*
* 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, sub-license, 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.
*********************************************************************************************************************/
#ifndef DIV_H_
#define DIV_H_
/*********************************************************************************************************************/
/*-----------------------------------------------------Includes------------------------------------------------------*/
/*********************************************************************************************************************/
#include "Ifx_Types.h"
/*********************************************************************************************************************/
/*------------------------------------------------------Macros-------------------------------------------------------*/
/*********************************************************************************************************************/
IFX_INLINE sint64 Ifx__div(sint32 d1, sint32 d2)
{
register sint64 e0;
__asm("div %0,%1,%2" : "=e"(e0) : "d"(d1), "d"(d2));
return e0;
}
IFX_INLINE uint64 Ifx__divu(uint32 d1, uint32 d2)
{
register uint64 e0;
__asm("div.u %0,%1,%2" : "=e"(e0) : "d"(d1), "d"(d2));
return e0;
}
/*********************************************************************************************************************/
/*-------------------------------------------------Data Structures---------------------------------------------------*/
/*********************************************************************************************************************/
struct Ifx_div
{
sint32 quo, rem;
};
struct Ifx_divu
{
uint32 quo, rem;
};
/*********************************************************************************************************************/
/*------------------------------------------------Function Prototypes------------------------------------------------*/
/*********************************************************************************************************************/
IFX_INLINE struct Ifx_div Ifx_div(sint32 dividend, sint32 divisor)
{
register sint64 e = Ifx__div(dividend, divisor);
struct Ifx_div div = {.quo = e, .rem = (sint32)(e >> 32)};
return div;
}
IFX_INLINE struct Ifx_divu Ifx_divu(uint32 dividend, uint32 divisor)
{
register uint64 e = Ifx__divu(dividend, divisor);
struct Ifx_divu divu = {.quo = e, .rem = (uint32)(e >> 32)};
return divu;
}
#endif /* DIV_H_ */
/*
* Quick sorting works on Aurix. Its standard library includes a standard sorter.
* Sort an array of floating-point numbers.
*
* \see https://cplusplus.com/reference/cstdlib/qsort/
*/
{
float32 array[] = {3.0F, 2.0F, 1.0F};
qsort(array, sizeof(array) / sizeof(array[0]), sizeof(array[0]), compare_float32);
}
#include <stdlib.h>
#include <math.h>
/*!
* \brief Compares two floating-point numbers by reference.
* \details Avoids comparing equality in floating-point space.
* Compiler warnings arise when comparing floating equality.
* Compare greater than or less than. Default to equality if neither
* greater or less.
*
* The implementation:
*
* - avoids direct equality of floating-point numbers for a stable
* three-way float comparison;
*
* - explicitly checks for Not a Number (NaN) values.
*
* Two NaN values are equal; NaN equals NaN, naturally. Otherwise, NaN
* precedes all numbers. NaN compared to N yields "less" when compared.
* Some floating-point N compared to NaN gives a "greater" comparison.
*
* Answers -1 for NaN with N, 0 for NaN and NaN, and 1 for N with NaN.
*
* Does **not** compare with epsilon tolerance.
* \param left Pointer to left-hand float in 32 bits.
* \param right Pointer to right-hand 32-bit float.
* \retval -1 if left is less than right.
* \retval 1 if right is less than left.
* \retval 0 if left and right default to equality.
*/
int compare_float32 (const void *left, const void *right)
{
float32 lhs = *(const float32*) left, rhs = *(const float32*) right;
if (isnan(lhs))
return isnan(rhs) ? 0 : -1;
if (isnan(rhs))
return 1;
if (lhs < rhs)
return -1;
if (rhs < lhs)
return 1;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment