amescon / raspicomm-module Goto Github PK
View Code? Open in Web Editor NEWraspicomm kernel module with tty driver support for rs485 (raspicommrs485.ko)
raspicomm kernel module with tty driver support for rs485 (raspicommrs485.ko)
Linux docs states that write(fd, buffer, length) is en equivalent to send(fd, buffer, length, 0)
Hy,
I've got problems to make the raspicomm driver for kernel 4.14 for use with PI3B+
Because I was unable to compile the module against the Kernel Header i've tried to compile it with current Raspberry Pi Kernel Source and ended with this.
LC_ALL=C make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -C ../linux/linux-raspberrypi-kernel_1.20180328-1/ -j 4 M=$(pwd) modules
make: Entering directory '/home/user/git/raspberrypi/linux/linux-raspberrypi-kernel_1.20180328-1'
CC [M] /home/user/git/raspberrypi/raspicomm-module/module.o
In file included from /home/user/git/raspberrypi/raspicomm-module/module.c:16:0:
/home/user/git/raspberrypi/raspicomm-module/platform.h:1:100: fatal error: mach/platform.h: Datei oder Verzeichnis nicht gefunden (translate: File or Directory not found)
#include <mach/platform.h> /* included for BCM2709 & BCM2708 definitions, e.g. BCM2708_PERI_BASE */
^
compilation terminated.
scripts/Makefile.build:328: die Regel für Ziel „/home/user/git/raspberrypi/raspicomm-module/module.o“ scheiterte (translate: recipe for target ... failed)
make[1]: *** [/home/user/git/raspberrypi/raspicomm-module/module.o] Fehler 1
Makefile:1519: recipe for target '_module_/home/user/git/raspberrypi/raspicomm-module' failed
make: *** [_module_/home/user/git/raspberrypi/raspicomm-module] Error 2
make: Leaving directory '/home/user/git/raspberrypi/linux/linux-raspberrypi-kernel_1.20180328-1'
As far as I found out (raspberrypi/linux#1844) the problem have to do something with the constraint to use devicetree.
Cannot detect if data is available via select() using fd_set, timeval (for timeout) (always returns "data available") -> still have to use the poll mechanism
We are using amescon raspicomm extension board to be able to use both rs232 (baudrate of 38400 bit/s) and rs485 (baudrate of 1200 bit/s) at the same time.
But it doesn't work very well: when both rs485 and rs232 are activated, we always get "X input overrun(s)" messages dumped to syslog and the application which is communicating over rs232 fails to decode some messages (probably because parts of these messages are dropped).
Here is a excerpt from syslog:
Mar 25 16:14:37 hl-mc-4-dev kernel: [25924.781649] ttyAMA0: 1 input overrun(s)
Mar 25 16:14:45 hl-mc-4-dev kernel: [25932.673028] ttyAMA0: 1 input overrun(s)
Mar 25 16:14:45 hl-mc-4-dev trserver: Error decoding tracker ID from tracker: #0150,0,0,0,0#012
Mar 25 16:15:32 hl-mc-4-dev kernel: [25979.919178] ttyAMA0: 1 input overrun(s)
Mar 25 16:15:32 hl-mc-4-dev trserver: Error decoding data from tracker: #015B2,3,0,0,0,0,0,0E3,0,0,0,12,1,84,-9999#012
Mar 25 16:15:35 hl-mc-4-dev kernel: [25982.313622] ttyAMA0: 1 input overrun(s)
Mar 25 16:15:45 hl-mc-4-dev kernel: [25992.947961] ttyAMA0: 1 input overrun(s)
Mar 25 16:15:45 hl-mc-4-dev trserver: Error decoding data from tracker: #015B3,1,1,0,0,02,258,0,1#012
Mar 25 16:15:52 hl-mc-4-dev trserver: Error decoding data from tracker: #015B2,2,0,0,0,0,0,2A2,3,0,0,0,0,0#012
Mar 25 16:15:52 hl-mc-4-dev kernel: [26000.096681] ttyAMA0: 1 input overrun(s)
Mar 25 16:15:57 hl-mc-4-dev kernel: [26004.244391] ttyAMA0: 1 input overrun(s)
Mar 25 16:15:57 hl-mc-4-dev trserver: Error decoding data from tracker: #015B0,2,0,0,0,0,0,0A0,3,0,0,0,0,0#012
Also please note that when rs485 is disabled, everything is fine.
So do you know why using rs485 causes these "ttyAMA0: X input overrun(s)"? and how we can fix those so that we can use both rs232 and rs485 at the same time?
Maybe this is due to some busy-wait operations in the rs485 driver source code?
My configuration:
Kernel 4.1.13-v7+
Raspberry Pi 2
When I try to compile module on RP2 I get
make -C /lib/modules/4.1.13-v7+/build M= modules
make[1]: Entering directory '/usr/src/linux-headers-4.1.13-v7+'
CHK include/config/kernel.release
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
make[2]: 'include/generated/mach-types.h' is up to date.
CHK include/generated/bounds.h
CHK include/generated/asm-offsets.h
CALL scripts/checksyscalls.sh
grep: scripts/../arch/x86/syscalls/syscall_32.tbl: No such file or directory
make[2]: *** No rule to make target 'arch/arm/crypto/aes-armv4.o', needed by 'arch/arm/crypto/aes-arm.o'. Stop.
Makefile:947: recipe for target 'arch/arm/crypto' failed
make[1]: *** [arch/arm/crypto] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.1.13-v7+'
Makefile2:6: recipe for target 'all' failed
make: *** [all] Error 2
I modified Makefile like this
CURRENT := $(shell uname -r)
KDIR := /lib/modules/$(CURRENT)/build
PWD := $(shell pwd)
obj-m += raspicommrs485.o
raspicommrs485-objs := module.o queue.o
all:
# $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
$(MAKE) -I $(KDIR)/arch/arm/include/asm/ -C $(KDIR) M=$(PWD)
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
but not I am getting error when I want to insmod
insmod: ERROR: could not insert module raspicommrs485.ko: No such device
Still no "packet mode" (buffering). poll() always returns only 1 byte to be readable at once -> so in this case, there is no real advantage (ok, no root rights needed ;)) regarding to the raspicomm API using the "char by char" callback function
Hi,
I'm getting intermittent system freezes on multiple new Raspi B+ V1.2 boards
running Raspian / Linux 3.18.7+ and the actual module driver.
SysRq doesn't work; no kernel dump, nothing logged.
Following test code will freeze my Pi in a matter of minutes.
#include <stdio.h> /* included for printf() */
#include <fcntl.h> /* included for O_RDWR, O_NOCTTY and O_NDELAY */
#include <termios.h> /* included for functions and defines used in set_interface_attribs */
#include <string.h> /* included for memset */
#include <unistd.h>
#include <errno.h>
#define READER "/dev/ttyRPC0"
//#define READER "/dev/ttyUSB0"
int comport;
unsigned char mesg1[]= {0x01,0x02,0x03,0x04};
/*
Source:
http://stackoverflow.com/questions/6947413/how-to-open-read-and-write-from-serial-port-in-c
*/
int set_interface_attribs (int fd, int speed, int parity)
{
struct termios tty;
memset (&tty, 0, sizeof tty);
if (tcgetattr (fd, &tty) != 0)
{
printf("error using tcgetattr\n");
return -1;
}
cfsetospeed (&tty, speed);
cfsetispeed (&tty, speed);
tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; // 8-bit chars
// disable IGNBRK for mismatched speed tests; otherwise receive break
// as \000 chars
tty.c_iflag &= ~IGNBRK; // ignore break signal
tty.c_lflag = 0; // no signaling chars, no echo,
// no canonical processing
tty.c_oflag = 0; // no remapping, no delays
tty.c_cc[VMIN] = 0; // read doesn't block
tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout
tty.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl
tty.c_cflag |= (CLOCAL | CREAD);// ignore modem controls,
// enable reading
tty.c_cflag &= ~(PARENB | PARODD); // shut off parity
tty.c_cflag |= parity;
tty.c_cflag &= ~CSTOPB;
tty.c_cflag &= ~CRTSCTS;
if (tcsetattr (fd, TCSANOW, &tty) != 0)
{
printf("error from tcsetattr\n");
return -1;
}
return 0;
}
int main(int argc, char** argv)
{
fprintf(stdout,"Test for RasPiComm\n");
fprintf(stdout,"Open Port %s...\n", READER);
if ( (comport = open(READER, O_RDWR | O_NOCTTY | O_NDELAY)) < 0 )
{
fprintf(stdout,"failed.\n");
fprintf(stdout,"possible causes:\n");
fprintf(stdout,"1) the raspicomm device driver is not loaded. type 'lsmod' and verify that you 'raspicommrs485' is loaded.\n");
fprintf(stdout,"2) the raspicomm device driver is in use. Is another application using the device driver?\n" );
fprintf(stdout,"3) something went wrong when loading the device driver. type 'dmesg' and check the kernel messages\n");
return -1;
}
printf("successful. fd=%i\n", comport);
// configure the port
if (set_interface_attribs(comport, B19200, PARENB) < 0)
{
fprintf(stdout,"Error configuring RS485 Port.\n");
return -2;
}
int count=0;
while(1)
{
fprintf(stdout,"Sending String \n");
int written=write(comport,mesg1,4);
if(written<4)
{
fprintf(stdout,"Write ERROR!");
}
if(count%20==0)
{
fprintf(stdout,"\nKLICK\n");
count=0;
}
count++;
usleep(10000);
}
//Never reached
close(comport);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.