void tasks_input_init()
{
  /* Mutexes */
  osMutexDef(mutex_menu);
  mutex_menuHandle = osMutexCreate(osMutex(mutex_menu));

  /* Semaphores */
  /* sem_input_touch_pen */
  osSemaphoreDef(sem_input_touch_pen);
  sem_input_touch_penHandle = osSemaphoreCreate(osSemaphore(sem_input_touch_pen), 1);

  /* sem_input_button_short_press */
  osSemaphoreDef(sem_input_button_short_press);
  sem_input_button_short_pressHandle = osSemaphoreCreate(osSemaphore(sem_input_button_short_press), 1);

  /* sem_input_button_long_press */
  osSemaphoreDef(sem_input_button_long_press);
  sem_input_button_long_pressHandle = osSemaphoreCreate(osSemaphore(sem_input_button_long_press), 1);

  /* Queues */
  /* queue_input_click */
  osMailQDef(queue_input_click, 16, click_t);
  queue_input_clickHandle = osMailCreate(osMailQ(queue_input_click), NULL);

  /* queue_input_menu */
  osMailQDef(queue_input_menu, 4, menu_t *);
  queue_input_menuHandle = osMailCreate(osMailQ(queue_input_menu), NULL);
}
void cpufreq_init(void)
{
    dfs_ddrc_calc();
	//dfs_to_max();
	memset(&g_cpufreq, 0x0, sizeof(T_CPUFREQ_ST));
	/* 初始化记录的上一次需要调的频率值 */
	g_cpufreq.maxprof = CPUFREQ_MAX_PROFILE;
	g_cpufreq.minprof = CPUFREQ_MIN_PROFILE;
	g_cpufreq.curprof = cpufreq_get_cur_profile();
    M3_CUR_CPUFREQ_PROFILE = g_cpufreq.curprof;
    M3_MAX_CPUFREQ_PROFILE = g_cpufreq.maxprof;
    M3_MIN_CPUFREQ_PROFILE = g_cpufreq.minprof;
    M3_CPUFREQ_DOWN_FLAG(0) = 0;
    M3_CPUFREQ_DOWN_FLAG(1) = 0;

	cpufreq_mail = osMailCreate(osMailQ(cpufreq_mail), NULL);

	thread_cpufreq_id = osThreadCreate (osThread (thread_cpufreq), NULL);
	if (thread_cpufreq_id == NULL)
	{
		M3CPUFREQ_PRINT(" thread create error\n");
	}

	/* icc channel */
	cpufreq_icc_init();

}
void tasks_fsm_init()
{
  /* Semaphores */

  /* Queues */
  /* queue_fsm_events */
  osMailQDef(queue_fsm_events, 8, fsm_event_f);
  queue_fsm_eventsHandle = osMailCreate(osMailQ(queue_fsm_events), NULL);
}
예제 #4
0
int Init_MailQueue (void) {

  qid_MailQueue = osMailCreate(osMailQ(MailQueue), NULL);       // create mail queue
  if(!qid_MailQueue) {
    ; // Mail Queue object not created, handle failure
  }
  
  tid_Thread_MailQueue1 = osThreadCreate (osThread(Thread_MailQueue1),  NULL);
  if(!tid_Thread_MailQueue1) return(-1);
  tid_Thread_MailQueue2 = osThreadCreate (osThread(Thread_MailQueue2),  NULL);
  if(!tid_Thread_MailQueue2) return(-1);
  
  return(0);
}
예제 #5
0
int main()
{
    SystemCoreClockUpdate();
    //Inicializa a UART
    UART_init(115200);
    printf("Inicializando...\n");
    //Inicializa as Threads
    tid_Comunicacao = osThreadCreate(osThread(task_comunicacao), NULL);
    if (tid_Comunicacao == NULL) {
         printf("Erro ao criar Thread de Comunicacao!\n");
    }
    tid_Enfileirador = osThreadCreate(osThread(task_enfileirador), NULL);
    if (tid_Enfileirador == NULL) {
         printf("Erro ao criar Thread de Enfileirador!\n");
    }
    tid_Controle = osThreadCreate(osThread(task_controle_elevador), NULL);
    if (tid_Controle == NULL) {
         printf("Erro ao criar Thread de Controle do elevador!\n");
    }
    //Inicializa a Mail Queue de envio de mensagens (Tarefa de Comunicacao)
	qid_filaEnvioMensagens = osMailCreate(osMailQ(filaEnvioMensagens), tid_Comunicacao);
    //Inicializa o kernel
    osKernelStart();
    //Desliga todas as luzes
    for (int i = 0; i < 4; i++) {
      comunicacao_envia_requisicao_atendida(i,-1);
      comunicacao_envia_requisicao_atendida(i,1);
    }
    //Inicializa o elevador na posicao inicial
    comunicacao_envia_comando_inicializa_elevador();
    //
    //Testes (remover quando for utilizar o sistema em produção)
    //
    /*
    osDelay(2000);
    comunicacao_envia_comando_portas(-1);
    osDelay(2000);
    comunicacao_envia_comando_movimento(1);
    while(1){
        osDelay(1000);
        comunicacao_envia_consulta_posicao();
    }
    */
    
    //while(1);
    
    //Aqui não tem problema dar return, pois as outras threads vão continuar rodando mesmo que a Main finalize (fato comprovado na prática).
    return 0;
}
예제 #6
0
파일: main.cpp 프로젝트: Archcady/mbed-os
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);
        }
    }
}
예제 #7
0
파일: main.c 프로젝트: dazuo78/TBall
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F103xG HAL library initialization:
       - Configure the Flash prefetch
       - Systick timer is configured by default as source of time base, but user 
         can eventually implement his proper time base source (a general purpose 
         timer for example or other time source), keeping in mind that Time base 
         duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
         handled in milliseconds basis.
       - Set NVIC Group Priority to 4
       - Low Level Initialization
     */
  HAL_Init();  
  
  /* Configure the System clock to 72 MHz */
  SystemClock_Config();
  
  /* Initialize LED1 and LED3 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED3);
  
  /* Create the mail queue used by the two tasks to pass the struct Amail_TypeDef */
  osMailQDef(mail, MAIL_SIZE, Amail_TypeDef); /* Define mail queue */
  
  mailId = osMailCreate(osMailQ(mail), NULL); /* create mail queue */
  
  /* Note the producer has a lower priority than the consumer when the tasks are
     spawned. */
  osThreadDef(QCons, MailQueueConsumer, osPriorityBelowNormal, 0, blckqSTACK_SIZE);
  osThreadCreate(osThread(QCons), NULL);
  
  osThreadDef(QProd, MailQueueProducer, osPriorityBelowNormal, 0, blckqSTACK_SIZE);
  osThreadCreate(osThread(QProd), NULL);
  
  /* Start scheduler */
  osKernelStart ();

  /* We should never get here as control is now taken by the scheduler */
  for(;;);
}
예제 #8
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* Enable the CPU Cache */
  CPU_CACHE_Enable();

  /* STM32F7xx HAL library initialization:
       - Configure the Flash ART accelerator on ITCM interface
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Low Level Initialization
     */
  HAL_Init();  
  
  /* Configure the system clock to 216 Mhz */
  SystemClock_Config();
  
  /* Initialize LEDs */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED3);
  
  /* Create the mail queue used by the two tasks to pass the struct Amail_TypeDef */
  osMailQDef(mail, MAIL_SIZE, Amail_TypeDef); /* Define mail queue */
  
  mailId = osMailCreate(osMailQ(mail), NULL); /* create mail queue */
  
  /* Note the producer has a lower priority than the consumer when the tasks are
     spawned. */
  osThreadDef(QCons, MailQueueConsumer, osPriorityBelowNormal, 0, blckqSTACK_SIZE);
  osThreadCreate(osThread(QCons), NULL);
  
  osThreadDef(QProd, MailQueueProducer, osPriorityBelowNormal, 0, blckqSTACK_SIZE);
  osThreadCreate(osThread(QProd), NULL);
  
  /* Start scheduler */
  osKernelStart ();

  /* We should never get here as control is now taken by the scheduler */
  for(;;);
}
int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_USART1_UART_Init();
  MX_USART2_UART_Init();
  MX_SPI1_Init();

  /* USER CODE BEGIN 2 */
  
    /* 硬件初始化开始 */
//  USART_printf( &BSP_USART_PRINT, "开始硬件初始化!\n");

  /* 初始化输出 */
  ControlOut_Init( );
  
  /*  初始化控制模式  */
  ModeControl_Init(  );
  
  /* 初始化主控模块 */
  DataProcess_Init( );
  
  /*启动循环接收DMA*/
  HAL_UART_Receive_DMA(&BSP_USART_SENSOR, (uint8_t*)&gUSART1_RX_TMP, 1);      


  /* 硬件初始化结束 */
//  USART_printf( &BSP_USART_PRINT, "硬件初始化结束 !\n");

  /* USER CODE END 2 */

  /* USER CODE BEGIN RTOS_MUTEX */
  /* add mutexes, ... */
  /* USER CODE END RTOS_MUTEX */

  /* USER CODE BEGIN RTOS_SEMAPHORES */
  /* add semaphores, ... */
  /* USER CODE END RTOS_SEMAPHORES */

  /* USER CODE BEGIN RTOS_TIMERS */
  /* start timers, add new ones, ... */
  /* USER CODE END RTOS_TIMERS */

  /* Create the thread(s) */
  /* definition and creation of MainTask */
  osThreadDef(MainTask, StartMainTask, osPriorityBelowNormal, 0, 128);
  MainTaskHandle = osThreadCreate(osThread(MainTask), NULL);

  /* definition and creation of DataParseTask */
  osThreadDef(DataParseTask, StartDataParseTask, osPriorityNormal, 0, 160);
  DataParseTaskHandle = osThreadCreate(osThread(DataParseTask), NULL);

  /* definition and creation of DataProcessTask */
  osThreadDef(DataProcessTask, StartDataProcessTask, osPriorityAboveNormal, 0, 256);
  DataProcessTaskHandle = osThreadCreate(osThread(DataProcessTask), NULL);

  /* definition and creation of DataOutTask */
  osThreadDef(DataOutTask, StartDataOutTask, osPriorityHigh, 0, 160);
  DataOutTaskHandle = osThreadCreate(osThread(DataOutTask), NULL);

  /* definition and creation of PrintTask */
  osThreadDef(PrintTask, StartPrintTask, osPriorityBelowNormal, 0, 128);
  PrintTaskHandle = osThreadCreate(osThread(PrintTask), NULL);

  /* USER CODE BEGIN RTOS_THREADS */
  /* add threads, ... */
  /* USER CODE END RTOS_THREADS */

  /* Create the queue(s) */
  /* definition and creation of ReceiveDataQueue */
  osMessageQDef(ReceiveDataQueue, 128, uint8_t);
  ReceiveDataQueueHandle = osMessageCreate(osMessageQ(ReceiveDataQueue), NULL);

  /* definition and creation of PrintQueues */
  osMessageQDef(PrintQueues, 512, uint8_t);
  PrintQueuesHandle = osMessageCreate(osMessageQ(PrintQueues), NULL);

  /* USER CODE BEGIN RTOS_QUEUES */
  /* add queues, ... */

  /* 创建传感器采集值邮箱 */
  gSenorDataMail = osMailCreate(osMailQ(gSenorDataMail), NULL);     

  /* 创建处理结果输出邮箱 */
  gControlDataMail = osMailCreate(osMailQ(gSenorDataMail), NULL);     

  
  
  /* USER CODE END RTOS_QUEUES */
 

  /* Start scheduler */
  osKernelStart();
  
  /* We should never get here as control is now taken by the scheduler */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
예제 #10
0
/**
 * init mailboxes used by MC
 */
void MAIL_CONTROLLER_init_mailboxes(void) {
	input_mailbox = osMailCreate(osMailQ(input_mailbox), NULL);
	led_mailbox = osMailCreate(osMailQ(led_mailbox), NULL);
}
예제 #11
0
static void key_event_init() {
    key_events = osMailCreate(osMailQ(key_events), NULL);
}