Example #1
0
void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
{
unsigned portBASE_TYPE uxLEDMask;

	if( uxLED < partstNUM_LEDs )
	{
		uxLEDMask = 1UL << uxLED;
		
		taskENTER_CRITICAL();
		{
			if( MCF_GPIO_PORTTC & uxLEDMask )
			{
				MCF_GPIO_PORTTC &= ~uxLEDMask;
			}
			else
			{
				MCF_GPIO_PORTTC |= uxLEDMask;
			}
		}
		taskEXIT_CRITICAL();
	}
}
Example #2
0
void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
{
unsigned portBASE_TYPE uxLEDMask;

	if( uxLED < partstNUM_LEDs )
	{
		uxLEDMask = xLEDs[ uxLED ];
		
		taskENTER_CRITICAL();
		{
			if( xValue )
			{
				P3 |= uxLEDMask;
			}
			else
			{
				P3 &= ~uxLEDMask;
			}
		}
		taskEXIT_CRITICAL();
	}
}
Example #3
0
void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
{
	if( uxLED < partstMAX_LEDS )
	{
		/* A critical section is used as the LEDs are also accessed from an
		interrupt. */
		taskENTER_CRITICAL();
		{
			if( ( ulGPIOState & ( 1UL << uxLED ) ) != 0UL )
			{
				ulGPIOState &= ~( 1UL << uxLED );
			}
			else
			{
				ulGPIOState |= ( 1UL << uxLED );
			}
			
			MSS_GPIO_set_outputs( ulGPIOState );
		}
		taskEXIT_CRITICAL();
	}
}
Example #4
0
int _gettimeofday_r(struct _reent *, struct timeval *__tp, void *__tzp)
{
	taskENTER_CRITICAL();

	uint_t t = sdk_system_get_time();
	if (s_lastSysTime > t)
	{
		s_timeAdj += (uint_t)-1;
	}

	s_lastSysTime = t;
	taskEXIT_CRITICAL();

	uint64_t usec = s_lastSysTime + s_timeAdj;

	__tp->tv_usec = usec;
	__tp->tv_sec = usec / 1000000;

	// DEBUG_PRINT("_gettimeofday_r:__tp->tv_sec=%08X, __tp->tv_usec=%08X, s_lastSysTime=%08X, s_timeAdj=%016llX\n", __tp->tv_sec, __tp->tv_usec, s_lastSysTime, s_timeAdj);

	return 0;
}
void vNetworkBufferRelease( xNetworkBufferDescriptor_t * const pxNetworkBuffer )
{
portBASE_TYPE xListItemAlreadyInFreeList;

	/* Ensure the buffer is returned to the list of free buffers before the
	counting semaphore is 'given' to say a buffer is available. */
	taskENTER_CRITICAL();
	{
		xListItemAlreadyInFreeList = listIS_CONTAINED_WITHIN( &xFreeBuffersList, &( pxNetworkBuffer->xBufferListItem ) );

		if( xListItemAlreadyInFreeList == pdFALSE )
		{
			vListInsertEnd( &xFreeBuffersList, &( pxNetworkBuffer->xBufferListItem ) );
		}

		configASSERT( xListItemAlreadyInFreeList == pdFALSE );
	}
	taskEXIT_CRITICAL();

	xSemaphoreGive( xNetworkBufferSemaphore );
	iptraceNETWORK_BUFFER_RELEASED( pxNetworkBuffer );
}
portBASE_TYPE xCmdIntRegisterCommand( const xCommandLineInput * const pxCommandToRegister )
{
static xCommandLineInputListItem *pxLastCommandInList = &xRegisteredCommands;
xCommandLineInputListItem *pxNewListItem;
portBASE_TYPE xReturn = pdFAIL;

	/* Check the parameter is not NULL. */
	configASSERT( pxCommandToRegister );

	/* Create a new list item that will reference the command being registered. */
	pxNewListItem = ( xCommandLineInputListItem * ) pvPortMalloc( sizeof( xCommandLineInputListItem ) );
	configASSERT( pxNewListItem );

	if( pxNewListItem != NULL )
	{
		taskENTER_CRITICAL();
		{
			/* Reference the command being registered from the newly created 
			list item. */
			pxNewListItem->pxCommandLineDefinition = pxCommandToRegister;

			/* The new list item will get added to the end of the list, so 
			pxNext has nowhere to point. */
			pxNewListItem->pxNext = NULL;

			/* Add the newly created list item to the end of the already existing
			list. */
			pxLastCommandInList->pxNext = pxNewListItem;

			/* Set the end of list marker to the new list item. */
			pxLastCommandInList = pxNewListItem;
		}
		taskEXIT_CRITICAL();
		
		xReturn = pdPASS;
	}

	return xReturn;
}
void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
{
unsigned portBASE_TYPE uxLEDMask;

	if( uxLED < partstNUM_LEDs )
	{
		uxLEDMask = xLEDs[ uxLED ];
		
		taskENTER_CRITICAL();
		{
			if( PCM & uxLEDMask )
			{
				PCM &= ~uxLEDMask;
			}
			else
			{
				PCM |= uxLEDMask;
			}
		}
		taskEXIT_CRITICAL();
	}
}
/*
 *  ======== MessageQCopy_create ========
 */
MessageQCopy_Handle MessageQCopy_create(UInt32 reserved, UInt32 * endpoint)
{
	MessageQCopy_Object *obj = NULL;
	Bool                found = FALSE;
	Int                 i;
	UInt16              queueIndex = 0;

	taskENTER_CRITICAL(&virtQueLock);

	if(reserved == MessageQCopy_ASSIGN_ANY){
		/* Search the array for a free slot above reserved: */
		for(i = MessageQCopy_MAX_RESERVED_ENDPOINT + 1;
			(i < MAXMESSAGEQOBJECTS) && (found == FALSE);
			i++){

			if(!IS_VALID_MSGQUEOBJ(&mQueObj[i])){
				queueIndex = i;
				found = TRUE;
				break;
			}
		}
	}
	else if((queueIndex = reserved) <= MessageQCopy_MAX_RESERVED_ENDPOINT){
		if(!IS_VALID_MSGQUEOBJ(&mQueObj[queueIndex])){
			found = TRUE;
		}
	}

	if(found){
		if(MsgQueObjInit(&mQueObj[queueIndex]) != FALSE){
			obj = &mQueObj[queueIndex];
			*endpoint = queueIndex;
		}
	}

	taskEXIT_CRITICAL(&virtQueLock);
	return obj;
}
void vtHandleFatalError(int code,int line,char file[]) {
    static unsigned int delayCounter = 0;
    // There are lots of ways you can (and may want to) handle a fatal error
    // In this implementation, I suspend tasks and then flash the LEDs.  Note that the stop may not be
    //   immediate because this task has to be scheduled first for that to happen.  In fact, one task might
    //   call this while another tries to get into
    taskENTER_CRITICAL();
    taskDISABLE_INTERRUPTS();
    /* LEDs on ports 1 and 2 to output (1). */
    // Note that all LED access is through the proper LPC library calls (or my own routines that call them)

    // Print where error occured for debugging
    printf("ERROR: code %d on line %d in file %s",code,line,file);

    vtInitLED();
    for (;;) {
        // Silly delay loop, but we really don't have much choice here w/o interrupts and FreeRTOS...
        // This won't be okay to do *anywhere* else in your code
        for (delayCounter=0; delayCounter<10000000; delayCounter++) {
        }
        // Turn off half and on half
        vtLEDOn(0xAA);
        vtLEDOff(0x55);
        // Delay again
        for (delayCounter=0; delayCounter<10000000; delayCounter++) {
        }
        // Toggle
        vtLEDOff(0xAA);
        vtLEDOn(0x55);
        // Here is some dumb code to make sure that the three input parameters are not optimized away by the compiler
        if ((code < -55) && (line < -55) && (file == NULL)) {
            vtLEDOff(0x0); // We won't get here
        }
        // End of dumb code
    }
    // We will never get here
    taskEXIT_CRITICAL();
}
Example #10
0
BaseType_t FreeRTOS_closesocket( xSocket_t xSocket )
{
xNetworkBufferDescriptor_t *pxNetworkBuffer;
xFreeRTOS_Socket_t *pxSocket;

	pxSocket = ( xFreeRTOS_Socket_t * ) xSocket;

	configASSERT( pxSocket );
	configASSERT( pxSocket != FREERTOS_INVALID_SOCKET );

	/* Socket must be unbound first, to ensure no more packets are queued on
	it. */
	if( socketSOCKET_IS_BOUND( pxSocket ) != pdFALSE )
	{
		taskENTER_CRITICAL();
		{
			uxListRemove( &( pxSocket->xBoundSocketListItem ) );
		}
		taskEXIT_CRITICAL();
	}

	/* Now the socket is not bound the list of waiting packets can be
	drained. */
	if( pxSocket->xWaitingPacketSemaphore != NULL )
	{
		while( listCURRENT_LIST_LENGTH( &( pxSocket->xWaitingPacketsList ) ) > 0U )
		{
			pxNetworkBuffer = ( xNetworkBufferDescriptor_t * ) listGET_OWNER_OF_HEAD_ENTRY( &( pxSocket->xWaitingPacketsList ) );
			uxListRemove( &( pxNetworkBuffer->xBufferListItem ) );
			vNetworkBufferRelease( pxNetworkBuffer );
		}
		vSemaphoreDelete( pxSocket->xWaitingPacketSemaphore );
	}

	vPortFree( pxSocket );

	return 0;
} /* Tested */
static uint16_t prvGetPrivatePortNumber( void )
{
static uint16_t usNextPortToUse = socketAUTO_PORT_ALLOCATION_START_NUMBER - 1;
uint16_t usReturn;

	/* Assign the next port in the range. */
	taskENTER_CRITICAL();
		usNextPortToUse++;
	taskEXIT_CRITICAL();

	/* Has it overflowed? */
	if( usNextPortToUse == 0U )
	{
		/* Don't go right back to the start of the dynamic/private port
		range numbers as any persistent sockets are likely to have been
		create first so the early port numbers may still be in use. */
		usNextPortToUse = socketAUTO_PORT_ALLOCATION_RESET_NUMBER;
	}

	usReturn = FreeRTOS_htons( usNextPortToUse );

	return usReturn;
} /* Tested */
Example #12
0
struct eth_frame* retrieve_frame(void)
{
	struct eth_frame *frame = NULL;

	taskENTER_CRITICAL();

	if(eth_buffer.head) {
		frame = eth_buffer.head;

		if(eth_buffer.head->next) {
			eth_buffer.head = eth_buffer.head->next;
			eth_buffer.head->prev = NULL;
		}
		else {
			eth_buffer.head = NULL;
			eth_buffer.tail = NULL;
		}
	}

	taskEXIT_CRITICAL();

	return frame;
}
Example #13
0
unsigned portSHORT vActivateQueue(TaskToken taskToken, unsigned portSHORT usNumElement)
{
	taskENTER_CRITICAL();
	{
		//detect queue already exist
		if (xTaskQueueHandles[taskToken->enTaskID] == NULL)
		{
			//trim requested queue size
			usNumElement = (usNumElement > MAX_QUEUE_REQ_SIZE) ? MAX_QUEUE_REQ_SIZE : usNumElement;

			//create task queue memory
			xTaskQueueHandles[taskToken->enTaskID] = xQueueCreate(usNumElement, sizeof(MessagePacket));
		}
		else
		{
			//TODO work out how to return existing queue size
			usNumElement = 0;
		}
	}
	taskEXIT_CRITICAL();

	return usNumElement;
}
Example #14
0
void stop_PWM_hardware()
{
    taskENTER_CRITICAL();
    pwmTCCRa = 0;

#if defined( portUSE_TIMER0_PWM )
    pwmTCCRb
	DDRD &= ~pwmDDRD; // PD6 OC0A (Pin 6) & PD5 OC0B (Pin 5)

#elif defined( portUSE_TIMER1_PWM )

	#if defined(__AVR_ATmega328P__)  // Arduino
		DDRB &= ~pwmDDRB; // PB1 OC1A (Pin 9) & PB2 OC1B (Pin 10)

	#elif defined(__AVR_ATmega324P__)  || defined(__AVR_ATmega644P__)|| defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega324PA__) || defined(__AVR_ATmega644PA__)// Pololu SVP with 1284p
		DDRD &= ~pwmDDRD; // PD5 OC1A & PD4 OC1B

	#endif

#endif

    taskEXIT_CRITICAL();
}
Example #15
0
void vPortFree( void *pv )
{
unsigned char *puc = ( unsigned char * ) pv;
xBlockLink *pxLink;

	if( pv != NULL )
	{
		/* The memory being freed will have an xBlockLink structure immediately
		before it. */
		puc -= heapSTRUCT_SIZE;

		/* This casting is to keep the compiler from issuing warnings. */
		pxLink = ( void * ) puc;

		taskENTER_CRITICAL( &xMemLock );
		{
			/* Add this block to the list of free blocks. */
			xFreeBytesRemaining += pxLink->xBlockSize;
			prvInsertBlockIntoFreeList( ( ( xBlockLink * ) pxLink ) );			
		}
		taskEXIT_CRITICAL( &xMemLock );
	}
}
Example #16
0
void vWriteMessageToDisk( const char * const pcMessage )
{
#ifdef USE_STDIO
const char * const pcFileName = "c:\\RTOSlog.txt";
const char * const pcSeparator = "\r\n-----------------------\r\n";
FILE *pf;

	taskENTER_CRITICAL();
	{	
		pf = fopen( pcFileName, "a" );
		if( pf != NULL )
		{
			fwrite( pcMessage, strlen( pcMessage ), ( unsigned short ) 1, pf );
			fwrite( pcSeparator, strlen( pcSeparator ), ( unsigned short ) 1, pf );
			fclose( pf );
		}
	}
	taskEXIT_CRITICAL();
#else
	/* Stop warnings. */
	( void ) pcMessage;
#endif /*USE_STDIO*/
}
Example #17
0
void vBSP430ledSet( unsigned portBASE_TYPE uxLED,
					signed portBASE_TYPE xValue )
{
	if (uxLED < ( unsigned portBASE_TYPE ) ucLEDDefnCount)
	{
		const xLEDDefn * pxLED = pxLEDDefn + uxLED;

		taskENTER_CRITICAL();
		if (xValue > 0)
		{
			*pxLED->pucPxOUT |= pxLED->ucBIT;
		}
		else if (xValue < 0)
		{
			*pxLED->pucPxOUT ^= pxLED->ucBIT;
		}
		else
		{
			*pxLED->pucPxOUT &= ~pxLED->ucBIT;
		}
		taskEXIT_CRITICAL();
	}
}
Example #18
0
File: port.c Project: Eclo/FreeRTOS
void vPortCloseRunningThread( void *pvTaskToDelete, volatile BaseType_t *pxPendYield )
{
xThreadState *pxThreadState;
void *pvThread;
uint32_t ulErrorCode;

	/* Remove compiler warnings if configASSERT() is not defined. */
	( void ) ulErrorCode;

	/* Find the handle of the thread being deleted. */
	pxThreadState = ( xThreadState * ) ( *( size_t *) pvTaskToDelete );
	pvThread = pxThreadState->pvThread;

	/* Raise the Windows priority of the thread to ensure the FreeRTOS scheduler
	does not run and swap it out before it is closed.  If that were to happen
	the thread would never run again and effectively be a thread handle and
	memory leak. */
	SetThreadPriority( pvThread, portDELETE_SELF_THREAD_PRIORITY );

	/* This function will not return, therefore a yield is set as pending to
	ensure a context switch occurs away from this thread on the next tick. */
	*pxPendYield = pdTRUE;

	/* Mark the thread associated with this task as invalid so
	vPortDeleteThread() does not try to terminate it. */
	pxThreadState->pvThread = NULL;

	/* Close the thread. */
	ulErrorCode = CloseHandle( pvThread );
	configASSERT( ulErrorCode );

	/* This is called from a critical section, which must be exited before the
	thread stops. */
	taskEXIT_CRITICAL();

	ExitThread( 0 );
}
Example #19
0
xNetworkBufferDescriptor_t *pxNetworkBufferGet( size_t xRequestedSizeBytes, TickType_t xBlockTimeTicks )
{
    xNetworkBufferDescriptor_t *pxReturn = NULL;

    /*_RB_ The current implementation only has a single size memory block, so
    the requested size parameter is not used (yet). */
    ( void ) xRequestedSizeBytes;

    /* If there is a semaphore available, there is a network buffer available. */
    if( xSemaphoreTake( xNetworkBufferSemaphore, xBlockTimeTicks ) == pdPASS ) {
        /* Protect the structure as it is accessed from tasks and interrupts. */
        taskENTER_CRITICAL();
        {
            pxReturn = ( xNetworkBufferDescriptor_t * ) listGET_OWNER_OF_HEAD_ENTRY( &xFreeBuffersList );
            uxListRemove( &( pxReturn->xBufferListItem ) );
        }
        taskEXIT_CRITICAL();
        iptraceNETWORK_BUFFER_OBTAINED( pxReturn );
    } else {
        iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER();
    }

    return pxReturn;
}
Example #20
0
BaseType_t FreeRTOS_CLIRegisterCommand( const CLI_Command_Definition_t * const pxCommandToRegister )
{
static CLI_Definition_List_Item_t *pxLastCommandInList = &xRegisteredCommands;
CLI_Definition_List_Item_t *pxNewListItem;
BaseType_t xReturn = pdFAIL;

	// проверим не пустая ли команда
	configASSERT( pxCommandToRegister );

	// Создать новый элемент списка, который будет ссылаться на команду
	pxNewListItem = ( CLI_Definition_List_Item_t * ) pvPortMalloc( sizeof( CLI_Definition_List_Item_t ) );
	configASSERT( pxNewListItem );

	if( pxNewListItem != NULL )
	{
		taskENTER_CRITICAL();
		{
			// ссылка на команду в списке
			pxNewListItem->pxCommandLineDefinition = pxCommandToRegister;

			// указатель на следующий элемент списка
			pxNewListItem->pxNext = NULL;

			// Добавим вновь созданный элемент списка в конец уже существующего списка
			pxLastCommandInList->pxNext = pxNewListItem;

			// Set the end of list marker to the new list item.
			pxLastCommandInList = pxNewListItem;
		}
		taskEXIT_CRITICAL();

		xReturn = pdPASS;
	}

	return xReturn;
}
Example #21
0
signed portBASE_TYPE xSerialPutChar( xComPortHandle pxPort, signed char cOutChar, TickType_t xBlockTime )
{
portBASE_TYPE xReturn = pdFALSE;

	/* The ISR is processing characters is so just add to the end of the queue. */
	if( pdTRUE == xQueueSend( xSerialTxQueue, &cOutChar, xBlockTime ) )
	{	
		xReturn = pdTRUE;
	}
	else
	{
		/* The queue is probably full. */
		xReturn = pdFALSE;
	}

	/* Make sure that the interrupt will fire in the case where:
	    Currently sending so the Tx Complete will fire.
	    Not sending so the Empty will fire.	*/
	taskENTER_CRITICAL();
		UART_1_SetTxInterruptMode( UART_1_TX_STS_COMPLETE | UART_1_TX_STS_FIFO_EMPTY );
	taskEXIT_CRITICAL();
	
	return xReturn;
}
Example #22
0
void StartFsTask(void const * argument)
{
	printf("Fs task started\n");
	taskENTER_CRITICAL();
	TREEVIEW_Handle filesystem  = TREEVIEW_CreateEx(	500, 0,
														300, 480,
														0, WM_CF_SHOW,
														TREEVIEW_CF_AUTOSCROLLBAR_V |
														TREEVIEW_CF_AUTOSCROLLBAR_H |
														TREEVIEW_CF_ROWSELECT,
														GUI_ID_TREEVIEW0
													);
	TREEVIEW_SetFont(filesystem, GUI_FONT_24_ASCII);
	scan_files("", &filesystem);
	TREEVIEW_ITEM_ExpandAll(TREEVIEW_GetItem(filesystem, 0, TREEVIEW_GET_FIRST));
	WM_SetCallback(WM_HBKWIN, _cbHBKWIN);
	WM_SetFocus(filesystem);
	taskEXIT_CRITICAL();

    while(1)
    {
		osDelay(5000);
    }
}
					vTaskDelay(100/portTICK_RATE_MS);
					receiver();
					
				}
				
					
			}
			correction();
			
vTaskDelay(500/portTICK_RATE_MS);
	}	 
}



void sender(void){
	#ifdef MASTERMODE
	uint8_t i;
	for(i=1;i<=MAX_SLAVE_CLOCK;i++){
		taskENTER_CRITICAL();
		unsigned long int timeSender=timeProt.saveTime[i].second;
		taskEXIT_CRITICAL();
		if(timeSender!=0){
			//printf("id : %d  , delay response time second : %lu",i,timeSender);
time_t ClockTimestamp()
{
	t_RTCC myrtcc;
	time_t epoch_time;
	struct tm ts; 
	//char rtccString[200];
	RTCCRead(&myrtcc);
	/*sprintf(rtccString, "RTC %.4d-%.2d-%.2d / %.2d:%.2d.%.2d / %d\r\n",(myrtcc.year), myrtcc.month, myrtcc.day,
					myrtcc.hour, myrtcc.min, myrtcc.sec, myrtcc.dweek);
	UARTWrite(1, rtccString);*/
	ts.tm_year = 100+myrtcc.year;
	ts.tm_mon = myrtcc.month-1;
	ts.tm_wday = myrtcc.dweek;
	ts.tm_mday	= myrtcc.day;
	ts.tm_hour = myrtcc.hour;
	ts.tm_min = myrtcc.min;
	ts.tm_sec = myrtcc.sec;
	ts.tm_isdst = 0;//DST flag explicitly set to NULL to avoid random assigment during mktime call
	
	taskENTER_CRITICAL();//making it task critical as this function was making 3600 jump issue
	epoch_time = mktime(&ts);//jump was due to isdst flag in tm structure
	taskEXIT_CRITICAL();
	return epoch_time;
}
Example #25
0
static void prvCheckForValidListAndQueue( void )
{
	/* Check that the list from which active timers are referenced, and the
	queue used to communicate with the timer service, have been
	initialised. */
	taskENTER_CRITICAL();
	{
		if( xTimerQueue == NULL )
		{
			vListInitialise( &xActiveTimerList1 );
			vListInitialise( &xActiveTimerList2 );
			pxCurrentTimerList = &xActiveTimerList1;
			pxOverflowTimerList = &xActiveTimerList2;
			xTimerQueue = xQueueCreate( ( UBaseType_t ) configTIMER_QUEUE_LENGTH, sizeof( DaemonTaskMessage_t ) );
			configASSERT( xTimerQueue );

			#if ( configQUEUE_REGISTRY_SIZE > 0 )
			{
				if( xTimerQueue != NULL )
				{
					vQueueAddToRegistry( xTimerQueue, "TmrQ" );
				}
				else
				{
					mtCOVERAGE_TEST_MARKER();
				}
			}
			#endif /* configQUEUE_REGISTRY_SIZE */
		}
		else
		{
			mtCOVERAGE_TEST_MARKER();
		}
	}
	taskEXIT_CRITICAL();
}
Example #26
0
EventBits_t xEventGroupClearBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToClear )
{
EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup;
EventBits_t uxReturn;

	/* Check the user is not attempting to clear the bits used by the kernel
	itself. */
	configASSERT( ( uxBitsToClear & eventEVENT_BITS_CONTROL_BYTES ) == 0 );

	taskENTER_CRITICAL();
	{
		traceEVENT_GROUP_CLEAR_BITS( xEventGroup, uxBitsToClear );

		/* The value returned is the event group value prior to the bits being
		cleared. */
		uxReturn = pxEventBits->uxEventBits;

		/* Clear the bits. */
		pxEventBits->uxEventBits &= ~uxBitsToClear;
	}
	taskEXIT_CRITICAL();

	return uxReturn;
}
Example #27
0
void vModeSmsStart(uint8_t option)
{
    if (state != MODE_SMS_STATE_STOP) return;
    
    taskENTER_CRITICAL();
    {
		eep_params.mode_sms_use_slider_as_shutter = 0;
		if (option & MODE_SMS_OPTION_SHUTTER)
		{
			eep_params.mode_sms_use_slider_as_shutter = 1;
		}

        for (uint8_t motor = 0; motor < SM_MOTORS_USED; motor++)
        {
            if (eep_params.mode_sms_accel_count[motor] == 0)
            {
                eep_params.mode_sms_accel_count[motor] = 1;
            }
            if (eep_params.mode_sms_decel_count[motor] == 0)
            {
                eep_params.mode_sms_decel_count[motor] = 1;
            }
            
            while (true)
            {
                if (mode_smsCOUNT_SUM_TOO_HIGH(motor) && eep_params.mode_sms_leadin_count[motor] > 0)
                {
                    eep_params.mode_sms_leadin_count[motor]--;
                }
                if (mode_smsCOUNT_SUM_TOO_HIGH(motor) && eep_params.mode_sms_leadout_count[motor] > 0)
                {
                    eep_params.mode_sms_leadout_count[motor]--;
                }
                if (mode_smsCOUNT_SUM_TOO_HIGH(motor) && eep_params.mode_sms_accel_count[motor] > 1)
                {
                    eep_params.mode_sms_accel_count[motor]--;
                }
                if (mode_smsCOUNT_SUM_TOO_HIGH(motor) && eep_params.mode_sms_decel_count[motor] > 1)
                {
                    eep_params.mode_sms_decel_count[motor]--;
                }
                if (!mode_smsCOUNT_SUM_TOO_HIGH(motor))
                {
                    break;
                }
            }

            int32_t steps = eep_params.mode_sms_positions[1].pos[motor] - eep_params.mode_sms_positions[0].pos[motor];

            //int32_t img_count = (int32_t)eep_params.mode_sms_count;
            int32_t step_count = (int32_t)eep_params.mode_sms_count - 1;
            int32_t ramp_count = (int32_t)eep_params.mode_sms_accel_count[motor] + (int32_t)eep_params.mode_sms_decel_count[motor];
            int32_t lead_count = (int32_t)eep_params.mode_sms_leadin_count[motor] + (int32_t)eep_params.mode_sms_leadout_count[motor];
            int32_t move_count = step_count - lead_count;
            int32_t run_count = step_count - lead_count - ramp_count;

            if (move_count > 0 && steps != 0)
            {
                run_steps[motor] = 2 * steps / (2 * run_count + ramp_count);
                accel_steps_x1000[motor] = run_steps[motor] * 1000 / (int32_t)eep_params.mode_sms_accel_count[motor];
                decel_steps_x1000[motor] = run_steps[motor] * 1000 / (int32_t)eep_params.mode_sms_decel_count[motor];
            }
            else
            {
                run_steps[motor] = 0;
                accel_steps_x1000[motor] = 0;
                decel_steps_x1000[motor] = 0;
            }
        }
        
        test_mode = mode_smsTEST_NONE;
        
        current_step = 0;
        current_loop = 0;
        step_timer = 0;
        interval_timer = 0;
   
        vModeSmsCalcTime();
        
        overall_time = eep_params.mode_sms_count * eep_params.mode_sms_interval;

        state = MODE_SMS_STATE_WAKE_SM;
        xTimerStart(xModeSmsControlTimer, 0);
    }
    taskEXIT_CRITICAL();
}
Example #28
0
signed portBASE_TYPE xQueueReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait )
{
signed portBASE_TYPE xReturn;

	/* This function is very similar to xQueueSend().  See comments within
	xQueueSend() for a more detailed explanation.

	Make sure other tasks do not access the queue. */
	vTaskSuspendAll();

	/* Make sure interrupts do not access the queue. */
	prvLockQueue( pxQueue );

	/* If there are no messages in the queue we may have to block. */
	if( prvIsQueueEmpty( pxQueue ) )
	{
		/* There are no messages in the queue, do we want to block or just
		leave with nothing? */			
		if( xTicksToWait > ( portTickType ) 0 )
		{
			vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );
			taskENTER_CRITICAL();
			{
				prvUnlockQueue( pxQueue );
				if( !xTaskResumeAll() )
				{
					taskYIELD();
				}

				vTaskSuspendAll();
				prvLockQueue( pxQueue );
			}
			taskEXIT_CRITICAL();
		}
	}

	taskENTER_CRITICAL();
	{
		if( pxQueue->uxMessagesWaiting > ( unsigned portBASE_TYPE ) 0 )
		{
			pxQueue->pcReadFrom += pxQueue->uxItemSize;
			if( pxQueue->pcReadFrom >= pxQueue->pcTail )
			{
				pxQueue->pcReadFrom = pxQueue->pcHead;
			}
			--( pxQueue->uxMessagesWaiting );
			memcpy( ( void * ) pvBuffer, ( void * ) pxQueue->pcReadFrom, ( unsigned ) pxQueue->uxItemSize );

			/* Increment the lock count so prvUnlockQueue knows to check for
			tasks waiting for space to become available on the queue. */
			++( pxQueue->xRxLock );
			xReturn = pdPASS;
		}
		else
		{
			xReturn = pdFAIL;
		}
	}
	taskEXIT_CRITICAL();

	/* We no longer require exclusive access to the queue. */
	if( prvUnlockQueue( pxQueue ) )
	{
		if( !xTaskResumeAll() )
		{
			taskYIELD();
		}
	}
	else
	{
		xTaskResumeAll();
	}

	return xReturn;
}
Example #29
0
EventBits_t xEventGroupWaitBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, const BaseType_t xClearOnExit, const BaseType_t xWaitForAllBits, TickType_t xTicksToWait )
{
EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup;
EventBits_t uxReturn, uxControlBits = 0;
BaseType_t xWaitConditionMet, xAlreadyYielded;

	/* Check the user is not attempting to wait on the bits used by the kernel
	itself, and that at least one bit is being requested. */
	configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
	configASSERT( uxBitsToWaitFor != 0 );
	#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
	{
		configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
	}
	#endif

	vTaskSuspendAll();
	{
		const EventBits_t uxCurrentEventBits = pxEventBits->uxEventBits;

		traceEVENT_GROUP_WAIT_BITS_START( xEventGroup, uxBitsToWaitFor );

		/* Check to see if the wait condition is already met or not. */
		xWaitConditionMet = prvTestWaitCondition( uxCurrentEventBits, uxBitsToWaitFor, xWaitForAllBits );

		if( xWaitConditionMet != pdFALSE )
		{
			/* The wait condition has already been met so there is no need to
			block. */
			uxReturn = uxCurrentEventBits;
			xTicksToWait = ( TickType_t ) 0;

			/* Clear the wait bits if requested to do so. */
			if( xClearOnExit != pdFALSE )
			{
				pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
			}
			else
			{
				mtCOVERAGE_TEST_MARKER();
			}
		}
		else if( xTicksToWait == ( TickType_t ) 0 )
		{
			/* The wait condition has not been met, but no block time was
			specified, so just return the current value. */
			uxReturn = uxCurrentEventBits;
		}
		else
		{
			/* The task is going to block to wait for its required bits to be
			set.  uxControlBits are used to remember the specified behaviour of
			this call to xEventGroupWaitBits() - for use when the event bits
			unblock the task. */
			if( xClearOnExit != pdFALSE )
			{
				uxControlBits |= eventCLEAR_EVENTS_ON_EXIT_BIT;
			}
			else
			{
				mtCOVERAGE_TEST_MARKER();
			}

			if( xWaitForAllBits != pdFALSE )
			{
				uxControlBits |= eventWAIT_FOR_ALL_BITS;
			}
			else
			{
				mtCOVERAGE_TEST_MARKER();
			}

			/* Store the bits that the calling task is waiting for in the
			task's event list item so the kernel knows when a match is
			found.  Then enter the blocked state. */
			vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | uxControlBits ), xTicksToWait );

			/* This is obsolete as it will get set after the task unblocks, but
			some compilers mistakenly generate a warning about the variable
			being returned without being set if it is not done. */
			uxReturn = 0;
		}
	}
	xAlreadyYielded = xTaskResumeAll();

	if( xTicksToWait != ( TickType_t ) 0 )
	{
		if( xAlreadyYielded == pdFALSE )
		{
			portYIELD_WITHIN_API();
		}
		else
		{
			mtCOVERAGE_TEST_MARKER();
		}

		/* The task blocked to wait for its required bits to be set - at this
		point either the required bits were set or the block time expired.  If
		the required bits were set they will have been stored in the task's
		event list item, and they should now be retrieved then cleared. */
		uxReturn = uxTaskResetEventItemValue();

		if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 )
		{
			taskENTER_CRITICAL();
			{
				/* The task timed out, just return the current event bit value. */
				uxReturn = pxEventBits->uxEventBits;

				/* It is possible that the event bits were updated between this
				task leaving the Blocked state and running again. */
				if( prvTestWaitCondition( uxReturn, uxBitsToWaitFor, xWaitForAllBits ) != pdFALSE )
				{
					if( xClearOnExit != pdFALSE )
					{
						pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
					}
					else
					{
						mtCOVERAGE_TEST_MARKER();
					}
				}
				else
				{
					mtCOVERAGE_TEST_MARKER();
				}
			}
			taskEXIT_CRITICAL();
		}
		else
		{
			/* The task unblocked because the bits were set.  Clear the control
			bits before returning the value. */
			uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;
		}
	}

	traceEVENT_GROUP_WAIT_BITS_END( xEventGroup, uxReturn );
	return uxReturn;
}
Example #30
0
EventBits_t xEventGroupSync( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToSet, const EventBits_t uxBitsToWaitFor, TickType_t xTicksToWait )
{
EventBits_t uxOriginalBitValue, uxReturn;
EventGroup_t *pxEventBits = ( EventGroup_t * ) xEventGroup;
BaseType_t xAlreadyYielded;

	configASSERT( ( uxBitsToWaitFor & eventEVENT_BITS_CONTROL_BYTES ) == 0 );
	configASSERT( uxBitsToWaitFor != 0 );
	#if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )
	{
		configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );
	}
	#endif

	vTaskSuspendAll();
	{
		traceEVENT_GROUP_SYNC_START( xEventGroup, uxBitsToSet );

		uxOriginalBitValue = pxEventBits->uxEventBits;

		( void ) xEventGroupSetBits( xEventGroup, uxBitsToSet );

		if( ( ( uxOriginalBitValue | uxBitsToSet ) & uxBitsToWaitFor ) == uxBitsToWaitFor )
		{
			/* All the rendezvous bits are now set - no need to block. */
			uxReturn = ( uxOriginalBitValue | uxBitsToSet );

			/* Rendezvous always clear the bits.  They will have been cleared
			already unless this is the only task in the rendezvous. */
			pxEventBits->uxEventBits &= uxBitsToWaitFor;

			xTicksToWait = 0;
		}
		else
		{
			if( xTicksToWait != ( TickType_t ) 0 )
			{
				/* Store the bits that the calling task is waiting for in the
				task's event list item so the kernel knows when a match is
				found.  Then enter the blocked state. */
				vTaskPlaceOnUnorderedEventList( &( pxEventBits->xTasksWaitingForBits ), ( uxBitsToWaitFor | eventCLEAR_EVENTS_ON_EXIT_BIT | eventWAIT_FOR_ALL_BITS ), xTicksToWait );

				/* This assignment is obsolete as uxReturn will get set after
				the task unblocks, but some compilers mistakenly generate a
				warning about uxReturn being returned without being set if the
				assignment is omitted. */
				uxReturn = 0;
			}
			else
			{
				/* The rendezvous bits were not set, but no block time was
				specified - just return the current event bit value. */
				uxReturn = pxEventBits->uxEventBits;
			}
		}
	}
	xAlreadyYielded = xTaskResumeAll();

	if( xTicksToWait != ( TickType_t ) 0 )
	{
		if( xAlreadyYielded == pdFALSE )
		{
			portYIELD_WITHIN_API();
		}
		else
		{
			mtCOVERAGE_TEST_MARKER();
		}

		/* The task blocked to wait for its required bits to be set - at this
		point either the required bits were set or the block time expired.  If
		the required bits were set they will have been stored in the task's
		event list item, and they should now be retrieved then cleared. */
		uxReturn = uxTaskResetEventItemValue();

		if( ( uxReturn & eventUNBLOCKED_DUE_TO_BIT_SET ) == ( EventBits_t ) 0 )
		{
			/* The task timed out, just return the current event bit value. */
			taskENTER_CRITICAL();
			{
				uxReturn = pxEventBits->uxEventBits;

				/* Although the task got here because it timed out before the
				bits it was waiting for were set, it is possible that since it
				unblocked another task has set the bits.  If this is the case
				then it may be required to clear the bits before exiting. */
				if( ( uxReturn & uxBitsToWaitFor ) == uxBitsToWaitFor )
				{
					pxEventBits->uxEventBits &= ~uxBitsToWaitFor;
				}
				else
				{
					mtCOVERAGE_TEST_MARKER();
				}
			}
			taskEXIT_CRITICAL();
		}
		else
		{
			/* The task unblocked because the bits were set.  Clear the control
			bits before returning the value. */
			uxReturn &= ~eventEVENT_BITS_CONTROL_BYTES;
		}
	}

	traceEVENT_GROUP_SYNC_END( xEventGroup, uxReturn );
	return uxReturn;
}