[Armadeus-commitlog] armadeus branch, master, updated. release-3.4-56-g54a6154
Brought to you by:
sszy
|
From: Fabien M <fa...@us...> - 2011-04-15 12:19:52
|
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 54a615476b3df9e8b0161ceb3d94f5e2a2d8a5c8 (commit)
from 181b8e9668b40f1529871dc562aa2e815fba975e (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 54a615476b3df9e8b0161ceb3d94f5e2a2d8a5c8
Author: Kevin JOLY <jol...@gm...>
Date: Fri Apr 15 13:46:35 2011 +0200
Update demo can_mcp25020
Signed-off-by: Kevin JOLY <jol...@gm...>
Signed-off-by: Fabien Marteau <fab...@ar...>
-----------------------------------------------------------------------
Summary of changes:
buildroot/package/armadeus/demos/Config.in | 9 +-
target/demos/mcp25020_ctrl/Makefile | 15 ++-
target/demos/mcp25020_ctrl/mcp25020_ctrl.c | 149 +++++++++++++---------------
3 files changed, 81 insertions(+), 92 deletions(-)
diff --git a/buildroot/package/armadeus/demos/Config.in b/buildroot/package/armadeus/demos/Config.in
index bd12889..f4d4d2f 100644
--- a/buildroot/package/armadeus/demos/Config.in
+++ b/buildroot/package/armadeus/demos/Config.in
@@ -1,4 +1,3 @@
-
config BR2_PACKAGE_ARMADEUS_DEMOS
bool "Armadeus misc demos"
default n
@@ -67,12 +66,12 @@ config BR2_PACKAGE_ARMADEUS_DEMOS_TEST_LCD
config BR2_PACKAGE_ARMADEUS_DEMOS_MCP25020
bool "DEMOS_MCP25020"
- depends on BR2_PACKAGE_SOCKETCAN
+ depends on BR2_PACKAGE_IPROUTE2
help
Test for CAN bus communication with MCP25020.
- Requires socket CAN.
+ Requires package iproute2.
-comment "DEMOS_MCP25020 requires socket CAN"
- depends on !BR2_PACKAGE_SOCKETCAN
+comment "DEMOS_MCP25020 requires package iproute2"
+ depends on !BR2_PACKAGE_IPROUTE2
endmenu
diff --git a/target/demos/mcp25020_ctrl/Makefile b/target/demos/mcp25020_ctrl/Makefile
index a338327..10882e3 100644
--- a/target/demos/mcp25020_ctrl/Makefile
+++ b/target/demos/mcp25020_ctrl/Makefile
@@ -11,21 +11,26 @@ STRIP:=$(ARMADEUS_TOOLCHAIN_PATH)arm-linux-sstrip
DEFINES=TARGET
CFLAGS= -Wall
-default: mcp25020_ctrl
+EXEC=mcp25020_ctrl
-all: mcp25020_ctrl
+default: $(EXEC)
+
+all: $(EXEC)
mcp25020_ctrl.o: mcp25020_ctrl.c
$(CC) $(CFLAGS) -c -o $@ $^
-install: mcp25020_ctrl
+$(EXEC): mcp25020_ctrl.o
+ $(CC) $(LDFLAGS) -o $@ $^
+
+install: $(EXEC)
mkdir -p $(INSTALL_DIR)
cp $^ $(INSTALL_DIR)
cp init_can.sh $(INIT_DIR)/S50init_can.sh
- $(STRIP) $(INSTALL_DIR)/mcp25020_ctrl
+ $(STRIP) $(INSTALL_DIR)/$^
uninstall:
- rm -f $(INSTALL_DIR)/mcp25020_ctrl
+ rm -f $(INSTALL_DIR)/$(EXEC)
rm -f $(INIT_DIR)/S50init_can.sh
clean:
diff --git a/target/demos/mcp25020_ctrl/mcp25020_ctrl.c b/target/demos/mcp25020_ctrl/mcp25020_ctrl.c
index 929f03c..fb964a3 100644
--- a/target/demos/mcp25020_ctrl/mcp25020_ctrl.c
+++ b/target/demos/mcp25020_ctrl/mcp25020_ctrl.c
@@ -22,13 +22,14 @@
#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);
+#define LED_OFF 0x10
+#define LED_ON 0x00
+
+void listen_mode(int can_socket);
+void led_flash(int can_socket, int interval);
+void set_led_state(int can_socket, int state);
+void sw2_get(int can_socket);
+void read_config(int can_socket);
void display_help();
void int_quit(int sig);
@@ -41,7 +42,7 @@ int main(int argc, char **argv)
struct sockaddr_can addr;
int can_socket;
- quit=0;
+ quit = 0;
signal(SIGINT, int_quit); /* Capture the ctrl+C sequence */
/* If no arguments is given */
@@ -75,11 +76,34 @@ int main(int argc, char **argv)
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 */
+
+ if (argc < 3) {
+ printf("led-flash : Please specify the flashing interval in ms (1 to 10000)\n");
+ return EXIT_SUCCESS;
+ }
+
+ if ((atoi(argv[2]) < 1) || (atoi(argv[2]) > 10000)) {
+ printf("led-flash : Please specify the flashing interval in ms (1 to 10000)\n");
+ return EXIT_SUCCESS;
+ }
+
+ led_flash(can_socket, atoi(argv[2]));/* Entering in led flashing mode */
+ } else if(strcmp(argv[1], "led-state") == 0) {
+
+ if (argc < 3) {
+ printf("led-state : Please specify ON or OFF\n");
+ return EXIT_SUCCESS;
+ }
+
+ if (strcmp(argv[2], "ON") == 0) {
+ set_led_state(can_socket, LED_ON);
+ } else if (strcmp(argv[2], "OFF") == 0) {
+ set_led_state(can_socket, LED_OFF);
+ } else {
+ printf("led-state : Please specify ON or OFF\n");
+ return EXIT_SUCCESS;
+ }
+
} 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) {
@@ -93,16 +117,16 @@ int main(int argc, char **argv)
return EXIT_SUCCESS;
}
-int listen_mode(int can_socket)
+void listen_mode(int can_socket)
{
struct can_frame receivedCanFrame;
- int i, size;
+ int i;
while (quit != 1) {
/* Read the data received by the interface */
- if ((size = read(can_socket, &receivedCanFrame, sizeof(receivedCanFrame))) < 0) {
+ if (read(can_socket, &receivedCanFrame, sizeof(receivedCanFrame)) < 0) {
perror("read");
- return size;
+ return;
}
if (receivedCanFrame.can_id & CAN_RTR_FLAG) {/* If the last data received was a remote request frame */
@@ -116,14 +140,10 @@ int listen_mode(int can_socket)
}
printf("\n");
}
-
- return EXIT_SUCCESS;
}
-int led_flash(int can_socket)
+void led_flash(int can_socket, int interval)
{
- int size;
-
struct can_frame frameToSend;
frameToSend.can_id = 0x500; /* ID */
@@ -135,21 +155,17 @@ int led_flash(int can_socket)
while (quit != 1) {
frameToSend.data[2] ^= 0x10; /* Invert the output bit of the LED */
- if ((size = write(can_socket, &frameToSend, sizeof(frameToSend))) != sizeof(frameToSend)) {
+ if (write(can_socket, &frameToSend, sizeof(frameToSend)) != sizeof(frameToSend)) {
perror("led_flash write");
- return size;
+ return;
}
- usleep(200000); /* Wait 200ms ... */
+ usleep(interval * 1000); /* Wait... */
}
-
- return EXIT_SUCCESS;
}
-int sw2_get(int can_socket)
+void sw2_get(int can_socket)
{
- int size;
-
struct can_frame frameToSend;
struct can_frame receivedCanFrame;
@@ -158,78 +174,49 @@ int sw2_get(int can_socket)
while (quit != 1) {
/* Send the RTR frame */
- if ((size = write(can_socket, &frameToSend, sizeof(frameToSend))) != sizeof(frameToSend)) {
+ if (write(can_socket, &frameToSend, sizeof(frameToSend)) != sizeof(frameToSend)) {
perror("sw2_get write");
- return size;
+ return;
}
/* Read the frame containing the information */
- if ((size = read(can_socket, &receivedCanFrame, sizeof(receivedCanFrame))) < 0) {
+ if (read(can_socket, &receivedCanFrame, sizeof(receivedCanFrame)) < 0) {
perror("sw2_get read");
- return size;
+ return;
}
-
- if ((receivedCanFrame.data[1] & SW2_MASK) == 1) /* If the SW2 bit is on, */
- printf("SW2 is released\n"); /* the SW2 switch is released */
+ if ((receivedCanFrame.data[1] & SW2_MASK) == 1) /* If the SW2 bit is on */
+ printf("SW2 is released\n");
else
- printf("SW2 is pushed\n");/* the SW2 switch is pushed */
+ printf("SW2 is pushed\n");
- /* Wait 1s */
sleep(1);
}
-
- return EXIT_SUCCESS;
}
-int led_on(int can_socket)
+void set_led_state(int can_socket, int state)
{
- 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) */
+ frameToSend.data[2] = state; /* Byte 3 (bit 4 = 0 to turn the led ON) */
/* Send the frame */
- if ((size = write(can_socket, &frameToSend, sizeof(frameToSend))) != sizeof(frameToSend)) {
+ if (write(can_socket, &frameToSend, sizeof(frameToSend)) != sizeof(frameToSend)) {
perror("led_on write");
- return size;
+ return;
}
-
- 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)
+void read_config(int can_socket)
{
struct can_frame frameToSend;
struct can_frame receivedCanFrame;
- int i,j, size;
+ int i,j;
for (i = 0; i < 7; i++) {
@@ -257,15 +244,15 @@ int read_config(int can_socket)
}
/* Send the RTR frame */
- if ((size = write(can_socket, &frameToSend, sizeof(frameToSend))) != sizeof(frameToSend)) {
+ if (write(can_socket, &frameToSend, sizeof(frameToSend)) != sizeof(frameToSend)) {
perror("read_config write");
- return size;
+ return;
}
/* Read the frame containing the information */
- if ((size = read(can_socket, &receivedCanFrame, sizeof(receivedCanFrame))) < 0) {
+ if (read(can_socket, &receivedCanFrame, sizeof(receivedCanFrame)) < 0) {
perror("read_config read");
- return size;
+ return;
}
printf("ID: 0x%X -> %d byte(s): ", receivedCanFrame.can_id, receivedCanFrame.can_dlc);
@@ -275,8 +262,6 @@ int read_config(int can_socket)
printf("\n");
}
-
- return EXIT_SUCCESS;
}
@@ -292,9 +277,8 @@ void display_help()
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("\tled-flash [INTERVAL]: flash the D6 led. You must specify the flashing interval in ms (1 to 10000 ms)\n");
+ printf("\tled-state [ON | OFF]: turn the D6 led on the specified state (ON or 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");
@@ -304,5 +288,6 @@ void int_quit(int sig)
{
signal(sig, SIG_IGN); /* Ignore the ctrl+c sequence for the system */
printf("Exiting...\n");
- quit=1;
+ quit = 1;
}
+
hooks/post-receive
--
armadeus
|