Seregon/rtnet-stack

Real-Time Embedded Network Stack

C/66 B/No license
platforms/rtnet_platform_baremetal.c
rtnet-stack / platforms / rtnet_platform_baremetal.c
1/**
2 * @file rtnet_platform_baremetal.c
3 * @brief Bare-metal platform hooks using IRQ disable/enable and a weak TX hook.
4 * @link https://github.com/seregonwar/rtnet-stack/blob/main/platforms/rtnet_platform_baremetal.c
5 * @version 1.0.0
6 * @date 2026-01-07
7 * @author Seregon
8 *
9MIT License
10 
11Copyright (c) 2026 Seregon
12 
13Permission is hereby granted, free of charge, to any person obtaining a copy
14of this software and associated documentation files (the "Software"), to deal
15in the Software without restriction, including without limitation the rights
16to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17copies of the Software, and to permit persons to whom the Software is
18furnished to do so, subject to the following conditions:
19 
20The above copyright notice and this permission notice shall be included in all
21copies or substantial portions of the Software.
22 
23THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29SOFTWARE.
30 */
31 
32#include "rtnet_stack.h"
33#include <stdint.h>
34 
35#if defined(_MSC_VER)
36 #define RTNET_WEAK __declspec(selectany)
37#else
38 #define RTNET_WEAK __attribute__((weak))
39#endif
40 
41/* Board-specific transmit hook to be provided by the BSP */
42RTNET_WEAK void RTNET_Platform_EthTransmit(const uint8_t* data, uint16_t length)
43{
44 (void)data;
45 (void)length;
46 /* Implement MAC driver TX here */
47}
48 
49/* Weak hooks for IRQ control; override with MCU-specific intrinsics */
50RTNET_WEAK void RTNET_Platform_DisableIRQ(void)
51{
52 /* __disable_irq(); */
53}
54 
55RTNET_WEAK void RTNET_Platform_EnableIRQ(void)
56{
57 /* __enable_irq(); */
58}
59 
60static volatile uint32_t g_time_ms = 0U;
61 
62void RTNET_CriticalSectionEnter(void)
63{
64 RTNET_Platform_DisableIRQ();
65}
66 
67void RTNET_CriticalSectionExit(void)
68{
69 RTNET_Platform_EnableIRQ();
70}
71 
72uint32_t RTNET_GetTimeMs(void)
73{
74 /* In bare-metal mode, ensure a 1ms tick updates g_time_ms (e.g., SysTick) */
75 return g_time_ms;
76}
77 
78void RTNET_HardwareTransmit(const uint8_t* data, uint16_t length)
79{
80 RTNET_Platform_EthTransmit(data, length);
81}
82 
83/* Call this from a 1ms ISR (e.g., SysTick) to advance time */
84void RTNET_Platform_Tick1ms(void)
85{
86 g_time_ms++;
87}
88