Zwischenspeichern

This commit is contained in:
2025-06-16 13:09:27 +02:00
parent 1a85b40444
commit 9d017f9f8d
11 changed files with 258 additions and 64 deletions

View File

@@ -9,6 +9,7 @@ project(hello_world)
target_sources(app PRIVATE src/main.c)
target_sources(app PRIVATE ../lib/canbus.c)
target_sources(app PRIVATE ../lib/config.c)
target_include_directories(app PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../lib
)

View File

@@ -1,5 +1,7 @@
CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=3
CONFIG_LOG_SETTINGS_LEVEL=4
CONFIG_LOG_CAN_LEVEL=4
CONFIG_CBPRINTF_FP_SUPPORT=y
CONFIG_UART_CONSOLE=y # Console on USART1
@@ -7,4 +9,3 @@ CONFIG_UART_CONSOLE=y # Console on USART1
#CONFIG_USE_SEGGER_RTT=y
CONFIG_LOOPBACK_MODE=y
CONFIG_LOG_CAN_LEVEL=4

View File

@@ -6,15 +6,25 @@
#include <zephyr/logging/log.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/sys/byteorder.h>
#include "canbus.h"
#include "config.h"
LOG_MODULE_REGISTER(main, CONFIG_LOG_DEFAULT_LEVEL);
int main(void)
{
int rc;
LOG_INF("Starting CAN bus initialization...");
// Initialize the configuration and CAN bus
rc = config_init();
if (rc != 0)
{
LOG_ERR("Failed to initialize configuration: %d", rc);
return rc;
}
rc = canbus_init();
if (rc != 0)
{
@@ -22,5 +32,25 @@ int main(void)
return rc;
}
LOG_INF("CAN bus initialized successfully");
uint16_t counter = 0;
k_sleep(K_SECONDS(1)); // Sleep for 1 second before starting the loop
while (1)
{
uint8_t data[2] = {0x00};
UNALIGNED_PUT(sys_cpu_to_be16(counter), (uint16_t *)&data[0]);
canbus_send_message(1, 0x01, data, sizeof(data)); // Example message sending
LOG_DBG("Sent message with counter: %d", counter);
canbus_send_message(2, 0x01, data, sizeof(data)); // Example message sending
LOG_DBG("Sent message with counter: %d", counter);
counter++;
if (counter > 1000) // Reset counter after 1000
{
counter = 0;
}
k_sleep(K_SECONDS(5)); // Sleep for 5 second before next iteration
return 0; // Exit the loop after one iteration for testing purposes
// In a real application, you would likely not return here and continue the loop indefinitely
}
return 0;
}