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 } } }
/* 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 */ }
void Start_input_clickTask(void const * argument) { osEvent event_click; item_t item; click_t *click; buzzer_note_t beep; /* Infinite loop */ for(;;) { /* Get click */ event_click = osMailGet(queue_input_clickHandle, osWaitForever); if (event_click.status == osEventMail) { /* Get click position */ click = (click_t *) event_click.value.p; /* Do something based on click type */ switch (click->click_type) { case CLICK_DOWN: break; case CLICK_HOLD: break; case CLICK_UP: /* Search item in menu on click position */ osMutexWait(mutex_menuHandle, osWaitForever); if (menu_search_click(¤t_menu, click, &item)) { /* Send item event */ while(osMailPut(queue_fsm_eventsHandle, (void *) &(item.area.event)) != osOK) { osDelay(1); } /* Beep */ beep.note = A5; beep.ms = 50; while(osMailPut(queue_periph_buzzerHandle, (void *) &beep) != osOK) { osDelay(1); } } osMutexRelease(mutex_menuHandle); break; default: break; } } } }
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); } } }
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 } } } }
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); } } }
/* State behaviour */ void behaviour_h2h_autentication(state_ptr state) { osEvent event; validation_key_t bt_key; /* Set events to react to */ state->h2h_ok = h2h_autentication_to_validation_ok; state->h2h_error = h2h_autentication_to_validation_error; /* Do state actions */ item_area_set_text(&menu_h2h_devices.items[6].item.area,"Validating Key..."); while (osMailPut(queue_lcdHandle, (void *) &menu_h2h_devices.items[6]) != osOK) { osDelay(1); } event = osMailGet(queue_ecg_keyfsmHandle, osWaitForever); if (event.status == osEventMail) { bt_key = *((validation_key_t*) event.value.v); osMailPut(queue_ecg_keyHandle, (void *) &bt_key); } }
void Start_fsm_managerTask(void const * argument) { osEvent event; fsm_event_f fsm_event; /* Initialize FSM */ fsm_client_init(&fsm); /* Infinite loop */ for(;;) { /* Get fsm event */ event = osMailGet(queue_fsm_eventsHandle, osWaitForever); if (event.status == osEventMail) { /* Retrieve event function */ fsm_event = *((fsm_event_f *) event.value.v); /* Trigger event */ fsm_event(&fsm); } } }
/** * @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 */ }
//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); } } }