Ejemplo n.º 1
0
//static PT_THREAD(protothread_I2C(struct pt *pt)){
//    PT_BEGIN(pt);
//    while(1){
//        
//        PT_YIELD_TIME_msec(500);
//    }   
//    PT_END(pt);
//}
static PT_THREAD(protothread_uart(struct pt *pt)) {
    // this thread interacts with the PC keyboard to take user input and set up PID parameters
    PT_BEGIN(pt);
    // send the prompt via DMA to serial
        sprintf(PT_send_buffer, "%s", "cmd>");
        // by spawning a print thread
        PT_SPAWN(pt, &pt_DMA_output, PT_DMA_PutSerialBuffer(&pt_DMA_output));//send date and time
    
    while (1) {
        buffer[0] = RcvIMUData(BNO055_QUATERNION_DATA_W_LSB_ADDR);
        buffer[1] = RcvIMUData(BNO055_QUATERNION_DATA_X_LSB_ADDR);
        buffer[2] = RcvIMUData(BNO055_QUATERNION_DATA_Y_LSB_ADDR);
	buffer[3] = RcvIMUData(BNO055_QUATERNION_DATA_Z_LSB_ADDR);
//        temp = RcvIMUData(BNO055_ACCEL_DATA_X_LSB_ADDR);
        
        

        sprintf(PT_send_buffer, "%s     %s%d, %s%d, %s%d, %s%d%s", "Accelerometer value: " , "W: ", buffer[0], "X: "
                , buffer[1], "Y: ", buffer[2], "Z: ", buffer[3],"\n\r");
//        sprintf(PT_send_buffer, "%s     %s%d, %s%d, %s%d%s", "Accelerometer value: " , "W: ", buffer[0], "X: "
//                , buffer[1], "Y: ", buffer[2],"\n\r");
        // by spawning a print thread
        PT_SPAWN(pt, &pt_DMA_output, PT_DMA_PutSerialBuffer(&pt_DMA_output));//send date and time

        
//        //spawn a thread to handle terminal input
//        // the input thread waits for input
//        // -- BUT does NOT block other threads
//        // string is returned in "PT_term_buffer"
//        PT_SPAWN(pt, &pt_input, PT_GetSerialBuffer(&pt_input));//wait for  input
//        sscanf(PT_term_buffer, "%s %f", cmd, &value);
//                         
//        // echo
//        sprintf(PT_send_buffer,"%04x%s", rcv, "\n");//send original message
//        PT_SPAWN(pt, &pt_DMA_output, PT_DMA_PutSerialBuffer(&pt_DMA_output) );
//        sprintf(PT_send_buffer,"\n");//next line
//        PT_SPAWN(pt, &pt_DMA_output, PT_DMA_PutSerialBuffer(&pt_DMA_output) );
//        sprintf(PT_send_buffer,"\r");//carriage return
//        PT_SPAWN(pt, &pt_DMA_output, PT_DMA_PutSerialBuffer(&pt_DMA_output) );
                
        
       
        PT_YIELD_TIME_msec(500);
    } // while(1)
    PT_END(pt);
} // uart input thread
Ejemplo n.º 2
0
//static PT_THREAD(protothread_I2C(struct pt *pt)){
//    PT_BEGIN(pt);
//    while(1){
//        
//        PT_YIELD_TIME_msec(500);
//    }   
//    PT_END(pt);
//}
static PT_THREAD(protothread_uart(struct pt *pt)) {
    // this thread interacts with the PC keyboard to take user input and set up PID parameters
    PT_BEGIN(pt);
    // send the prompt via DMA to serial
        sprintf(PT_send_buffer, "%s", "cmd>");
        // by spawning a print thread
        PT_SPAWN(pt, &pt_DMA_output, PT_DMA_PutSerialBuffer(&pt_DMA_output));//send date and time
    
    while (1) {
        
        temp = RcvData2(addr);

        sprintf(PT_send_buffer, "%s%d%s", "Temperature value: " ,temp, "\n\r");
        // by spawning a print thread
        PT_SPAWN(pt, &pt_DMA_output, PT_DMA_PutSerialBuffer(&pt_DMA_output));//send date and time

        
//        //spawn a thread to handle terminal input
//        // the input thread waits for input
//        // -- BUT does NOT block other threads
//        // string is returned in "PT_term_buffer"
//        PT_SPAWN(pt, &pt_input, PT_GetSerialBuffer(&pt_input));//wait for  input
//        sscanf(PT_term_buffer, "%s %f", cmd, &value);
//                         
//        // echo
//        sprintf(PT_send_buffer,"%04x%s", rcv, "\n");//send original message
//        PT_SPAWN(pt, &pt_DMA_output, PT_DMA_PutSerialBuffer(&pt_DMA_output) );
//        sprintf(PT_send_buffer,"\n");//next line
//        PT_SPAWN(pt, &pt_DMA_output, PT_DMA_PutSerialBuffer(&pt_DMA_output) );
//        sprintf(PT_send_buffer,"\r");//carriage return
//        PT_SPAWN(pt, &pt_DMA_output, PT_DMA_PutSerialBuffer(&pt_DMA_output) );
                
        
       
        PT_YIELD_TIME_msec(500);
    } // while(1)
    PT_END(pt);
} // uart input thread
static PT_THREAD (protothread3(struct pt *pt))
{
    PT_BEGIN(pt);
      while(1) {
          
            // send the prompt via DMA to serial
            sprintf(PT_send_buffer,"cmd>");
            // by spawning a print thread
            PT_SPAWN(pt, &pt_DMA_output, PT_DMA_PutSerialBuffer(&pt_DMA_output) );
 
          //spawn a thread to handle terminal input
            // the input thread waits for input
            // -- BUT does NOT block other threads
            // string is returned in "PT_term_buffer"
            PT_SPAWN(pt, &pt_input, PT_GetSerialBuffer(&pt_input) );
            // returns when the thead dies
            // in this case, when <enter> is pushed
            // now parse the string
             sscanf(PT_term_buffer, "%s %d", cmd, &value);

             if (cmd[0]=='t' && cmd[1]=='1') { wait_t1 = value ;} // set the blink time MILLIsec
             if (cmd[0]=='t' && cmd[1]=='4') { wait_t2 = value ;} // set the blink time MICROsec
             if (cmd[0] == 'g' && cmd[1]=='1') {cntl_blink = 1 ;} // make it blink using YIELD
             if (cmd[0] == 's' && cmd[1]=='1') {cntl_blink = 0 ;} // make it stop
             if (cmd[0] == 'g' && cmd[1]=='4') {run_t4 = 1 ;} // make it blink using scheduler
             if (cmd[0] == 's' && cmd[1]=='4') {run_t4 = 0 ;} // make it stop using scheduler
             if (cmd[0] == 'k') {PT_EXIT(pt);} // kill this input thread (see also MAIN)
             // scheduler control
             if (cmd[0] == 'p' && cmd[1]=='1') { t1_rate = value ;}
             if (cmd[0] == 'p' && cmd[1]=='3') { t3_rate = value ;}
             if (cmd[0] == 'p' && cmd[1]=='4') { t4_rate = value ;}
             if (cmd[0] == 'z') printf("%d\t%d\n\r", PT_GET_TIME(), sys_time_seconds);
            // never exit while
      } // END WHILE(1)
  PT_END(pt);
} // thread 3
Ejemplo n.º 4
0
static PT_THREAD (protothread_cmd(struct pt *pt))
{
    PT_BEGIN(pt);
      while(1) {
          
            // send the prompt via DMA to serial
            sprintf(PT_send_buffer,"cmd>");
            // by spawning a print thread
            PT_SPAWN(pt, &pt_DMA_output, PT_DMA_PutSerialBuffer(&pt_DMA_output) );
 
          //spawn a thread to handle terminal input
            // the input thread waits for input
            // -- BUT does NOT block other threads
            // string is returned in "PT_term_buffer"
            PT_SPAWN(pt, &pt_input, PT_GetSerialBuffer(&pt_input) );
            // returns when the thread dies
            // in this case, when <enter> is pushed
            // now parse the string
             sscanf(PT_term_buffer, "%s %d", cmd, &value);
         

             
              if (cmd[0]=='d' ) {
                //set mux to DSP chip
                mPORTAClearBits(BIT_4);
                mPORTBClearBits(BIT_13);
                mPORTASetBits(BIT_4);
                mPORTBClearBits(BIT_3 | BIT_7 | BIT_8 | BIT_9);
                 
                 if(((value << 6) & (0x0040))){
                     mPORTBSetBits(BIT_3);
                 }
                     //select sound effect
                 mPORTBSetBits(value << 6);
                 }
             if (cmd[0] == 's'){ //distortion
                 //set mux to Distortion
                mPORTAClearBits(BIT_4);
                mPORTBClearBits(BIT_13);
             }
             if (cmd[0] == 'n'){ //normal: only tone stack
                 //set mux to channel 0
                mPORTAClearBits(BIT_4);
                mPORTBClearBits(BIT_13);
                mPORTBSetBits(BIT_13);
             }
             //pots
             if (cmd[0] == 't'){ //treble
                // CS low to start transaction
                mPORTBClearBits(BIT_4); // start transaction
                deliverSPICh1Datum(value);
                // CS high
                mPORTBSetBits(BIT_4); // end transaction
             }
             if (cmd[0] == 'b'){ //bass
                // CS low to start transaction
                mPORTAClearBits(BIT_0); // start transaction
                deliverSPICh1Datum(value);
                // CS high
                mPORTASetBits(BIT_0); // end transaction
            }
            if (cmd[0] == 'v'){ //level
                // CS low to start transaction
                    mPORTAClearBits(BIT_2); // start transaction
                    deliverSPICh1Datum(value);                              
                     // CS high
                    mPORTASetBits(BIT_2); // end transaction
            }
            if (cmd[0] == 'm'){ //mid
                // CS low to start transaction
                mPORTAClearBits(BIT_3); // start transaction
                deliverSPICh1Datum(value);
                // CS high
                mPORTASetBits(BIT_3); // end transaction
            }
                          
            // never exit while
      } // END WHILE(1)
  PT_END(pt);
} // thread 3