How to create a kernel thread which blinks led for every 500ms ?
I am facing an issue (buffer overflow) when I create kernel thread which actually blinks led for every 500ms.
My implementation of kernel thread is as below
From above code,PDC is the global structure, led_blink function will be called with input 0 or 1. Value 1 is passed to make led blink and 0 to put ON led constantly (no blinking).
static int led_control_thread()
int led_on = 0;
while(!PDC->led.thread_should_stop && !signal_pending(current))
/* Sleep for 500 mili seconds */
LED made on and off (alternatively)
DWORD led_blink(Bool bOn)
// start LED flashing thread
if( atomic_add_unless(&(PDC->led.thread_created), 1, 1) )
PDC->led.last_jiffies = 0;
PDC->led.thread_should_stop = 0;
kernel_thread(led_control_thread, 0, 0);
// stop LED flashing thread
if( atomic_add_unless(&(PDC->led.thread_created), -1, 0) )
PDC->led.thread_should_stop = 1;
This code is working fine for short period, but in long run, causing issues with other kernel threads. Say if there is any background recording going on in my embedded device in which this code is used, in long run, this kernel thread is interrupting the recording which shouldn't happend.
When investigated this thread is hanging on for more than 2 seconds and leading to issue in my system. Why does it hang for more than 2 seconds ?
I suspect following lines may be causing the thread to hang on for more than 2 seconds.
Could you please let me know whats wrong with my code ?
Let me know if you need any additional information for better understanding of the problem.
Thanks in advance,