コード例 #1
0
ファイル: flop.c プロジェクト: sean93park/freertos
static void vCompetingMathTask3( void *pvParameters )
{
    volatile double *pdArray, dTotal1, dTotal2, dDifference;
    volatile unsigned short *pusTaskCheckVariable;
    const size_t xArraySize = 10;
    size_t xPosition;
    short sError = pdFALSE;

    /* The variable this task increments to show it is still running is passed
    in as the parameter. */
    pusTaskCheckVariable = ( unsigned short * ) pvParameters;

    /* Allocate memory for use as an array. */
    pdArray = ( double * ) pvPortMalloc( xArraySize * sizeof( double ) );

    /* Keep filling an array, keeping a running total of the values placed in
    the array.  Then run through the array adding up all the values.  If the two
    totals do not match, stop the check variable from incrementing. */
    for( ;; )
    {
        dTotal1 = 0.0;
        dTotal2 = 0.0;

        for( xPosition = 0; xPosition < xArraySize; xPosition++ )
        {
            pdArray[ xPosition ] = ( double ) xPosition + 5.5;
            dTotal1 += ( double ) xPosition + 5.5;
        }

        for( xPosition = 0; xPosition < xArraySize; xPosition++ )
        {
            dTotal2 += pdArray[ xPosition ];
        }

        dDifference = dTotal1 - dTotal2;
        if( fabs( dDifference ) > 0.001 )
        {
            sError = pdTRUE;
        }

        if( sError == pdFALSE )
        {
            /* If the calculation has always been correct, increment the check
            variable so we know	this task is still running okay. */
            ( *pusTaskCheckVariable )++;
        }
    }
}
コード例 #2
0
/*!
 *  \brief Get the ledb2 current value.
 *
 *  \param pxLog a Log structure.
 *
 *  \return true upon success, false if error.
 */
bool b_ledb2_get_value( xLogDef *pxLog )
{
   // Alloc memory for the log string.
   pxLog->pcStringLog = pvPortMalloc( 8*sizeof( char ) );
   if( NULL == pxLog->pcStringLog )
   {
      return( false );
   }
   pxLog->pfFreeStringLog = vPortFree; // Because pvPortMalloc() was used to
                                       // alloc the log string.
   // Build the log string.
   sprintf( pxLog->pcStringLog, "%d,%d", LED_Get_Intensity( LEDB2G ),
            LED_Get_Intensity( LEDB2R ) );

   return( true );
}
コード例 #3
0
ファイル: pios_gcsrcvr.c プロジェクト: ICRS/OpenPilot-Clone
static struct pios_gcsrcvr_dev *PIOS_gcsrcvr_alloc(void)
{
	struct pios_gcsrcvr_dev * gcsrcvr_dev;

	gcsrcvr_dev = (struct pios_gcsrcvr_dev *)pvPortMalloc(sizeof(*gcsrcvr_dev));
	if (!gcsrcvr_dev) return(NULL);

	gcsrcvr_dev->magic = PIOS_GCSRCVR_DEV_MAGIC;
	gcsrcvr_dev->Fresh = FALSE;
	gcsrcvr_dev->supv_timer = 0;

	/* The update callback cannot receive the device pointer, so set it in a global */
	global_gcsrcvr_dev = gcsrcvr_dev;

	return(gcsrcvr_dev);
}
コード例 #4
0
ファイル: potentiometer.c プロジェクト: InSoonPark/asf
/*!
 *  \brief Get the potentiometer sensor config.
 *
 *  \param ppcStringReply Input/Output. The response string. NEVER NULL AS INPUT.
 *                        A malloc for the response string is performed here;
 *                        the caller must free this string.
 *
 *  \return the status of the command execution.
 */
eExecStatus e_potentiometer_get_config( signed portCHAR **ppcStringReply )
{
   // Alloc space for the reply.
   *ppcStringReply = (signed portCHAR *)pvPortMalloc( POT_GETCONF_MAXLEN );
   if( NULL == *ppcStringReply )
   {
      *ppcStringReply = (signed portCHAR *)SHELL_ERRMSG_MEMALLOC;
      return( SHELL_EXECSTATUS_KO );
   }

   // Build the string.
   sprintf( (char *)*ppcStringReply, "lograte=%d\r\n""min=%d%%\r\n""max=%d%%\r\n""alarm=%s\r\n",
            ul_pot_lograte, ul_pot_min, ul_pot_max, ((b_pot_alarm == pdTRUE) ? "on" : "off"));

   return( SHELL_EXECSTATUS_OK );
}
コード例 #5
0
EventGroupHandle_t xEventGroupCreate( void )
{
	EventGroup_t *pxEventBits;

	pxEventBits = pvPortMalloc( sizeof( EventGroup_t ) );
	if( pxEventBits != NULL ) {
		pxEventBits->uxEventBits = 0;
		vListInitialise( &( pxEventBits->xTasksWaitingForBits ) );
		traceEVENT_GROUP_CREATE( pxEventBits );
	}
	else {
		traceEVENT_GROUP_CREATE_FAILED();
	}

	return ( EventGroupHandle_t ) pxEventBits;
}
コード例 #6
0
ファイル: main_full.c プロジェクト: ptracton/experimental
/* Called from vApplicationIdleHook(), which is defined in main.c. */
void vFullDemoIdleFunction( void )
{
const unsigned long ulMSToSleep = 15;
const unsigned char ucConstQueueNumber = 0xaaU;
void *pvAllocated;

/* These three functions are only meant for use by trace code, and not for
direct use from application code, hence their prototypes are not in queue.h. */
extern void vQueueSetQueueNumber( xQueueHandle pxQueue, unsigned char ucQueueNumber );
extern unsigned char ucQueueGetQueueNumber( xQueueHandle pxQueue );
extern unsigned char ucQueueGetQueueType( xQueueHandle pxQueue );
extern void vTaskSetTaskNumber( xTaskHandle xTask, unsigned portBASE_TYPE uxHandle );
extern unsigned portBASE_TYPE uxTaskGetTaskNumber( xTaskHandle xTask );

	/* Sleep to reduce CPU load, but don't sleep indefinitely in case there are
	tasks waiting to be terminated by the idle task. */
	Sleep( ulMSToSleep );

	/* Demonstrate a few utility functions that are not demonstrated by any of
	the standard demo tasks. */
	prvDemonstrateTaskStateAndHandleGetFunctions();

	/* If xMutexToDelete has not already been deleted, then delete it now.
	This is done purely to demonstrate the use of, and test, the 
	vSemaphoreDelete() macro.  Care must be taken not to delete a semaphore
	that has tasks blocked on it. */
	if( xMutexToDelete != NULL )
	{
		/* Before deleting the semaphore, test the function used to set its
		number.  This would normally only be done from trace software, rather
		than application code. */
		vQueueSetQueueNumber( xMutexToDelete, ucConstQueueNumber );

		/* Before deleting the semaphore, test the functions used to get its
		type and number.  Again, these would normally only be done from trace
		software, rather than application code. */
		configASSERT( ucQueueGetQueueNumber( xMutexToDelete ) == ucConstQueueNumber );
		configASSERT( ucQueueGetQueueType( xMutexToDelete ) == queueQUEUE_TYPE_MUTEX );
		vSemaphoreDelete( xMutexToDelete );
		xMutexToDelete = NULL;
	}

	/* Exercise heap_4 a bit.  The malloc failed hook will trap failed 
	allocations so there is no need to test here. */
	pvAllocated = pvPortMalloc( ( rand() % 100 ) + 1 );
	vPortFree( pvAllocated );
}
コード例 #7
0
ファイル: main_full.c プロジェクト: AlexShiLucky/freertos
/* Called from vApplicationIdleHook(), which is defined in main.c. */
void vFullDemoIdleFunction( void )
{
const unsigned long ulMSToSleep = 15;
void *pvAllocated;

	/* Sleep to reduce CPU load, but don't sleep indefinitely in case there are
	tasks waiting to be terminated by the idle task. */
	Sleep( ulMSToSleep );

	/* Demonstrate a few utility functions that are not demonstrated by any of
	the standard demo tasks. */
	prvDemonstrateTaskStateAndHandleGetFunctions();

	/* Demonstrate the use of xTimerPendFunctionCall(), which is not
	demonstrated by any of the standard demo tasks. */
	prvDemonstratePendingFunctionCall();

	/* Demonstrate the use of functions that query information about a software
	timer. */
	prvDemonstrateTimerQueryFunctions();


	/* If xMutexToDelete has not already been deleted, then delete it now.
	This is done purely to demonstrate the use of, and test, the
	vSemaphoreDelete() macro.  Care must be taken not to delete a semaphore
	that has tasks blocked on it. */
	if( xMutexToDelete != NULL )
	{
		/* For test purposes, add the mutex to the registry, then remove it
		again, before it is deleted - checking its name is as expected before
		and after the assertion into the registry and its removal from the
		registry. */
		configASSERT( pcQueueGetName( xMutexToDelete ) == NULL );
		vQueueAddToRegistry( xMutexToDelete, "Test_Mutex" );
		configASSERT( strcmp( pcQueueGetName( xMutexToDelete ), "Test_Mutex" ) == 0 );
		vQueueUnregisterQueue( xMutexToDelete );
		configASSERT( pcQueueGetName( xMutexToDelete ) == NULL );

		vSemaphoreDelete( xMutexToDelete );
		xMutexToDelete = NULL;
	}

	/* Exercise heap_5 a bit.  The malloc failed hook will trap failed
	allocations so there is no need to test here. */
	pvAllocated = pvPortMalloc( ( rand() % 500 ) + 1 );
	vPortFree( pvAllocated );
}
コード例 #8
0
ファイル: gsm.c プロジェクト: just4chill/SIM900
uint8_t gsm_query_imsi(void)
{
	// Query IMSI
	modem_out("AT+CIMI\r");

	// Read 4 lines
	gsm_read(	4,
				gsm.line);

	// trim and store IMSI
	line_trim(gsm.line[1], ' ');
	network.imsi = (char *)pvPortMalloc(40);
	strcpy(network.imsi, gsm.line[1]);

	// TODO: Check for errors
	return 0;	
}
コード例 #9
0
ファイル: backend_ram.c プロジェクト: lirihe/arm
ftp_return_t ftp_ram_upload(void * state, const char const * path, uint32_t memaddr, uint32_t size, uint32_t chunk_size) {

	file_mem_addr = memaddr;
	file_size = size;
	file_chunk_size = chunk_size;
	file_chunks = (size + chunk_size - 1) / chunk_size;

	/* Allocate map */
	ram_map = pvPortMalloc(file_chunks);
	if (ram_map == NULL)
		return FTP_RET_NOSPC;

	memset(ram_map, 0, file_chunks);

	return FTP_RET_OK;

}
コード例 #10
0
ファイル: pios_usart.c プロジェクト: Crash1/TauLabs
static struct pios_usart_dev * PIOS_USART_alloc(void)
{
	struct pios_usart_dev * usart_dev;

	usart_dev = (struct pios_usart_dev *)pvPortMalloc(sizeof(*usart_dev));
	if (!usart_dev) return(NULL);

	usart_dev->rx_in_cb = 0;
	usart_dev->rx_in_context = 0;
	usart_dev->tx_out_cb = 0;
	usart_dev->tx_out_context = 0;
	usart_dev->magic = PIOS_USART_DEV_MAGIC;

	usart_dev->error_overruns = 0;

	return(usart_dev);
}
コード例 #11
0
int
IIS328DQ::init()
{
	int ret = ERROR;
	
	if (probe() != OK)
		goto out;

	/* do SPI init (and probe) first */
	if (CDev::init() != OK)
		goto out;

	/* allocate basic report buffers */
	if (_reports != NULL) {
        ringbuf_deinit(_reports);
		vPortFree(_reports);
		_reports = NULL;
	}
	/* allocate basic report buffers */
	_reports = (ringbuf_t *) pvPortMalloc (sizeof(ringbuf_t));
	ringbuf_init(_reports, 2, sizeof(accel_report));

	if (_reports == NULL)
		goto out;

	_class_instance = register_class_devname(ACCEL_BASE_DEVICE_PATH);

	reset();

	measure();

	/* advertise sensor topic, measure manually to initialize valid report */
	struct accel_report arp;
	ringbuf_get(_reports, &arp, sizeof(arp));

	_accel_topic = orb_advertise_multi(ORB_ID(sensor_accel), &arp,
		&_orb_class_instance, (is_external()) ? ORB_PRIO_VERY_HIGH : ORB_PRIO_DEFAULT);

	if (_accel_topic == NULL) {
		DEVICE_DEBUG("failed to create sensor_accel publication");
	}

	ret = OK;
out:
	return ret;
}
コード例 #12
0
ファイル: pios_l3gd20.c プロジェクト: Crash1/TauLabs
/**
 * @brief Allocate a new device
 */
static struct l3gd20_dev * PIOS_L3GD20_alloc(void)
{
	struct l3gd20_dev * l3gd20_dev;

	l3gd20_dev = (struct l3gd20_dev *)pvPortMalloc(sizeof(*l3gd20_dev));
	if (!l3gd20_dev) return (NULL);

	l3gd20_dev->magic = PIOS_L3GD20_DEV_MAGIC;

	l3gd20_dev->queue = xQueueCreate(PIOS_L3GD20_MAX_DOWNSAMPLE, sizeof(struct pios_sensor_gyro_data));
	if(l3gd20_dev->queue == NULL) {
		vPortFree(l3gd20_dev);
		return NULL;
	}

	return(l3gd20_dev);
}
コード例 #13
0
ファイル: displayDraw.c プロジェクト: hitubaldaniya/lumweb
tWidget* xGetLabelWidget(void *akt, int row)
{

	basicDisplayLine *line = (basicDisplayLine*) akt;
	if (line->labelWidget != NULL)
	{
		vPortFree(line->labelWidget);
	}
	line->labelWidget = pvPortMalloc(sizeof(tCanvasWidget));

	if (line->type == xTagList + TAG_INDEX_GROUP)
	{
		((tCanvasWidget*) line->labelWidget)->pFont = DISPLAY_LABEL_GROUP_FONT;
	}
	else
	{
		((tCanvasWidget*) line->labelWidget)->pFont = DISPLAY_LABEL_FONT;
	}
	((tCanvasWidget*) line->labelWidget)->pcText = line->label;
	((tCanvasWidget*) line->labelWidget)->pucImage = NULL;
	((tCanvasWidget*) line->labelWidget)->ulFillColor
			= DISPLAY_LABEL_BACKGROUND_COLOR;
	((tCanvasWidget*) line->labelWidget)->ulOutlineColor = ClrBlack;
	((tCanvasWidget*) line->labelWidget)->ulStyle = DISPLAY_LABEL_STYLE;
	((tCanvasWidget*) line->labelWidget)->ulTextColor = DISPLAY_LABEL_COLOR;

	((tCanvasWidget*) line->labelWidget)->sBase.lSize = sizeof(tCanvasWidget);
	((tCanvasWidget*) line->labelWidget)->sBase.pChild = NULL;
	((tCanvasWidget*) line->labelWidget)->sBase.pDisplay = DISPLAY_DRIVER;
	((tCanvasWidget*) line->labelWidget)->sBase.pNext = NULL;
	((tCanvasWidget*) line->labelWidget)->sBase.pParent = NULL;
	((tCanvasWidget*) line->labelWidget)->sBase.pfnMsgProc = CanvasMsgProc;
	((tCanvasWidget*) line->labelWidget)->sBase.sPosition.sXMin
			= DISPLAY_LABEL_LEFT;
	((tCanvasWidget*) line->labelWidget)->sBase.sPosition.sYMin = (row
			* (DISPLAY_LINE_HEIGHT + DISPLAY_LINE_MARGIN))
			+ (DISPLAY_TOP_OFFSET);
	((tCanvasWidget*) line->labelWidget)->sBase.sPosition.sXMax
			= DISPLAY_LABEL_LEFT + DISPLAY_LABEL_WIDTH - 1;
	((tCanvasWidget*) line->labelWidget)->sBase.sPosition.sYMax = (row
			* (DISPLAY_LINE_HEIGHT + DISPLAY_LINE_MARGIN))
			+ (DISPLAY_TOP_OFFSET) + DISPLAY_LINE_HEIGHT - 1;

	return line->labelWidget;
}
コード例 #14
0
ファイル: heap_5.c プロジェクト: karawin/Ka-Radio
void *pvPortRealloc(void *mem, size_t newsize, const char *file, unsigned line)
{
    if (newsize == 0) {
        vPortFree(mem, file, line);
        return NULL;
    }

    void *p;
    p = pvPortMalloc(newsize, file, line, false);
    if (p) {
        /* zero the memory */
        if (mem != NULL) {
            memcpy(p, mem, newsize);
            vPortFree(mem, file, line);
        }
    }
    return p;
}
コード例 #15
0
ファイル: heap_5.c プロジェクト: karawin/Ka-Radio
void *pvPortRealloc(void *mem, size_t newsize)
{
    if (newsize == 0) {
        vPortFree(mem);
        return NULL;
    }

    void *p;
    p = pvPortMalloc(newsize);
    if (p) {
        /* zero the memory */
        if (mem != NULL) {
            memcpy(p, mem, newsize);
            vPortFree(mem);
        }
    }
    return p;
}
コード例 #16
0
ファイル: event_groups.c プロジェクト: mattmanj17/freertos
EventGroupHandle_t xEventGroupGenericCreate( StaticEventGroup_t *pxStaticEventGroup )
{
EventGroup_t *pxEventBits;

	if( pxStaticEventGroup == NULL )
	{
		/* The user has not provided a statically allocated event group, so
		create on dynamically. */
		pxEventBits = ( EventGroup_t * ) pvPortMalloc( sizeof( EventGroup_t ) );
	}
	else
	{
		/* The user has provided a statically allocated event group - use it. */
		pxEventBits = ( EventGroup_t * ) pxStaticEventGroup; /*lint !e740 EventGroup_t and StaticEventGroup_t are guaranteed to have the same size and alignment requirement - checked by configASSERT(). */
	}

	if( pxEventBits != NULL )
	{
		pxEventBits->uxEventBits = 0;
		vListInitialise( &( pxEventBits->xTasksWaitingForBits ) );

		#if( configSUPPORT_STATIC_ALLOCATION == 1 )
		{
			if( pxStaticEventGroup == NULL )
			{
				pxEventBits->ucStaticallyAllocated = pdFALSE;
			}
			else
			{
				pxEventBits->ucStaticallyAllocated = pdTRUE;
			}
		}
		#endif /* configSUPPORT_STATIC_ALLOCATION */

		traceEVENT_GROUP_CREATE( pxEventBits );
	}
	else
	{
		traceEVENT_GROUP_CREATE_FAILED();
	}

	return ( EventGroupHandle_t ) pxEventBits;
}
コード例 #17
0
ファイル: main.c プロジェクト: vstehle/ducati_FreeRTOS
static void IpcTask (void * pvParameters)
{
	unsigned int msg, *local_vq_buf;
	int ret;
	struct virtqueue_buf virtq_buf;

	virtqueue_init();
	nvic_enable_irq(MAILBOX_IRQ);
	enable_mailbox_irq();

	for (;;) {
		xQueueReceive(MboxQueue, &msg, portMAX_DELAY);
		trace_printf("msg from mailbox : ");
		trace_value(msg);

		switch(msg) {

		case RP_MBOX_ECHO_REQUEST :
			mailbox_send(M3_TO_HOST_MBX, RP_MBOX_ECHO_REPLY);
			break;

		case HOST_TO_M3_VRING :
			ret = virtqueue_get_avail_buf(&virtqueue_list[msg], &virtq_buf);

			/* make a local copy of the buffer */
			local_vq_buf = pvPortMalloc(RP_MSG_BUF_SIZE);
			memcpy(local_vq_buf, virtq_buf.buf_ptr, RP_MSG_BUF_SIZE);

			virtqueue_add_used_buf(&virtqueue_list[msg], virtq_buf.head);

			/* dispatch to the service queue */
			rpmsg_dispatch_msg(local_vq_buf);

			break;

		case M3_TO_HOST_VRING :
			trace_printf("kick on vq0, dropping it \n");
			xSemaphoreGive(InitDoneSemaphore);
			break;
		}
	}
	vTaskDelete(NULL);
}
コード例 #18
0
/*void create_satellite_receiver_task(void)
 * Spectrum satellite receiver task. Initialize the USART instance
 * and create the task.
 */ 
void Satellite_CreateReceiverTask(  QueueHandle_t eventMaster, FlightModeHandler_t* stateHandler, SpHandler_t* setPointHandler, CtrlModeHandler_t * CtrlModeHandler)
{
  uint8_t* receiver_buffer_driver = pvPortMalloc(
      sizeof(uint8_t) * SATELLITE_MESSAGE_LENGTH*2 );

  Satellite_t *SatelliteParam = Satellite_Init(eventMaster, stateHandler, setPointHandler, CtrlModeHandler);


  if(!SatelliteParam || !receiver_buffer_driver)
  {
    for ( ;; );
  }

  QuadFC_SerialOptions_t opt = {
      BAUD_SATELLITE,
      EightDataBits,
      NoParity,
      OneStopBit,
      NoFlowControl,
      receiver_buffer_driver,
      SATELLITE_MESSAGE_LENGTH*2
  };

  uint8_t rsp = QuadFC_SerialInit(SATELITE_USART, &opt);
  if(!rsp)
  {
    /*Error - Could not create serial interface.*/

    for ( ;; )
    {

    }
  }


  /*Create the worker task*/
  xTaskCreate(  Satellite_ReceiverTask,   /* The task that implements the test. */
      "Satellite",                        /* Text name assigned to the task.  This is just to assist debugging.  The kernel does not use this name itself. */
      500,                                /* The size of the stack allocated to the task. */
      (void *) SatelliteParam,            /* The parameter is used to pass the already configured USART port into the task. */
      configMAX_PRIORITIES-2,             /* The priority allocated to the task. */
      NULL);                              /* Used to store the handle to the created task - in this case the handle is not required. */
}
コード例 #19
0
static void reader_task(){
	
	struct Message *pmessage = (struct Message*)pvPortMalloc(sizeof(struct Message));

	while (1) {
		xQueueReceive(xQueue, &pmessage, portMAX_DELAY);

		printf("\n...Message received!\n\n");
		fflush(stdout);

		for (int x = 0; x < ROW; x++) {
			for (int y = 0; y < COL; y++) {
				printf("%.1f, ", pmessage->Data[x, y]);
			}
			printf("\n");
			fflush(stdout);
		}
	}
}
コード例 #20
0
/*
成功 0
失败 -1
*/
int fifo__init(fifo_t *fifo,int size)
{
  fifo->buf=(uint8_t *)pvPortMalloc(size);
	MO_ASSERT((fifo->buf!=NULL));

  fifo->size=size;
  fifo->p_w=0;
  fifo->p_r=0;

	if(fifo->buf==NULL)
	{
		return -1;
	}
	else
	{
		return 0;
	}

}
コード例 #21
0
/**
 * @brief Allocate a new device
 */
static struct mpu6000_dev *PIOS_MPU6000_alloc(void)
{
    struct mpu6000_dev *mpu6000_dev;

    mpu6000_dev = (struct mpu6000_dev *)pvPortMalloc(sizeof(*mpu6000_dev));
    if (!mpu6000_dev) {
        return NULL;
    }

    mpu6000_dev->magic = PIOS_MPU6000_DEV_MAGIC;

    mpu6000_dev->queue = xQueueCreate(PIOS_MPU6000_MAX_DOWNSAMPLE, sizeof(struct pios_mpu6000_data));
    if (mpu6000_dev->queue == NULL) {
        vPortFree(mpu6000_dev);
        return NULL;
    }

    return mpu6000_dev;
}
コード例 #22
0
ファイル: TCPEchoSelectServer.c プロジェクト: ttzeng/lpcopen
static void prvTcpInit( xTcpServer_t *pxTcpServer )
{
struct freertos_sockaddr addr;
BaseType_t xReceiveTimeOut = 0;
BaseType_t xSendTimeOut = 0;

	pxTcpServer->pxSendData = ( SSimpleBuf * )pvPortMalloc( sizeof( *pxTcpServer->pxSendData ) - sizeof( pxTcpServer->pxSendData->array ) + SEND_BUFFER_SIZE + 1 );

	configASSERT( pxTcpServer->pxSendData != NULL );
	memset( pxTcpServer->pxSendData, '\0', sizeof( *pxTcpServer->pxSendData ) );
	pxTcpServer->pxSendData->LENGTH = SEND_BUFFER_SIZE + 1;

	FreeRTOS_GetRemoteAddress( pxTcpServer->xSocket, &addr );
	FreeRTOS_debug_printf( ( "prvTcpInit: serving %xip:%u\n",
		FreeRTOS_ntohl( addr.sin_addr ), addr.sin_port) );

	FreeRTOS_setsockopt( pxTcpServer->xSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
	FreeRTOS_setsockopt( pxTcpServer->xSocket, 0, FREERTOS_SO_SNDTIMEO, &xSendTimeOut, sizeof( xReceiveTimeOut ) );
}
コード例 #23
0
void startFileWriterTask( int priority )
{
        g_sampleRecordQueue = xQueueCreate(SAMPLE_RECORD_QUEUE_SIZE,
                                           sizeof( ChannelSample *));
        if (NULL == g_sampleRecordQueue) {
                pr_error("file: sampleRecordQueue err\r\n");
                return;
        }

        g_logfile = (FIL *) pvPortMalloc(sizeof(FIL));
        if (NULL == g_logfile) {
                pr_error("file: logfile sruct alloc err\r\n");
                return;
        }
        memset(g_logfile, 0, sizeof(FIL));

        xTaskCreate( fileWriterTask,( signed portCHAR * ) "fileWriter",
                     FILE_WRITER_STACK_SIZE, NULL, priority, NULL );
}
コード例 #24
0
ファイル: queue.c プロジェクト: kidfiction/openDrive
	xQueueHandle xQueueCreateMutex( void )
	{
	xQUEUE *pxNewQueue;

		/* Allocate the new queue structure. */
		pxNewQueue = ( xQUEUE * ) pvPortMalloc( sizeof( xQUEUE ) );
		if( pxNewQueue != NULL )
		{
			/* Information required for priority inheritance. */
			pxNewQueue->pxMutexHolder = NULL;
			pxNewQueue->uxQueueType = queueQUEUE_IS_MUTEX;

			/* Queues used as a mutex no data is actually copied into or out
			of the queue. */
			pxNewQueue->pcWriteTo = NULL;
			pxNewQueue->pcReadFrom = NULL;

			/* Each mutex has a length of 1 (like a binary semaphore) and
			an item size of 0 as nothing is actually copied into or out
			of the mutex. */
			pxNewQueue->uxMessagesWaiting = 0;
			pxNewQueue->uxLength = 1;
			pxNewQueue->uxItemSize = 0;
			pxNewQueue->xRxLock = queueUNLOCKED;
			pxNewQueue->xTxLock = queueUNLOCKED;

			/* Ensure the event queues start with the correct state. */
			vListInitialise( &( pxNewQueue->xTasksWaitingToSend ) );
			vListInitialise( &( pxNewQueue->xTasksWaitingToReceive ) );

			/* Start with the semaphore in the expected state. */
			xQueueGenericSend( pxNewQueue, NULL, 0, queueSEND_TO_BACK );

			traceCREATE_MUTEX( pxNewQueue );
		}
		else
		{
			traceCREATE_MUTEX_FAILED();
		}

		return pxNewQueue;
	}
コード例 #25
0
ファイル: port.c プロジェクト: ICRS/OpenPilot-Clone
/*
 * See header file for description.
 */
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
{
/* Should actually keep this struct on the stack. */
xParams *pxThisThreadParams = pvPortMalloc( sizeof( xParams ) );

	(void)pthread_once( &hSigSetupThread, prvSetupSignalsAndSchedulerPolicy );

	if ( (pthread_t)NULL == hMainThread )
	{
		hMainThread = pthread_self();
	}

	/* No need to join the threads. */
	pthread_attr_init( &xThreadAttributes );
	pthread_attr_setdetachstate( &xThreadAttributes, PTHREAD_CREATE_DETACHED );

	/* Add the task parameters. */
	pxThisThreadParams->pxCode = pxCode;
	pxThisThreadParams->pvParams = pvParameters;

	vPortEnterCritical();

	lIndexOfLastAddedTask = prvGetFreeThreadState();

	/* Create the new pThread. */
	if ( 0 == pthread_mutex_lock( &xSingleThreadMutex ) )
	{
		xSentinel = 0;
		if ( 0 != pthread_create( &( pxThreads[ lIndexOfLastAddedTask ].hThread ), &xThreadAttributes, prvWaitForStart, (void *)pxThisThreadParams ) )
		{
			/* Thread create failed, signal the failure */
			pxTopOfStack = 0;
		}

		/* Wait until the task suspends. */
		(void)pthread_mutex_unlock( &xSingleThreadMutex );
		while ( xSentinel == 0 );
		vPortExitCritical();
	}

	return pxTopOfStack;
}
コード例 #26
0
xSocket_t FreeRTOS_socket( BaseType_t xDomain, BaseType_t xType, BaseType_t xProtocol )
{
xFreeRTOS_Socket_t *pxSocket;

	/* Only UDP on Ethernet is currently supported. */
	configASSERT( xDomain == FREERTOS_AF_INET );
	configASSERT( xType == FREERTOS_SOCK_DGRAM );
	configASSERT( xProtocol == FREERTOS_IPPROTO_UDP );
	configASSERT( listLIST_IS_INITIALISED( &xBoundSocketsList ) );

	/* Allocate the structure that will hold the socket information. */
	pxSocket = ( xFreeRTOS_Socket_t * ) pvPortMalloc( sizeof( xFreeRTOS_Socket_t ) );

	if( pxSocket == NULL )
	{
		pxSocket = ( xFreeRTOS_Socket_t * ) FREERTOS_INVALID_SOCKET;
		iptraceFAILED_TO_CREATE_SOCKET();
	}
	else
	{
		/* Initialise the socket's members.  The semaphore will be created if
		the socket is bound to an address, for now the pointer to the semaphore
		is just set to NULL to show it has not been created. */
		pxSocket->xWaitingPacketSemaphore = NULL;
		vListInitialise( &( pxSocket->xWaitingPacketsList ) );
		vListInitialiseItem( &( pxSocket->xBoundSocketListItem ) );
		listSET_LIST_ITEM_OWNER( &( pxSocket->xBoundSocketListItem ), ( void * ) pxSocket );
		pxSocket->xSendBlockTime = ( TickType_t ) 0;
		pxSocket->xReceiveBlockTime = portMAX_DELAY;
		pxSocket->ucSocketOptions = FREERTOS_SO_UDPCKSUM_OUT;
		#if ipconfigSUPPORT_SELECT_FUNCTION == 1
			pxSocket->xSelectQueue = NULL;
		#endif
	}

	/* Remove compiler warnings in the case the configASSERT() is not defined. */
	( void ) xDomain;
	( void ) xType;
	( void ) xProtocol;

	return ( xSocket_t ) pxSocket;
}
コード例 #27
0
ファイル: malloc.c プロジェクト: datalightinc/reliance-edge
/*  This is a wrapper to pvPortMalloc.  It allocates the requested amount
    of space plus enough to store the size of the request (to enable realloc).
*/
void *malloc(size_t size)
{
    void *ptr;

    if(size + sizeof(size_t) < size)
    {
        return NULL;
    }

    ptr = pvPortMalloc(size + sizeof(size_t));

    if(ptr == NULL)
    {
        return NULL;
    }

    *((size_t *) ptr) = size;

    return ptr + sizeof(size_t);
}
コード例 #28
0
ファイル: BasicWEB.c プロジェクト: AndreyMostovov/asf
/*! \brief The get webserver config command: get the config fields value of http port
 *         Takes no parameter
 *
 *  \note  This function must be of the type pfShellCmd defined by the shell module.
 *
 *  \param xModId         Input. The module that is calling this function.
 *  \param FsNavId        Ignored.
 *  \param ac             Input. The argument counter. For this command, should be 1.
 *  \param av             Input. The argument vector.
 *  \param ppcStringReply Input/Output. The response string.
 *                        If Input is NULL, no response string will be output.
 *                        Else a malloc for the response string is performed here;
 *                        the caller must free this string.
 *
 *  \return the status of the command execution.
 */
eExecStatus e_webserver_cmd_get_config( eModId xModId, signed short FsNavId,
                                     int ac, signed portCHAR *av[],
                                     signed portCHAR **ppcStringReply )
{
  if(ppcStringReply != NULL)
  {
    /* allocate a buffer for answer */
    *ppcStringReply = (signed portCHAR *)pvPortMalloc(15);
    if( NULL == *ppcStringReply )
    {
       *ppcStringReply = (signed portCHAR *)SHELL_ERRMSG_MEMALLOC;
       return( SHELL_EXECSTATUS_KO );
    }
    /* get HTTP port and add it to the buffer */
    sprintf((char *)*ppcStringReply,"port=%u\r\n", webHttpPort);
    /* no error, return */
    return( SHELL_EXECSTATUS_OK );
  }
  return( SHELL_EXECSTATUS_KO );
}
コード例 #29
0
ファイル: DebugConsole.c プロジェクト: sagok/SmI_IEC104
void 	vOutputTime (void){
	extern 	RTC_HandleTypeDef hrtc;
	RTC_TimeTypeDef sTime;
	RTC_DateTypeDef sDate;

//	if( xSemaphoreTake( xDEBUGbusMutex, cmdMAX_MUTEX_WAIT ) == pdPASS )						// ждем семафор cmdMAX_MUTEX_WAIT иначе уходим
//	{
		HAL_RTC_GetTime(&hrtc, &sTime, FORMAT_BIN);			// Читаем время
		HAL_RTC_GetDate(&hrtc, &sDate, FORMAT_BIN);			// читаем дату

		char* WriteBuffer = pvPortMalloc(30);

		sprintf( WriteBuffer, "[%d.%d.%d.%u] ",sTime.Hours,sTime.Minutes,sTime.Seconds,(uint16_t)(sTime.SubSeconds/2) );
		USART_0TRACE(WriteBuffer);

		vPortFree(WriteBuffer);
//		xSemaphoreGive( xDEBUGbusMutex );													// вернём семафор
//	}

}
コード例 #30
0
ファイル: xenbus.c プロジェクト: ScienceXChina/FreeRTOS-Xen
char *xenbus_get_perms(xenbus_transaction_t xbt, const char *path, char **value)
{
    struct write_req req[] = { {path, strlen(path) + 1} };
    struct xsd_sockmsg *rep;
    char *res, *msg;

    DEBUG("xenbus_get_perms: called\n");
    rep = xenbus_msg_reply(XS_GET_PERMS, xbt, req, ARRAY_SIZE(req));
    msg = errmsg(rep);
    if (msg) {
	*value = NULL;
	return msg;
    }
    res = pvPortMalloc(rep->len + 1);
    memcpy(res, rep + 1, rep->len);
    res[rep->len] = 0;
    vPortFree(rep);
    *value = res;
    return NULL;
}