This repository has been archived by the owner on Apr 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_SerialDrv.h
112 lines (92 loc) · 3.24 KB
/
user_SerialDrv.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*******************************************************************************
* FILE NAME: user_serialdrv.h
*
* DESCRIPTION:
* This is the header file for the serial device driver.
*
* USAGE:
* This file may be modified to suit the needs of the user.
*******************************************************************************/
#ifndef __serialdrv_h_
#define __serialdrv_h_
typedef char sword8;
typedef short sword16;
typedef long sword32;
typedef unsigned char uword8;
typedef unsigned short uword16;
typedef unsigned long uword32;
typedef unsigned int uint32;
#define TOTAL_SERIAL_PORTS 2
// Set these equal to 1 if you want to use these features, to 0 if not.
#define PROGRAM_PORT 0
#define TTL_PORT 1
// ASSIGN SERIAL PORTS
// Set which USART (serial port) you want to use for printfs
// and which you want to use for the Dynamic Debug Tool.
#define PRINTF_PORT PROGRAM_PORT
#define BREAKER_PANEL_PORT PROGRAM_PORT
#define MAX_RD_BUFR_SIZE 32
#define MAX_WT_BUFR_SIZE 80
#define RXINTF PIR1bits.RCIF
#define RXINTE PIE1bits.RCIE
#define TXINTF PIR1bits.TXIF
#define TXINTE PIE1bits.TXIE
#define RXINTF2 PIR3bits.RC2IF
#define RXINTE2 PIE3bits.RC2IE
#define TXINTF2 PIR3bits.TX2IF
#define TXINTE2 PIE3bits.TX2IE
#define TXSTA TXSTA1
#define TXREG TXREG1
#define RCSTA RCSTA1
#define RCREG RCREG1
/*******************************************************************************
MACRO DEFINITIONS
*******************************************************************************/
typedef enum
{
baud_19 = 128, // @40Hhz
baud_38 = 64,
baud_56 = 42,
baud_115 = 21 // @40Hhz
} SERIAL_SPEED;
typedef struct
{
unsigned int bit0:1;
unsigned int bit1:1;
unsigned int bit2:1;
unsigned int bit3:1;
unsigned int bit4:1;
unsigned int validChecksum:1;
unsigned int bp2006:1;
unsigned int tripped:1;
} panel_bitid;
/*******************************************************************************
* This stucture is used to pass data from the PC to the device driver.
*******************************************************************************/
typedef struct
{
unsigned char RX_SYNC1; //Always 0xC9
unsigned char RX_SYNC2; //Always 0x17 or 0x18
union
{
panel_bitid bitselect;
unsigned char allbits;
} data1Byte;
unsigned char data2;
unsigned char data3;
unsigned char data4;
} PANEL_INPUT_RECORD;
/*******************************************************************************
FUNCTION PROTOTYPES
*******************************************************************************/
/* These routines reside in PicPerialDrv.c */
void CheckUartInts(void);
void Serial_Driver_Initialize(void);
void Serial_Write_Char(int port,int ch_out);
void Serial_Display_Char(unsigned char data);
void Serial_Write_Bufr(int port,unsigned char *ch_out, sword16 len);
unsigned char Serial_Write(int port,rom const char *obufr,sword16 len);
void Serial_Char_Callback(unsigned char data);
unsigned char Breaker_Tripped(unsigned char id);
unsigned char NewPanel(void);
#endif