#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/drivers/uart.h>
#include <zephyr/usb/usb_device.h>
#include <zephyr/usb/usbd.h>
#include<stdio.h>
volatile uint8_t g_u8_onesec_timer_interrupt;
LOG_MODULE_REGISTER(UART, CONFIG_LOG_DEFAULT_LEVEL);
const struct device *const uart_dev = DEVICE_DT_GET_ONE(zephyr_cdc_acm_uart);
void config_uart(void)
{
int ret;
if (!device_is_ready(uart_dev))
{
LOG_ERR("CDC ACM device not ready");
}
ret = usb_enable(NULL);
if (ret != 0)
{
LOG_ERR("Failed to enable USB");
}
}
void uart_enable(void)
{
uart_irq_rx_enable(uart_dev);
uart_irq_tx_enable(uart_dev);
}
void uart_disable(void)
{
uart_irq_tx_disable(uart_dev);
uart_irq_rx_disable(uart_dev);
}
/////////////////////////////////
// Add function prototypes at the top before K_WORK_DEFINE()
static void my_work_sys_app_handler(struct k_work *work);
// Define the work items properly
K_WORK_DEFINE(my_work_sys_app, my_work_sys_app_handler);
// Define the timers
struct k_timer my_sys_app_timer;
// Function prototypes for expiry handlers
static void my_sys_app_timer_expiry_function(struct k_timer *timer_id);
// Initialize the timers with the correct expiry functions
K_TIMER_DEFINE(my_sys_app_timer, my_sys_app_timer_expiry_function, NULL);
// Work queue handler for system application timer
void my_work_sys_app_handler(struct k_work *work)
{
g_u8_onesec_timer_interrupt = 1;
}
// Timer expiry function for system application timer
void my_sys_app_timer_expiry_function(struct k_timer *my_sys_app_timer)
{
k_work_submit(&my_work_sys_app);
}
// Function to start the system application timer
void sys_app_start_timer(uint32_t u32_interval)
{
k_timer_start(&my_sys_app_timer, K_MSEC(u32_interval), K_MSEC(u32_interval));
}
// Function to stop the system application timer
void stop_sys_app_timer(void)
{
k_timer_stop(&my_sys_app_timer);
}
///////////////////////////////////////////////////////////
int main(void)
{
config_uart();
sys_app_start_timer(1000);
while(1)
{
printf("hello nRF...\n");
if(g_u8_onesec_timer_interrupt)
{
g_u8_onesec_timer_interrupt = 0;
uart_enable();
}
}
uart_disable();
k_cpu_idle();
}
//////////////////prj.conf//////////////////////////////
CONFIG_CONSOLE=y
CONFIG_STDOUT_CONSOLE=y
CONFIG_PRINTK=y
CONFIG_SERIAL=y
CONFIG_UART_CONSOLE=y
CONFIG_UART_LINE_CTRL=y
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="Zephyr USB console sample"
CONFIG_USB_DEVICE_PID=0x0004
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_CDC_ACM=y
CONFIG_SERIAL=y
CONFIG_PM_DEVICE=y
CONFIG_PM_DEVICE_RUNTIME=y
even thuogh i am using k_cpu_idle why wake_count = 50? ... is their any methods to keep the device in idle when it is idle.....