예제 #1
0
BaseType_t xNetworkBuffersInitialise( void )
{
BaseType_t xReturn, x;

	/* Only initialise the buffers and their associated kernel objects if they
	have not been initialised before. */
	if( xNetworkBufferSemaphore == NULL )
	{
		xNetworkBufferSemaphore = xSemaphoreCreateCounting( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS, ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS );
		configASSERT( xNetworkBufferSemaphore );
		#if ( configQUEUE_REGISTRY_SIZE > 0 )
		{
			vQueueAddToRegistry( xNetworkBufferSemaphore, "NetBufSem" );
		}
		#endif /* configQUEUE_REGISTRY_SIZE */

		/* If the trace recorder code is included name the semaphore for viewing
		in FreeRTOS+Trace.  */
		#if( ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1 )
		{
			extern QueueHandle_t xNetworkEventQueue;
			vTraceSetQueueName( xNetworkEventQueue, "IPStackEvent" );
			vTraceSetQueueName( xNetworkBufferSemaphore, "NetworkBufferCount" );
		}
		#endif /*  ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1 */

		if( xNetworkBufferSemaphore != NULL )
		{
			vListInitialise( &xFreeBuffersList );

			/* Initialise all the network buffers.  No storage is allocated to
			the buffers yet. */
			for( x = 0; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ )
			{
				/* Initialise and set the owner of the buffer list items. */
				xNetworkBufferDescriptors[ x ].pucEthernetBuffer = NULL;
				vListInitialiseItem( &( xNetworkBufferDescriptors[ x ].xBufferListItem ) );
				listSET_LIST_ITEM_OWNER( &( xNetworkBufferDescriptors[ x ].xBufferListItem ), &xNetworkBufferDescriptors[ x ] );

				/* Currently, all buffers are available for use. */
				vListInsert( &xFreeBuffersList, &( xNetworkBufferDescriptors[ x ].xBufferListItem ) );
			}

			uxMinimumFreeNetworkBuffers = ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS;
		}
	}

	if( xNetworkBufferSemaphore == NULL )
	{
		xReturn = pdFAIL;
	}
	else
	{
		xReturn = pdPASS;
	}

	return xReturn;
}
예제 #2
0
BaseType_t xNetworkInterfaceInitialise( void )
{
    BaseType_t xReturn;
    extern uint8_t ucMACAddress[ 6 ];

    xReturn = xEMACInit( ucMACAddress );

    if( xReturn == pdPASS ) {
        /* Create the event semaphore if it has not already been created. */
        if( xEMACRxEventSemaphore == NULL ) {
            vSemaphoreCreateBinary( xEMACRxEventSemaphore );
#if ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1
            {
                /* If the trace recorder code is included name the semaphore for
                viewing in FreeRTOS+Trace. */
                vTraceSetQueueName( xEMACRxEventSemaphore, "MAC_RX" );
            }
#endif /*  ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1 */

            configASSERT( xEMACRxEventSemaphore );

            /* The Rx deferred interrupt handler task is created at the highest
            possible priority to ensure the interrupt handler can return directly to
            it no matter which task was running when the interrupt occurred. */
            xTaskCreate( 	prvEMACDeferredInterruptHandlerTask,/* The function that implements the task. */
                            "MACTsk",
                            configMINIMAL_STACK_SIZE,	/* Stack allocated to the task (defined in words, not bytes). */
                            NULL, 						/* The task parameter is not used. */
                            configMAX_PRIORITIES - 1, 	/* The priority assigned to the task. */
                            NULL );						/* The handle is not required, so NULL is passed. */
        }
    }

    return xReturn;
}
예제 #3
0
int main( void )
{
const uint32_t ulLongTime_ms = 250UL;

	/* Initialise the trace recorder and create the label used to post user
	events to the trace recording on each tick interrupt. */
	vTraceInitTraceData();
	xTickTraceUserEvent = xTraceOpenLabel( "tick" );

	/* Create the queue used to pass messages from the queue send task to the
	queue receive task. */
	xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );

	/* Give the queue a name for the FreeRTOS+Trace log. */
	vTraceSetQueueName( xQueue, "DemoQ" );

	/* Start the two tasks as described in the comments at the top of this
	file. */
	xTaskCreate( prvQueueReceiveTask,				/* The function that implements the task. */
				"Rx", 								/* The text name assigned to the task - for debug only as it is not used by the kernel. */
				configMINIMAL_STACK_SIZE, 			/* The size of the stack to allocate to the task.  Not actually used as a stack in the Win32 simulator port. */
				NULL,								/* The parameter passed to the task - not used in this example. */
				mainQUEUE_RECEIVE_TASK_PRIORITY, 	/* The priority assigned to the task. */
				NULL );								/* The task handle is not required, so NULL is passed. */

	xTaskCreate( prvQueueSendTask, "TX", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_SEND_TASK_PRIORITY, NULL );

	/* Create the task that handles the CLI on a UDP port.  The port number
	is set using the configUDP_CLI_PORT_NUMBER setting in FreeRTOSConfig.h. */
	xTaskCreate( vUDPCommandInterpreterTask, "CLI", configMINIMAL_STACK_SIZE, NULL, mainUDP_CLI_TASK_PRIORITY, NULL );

	/* Register commands with the FreeRTOS+CLI command interpreter. */
	vRegisterCLICommands();

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

	/* If all is well, the scheduler will now be running, and the following
	line will never be reached.  If the following line does execute, then
	there was insufficient FreeRTOS heap memory available for the idle and/or
	timer tasks	to be created.  See the memory management section on the
	FreeRTOS web site for more details (this is standard text that is not not
	really applicable to the Win32 simulator port). */
	for( ;; )
	{
		Sleep( ulLongTime_ms );
	}
}
예제 #4
0
파일: main.c 프로젝트: unnamet/Repo
int main( void )
{
	/* Prepare the trace recorder library. */
	#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
		vTraceInitTraceData();
	#endif

	/* The examples assume that all priority bits are assigned as preemption
	priority bits. */
	NVIC_SetPriorityGrouping( 0UL );

	/* Start the timer that just toggles an LED to show the demo is running. */
	vLEDsInitialise();

	/* Start the tasks that implements the command console on the UART, as
	described above. */
	vCDCCommandConsoleStart( mainCDC_COMMAND_CONSOLE_STACK_SIZE, mainCDC_COMMAND_CONSOLE_TASK_PRIORITY );

	/* Register CLI commands. */
	vRegisterCLICommands();

	/* Initialise the network interface.  Tasks that use the network are
	created in the network event hook when the network is connected and ready
	for use.  The address values passed in here are used if ipconfigUSE_DHCP is
	set to 0, or if ipconfigUSE_DHCP is set to 1 but a DHCP server cannot be
	contacted. */
	FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );

	/* If the trace recorder code is included... */
	#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
	{
		extern xQueueHandle xNetworkEventQueue;

		/* Name the queue for viewing in FreeRTOS+Trace. */
		vTraceSetQueueName( xNetworkEventQueue, "IPStackEvent" );
	}
	#endif /*  configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 */

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

	/* The following line should never execute.  If it does, it means there was
	insufficient FreeRTOS heap memory available to create the Idle and/or timer
	tasks.  See the memory management section on the http://www.FreeRTOS.org web
	site for more information. */
	for( ;; );
}
예제 #5
0
BaseType_t xNetworkInterfaceInitialise( void )
{
EMAC_CFG_Type Emac_Config;
BaseType_t xReturn;
extern uint8_t ucMACAddress[ 6 ];

	Emac_Config.pbEMAC_Addr = ucMACAddress;
	xReturn = EMAC_Init( &Emac_Config );

	if( xReturn == pdPASS )
	{
		LPC_ETHERNET->DMA_INT_EN =  DMA_INT_NOR_SUM | DMA_INT_RECEIVE;

		/* Create the event semaphore if it has not already been created. */
		if( xEMACRxEventSemaphore == NULL )
		{
			vSemaphoreCreateBinary( xEMACRxEventSemaphore );
			#if ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1
			{
				/* If the trace recorder code is included name the semaphore for
				viewing in FreeRTOS+Trace. */
				vTraceSetQueueName( xEMACRxEventSemaphore, "MAC_RX" );
			}
			#endif /*  ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1 */
		}

		configASSERT( xEMACRxEventSemaphore );

		/* The Rx deferred interrupt handler task is created at the highest
		possible priority to ensure the interrupt handler can return directly to
		it no matter which task was running when the interrupt occurred. */
		xTaskCreate( 	prvEMACDeferredInterruptHandlerTask,		/* The function that implements the task. */
						"MACTsk",
						configMINIMAL_STACK_SIZE,	/* Stack allocated to the task (defined in words, not bytes). */
						NULL, 						/* The task parameter is not used. */
						configMAX_PRIORITIES - 1, 	/* The priority assigned to the task. */
						NULL );						/* The handle is not required, so NULL is passed. */

		/* Enable the interrupt and set its priority as configured.  THIS
		DRIVER REQUIRES configMAC_INTERRUPT_PRIORITY TO BE DEFINED, PREFERABLY
		IN FreeRTOSConfig.h. */
		NVIC_SetPriority( ETHERNET_IRQn, configMAC_INTERRUPT_PRIORITY );
		NVIC_EnableIRQ( ETHERNET_IRQn );
	}

	return xReturn;
}
BaseType_t xNetworkInterfaceInitialise( void )
{
gmac_options_t xGMACOptions;
extern uint8_t ucMACAddress[ 6 ];
const TickType_t xPHYDelay_400ms = 400UL;
BaseType_t xReturn = pdFALSE;

	/* Ensure PHY is ready. */
	vTaskDelay( xPHYDelay_400ms / portTICK_RATE_MS );

	/* Enable GMAC clock. */
	pmc_enable_periph_clk( ID_GMAC );

	/* Fill in GMAC options */
	xGMACOptions.uc_copy_all_frame = 0;
	xGMACOptions.uc_no_boardcast = 0;
	memcpy( xGMACOptions.uc_mac_addr, ucMACAddress, sizeof( ucMACAddress ) );

	xGMACStruct.p_hw = GMAC;

	/* Init GMAC driver structure. */
	gmac_dev_init( GMAC, &xGMACStruct, &xGMACOptions );

	/* Init MAC PHY driver. */
	if( ethernet_phy_init( GMAC, BOARD_GMAC_PHY_ADDR, sysclk_get_cpu_hz() ) == GMAC_OK )
	{
		/* Auto Negotiate, work in RMII mode. */
		if( ethernet_phy_auto_negotiate( GMAC, BOARD_GMAC_PHY_ADDR ) == GMAC_OK )
		{
			/* Establish Ethernet link. */
			vTaskDelay( xPHYDelay_400ms * 2UL );
			if( ethernet_phy_set_link( GMAC, BOARD_GMAC_PHY_ADDR, 1 ) == GMAC_OK )
			{
				/* Create the event semaphore if it has not already been
				created. */
				if( xGMACRxEventSemaphore == NULL )
				{
					xGMACRxEventSemaphore = xSemaphoreCreateCounting( ULONG_MAX, 0 );
					#if ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1
					{
						/* If the trace recorder code is included name the semaphore for
						viewing in FreeRTOS+Trace. */
						vTraceSetQueueName( xGMACRxEventSemaphore, "MAC_RX" );
					}
					#endif /*  ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1 */
				}

				/* Register the callbacks. */
				gmac_dev_set_rx_callback( &xGMACStruct, prvGMACRxCallback );

				/* The Rx deferred interrupt handler task is created at the
				highest	possible priority to ensure the interrupt handler can
				return directly to it no matter which task was running when the
				interrupt occurred. */
				xTaskCreate( 	prvGMACDeferredInterruptHandlerTask,/* The function that implements the task. */
								"MACTsk",
								configMINIMAL_STACK_SIZE,	/* Stack allocated to the task (defined in words, not bytes). */
								NULL, 						/* The task parameter is not used. */
								configMAX_PRIORITIES - 1, 	/* The priority assigned to the task. */
								NULL );						/* The handle is not required, so NULL is passed. */

				/* Enable the interrupt and set its priority as configured.
				THIS DRIVER REQUIRES configMAC_INTERRUPT_PRIORITY TO BE DEFINED,
				PREFERABLY IN FreeRTOSConfig.h. */
				NVIC_SetPriority( GMAC_IRQn, configMAC_INTERRUPT_PRIORITY );
				NVIC_EnableIRQ( GMAC_IRQn );
				xReturn = pdPASS;
			}
		}
	}

	return xReturn;
}