コード例 #1
0
/*----------------------------------------------------------------------------
 *   Main:
 *---------------------------------------------------------------------------*/
int main (void) {                     /* program execution starts here       */

  semaphore = osSemaphoreCreate(osSemaphore(semaphore), 1);

  tid_thread1 = osThreadCreate(osThread(thread1), NULL);
  tid_thread2 = osThreadCreate(osThread(thread2), NULL);

  osDelay(osWaitForever);
  for (;;);
}
コード例 #2
0
/**
  * @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);
}
コード例 #3
0
ファイル: Semaphore.c プロジェクト: AdrK/STM32F7_ADC_DMA_LCD
int Init_Semaphore (void) {

  sid_Thread_Semaphore = osSemaphoreCreate (osSemaphore(SampleSemaphore), 1);
  if (!sid_Thread_Semaphore) {
    ; // Semaphore object not created, handle failure
  }
  
  tid_Thread_Semaphore = osThreadCreate (osThread(Thread_Semaphore), NULL);
  if (!tid_Thread_Semaphore) return(-1);
  
  return(0);
}
コード例 #4
0
s32 bsp_rfile_init(void)
{
    s32 ret;

	g_stRfileMain.semAll = osSemaphoreCreate(osSemaphore(rfile_all_sem), 1);

	g_stRfileMain.semReq = osSemaphoreCreate(osSemaphore(rfile_req_sem), 0);

    ret = bsp_icc_event_register(RFILE_MCORE_ICC_RD_CHAN, bsp_RfileCallback, NULL, NULL, NULL);
    if(ret)
    {
        bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_RFILE, "[%s] bsp_icc_event_register failed.\n", __FUNCTION__);
        return BSP_ERROR;
    }

    g_stRfileMain.bInitFlag = BSP_TRUE;

//    bsp_trace(BSP_LOG_LEVEL_ERROR, BSP_MODU_RFILE, "[%s] success.\n", __FUNCTION__);

    return BSP_OK;
}
コード例 #5
0
ファイル: main.c プロジェクト: acrepina/STM32F7_serverWEB
/**
  * @brief  Network interface configuration
  * @param  None
  * @retval None
  */
static void Netif_Config(void)
{
  struct ip_addr ipaddr;
  struct ip_addr netmask;
  struct ip_addr gw;	
  
  /* IP address default 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 */
  osThreadDef(LinkThr, ethernetif_set_link, osPriorityNormal, 0, configMINIMAL_STACK_SIZE);
  osThreadCreate (osThread(LinkThr), &link_arg);
}
コード例 #6
0
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;
}
コード例 #7
0
/*! 
    \brief Initializing Semaphore
		\return 0=successful; -1=failure
*/
int Init_Semaphore1 (void) 
{
  //TWPV1 create with count = 1
	sid_Semaphore1 = osSemaphoreCreate(osSemaphore(Semaphore1), 1,osPriorityAboveNormal);
  if (!sid_Semaphore1)  {
//TWP    if (addTrace("sem1 could not create") != TRACE_OK)
//TWP		{
//TWP			stop_cpu;
//TWP		}
		return (-1);
  } 
	printf("created sem1\n\r");
  return(0);
}
コード例 #8
0
ファイル: menu.c プロジェクト: z80/stm32f429
/**
  * @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);
}
/**
  * @brief  create a thread for temperature measurement
  * @param  None
  * @retval The thread ID for temperature
  */
osThreadId  temperature_Thread_Create(void)
{
  //initialize ADC
	temperature_Init();
  pwm_alarm_init();
  //create semaphore
  tempeature_semaphore = osSemaphoreCreate(osSemaphore(tempeature_semaphore), 1);
	//initialize filter
  filter_init(&temperature_filter_struct, 20);
  temperature_filter_struct.mutexId = osMutexCreate(osMutex (temperatureFilterMutex));
  
  //create temperature thread
  tempeature_thread_id = osThreadCreate(osThread(temperature_Thread), NULL);
  return tempeature_thread_id;
}
コード例 #10
0
ファイル: menu.c プロジェクト: z80/stm32f429
/**
  * @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");  
}
コード例 #11
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);
  
  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");
}
コード例 #12
0
void InitializeAppShooter()
{
  TimerId = osTimerCreate (osTimer(PeriodicTimer), osTimerPeriodic, NULL);
  if (TimerId) {
    osTimerStart (TimerId, 8);
  }
	
  /* Prepare display */
	GLCD_SetBackgroundColor (GLCD_COLOR_BLACK);
  GLCD_SetForegroundColor (GLCD_COLOR_WHITE);
  GLCD_ClearScreen();
	
	// Variables initialization
	timerTick_01 = 0;										// Timer counter for Main
	timerTick_02 = 0;										// Timer counter for drawing the Objects
	plane_x = 0;												// Plane X position
	plane_y = 110;											// Plane Y position
	actualBallNumber = 0;
	newBall = false;										// Tells to the routine S_MoveBall to create a new ball
	objectNumb = 0;
	objectColor = 1;
	stopThreads = false;
	ballTimer = 0;
	stopShooter = false;
	playerScore = 0;
	machineScore = 0;
	
	S_IncPlayerScore();
	S_IncMachineScore();
	
	if(S_firstTime){
		glcd_semaph_id = osSemaphoreCreate(osSemaphore(glcd_semaph), 1); // Semaphore binaire, only one thread at the same time
		planeVar_mutex_id = osMutexCreate(osMutex(planeVar_mutex));
		objectVar_mutex_id = osMutexCreate(osMutex(objectVar_mutex));
		S_firstTime = false;
	}
	
	idThreadPlane = osThreadCreate (osThread (S_Thread_MovePlane), NULL);   // create the thread

}
コード例 #13
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 */
#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");
}
コード例 #14
0
ファイル: comm.c プロジェクト: tusimbe/battery
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;
}
コード例 #15
0
ファイル: main-ex4.c プロジェクト: Shreeyak/mastering-stm32
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);
}
コード例 #16
0
ファイル: freertos.c プロジェクト: OUWECAD/MOWE
/* 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();
	

	
}
コード例 #17
0
ファイル: main.c プロジェクト: pauliusbau/electronics-farm
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 */

}
コード例 #18
0
ファイル: m_serial.cpp プロジェクト: jackeyjiang/meizi_f7disc
void serial::setSem(void) {
    semTxReady = osSemaphoreCreate(osSemaphore(semTxReady),0);
    semRxReady = osSemaphoreCreate(osSemaphore(semRxReady),0);
    printMutexId = osMutexCreate(osMutex(printMutexId));
}
コード例 #19
0
void dma_init(void)	{
	dmaSema_ID = osMutexCreate(osMutex(dmaSema));
	dmaComplete_ID = osSemaphoreCreate(osSemaphore(dmaComplete), 1);
	
	   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);

	
	// SPI_InitTypeDef  SPI_InitStructure;
	DMA_InitTypeDef  DMA_InitStructure;
	NVIC_InitTypeDef NVIC_InitStructure;
	
	DMA_Cmd(DMA2_Stream0, DISABLE); //disable receiver
	DMA_Cmd(DMA2_Stream3, DISABLE);	//disable transmitter
    
    DMA_DeInit(DMA2_Stream0);	//place default values 
	DMA_DeInit(DMA2_Stream3); 
	
	DMA_ClearFlag(DMA2_Stream0, DMA_FLAG_TCIF0);	//transfer complete
	DMA_ClearFlag(DMA2_Stream3, DMA_FLAG_TCIF3); 
  
	DMA_ClearFlag(DMA2_Stream0, DMA_FLAG_TEIF0);	//transfer error
	DMA_ClearFlag(DMA2_Stream3, DMA_FLAG_TEIF3); 
  
	DMA_ClearFlag(DMA2_Stream0, DMA_FLAG_FEIF0); //FIFO error
	DMA_ClearFlag(DMA2_Stream3, DMA_FLAG_FEIF3); 
  
	DMA_ClearFlag(DMA2_Stream0, DMA_FLAG_DMEIF0); //direct mode error
	DMA_ClearFlag(DMA2_Stream3, DMA_FLAG_DMEIF3);
      
    /* Start DMA2 clock */
    
	// Configure DMA streams
	DMA_InitStructure.DMA_Channel = DMA_Channel_3;
	DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(SPI1->DR);
	DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
	DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
	DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
	DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
	DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
	DMA_InitStructure.DMA_Priority = DMA_Priority_High;
	DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
	DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull;  //not needed
	DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
	DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
	
    //receiving
	DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
	DMA_Init(DMA2_Stream0, &DMA_InitStructure);
  
	//sending
	DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; 
	DMA_Init(DMA2_Stream3, &DMA_InitStructure);
    
    
	//enable
	SPI_DMACmd(SPI1, SPI_DMAReq_Rx | SPI_DMAReq_Tx, ENABLE);   
  
	//Setting up interrupt
	NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream0_IRQn; 
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; 
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; 
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 
	NVIC_Init(&NVIC_InitStructure); 
  
  
	//enable receiving
	DMA_ITConfig(DMA2_Stream0, DMA_IT_TC, ENABLE);

}
コード例 #20
0
ファイル: drive.c プロジェクト: vpcola/stm32f4
void initDriveSemaphores(void)
{
    osSemaphoreDef(driveUpdaterSemaphore);
    driveUpdaterHandle = osSemaphoreCreate(osSemaphore(driveUpdaterSemaphore), 1);
}
コード例 #21
0
ファイル: main.c プロジェクト: sincoon/injex
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 */

}
コード例 #22
0
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);
}
コード例 #23
0
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 */
}