/* StartDataOutTask function */
void StartDataOutTask(void const * argument)
{
  /* USER CODE BEGIN StartDataOutTask */
  SYS_DEBUG_TRACK();
  ControlData_t* pControlData;
  
  
  /* Infinite loop */
  for(;;)
  {
    SYS_DEBUG("one loop!\n");
    
    /* -----| 1.接收待输出数据 |--------------------*/
    osEvent event = osMailGet( gControlDataMail, osWaitForever);
    pControlData = (ControlData_t *)event.value.p;
    
    
    /* -----| 2.输出数据       |--------------------*/
    ControlOut_PutControlData( pControlData  );
    
   
    /* -----| 3.释放数据缓冲区 |--------------------*/
    osMailFree( gControlDataMail, pControlData );
   
    
    osDelay(1);
  }
  /* USER CODE END StartDataOutTask */
}
extern "C" void user_main() {
    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_SET);

    osKernelInitialize();
    osKernelStart();

    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_RESET);

    key_event_init();
    keymat_init();
    keymat_callback = key_event_handler;
    keymat_start();

    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_SET);

    while (1) {
        osEvent ose = osMailGet(key_events, osWaitForever);
        if (ose.status == osEventMail) {
            KeyEvent* e = (KeyEvent*)ose.value.p;

            // NOTE: MIDI handling is hardcoded for now
            buf[0] = (e->state ? 0x90 : 0x80); // use ch0
            buf[1] = e->keycode;
            buf[2] = 100; // use hard-coded velocity

            osMailFree(key_events, e);

            send_n(3); // blocking call
        }
    }
}
Exemple #3
0
int main (void) {
    mail_box = osMailCreate(osMailQ(mail_box), NULL);
    osThreadCreate(osThread(send_thread), NULL);

    while (true) {
        osEvent evt = osMailGet(mail_box, osWaitForever);
        if (evt.status == osEventMail) {
            mail_t *mail = (mail_t*)evt.value.p;
            printf("\nVoltage: %.2f V\n\r"   , mail->voltage);
            printf("Current: %.2f A\n\r"     , mail->current);
            printf("Number of cycles: %u\n\r", mail->counter);

            osMailFree(mail_box, mail);
        }
    }
}
Exemple #4
0
void Thread_MailQueue2(void const *argument) {
  MAILQUEUE_OBJ_t  *pMail = 0;
  osEvent           evt;

  while(1) {
    ; // Insert thread code here...
    evt = osMailGet(qid_MailQueue, osWaitForever);              // wait for mail
    if (evt.status == osEventMail) {
      pMail = evt.value.p;
      if(pMail) {
        ; // process data
        osMailFree(qid_MailQueue, pMail);                       // free memory allocated for mail
      }
    }
  }
}
Exemple #5
0
void TX_Thread (void const *argument)
{
	T_MEAS  *rptr;
  osEvent  evt;
	
	while(1)
	{
		evt = osMailGet(mail, osWaitForever); 
		if(evt.status == osEventMail)
		{
			rptr = evt.value.p;
			vcom_write(&g_rxBuff[0], 256);
			osMailFree(mail, rptr);
		}
	}
}
static void thread_cpufreq (void const *arg)
{
	T_CPUFREQ_MAIL  *rmail = NULL;
	osEvent  evt;

	for(;;)
	{
		/*lint --e{569} */
		evt = osMailGet(cpufreq_mail, osWaitForever);
		if (evt.status == osEventMail)
		{
			rmail = evt.value.p;
			cpufreq_recv_mail(rmail);
			osMailFree(cpufreq_mail, rmail);
		}
	}
}
Exemple #7
0
/**
  * @brief  Mail Consumer Thread.
  * @param  argument: Not used
  * @retval None
  */
static void MailQueueConsumer (const void *argument)
{
  osEvent event;
  Amail_TypeDef *pRMail;
  
  for(;;)
  {
    /* Get the message from the queue */
    event = osMailGet(mailId, osWaitForever); /* wait for mail */
    
    if(event.status == osEventMail)
    {
      pRMail = event.value.p;
      
      if((pRMail->var1 != ConsumerValue1) || (pRMail->var2 != ConsumerValue2) || (pRMail->var3 != ConsumerValue3))
      {
        /* Catch-up. */
        ConsumerValue1 = pRMail->var1;
        ConsumerValue2 = pRMail->var2;
        ConsumerValue3 = pRMail->var3;
        
        /* Toggle LED2 to indicate error */
        BSP_LED_Toggle(LED2);
      }
      else
      {  
        /* Calculate values we expect to remove from the mail queue next time
        round. */
        ++ConsumerValue1;
        ConsumerValue2 += 2;
        ConsumerValue3 += 3;        
      }

      osMailFree(mailId, pRMail); /* free memory allocated for mail */       
    }		
  }
}
/* StartDataProcessTask function */
void StartDataProcessTask(void const * argument)
{
  /* USER CODE BEGIN StartDataProcessTask */
  SYS_DEBUG_TRACK();

  SensorData_t* pSensorData;
  ControlData_t* pControlData;
  /* Infinite loop */
  for(;;)
  {
    SYS_DEBUG("one loop!\n");

    /* -----| 1.从邮箱接收传感器数据   |---------------------*/
    osEvent event = osMailGet( gSenorDataMail, osWaitForever);
    pSensorData = (SensorData_t *)event.value.p;
    
    
    /* -----| 2.申请输出数据邮箱 |-------------------------- */
    pControlData = (ControlData_t *) osMailAlloc(gControlDataMail, osWaitForever);    
    
    
    /* -----| 3.处理数据,处理结果存放于输出缓冲区  |--------*/
    DataProcess_DoProcess( pSensorData, pControlData  );
    
    
    /* -----| 4.发送处理结果(缓冲区)到输出邮箱 | -----------*/
    osMailPut( gControlDataMail , pControlData ) ;
   
    
    /* -----| 5.释放超声波数据缓冲区  |------------------------*/
    osMailFree( gSenorDataMail, pSensorData );
    
    
//    osDelay(1);
  }
  /* USER CODE END StartDataProcessTask */
}
/* StartDataParseTask function */
void StartDataParseTask(void const * argument)
{
  /* USER CODE BEGIN StartDataParseTask */
  uint8_t tmp;
  SYS_DEBUG_TRACK();
  
  /* Infinite loop */
  for(;;)
  {
    SYS_DEBUG("one loop!\n");

    /*------------------------接收并解析数据包---------------------------*/
    /* 1. 开始接收数据帧*/
     /*读取帧头1——head1 */
    xSerialGetChar( ReceiveDataQueueHandle, &tmp, osWaitForever ); 

    /*判断是否为帧头1——head1*/
    if( tmp == SENSOR_PROTOCOL_PACK_HEADER0 )                            
    {
      /*读取帧头2——head2*/
      xSerialGetChar( ReceiveDataQueueHandle, &tmp, osWaitForever );

      /*如果读到的还是帧头1,则重新读帧头2;防止重复的帧头1干扰*/
      if( tmp == SENSOR_PROTOCOL_PACK_HEADER0 )                           
      {
        /* 重新读取帧头2 */
        xSerialGetChar( ReceiveDataQueueHandle, &tmp, osWaitForever );        
      }
 
      /* 验证帧头2——head2*/
      if( tmp == SENSOR_PROTOCOL_PACK_HEADER1  )                        
      {
        /* 读取数据段长度 len */
        uint8_t len;
        xSerialGetChar( ReceiveDataQueueHandle, &len, osWaitForever );
        if( len == SENSOR_PROTOCOL_PACK_MAX_DATA_LEN )
        {
          /* 从邮箱申请空间,用来保存读取结果 */
          SensorData_t* pSensorData;
          pSensorData = (SensorData_t *) osMailAlloc( gSenorDataMail, osWaitForever);
          
          /* 读取数据段内容 */
          uint8_t* ptr = (uint8_t*)pSensorData ;
          uint8_t i;
          for( i = 0; i < len; i++ )
          {
            /* 循环接收整个数据段 */
            xSerialGetChar( ReceiveDataQueueHandle, ptr++, osWaitForever ); 
          }
          
          /* 读取校验字节 */
          xSerialGetChar( ReceiveDataQueueHandle, &tmp , osWaitForever ); 
          if( tmp == doSumCheck( (uint8_t*)pSensorData, len ) )
          {
            /* 如果校验通过,则发送缓冲区到队列 */
            if( osOK != osMailPut( gSenorDataMail, pSensorData) )  
            {
              ;   //TODO: Add something here
            }
          }else
          {
            /* 释放内存空间 */
            osMailFree( gSenorDataMail, pSensorData );
          }
          
        }
      }
    }
    
//    osDelay(1);
  }
  /* USER CODE END StartDataParseTask */
}
//Mailbox thread behaviour
void Thread_MAIL_CONTROLLER(void const *argument) {
	osEvent event;
	MAIL_package_typedef *package_recieved;
	MAIL_package_typedef *package_to_send;

	while (1) {
		event = osMailGet(input_mailbox, osWaitForever);

		if (event.status == osEventMail) {
			package_recieved = (MAIL_package_typedef *) event.value.p;

			if (package_recieved->type == MAIL_TEMP) { //Update temp

				//Synthetic alarm simulator
				//if (test < 150) package_recieved->value += 20;
				//test = (test +1) % 300;

				temperature = package_recieved->value;

				if (temperature >= ALARM_THRESHOLD && !alarm_on) {
					package_to_send = osMailAlloc(led_mailbox, osWaitForever);
					package_to_send->type = MAIL_ALARM;
					package_to_send->value = 100.0f;
					osMailPut(led_mailbox, package_to_send);
					alarm_on = 1;
				} else if(temperature < ALARM_THRESHOLD && alarm_on) {
					package_to_send = osMailAlloc(led_mailbox, osWaitForever);
					package_to_send->type = MAIL_ALARM;
					package_to_send->value = 0.0f;
					osMailPut(led_mailbox, package_to_send);
					alarm_on = 0;
				}

			} else if (package_recieved->type == MAIL_ANGLE) { //Update angle
				angle = package_recieved->value;

			} else if (package_recieved->type == MAIL_KEY) { //Update key event

				key_event = (int)package_recieved->value;
				printf("%i\n", key_event);
				if (key_event == KP_STAR) { //Star pressed
					//Change which type of event we send to led
					if (curent_display_type == MAIL_TEMP) {
						curent_display_type = MAIL_ANGLE;

						//Prepare package to send current angle value to led right away at last if of function
						package_recieved->type = curent_display_type;
						package_recieved->value = angle;

					} else if (curent_display_type == MAIL_ANGLE) {
						curent_display_type = MAIL_TEMP;

						//Prepare package to send current temp value to led right away at last if of function
						package_recieved->type = curent_display_type;
						package_recieved->value = temperature;
					}

				} else if (key_event == KP_POUND && curent_display_type != MAIL_TEMP) { //Pound pressed
					if (!target_set) {
						target_set = 1;

						//Send pound event to led to confirm current target value
						package_to_send = osMailAlloc(led_mailbox, osWaitForever);
						package_to_send->value = key_event;
						package_to_send->type = MAIL_KEY;
						osMailPut(led_mailbox, package_to_send);
					}

				} else { //Digit pressed
					if (!target_set) {

						//Send key event to led to change current digit
						package_to_send = osMailAlloc(led_mailbox, osWaitForever);
						package_to_send->value = key_event;
						package_to_send->type = MAIL_KEY;
						osMailPut(led_mailbox, package_to_send);
					}
				}
			}

			//Send new data to LED if of current type
			if (package_recieved->type == curent_display_type){
				package_to_send = osMailAlloc(led_mailbox, osWaitForever);
				package_to_send->value = package_recieved->value;
				package_to_send->type = package_recieved->type;
				osMailPut(led_mailbox, package_to_send);
			}

			osMailFree(input_mailbox, package_recieved);
		}
	}
}