Book Image

GNU/Linux Rapid Embedded Programming

By : Rodolfo Giometti
Book Image

GNU/Linux Rapid Embedded Programming

By: Rodolfo Giometti

Overview of this book

Embedded computers have become very complex in the last few years and developers need to easily manage them by focusing on how to solve a problem without wasting time in finding supported peripherals or learning how to manage them. The main challenge with experienced embedded programmers and engineers is really how long it takes to turn an idea into reality, and we show you exactly how to do it. This book shows how to interact with external environments through specific peripherals used in the industry. We will use the latest Linux kernel release 4.4.x and Debian/Ubuntu distributions (with embedded distributions like OpenWrt and Yocto). The book will present popular boards in the industry that are user-friendly to base the rest of the projects on - BeagleBone Black, SAMA5D3 Xplained, Wandboard and system-on-chip manufacturers. Readers will be able to take their first steps in programming the embedded platforms, using C, Bash, and Python/PHP languages in order to get access to the external peripherals. More about using and programming device driver and accessing the peripherals will be covered to lay a strong foundation. The readers will learn how to read/write data from/to the external environment by using both C programs or a scripting language (Bash/PHP/Python) and how to configure a device driver for a specific hardware. After finishing this book, the readers will be able to gain a good knowledge level and understanding of writing, configuring, and managing drivers, controlling and monitoring applications with the help of efficient/quick programming and will be able to apply these skills into real-world projects.
Table of Contents (26 chapters)
GNU/Linux Rapid Embedded Programming
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

The raw CAN bus


In a Linux-based system, we can use the SocketCAN implementation to manage these devices and then exchange data between them. It uses the Berkeley socket API and the Linux network stack (and raw sockets) to implement CAN device drivers as network interfaces to allow programmers familiar with network programming to easily learn how to use CAN sockets.

Note

See the Documentation/networking/can.txt file in the kernel's repository for more information.

Here is a simplified example in C language regarding how to open a SocketCAN socket:

int s; 
char *ifname; 
struct sockaddr_can addr; 
struct can_frame frame; 
struct ifreq ifr; 
int ret; 
 
/* Open the PF_CAN socket */ 
s = socket(PF_CAN, SOCK_RAW, CAN_RAW); 
if (s < 0) { 
    perror("Error while opening socket"); 
    exit(-1); 
} 
 
/* Find the CAN device */ 
strcpy(ifr.ifr_name, ifname); 
ret = ioctl(s, SIOCGIFINDEX, &ifr); 
if (ret &lt...