Contiki-NG
Toggle main menu visibility
Loading...
Searching...
No Matches
rs232.c
1
/*
2
* Copyright (c) 2006, Swedish Institute of Computer Science.
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 copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
13
* 3. Neither the name of the Institute nor the names of its contributors
14
* may be used to endorse or promote products derived from this software
15
* without specific prior written permission.
16
*
17
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
* SUCH DAMAGE.
28
*
29
*/
30
31
#include "lib/sensors.h"
32
#include "
dev/rs232.h
"
33
#include "
dev/serial-line.h
"
34
#include "lib/simEnvChange.h"
35
#include <string.h>
36
#include <stdio.h>
37
38
#define SERIAL_BUF_SIZE 2048
39
40
// COOJA variables
41
char
simSerialReceivingData[SERIAL_BUF_SIZE];
42
int
simSerialReceivingLength;
43
char
simSerialReceivingFlag;
44
45
static
int (* input_handler)(
unsigned
char) = NULL;
46
47
int
simlog_char(
char
c);
48
/*-----------------------------------------------------------------------------------*/
49
void
rs232_init
(
void
) { }
50
/*-----------------------------------------------------------------------------------*/
51
void
rs232_set_speed(
unsigned
char
speed) { }
52
/*-----------------------------------------------------------------------------------*/
53
void
54
rs232_set_input(
int
(*f)(
unsigned
char
))
55
{
56
input_handler = f;
57
}
58
/*-----------------------------------------------------------------------------------*/
59
void
rs232_send(
char
c) {
60
printf(
"%c"
, c);
61
}
62
/*-----------------------------------------------------------------------------------*/
63
void
64
rs232_print(
char
*message)
65
{
66
printf(
"%s"
, message);
67
}
68
/*-----------------------------------------------------------------------------------*/
69
void
70
slip_arch_writeb(
unsigned
char
c)
71
{
72
simlog_char(c);
73
}
74
/*-----------------------------------------------------------------------------------*/
75
static
void
76
doInterfaceActionsBeforeTick(
void
)
77
{
78
int
i;
79
80
if
(!simSerialReceivingFlag) {
81
return
;
82
}
83
84
if
(simSerialReceivingLength == 0) {
85
/* Error, should not be zero */
86
simSerialReceivingFlag = 0;
87
return
;
88
}
89
90
/* Notify specified rs232 handler */
91
if
(input_handler != NULL) {
92
for
(i=0; i < simSerialReceivingLength; i++) {
93
input_handler(simSerialReceivingData[i]);
94
}
95
}
else
{
96
/* Notify serial process */
97
for
(i=0; i < simSerialReceivingLength; i++) {
98
serial_line_input_byte(simSerialReceivingData[i]);
99
}
100
serial_line_input_byte(0x0a);
101
}
102
103
simSerialReceivingLength = 0;
104
simSerialReceivingFlag = 0;
105
}
106
/*-----------------------------------------------------------------------------------*/
107
COOJA_PRE_TICK_ACTION(COOJA_RS232_INIT_PRIO, doInterfaceActionsBeforeTick);
rs232.h
Header file for COOJA RS232 driver.
rs232_init
void rs232_init(void)
Initialize the RS232 module.
Definition
rs232.c:49
serial-line.h
Generic serial I/O process header filer.
arch
platform
cooja
dev
rs232.c
Generated on
for Contiki-NG by
1.17.0