Contiki 2.5
contiki-serial-main.c
1 /*
2  * Copyright (c) 2007, Takahide Matsutsuka.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following
12  * disclaimer in the documentation and/or other materials provided
13  * with the distribution.
14  * 3. The name of the author may not be used to endorse or promote
15  * products derived from this software without specific prior
16  * written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * $Id: contiki-serial-main.c,v 1.5 2009/12/11 14:59:31 matsutsuka Exp $
31  *
32  */
33 
34 /*
35  * \file
36  * This is a sample main file with serial.
37  * \author
38  * Takahide Matsutsuka <markn@markn.org>
39  */
40 
41 #include "contiki.h"
42 
43 /* devices */
44 #include "dev/serial-line.h"
45 #include "ctk/libconio_arch-small.h"
46 
47 #undef RS232_INTR
48 #ifdef RS232_INTR
49 void rs232_arch_writeb(u8_t ch);
50 void rs232_arch_init(int (* callback)(unsigned char), unsigned long ubr);
51 #else
52 #include "dev/rs232.h"
53 #endif
54 
55 PROCESS(stest_process, "Serial test process");
56 /*---------------------------------------------------------------------------*/
57 static void
58 rs232_print(char* str) {
59  while (*str != 0) {
60  rs232_arch_writeb(*str++);
61  }
62 }
63 /*---------------------------------------------------------------------------*/
64 static void
65 log(char* str) {
66  while (*str != 0) {
67  libputc_arch(*str++);
68  }
69 }
70 /*---------------------------------------------------------------------------*/
71 PROCESS_THREAD(stest_process, ev, data)
72 {
73  static struct etimer timer;
74  PROCESS_BEGIN();
75 
76  clrscr_arch();
77 #ifdef RS232_INTR
78  rs232_arch_init(serial_line_input_byte, 0);
79 #endif
80 
82 
83  log("Starting serial test process");
84  while(1) {
86 
87  if (etimer_expired(&timer)) {
88  log("Sending serial data now");
89  rs232_print("GNU's not Unix\n");
91  }
92 
93  if(ev == serial_line_event_message) {
94  log(data);
95  }
96  }
97 
98  PROCESS_END();
99 }
100 /*---------------------------------------------------------------------------*/
101 void
102 main(void)
103 {
104  /* initialize process manager. */
105  process_init();
106 
107  /* start services */
108  process_start(&etimer_process, NULL);
109  process_start(&serial_line_process, NULL);
110 #ifndef RS232_INTR
111  process_start(&rs232_process, NULL);
112 #endif
113  process_start(&stest_process, NULL);
114 
115  while(1) {
116  process_run();
118  }
119 }