diff --git a/platform/stepper-robot/Makefile b/platform/stepper-robot/Makefile index 09972d548..47aa4ffe1 100644 --- a/platform/stepper-robot/Makefile +++ b/platform/stepper-robot/Makefile @@ -1,45 +1,23 @@ -CONTIKI=../.. - TARGET=stepper-robot -CONTIKI_TARGET_DIRS=stepper +all: core -KERNELS= sys-tst.elf robot-main-syms.elf +core: + $(MAKE) core.$(TARGET) -# Master clock frequency -MCK=23961600 +CONTIKI=../.. -ARCH=debug-uart.o clock.o sys-interrupt.o interrupt-utils.o newlib-syscalls.o \ -leds-arch.o sam7s-spi.o - -SYSTEM=process.o procinit.o service.o clock.o etimer.o timer.o leds.o uip-log.o cfs.o -DEBUG_IO=dbg-printf.o dbg-puts.o dbg-putchar.o strformat.o - -UIP=uip.o uiplib.o tcpip.o uip-fw.o uip-fw-service.o uipbuf.o \ - tcpdump.o psock.o uaodv.o uaodv-rt.o uip-udp-packet.o - -UIPDRIVERS= cc2420.o cc2420_send_ip.o cc2420_send_uaodv.o cc2420-interrupt.o \ -cc2420-spi.o - -SYSLIB=memb.o list.o malloc.o realloc.o - -STEPPER=stepper-interrupt.o stepper-move.o stepper.o - -ELFLOADER=elfloader-arm.o elfloader-otf.o symtab.o -CODEPROP=$(ELFLOADER) cfs-ram.o codeprop-otf.o ram-segments.o \ -autostart.o random.o - -CFLAGS+= -I stepper - -cfs-ram.o: CFLAGS+= -DCFS_RAM_CONF_SIZE=4096 - -all: $(KERNELS) codeprop - -sys-tst.elf: sys-tst.o $(ARCH) $(SYSTEM) - -robot-main-syms.elf: robot-main.o stepper-process.o $(ARCH) $(SYSTEM) $(SYSLIB) $(UIP) $(UIPDRIVERS) $(STEPPER) $(CODEPROP) $(DEBUG_IO) +CORE=core-nosyms.$(TARGET) codeprop: $(CONTIKI)/tools/codeprop.c cc -g -Wall $< -o $@ -include $(CONTIKI)/cpu/at91sam7s/Makefile.at91sam7s +clean: stepper_robot_clean + +.PHONY: stepper_robot_clean + +stepper_robot_clean: + -rm codeprop + +include $(CONTIKI)/Makefile.include + diff --git a/platform/stepper-robot/cc2420-interrupt.c b/platform/stepper-robot/cc2420-interrupt.c index 68ba56d7a..906c28a37 100644 --- a/platform/stepper-robot/cc2420-interrupt.c +++ b/platform/stepper-robot/cc2420-interrupt.c @@ -26,6 +26,8 @@ cc2420_interrupt_fifop_int_init(void) /* *AT91C_AIC_IECR = (1 << AT91C_ID_IRQ1); */ } +#ifndef __MAKING_DEPS__ + inline int splhigh(void) { int save; @@ -45,3 +47,5 @@ inline void splx(int saved) #error Must be compiled in ARM mode #endif } + +#endif /* __MAKING_DEPS__ */ diff --git a/platform/stepper-robot/contiki-conf.h b/platform/stepper-robot/contiki-conf.h index 10b045a80..87ce334ed 100644 --- a/platform/stepper-robot/contiki-conf.h +++ b/platform/stepper-robot/contiki-conf.h @@ -16,6 +16,9 @@ typedef uint8_t u8_t; typedef uint16_t u16_t; typedef uint32_t u32_t; +typedef int8_t s8_t; +typedef int16_t s16_t; +typedef int32_t s32_t; typedef unsigned int clock_time_t; typedef unsigned int uip_stats_t; @@ -39,6 +42,7 @@ typedef unsigned int uip_stats_t; #define VREG_IS_1 1 /* Hardwired */ #define FIFOP_IS_1 (*AT91C_PIOA_PDSR & AT91C_PIO_PA30) #define SFD_IS_1 (*AT91C_PIOA_PDSR & AT91C_PIO_PA15) +#define CCA_IS_1 1 #define SET_RESET_INACTIVE() cc2420_setreg(CC2420_MAIN, 0xf800); #define SET_RESET_ACTIVE() cc2420_setreg(CC2420_MAIN, 0x0000); diff --git a/platform/stepper-robot/contiki-main.c b/platform/stepper-robot/contiki-main.c new file mode 100644 index 000000000..71890059c --- /dev/null +++ b/platform/stepper-robot/contiki-main.c @@ -0,0 +1,97 @@ +#include +#include +#include +#include +#include +#include +#include +#include "net/uip-fw-drv.h" +#include "net/uaodv.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#ifndef RF_CHANNEL +#define RF_CHANNEL 15 +#endif + +extern char __heap_end__; +extern char __heap_start__; + +struct uip_fw_netif cc2420if = + {UIP_FW_NETIF(172,16,0,2, 255,255,0,0, cc2420_send_ip)}; + +#if 0 +/* Wathcdog is already disabled in startup code */ +static void +wdt_setup() +{ + +} +#endif + +static void +wdt_reset() +{ + *AT91C_WDTC_WDCR = (0xa5<<24) | AT91C_WDTC_WDRSTT; +} + +#if 0 +static uip_ipaddr_t gw_addr = {{172,16,0,1}}; +#endif + +PROCINIT(&etimer_process, &tcpip_process, &cc2420_process, + &uip_fw_process /*, &uaodv_process */ + ); + + +int +main() +{ + disableIRQ(); + disableFIQ(); + *AT91C_AIC_IDCR = 0xffffffff; + *AT91C_PMC_PCDR = 0xffffffff; + *AT91C_PMC_PCER = (1 << AT91C_ID_PIOA); + + dbg_setup_uart(); + printf("Initialising\n"); + leds_arch_init(); + clock_init(); + uip_sethostaddr(&cc2420if.ipaddr); + uip_setnetmask(&cc2420if.netmask); + + /*uip_setdraddr(&gw_addr);*/ + cc2420_init(); + cc2420_set_chan_pan_addr(RF_CHANNEL, HTONS(0x2024), uip_hostaddr.u16[1], NULL); + process_init(); + uip_init(); + uip_fw_default(&cc2420if); + tcpip_set_forwarding(1); + printf("Heap size: %ld bytes\n", &__heap_end__ - (char*)sbrk(0)); + printf("Started\n"); + + procinit_init(); + enableIRQ(); + cc2420_on(); + autostart_start(autostart_processes); + printf("Processes running\n"); + while(1) { + do { + /* Reset watchdog. */ + wdt_reset(); + } while(process_run() > 0); + /* Idle! */ + /* Stop processor clock */ + *AT91C_PMC_SCDR |= AT91C_PMC_PCK; + } + return 0; +} diff --git a/platform/stepper-robot/core.c b/platform/stepper-robot/core.c new file mode 100644 index 000000000..0ac8437a8 --- /dev/null +++ b/platform/stepper-robot/core.c @@ -0,0 +1,27 @@ +#include +#include +#include +#include +#include +#include "codeprop-otf.h" +#include +#include + +PROCESS(blink_process, "LED blink process"); + +PROCESS_THREAD(blink_process, ev , data) +{ + static struct etimer timer; + PROCESS_BEGIN(); + etimer_set(&timer, CLOCK_SECOND/2); + while(1) { + PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_EXIT || + ev== PROCESS_EVENT_TIMER); + if (ev == PROCESS_EVENT_EXIT) break; + leds_invert(LEDS_RED); + etimer_reset(&timer); + } + PROCESS_END(); +} + +AUTOSTART_PROCESSES(&codeprop_process, &ram_segments_cleanup_process, &stepper_process,&blink_process); diff --git a/platform/stepper-robot/robot-main.c b/platform/stepper-robot/robot-main.c index 5f3beaebb..577f9d341 100644 --- a/platform/stepper-robot/robot-main.c +++ b/platform/stepper-robot/robot-main.c @@ -10,17 +10,19 @@ #include #include #include +#include #include #include +#include #include #include -#include -#include -#include -#include -#include #include +#include +#include +#include + + #ifndef RF_CHANNEL #define RF_CHANNEL 15 #endif @@ -29,37 +31,44 @@ extern char __heap_end__; extern char __heap_start__; -PROCESS(blink_process, "LED blink process"); +static const uint32_t stepper0_steps_acc[] = MICRO_STEP(0,3); +static const uint32_t stepper0_steps_run[] = MICRO_STEP(0,2); +static const uint32_t stepper0_steps_hold[] = MICRO_STEP(0,1); + +static const uint32_t stepper1_steps_acc[] = MICRO_STEP(1,3); +static const uint32_t stepper1_steps_run[] = MICRO_STEP(1,2); +static const uint32_t stepper1_steps_hold[] = MICRO_STEP(1,1); + +static StepperAccSeq seq_heap[40]; + +static void +init_seq_heap() +{ + unsigned int i; + for(i = 0; i < sizeof(seq_heap)/sizeof(seq_heap[0]); i++) { + seq_heap[i].next = NULL; + stepper_free_seq(&seq_heap[i]); + } +} + +static void +robot_stepper_init() +{ + init_seq_heap(); + stepper_init(AT91C_BASE_TC0, AT91C_ID_TC0); + *AT91C_PIOA_OER = STEPPER_INHIBIT; + *AT91C_PIOA_MDER = STEPPER_INHIBIT; /* | STEPPER0_IOMASK; */ + *AT91C_PIOA_CODR = STEPPER_INHIBIT; + stepper_init_io(1, STEPPER_IOMASK(0), stepper0_steps_acc, + stepper0_steps_run, stepper0_steps_hold, + (sizeof(stepper0_steps_run) / sizeof(stepper0_steps_run[0]))); + stepper_init_io(0, STEPPER_IOMASK(1), stepper1_steps_acc, + stepper1_steps_run, stepper1_steps_hold, + (sizeof(stepper1_steps_run) / sizeof(stepper1_steps_run[0])));} struct uip_fw_netif cc2420if = {UIP_FW_NETIF(172,16,0,2, 255,255,0,0, cc2420_send_ip)}; -PROCESS_THREAD(blink_process, ev , data) -{ - static struct etimer timer; - PROCESS_BEGIN(); - etimer_set(&timer, CLOCK_SECOND/2); - while(1) { - PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_EXIT || - ev== PROCESS_EVENT_TIMER); - if (ev == PROCESS_EVENT_EXIT) break; - leds_invert(LEDS_RED); -#if 0 - { - DISABLE_FIFOP_INT(); - printf("FSMSTATE: %04x",cc2420_getreg(CC2420_FSMSTATE)); - ENABLE_FIFOP_INT(); - if (SFD_IS_1) printf(" SFD"); - if (FIFO_IS_1) printf(" FIFO"); - if (FIFOP_IS_1) printf(" FIFOP"); - putchar('\n'); - } -#endif - etimer_reset(&timer); - } - printf("Ended process\n"); - PROCESS_END(); -} #if 0 PROCESS(udprecv_process, "UDP recv process"); @@ -136,13 +145,13 @@ wdt_reset() *AT91C_WDTC_WDCR = (0xa5<<24) | AT91C_WDTC_WDRSTT; } +#if 0 static uip_ipaddr_t gw_addr = {{172,16,0,1}}; +#endif - -PROCINIT(&etimer_process, &tcpip_process, &uip_fw_process, &cc2420_process, - /* &uaodv_process, */ &cfs_ram_process, &codeprop_process, - &ram_segments_cleanup_process, - &blink_process, &stepper_process); +PROCINIT(&etimer_process, &tcpip_process, &cc2420_process, + &uip_fw_process /*, &uaodv_process */ + ); int @@ -156,7 +165,7 @@ main() dbg_setup_uart(); printf("Initialising\n"); - leds_arch_init(); + leds_arch_init(); clock_init(); uip_sethostaddr(&cc2420if.ipaddr); uip_setnetmask(&cc2420if.netmask); @@ -170,10 +179,12 @@ main() tcpip_set_forwarding(1); printf("Heap size: %ld bytes\n", &__heap_end__ - (char*)sbrk(0)); printf("Started\n"); - + + robot_stepper_init(); procinit_init(); enableIRQ(); cc2420_on(); + autostart_start(autostart_processes); printf("Processes running\n"); while(1) { do { diff --git a/platform/stepper-robot/stepper-process.c b/platform/stepper-robot/stepper-process.c index d2aeb57f3..e47cd01af 100644 --- a/platform/stepper-robot/stepper-process.c +++ b/platform/stepper-robot/stepper-process.c @@ -9,27 +9,9 @@ #include #include + #undef putchar -static const uint32_t stepper0_steps_acc[] = MICRO_STEP(0,3); -static const uint32_t stepper0_steps_run[] = MICRO_STEP(0,2); -static const uint32_t stepper0_steps_hold[] = MICRO_STEP(0,1); - -static const uint32_t stepper1_steps_acc[] = MICRO_STEP(1,3); -static const uint32_t stepper1_steps_run[] = MICRO_STEP(1,2); -static const uint32_t stepper1_steps_hold[] = MICRO_STEP(1,1); - -static StepperAccSeq seq_heap[40]; - -static void -init_seq_heap() -{ - unsigned int i; - for(i = 0; i < sizeof(seq_heap)/sizeof(seq_heap[0]); i++) { - seq_heap[i].next = NULL; - stepper_free_seq(&seq_heap[i]); - } -} static unsigned int parse_uint_hex(const char **pp, const char *end) @@ -189,6 +171,7 @@ static int handle_line(const char *input_line, const char *inend, ReplyBuffer *reply) { unsigned long when; +#if 0 { const char *p = input_line; printf("Got line: '"); @@ -198,6 +181,7 @@ handle_line(const char *input_line, const char *inend, ReplyBuffer *reply) printf("'\n"); fsync(1); } +#endif skip_white(&input_line, inend); CHECK_INPUT_LEFT(1); if (*input_line == '#') { @@ -226,8 +210,8 @@ handle_line(const char *input_line, const char *inend, ReplyBuffer *reply) int speed; input_line++; if (input_line == inend) { - printf("Speed: %ld\n", - stepper_current_velocity(stepper_index)/VEL_SCALE); + /* printf("Speed: %ld\n", + stepper_current_velocity(stepper_index)/VEL_SCALE);*/ reply_char(reply, input_line[-2]); reply_char(reply, 'S'); format_int_hex(&reply->write, REPLY_BUFFER_END(reply), @@ -240,7 +224,7 @@ handle_line(const char *input_line, const char *inend, ReplyBuffer *reply) unsigned int acc; input_line++; acc = parse_uint_hex(&input_line, inend); - printf("Speed=%d, Acc=%u\n", speed, acc); + /* printf("Speed=%d, Acc=%u\n", speed, acc); */ res = stepper_set_velocity(stepper_index, &when, acc, speed*VEL_SCALE); @@ -269,7 +253,7 @@ handle_line(const char *input_line, const char *inend, ReplyBuffer *reply) StepperResult res; input_line++; move = parse_int_hex(&input_line, inend); - printf("Speed=%u, Acc=%u, Move=%d\n", speed, acc, move); + /*printf("Speed=%u, Acc=%u, Move=%d\n", speed, acc, move);*/ res = stepper_move(stepper_index, &when, acc,speed*VEL_SCALE,move*DIST_SCALE); stepper_reply(reply, res); @@ -283,11 +267,11 @@ handle_line(const char *input_line, const char *inend, ReplyBuffer *reply) reply_str(reply, "ERR\n"); } } else if (input_line[0] == 'E') { - *AT91C_PIOA_SODR = STEPPER_INHIBIT; + STEPPER_ENABLE(); printf("Stepper enabled\n"); reply_str(reply, "OK\n"); } else if (input_line[0] == 'D') { - *AT91C_PIOA_CODR = STEPPER_INHIBIT; + STEPPER_DISABLE(); printf("Stepper disabled\n"); reply_str(reply, "OK\n"); } else if (input_line[0] == 'p') { @@ -354,7 +338,7 @@ handle_connection() if (uip_newdata()) { const char *read_pos = uip_appdata; const char *read_end = read_pos + uip_len; - printf("Got data\n"); + /* printf("Got data\n"); */ while(read_pos < read_end) { if (line_end == line_buffer+sizeof(line_buffer)) { /* Buffer too small, just discard everything */ @@ -440,7 +424,7 @@ PROCESS_THREAD(udp_stepper_process, ev, data) } else if (uip_poll()) { if (data == &conn) { uip_send(udp_reply.buffer, udp_reply.write - udp_reply.buffer); - printf("sent %ld\n", udp_reply.write - udp_reply.buffer); + /* printf("sent %ld\n", udp_reply.write - udp_reply.buffer); */ } } } else if (ev == PROCESS_EVENT_TIMER) { @@ -466,24 +450,14 @@ PROCESS_THREAD(stepper_process, ev, data) PROCESS_EXITHANDLER(goto exit); PROCESS_BEGIN(); tcp_listen(HTONS(1010)); - init_seq_heap(); - stepper_init(AT91C_BASE_TC0, AT91C_ID_TC0); - *AT91C_PIOA_OER = STEPPER_INHIBIT; - *AT91C_PIOA_MDER = STEPPER_INHIBIT; /* | STEPPER0_IOMASK; */ - *AT91C_PIOA_CODR = STEPPER_INHIBIT; - stepper_init_io(1, STEPPER_IOMASK(0), stepper0_steps_acc, - stepper0_steps_run, stepper0_steps_hold, - (sizeof(stepper0_steps_run) / sizeof(stepper0_steps_run[0]))); - stepper_init_io(0, STEPPER_IOMASK(1), stepper1_steps_acc, - stepper1_steps_run, stepper1_steps_hold, - (sizeof(stepper1_steps_run) / sizeof(stepper1_steps_run[0]))); + process_start(&udp_stepper_process, NULL); printf("Stepper starting\n"); while(1) { PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); if(uip_connected()) { - printf("connected\n"); + /* printf("connected\n"); */ handle_connection(); /* Initialise parser */ while(!(uip_aborted() || uip_closed() || uip_timedout())) { PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); diff --git a/platform/stepper-robot/stepper/stepper-steps.h b/platform/stepper-robot/stepper/stepper-steps.h index 7ff13b42d..35f778454 100644 --- a/platform/stepper-robot/stepper/stepper-steps.h +++ b/platform/stepper-robot/stepper/stepper-steps.h @@ -98,3 +98,6 @@ STEPPER_STEP(s,-(l),(l)), \ STEPPER_STEP(s,-MIN((l),2),(l)), \ STEPPER_STEP(s,-1,(l))} + +#define STEPPER_ENABLE() (*AT91C_PIOA_SODR = STEPPER_INHIBIT) +#define STEPPER_DISABLE() (*AT91C_PIOA_CODR = STEPPER_INHIBIT)