Zeitsteuerung

Fork of timer0 by V09

Committer:
rs27
Date:
Fri Feb 05 14:39:43 2016 +0000
Revision:
1:8779e76fd4ea
RS485 driver

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rs27 1:8779e76fd4ea 1
rs27 1:8779e76fd4ea 2 #include "mbed.h"
rs27 1:8779e76fd4ea 3 #include "MODSERIAL.h"
rs27 1:8779e76fd4ea 4
rs27 1:8779e76fd4ea 5 // Schnittstelle für den H-Bus
rs27 1:8779e76fd4ea 6 #define RS485_TX2 P2_0
rs27 1:8779e76fd4ea 7 #define RS485_RX2 P2_1
rs27 1:8779e76fd4ea 8 #define RS485_DIR2 P1_4
rs27 1:8779e76fd4ea 9
rs27 1:8779e76fd4ea 10 class rs_485 {
rs27 1:8779e76fd4ea 11
rs27 1:8779e76fd4ea 12 private:
rs27 1:8779e76fd4ea 13
rs27 1:8779e76fd4ea 14 Timer timeout; // define debounce timer
rs27 1:8779e76fd4ea 15 Timeout timeout_out;
rs27 1:8779e76fd4ea 16
rs27 1:8779e76fd4ea 17 int tx_timeout1;
rs27 1:8779e76fd4ea 18 int tx_timeout2;
rs27 1:8779e76fd4ea 19
rs27 1:8779e76fd4ea 20 bool send_end_flag; // Flag für Telegrammende
rs27 1:8779e76fd4ea 21 uint8_t rs_aktiv; // 0 inaktiv auf Empfang
rs27 1:8779e76fd4ea 22 // 1 aktiv auf Empfang
rs27 1:8779e76fd4ea 23 // 2 aktiv im Sendemodus
rs27 1:8779e76fd4ea 24 uint8_t rs_aktiv_old;
rs27 1:8779e76fd4ea 25 uint8_t t_array[4];
rs27 1:8779e76fd4ea 26 int zeit;
rs27 1:8779e76fd4ea 27
rs27 1:8779e76fd4ea 28 public:
rs27 1:8779e76fd4ea 29
rs27 1:8779e76fd4ea 30 struct Message {
rs27 1:8779e76fd4ea 31 uint8_t STX; // Start byte
rs27 1:8779e76fd4ea 32 uint8_t source; // Absender Adresse
rs27 1:8779e76fd4ea 33 uint8_t dest; // Ziel Adresse
rs27 1:8779e76fd4ea 34 uint8_t len; // Length of data field in bytes
rs27 1:8779e76fd4ea 35 uint8_t data[8]; // Data field
rs27 1:8779e76fd4ea 36 uint8_t CRC; // CRC
rs27 1:8779e76fd4ea 37 uint8_t ETX; // Telegramm Ende
rs27 1:8779e76fd4ea 38 uint8_t h;
rs27 1:8779e76fd4ea 39 uint8_t m;
rs27 1:8779e76fd4ea 40 uint8_t s;
rs27 1:8779e76fd4ea 41 uint16_t ms;
rs27 1:8779e76fd4ea 42 uint8_t count; // interner Zähler
rs27 1:8779e76fd4ea 43 uint8_t sm; // interne Steuerung ( state maschine )
rs27 1:8779e76fd4ea 44 uint8_t error;
rs27 1:8779e76fd4ea 45 };
rs27 1:8779e76fd4ea 46
rs27 1:8779e76fd4ea 47 Message msg_out;
rs27 1:8779e76fd4ea 48 Message msg_in;
rs27 1:8779e76fd4ea 49
rs27 1:8779e76fd4ea 50 rs_485();
rs27 1:8779e76fd4ea 51
rs27 1:8779e76fd4ea 52 void isr_timeout(void);
rs27 1:8779e76fd4ea 53 void txEmpty(MODSERIAL_IRQ_INFO *q);
rs27 1:8779e76fd4ea 54 uint8_t get_crc(uint8_t *pbuffer, uint8_t count);
rs27 1:8779e76fd4ea 55 void msg_print(Message msg);
rs27 1:8779e76fd4ea 56 void write(uint8_t *data);
rs27 1:8779e76fd4ea 57 void execute(void);
rs27 1:8779e76fd4ea 58 void send(void);
rs27 1:8779e76fd4ea 59 void receive(void);
rs27 1:8779e76fd4ea 60
rs27 1:8779e76fd4ea 61 };