first commit
This commit is contained in:
commit
d7907f3cbe
|
@ -0,0 +1,5 @@
|
|||
*.o
|
||||
*.order
|
||||
*.symvers
|
||||
*.mod.c
|
||||
*.ko
|
|
@ -0,0 +1,124 @@
|
|||
/*
|
||||
* Beispiel: Grundgeruest einer Modbus-Kommunikation
|
||||
*
|
||||
* Aufbau einer Modbus-Kommunikation ohne weitere Funktion
|
||||
*
|
||||
*/
|
||||
|
||||
#include <rtai_mbx.h>
|
||||
#include <rtai_sched.h>
|
||||
|
||||
#include <uint128.h>
|
||||
#include <sys/rtai_modbus.h>
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
static RT_TASK entry_task;
|
||||
|
||||
/* Control Task */
|
||||
static void
|
||||
entry(long x)
|
||||
{
|
||||
int fd_node;
|
||||
int ready = 0;
|
||||
|
||||
rt_printk("control: task started\n");
|
||||
|
||||
/* Verbindung zum Modbus-Knoten herstellen */
|
||||
if ((fd_node = rt_modbus_connect("modbus-node")) == -1) {
|
||||
rt_printk("Acontrol: task exited\n");
|
||||
return;
|
||||
}
|
||||
rt_printk("control: MODBUS communication opened\n");
|
||||
|
||||
while(1) {
|
||||
int value = 0;
|
||||
int output = 0;
|
||||
if(rt_modbus_get(fd_node, DIGITAL_IN, 0, (unsigned short *) &value))
|
||||
goto fail;
|
||||
if(rt_modbus_get(fd_node, DIGITAL_OUT, 0, (unsigned short *) &output))
|
||||
goto fail;
|
||||
|
||||
if(value >32) {
|
||||
rt_printk("halloo welt");
|
||||
if(rt_modbus_set(fd_node, DIGITAL_OUT, 0, output |= 0b00000010))
|
||||
goto fail;
|
||||
|
||||
|
||||
// if(rt_modbus_set(fd_node, DIGITAL_IN, 0, 00000000))
|
||||
// goto fail;
|
||||
// }
|
||||
}else {
|
||||
if(rt_modbus_set(fd_node, DIGITAL_OUT, 0, output &= 0b00000000))
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Evtl. Ausgang zum Aufraemen */
|
||||
if (ready)
|
||||
goto fail;
|
||||
|
||||
/* Fair zu Linux sein und Zeit abgeben */
|
||||
rt_sleep(1000 * nano2count(1000000));
|
||||
}
|
||||
|
||||
/* Aufraeumen */
|
||||
fail:
|
||||
rt_modbus_disconnect(fd_node);
|
||||
rt_printk("control: task exited\n");
|
||||
}
|
||||
|
||||
/* Funktion die beim Entfernen des Moduls aufgerufen wird */
|
||||
static void __exit
|
||||
example_exit(void)
|
||||
{
|
||||
/* Task loeschen */
|
||||
rt_task_delete(&entry_task);
|
||||
/* Timer stoppen */
|
||||
stop_rt_timer();
|
||||
printk("rtai_example unloaded\n");
|
||||
}
|
||||
|
||||
/* Funktion die beim Laden des Moduls aufgerufen wird */
|
||||
static int __init
|
||||
example_init(void)
|
||||
{
|
||||
/* variables Timing basierend auf dem CPU-Takt */
|
||||
rt_set_oneshot_mode();
|
||||
/* Timer starten */
|
||||
start_rt_timer(0);
|
||||
/* Modbuskommunikation initialisieren */
|
||||
modbus_init();
|
||||
|
||||
/* Taskinitialisierung
|
||||
*
|
||||
* &task = Adresse des zu initialisierenden TCB
|
||||
* control = zum Task gehörende Funktion
|
||||
* 0 = Uebergabeparameter an die zum Task gehoerende Funktion (long)
|
||||
* 1024 = Stacksize
|
||||
* 0 = Priorität des Tasks (0 = groesste)
|
||||
* 0 = uses_fpu (Fliesskommaeinheit nicht benutzen); im Praktikum sollte es 0 bleiben
|
||||
* NULL = &signal_handler; Referenz zu einer Fkt., die bei jeder Aktivierung
|
||||
* des Tasks aufgerufen wird, ansonsten NULL
|
||||
*
|
||||
* Achtung: Nach der Initialisierung ist der Task "suspended"!
|
||||
*
|
||||
*/
|
||||
if (rt_task_init(&entry_task, entry, 0, 1024, 0, 0, NULL)) {
|
||||
printk("cannot initialize control task\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* suspend -> ready bzw. running */
|
||||
rt_task_resume(&entry_task);
|
||||
printk("rtai_example loaded\n");
|
||||
return (0);
|
||||
|
||||
fail:
|
||||
/* Aufraeumen */
|
||||
stop_rt_timer();
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Modulein- und ausstieg festlegen */
|
||||
module_exit(example_exit)
|
||||
module_init(example_init)
|
|
@ -0,0 +1,25 @@
|
|||
################################################################################
|
||||
# MODULE_NAME muss ungleich SOURCES sein!
|
||||
MODULE_NAME = control_module
|
||||
|
||||
OBJS = Bearbeiten2.o
|
||||
SOURCES = Bearbeiten2.c
|
||||
################################################################################
|
||||
|
||||
KERNEL_DIR := /usr/src/linux/
|
||||
INCLUDES := -I/usr/src/linux/include -I/usr/src/linux/arch/x86/include -I/usr/realtime/include -I/usr/include -I/usr/include/x86_64-linux-gnu
|
||||
LIBS :=
|
||||
LFLAGS :=
|
||||
SYMBOLS := /usr/realtime/Module.symvers /usr/share/modbus-com/Module.symvers
|
||||
EXTRA := -O2 -Wall
|
||||
|
||||
KBUILD_EXTRA_SYMBOLS := $(SYMBOLS)
|
||||
EXTRA_CFLAGS += $(INCLUDES) $(EXTRA) $(LIBS)
|
||||
obj-m += $(MODULE_NAME).o
|
||||
$(MODULE_NAME)-objs := $(OBJS)
|
||||
|
||||
all:
|
||||
$(MAKE) KBUILD_VERBOSE=3 -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules
|
||||
|
||||
clean:
|
||||
rm -rf .tmp_versions *.symvers *.o *.ko *.mod.c .*.cmd .*flags *.order
|
Loading…
Reference in New Issue