unable to open serial port from a kernel module
hi,
when i use rt_dev_open ("/dev/ttyS0", 0); from the function init_module () of a self written kernel module, it returns -19 ! What must be the reason, can't a file be opened from a kernel module ?
kindly help !
-------------------------------------
Hi-Tech Gears Limited, Gurgaon, India
Quoted 5 lines · Anisha Kaul
hi,
when i use
rt_dev_open("/dev/ttyS0", 0); from the functioninit_module() of a self written kernel module, it returns -19 ! What must be the reason, can't a file be opened from a kernel module ?
Please read documentation and examples more carefully: "rtdev0" is the answer.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux
Quoted 11 lines
Quoted 5 lines · Anisha Kaul
hi,
when i use
rt_dev_open("/dev/ttyS0", 0); from the functioninit_module() of a self written kernel module, it returns -19 ! What must be the reason, can't a file be opened from a kernel module ?Please read documentation and examples more carefully: "rtdev0" is the answer.
Jan
Thanks for being patient,
Did you mean this --> ''rtdm_open ("rtdev0", 0);"
I tried this from the init_module () of the concerned kernel module, it still returns '-19'.
Anyways, as per your example '', I tried --> "rt_dev_open ("rtdev0", 0);" from the main () function of the user space program. As per one of your mails I added "-lrtdm" to the LDFLAGS of the concerned Makefile for the compilation of rt_dev_open. The program compiled without errors but still it returns '-19'.
regards,
anisha
-------------------------------------
Hi-Tech Gears Limited, Gurgaon, India
Quoted 11 lines · On Wednesday November 11 2009 14 : 49 : 19 you wrote:
Quoted 5 lines · Anisha Kaul
hi,
when i use
rt_dev_open("/dev/ttyS0", 0); from the functioninit_module() of a self written kernel module, it returns -19 ! What must be the reason, can't a file be opened from a kernel module ?Please read documentation and examples more carefully: "rtdev0" is the answer.
Jan
Hi,
I forgot to attach the kernel module file as well as the user space file in the previous mail. Hereby I have included both of them !
kernel module file: serialPortISR.c
user space file : userSpace.c
thanks,
anisha
#include <native/task.h>
#include <native/heap.h>
#include <native/intr.h>
#include <linux/kernel.h>
#include <rtdm/rtdm_driver.h>
#define PORT 0x3F8
RT_INTR serialRT;RT_HEAP heap_desc;rtdm_task_t task;
char* shmem;
static rtdm_task_t tasklet;
static int times;rtdm_task_proc_t resetRegisters (void * f)
{
outb (0x83, PORT + 3);
outb (0x01, PORT + 0);
outb (0x00, PORT + 1);
outb (0x03, PORT + 3);
outb (0x01, PORT + 1);
outb (0x27, PORT + 2);
outb (0x08, PORT + 4);
return NULL;
}rt_isr_t isrSerialPort (int irq, void *dev_id, struct pt_regs *regs)
{
times++;
printk (KERN_ALERT "\nisrSerialPort called %d ", times);
*shmem = inb (PORT);
printk ("\nsharedMem: %s", shmem);
rtdm_task_init (&tasklet, "tasklet", resetRegisters, NULL, 1, 0);
return (rt_isr_t) IRQ_HANDLED;
}int init_module ()
{
rt_intr_create (&serialRT, "softbrainISR", 4, isrSerialPort, NULL, I_SHARED);
rt_intr_enable (&serialRT);
outb (0x83, PORT + 3);
outb (0x01, PORT + 0);
outb (0x00, PORT + 1);
outb (0x03, PORT + 3);
outb (0x01, PORT + 1);
outb (0x27, PORT + 2);
outb (0x08, PORT + 4);
rt_heap_create (&heap_desc, "MyHeap", 16384, H_SHARED);
rt_heap_alloc (&heap_desc, 0, TM_NONBLOCK, (void*)&shmem);
return result;
}void cleanup_module ()
{
rt_heap_free (&heap_desc, &shmem);
rt_intr_delete (&serialRT);
printk (KERN_ALERT "\ncleanup_module called\n");
}MODULE_LICENSE ("GPL");
#include <sys/mman.h>
#include <native/task.h>
#include <native/timer.h>
#include <native/heap.h>
#include <string.h>
#include <rtdm/rtdm.h>
RT_TASK task_desc;RT_HEAP heap_desc;
void* shmem;
int main ()
{
mlockall (MCL_CURRENT|MCL_FUTURE);
rt_heap_bind (&heap_desc, "MyHeap", TM_NONBLOCK);
rt_heap_alloc (&heap_desc, 1, TM_NONBLOCK, &shmem);/***************************************/
int result = rt_dev_open ("rtdev0", 0);
printf ("\n%d passed ", result);
rt_dev_write (result, "abcd", 4);/***************************************/
}
-------------------------------------
Hi-Tech Gears Limited, Gurgaon, India
Hi,
Quoted 3 lines
int main ()
{ mlockall (MCL_CURRENT|MCL_FUTURE);
you need to call rt_task_shadow(...) here (see docs), which turns the current Linux task into a native Xenomai task.
Quoted 2 lines
rt_heap_bind (&heap_desc, "MyHeap", TM_NONBLOCK);
rt_heap_alloc (&heap_desc, 1, TM_NONBLOCK, &shmem);check all return values. I guess its -19 too without rt_task_shadow.
Quoted 8 lines
/***************************************/
int result = rt_dev_open ("rtdev0", 0); printf ("\n%d passed ", result); rt_dev_write (result, "abcd", 4);/***************************************/
}
good luck,
kisda
Quoted 39 lines · Anisha Kaul
Quoted 10 lines · On Wednesday November 11 2009 14 : 49 : 19 you wrote:
Quoted 5 lines · Anisha Kaul
hi,
when i use
rt_dev_open("/dev/ttyS0", 0); from the functioninit_module() of a self written kernel module, it returns -19 ! What must be the reason, can't a file be opened from a kernel module ?Please read documentation and examples more carefully: "rtdev0" is the answer.
Jan
Hi,
I forgot to attach the kernel module file as well as the user space file in the previous mail. Hereby I have included both of them !
kernel module file:
serialPortISR.c
user space file :userSpace.cthanks,
anisha------------------------------------------------------------------------
-------------------------------------
Hi-Tech Gears Limited, Gurgaon, India------------------------------------------------------------------------
_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help