Contiki 2.5
sys-tst.c
1 #include <AT91SAM7S64.h>
2 #include <stdio.h>
3 #include <sys/process.h>
4 #include <sys/procinit.h>
5 #include <sys/etimer.h>
6 #include <dev/leds.h>
7 #include <debug-uart.h>
8 #include <interrupt-utils.h>
9 
10 volatile const char * volatile input_line = NULL;
11 volatile unsigned int input_line_len = 0;
12 
13 static void
14 recv_input(const char *str, unsigned int len)
15 {
16  /* Assume that the line is handled before any new characters is written
17  to the buffer */
18  input_line = str;
19  input_line_len = len;
20 }
21 PROCESS(blink_process, "LED blink process");
22 
23 PROCESS_THREAD(blink_process, ev , data)
24 {
25  static struct etimer timer;
26  PROCESS_BEGIN();
28  while(1) {
29  PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_EXIT ||
30  ev== PROCESS_EVENT_TIMER);
31  if (ev == PROCESS_EVENT_EXIT) break;
32  leds_invert(LEDS_RED);
33 #if 0
34  {
35  DISABLE_FIFOP_INT();
36  printf("FSMSTATE: %04x",cc2420_getreg(CC2420_FSMSTATE));
37  ENABLE_FIFOP_INT();
38  if (SFD_IS_1) printf(" SFD");
39  if (FIFO_IS_1) printf(" FIFO");
40  if (FIFOP_IS_1) printf(" FIFOP");
41  putchar('\n');
42  }
43 #endif
45  }
46  printf("Ended process\n");
47  PROCESS_END();
48 }
49 PROCINIT(&etimer_process, &blink_process);
50 int
52 {
53  disableIRQ();
54  disableFIQ();
55  *AT91C_AIC_IDCR = 0xffffffff;
56  *AT91C_PMC_PCDR = 0xffffffff;
57  *AT91C_PMC_PCER = (1 << AT91C_ID_PIOA);
58 
59  dbg_setup_uart();
60  printf("Initialising\n");
61  dbg_set_input_handler(recv_input);
63  clock_init();
64 
65  process_init();
66  printf("Started\n");
67 
68  procinit_init();
69  enableIRQ();
70  printf("Processes running\n");
71  while(1) {
72  do {
73  /* Reset watchdog. */
74  } while(process_run() > 0);
75  /* Idle! */
76  /* Stop processor clock */
77  *AT91C_PMC_SCDR |= AT91C_PMC_PCK;
78  }
79  return 0;
80 }