1 /* Author: Domen Puncer <domen@cba.si>. License: WTFPL, see file LICENSE */
8 #ifdef ARCH_ARM_CORTEX_M3
9 #include <arch/cm3_regs.h>
14 #include <drivers/spi.h>
15 #include <drivers/spi_tmp124.h>
17 #ifdef BOARD_LPCXPRESSO
18 #include <mach/lpc13xx_gpio.h>
19 #include <mach/board_lpcxpresso.h>
20 #define GPIO_CS0 GPIO_2_10
26 static int command_spi(const char *_cmd
)
28 char *cmd
= (char*)_cmd
; /* we don't change it, but strtol is idiotic */
29 static struct spi_device dev
= {
32 .clock
= 10*1000*1000, /* 10 MHz max */
36 if (strncmp(cmd
, "spi ", 4) != 0)
41 if (strncmp(cmd
, "init", 4) == 0) {
42 // TODO hardcoded - how to configure gpio easily? same problem will be with command_gpio
43 spi_register_device(&spi0
, &dev
);
46 if (strncmp(cmd
, "data ", 5) == 0) {
47 struct spi_transfer transfer
;
52 transfer
.tx_buf
= buf
;
53 transfer
.rx_buf
= buf
;
54 len
= strtoul(cmd
, &cmd
, 0);
57 while (cmd
&& idx
< len
) {
58 u8 data
= strtoul(cmd
, &cmd
, 0);
61 /* pad the rest with 0xff */
65 spi_transfer(&dev
, &transfer
);
68 for (idx
= 0; idx
< len
; idx
++)
69 printf(" %02x", buf
[idx
]);
77 static int command_x(const char *_cmd
)
82 char *cmd
= (char*)_cmd
; /* we don't change it, but strtol is idiotic */
84 if (cmd
[0] != 'x' || isalpha(cmd
[1]))
91 len
= strtoul(cmd
, &cmd
, 0);
92 /* just some sanity */
96 // while, check for xs...
100 else if (*cmd
== 'h')
102 else if (*cmd
== 'w')
105 printf("E: invalid argument for size\n");
114 addr
= strtoul(cmd
, NULL
, 0);
117 /* currently it only works for hex, with size 4 */
119 printf("%#010x: ", addr
);
120 for (i
=0; i
<len
; i
++) {
121 if (i
% 8 == 0 && i
) {
122 printf("\n%#010x: ", addr
);
124 printf("%#010x ", *(u32
*)addr
);
132 static int command_boot(const char *cmd
)
134 if (strcmp(cmd
, "boot") != 0)
137 #ifdef ARCH_ARM_CORTEX_M3
138 AIRCR
= (AIRCR
& 0x8700) | 0x05FA<<16 /* magic */ | 1<<2 /* SYSRESETREQ */;
145 static int command_fail(const char *cmd
)
147 volatile u32
*tmp
= (volatile u32
*)0x12345678;
148 void (*f
)() = (void (*)())0x23456789;
150 if (strncmp(cmd
, "fail ", 5) != 0)
155 /* invalid pointer deference */
159 /* invalid pointer deference */
163 /* invalid stack pointer */
164 #ifdef ARCH_ARM_CORTEX_M3
165 asm volatile ("ldr sp, =#0x87654321\n\t");
169 /* undefined instruction */
170 #ifdef ARCH_ARM_CORTEX_M3
171 *(u32
*)0xe000ed24 |= 1<<18; /* enable usage fault */
172 /* http://www.keil.com/support/man/docs/armasm/armasm_cihjijca.htm */
173 asm volatile (".short 0xdead\n\t"); /* arm arm says, 0xdexx for thumb */
174 /* some other document said 1101 011... 1 xxxx for arm mode */
179 #ifdef ARCH_ARM_CORTEX_M3
180 asm volatile ("svc #0\n");
185 printf("%s: unknown argument %c\n", __func__
, cmd
[5]);
186 printf("fail arguments: \n"
187 "\t0 - write to invalid pointer\n"
188 "\t1 - call invalid function\n"
189 "\ts - corrupt stack pointer\n"
190 "\tu - undefined instruction\n"
196 static int command_test(const char *cmd
)
198 if (strncmp(cmd
, "test ", 5) != 0)
201 strncpy(foo
, cmd
+5, 16);
205 printf("%s: %02x %02x %02x %02x\n", __func__
, foo
[0], foo
[1], foo
[2], foo
[3]);
209 static int command_help(const char *cmd
)
211 if (strcmp(cmd
, "help") != 0)
213 printf("something helpful should be written here\n");
216 static int command_invalid(const char *cmd
)
219 printf("invalid command\n");
223 /* 1 for handled, 0 for not handled, negative for error (should abort handling) */
224 int (* const command_list
[])(const char *cmd
) = {