From 979126421ca3b2a70bf88deb578a77d132c96c24 Mon Sep 17 00:00:00 2001 From: Martin Rakovec Date: Thu, 2 Jul 2009 16:01:27 +0200 Subject: [PATCH] Software testing lpcanvca.h --- app/lpcanvcaTest/Makefile | 14 ++++++ app/lpcanvcaTest/Makefile.omk | 7 +++ app/lpcanvcaTest/led.c | 35 +++++++++++++ app/lpcanvcaTest/led.h | 20 ++++++++ app/lpcanvcaTest/lpcanvcaTest.c | 107 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 183 insertions(+) create mode 100644 app/lpcanvcaTest/Makefile create mode 100644 app/lpcanvcaTest/Makefile.omk create mode 100644 app/lpcanvcaTest/led.c create mode 100644 app/lpcanvcaTest/led.h create mode 100644 app/lpcanvcaTest/lpcanvcaTest.c diff --git a/app/lpcanvcaTest/Makefile b/app/lpcanvcaTest/Makefile new file mode 100644 index 0000000..08cf5ff --- /dev/null +++ b/app/lpcanvcaTest/Makefile @@ -0,0 +1,14 @@ +# Generic directory or leaf node makefile for OCERA make framework + +ifndef MAKERULES_DIR +MAKERULES_DIR := $(shell ( old_pwd="" ; while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd` ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) ) +endif + +ifeq ($(MAKERULES_DIR),) +all : default +.DEFAULT:: + @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n" +else +include $(MAKERULES_DIR)/Makefile.rules +endif + diff --git a/app/lpcanvcaTest/Makefile.omk b/app/lpcanvcaTest/Makefile.omk new file mode 100644 index 0000000..07e1b4b --- /dev/null +++ b/app/lpcanvcaTest/Makefile.omk @@ -0,0 +1,7 @@ +bin_PROGRAMS = lpcanvcaTest + +lpcanvcaTest_SOURCES = lpcanvcaTest.c led.c + +lpcanvcaTest_LIBS = lpcanvca lpcan + + diff --git a/app/lpcanvcaTest/led.c b/app/lpcanvcaTest/led.c new file mode 100644 index 0000000..fb6c228 --- /dev/null +++ b/app/lpcanvcaTest/led.c @@ -0,0 +1,35 @@ +#include "led.h" + +struct { + volatile uint32_t *ioset, *ioclr, bit; +} led_ctl[] = { + {(uint32_t*)&IOSET0, (uint32_t*)&IOCLR0, 1<<22}, + {(uint32_t*)&IOSET0, (uint32_t*)&IOCLR0, 1<<23}, + {(uint32_t*)&IOSET0, (uint32_t*)&IOCLR0, 1<<24}, + {(uint32_t*)&IOSET1, (uint32_t*)&IOCLR1, 1<<19} +}; + +void led_init() { + PINSEL1 &= ~0x0003f000; + PINSEL2 &= ~0x00000008; + IODIR0 |= 0x01c00000; + IODIR1 |= 0x00040000; + IOCLR0 = 0x01c00000; + IOCLR1 = 0x00040000; +} + +void led_set(uint8_t led, uint8_t state) { + if (state) + *led_ctl[led].ioset = led_ctl[led].bit; + else + *led_ctl[led].ioclr = led_ctl[led].bit; +} + +void led_toggle(uint8_t led) { + if ((*led_ctl[led].ioset) & led_ctl[led].bit) + *led_ctl[led].ioclr = led_ctl[led].bit; + else + *led_ctl[led].ioset = led_ctl[led].bit; +} + +/* Tot vse. */ diff --git a/app/lpcanvcaTest/led.h b/app/lpcanvcaTest/led.h new file mode 100644 index 0000000..167a4a4 --- /dev/null +++ b/app/lpcanvcaTest/led.h @@ -0,0 +1,20 @@ +#include +#include + +#define LED_PINSEL PINSEL1 +#define LED_PINSEL_VAL 0xffff3fff; +#define LED_IODIR IODIR0 +#define LED_IOSET IOSET0 +#define LED_IOCLR IOCLR0 +#define LED_IOBIT 0x00800000 + +#define LED_RED 0 +#define LED_YEL 1 +#define LED_GRN 2 +#define LED_BLU 3 + +void led_init(); +void led_set(uint8_t led, uint8_t state); +void led_toggle(uint8_t led); + +/* .oOo. */ diff --git a/app/lpcanvcaTest/lpcanvcaTest.c b/app/lpcanvcaTest/lpcanvcaTest.c new file mode 100644 index 0000000..484c30d --- /dev/null +++ b/app/lpcanvcaTest/lpcanvcaTest.c @@ -0,0 +1,107 @@ +////////////////////////////////////////////////// +/* test lpcanvca smer pc => lpc */ +/* program pro spejblarm desku */ +/* */ +/* Autor: Martin Rakovec */ +/* E-mail: martin.rakovec@tiscali.cz */ +////////////////////////////////////////////////// + +/* LPC21xx definitions */ +#include +/* CAN definitions*/ +#include +#include +#include +#include "led.h" + +#define CFG_MSG_ID 0x4CC +#define LPC_ID 0x4AB +#define PC_ID 0x4BA +#define START_MSG_DATA 0xAB +#define STOP_MSG_DATA 0xBA +#define ACK_MSG_DATA 0xAA + +/** + * Main function + */ +int main (void) { + VICIntEnClr = 0xFFFFFFFF; + VICIntSelect = 0x00000000; + + VPBDIV = 1; + + led_init(); + led_set(LED_GRN,1); + + /* CAN bus setup */ + uint32_t btr; + vca_handle_t can; + + canmsg_t sendmsg = {.flags = 0, .length = 1}; + canmsg_t readmsg; + + lpcan_btr(&btr, 1000000 /*Bd*/, 10000000, 0/*SJW*/, 70/*%sampl.pt.*/, 0/*SAM*/); + lpc_vca_open_handle(&can, 0/*device*/, 0/*flags*/, btr, 10, 11, 12); + + uint8_t count = 0; + while(1){ + /* if nothig is recieved, continue*/ + if(vca_rec_msg_seq(can,&readmsg,1)<0) continue; + switch(readmsg.id){ + case CFG_MSG_ID: + switch(readmsg.data[0]){ + case START_MSG_DATA: + //set sendmsg.id and data(counter) at 0 + sendmsg.id = LPC_ID+1; + count = 0; + led_set(LED_RED,0); + led_set(LED_YEL,0); + break; + case STOP_MSG_DATA: + //send msg(counter) + sendmsg.data[0] = count; + vca_send_msg_seq(can,&sendmsg,1); + led_set(LED_RED,1); + break; + case ACK_MSG_DATA: + //set sendmsg.id and data + sendmsg.id = LPC_ID; + sendmsg.data[0] = 0; + //send 1000 messages + int s = 1; + int i = 0; + while(i < 1000){ + vca_send_msg_seq(can,&sendmsg,1); + if(sendmsg.data[0] == 0xFF) s = -1; + if(sendmsg.data[0] == 0x00) s = 1; + sendmsg.data[0] += s; + i++; + } + //send stop message + sendmsg.id = CFG_MSG_ID; + sendmsg.data[0] = STOP_MSG_DATA; + + vca_send_msg_seq(can,&sendmsg,1); + vca_send_msg_seq(can,&sendmsg,1); + vca_send_msg_seq(can,&sendmsg,1); + vca_send_msg_seq(can,&sendmsg,1); + vca_send_msg_seq(can,&sendmsg,1); + + led_set(LED_YEL,1); + break; + default: + break; + } + break; + case PC_ID: + //increment counter + count++; + break; + default: + break; + } + } +} + + + -- 2.11.4.GIT