示例#1
0
static err_t low_level_output(struct netif *netif, struct pbuf *p)
{
  static xSemaphoreHandle xTxSemaphore = NULL;
  struct pbuf *q;
  u32_t l = 0;

  if( xTxSemaphore == NULL )
  {
      vSemaphoreCreateBinary( xTxSemaphore );
  }


#if ETH_PAD_SIZE
  pbuf_header(p, -ETH_PAD_SIZE);			/* drop the padding word */
#endif


  /* Access to the EMAC is guarded using a semaphore. */
  if( xSemaphoreTake( xTxSemaphore, netifGUARD_BLOCK_TIME ) )
  {
      for(q = p; q != NULL; q = q->next) {
        /* Send the data from the pbuf to the interface, one pbuf at a
           time. The size of the data in each pbuf is kept in the ->len
           variable. */
        memcpy(&TxBuff[l], (u8_t*)q->payload, q->len);
        l += q->len;
      }

      ENET_TxPkt(0, l);

      #if ETH_PAD_SIZE
        pbuf_header(p, ETH_PAD_SIZE);			/* reclaim the padding word */
      #endif

      #if LINK_STATS
        lwip_stats.link.xmit++;
      #endif /* LINK_STATS */

      xSemaphoreGive( xTxSemaphore );
  }

  return ERR_OK;
}
示例#2
0
文件: STBT.c 项目: yerpj/F3000
void STBT_Init(COM_TypeDef SerialCOM)
{
  USART_InitTypeDef USART_InitStruct;
  BT_State=Active_Command_mode;
  BTCOM=SerialCOM;
  
  USART_InitStruct.USART_BaudRate=115200;
  USART_InitStruct.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
  USART_InitStruct.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
  USART_InitStruct.USART_Parity=USART_Parity_No;
  USART_InitStruct.USART_StopBits=USART_StopBits_1;
  USART_InitStruct.USART_WordLength=USART_WordLength_8b;
  
  CU_COMInit(SerialCOM,&USART_InitStruct);
  vSemaphoreCreateBinary(BT_UART_sem);
  BT_UART_RX_Queue = xQueueCreate( 100, sizeof( uint8_t ) );

  xTaskCreate(STBT_Task, "BlueTooth", 5*configMINIMAL_STACK_SIZE, NULL, 9, NULL);
}
示例#3
0
struct pios_semaphore *PIOS_Semaphore_Create(void)
{
	struct pios_semaphore *sema = PIOS_malloc(sizeof(struct pios_semaphore));

	if (sema == NULL)
		return NULL;

	/*
	 * The initial state of a binary semaphore is "given".
	 * FreeRTOS executes a "give" upon creation.
	 */
#if defined(PIOS_INCLUDE_FREERTOS)
	vSemaphoreCreateBinary(sema->sema_handle);
#else
	sema->sema_count = 1;
#endif

	return sema;
}
示例#4
0
文件: main.c 项目: HclX/freertos
int main( void )
{
	/* Setup the peripheral bus to be the same as the PLL output. */
	VPBDIV = mainBUS_CLK_FULL;

	/* Create the queue used to pass message to vPrintTask. */
	xPrintQueue = xQueueCreate( mainQUEUE_SIZE, sizeof( char * ) );

	/* Create the semaphore used to wake vButtonHandlerTask(). */
	vSemaphoreCreateBinary( xButtonSemaphore );
	xSemaphoreTake( xButtonSemaphore, 0 );

	/* Start the standard demo tasks. */
	vStartIntegerMathTasks( tskIDLE_PRIORITY );
	vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
	vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
	vStartDynamicPriorityTasks();
	vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );

	#if configUSE_PREEMPTION == 1
	{
		/* The timing of console output when not using the preemptive
		scheduler causes the block time tests to detect a timing problem. */
		vCreateBlockTimeTasks();
	}
	#endif

    vStartRecursiveMutexTasks();

	/* Start the tasks defined within this file. */
	xTaskCreate( vLEDTask, "LED", configMINIMAL_STACK_SIZE, NULL, mainLED_TASK_PRIORITY, NULL );
    xTaskCreate( vCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
    xTaskCreate( vPrintTask, "Print", configMINIMAL_STACK_SIZE, NULL, mainPRINT_TASK_PRIORITY, NULL );
    xTaskCreate( vButtonHandlerTask, "Button", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );

	/* Start the scheduler. */
	vTaskStartScheduler();

	/* The scheduler should now be running, so we will only ever reach here if we
	ran out of heap space. */

	return 0;
}
示例#5
0
int main(void)
{
    //Start the HW
	initHardware();
  ciaaWriteOutput(3,0); 
  // Create a semaphore
  vSemaphoreCreateBinary(xSemaphore);
  xSemaphoreTake(xSemaphore,0);
    //Create task to read the button
	xTaskCreate(taskReadButton, (const char *)"taskReadButton", configMINIMAL_STACK_SIZE*2, 0, tskIDLE_PRIORITY+1, 0);
    
    //Create task to blick the led
  xTaskCreate(taskBlickLed, (const char *)"taskReadButton", configMINIMAL_STACK_SIZE*2, 0, tskIDLE_PRIORITY+1, 0);

    //Start the Scheduler
	vTaskStartScheduler();

	while (1) {
	}
}
示例#6
0
void SHT10Init(void) {
	GPIO_InitTypeDef GPIO_InitStructure;
	if (__semaphore != NULL) {
		return;
	}

	vSemaphoreCreateBinary(__semaphore);

	GPIO_InitStructure.GPIO_Pin = CLK_GPIO_PIN;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
	GPIO_Init(CLK_GPIO_PORT, &GPIO_InitStructure);

	GPIO_InitStructure.GPIO_Pin = DAT_GPIO_PIN;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
	GPIO_Init(DAT_GPIO_PORT, &GPIO_InitStructure);

	__clkSetLow();
	__clkDataLow();
}
示例#7
0
int main()
{
	init_rs232();
	enable_rs232_interrupts();
	enable_rs232();
	
	fs_init();
	fio_init();
    
    //register_fs(&ramfs_r);
    register_devfs();
    register_ramfs();
    fs_mount(NULL, RAMFS_TYPE, NULL);

//	register_romfs("romfs", &_sromfs);
//	register_ramfs("ramfs");
	
	/* Create the queue used by the serial task.  Messages for write to
	 * the RS232. */
	vSemaphoreCreateBinary(serial_tx_wait_sem);
	/* Add for serial input 
	 * Reference: www.freertos.org/a00116.html */
	serial_rx_queue = xQueueCreate(1, sizeof(char));

	/* Create a task to output text read from romfs. */
	xTaskCreate(command_prompt,
	            "CLI",
	            512 /* stack size */, NULL, tskIDLE_PRIORITY + 2, NULL);

#if 0
	/* Create a task to record system log. */
	xTaskCreate(system_logger,
	            (signed portCHAR *) "Logger",
	            1024 /* stack size */, NULL, tskIDLE_PRIORITY + 1, NULL);
#endif

	/* Start running the tasks. */
	vTaskStartScheduler();

	return 0;
}
portBASE_TYPE xNetworkInterfaceInitialise( void )
{
EMAC_CFG_Type Emac_Config;
PINSEL_CFG_Type xPinConfig;
portBASE_TYPE xStatus, xReturn;
extern uint8_t ucMACAddress[ 6 ];

	/* Enable Ethernet Pins */
	boardCONFIGURE_ENET_PINS( xPinConfig );

	Emac_Config.Mode = EMAC_MODE_AUTO;
	Emac_Config.pbEMAC_Addr = ucMACAddress;
	xStatus = EMAC_Init( &Emac_Config );

	LPC_EMAC->IntEnable &= ~( EMAC_INT_TX_DONE );

	if( xStatus != ERROR )
	{
		vSemaphoreCreateBinary( xEMACRxEventSemaphore );
		configASSERT( xEMACRxEventSemaphore );

		/* The handler task is created at the highest possible priority to
		ensure the interrupt handler can return directly to it. */
		xTaskCreate( prvEMACHandlerTask, ( const signed char * const ) "EMAC", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );

		/* Enable the interrupt and set its priority to the minimum
		interrupt priority.  */
		NVIC_SetPriority( ENET_IRQn, configMAC_INTERRUPT_PRIORITY );
		NVIC_EnableIRQ( ENET_IRQn );

		xReturn = pdPASS;
	}
	else
	{
		xReturn = pdFAIL;
	}

	configASSERT( xStatus != ERROR );

	return xReturn;
}
static void low_level_init( struct netif *pnetif )
{
	// set MAC hardware address length 
	pnetif->hwaddr_len = ETHARP_HWADDR_LEN;

	// set MAC hardware address 
	//MACStrToBin( DEFAULT_MAC_ADDR, pnetif->hwaddr );
	pnetif->hwaddr[ 0 ] = 0x00;
	pnetif->hwaddr[ 1 ] = 0x04;
	pnetif->hwaddr[ 2 ] = 0xa3;
	pnetif->hwaddr[ 3 ] = 0x00;
	pnetif->hwaddr[ 4 ] = 0x00;
	pnetif->hwaddr[ 5 ] = 0x02;

	// maximum transfer unit 
	pnetif->mtu = netifMTU;

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

	// Do whatever else is needed to initialize interface. 
	
	if ( s_xSemaphore == NULL )
	{
		vSemaphoreCreateBinary( s_xSemaphore );
		xSemaphoreTake( s_xSemaphore,  0);
	}

	// Initialise the MAC. 
	enc28j60_MACInit( pnetif );
		
	pnetif->flags |= NETIF_FLAG_LINK_UP;

	// Create the task that handles the EMAC. 
	sys_thread_new( ( signed portCHAR *)"eth", 
                        ethernetif_input, 
                        (void *)pnetif, 
                        netifINTERFACE_TASK_STACK_SIZE, 
                        netifINTERFACE_TASK_PRIORITY );
}	
示例#10
0
//---------------------------------------------------------------------------------------------
static void setup_debug_port_peri(void)
{
    USART_InitTypeDef USART_InitStructure;
    GPIO_InitTypeDef GPIO_InitStructure;

    txchars_queue = xQueueCreate(100, sizeof(signed char));
    vSemaphoreCreateBinary(xRxCompleteSemaphore);
    xSemaphoreTake(xRxCompleteSemaphore, 0);

    /* Enable USART1 clock */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);

    /* Configure USART1 Rx (PA10) as input floating */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    /* Configure USART1 Tx (PA9) as alternate function push-pull */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    USART_InitStructure.USART_BaudRate = 115200;
    USART_InitStructure.USART_WordLength = USART_WordLength_8b;
    USART_InitStructure.USART_StopBits = USART_StopBits_1;
    USART_InitStructure.USART_Parity = USART_Parity_No;
    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

    USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
    USART_ITConfig(USART1, USART_IT_TXE, DISABLE);

    /* Configure the USARTx */
    USART_Init(USART1, &USART_InitStructure);

    NVIC_EnableIRQ(USART1_IRQn);

    /* Enable the USARTx */
    USART_Cmd(USART1, ENABLE);
}
示例#11
0
/**
 * Initialize the UAVTalk library
 * \param[in] connection UAVTalkConnection to be used
 * \param[in] outputStream Function pointer that is called to send a data buffer
 * \return 0 Success
 * \return -1 Failure
 */
UAVTalkConnection UAVTalkInitialize(UAVTalkOutputStream outputStream)
{
	// allocate object
	UAVTalkConnectionData * connection = pvPortMalloc(sizeof(UAVTalkConnectionData));
	if (!connection) return 0;
	connection->canari = UAVTALK_CANARI;
	connection->iproc.rxPacketLength = 0;
	connection->iproc.state = UAVTALK_STATE_SYNC;
	connection->outStream = outputStream;
	connection->lock = xSemaphoreCreateRecursiveMutex();
	connection->transLock = xSemaphoreCreateRecursiveMutex();
	// allocate buffers
	connection->rxBuffer = pvPortMalloc(UAVTALK_MAX_PACKET_LENGTH);
	if (!connection->rxBuffer) return 0;
	connection->txBuffer = pvPortMalloc(UAVTALK_MAX_PACKET_LENGTH);
	if (!connection->txBuffer) return 0;
	vSemaphoreCreateBinary(connection->respSema);
	xSemaphoreTake(connection->respSema, 0); // reset to zero
	UAVTalkResetStats( (UAVTalkConnection) connection );
	return (UAVTalkConnection) connection;
}
示例#12
0
文件: supervisor.c 项目: lirihe/arm
int sv_init(uint32_t initial_timeout) {

	/* Init list semaphore */
	vSemaphoreCreateBinary(sv_sem);
	if (sv_sem == NULL) {
		printf("Failed to create supervisor semaphore\r\n");
		return -1;
	}

	/* Set maximum timeout */
	interval = initial_timeout;

	/* Start task */
	if (xTaskCreate(&sv_task, (signed char *)"SV", 1024, NULL, configMAX_PRIORITIES - 1, NULL) != pdPASS) {
		printf("Failed to create supervisor task\r\n");
		return -1;
	}

	return 0;

}
示例#13
0
static void prvSetupEMACInterrupt( void )
{
	/* Create the semaphore used to trigger the EMAC task. */
	vSemaphoreCreateBinary( xSemaphore );
	if( xSemaphore )
	{
		/* We start by 'taking' the semaphore so the ISR can 'give' it when the
		first interrupt occurs. */
		xSemaphoreTake( xSemaphore, emacNO_DELAY );
		portENTER_CRITICAL();
		{
			/* We want to interrupt on Rx and Tx events. */
			AT91C_BASE_EMAC->EMAC_IER = AT91C_EMAC_RCOMP | AT91C_EMAC_TCOMP;

			/* Enable the interrupts in the AIC. */
			AT91F_AIC_ConfigureIt( AT91C_ID_EMAC, emacINTERRUPT_LEVEL, AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL, ( void (*)( void ) ) vEMACISR_Wrapper );
            AT91C_BASE_AIC->AIC_IECR = 0x1 << AT91C_ID_EMAC;
		}
		portEXIT_CRITICAL();
	}
}
示例#14
0
//---------------------------------------------------------------------------------------------
static void setup_uart(struct UartPort *port)
{
    port->cache_tx.queue = xQueueCreate(port->cache_tx.queue_length, sizeof(uint8_t)); 
    port->cache_rx.queue = xQueueCreate(port->cache_rx.queue_length, sizeof(uint8_t)); 
    vSemaphoreCreateBinary(port->sem); 
    xSemaphoreTake(port->sem, 0);

    RCC_APB1PeriphClockCmd(port->peri->periph, ENABLE); 

    setup_uart_port(&port->peri->tx, &port->peri->rx);
    setup_uart_setting(port->peri, port->setting);

    /* Enable USART2 Receive and Transmit interrupts */
    USART_ITConfig(port->peri->uart, USART_IT_RXNE, ENABLE);
    USART_ITConfig(port->peri->uart, USART_IT_TXE, DISABLE);

    NVIC_EnableIRQ(port->peri->irq); 

    /* Enable the USARTx */
    USART_Cmd(port->peri->uart, ENABLE);
}
示例#15
0
void FreeRTOS_Configuration(void)
{
 
  // Create semaphore
  vSemaphoreCreateBinary(dataSemaphore);
  
  // Semaphore not created
  while(dataSemaphore == NULL);
  
  xSemaphoreTake(dataSemaphore, 0);
  
  // Task Creations
  xTaskCreate(vTaskDetectEmergency, NULL, 100, NULL, (tskIDLE_PRIORITY + 5), NULL);
  xTaskCreate(vTaskRefreshSensorData, NULL, 100, NULL, (tskIDLE_PRIORITY + 4), NULL);
  xTaskCreate(vTaskCalculateOrientation, NULL, 100, NULL, (tskIDLE_PRIORITY + 3), NULL);
  //xTaskCreate(vTaskUpdatePid, NULL, 100, NULL, (tskIDLE_PRIORITY + 2), NULL);
  xTaskCreate(vTaskLogDebugInfo, NULL, 100, NULL, (tskIDLE_PRIORITY + 1), NULL);
  xTaskCreate(vTaskRLED, NULL, 100, NULL, tskIDLE_PRIORITY, NULL);
  xTaskCreate(vTaskGLED, NULL, 100, NULL, tskIDLE_PRIORITY, NULL);
  
}
void vCDCCommandConsoleStart( uint16_t usStackSize, unsigned portBASE_TYPE uxPriority )
{
	/* Create the semaphores and mutexes used by the CDC to task interface. */
	xCDCMutex = xSemaphoreCreateMutex();
	vSemaphoreCreateBinary( xNewDataSemaphore );
	configASSERT( xCDCMutex );
	configASSERT( xNewDataSemaphore );

	/* Add the semaphore and mutex to the queue registry for viewing in the
	kernel aware state viewer. */
	vQueueAddToRegistry( xCDCMutex, "CDCMu" );
	vQueueAddToRegistry( xNewDataSemaphore, "CDCDat" );

	/* Create that task that handles the console itself. */
	xTaskCreate( 	prvCDCCommandConsoleTask,	/* The task that implements the command console. */
					"CDCCmd",					/* Text name assigned to the task.  This is just to assist debugging.  The kernel does not use this name itself. */
					usStackSize,				/* The size of the stack allocated to the task. */
					NULL,						/* The parameter is not used, so NULL is passed. */
					uxPriority,					/* The priority allocated to the task. */
					NULL );						/* A handle is not required, so just pass NULL. */
}
示例#17
0
void init_threshold_control(void)
{
	xTaskHandle task;
	threshold_queue = xQueueCreate(1, sizeof(struct threshold));
	if (threshold_queue == NULL)
		panic("xQueueCreate failed");
	vSemaphoreCreateBinary(threshold_sem);
	if (threshold_sem == NULL)
		panic("vSemaphoreCreateBinary failed");
	xTaskCreate(threshold_control_task, "threshold_control", configMINIMAL_STACK_SIZE,
		    NULL, tskIDLE_PRIORITY+1, &task);

	// initialise ps2 (keyboard) device, register keyboard irq
	alt_up_ps2_dev *ps2_device = alt_up_ps2_open_dev(PS2_NAME);
	if (ps2_device == NULL)
		panic("unable to open ps2 device");
	alt_up_ps2_clear_fifo (ps2_device);
	alt_irq_register(PS2_IRQ, ps2_device, do_keyboard_irq);
	// register the PS/2 interrupt
	IOWR_8DIRECT(PS2_BASE,4,1);
}
示例#18
0
int main( void )
{
	LPC_IOCON->PIO0_7 = 0x30;	 // configure PIO0_7 as an input with hysteresis
	LPC_GPIO0->IS  &= ~(1<<7);   // edge trigger
	LPC_GPIO0->IBE &= ~(1<<7);   // control based on IEV register
	LPC_GPIO0->IEV &= ~(1<<7);   // falling edge
	LPC_GPIO0->IE  |= (1<<7);    // enable interrupt

	LPC_GPIO0->DIR |= (1<<6);	/* Set up P0.7 as output */
	LPC_GPIO0->DATA &= ~(1<<6);	/* Turn off LED2 on LPCXpresso board */

	init_lcd();

//--------- Lab edit begin ---------
	vSemaphoreCreateBinary(ButtonSemaphore);

	/* Create one of the three tasks. */
	xTaskCreate(	vTaskLEDBlinker1,	/* Pointer to the function that implements the task. */
				    (const signed portCHAR *)"Blinker 1",		/* Text name for the task.  This is to facilitate debugging only. */
				    configMINIMAL_STACK_SIZE,		/* Stack depth in words. */
					NULL,		/* We are not using the task parameter. */
					3,			/* This task will run at priority 3. */
					NULL );		/* We are not using the task handle. */

	/* Create the other tasks in exactly the same way. */
	xTaskCreate( vTaskDebuggerHeartbeat, (const signed portCHAR *)"Heartbeat", configMINIMAL_STACK_SIZE, NULL, 3, NULL);
	xTaskCreate( vTaskLcdDisplay, (const signed portCHAR *)"Display", configMINIMAL_STACK_SIZE, NULL, 3, NULL);

	NVIC_SetPriority( EINT0_IRQn, 0);
	NVIC_EnableIRQ( EINT0_IRQn );

	/* Start the scheduler so our tasks start executing. */
	vTaskStartScheduler();

	/* If all is well we will never reach here as the scheduler will now be
	running.  If we do reach here then it is likely that there was insufficient
	heap available for the idle task to be created. */
	for( ;; );
	return 0;
}
示例#19
0
文件: twi.c 项目: FlameN/STM32RUNO
//===============================================================================================
//*----------------------------------------------------------------------------
//* \fn    AT91F_TWI_Open
//* \brief Initializes TWI device
//*----------------------------------------------------------------------------
void AT91F_TWI_Init(void)
{


        TWI_QUEUE = xQueueCreate( 1, sizeof( unsigned int ) );
        TWI_NACK_Error = ErrorCreate("TWI Nack");
        TWI_TMO_Error  = ErrorCreate("TWI TimeOut");
        TWI_SEM_Error  = ErrorCreate("TWI Access");
        TWI_WriteData_Error = ErrorCreate("TWI Write");
        TWI_OVRE_Error = ErrorCreate("TWI OVRE");
         vSemaphoreCreateBinary( TWI_Semaphore );
        while( TWI_QUEUE == 0 ) ;    // Queue was not created and must not be used.
        portENTER_CRITICAL();
        {
 	 // Configure TWI in master mode
	 AT91F_TWI_Configure (AT91C_BASE_TWI);
         // Configure TWI PIOs
      	 AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, AT91C_PA1_TWCK );
         AT91F_PIO_CfgOpendrain(AT91C_BASE_PIOA, // PIO controller base address
    		                ((unsigned int) AT91C_PA1_TWCK    ) |
      		                ((unsigned int) AT91C_PA0_TWD  )  );

         AT91F_TWI_CfgPIO();

         // Configure PMC by enabling TWI clock
	 AT91F_TWI_CfgPMC ();
    	 // AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1<<AT91C_ID_TWI ) ;
	 // Set TWI Clock Waveform Generator Register
 	 AT91F_SetTwiClock();
         AT91F_AIC_ConfigureIt ( AT91C_BASE_AIC,
                                AT91C_ID_TWI,
                                TWI_INTERRUPT_LEVEL,
                                AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE,
                                ( void (*)( void ) )AT91_TWI_ISR_ENTRY);

  	 AT91F_AIC_EnableIt (AT91C_BASE_AIC, AT91C_ID_TWI);
        TWI_TransferStatus = FREE;
        }
        portEXIT_CRITICAL();
}
示例#20
0
TaskToken ActivateTask(TaskID 		enTaskID,
						portCHAR 	*pcTaskName,
						TASK_TYPE 	enTaskType,
						unsigned 	portBASE_TYPE uxPriority,
						unsigned 	portSHORT usStackSize,
						pdTASK_CODE pvTaskFunction)
{
	TaskToken taskToken = NULL;

	//catch NO task name input
	if (pcTaskName == NULL) return NULL;

	taskENTER_CRITICAL();
	{
		//detect task already exist
		if (TaskTokens[enTaskID].pcTaskName == NULL)
		{
			//create task
			xTaskCreate(pvTaskFunction, (signed portCHAR *)pcTaskName, usStackSize, NULL, uxPriority, &TaskHandles[enTaskID]);

			//store task profile in array
			TaskTokens[enTaskID].pcTaskName		= pcTaskName;
			TaskTokens[enTaskID].enTaskType		= enTaskType;
			TaskTokens[enTaskID].enTaskID		= enTaskID;

			//create semaphore for task
			vSemaphoreCreateBinary(TaskSemphrs[enTaskID]);

			//exhaust task semaphore
			xSemaphoreTake(TaskSemphrs[enTaskID], NO_BLOCK);

			taskToken = &TaskTokens[enTaskID];
		}
	}
	taskEXIT_CRITICAL();
	
	//return pointer to task profile
	return taskToken;
}
示例#21
0
int ff_cre_syncobj (	/* !=0:Function succeeded, ==0: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;

//
//	*sobj = CreateMutex(NULL, FALSE, NULL);		/* Win32 */
//	ret = (int)(*sobj != INVALID_HANDLE_VALUE);

//	*sobj = SyncObjects[vol];			/* uITRON (give a static created sync object) */
//	ret = 1;							/* The initial value of the semaphore must be 1. */

//	*sobj = OSMutexCreate(0, &err);		/* uC/OS-II */
//	ret = (int)(err == OS_NO_ERR);

	vSemaphoreCreateBinary( (*sobj) );	/* FreeRTOS */
	ret = (int)(*sobj != NULL);

	return ret;
}
示例#22
0
int main(void) {
	prvSetupHardware();

	vSemaphoreCreateBinary(sem);

	xSemaphoreTake(sem, portMAX_DELAY);

	xTaskCreate(task_pwm, (signed char * ) "task_pwm", configMINIMAL_STACK_SIZE,
			NULL, (tskIDLE_PRIORITY + 1UL), (xTaskHandle *) NULL);

	xTaskCreate(task_pwm_alt, (signed char * ) "task_pwm_alt",
			configMINIMAL_STACK_SIZE, NULL, (tskIDLE_PRIORITY + 1UL),
			(xTaskHandle *) NULL);

	xTaskCreate(task_control, (signed char * ) "task_control",
			configMINIMAL_STACK_SIZE, NULL, (tskIDLE_PRIORITY + 1UL),
			(xTaskHandle *) NULL);

	vTaskStartScheduler();

	return 1;
}
示例#23
0
void phy_init(xSemaphoreHandle spi_m, phy_rx_callback_t callback,
		uint8_t channel, enum phy_tx_power power) {
	// Store the SPI mutex
	spi_mutex = spi_m;

	// Store the callback
	rx_cb = callback;

	// Store the channel
	radio_channel = channel;

	// Store the TX power
	switch (power) {
	case PHY_TX_0dBm:
		radio_power = CC1101_868MHz_TX_0dBm;
		break;
	case PHY_TX_m5dBm:
		radio_power = CC1101_868MHz_TX_m6dBm;   // No exact match so using the nearest
		break;
	case PHY_TX_m10dBm:
		radio_power = CC1101_868MHz_TX_m10dBm;
		break;
	case PHY_TX_m20dBm:
		radio_power = CC1101_868MHz_TX_m20dBm;
		break;
	default:
		radio_power = CC1101_868MHz_TX_0dBm;
		break;
	}

	// Initialize the semaphore
	vSemaphoreCreateBinary(rx_sem);

	// Set initial state
	state = IDLE;

	// Create the task
	xTaskCreate(cc1101_task, (const signed char*) "phy_cc1101", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES-1, NULL);
}
示例#24
0
/** Create a new semaphore
 * @param sem pointer to the semaphore to create
 * @param count initial count of the semaphore
 * @return ERR_OK if successful, another err_t otherwise */
err_t sys_sem_new(sys_sem_t *sem, u8_t count)
{
	err_t ercd = ERR_MEM;

	vSemaphoreCreateBinary((*sem));

	if (sys_sem_valid(sem)) {
		if (count == 0) {
			if (xSemaphoreTake(*sem, 1) == pdPASS) {
				ercd = ERR_OK;
				SYS_STATS_INC_USED(sem);
			}
		} else {
			ercd = ERR_OK;
			SYS_STATS_INC_USED(sem);
		}
	} else {
		SYS_STATS_INC(sem.err);
	}

	return ercd;
}
示例#25
0
/**
 * \brief Initialize the GMAC driver.
 *
 * \param p_gmac   Pointer to the GMAC instance.
 * \param p_gmac_dev Pointer to the GMAC device instance.
 * \param p_opt GMAC configure options.
 */
void gmac_dev_init(Gmac* p_gmac, gmac_device_t* p_gmac_dev,
		gmac_options_t* p_opt)
{
	/* Disable TX & RX and more */
	gmac_network_control(p_gmac, 0);
	gmac_disable_interrupt(p_gmac, ~0u);

	gmac_clear_statistics(p_gmac);

	/* Clear all status bits in the receive status register. */
	gmac_clear_rx_status(p_gmac, GMAC_RSR_RXOVR | GMAC_RSR_REC | GMAC_RSR_BNA
			| GMAC_RSR_HNO);

	/* Clear all status bits in the transmit status register */
	gmac_clear_tx_status(p_gmac, GMAC_TSR_UBR | GMAC_TSR_COL | GMAC_TSR_RLE
            | GMAC_TSR_TXGO | GMAC_TSR_TFC | GMAC_TSR_TXCOMP | GMAC_TSR_HRESP );

	/* Enable the copy of data into the buffers
	   ignore broadcasts, and not copy FCS. */
	gmac_set_config(p_gmac, gmac_get_config(p_gmac) |
			GMAC_NCFGR_FD | GMAC_NCFGR_DBW(0) | GMAC_NCFGR_MAXFS |
			GMAC_NCFGR_RFCS | GMAC_NCFGR_PEN);
	gmac_enable_copy_all(p_gmac, p_opt->uc_copy_all_frame);
	gmac_disable_broadcast(p_gmac, p_opt->uc_no_boardcast);

	gmac_init_queue(p_gmac, p_gmac_dev);

	gmac_set_address(p_gmac, 0, p_opt->uc_mac_addr);

#ifdef FREERTOS_USED
	/* Asynchronous operation requires a notification semaphore.  First,
	 * create the semaphore. */
	vSemaphoreCreateBinary(netif_notification_semaphore);
	vQueueAddToRegistry(netif_notification_semaphore, "GMAC Sem");

	/* Then set the semaphore into the correct initial state. */
	xSemaphoreTake(netif_notification_semaphore, 0);
#endif
}
示例#26
0
//  Creates and returns a new semaphore. The "count" argument specifies
//  the initial state of the semaphore. TBD finish and test
sys_sem_t
sys_sem_new(u8_t count)
{
	xSemaphoreHandle  xSemaphore;

	portENTER_CRITICAL();
	vSemaphoreCreateBinary( xSemaphore );
	if(count == 0)	// Means it can't be taken
	{
		xSemaphoreTake(xSemaphore,1);
	}
	portEXIT_CRITICAL();

	if( xSemaphore == NULL )
	{
		return NULL;	// TBD need assert
	}
	else
	{
		return xSemaphore;
	}
}
示例#27
0
int main( void )
{

	trace_printf("--------\n");
	trace_printf("FreeRTOS\n");
	trace_printf("--------\n");

	MboxQueue = xQueueCreate( 32, sizeof( unsigned int* ) );
	vSemaphoreCreateBinary(InitDoneSemaphore);

	xSemaphoreTake(InitDoneSemaphore, portMAX_DELAY);

	xTaskCreate(IpcTask, "IpcTask", 100, NULL, 2, NULL);
	xTaskCreate(RdaemonTask, "RdaemonTask", 100, NULL, 2, NULL);

	/* Start the scheduler. */
	vTaskStartScheduler();

	while(1);

	return 0;
}
int main(void)
{

	SystemInit();			/* Initialize the controller */
	UART_Init(38400);		 /* Initialize the Uart module */	
	LPC_GPIO2->FIODIR = 0xffffffffu;

	vSemaphoreCreateBinary(Sem_A);	/* Create binary semaphore */

	if(Sem_A != NULL)
	 {
	    UART_Printf("\n\r\n\nSemaphore successfully created, Creating low priority task");
		xTaskCreate( My_LPT, ( signed char * )"LowTask", configMINIMAL_STACK_SIZE, NULL, 1, &LPT_Handle );
		vTaskStartScheduler();
	 }
	else
     	UART_Printf("\n\rFailed to create Semaphore");

	while(1);

	return 0;
}
示例#29
0
文件: i2c.c 项目: ArakniD/dynawa
int i2c_init() {
    volatile AT91PS_TWI pTWI = AT91C_BASE_TWI;

    pTWI->TWI_CR = AT91C_TWI_SWRST;
    pTWI->TWI_CR &= ~(AT91C_TWI_SWRST);
    uint32_t s;
    s = pTWI->TWI_SR;
    TRACE_I2C("TWI_SR %x\r\n", s);
    s = pTWI->TWI_SR;
    TRACE_I2C("TWI_SR %x\r\n", s);

    pTWI->TWI_CWGR = 0x048585; //I2C clk cca 9kHz 

    //i2c_mutex = xSemaphoreCreateMutex();
    i2c_mutex = MUTEX_CREATE();
    if(i2c_mutex == NULL) {
        panic("i2c_init");
    }

#if I2C_IRQ
    vSemaphoreCreateBinary(i2c_semaphore);
    xSemaphoreTake(i2c_semaphore, -1);

    // Initialize the interrupts
    pTWI->TWI_IDR = 0xffffffff;

    unsigned int mask = 0x1 << AT91C_ID_TWI;

    // Disable the interrupt controller & register our interrupt handler
    AT91C_BASE_AIC->AIC_IDCR = mask ;
    AT91C_BASE_AIC->AIC_SVR[ AT91C_ID_TWI ] = (unsigned int)i2c_Isr_Wrapper;
    AT91C_BASE_AIC->AIC_SMR[ AT91C_ID_TWI ] = AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL | IRQ_I2C_PRI;
    AT91C_BASE_AIC->AIC_ICCR = mask;
    AT91C_BASE_AIC->AIC_IECR = mask;
#endif

    return 0;
}
示例#30
0
void prvDataReceiveTask( void *pvParameters )
{
	uint8_t m,n;
	pvParameters = pvParameters;
	PumpsInit();
	vSemaphoreCreateBinary( xSerialSemaphore );
	if(xSerialSemaphore == 0)
	{
		while(1);
	}
	for(n=0;n<8;n++)
		NewSpeed[n] = 0;
	PumpsSetSpeed(1, NewSpeed[0]);
    for(;;)
    {
    	if( xSemaphoreTake( xSerialSemaphore, portMAX_DELAY ) == pdTRUE )
    	{
    		if (InLength == 16)
			{
				for (n = 0; n < 8; n++)
				{
					m = (InBuff+3) & 0x3;
					NewSpeed[n] = InputPayload[m][2 * n];
					NewSpeed[n] += (((uint16_t) (InputPayload[m][2* n + 1])) << 8);
				}
				PumpsSetSpeed(1, NewSpeed[0]);
				PumpsSetSpeed(2, NewSpeed[1]);
				PumpsSetSpeed(3, NewSpeed[2]);
				PumpsSetSpeed(4, NewSpeed[3]);
				PumpsSetSpeed(5, NewSpeed[4]);
				PumpsSetSpeed(6, NewSpeed[5]);
				PumpsSetSpeed(7, NewSpeed[6]);
				PumpsSetSpeed(8, NewSpeed[7]);
				GPIOToggle(LED_PORT,LED_RED_BIT);
			}
    	}
    }
}