[Armadeus-commitlog] armadeus branch, master, updated. release-3.4-54-g96d2837
Brought to you by:
sszy
|
From: Fabien M <fa...@us...> - 2011-04-14 10:15:20
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "armadeus".
The branch, master has been updated
via 96d28377434501120fd4d464928e3f451f664a58 (commit)
via b9806306962d854c43cc111f349c92d15ee4d506 (commit)
from ab617c5cfc95337575baef95930fc1f82d65757b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 96d28377434501120fd4d464928e3f451f664a58
Author: Kevin JOLY <jol...@gm...>
Date: Thu Apr 14 11:07:16 2011 +0200
[BUILDROOT] Update makefile of socketcan (strip command added)
Signed-off-by: Kevin JOLY <jol...@gm...>
Signed-off-by: Fabien Marteau <fab...@ar...>
commit b9806306962d854c43cc111f349c92d15ee4d506
Author: Kevin JOLY <jol...@gm...>
Date: Thu Apr 14 10:57:28 2011 +0200
[DEMOS] Demo for can mcp25020 IOexpander chip added
Signed-off-by: Kevin JOLY <jol...@gm...>
Signed-off-by: Fabien Marteau <fab...@ar...>
-----------------------------------------------------------------------
Summary of changes:
buildroot/package/armadeus/demos/Config.in | 10 +
buildroot/package/armadeus/demos/demos.mk | 8 +-
patches/buildroot/2010.11/042-socketcan.patch | 13 +-
target/demos/mcp25020_ctrl/Makefile | 36 +++
target/demos/mcp25020_ctrl/init_can.sh | 10 +
target/demos/mcp25020_ctrl/mcp25020_ctrl.c | 308 +++++++++++++++++++++++++
6 files changed, 376 insertions(+), 9 deletions(-)
create mode 100644 target/demos/mcp25020_ctrl/Makefile
create mode 100755 target/demos/mcp25020_ctrl/init_can.sh
create mode 100644 target/demos/mcp25020_ctrl/mcp25020_ctrl.c
diff --git a/buildroot/package/armadeus/demos/Config.in b/buildroot/package/armadeus/demos/Config.in
index e15ce36..bd12889 100644
--- a/buildroot/package/armadeus/demos/Config.in
+++ b/buildroot/package/armadeus/demos/Config.in
@@ -65,4 +65,14 @@ config BR2_PACKAGE_ARMADEUS_DEMOS_TEST_LCD
help
Test for LCD dead pixels. Needs SDL.
+config BR2_PACKAGE_ARMADEUS_DEMOS_MCP25020
+ bool "DEMOS_MCP25020"
+ depends on BR2_PACKAGE_SOCKETCAN
+ help
+ Test for CAN bus communication with MCP25020.
+ Requires socket CAN.
+
+comment "DEMOS_MCP25020 requires socket CAN"
+ depends on !BR2_PACKAGE_SOCKETCAN
+
endmenu
diff --git a/buildroot/package/armadeus/demos/demos.mk b/buildroot/package/armadeus/demos/demos.mk
index 785f573..db6f92a 100644
--- a/buildroot/package/armadeus/demos/demos.mk
+++ b/buildroot/package/armadeus/demos/demos.mk
@@ -9,7 +9,7 @@ ARMADEUS-DEMOS_SOURCE:=$(TOPDIR)/../target/demos
ARMADEUS-DEMOS_DIR:=$(BUILD_DIR)/armadeus-demos-$(ARMADEUS-DEMOS_VER)
ARMADEUS-DEMOS_TARGET_DIR:=$(TARGET_DIR)/usr/local/bin
ARMADEUS-DEMOS_TARGET_DATA_DIR:=$(TARGET_DIR)/usr/share
-
+ARMADEUS-DEMOS_TARGET_INIT_DIR:=$(TARGET_DIR)/etc/init.d
ifeq ($(BR2_PACKAGE_ARMADEUS_DEMOS_ARMANOID),y)
ARMADEUS-DEMOS_SUBDIRS+=armanoid
@@ -58,7 +58,6 @@ ARMADEUS-DEMOS_SUBDIRS+=test_lcd
ARMADEUS-DEMOS_DEPS=sdl
endif
-
ifeq ($(BR2_PACKAGE_ARMADEUS_DEMOS_MUSIC_PLAYER),y)
ARMADEUS-DEMOS_DEPS+=sdl_ttf sdl_mixer
endif
@@ -66,6 +65,9 @@ ifeq ($(BR2_PACKAGE_ARMADEUS_DEMOS_SHOW_IMAGE),y)
ARMADEUS-DEMOS_DEPS+=sdl_image
endif
+ifeq ($(BR2_PACKAGE_ARMADEUS_DEMOS_MCP25020),y)
+ARMADEUS-DEMOS_SUBDIRS+=mcp25020_ctrl
+endif
$(ARMADEUS-DEMOS_DIR)/.unpacked:
mkdir -p $(ARMADEUS-DEMOS_DIR)/
@@ -88,7 +90,7 @@ $(ARMADEUS-DEMOS_DIR)/.installed: $(ARMADEUS-DEMOS_DIR)/.compiled
dir=$(ARMADEUS-DEMOS_DIR)/$$dir ; \
if [ -d $$dir ] ; then \
(cd $$dir && $(MAKE) install INSTALL_DIR=$(ARMADEUS-DEMOS_TARGET_DIR) \
- INSTALL_DATA_DIR=$(ARMADEUS-DEMOS_TARGET_DATA_DIR) STRIP=$(TARGET_STRIP)) || exit 1 ; \
+ INSTALL_DATA_DIR=$(ARMADEUS-DEMOS_TARGET_DATA_DIR) INIT_DIR=$(ARMADEUS-DEMOS_TARGET_INIT_DIR) STRIP=$(TARGET_STRIP)) || exit 1 ; \
fi \
done
touch $@
diff --git a/patches/buildroot/2010.11/042-socketcan.patch b/patches/buildroot/2010.11/042-socketcan.patch
index 59a016a..710825b 100644
--- a/patches/buildroot/2010.11/042-socketcan.patch
+++ b/patches/buildroot/2010.11/042-socketcan.patch
@@ -5,8 +5,8 @@ Signed-off-by: Kevin Joly <jol...@gm...>
Index: buildroot/package/Config.in
===================================================================
---- buildroot.orig/package/Config.in 2011-04-12 14:13:34.037382997 +0200
-+++ buildroot/package/Config.in 2011-04-12 14:14:25.261382995 +0200
+--- buildroot.orig/package/Config.in 2011-04-14 11:00:01.037201002 +0200
++++ buildroot/package/Config.in 2011-04-14 11:01:48.489201004 +0200
@@ -428,6 +428,7 @@
source "package/samba/Config.in"
source "package/ser2net/Config.in"
@@ -18,7 +18,7 @@ Index: buildroot/package/Config.in
Index: buildroot/package/socketcan/Config.in
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
-+++ buildroot/package/socketcan/Config.in 2011-04-12 14:13:34.057382996 +0200
++++ buildroot/package/socketcan/Config.in 2011-04-14 11:00:01.061201003 +0200
@@ -0,0 +1,15 @@
+config BR2_PACKAGE_SOCKETCAN
+ bool "Socket CAN"
@@ -38,8 +38,8 @@ Index: buildroot/package/socketcan/Config.in
Index: buildroot/package/socketcan/socketcan.mk
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
-+++ buildroot/package/socketcan/socketcan.mk 2011-04-12 14:18:14.589382996 +0200
-@@ -0,0 +1,54 @@
++++ buildroot/package/socketcan/socketcan.mk 2011-04-14 11:02:47.957201006 +0200
+@@ -0,0 +1,55 @@
+#############################################################
+#
+# Socket CAN
@@ -75,7 +75,8 @@ Index: buildroot/package/socketcan/socketcan.mk
+
+$(TARGET_DIR)/usr/local/bin/$(PROGRAMS): $(SOCKETCAN_DIR)/can-utils/$(PROGRAMS)
+ $(MAKE) DESTDIR=$(TARGET_DIR) -C $(SOCKETCAN_DIR)/can-utils install
-+
++ $(TARGET_STRIP) $(TARGET_DIR)/usr/local/bin/$(PROGRAMS)
++
+SOCKETCAN socketcan: $(TARGET_DIR)/usr/local/bin/$(PROGRAMS)
+
+socketcan-source: $(DL_DIR)/$(SOCKETCAN_SOURCE)
diff --git a/target/demos/mcp25020_ctrl/Makefile b/target/demos/mcp25020_ctrl/Makefile
new file mode 100644
index 0000000..a338327
--- /dev/null
+++ b/target/demos/mcp25020_ctrl/Makefile
@@ -0,0 +1,36 @@
+# Default values for local compiling:
+ARMADEUS_BASE_DIR=../../..
+-include $(ARMADEUS_BASE_DIR)/Makefile.in
+
+STAGING_DIR:=$(ARMADEUS_BUILD_DIR)/staging_dir/
+INSTALL_DIR:=$(ARMADEUS_ROOTFS_DIR)/usr/local/bin
+INIT_DIR:=$(ARMADEUS_ROOTFS_DIR)/etc/init.d
+CC:=$(ARMADEUS_TOOLCHAIN_PATH)/arm-linux-gcc
+STRIP:=$(ARMADEUS_TOOLCHAIN_PATH)arm-linux-sstrip
+
+DEFINES=TARGET
+CFLAGS= -Wall
+
+default: mcp25020_ctrl
+
+all: mcp25020_ctrl
+
+mcp25020_ctrl.o: mcp25020_ctrl.c
+ $(CC) $(CFLAGS) -c -o $@ $^
+
+install: mcp25020_ctrl
+ mkdir -p $(INSTALL_DIR)
+ cp $^ $(INSTALL_DIR)
+ cp init_can.sh $(INIT_DIR)/S50init_can.sh
+ $(STRIP) $(INSTALL_DIR)/mcp25020_ctrl
+
+uninstall:
+ rm -f $(INSTALL_DIR)/mcp25020_ctrl
+ rm -f $(INIT_DIR)/S50init_can.sh
+
+clean:
+ rm -rf mcp25020_ctrl
+ rm -rf *.o
+
+.PHONY: clean install uninstall
+
diff --git a/target/demos/mcp25020_ctrl/init_can.sh b/target/demos/mcp25020_ctrl/init_can.sh
new file mode 100755
index 0000000..3365644
--- /dev/null
+++ b/target/demos/mcp25020_ctrl/init_can.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+modprobe can
+modprobe can-dev
+modprobe can-raw
+modprobe mcp251x
+ip link set can0 up type can bitrate 125000
+ifconfig can0 up
+
+exit 0
diff --git a/target/demos/mcp25020_ctrl/mcp25020_ctrl.c b/target/demos/mcp25020_ctrl/mcp25020_ctrl.c
new file mode 100644
index 0000000..929f03c
--- /dev/null
+++ b/target/demos/mcp25020_ctrl/mcp25020_ctrl.c
@@ -0,0 +1,308 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <signal.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+
+#include <net/if.h>
+
+#include <linux/can.h>
+#include <linux/can/raw.h>
+
+#ifndef PF_CAN
+#define PF_CAN 29
+#endif
+
+#ifndef AF_CAN
+#define AF_CAN PF_CAN
+#endif
+
+#define SW2_MASK 0x01 /* Mask of the SW2 bit */
+
+int listen_mode(int can_socket);
+int led_flash(int can_socket);
+int led_on(int can_socket);
+int led_off(int can_socket);
+int sw2_get(int can_socket);
+int read_config(int can_socket);
+void display_help();
+void int_quit(int sig);
+
+/* Global variable */
+int quit;
+
+int main(int argc, char **argv)
+{
+ struct ifreq ifr;
+ struct sockaddr_can addr;
+ int can_socket;
+
+ quit=0;
+ signal(SIGINT, int_quit); /* Capture the ctrl+C sequence */
+
+ /* If no arguments is given */
+ if (argc < 2) {
+ display_help();
+ return EXIT_SUCCESS;
+ }
+
+ /* Interface selection on can0 */
+ strcpy(ifr.ifr_name, "can0");
+
+ /* Socket creation */
+ if ((can_socket = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0 ) {
+ perror("socket");
+ return EXIT_FAILURE;
+ }
+
+ /* Association of the socket with the interface */
+ ioctl(can_socket, SIOCGIFINDEX, &ifr);
+
+ /* Socket param */
+ addr.can_family = AF_CAN;
+ addr.can_ifindex = ifr.ifr_ifindex;
+
+ /* Bind of the socket */
+ if(bind(can_socket, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
+ perror("bind");
+ return EXIT_FAILURE;
+ }
+
+ if (strcmp(argv[1], "listen") == 0) {
+ listen_mode(can_socket);/* Entering in listen mode */
+ } else if(strcmp(argv[1], "led-flash") == 0) {
+ led_flash(can_socket);/* Entering in led flashing mode */
+ } else if(strcmp(argv[1], "led-on") == 0) {
+ led_on(can_socket);/* Entering in led on mode */
+ } else if(strcmp(argv[1], "led-off") == 0) {
+ led_off(can_socket);/* Entering in led off mode */
+ } else if(strcmp(argv[1], "sw2-get") == 0) {
+ sw2_get(can_socket);/* Entering in get state of the SW2 switch mode */
+ } else if(strcmp(argv[1], "config") == 0) {
+ read_config(can_socket);
+ } else {
+ display_help();/* Display display_help */
+ }
+
+ close(can_socket);
+
+ return EXIT_SUCCESS;
+}
+
+int listen_mode(int can_socket)
+{
+ struct can_frame receivedCanFrame;
+ int i, size;
+
+ while (quit != 1) {
+ /* Read the data received by the interface */
+ if ((size = read(can_socket, &receivedCanFrame, sizeof(receivedCanFrame))) < 0) {
+ perror("read");
+ return size;
+ }
+
+ if (receivedCanFrame.can_id & CAN_RTR_FLAG) {/* If the last data received was a remote request frame */
+ printf("ID: 0x%X is a remote request of %d byte(s) ", (receivedCanFrame.can_id ^ CAN_RTR_FLAG), receivedCanFrame.can_dlc);
+ }
+ else {/* If the last frame received was a data frame */
+ printf("ID: 0x%X -> %d byte(s): ", receivedCanFrame.can_id, receivedCanFrame.can_dlc);
+
+ for (i= 0; i<receivedCanFrame.can_dlc; i++)
+ printf("0x%X ",receivedCanFrame.data[i]);
+ }
+ printf("\n");
+ }
+
+ return EXIT_SUCCESS;
+}
+
+int led_flash(int can_socket)
+{
+ int size;
+
+ struct can_frame frameToSend;
+
+ frameToSend.can_id = 0x500; /* ID */
+ frameToSend.can_dlc = 3; /* We want to send 3 bytes */
+ frameToSend.data[0] = 0x1E; /* Byte 1 */
+ frameToSend.data[1] = 0x10; /* Byte 2 */
+ frameToSend.data[2] = 0x10; /* Byte 3 */
+
+ while (quit != 1) {
+ frameToSend.data[2] ^= 0x10; /* Invert the output bit of the LED */
+
+ if ((size = write(can_socket, &frameToSend, sizeof(frameToSend))) != sizeof(frameToSend)) {
+ perror("led_flash write");
+ return size;
+ }
+
+ usleep(200000); /* Wait 200ms ... */
+ }
+
+ return EXIT_SUCCESS;
+}
+
+int sw2_get(int can_socket)
+{
+ int size;
+
+ struct can_frame frameToSend;
+ struct can_frame receivedCanFrame;
+
+ frameToSend.can_id = 0x280 | CAN_RTR_FLAG; /* Remote request frame */
+ frameToSend.can_dlc = 8; /* The data received must contains 8 byte of datas */
+
+ while (quit != 1) {
+ /* Send the RTR frame */
+ if ((size = write(can_socket, &frameToSend, sizeof(frameToSend))) != sizeof(frameToSend)) {
+ perror("sw2_get write");
+ return size;
+ }
+
+ /* Read the frame containing the information */
+ if ((size = read(can_socket, &receivedCanFrame, sizeof(receivedCanFrame))) < 0) {
+ perror("sw2_get read");
+ return size;
+ }
+
+
+ if ((receivedCanFrame.data[1] & SW2_MASK) == 1) /* If the SW2 bit is on, */
+ printf("SW2 is released\n"); /* the SW2 switch is released */
+ else
+ printf("SW2 is pushed\n");/* the SW2 switch is pushed */
+
+ /* Wait 1s */
+ sleep(1);
+ }
+
+ return EXIT_SUCCESS;
+}
+
+int led_on(int can_socket)
+{
+ int size;
+
+ struct can_frame frameToSend;
+
+ frameToSend.can_id = 0x500; /* ID */
+ frameToSend.can_dlc = 3; /* We want to send 3 bytes */
+ frameToSend.data[0] = 0x1E; /* Byte 1 */
+ frameToSend.data[1] = 0x10; /* Byte 2 */
+ frameToSend.data[2] = 0x00; /* Byte 3 (bit 4 = 0 to turn the led ON) */
+
+ /* Send the frame */
+ if ((size = write(can_socket, &frameToSend, sizeof(frameToSend))) != sizeof(frameToSend)) {
+ perror("led_on write");
+ return size;
+ }
+
+ return EXIT_SUCCESS;
+}
+
+int led_off(int can_socket)
+{
+ int size;
+
+ struct can_frame frameToSend;
+
+ frameToSend.can_id = 0x500; /* ID */
+ frameToSend.can_dlc = 3; /* We want to send 3 bytes */
+ frameToSend.data[0] = 0x1E; /* Byte 1 */
+ frameToSend.data[1] = 0x10; /* Byte 2 */
+ frameToSend.data[2] = 0x10; /* Byte 3 (bit 4 = 1 to turn the led OFF) */
+
+ /* Send the frame */
+ if ((size = write(can_socket, &frameToSend, sizeof(frameToSend))) != sizeof(frameToSend)) {
+ perror("led_off write");
+ return size;
+ }
+
+ return EXIT_SUCCESS;
+}
+
+int read_config(int can_socket)
+{
+ struct can_frame frameToSend;
+ struct can_frame receivedCanFrame;
+
+ int i,j, size;
+
+ for (i = 0; i < 7; i++) {
+
+ frameToSend.can_id = 0x280 | CAN_RTR_FLAG | i; /* Remote request frame */
+ switch (i) {
+
+ case 1 :
+ frameToSend.can_dlc = 7;
+ break;
+
+ case 2 :
+ frameToSend.can_dlc = 5;
+ break;
+
+ case 3 :
+ frameToSend.can_dlc = 3;
+ break;
+
+ case 4 :
+ frameToSend.can_dlc = 6;
+ break;
+
+ default :
+ frameToSend.can_dlc = 8;
+ }
+
+ /* Send the RTR frame */
+ if ((size = write(can_socket, &frameToSend, sizeof(frameToSend))) != sizeof(frameToSend)) {
+ perror("read_config write");
+ return size;
+ }
+
+ /* Read the frame containing the information */
+ if ((size = read(can_socket, &receivedCanFrame, sizeof(receivedCanFrame))) < 0) {
+ perror("read_config read");
+ return size;
+ }
+
+ printf("ID: 0x%X -> %d byte(s): ", receivedCanFrame.can_id, receivedCanFrame.can_dlc);
+
+ for (j= 0; j<receivedCanFrame.can_dlc; j++)
+ printf("0x%X ",receivedCanFrame.data[j]);
+
+ printf("\n");
+ }
+
+ return EXIT_SUCCESS;
+}
+
+
+
+void display_help()
+{/* Display display_help */
+ printf("#################################\n");
+ printf("# #\n");
+ printf("# Armadeus Systems #\n");
+ printf("# Demo can_mcp25020 #\n");
+ printf("# #\n");
+ printf("#################################\n\n");
+ printf("This sofware is a demonstration. It show how to communicate with a MICROCHIP MCP25020 using the can bus with socketCAN\n\n");
+ printf("USE: can_mcp25020 [TEST]\nTEST are:\n");
+ printf("\tlisten : Listen on the can bus\n");
+ printf("\tled-flash : flash the D6 led (interval: 200ms)\n");
+ printf("\tled-on : turn the D6 led on\n");
+ printf("\tled-off : turn the D6 led off\n");
+ printf("\tsw2-get : get the value of the switch SW2\n");
+ printf("\tCONFIG : get the value of several config registers\n\n");
+ printf("\tMore informations, please contact jol...@gm...\n");
+}
+
+void int_quit(int sig)
+{
+ signal(sig, SIG_IGN); /* Ignore the ctrl+c sequence for the system */
+ printf("Exiting...\n");
+ quit=1;
+}
hooks/post-receive
--
armadeus
|