Subversion Repositories HomeAutomation

Rev

Rev 228 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 228 Rev 240
Line 5... Line 5...
5
#include <avr/interrupt.h>
5
#include <avr/interrupt.h>
6
#include <avr/wdt.h>
6
#include <avr/wdt.h>
7
#include <avr/pgmspace.h>
7
#include <avr/pgmspace.h>
8
#include <stdio.h>
8
#include <stdio.h>
9
#include "flash.h"
9
#include "flash.h"
10
#include "vectors.h" // Must be included after sfr_defs.h
10
#include "vectors.h" // Must be included after sfr_defs.h but before any ISR()
-
 
11
#include "can.h"
11
 
12
 
12
//---------------------------------------------------------------------------
13
//---------------------------------------------------------------------------
13
// Globals
14
// Globals
14
 
15
 
15
volatile long gMilliSecTick;
16
volatile long gMilliSecTick;
Line 100... Line 101...
100
        printf("Starting application.\n");
101
        printf("Starting application.\n");
101
        app_reset();
102
        app_reset();
102
    }
103
    }
103
   
104
   
104
    printf("No application found.\n");
105
    printf("No application found.\n");
-
 
106
   
-
 
107
    printf("\n------------------------------------------------------------\n");
-
 
108
    printf(  "   CAN Test: Periodic Transmission\n");
-
 
109
    printf(  "------------------------------------------------------------\n");
-
 
110
   
-
 
111
    printf("CanInit...");
-
 
112
    if (Can_Init() != CAN_OK) {
-
 
113
        printf("FAILED!\n");
-
 
114
    }
-
 
115
    else {
-
 
116
        printf("OK!\n");
-
 
117
    }
-
 
118
   
-
 
119
    uint32_t timeStamp = 0;
-
 
120
   
-
 
121
    Can_Message_t txMsg;
-
 
122
    Can_Message_t rxMsg;
-
 
123
    //The databytes are just what happens to be in the memory. They are never set.
-
 
124
    txMsg.RemoteFlag = 0;
-
 
125
    txMsg.ExtendedFlag = 1;
-
 
126
#define NODENUMBER 2
-
 
127
#if NODENUMBER == 1
-
 
128
    txMsg.Id = 16;
-
 
129
    txMsg.DataLength = 2;
-
 
130
#elif NODENUMBER == 2
-
 
131
    txMsg.Id = 32;
-
 
132
    txMsg.DataLength = 5;
-
 
133
#else
-
 
134
# error NODENUMBER not set!
-
 
135
#endif
-
 
136
   
-
 
137
    uint8_t i;
-
 
138
    /* main loop */
-
 
139
    while (1) {
-
 
140
        /* service the CAN routines */
-
 
141
        Can_Service();
-
 
142
       
-
 
143
        /* send CAN message and check for CAN errors once every second */
-
 
144
        if ((timebase_get() - timeStamp) >= 1000) {
-
 
145
            timeStamp = timebase_get();
-
 
146
            /* send txMsg */
-
 
147
            txMsg.Id++;
-
 
148
            Can_Send(&txMsg);
-
 
149
        }
-
 
150
       
-
 
151
        /* check if any messages have been received */
-
 
152
        while (Can_Receive(&rxMsg) == CAN_OK) {
-
 
153
            printf("BIOS Received: ID=%lx, DLC=%u, EXT=%u, RTR=%u, ", rxMsg.Id, (uint16_t)(rxMsg.DataLength), (uint16_t)(rxMsg.ExtendedFlag), (uint16_t)(rxMsg.RemoteFlag));
-
 
154
            printf("data={ ");
-
 
155
            for (i=0; i<rxMsg.DataLength; i++) {
-
 
156
                printf("%x ", rxMsg.Data.bytes[i]);
-
 
157
            }
-
 
158
            printf("}\n");
-
 
159
           
-
 
160
            if (rxMsg.Id % 20 == 19) reset();
-
 
161
        }
-
 
162
    }
-
 
163
 
105
    return 0;
164
    return 0;
106
}
165
}