Subversion Repositories Code-Repo

Rev

Rev 116 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 116 Rev 117
Line 98... Line 98...
98
    
98
    
99
    /* --------------------- Oscillator Configuration --------------------- */
99
    /* --------------------- Oscillator Configuration --------------------- */
100
    OSCTUNEbits.PLLEN = 1;          // Enable 4x PLL
100
    OSCTUNEbits.PLLEN = 1;          // Enable 4x PLL
101
    OSCCONbits.IRCF = 0b111;        // Set INTOSC postscaler to 8MHz
101
    OSCCONbits.IRCF = 0b111;        // Set INTOSC postscaler to 8MHz
102
    OSCCONbits.SCS = 0b00; // Use PLL as primary clock source
102
    OSCCONbits.SCS = 0b00; // Use PLL as primary clock source
-
 
103
    OSCCONbits.IDLEN = 1;   // Set CPU to IDLE on sleep instruction
103
    /* -------------------------------------------------------------------- */
104
    /* -------------------------------------------------------------------- */
104
 
105
 
105
    // Set all ports as digial I/O
106
    // Set all ports as digial I/O
106
    ANCON0 = 0xFF;
107
    ANCON0 = 0xFF;
107
    ANCON1 = 0x1F;
108
    ANCON1 = 0x1F;
Line 190... Line 191...
190
                        case 0x4:
191
                        case 0x4:
191
                            // Return data stored in buffer
192
                            // Return data stored in buffer
192
                            buffer_read(i2c_last_req_size, msgbuffer);
193
                            buffer_read(i2c_last_req_size, msgbuffer);
193
                            DBG_PRINT_MAIN("Main: (I2C Return 0x4) Returning %d bytes\r\n", i2c_last_req_size);
194
                            DBG_PRINT_MAIN("Main: (I2C Return 0x4) Returning %d bytes\r\n", i2c_last_req_size);
194
                            MQ_sendmsg_FromMainToHigh(i2c_last_req_size, MSGTYPE_I2C_REPLY, (void *) msgbuffer);
195
                            MQ_sendmsg_FromMainToHigh(i2c_last_req_size, MSGTYPE_I2C_REPLY, (void *) msgbuffer);
195
                            pwm_LED_off();  // Turn off LED if it was on
-
 
196
                            break;
196
                            break;
197
                        case 0x6:
197
                        case 0x6:
198
                            // Return status of IR signal input
198
                            // Return status of IR signal input
199
                            length = 1;
199
                            length = 1;
200
                            msgbuffer[0] = IR_receive_flag;
200
                            msgbuffer[0] = IR_receive_flag;
Line 390... Line 390...
390
                        // Receive data from same remote that previously sent data
390
                        // Receive data from same remote that previously sent data
391
                        buffer_insert(length - XBEE_RX_DATA_PACKET_FRAME_SIZE, frame_data_packet->data);
391
                        buffer_insert(length - XBEE_RX_DATA_PACKET_FRAME_SIZE, frame_data_packet->data);
392
                    }
392
                    }
393
                    
393
                    
394
                    // Send value of first byte received to LED display
394
                    // Send value of first byte received to LED display
395
                    led_driver_num(frame_data_packet->data[0]);
395
//                    led_driver_num(frame_data_packet->data[0]);
396
#endif
396
#endif
397
#ifdef _REMOTE
397
#ifdef _REMOTE
398
                    led_driver_num(frame_data_packet->data[0]);
398
                    led_driver_num(frame_data_packet->data[0]);
399
#endif
399
#endif
400
                    sleep();
400
                    sleep();
Line 503... Line 503...
503
            if (length != MSG_QUEUE_EMPTY) {
503
            if (length != MSG_QUEUE_EMPTY) {
504
                DBG_PRINT_MAIN("Main: (ERROR) Bad low priority receive, code = %d\r\n", length);
504
                DBG_PRINT_MAIN("Main: (ERROR) Bad low priority receive, code = %d\r\n", length);
505
            }
505
            }
506
        } else {
506
        } else {
507
            switch (msgtype) {
507
            switch (msgtype) {
508
                case MSGTYPE_INT1:
-
 
509
#ifdef _BASE_STATION
-
 
510
                    wake();
-
 
511
                    IR_receive_flag = 1;
-
 
512
                    pwm_LED_on();
-
 
513
//                    timer2_enable();    // Enable timer 2 to turn off LED
-
 
514
                    sleep();
-
 
515
//                    DBG_PRINT_MAIN("Main: INT1 Interrupt\r\n");
-
 
516
#endif
-
 
517
                    break;
-
 
518
                /* --- Port B Interrupt Handlers -----------------------------*/
508
                /* --- Port B Interrupt Handlers -----------------------------*/
519
                case MSGTYPE_PORTB_4_DOWN:
509
                case MSGTYPE_PORTB_4_DOWN:
520
                    DBG_PRINT_MAIN("Main: Port B4 Down\r\n");
510
                    DBG_PRINT_MAIN("Main: Port B4 Down\r\n");
521
#ifdef _REMOTE
511
#ifdef _REMOTE
522
                    if (xbee_state == XBEE_STATE_JOINED_NETWORK) {
512
                    if (xbee_state == XBEE_STATE_JOINED_NETWORK) {
Line 650... Line 640...
650
                        sleep();
640
                        sleep();
651
                    }
641
                    }
652
#endif
642
#endif
653
                    break;
643
                    break;
654
                    /* -----------------------------------------------------------*/
644
                    /* -----------------------------------------------------------*/
-
 
645
                case MSGTYPE_INT1:
-
 
646
#ifdef _BASE_STATION
-
 
647
                    wake();
-
 
648
                    IR_receive_flag = 1;
-
 
649
                    sleep();
-
 
650
//                    DBG_PRINT_MAIN("Main: INT1 Interrupt\r\n");
-
 
651
#endif
-
 
652
                    break;
655
                    /* --- Timer Interrupt Handlers ------------------------------*/
653
                    /* --- Timer Interrupt Handlers ------------------------------*/
656
                case MSGTYPE_TIMER0:
654
                case MSGTYPE_TIMER0:
657
                    DBG_PRINT_MAIN("Main: Timer 0 Interrupt\r\n");
655
                    DBG_PRINT_MAIN("Main: Timer 0 Interrupt\r\n");
658
#ifdef _BASE_STATION
656
#ifdef _BASE_STATION
659
                    pwm_LED_off();
-
 
660
                    IR_receive_flag = 0;    // Reset IR receive flag
657
                    IR_receive_flag = 0;    // Reset IR receive flag
661
                    INTCON3bits.INT1IE = 1; // Turn on INT1 interrupt
658
                    INTCON3bits.INT1IE = 1; // Turn on INT1 interrupt
662
#endif
659
#endif
663
                    sleep_enable();
660
                    sleep_enable();
664
                    break;
661
                    break;
665
                case MSGTYPE_TIMER1:
662
                case MSGTYPE_TIMER1:
666
                    DBG_PRINT_MAIN("Main: Timer 1 Interrupt\r\n");
663
                    DBG_PRINT_MAIN("Main: Timer 1 Interrupt\r\n");
667
#ifdef _REMOTE
664
#ifdef _REMOTE
668
//                    /* XBee Demo */
-
 
669
//                    frame_tx_data = (void *) msgbuffer;
-
 
670
//                    frame_tx_data->frame_type = XBEE_TX_DATA_PACKET;
-
 
671
//                    frame_tx_data->frame_id = 0;
-
 
672
//                    frame_tx_data->destination_64.UPPER_32.long_value = 0x00000000;
-
 
673
//                    frame_tx_data->destination_64.LOWER_32.long_value = 0x00000000;
-
 
674
//                    ConvertEndian64(&frame_tx_data->destination_64);
-
 
675
//                    frame_tx_data->destination_16.INT_16.int_value = xbee_parent_address;
-
 
676
//                    ConvertEndian16(&frame_tx_data->destination_16);
-
 
677
//                    frame_tx_data->broadcast_radius = 1;
-
 
678
//                    frame_tx_data->options = 0x01; // Disable ACK
-
 
679
//                    frame_tx_data->data[0] = counter;
-
 
680
//
-
 
681
//                    led_driver_num(counter);
-
 
682
//                    counter++;
-
 
683
//                    if (counter == 100)
-
 
684
//                        counter = 0;
-
 
685
//
-
 
686
//                    length = XBEE_TX_DATA_PACKET_FRAME_SIZE + 1;
-
 
687
//                    xbee_process_transmit_frame((void *) msgbuffer, length);
-
 
688
 
-
 
689
                    /* Read values from accelerometer and gyroscope */
665
                    /* Read values from accelerometer and gyroscope */
690
                    if (i2c_state == I2C_STATE_READ_GYRO) {
666
                    if (i2c_state == I2C_STATE_READ_GYRO) {
691
                        imu_read_acc();
667
                        imu_read_acc();
692
                        i2c_state = I2C_STATE_READ_ACC;
668
                        i2c_state = I2C_STATE_READ_ACC;
693
                    } else if (i2c_state == I2C_STATE_READ_ACC) {
669
                    } else if (i2c_state == I2C_STATE_READ_ACC) {
Line 700... Line 676...
700
#endif
676
#endif
701
                    break;
677
                    break;
702
                case MSGTYPE_TIMER2:
678
                case MSGTYPE_TIMER2:
703
                    DBG_PRINT_MAIN("Main: Timer 2 Interrupt\r\n");
679
                    DBG_PRINT_MAIN("Main: Timer 2 Interrupt\r\n");
704
#ifdef _BASE_STATION
680
#ifdef _BASE_STATION
705
                    IR_receive_flag = 0;
681
//                    IR_receive_flag = 0;
706
                    pwm_LED_off();
682
//                    pwm_LED_off();
707
                    INTCON3bits.INT1IE = 1; // Turn on INT1 interrupt
683
//                    INTCON3bits.INT1IE = 1; // Turn on INT1 interrupt
708
#endif
684
#endif
709
                    break;
685
                    break;
710
//                case MSGTYPE_ADC_NEWVALUE:
686
//                case MSGTYPE_ADC_NEWVALUE:
711
//                    // Get the value in the ADC
687
//                    // Get the value in the ADC
712
//                    adc_last_value = *((unsigned int*) msgbuffer);
688
//                    adc_last_value = *((unsigned int*) msgbuffer);