Пример #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
Пример #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
Пример #4
0
PROCESS_THREAD(ecdh_test, ev, data) {
  PROCESS_BEGIN();

  /*
   * Variable for Time Measurement
   */
  static rtimer_clock_t time;

  /*
   * Activate Engine
   */
  puts("-----------------------------------------\n"
       "Initializing pka...");
  pka_init();

  /*
   * Generate secrets make sure they are valid (smaller as order)
   */
  static ecc_compare_state_t state = {
    .process = &ecdh_test,
    .size    = 8,
  };
  memcpy(state.b, nist_p_256.n, sizeof(uint32_t) * 8);
  static uint32_t secret_a[8];
  do {
    ecc_set_random(secret_a);
    memcpy(state.a, secret_a, sizeof(uint32_t) * 8);
    PT_SPAWN(&(ecdh_test.pt), &(state.pt), ecc_compare(&state));
  } while(state.result != PKA_STATUS_A_LT_B);

  static uint32_t secret_b[8];
  ecc_set_random(secret_b);
  do {
    ecc_set_random(secret_b);
    memcpy(state.a, secret_b, sizeof(uint32_t) * 8);
    PT_SPAWN(&(ecdh_test.pt), &(state.pt), ecc_compare(&state));
  } while(state.result != PKA_STATUS_A_LT_B);

  /*
   * Prepare Points
   */
  static ecc_multiply_state_t side_a = {
    .process    = &ecdh_test,
    .curve_info = &nist_p_256,
  };
  memcpy(side_a.point_in.x, nist_p_256.x, sizeof(uint32_t) * 8);
  memcpy(side_a.point_in.y, nist_p_256.y, sizeof(uint32_t) * 8);
  memcpy(side_a.secret, secret_a, sizeof(secret_a));

  static ecc_multiply_state_t side_b = {
    .process    = &ecdh_test,
    .curve_info = &nist_p_256,
  };
  memcpy(side_b.point_in.x, nist_p_256.x, sizeof(uint32_t) * 8);
  memcpy(side_b.point_in.y, nist_p_256.y, sizeof(uint32_t) * 8);
  memcpy(side_b.secret, secret_b, sizeof(secret_b));

  /*
   * Round 1
   */
  time = RTIMER_NOW();
  PT_SPAWN(&(ecdh_test.pt), &(side_a.pt), ecc_multiply(&side_a));
  time = RTIMER_NOW() - time;
  printf("Round 1, Side a: %i, %lu ms\n", (unsigned)side_a.result,
         (uint32_t)((uint64_t)time * 1000 / RTIMER_SECOND));

  time = RTIMER_NOW();
  PT_SPAWN(&(ecdh_test.pt), &(side_b.pt), ecc_multiply(&side_b));
  time = RTIMER_NOW() - time;
  printf("Round 1, Side b: %i, %lu ms\n", (unsigned)side_b.result,
         (uint32_t)((uint64_t)time * 1000 / RTIMER_SECOND));

  /*
   * Key Exchange
   */
  memcpy(side_a.point_in.x, side_b.point_out.x, sizeof(uint32_t) * 8);
  memcpy(side_a.point_in.y, side_b.point_out.y, sizeof(uint32_t) * 8);
  memcpy(side_b.point_in.x, side_a.point_out.x, sizeof(uint32_t) * 8);
  memcpy(side_b.point_in.y, side_a.point_out.y, sizeof(uint32_t) * 8);

  /*
   * Round 2
   */
  time = RTIMER_NOW();
  PT_SPAWN(&(ecdh_test.pt), &(side_a.pt), ecc_multiply(&side_a));
  time = RTIMER_NOW() - time;
  printf("Round 2, Side a: %i, %lu ms\n", (unsigned)side_a.result,
         (uint32_t)((uint64_t)time * 1000 / RTIMER_SECOND));
  time = RTIMER_NOW();
  PT_SPAWN(&(ecdh_test.pt), &(side_b.pt), ecc_multiply(&side_b));
  time = RTIMER_NOW() - time;
  printf("Round 2, Side b: %i, %lu ms\n", (unsigned)side_b.result,
         (uint32_t)((uint64_t)time * 1000 / RTIMER_SECOND));

  /*
   * Check Result
   */
  memcpy(state.a, side_a.point_out.x, sizeof(uint32_t) * 8);
  memcpy(state.b, side_b.point_out.x, sizeof(uint32_t) * 8);

  PT_SPAWN(&(ecdh_test.pt), &(state.pt), ecc_compare(&state));
  if(state.result) {
    puts("shared secrets do not match");
  } else {
    puts("shared secrets MATCH");
  }

  puts("-----------------------------------------\n"
       "Disabling pka...");
  pka_disable();

  puts("Done!");

  PROCESS_END();
}
Пример #5
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
Пример #6
0
static 
PT_THREAD(data_write_thread(struct pt *pt))
{
PT_BEGIN(pt);

	char dataBuf[4096];

	static exosite_http_context_t *opContext;
	int status;

	do
	{
		printf("data_write_thread():\r\n");
		if(!is_http_op_context_existed(EXO_OP_MODE_WRITE))
			break;

		opContext = get_http_op_context(EXO_OP_MODE_WRITE);

		if(exoHttpContextQueue.deviceStatus != EXO_DEVICE_STATE_INITIALIZED)
		{
			struct pt actPt;

			PT_SPAWN(pt, &actPt, data_activate_thread(&actPt));

			exoHttpContextQueue.deviceStatus = EXO_DEVICE_STATE_INITIALIZED;
		}

		if(!build_http_msg(opContext))
		{
			release_op(opContext);
			break;
		}

		if(!exosite_pal_sock_write( &opContext->sock,
									opContext->pdu,
									strlen(opContext->pdu)))
		{
			opContext->opStatus = -1;

			opContext->resultCallback(	NULL,
										opContext->opStatus);

			close_socket(&opContext->sock);
			release_op(opContext);
			break;
		}

		PT_YIELD(pt);

		memset(dataBuf, 0, sizeof(dataBuf));
		size_t bufLen = sizeof(dataBuf);

		exosite_pal_timer_init(&opContext->waitTimer);
		exosite_pal_timer_countdown_ms(&opContext->waitTimer, WAIT_TIME_MS);

		bool isReadData = true;
		while(exosite_pal_sock_read(	&opContext->sock,
										dataBuf,
										&bufLen) == 0)
		{
			PT_YIELD(pt);
			if(exosite_pal_timer_expired(&opContext->waitTimer))
			{
				opContext->opStatus = -1;

				opContext->resultCallback(	NULL,
											opContext->opStatus);

				close_socket(&opContext->sock);
				release_op(opContext);

				isReadData = false;
				break;
			}
		}

		if(!isReadData)
			break;

		printf("data_write_thread(): got rsp\r\n");


		if(parse_rsp_status(dataBuf,
							bufLen,
							&status))
		{
			opContext->opStatus = status;
			opContext->resultCallback(	NULL,
										opContext->opStatus);

			release_op(opContext);

			check_http_error_status_to_determine_if_reset_cik(status);
		}

		printf("rsp status = %d\r\n", status);

		if(status == 401 || status == 403)
		{
			struct pt actPt;

			PT_SPAWN(pt, &actPt, data_activate_thread(&actPt));
		}
	} while(false);

PT_END(pt);
}