Exploring BeagleBone: LKMs (by Derek Molloy)  V1.0
This project describes how you can build loadable kernel modules (LKMs) on your BeagleBone platform
 All Files Functions Variables Enumerations Enumerator Macros
Macros | Functions | Variables
testebbchar.c File Reference

A Linux user space program that communicates with the ebbchar.c LKM. It passes a string to the LKM and reads the response from the LKM. For this example to work the device must be called /dev/ebbchar. More...

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
Include dependency graph for testebbchar.c:

Macros

#define BUFFER_LENGTH   256
 The buffer length (crude but fine) More...
 

Functions

int main ()
 

Variables

static char receive [BUFFER_LENGTH]
 The receive buffer from the LKM. More...
 

Detailed Description

A Linux user space program that communicates with the ebbchar.c LKM. It passes a string to the LKM and reads the response from the LKM. For this example to work the device must be called /dev/ebbchar.

Author
Derek Molloy
Date
7 April 2015
Version
0.1
See also
http://www.derekmolloy.ie/ for a full description and follow-up descriptions.

Macro Definition Documentation

#define BUFFER_LENGTH   256

The buffer length (crude but fine)

Function Documentation

int main ( )
20  {
21  int ret, fd;
22  char stringToSend[BUFFER_LENGTH];
23  printf("Starting device test code example...\n");
24  fd = open("/dev/ebbchar", O_RDWR); // Open the device with read/write access
25  if (fd < 0){
26  perror("Failed to open the device...");
27  return errno;
28  }
29  printf("Type in a short string to send to the kernel module:\n");
30  scanf("%[^\n]%*c", stringToSend); // Read in a string (with spaces)
31  printf("Writing message to the device [%s].\n", stringToSend);
32  ret = write(fd, stringToSend, strlen(stringToSend)); // Send the string to the LKM
33  if (ret < 0){
34  perror("Failed to write the message to the device.");
35  return errno;
36  }
37 
38  printf("Press ENTER to read back from the device...\n");
39  getchar();
40 
41  printf("Reading from the device...\n");
42  ret = read(fd, receive, BUFFER_LENGTH); // Read the response from the LKM
43  if (ret < 0){
44  perror("Failed to read the message from the device.");
45  return errno;
46  }
47  printf("The received message is: [%s]\n", receive);
48  printf("End of the program\n");
49  return 0;
50 }
#define BUFFER_LENGTH
The buffer length (crude but fine)
Definition: testebbchar.c:17
static char receive[BUFFER_LENGTH]
The receive buffer from the LKM.
Definition: testebbchar.c:18

Variable Documentation

char receive[BUFFER_LENGTH]
static

The receive buffer from the LKM.