summaryrefslogtreecommitdiff
path: root/rs422lib/rsbus.h
blob: 2faf620dff4abffa4f09a8b346735d5780be3041 (plain)
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
/*
 * rsbus.h
 *
 *  Created on: 2014-4-26
 *      Author: Tuowen
 */

// DE RSOUT.RSPIN HIGH ENABLE
// RE LOW ENABLE -> ALWAYS ENABLE
// RECEIVE QUERY -> Conditional FNC call
//		Process -> Output (Done in main program)
// SMCLK set to 4MHZ


#ifndef RSBUS_H_
#define RSBUS_H_

#include<msp430g2553.h>
#include"precomp.h"

// MAXIMUM length to be send
#define RS_MAX   (14)

#define ST_BUSY (0x04)
#define ST_RUN (0x02)
#define ST_RES (0x01)
#define ST_REST (0x00)

// Switch the machine to a new state specified above
// This will shown on the network -> must call
#define SWITCH_STATE(STATE) (mac_stat[0]=STATE)

// Changing the state value (unsigned char) ->
//		Available indices 0,1,2
#define STATE(X) (mac_stat[X+1])

#define STBIT0 (0x5B)
#define STBIT1 (0xAD)
#define EDBIT0 (0xA4)
#define EDBIT1 (0x52)

typedef void (*rshdlr)(unsigned char*,int);

void rsbus_init(rshdlr);

void rsbus_w(int addr,unsigned char* buf,unsigned int len);

extern volatile unsigned char mac_stat[4]; // Machine status -> change it to change the auto respond status

#endif /* RSBUS_H_ */