extruder/intercom.h

00001 #ifndef _INTERCOM_H
00002 #define _INTERCOM_H
00003 
00004 #include  <stdint.h>
00005 #include  "config.h"
00006 
00007 #ifdef HOST
00008   #define enable_transmit()     do { WRITE(TX_ENABLE_PIN,1);  UCSR1B &=~MASK(RXEN1); } while(0)
00009   #define disable_transmit()      do { WRITE(TX_ENABLE_PIN,0);  UCSR1B &= ~(MASK(TXCIE1) | MASK(UDRIE1)); UCSR1B |= MASK(RXEN1); } while(0)
00010 #else
00011   #define enable_transmit()     do { WRITE(TX_ENABLE_PIN,1);  UCSR0B &= ~MASK(RXEN0); } while(0)
00012   #define disable_transmit()      do { WRITE(TX_ENABLE_PIN,0);  UCSR0B &= ~(MASK(TXCIE0) | MASK(UDRIE0)); UCSR0B |= MASK(RXEN0); } while(0)
00013 #endif
00014 
00016 enum {
00017   ERROR_BAD_CRC
00018 } err_codes;
00019 
00022 typedef struct {
00023   uint8_t   start; 
00024   uint8_t   dio;  
00025   uint8_t   controller_num; 
00026   uint8_t   control_word;   
00027   uint8_t   control_index;  
00028 
00029   union {
00030     int32_t   control_data_int32;
00031     uint32_t  control_data_uint32;
00032     float     control_data_float;
00033     uint16_t  temp[2];
00034   };
00035   uint8_t   err;  
00036   uint8_t   crc;  
00037 } intercom_packet_t;
00038 
00040 typedef union {
00041   intercom_packet_t packet;
00042   uint8_t           data[sizeof(intercom_packet_t)];
00043 } intercom_packet;
00044 
00045 extern intercom_packet tx;
00046 extern intercom_packet rx;
00047 
00049 void intercom_init(void);
00050 
00053 void send_temperature(uint8_t index, uint16_t temperature);
00054 
00057 uint16_t read_temperature(uint8_t index);
00058 
00061 void set_dio(uint8_t index, uint8_t value);
00062 
00065 uint8_t get_dio(uint8_t index);
00066 
00068 void set_err(uint8_t err);
00069 
00071 uint8_t get_err(void);
00072 
00075 void start_send(void);
00076 
00077 #define FLAG_RX_IN_PROGRESS 1
00078 #define FLAG_TX_IN_PROGRESS 2
00079 #define FLAG_NEW_RX         4
00080 #define FLAG_TX_FINISHED    8
00081 extern volatile uint8_t intercom_flags;
00082 
00083 
00084 
00085 #endif  /* _INTERCOM_H */
 All Data Structures Files Functions Variables Defines