Subversion Repositories Code-Repo

Rev

Rev 107 | Rev 111 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 107 Rev 109
Line 92... Line 92...
92
    MQ_init(); // Initialize message queues before enabling any interrupts
92
    MQ_init(); // Initialize message queues before enabling any interrupts
93
    led_driver_init(); // Initialize the driver for the LED display
93
    led_driver_init(); // Initialize the driver for the LED display
94
    pwm_init(); // Initialize the PWM output driver
94
    pwm_init(); // Initialize the PWM output driver
95
    timers_init(); // Initialize timers
95
    timers_init(); // Initialize timers
96
    intx_init();
96
    intx_init();
97
    //    port_b_int_init();          // Initialze Port B interrupt handler
97
    port_b_int_init(); // Initialze Port B interrupt handler
98
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
98
    interrupt_enable(); // Enable high-priority interrupts and low-priority interrupts
99
    interrupt_init(); // Initialize the interrupt priorities
99
    interrupt_init(); // Initialize the interrupt priorities
100
 
100
 
-
 
101
    // Set all ports as digial I/O
-
 
102
    ANCON0 = 0xFF;
-
 
103
    ANCON1 = 0x1F;
-
 
104
 
101
    // Configure the hardware i2c device as a slave
105
    // Configure the hardware i2c device as a slave
102
#ifdef _MASTER
106
#ifdef _MASTER
103
    i2c_configure_master();
107
    i2c_configure_master();
104
#endif
108
#endif
105
#ifdef _SLAVE
109
#ifdef _SLAVE
106
    i2c_configure_slave(0x5F);
110
    i2c_configure_slave(0x5F);
107
#endif
111
#endif
108
    
112
 
109
    DBG_PRINT_MAIN("\r\nMain: Program Started\r\n");
113
    DBG_PRINT_MAIN("\r\nMain: Program Started\r\n");
110
 
114
 
111
#ifdef _MASTER
115
#ifdef _MASTER
112
    //     Delay a bit to allow XBees to start up
116
    //     Delay a bit to allow XBees to start up
113
    for (i = 0; i < 20; i++)
117
    for (i = 0; i < 20; i++)
Line 141... Line 145...
141
        while (i2c_master_busy());
145
        while (i2c_master_busy());
142
 
146
 
143
        // Read 2 bytes back
147
        // Read 2 bytes back
144
        i2c_master_recv(0x5F, 2);
148
        i2c_master_recv(0x5F, 2);
145
        while (i2c_master_busy());
149
        while (i2c_master_busy());
146
        Delay10KTCYx(100);
150
//        Delay10KTCYx(100);
147
    }
151
    }
148
#endif
152
#endif
149
    
153
 
150
    // Loop and process recieved messages from interrupts
154
    // Loop and process recieved messages from interrupts
151
    while (1) {
155
    while (1) {
152
        // Call a routine that blocks until either message queues are not empty
156
        // Call a routine that blocks until either message queues are not empty
153
        MQ_wait_on_incoming_msg_queues();
157
        MQ_wait_on_incoming_msg_queues();
154
 
158
 
Line 180... Line 184...
180
                    DBG_PRINT_MAIN(" Event Count: %d", msgbuffer[length - 1]);
184
                    DBG_PRINT_MAIN(" Event Count: %d", msgbuffer[length - 1]);
181
                    DBG_PRINT_MAIN("\r\n");
185
                    DBG_PRINT_MAIN("\r\n");
182
                    switch (msgbuffer[0]) {
186
                    switch (msgbuffer[0]) {
183
                        case 0x2:
187
                        case 0x2:
184
                            length = 1;
188
                            length = 1;
185
                            msgbuffer[0] = 1;   // Size
189
                            msgbuffer[0] = 1; // Size
186
                            MQ_sendmsg_FromMainToHigh(length, MSGTYPE_I2C_REPLY, (void *) msgbuffer);
190
                            MQ_sendmsg_FromMainToHigh(length, MSGTYPE_I2C_REPLY, (void *) msgbuffer);
187
                            break;
191
                            break;
188
                        case 0x4:
192
                        case 0x4:
189
                            length = 1;
193
                            length = 1;
190
                            msgbuffer[0] = last_data_received;
194
                            msgbuffer[0] = last_data_received;
Line 277... Line 281...
277
                    frame_modem_status = (void *) msgbuffer;
281
                    frame_modem_status = (void *) msgbuffer;
278
                    break;
282
                    break;
279
                    /* -----------------------------------------------------------*/
283
                    /* -----------------------------------------------------------*/
280
                    /* --- Port B Interrupt Handlers -----------------------------*/
284
                    /* --- Port B Interrupt Handlers -----------------------------*/
281
                case MSGTYPE_PORTB_4_DOWN:
285
                case MSGTYPE_PORTB_4_DOWN:
282
 
-
 
-
 
286
                    DBG_PRINT_MAIN("Main: Port B4 Down\r\n");
283
                    break;
287
                    break;
284
                case MSGTYPE_PORTB_4_UP:
288
                case MSGTYPE_PORTB_4_UP:
285
 
-
 
-
 
289
                    DBG_PRINT_MAIN("Main: Port B4 Up\r\n");
286
                    break;
290
                    break;
287
                case MSGTYPE_PORTB_5_DOWN:
291
                case MSGTYPE_PORTB_5_DOWN:
288
 
-
 
-
 
292
                    DBG_PRINT_MAIN("Main: Port B5 Down\r\n");
289
                    break;
293
                    break;
290
                case MSGTYPE_PORTB_5_UP:
294
                case MSGTYPE_PORTB_5_UP:
291
 
-
 
-
 
295
                    DBG_PRINT_MAIN("Main: Port B5 Up\r\n");
292
                    break;
296
                    break;
293
                case MSGTYPE_PORTB_6_DOWN:
297
                case MSGTYPE_PORTB_6_DOWN:
294
 
-
 
-
 
298
                    DBG_PRINT_MAIN("Main: Port B6 Down\r\n");
295
                    break;
299
                    break;
296
                case MSGTYPE_PORTB_6_UP:
300
                case MSGTYPE_PORTB_6_UP:
297
 
-
 
-
 
301
                    DBG_PRINT_MAIN("Main: Port B6 Up\r\n");
298
                    break;
302
                    break;
299
                case MSGTYPE_PORTB_7_DOWN:
303
                case MSGTYPE_PORTB_7_DOWN:
300
 
-
 
-
 
304
                    DBG_PRINT_MAIN("Main: Port B7 Down\r\n");
301
                    break;
305
                    break;
302
                case MSGTYPE_PORTB_7_UP:
306
                case MSGTYPE_PORTB_7_UP:
303
 
-
 
-
 
307
                    DBG_PRINT_MAIN("Main: Port B7 Up\r\n");
304
                    break;
308
                    break;
305
                    /* -----------------------------------------------------------*/
309
                    /* -----------------------------------------------------------*/
306
                default:
310
                default:
307
                    DBG_PRINT_MAIN("Main: (ERROR) Unexpected msg in high queue, length = %d, type = %d\r\n", length, msgtype);
311
                    DBG_PRINT_MAIN("Main: (ERROR) Unexpected msg in high queue, length = %d, type = %d\r\n", length, msgtype);
308
                    for (i = 0; i < length; i++) {
312
                    for (i = 0; i < length; i++) {