Subversion Repositories HomeAutomation

Rev

Rev 360 | Rev 392 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 360 Rev 391
Line 22... Line 22...
22
#include <avr/io.h>
22
#include <avr/io.h>
23
#include <avr/interrupt.h>
23
#include <avr/interrupt.h>
24
#include <stdio.h>
24
#include <stdio.h>
25
/* lib files */
25
/* lib files */
26
#include <bios.h>
26
#include <bios.h>
-
 
27
#include <config.h>
-
 
28
#include <drivers/timer/timebase.h>
27
#include <tc1047.h>
29
#include <tc1047.h>
28
#include <funcdefs.h>
30
#include <funcdefs.h>
29
 
31
 
30
/* defines */
32
/* defines */
31
#define GROUP_ID        0x01UL
33
#define GROUP_ID        0x01UL
32
 
34
 
33
#define RELAY_OFF           0x01
35
#define RELAY_OFF           0x01
34
#define RELAY_ON            0x02
36
#define RELAY_ON            0x02
35
#define FAILSAFE_MODE       0x0F
37
#define FAILSAFE_MODE       0x0F
36
#define FAILSAFE_TRESHOLD   60  /* Degrees when nodeRelay goes into failsafe mode */
38
#define FAILSAFE_TRESHOLD   0xFF  /* Degrees when nodeRelay goes into failsafe mode */
37
 
39
 
38
#define RELAY_CMD_ON        0x01
40
#define RELAY_CMD_ON        0x01
39
#define RELAY_CMD_OFF       0x02
41
#define RELAY_CMD_OFF       0x02
40
#define RELAY_CMD_TOGGLE    0x03
42
#define RELAY_CMD_TOGGLE    0x03
41
#define RELAY_CMD_STATUS    0x04
43
#define RELAY_CMD_STATUS    0x04
Line 43... Line 45...
43
#define STATUS_SEND_PERIOD  10000UL /* milliseconds */
45
#define STATUS_SEND_PERIOD  10000UL /* milliseconds */
44
#define FAILSAFE_SEND_PERIOD    10000UL /* milliseconds */
46
#define FAILSAFE_SEND_PERIOD    10000UL /* milliseconds */
45
#define BOUNCE_TIME         10 /* milliseconds */
47
#define BOUNCE_TIME         10 /* milliseconds */
46
#define BUTTON1             1
48
#define BUTTON1             1
47
#define BUTTON2             2
49
#define BUTTON2             2
48
 
-
 
49
#define TRUE    1
-
 
50
#define FALSE   0
-
 
51
 
50
 
52
/*-------------------------------------------------------------------------
51
/*-------------------------------------------------------------------------
53
 * Global variables
52
 * Global variables
54
 * -----------------------------------------------------------------------*/
53
 * -----------------------------------------------------------------------*/
55
uint8_t relayStatus, failsafe_flag = FALSE, rxMsg_Data_bytes[8], msg_received = FALSE;
54
uint8_t relayStatus, failsafe_flag = 0, rxMsg_Data_bytes[8], msg_received = 0;
56
uint32_t boardTemperature = 0;
55
uint32_t boardTemperature = 0;
57
 
56
 
58
 
57
 
59
/*----------------------------------------------------------------------------
58
/*----------------------------------------------------------------------------
60
 * Functions
59
 * Functions
Line 80... Line 79...
80
            // This is a message for this node
79
            // This is a message for this node
81
 
80
 
82
            if(rxMsg_Data_bytes[0] == RELAY_CMD_RESET){
81
            if(rxMsg_Data_bytes[0] == RELAY_CMD_RESET){
83
                // Return to normal operation
82
                // Return to normal operation
84
                failsafe_flag = 0;
83
                failsafe_flag = 0;
85
            }
84
            }
86
 
85
 
87
            for(m=0;m<(msg->DataLength);m++){
86
            for(m=0;m<(msg->DataLength);m++){
88
                rxMsg_Data_bytes[m] = msg->Data.bytes[m];
87
                rxMsg_Data_bytes[m] = msg->Data.bytes[m];
89
            }
88
            }
90
            msg_received = TRUE; // Tell application that message has arrived
89
            msg_received = 1; // Tell application that message has arrived
91
        }
90
        }
92
    }
91
    }
93
}
92
}
94
 
93
 
95
/*----------------------------------------------------------------------------
94
/*----------------------------------------------------------------------------
Line 105... Line 104...
105
/*-----------------------------------------------------------------------------
104
/*-----------------------------------------------------------------------------
106
 * Main Program
105
 * Main Program
107
 *---------------------------------------------------------------------------*/
106
 *---------------------------------------------------------------------------*/
108
int main(void) {
107
int main(void) {
109
 
108
 
110
    uint32_t timeStamp = bios->timebase_get(), temp = timeStamp;
109
    uint32_t timeStamp = Timebase_CurrentTime(), temp = timeStamp;
111
 
110
 
112
    Can_Message_t txMsg;
111
    Can_Message_t txMsg;
113
    txMsg.RemoteFlag = 0;
112
    txMsg.RemoteFlag = 0;
114
    txMsg.ExtendedFlag = 1;
113
    txMsg.ExtendedFlag = 1;
115
    txMsg.DataLength = 4;
114
    txMsg.DataLength = 4;
116
 
115
 
117
    adcTemperatureInit();
116
    adcTemperatureInit();
118
 
117
 
119
    // Set up callback for CAN messages
118
    // Set up callback for CAN messages
120
    bios->can_callback = &can_receive;
119
    BIOS_CanCallback = &can_receive;
121
 
120
 
122
    sei();
121
    sei();
-
 
122
   
-
 
123
    Timebase_Init();
123
 
124
 
124
    // Turn relay off
125
    // Turn relay off
125
    relayStatus = relayOff();
126
    relayStatus = relayOff();
126
//  txMsg.Id = 0x8000110; // FIXME
127
//  txMsg.Id = 0x8000110; // FIXME
127
//  bios->can_send(&txMsg);
128
//  bios->can_send(&txMsg);
Line 149... Line 150...
149
 
150
 
150
            }else if(rxMsg_Data_bytes[0] == RELAY_CMD_STATUS ){
151
            }else if(rxMsg_Data_bytes[0] == RELAY_CMD_STATUS ){
151
                // Send relay status to CAN
152
                // Send relay status to CAN
152
                sendStatus();
153
                sendStatus();
153
            }
154
            }
154
            msg_received = FALSE;
155
            msg_received = 0;
155
        }
156
        }
156
 
157
 
157
        temp = bios->timebase_get();
158
        temp = Timebase_CurrentTime();
158
        if( temp - timeStamp >= STATUS_SEND_PERIOD ){
159
        if( temp - timeStamp >= STATUS_SEND_PERIOD ){
159
            timeStamp = temp;
160
            timeStamp = temp;
160
/*          txMsg.Id = 0x8000111;
161
/*          txMsg.Id = 0x8000111;
161
            txMsg.Data.bytes[0] = timeStamp & 0x000000FF;
162
            txMsg.Data.bytes[0] = timeStamp & 0x000000FF;
162
            txMsg.Data.bytes[0] = (timeStamp & 0x0000FF00)>>8;
163
            txMsg.Data.bytes[0] = (timeStamp & 0x0000FF00)>>8;
Line 223... Line 224...
223
        statusMsg.Data.bytes[0] = temperature & 0x00FF;
224
        statusMsg.Data.bytes[0] = temperature & 0x00FF;
224
        statusMsg.Data.bytes[1] = (temperature & 0xFF00)>>8;
225
        statusMsg.Data.bytes[1] = (temperature & 0xFF00)>>8;
225
        statusMsg.Data.bytes[2] = relayStatus;
226
        statusMsg.Data.bytes[2] = relayStatus;
226
        statusMsg.Data.bytes[3] = failsafe_flag;
227
        statusMsg.Data.bytes[3] = failsafe_flag;
227
 
228
 
228
        bios->can_send( &statusMsg );
229
        BIOS_CanSend( &statusMsg );
229
    }
230
    }
230
}
231
}