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);
}
int main(void)
{
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();


  /* Initialize all configured peripherals */
  MX_GPIO_Init();

  /* Create the threads and semaphore */
  osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
  defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
  osThreadDef(blinkTask, BlinkTask, osPriorityNormal, 0, 128);
  blinkTaskHandle = osThreadCreate(osThread(blinkTask), NULL);
  osSemaphoreDef(sem);
  semHandle = osSemaphoreCreate(osSemaphore(sem), 1);
  osSemaphoreWait(semHandle, osWaitForever);

  /* Start scheduler */
  osKernelStart();

  /* We should never get here as control is now taken by the scheduler */

  /* Infinite loop */
  while (1);

}
Exemple #3
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();  
  
  /* Configure the system clock to 168 MHz */
  SystemClock_Config();
  
  /* Configure LED1, LED2, LED3 and LED4 */
  BSP_LED_Init(LED1);
  
  /* Configure Key Button */
  BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI);  
  
  /* Define used semaphore */
  osSemaphoreDef(SEM);
  
  /* Create the semaphore used by the two threads. */
  osSemaphore = osSemaphoreCreate(osSemaphore(SEM) , 1);
  
  /* Create the Thread that toggle LED1 */
  osThreadDef(SEM_Thread, SemaphoreTest, osPriorityNormal, 0, semtstSTACK_SIZE);
  osThreadCreate(osThread(SEM_Thread), (void *) osSemaphore);
  
  /* Start scheduler */
  osKernelStart();

  /* We should never get here as control is now taken by the scheduler */
  for(;;);
}
void SensorsTaskOSInit(void)
{   
    osSemaphoreDef(i2cTransactSem);
        
    i2cSem = osSemaphoreCreate(osSemaphore(i2cTransactSem), 1);
    
    ALBI2CHandle.Instance              = ALB_I2C;
    ALBI2CHandle.Init.AddressingMode   = I2C_ADDRESSINGMODE_7BIT;
    ALBI2CHandle.Init.Timing           = I2C_TIMING_100KHZ;
    ALBI2CHandle.Init.DualAddressMode  = I2C_DUALADDRESS_DISABLED;
    ALBI2CHandle.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
    ALBI2CHandle.Init.GeneralCallMode  = I2C_GENERALCALL_DISABLED;
    ALBI2CHandle.Init.NoStretchMode    = I2C_NOSTRETCH_DISABLED;
    ALBI2CHandle.Init.OwnAddress1      = 0x00;
    ALBI2CHandle.Init.OwnAddress2      = 0x00;
    
    assert_param(HAL_I2C_Init(&ALBI2CHandle) == HAL_OK);
    
    SLBI2CHandle.Instance              = SLB_I2C;
    SLBI2CHandle.Init.AddressingMode   = I2C_ADDRESSINGMODE_7BIT;
    SLBI2CHandle.Init.Timing           = I2C_TIMING_100KHZ;
    SLBI2CHandle.Init.DualAddressMode  = I2C_DUALADDRESS_DISABLED;
    SLBI2CHandle.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
    SLBI2CHandle.Init.GeneralCallMode  = I2C_GENERALCALL_DISABLED;
    SLBI2CHandle.Init.NoStretchMode    = I2C_NOSTRETCH_DISABLED;
    SLBI2CHandle.Init.OwnAddress1      = 0x00;
    SLBI2CHandle.Init.OwnAddress2      = 0x00;
    
    assert_param(HAL_I2C_Init(&SLBI2CHandle) == HAL_OK);
}
Exemple #5
0
/**
  * @brief  Initializes the lwIP stack
  * @param  None
  * @retval None
  */
static void Netif_Config(void)
{
  struct ip_addr ipaddr;
  struct ip_addr netmask;
  struct ip_addr gw;	
  
  /* IP address setting */
  IP4_ADDR(&ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
  IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1 , NETMASK_ADDR2, NETMASK_ADDR3);
  IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
  
  /* - netif_add(struct netif *netif, struct ip_addr *ipaddr,
  struct ip_addr *netmask, struct ip_addr *gw,
  void *state, err_t (* init)(struct netif *netif),
  err_t (* input)(struct pbuf *p, struct netif *netif))
  
  Adds your network interface to the netif_list. Allocate a struct
  netif and pass a pointer to this structure as the first argument.
  Give pointers to cleared ip_addr structures when using DHCP,
  or fill them with sane numbers otherwise. The state pointer may be NULL.
  
  The init function pointer must point to a initialization function for
  your ethernet netif interface. The following code illustrates it's use.*/
  
  netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &tcpip_input);
  
  /*  Registers the default network interface. */
  netif_set_default(&gnetif);
  
  if (netif_is_link_up(&gnetif))
  {
    /* When the netif is fully configured this function must be called.*/
    netif_set_up(&gnetif);
  }
  else
  {
    /* When the netif link is down this function must be called */
    netif_set_down(&gnetif);
  }

  /* Set the link callback function, this function is called on change of link status*/
  netif_set_link_callback(&gnetif, ethernetif_update_config);
  
  /* create a binary semaphore used for informing ethernetif of frame reception */
  osSemaphoreDef(Netif_SEM);
  Netif_LinkSemaphore = osSemaphoreCreate(osSemaphore(Netif_SEM) , 1 );
  
  link_arg.netif = &gnetif;
  link_arg.semaphore = Netif_LinkSemaphore;
  /* Create the Ethernet link handler thread */
#if defined(__GNUC__)
  osThreadDef(LinkThr, ethernetif_set_link, osPriorityNormal, 0, configMINIMAL_STACK_SIZE * 5);
#else
  osThreadDef(LinkThr, ethernetif_set_link, osPriorityNormal, 0, configMINIMAL_STACK_SIZE * 2);
#endif

  osThreadCreate (osThread(LinkThr), &link_arg);
}
/**
  * @brief In this function, the hardware should be initialized.
  * Called from ethernetif_init().
  *
  * @param netif the already initialized lwip network interface structure
  *        for this ethernetif
  */
static void low_level_init(struct netif *netif)
{
  uint8_t macaddress[6]= { MAC_ADDR0, MAC_ADDR1, MAC_ADDR2, MAC_ADDR3, MAC_ADDR4, MAC_ADDR5 };
  
  EthHandle.Instance = ETH;  
  EthHandle.Init.MACAddr = macaddress;
  EthHandle.Init.AutoNegotiation = ETH_AUTONEGOTIATION_ENABLE;
  EthHandle.Init.Speed = ETH_SPEED_100M;
  EthHandle.Init.DuplexMode = ETH_MODE_FULLDUPLEX;
  EthHandle.Init.MediaInterface = ETH_MEDIA_INTERFACE_RMII;
  EthHandle.Init.RxMode = ETH_RXINTERRUPT_MODE;
  EthHandle.Init.ChecksumMode = ETH_CHECKSUM_BY_HARDWARE;
  EthHandle.Init.PhyAddress = LAN8742A_PHY_ADDRESS;
  
  /* configure ethernet peripheral (GPIOs, clocks, MAC, DMA) */
  if (HAL_ETH_Init(&EthHandle) == HAL_OK)
  {
    /* Set netif link flag */
    netif->flags |= NETIF_FLAG_LINK_UP;
  }
  
  /* Initialize Tx Descriptors list: Chain Mode */
  HAL_ETH_DMATxDescListInit(&EthHandle, DMATxDscrTab, &Tx_Buff[0][0], ETH_TXBUFNB);
     
  /* Initialize Rx Descriptors list: Chain Mode  */
  HAL_ETH_DMARxDescListInit(&EthHandle, DMARxDscrTab, &Rx_Buff[0][0], ETH_RXBUFNB);
  
  /* set netif MAC hardware address length */
  netif->hwaddr_len = ETHARP_HWADDR_LEN;

  /* set netif MAC hardware address */
  netif->hwaddr[0] =  MAC_ADDR0;
  netif->hwaddr[1] =  MAC_ADDR1;
  netif->hwaddr[2] =  MAC_ADDR2;
  netif->hwaddr[3] =  MAC_ADDR3;
  netif->hwaddr[4] =  MAC_ADDR4;
  netif->hwaddr[5] =  MAC_ADDR5;

  /* set netif maximum transfer unit */
  netif->mtu = 1500;

  /* Accept broadcast address and ARP traffic */
  netif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;

  /* create a binary semaphore used for informing ethernetif of frame reception */
  osSemaphoreDef(SEM);
  s_xSemaphore = osSemaphoreCreate(osSemaphore(SEM) , 1 );

  /* create the task that handles the ETH_MAC */
  osThreadDef(EthIf, ethernetif_input, osPriorityRealtime, 0, INTERFACE_THREAD_STACK_SIZE);
  osThreadCreate (osThread(EthIf), netif);

  /* Enable MAC and DMA transmission and reception */
  HAL_ETH_Start(&EthHandle);
}
int ff_cre_syncobj (    /* TRUE:Function succeeded, FALSE:Could not create due to any error */
    BYTE vol,           /* Corresponding logical drive being processed */
    _SYNC_t *sobj       /* Pointer to return the created sync object */
)
{
  int ret;

  osSemaphoreDef(SEM);
  *sobj = osSemaphoreCreate(osSemaphore(SEM), 1);
  ret = (*sobj != NULL);

  return ret;
}
/* Init OS */
void GUI_X_InitOS(void)
{
  /* Create Mutex lock */
  osMutexDef(MUTEX);

  /* Create the Mutex used by the two threads */
  osMutex = osMutexCreate(osMutex(MUTEX));

  /* Create Semaphore lock */
  osSemaphoreDef(SEM);

  /* Create the Semaphore used by the two threads */
  osSemaphore= osSemaphoreCreate(osSemaphore(SEM), 1);
}
Exemple #9
0
/**
  * @brief  Demo state machine.
  * @param  None
  * @retval None
  */
void HID_MenuInit(void)
{
  /* Create Menu Semaphore */
  osSemaphoreDef(osSem);

  MenuEvent = osSemaphoreCreate(osSemaphore(osSem), 1); 
  
  /* Force menu to show Item 0 by default */
  osSemaphoreRelease(MenuEvent);
  
  /* Menu task */
  osThreadDef(Menu_Thread, HID_MenuThread, osPriorityHigh, 0, 8 * configMINIMAL_STACK_SIZE);
  osThreadCreate(osThread(Menu_Thread), NULL);
}
Exemple #10
0
/**
  * @brief  Demo state machine.
  * @param  None
  * @retval None
  */
void Menu_Init(void)
{
  /* Create Menu Semaphore */
  osSemaphoreDef(osSem);

  MenuEvent = osSemaphoreCreate(osSemaphore(osSem), 1); 
  
  /* Force menu to show Item 0 by default */
  osSemaphoreRelease(MenuEvent);

  /* Menu task */
  osThreadDef(Menu_Thread, MSC_MenuThread, osPriorityHigh, 0, 8 * configMINIMAL_STACK_SIZE);
  osThreadCreate(osThread(Menu_Thread), NULL);
  
  /* Define used semaphore fot Joystick*/
  osSemaphoreDef(JOY_SEM);
  
  /* Create the semaphore used by the two threads. */
  osJoySemaphore = osSemaphoreCreate(osSemaphore(JOY_SEM) , 1);
  
  BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
  BSP_LCD_DisplayStringAtLine(15, (uint8_t *)"Use [Joystick Left/Right] to scroll up/down");
  BSP_LCD_DisplayStringAtLine(16, (uint8_t *)"Use [Joystick Up/Down] to scroll MSC menu");  
}
/**
  * @brief  Demo state machine.
  * @param  None
  * @retval None
  */
void HID_MenuInit(void)
{
  /* Create Menu Semaphore */
  osSemaphoreDef(osSem);

  MenuEvent = osSemaphoreCreate(osSemaphore(osSem), 1); 
  
  /* Force menu to show Item 0 by default */
  osSemaphoreRelease(MenuEvent);
  
  /* Menu task */
  osThreadDef(Menu_Thread, HID_MenuThread, osPriorityHigh, 0, 8 * configMINIMAL_STACK_SIZE);
  osThreadCreate(osThread(Menu_Thread), NULL);
  
  BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
  BSP_LCD_DisplayStringAtLine(18, (uint8_t *)"Use [Joystick Left/Right] to scroll up/down");
  BSP_LCD_DisplayStringAtLine(19, (uint8_t *)"Use [Joystick Up/Down] to scroll HID menu");
}
Exemple #12
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F3xx 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();

  /* Initialize LEDs */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED2);

  /* Configure the system clock to 72 MHz */
  SystemClock_Config();

  /* Define used semaphore */
  osSemaphoreDef(SEM);

  /* Create the semaphore used by the two threads. */
  osSemaphore = osSemaphoreCreate(osSemaphore(SEM) , 1);

  /* Create the first Thread */
  osThreadDef(SEM_Thread1, SemaphoreThread1, osPriorityLow, 0, semtstSTACK_SIZE);
  SemThread1Handle = osThreadCreate(osThread(SEM_Thread1), (void *) osSemaphore);

  /* Create the second Thread */
  osThreadDef(SEM_Thread2, SemaphoreThread2, osPriorityIdle, 0, semtstSTACK_SIZE);
  SemThread2Handle = osThreadCreate(osThread(SEM_Thread2), (void *) osSemaphore);

  /* Start scheduler */
  osKernelStart(NULL, NULL);

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

}
/**
  * @brief  Demo state machine.
  * @param  None
  * @retval None
  */
void Menu_Init(void)
{
  /* Create Menu Semaphore */
  osSemaphoreDef(osSem);

  MenuEvent = osSemaphoreCreate(osSemaphore(osSem), 1);

  /* Force menu to show Item 0 by default */
  osSemaphoreRelease(MenuEvent);

  /* Menu task */
#if defined(__GNUC__)
  osThreadDef(Menu_Thread, MSC_MenuThread, osPriorityHigh, 0, 8 * configMINIMAL_STACK_SIZE);
#else
  osThreadDef(Menu_Thread, MSC_MenuThread, osPriorityHigh, 0, 4 * configMINIMAL_STACK_SIZE);
#endif
  osThreadCreate(osThread(Menu_Thread), NULL);

  BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
  BSP_LCD_DisplayStringAtLine(15, (uint8_t *)"Use [Joystick Left/Right] to scroll up/down");
  BSP_LCD_DisplayStringAtLine(16, (uint8_t *)"Use [Joystick Up/Down] to scroll MSC menu");
}
Exemple #14
0
int main(void) {
  HAL_Init();

  Nucleo_BSP_Init();

  RetargetInit(&huart2);

  osThreadDef(blink, blinkThread, osPriorityNormal, 0, 100);
  osThreadCreate(osThread(blink), NULL);

  osThreadDef(delay, delayThread, osPriorityNormal, 0, 100);
  osThreadCreate(osThread(delay), NULL);

  osSemaphoreDef(sem);
  semid = osSemaphoreCreate(osSemaphore(sem), 1);
  osSemaphoreWait(semid, osWaitForever);

  osKernelStart();

  /* Infinite loop */
  while (1);
}
Exemple #15
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();  
  
  /* Configure the system clock to 180 MHz */
  SystemClock_Config();

  /* Configure LED1 and LED3 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED3);


  /* Define used semaphore */
  osSemaphoreDef(SEM);
  
  /* Create the semaphore used by the two threads. */
  osSemaphore = osSemaphoreCreate(osSemaphore(SEM) , 1);
  osSemaphoreRelease(osSemaphore);
  
  /* Create the first Thread */
  osThreadDef(SEM_Thread1, SemaphoreThread1, osPriorityLow, 0, semtstSTACK_SIZE);
  SemThread1Handle = osThreadCreate(osThread(SEM_Thread1), (void *) osSemaphore);
  
  /* Create the second Thread */
  osThreadDef(SEM_Thread2, SemaphoreThread2, osPriorityIdle, 0, semtstSTACK_SIZE);
  SemThread2Handle = osThreadCreate(osThread(SEM_Thread2), (void *) osSemaphore);
  
  /* Start scheduler */
  osKernelStart();
  
  /* We should never get here as control is now taken by the scheduler */
  for(;;);
}
Exemple #16
0
void CommInit(void)
{
    huart2.Instance = USART2;
    huart2.Init.BaudRate = 57600;
    huart2.Init.WordLength = UART_WORDLENGTH_8B;
    huart2.Init.StopBits = UART_STOPBITS_1;
    huart2.Init.Parity = UART_PARITY_NONE;
    huart2.Init.Mode = UART_MODE_TX_RX;
    huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
    huart2.Init.OverSampling = UART_OVERSAMPLING_16;
    HAL_UART_Init(&huart2);

    hcrc.Instance = CRC;
    HAL_CRC_Init(&hcrc);

    chIQInit(&g_iqp, g_comm_iqp_buf, COMM_IQP_BUF_SIZE, NULL);

    osSemaphoreDef(COMM_SEMA);
    commSema = osSemaphoreEmptyCreate(osSemaphore(COMM_SEMA));
    if (NULL == commSema)
    {
        printf("[%s, L%d] create semaphore failed!\r\n", __FILE__, __LINE__);
        return;
    }

    osThreadDef(CommTask, CommStartTask, osPriorityNormal, 0, 1024);
    CommTaskHandle = osThreadCreate(osThread(CommTask), NULL);
    if (NULL == CommTaskHandle)
    {
        printf("[%s, L%d] create thread failed!\r\n", __FILE__, __LINE__);
        return;
    }

    HAL_NVIC_SetPriority(USART2_IRQn, configLIBRARY_LOWEST_INTERRUPT_PRIORITY, 0);
    HAL_NVIC_EnableIRQ(USART2_IRQn);

    __HAL_UART_ENABLE_IT(&huart2, UART_IT_RXNE);
    return;
}
Exemple #17
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();
  
  /* Configure LED1 */
  BSP_LED_Init(LED1);
  
  /* Configure TAMPER Button */
  BSP_PB_Init(BUTTON_TAMPER, BUTTON_MODE_EXTI);  
  
  /* Define used semaphore */
  osSemaphoreDef(SEM);
  
  /* Create the semaphore used by the two threads. */
  osSemaphore = osSemaphoreCreate(osSemaphore(SEM) , 1);
  
  /* Create the Thread that toggle LED1 */
  osThreadDef(SEM_Thread, SemaphoreTest, osPriorityNormal, 0, semtstSTACK_SIZE);
  osThreadCreate(osThread(SEM_Thread), (void *) osSemaphore);
  
  /* Start scheduler */
  osKernelStart();

  /* We should never get here as control is now taken by the scheduler */
  for(;;);
}
Exemple #18
0
/* Init FreeRTOS */
void MX_FREERTOS_Init(void) 
{

  /* Create a defaultTask */
  xTaskCreate(StartDefaultTask, (const char *) "DefaultTask", configMINIMAL_STACK_SIZE, NULL, osPriorityNormal, &defaultTaskHandle);	
	
  /* Create tasks for module ports */
  xTaskCreate(PxTask, (const char *) "P1Task", configMINIMAL_STACK_SIZE, (void *) P1, osPriorityNormal, &P1TaskHandle);
	xTaskCreate(PxTask, (const char *) "P2Task", configMINIMAL_STACK_SIZE, (void *) P2, osPriorityNormal, &P2TaskHandle);
	xTaskCreate(PxTask, (const char *) "P3Task", configMINIMAL_STACK_SIZE, (void *) P3, osPriorityNormal, &P3TaskHandle);
	xTaskCreate(PxTask, (const char *) "P4Task", configMINIMAL_STACK_SIZE, (void *) P4, osPriorityNormal, &P4TaskHandle);
	xTaskCreate(PxTask, (const char *) "P5Task", configMINIMAL_STACK_SIZE, (void *) P5, osPriorityNormal, &P5TaskHandle);
#if (HO01R1 || HO02R0 || HO01R2 || HO02R1 || HO01R3 || HO02R2)
	xTaskCreate(PxTask, (const char *) "P6Task", configMINIMAL_STACK_SIZE, (void *) P6, osPriorityNormal, &P6TaskHandle);
#endif

	/* Create the front-end task */
	xTaskCreate(FrontEndTask, (const char *) "FrontEndTask", configMINIMAL_STACK_SIZE, NULL, osPriorityAboveNormal, &FrontEndTaskHandle);

	/* Create the motor continuous rotation task */
//	xTaskCreate(ContRotationTask, (const char *) "ContRotationTask", configMINIMAL_STACK_SIZE, NULL, osPriorityAboveNormal, &ContRotationHandle);
		
	/* Create semaphores to protect module ports (FreeRTOS vSemaphoreCreateBinary didn't work) */
	osSemaphoreDef(SemaphoreP1); PxSemaphoreHandle[P1] = osSemaphoreCreate(osSemaphore(SemaphoreP1), 1);
	osSemaphoreDef(SemaphoreP2); PxSemaphoreHandle[P2] = osSemaphoreCreate(osSemaphore(SemaphoreP2), 1);	
	osSemaphoreDef(SemaphoreP3); PxSemaphoreHandle[P3] = osSemaphoreCreate(osSemaphore(SemaphoreP3), 1);
	osSemaphoreDef(SemaphoreP4); PxSemaphoreHandle[P4] = osSemaphoreCreate(osSemaphore(SemaphoreP4), 1);	
	osSemaphoreDef(SemaphoreP5); PxSemaphoreHandle[P5] = osSemaphoreCreate(osSemaphore(SemaphoreP5), 1);
#if (HO01R1 || HO02R0 || HO01R2 || HO02R1 || HO01R3 || HO02R2)
	osSemaphoreDef(SemaphoreP6); PxSemaphoreHandle[P6] = osSemaphoreCreate(osSemaphore(SemaphoreP6), 1);
#endif

	/* Register command line commands */
	vRegisterCLICommands();
	
	/* Start the tasks that implements the command console on the UART */
	vUARTCommandConsoleStart();
	

	
}
void MX_FREERTOS_Init(void) {
  /* USER CODE BEGIN Init */
       
  /* USER CODE END Init */

  /* Create the recursive mutex(es) */
  /* definition and creation of uart2_mutex */
  osMutexDef(uart2_mutex);
  uart2_mutexHandle = osRecursiveMutexCreate(osMutex(uart2_mutex));

  /* definition and creation of mem_mutex */
  osMutexDef(mem_mutex);
  mem_mutexHandle = osRecursiveMutexCreate(osMutex(mem_mutex));

  /* definition and creation of sys_i2c_mutex */
  osMutexDef(sys_i2c_mutex);
  sys_i2c_mutexHandle = osRecursiveMutexCreate(osMutex(sys_i2c_mutex));

  /* definition and creation of rtc_mutex */
  osMutexDef(rtc_mutex);
  rtc_mutexHandle = osRecursiveMutexCreate(osMutex(rtc_mutex));

  /* definition and creation of imu_mutex */
  osMutexDef(imu_mutex);
  imu_mutexHandle = osRecursiveMutexCreate(osMutex(imu_mutex));

  /* definition and creation of eps_mutex */
  osMutexDef(eps_mutex);
  eps_mutexHandle = osRecursiveMutexCreate(osMutex(eps_mutex));

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

  /* Create the semaphores(s) */
  /* definition and creation of uart2_txSemaphore */
  osSemaphoreDef(uart2_txSemaphore);
  uart2_txSemaphoreHandle = osSemaphoreCreate(osSemaphore(uart2_txSemaphore), 1);

  /* definition and creation of mem_semaphore */
  osSemaphoreDef(mem_semaphore);
  mem_semaphoreHandle = osSemaphoreCreate(osSemaphore(mem_semaphore), 1);

  /* definition and creation of sys_i2c_semaphore */
  osSemaphoreDef(sys_i2c_semaphore);
  sys_i2c_semaphoreHandle = osSemaphoreCreate(osSemaphore(sys_i2c_semaphore), 1);

  /* definition and creation of radio_txSemaphore */
  osSemaphoreDef(radio_txSemaphore);
  radio_txSemaphoreHandle = osSemaphoreCreate(osSemaphore(radio_txSemaphore), 1);

  /* definition and creation of radio_rxSemaphore */
  osSemaphoreDef(radio_rxSemaphore);
  radio_rxSemaphoreHandle = osSemaphoreCreate(osSemaphore(radio_rxSemaphore), 1);

  /* definition and creation of eps_semaphore */
  osSemaphoreDef(eps_semaphore);
  eps_semaphoreHandle = osSemaphoreCreate(osSemaphore(eps_semaphore), 1);

  /* 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 defaultTask */
  osThreadDef(defaultTask, DefaultTask, osPriorityNormal, 0, 1024);
  defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);

  /* definition and creation of heartbeatTask */
  osThreadDef(heartbeatTask, HeartbeatTask, osPriorityNormal, 0, 1024);
  heartbeatTaskHandle = osThreadCreate(osThread(heartbeatTask), NULL);

  /* definition and creation of radio_TxTask */
  osThreadDef(radio_TxTask, He100_TxTask, osPriorityIdle, 0, 1024);
  radio_TxTaskHandle = osThreadCreate(osThread(radio_TxTask), NULL);

  /* definition and creation of radio_RxTask */
  osThreadDef(radio_RxTask, He100_RxTask, osPriorityHigh, 0, 1024);
  radio_RxTaskHandle = osThreadCreate(osThread(radio_RxTask), NULL);

  /* definition and creation of heapTask */
  osThreadDef(heapTask, HeapTask, osPriorityNormal, 0, 1024);
  heapTaskHandle = osThreadCreate(osThread(heapTask), NULL);

  /* definition and creation of downlinkTask */
  osThreadDef(downlinkTask, DownlinkTask, osPriorityNormal, 0, 1024);
  downlinkTaskHandle = osThreadCreate(osThread(downlinkTask), NULL);

  /* definition and creation of epsTask */
  osThreadDef(epsTask, EPSTask, osPriorityNormal, 0, 1024);
  epsTaskHandle = osThreadCreate(osThread(epsTask), NULL);

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

  /* USER CODE BEGIN RTOS_QUEUES */
  /* add queues, ... */
  InitializeRTOS();
  /* USER CODE END RTOS_QUEUES */
}
static void low_level_init(struct netif *netif)
{
  uint8_t macaddress[6];
  uint32_t regvalue = 0;

  // Get Ethernet MAC address
  stm32f_set_mac_addr((uint8_t*) macaddress);

  EthHandle.Instance = ETH;
  EthHandle.Init.MACAddr = macaddress;
  EthHandle.Init.AutoNegotiation = ETH_AUTONEGOTIATION_ENABLE;
  EthHandle.Init.Speed = ETH_SPEED_100M;
  EthHandle.Init.DuplexMode = ETH_MODE_FULLDUPLEX;
  EthHandle.Init.MediaInterface = ETH_MEDIA_INTERFACE_MII;
  EthHandle.Init.RxMode = ETH_RXINTERRUPT_MODE;
  EthHandle.Init.ChecksumMode = ETH_CHECKSUM_BY_HARDWARE;
  EthHandle.Init.PhyAddress = DP83848_PHY_ADDRESS;

  /* configure ethernet peripheral (GPIOs, clocks, MAC, DMA) */
  if (HAL_ETH_Init(&EthHandle) == HAL_OK)
  {
    /* Set netif link flag */
    netif->flags |= NETIF_FLAG_LINK_UP;
  }

  /* Initialize Tx Descriptors list: Chain Mode */
  HAL_ETH_DMATxDescListInit(&EthHandle, DMATxDscrTab, &Tx_Buff[0][0], ETH_TXBUFNB);

  /* Initialize Rx Descriptors list: Chain Mode  */
  HAL_ETH_DMARxDescListInit(&EthHandle, DMARxDscrTab, &Rx_Buff[0][0], ETH_RXBUFNB);

  /* set MAC hardware address length */
  netif->hwaddr_len = ETHARP_HWADDR_LEN;

  /* set netif MAC hardware address */
  stm32f_set_mac_addr((uint8_t*) netif->hwaddr);

  /* maximum transfer unit */
  netif->mtu = 1500;

  /* device capabilities */
  /* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
  netif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;

  /* Enable MAC and DMA transmission and reception */
  HAL_ETH_Start(&EthHandle);

  /**** Configure PHY to generate an interrupt when Eth Link state changes ****/
  /* Read Register Configuration */
  HAL_ETH_ReadPHYRegister(&EthHandle, PHY_MICR, &regvalue);

  regvalue |= (PHY_MICR_INT_EN | PHY_MICR_INT_OE);

  /* Enable Interrupts */
  HAL_ETH_WritePHYRegister(&EthHandle, PHY_MICR, regvalue );

  /* Read Register Configuration */
  HAL_ETH_ReadPHYRegister(&EthHandle, PHY_MISR, &regvalue);

  regvalue |= PHY_MISR_LINK_INT_EN;

  /* create a binary semaphore used for informing ethernetif of frame reception */
  osSemaphoreDef( SEM , rtems_build_name( 'E', 'T', 'H', 'I' ));
  s_xSemaphore = osSemaphoreCreate( osSemaphore( SEM ), 0 );

  /* create the task that handles the ETH_MAC */
  osThreadDef( EthIf,
    ethernetif_input,
    osPriorityRealtime,
    1,
    INTERFACE_THREAD_STACK_SIZE,
    rtems_build_name( 'E', 'T', 'H', 'I' ));

  osThreadCreate( osThread( EthIf ), netif );

  /* Enable Interrupt on change of link status */
  HAL_ETH_WritePHYRegister(&EthHandle, PHY_MISR, regvalue);
}
Exemple #21
0
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_SPI2_Init();
  MX_TIM1_Init();
  MX_TIM2_Init();

  /* USER CODE BEGIN 2 */
	InitMotor();
	HAL_TIM_Encoder_Start(&htim1,TIM_CHANNEL_ALL);


  /* USER CODE END 2 */

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

  /* Create the semaphores(s) */
  /* definition and creation of stopMoveByTime */
  osSemaphoreDef(stopMoveByTime);
  stopMoveByTimeHandle = osSemaphoreCreate(osSemaphore(stopMoveByTime), 1);

  /* definition and creation of suspendMoveByTime */
  osSemaphoreDef(suspendMoveByTime);
  suspendMoveByTimeHandle = osSemaphoreCreate(osSemaphore(suspendMoveByTime), 1);

  /* USER CODE BEGIN RTOS_SEMAPHORES */
  xSemaphoreTake(stopMoveByTimeHandle, 0);
  xSemaphoreTake(suspendMoveByTimeHandle, 0);
	/* add semaphores, ... */
  /* USER CODE END RTOS_SEMAPHORES */

  /* Create the timer(s) */
  /* definition and creation of elapsedTimer */
  osTimerDef(elapsedTimer, elapsedTimerCallback);
  elapsedTimerHandle = osTimerCreate(osTimer(elapsedTimer), osTimerPeriodic, NULL);

  /* definition and creation of moveTimer */
  osTimerDef(moveTimer, moveTimerCallback);
  moveTimerHandle = osTimerCreate(osTimer(moveTimer), osTimerPeriodic, NULL);

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

  /* Create the thread(s) */
  /* definition and creation of defaultTask */
  osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 64);
  defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);

  /* definition and creation of buttonScanTask */
  osThreadDef(buttonScanTask, buttonScanFunc, osPriorityLow, 0, 128);
  buttonScanTaskHandle = osThreadCreate(osThread(buttonScanTask), NULL);

  /* definition and creation of guiTask */
  osThreadDef(guiTask, guiFunc, osPriorityNormal, 0, 128);
  guiTaskHandle = osThreadCreate(osThread(guiTask), NULL);

  /* definition and creation of motorTask */
  osThreadDef(motorTask, motorFunc, osPriorityAboveNormal, 0, 64);
  motorTaskHandle = osThreadCreate(osThread(motorTask), NULL);

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

  /* Create the queue(s) */
  /* definition and creation of buttonEvents */
  osMessageQDef(buttonEvents, 16, uint16_t);
  buttonEventsHandle = osMessageCreate(osMessageQ(buttonEvents), NULL);

  /* definition and creation of encoderEvents */
  osMessageQDef(encoderEvents, 16, uint16_t);
  encoderEventsHandle = osMessageCreate(osMessageQ(encoderEvents), NULL);

  /* USER CODE BEGIN RTOS_QUEUES */
	/* add queues, ... */
  xInputEvents = xQueueCreate( 8, sizeof( struct Event ) );
  xMotorEvents = xQueueCreate( 4, sizeof( struct MotorEvent ) );
  /* 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 */

}
Exemple #22
0
void initDriveSemaphores(void)
{
    osSemaphoreDef(driveUpdaterSemaphore);
    driveUpdaterHandle = osSemaphoreCreate(osSemaphore(driveUpdaterSemaphore), 1);
}
Exemple #23
0
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_USART2_UART_Init();

  /* USER CODE BEGIN 2 */

  /* Create the threads and semaphore */
//  osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
//  defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
  osThreadDef(blinkTask, BlinkTask, osPriorityNormal, 0, 128);
  blinkTaskHandle = osThreadCreate(osThread(blinkTask), NULL);
  osSemaphoreDef(sem);
  semHandle = osSemaphoreCreate(osSemaphore(sem), 1);
  osSemaphoreWait(semHandle, osWaitForever);

  /* 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 defaultTask */
  osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
  defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);

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

  /* USER CODE BEGIN RTOS_QUEUES */
  /* add queues, ... */
  /* 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 */

}