OpenWSN Firmware
openserial.h
Go to the documentation of this file.
1 
7 #ifndef __OPENSERIAL_H
8 #define __OPENSERIAL_H
9 
10 #include "openwsn.h"
11 
19 //=========================== define ==========================================
20 
27 #define SERIAL_OUTPUT_BUFFER_SIZE 256 // leave at 256!
28 
35 #define SERIAL_INPUT_BUFFER_SIZE 200
36 
38 enum {
39  MODE_OFF = 0,
40  MODE_INPUT = 1,
42 };
43 
44 // frames sent mote->PC
45 #define SERFRAME_MOTE2PC_DATA ((uint8_t)'D')
46 #define SERFRAME_MOTE2PC_STATUS ((uint8_t)'S')
47 #define SERFRAME_MOTE2PC_INFO ((uint8_t)'I')
48 #define SERFRAME_MOTE2PC_ERROR ((uint8_t)'E')
49 #define SERFRAME_MOTE2PC_CRITICAL ((uint8_t)'C')
50 #define SERFRAME_MOTE2PC_REQUEST ((uint8_t)'R')
51 
52 // frames sent PC->mote
53 #define SERFRAME_PC2MOTE_SETROOT ((uint8_t)'R')
54 #define SERFRAME_PC2MOTE_SETBRIDGE ((uint8_t)'B')
55 #define SERFRAME_PC2MOTE_DATA ((uint8_t)'D')
56 #define SERFRAME_PC2MOTE_TRIGGERTCPINJECT ((uint8_t)'T')
57 #define SERFRAME_PC2MOTE_TRIGGERUDPINJECT ((uint8_t)'U')
58 #define SERFRAME_PC2MOTE_TRIGGERICMPv6ECHO ((uint8_t)'E')
59 #define SERFRAME_PC2MOTE_TRIGGERSERIALECHO ((uint8_t)'S')
60 
61 //=========================== typedef =========================================
62 
63 //=========================== module variables ================================
64 
65 typedef struct {
66  // admin
67  uint8_t mode;
69  // input
70  uint8_t reqFrame[1+1+2+1]; // flag (1B), command (2B), CRC (2B), flag (1B)
71  uint8_t reqFrameIdx;
72  uint8_t lastRxByte;
75  uint16_t inputCrc;
76  uint8_t inputBufFill;
77  uint8_t inputBuf[SERIAL_INPUT_BUFFER_SIZE];
78  // output
80  uint16_t outputCrc;
81  uint8_t outputBufIdxW;
82  uint8_t outputBufIdxR;
83  uint8_t outputBuf[SERIAL_OUTPUT_BUFFER_SIZE];
85 
86 //=========================== prototypes ======================================
87 
88 void openserial_init(void);
89 owerror_t openserial_printStatus(uint8_t statusElement, uint8_t* buffer, uint8_t length);
90 owerror_t openserial_printInfo(uint8_t calling_component, uint8_t error_code,
91  errorparameter_t arg1,
92  errorparameter_t arg2);
93 owerror_t openserial_printError(uint8_t calling_component, uint8_t error_code,
94  errorparameter_t arg1,
95  errorparameter_t arg2);
96 owerror_t openserial_printCritical(uint8_t calling_component, uint8_t error_code,
97  errorparameter_t arg1,
98  errorparameter_t arg2);
99 owerror_t openserial_printData(uint8_t* buffer, uint8_t length);
100 uint8_t openserial_getNumDataBytes(void);
101 uint8_t openserial_getInputBuffer(uint8_t* bufferToWrite, uint8_t maxNumBytes);
102 void openserial_startInput(void);
103 void openserial_startOutput(void);
104 void openserial_stop(void);
105 bool debugPrint_outBufferIndexes(void);
106 void openserial_echo(uint8_t* but, uint8_t bufLen);
107 
108 // interrupt handlers
109 void isr_openserial_rx(void);
110 void isr_openserial_tx(void);
111 
117 #endif
uint16_t outputCrc
Definition: openserial.h:80
uint8_t openserial_getInputBuffer(uint8_t *bufferToWrite, uint8_t maxNumBytes)
Definition: openserial.c:216
Definition: openserial.h:65
owerror_t openserial_printData(uint8_t *buffer, uint8_t length)
Definition: openserial.c:130
owerror_t openserial_printCritical(uint8_t calling_component, uint8_t error_code, errorparameter_t arg1, errorparameter_t arg2)
Definition: openserial.c:185
uint16_t inputCrc
Definition: openserial.h:75
uint8_t outputBufIdxR
Definition: openserial.h:82
bool busyReceiving
Definition: openserial.h:73
void isr_openserial_tx()
Definition: openserial.c:544
owerror_t openserial_printStatus(uint8_t statusElement, uint8_t *buffer, uint8_t length)
Definition: openserial.c:83
The module is off, no serial activity.
Definition: openserial.h:39
uint8_t owerror_t
Definition: openwsn.h:265
bool inputEscaping
Definition: openserial.h:74
uint8_t outputBufIdxW
Definition: openserial.h:81
uint8_t inputBufFill
Definition: openserial.h:76
uint8_t reqFrameIdx
Definition: openserial.h:71
bool outputBufFilled
Definition: openserial.h:79
uint16_t errorparameter_t
Definition: openwsn.h:263
void openserial_startOutput()
Definition: openserial.c:270
void openserial_startInput()
Definition: openserial.c:238
#define SERIAL_INPUT_BUFFER_SIZE
Number of bytes of the serial input buffer, in bytes.
Definition: openserial.h:35
void openserial_init()
Definition: openserial.c:48
bool debugPrint_outBufferIndexes()
Trigger this module to print status information, over serial.
Definition: openserial.c:432
owerror_t openserial_printInfo(uint8_t calling_component, uint8_t error_code, errorparameter_t arg1, errorparameter_t arg2)
Definition: openserial.c:158
void openserial_echo(uint8_t *buf, uint8_t bufLen)
Definition: openserial.c:639
void isr_openserial_rx()
Definition: openserial.c:567
uint8_t debugPrintCounter
Definition: openserial.h:68
uint8_t lastRxByte
Definition: openserial.h:72
#define SERIAL_OUTPUT_BUFFER_SIZE
Number of bytes of the serial output buffer, in bytes.
Definition: openserial.h:27
uint8_t mode
Definition: openserial.h:67
The serial is transmitting bytes.
Definition: openserial.h:41
void openserial_stop()
Definition: openserial.c:354
The serial is listening or receiving bytes.
Definition: openserial.h:40
owerror_t openserial_printError(uint8_t calling_component, uint8_t error_code, errorparameter_t arg1, errorparameter_t arg2)
Definition: openserial.c:170
uint8_t openserial_getNumDataBytes()
Definition: openserial.c:205