Ejemplo n.º 1
0
	TaskHandle_t MPU_xTaskGetCurrentTaskHandle( void )
	{
	TaskHandle_t xReturn;
    BaseType_t xRunningPrivileged = prvRaisePrivilege();

		xReturn = xTaskGetCurrentTaskHandle();
        portRESET_PRIVILEGE( xRunningPrivileged );
		return xReturn;
	}
Ejemplo n.º 2
0
/**
  * @brief  Stop Idle monitor
  * @param  None
  * @retval None
  */
void EndIdleMonitor (void)
{
  if( xTaskGetCurrentTaskHandle() == xIdleHandle )
  {
    /* Store the handle to the idle task. */
    osCPU_IdleSpentTime = xTaskGetTickCountFromISR() - osCPU_IdleStartTime;
    osCPU_TotalIdleTime += osCPU_IdleSpentTime;
  }
}
Ejemplo n.º 3
0
	xTaskHandle MPU_xTaskGetCurrentTaskHandle( void )
	{
	xTaskHandle xReturn;
    portBASE_TYPE xRunningPrivileged = prvRaisePrivilege();

		xReturn = xTaskGetCurrentTaskHandle();
        portRESET_PRIVILEGE( xRunningPrivileged );
		return xReturn;
	}
Ejemplo n.º 4
0
	TaskHandle_t MPU_xTaskGetCurrentTaskHandle( void )
	{
	TaskHandle_t xReturn;
	BaseType_t xRunningPrivileged = xPortRaisePrivilege();

		xReturn = xTaskGetCurrentTaskHandle();
		vPortResetPrivilege( xRunningPrivileged );
		return xReturn;
	}
Ejemplo n.º 5
0
Archivo: port.c Proyecto: moussu/GLiP
void vPortForciblyEndThread( void *pxTaskToDelete )
{
xTaskHandle hTaskToDelete = ( xTaskHandle )pxTaskToDelete;
pthread_t xTaskToDelete;
pthread_t xTaskToResume;

	if ( 0 == pthread_mutex_lock( &xSingleThreadMutex ) )
	{
		xTaskToDelete = prvGetThreadHandle( hTaskToDelete );
		xTaskToResume = prvGetThreadHandle( xTaskGetCurrentTaskHandle() );

		if ( xTaskToResume == xTaskToDelete )
		{
			/* This is a suicidal thread, need to select a different task to run. */
			vTaskSwitchContext();
			xTaskToResume = prvGetThreadHandle( xTaskGetCurrentTaskHandle() );
		}

		if ( pthread_self() != xTaskToDelete )
		{
			/* Cancelling a thread that is not me. */
			if ( xTaskToDelete != ( pthread_t )NULL )
			{
				/* Send a signal to wake the task so that it definitely cancels. */
				pthread_testcancel();
				pthread_cancel( xTaskToDelete );
				/* Pthread Clean-up function will note the cancellation. */
			}
			(void)pthread_mutex_unlock( &xSingleThreadMutex );
		}
		else
		{
			/* Resume the other thread. */
			prvResumeThread( xTaskToResume );
			/* Pthread Clean-up function will note the cancellation. */
			/* Release the execution. */
			uxCriticalNesting = 0;
			vPortEnableInterrupts();
			(void)pthread_mutex_unlock( &xSingleThreadMutex );
			/* Commit suicide */
			pthread_exit( (void *)1 );
		}
	}
}
Ejemplo n.º 6
0
signed portBASE_TYPE xDoIOwnTheMutex( xMutexHandle pxMutex )
{
    portBASE_TYPE c;

    portENTER_CRITICAL( );
    c = pxMutex->pxOwner == xTaskGetCurrentTaskHandle( );
    portEXIT_CRITICAL( );

    return c;
}
Ejemplo n.º 7
0
int *task_getCurrentIndex(){
  int i;TaskHandle_t handle;
  handle = xTaskGetCurrentTaskHandle();
  for(i = 0; i < taskMax; i++){
	if(RTOStasks[i].handle == handle){
	  return i;
	}
  }
  return NULL;
}
Ejemplo n.º 8
0
char *task_getCurrentName(){
  int i;TaskHandle_t handle;
  handle = xTaskGetCurrentTaskHandle();
  for(i = 0; i < taskMax; i++){
    if(RTOStasks[i].handle == handle){
	  return RTOStasks[i].name;
    }
  }
  return NULL;
}
Ejemplo n.º 9
0
void mp_thread_start(void) {
    mp_thread_mutex_lock(&thread_mutex, 1);
    for (thread_t *th = thread; th != NULL; th = th->next) {
        if (th->id == xTaskGetCurrentTaskHandle()) {
            th->ready = 1;
            break;
        }
    }
    mp_thread_mutex_unlock(&thread_mutex);
}
Ejemplo n.º 10
0
void mp_thread_finish(void) {
    mp_thread_mutex_lock(&thread_mutex, 1);
    // TODO unlink from list
    for (thread_t *th = thread; th != NULL; th = th->next) {
        if (th->id == xTaskGetCurrentTaskHandle()) {
            th->ready = 0;
            break;
        }
    }
    mp_thread_mutex_unlock(&thread_mutex);
}
Ejemplo n.º 11
0
void *aos_task_getspecific(aos_task_key_t key)
{
    AosStaticTask_t *task = (AosStaticTask_t *)xTaskGetCurrentTaskHandle();
    if (key >= 4)
        return NULL;

    if (task->magic != AOS_MAGIC)
        return NULL;

    return task->keys[key];
}
Ejemplo n.º 12
0
void vPortStartFirstTask( void )
{
	/* Initialise the critical nesting count ready for the first task. */
	uxCriticalNesting = 0;

	/* Start the first task. */
	vPortEnableInterrupts();

	/* Start the first task. */
	prvResumeThread( prvGetThreadHandle( xTaskGetCurrentTaskHandle() ) );
}
Ejemplo n.º 13
0
/**
  * @brief  This function handles Hard Fault exception.
  * @param  None
  * @retval None
  */
void HardFault_Handler(void)
{
#ifdef FREERTOS_CONFIG_H
  CurrentTaskHandle = xTaskGetCurrentTaskHandle();
  pNameCurrentTask = pcTaskGetTaskName(CurrentTaskHandle);    
#endif
  
  /* Go to infinite loop when Hard Fault exception occurs */
  while (1)
  {
  }
}
Ejemplo n.º 14
0
int aos_task_setspecific(aos_task_key_t key, void *vp)
{
    AosStaticTask_t *task = (AosStaticTask_t *)xTaskGetCurrentTaskHandle();
    if (key >= 4)
        return -1;

    if (task->magic != AOS_MAGIC)
        return -1;

    task->keys[key] = vp;
    return 0;
}
Ejemplo n.º 15
0
int mp_thread_gc_others(void) {
/*    mp_thread_mutex_lock(&thread_mutex, 1);
    for (thread_t *th = thread; th != NULL; th = th->next) {
        gc_collect_root((void**)&th, 1);
        gc_collect_root(&th->arg, 1); // probably not needed
        if (th->id == xTaskGetCurrentTaskHandle()) {
            continue;
        }
        if (!th->ready) {
            continue;
        }
        gc_collect_root(th->stack, th->stack_len); // probably not needed
    }
    mp_thread_mutex_unlock(&thread_mutex);
*/
    int n_th = 0;
    void **ptrs;
    mp_state_thread_t *state;

    mp_thread_mutex_lock(&thread_mutex, 1);
    for (thread_t *th = thread; th != NULL; th = th->next) {
        if (!th->ready) continue;                               // thread not ready
		//if (th->type == THREAD_TYPE_SERVICE) continue;          // Only scan PYTHON threads
        if (th->id == xTaskGetCurrentTaskHandle()) continue;    // Do not process the running thread

        //state = (mp_state_thread_t *)th->state_thread;
        n_th++;

        // Mark the root pointers on thread
        //gc_collect_root((void **)state->dict_locals, 1);

        if (th->arg) {
            // Mark the pointers on thread arguments
            ptrs = (void**)(void*)&th->arg;
            gc_collect_root(ptrs, 1);
        }

        #if MICROPY_ENABLE_PYSTACK
        // Mark the pointers on thread pystack
        //ptrs = (void**)(void*)state->pystack_start;
        //gc_collect_root(ptrs, (state->pystack_cur - state->pystack_start) / sizeof(void*));
        #endif

        // If PyStack is used, no pointers to MPy heap are placed on tasks stack
        #if !MICROPY_ENABLE_PYSTACK
        // Mark the pointers on thread stack
        //gc_collect_root(th->curr_sp, ((void *)state->stack_top - th->curr_sp) / sizeof(void*)); // probably not needed
        #endif
    }
    mp_thread_mutex_unlock(&thread_mutex);
    return n_th;
	
}
Ejemplo n.º 16
0
signed portBASE_TYPE xMutexTake( xMutexHandle pxMutex, portTickType xTicksToWait )
{
    portENTER_CRITICAL( );
    if ( pxMutex->pxOwner == xTaskGetCurrentTaskHandle( ) )
    {
        pxMutex->uxCount++;
        portEXIT_CRITICAL( );
        return pdTRUE;
    }

    if ( ( xTicksToWait > ( portTickType ) 0 ) && ( pxMutex->pxOwner != NULL ) )
    {
        vTaskPlaceOnEventList( &( pxMutex->xTasksWaitingToTake ), xTicksToWait );
        taskYIELD( );

        if ( pxMutex->pxOwner == xTaskGetCurrentTaskHandle( ) )
        {
            pxMutex->uxCount = 1;
            portEXIT_CRITICAL( );
            return pdTRUE;
        }
        else
        {
            portEXIT_CRITICAL( );
            return pdFALSE;
        }
    }

    if ( pxMutex->pxOwner == NULL )
    {
        pxMutex->pxOwner = xTaskGetCurrentTaskHandle( );
        pxMutex->uxCount = 1;
        portEXIT_CRITICAL( );
        return pdTRUE;
    }

    portEXIT_CRITICAL( );
    return pdFALSE;
}
Ejemplo n.º 17
0
void mp_thread_init(void) {
    mp_thread_mutex_init(&thread_mutex);
    mp_thread_set_state(&mp_state_ctx.thread);

    // create first entry in linked list of all threads
    thread = &thread_entry0;
    thread->id = xTaskGetCurrentTaskHandle();
    thread->ready = 1;
    thread->arg = NULL;
    thread->stack = mpTaskStack;
    thread->stack_len = MICROPY_TASK_STACK_LEN;
    thread->next = NULL;
}
Ejemplo n.º 18
0
void mp_thread_init(void *stack, uint32_t stack_len) {
    mp_thread_set_state(&mp_state_ctx.thread);
    // create the first entry in the linked list of all threads
    thread = &thread_entry0;
    thread->id = xTaskGetCurrentTaskHandle();
    thread->ready = 1;
    thread->arg = NULL;
    thread->stack = stack;
    thread->stack_len = stack_len;
    thread->next = NULL;
    mp_thread_mutex_init(&thread_mutex);
   // MP_THREAD_GIL_EXIT();
}
Ejemplo n.º 19
0
void test_task_get_state(void* arg)
{
    //Current task should return eRunning
    TEST_ASSERT(eTaskGetState(xTaskGetCurrentTaskHandle()) == eRunning);
    //Idle task of current core should return eReady
    TEST_ASSERT(eTaskGetState(xTaskGetIdleTaskHandle()) == eReady);
    //Blocked Task should return eBlocked
    TEST_ASSERT(eTaskGetState(blocked_task_handle) == eBlocked);
    //Suspended Task should return eSuspended
    TEST_ASSERT(eTaskGetState(suspended_task_handle) == eSuspended);

    xSemaphoreGive(done_sem);
    vTaskDelete(NULL);
}
Ejemplo n.º 20
0
void mp_thread_finish(void) {
    mp_thread_mutex_lock(&thread_mutex, 1);
    thread_t *th = thread;
    thread_t *pre_th = NULL;
    for (th = thread; th != NULL; th = th->next) {
        if (th->id == xTaskGetCurrentTaskHandle()) {
            th->ready = 0;
            //mp_thread_delete(pre_th,th);//TODO:wether need to delete threand to free memory
            break;
        }
        pre_th = th;
    }
    mp_thread_mutex_unlock(&thread_mutex);
}
Ejemplo n.º 21
0
/*
 * Returns the thread control block for the currently active task. In case
 * of an error the functions returns NULL.
 */
sys_thread_t
sys_arch_thread_current( void )
{
    sys_tcb_t      *p = tasks;
    xTaskHandle     pid = xTaskGetCurrentTaskHandle(  );

    vPortEnterCritical(  );
    while( ( p != NULL ) && ( p->pid != pid ) )
    {
        p = p->next;
    }
    vPortExitCritical(  );
    return p;
}
Ejemplo n.º 22
0
static void vHelloWorld( void *pvParameters ) {
	xTaskHandle thisTask = xTaskGetCurrentTaskHandle();
	char buf[64];
	/* The parameters are not used. */
	( void ) pvParameters;

	consoleInit();
	vTaskList(buf);
	printf("%s", buf);

	for( ;; ) {
		printf("Running: %u\r\n", xTaskGetTickCount());
		vTaskDelay( 5000 );
	}
}
Ejemplo n.º 23
0
void mp_thread_gc_others(void) {
    mp_thread_mutex_lock(&thread_mutex, 1);
    for (thread_t *th = thread; th != NULL; th = th->next) {
        gc_collect_root((void**)&th, 1);
        gc_collect_root(&th->arg, 1); // probably not needed
        if (th->id == xTaskGetCurrentTaskHandle()) {
            continue;
        }
        if (!th->ready) {
            continue;
        }
        gc_collect_root(th->stack, th->stack_len); // probably not needed
    }
    mp_thread_mutex_unlock(&thread_mutex);
}
Ejemplo n.º 24
0
static inline void mqtt_task()
{
    struct Network network;
    char client_id[20];
    uint8_t mqtt_buf[100];
    uint8_t mqtt_readbuf[100];
    MQTTPacket_connectData data = MQTTPacket_connectData_initializer;

    NewNetwork( &network );
    strcpy(client_id, "esp-gizmo-ir");

    if (ConnectNetwork(&network, config_get_mqtt_host(),
                config_get_mqtt_port()) != 0) {
        printf("Connect to MQTT server failed\n");
        return;
    }

    NewMQTTClient(&mqtt_client, &network, 5000, mqtt_buf, 100, mqtt_readbuf, 100);

    data.willFlag       = 0;
    data.MQTTVersion    = 3;
    data.clientID.cstring   = client_id;
    data.username.cstring   = NULL;
    data.password.cstring   = NULL;
    data.keepAliveInterval  = 10;
    data.cleansession   = 0;

    printf("Send MQTT connect ... \n");
    if (MQTTConnect(&mqtt_client, &data) != 0) {
        printf("MQTT connect failed\n");
        return;
    }

    const char *topic = config_get_cmd_topic();
    printf("Sibscribe to topic: %s\n", topic);
    if (MQTTSubscribe(&mqtt_client, topic, QOS1, topic_received) != 0) {
        printf("Subscription failed\n");
        return;
    }

    while (MQTTYield(&mqtt_client, 1000) != DISCONNECTED) {
        printf("free heap: %d bytes\n", xPortGetFreeHeapSize());
        uint16_t free_stack = uxTaskGetStackHighWaterMark(xTaskGetCurrentTaskHandle());
        printf("minimum free stack: %d bytes\n", free_stack);
    };

    printf("Connection dropped, request restart\n");
}
Ejemplo n.º 25
0
uint CreatorThread_GetThreadID(CreatorThread self)
{
    uint result = 0;
    xTaskHandle currentTask;
    if (self)
    {
        ThreadInfo *threadInfo = (ThreadInfo*)self;
        currentTask = threadInfo->ThreadID;
    }
    else
    {
        currentTask = xTaskGetCurrentTaskHandle();
    }
    result = (uint)uxTaskGetTaskNumber(currentTask);
    return result;
}
Ejemplo n.º 26
0
void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength )
{
const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 150UL );

	( void ) pxPort;

	/* Note this is the currently sending task. */
	xUARTSendingTask = xTaskGetCurrentTaskHandle();

	/* Output uxStringLength bytes starting from pcString. */
	XUartLite_Send( &xUartLiteInstance, ( unsigned char * ) pcString, usStringLength );

	/* Wait in the Blocked state (so not using any CPU time) for the Tx to
	complete. */
	ulTaskNotifyTake( pdTRUE, xMaxBlockTime );
}
Ejemplo n.º 27
0
/*
 * Returns the thread control block for the currently active task. In case
 * of an error the functions returns NULL.
 */
sys_tcb_t
*sys_arch_thread_current( void )
{
	OS_SR_SAVE_VAR
	sys_tcb_t      *p = tasks;
	sys_thread_t   pid = xTaskGetCurrentTaskHandle();

    // Enter Critical Section
    OSEnterCritical();
    while( ( p != NULL ) && ( p->pid != pid ) )
    {
        p = p->next;
    }
    // Exit Critical Section
    OSExitCritical();
    return p;
}
Ejemplo n.º 28
0
void mp_thread_deinit(void) {

    mp_thread_mutex_lock(&thread_mutex, 1);
    for (thread_t *th = thread; th != NULL; th = th->next) {
        // don't delete the current task
        if (th->id == xTaskGetCurrentTaskHandle()) {
            continue;
        }
        vTaskDelete(th->id);
        // m_del_obj(thread_t,th);
        free(th);
    }
    mp_thread_mutex_unlock(&thread_mutex);
    // allow FreeRTOS to clean-up the threads
    vTaskDelay(2);

}
Ejemplo n.º 29
0
bool CreatorThread_SleepTicks(CreatorThread self, uint ticks)
{
    bool result = false;
    if (ticks > 0)
    {
        if (self)
        {
            ThreadInfo *threadInfo = (ThreadInfo*)self;
            xTaskHandle currentTask = xTaskGetCurrentTaskHandle();
            result = (currentTask == threadInfo->ThreadID);
        }
        else
        result = true;
        if (result)
        vTaskDelay(ticks);
    }
    return result;
}
Ejemplo n.º 30
0
int aos_task_key_create(aos_task_key_t *key)
{
    AosStaticTask_t *task = (AosStaticTask_t *)xTaskGetCurrentTaskHandle();
    int i;

    if (task->magic != AOS_MAGIC)
        return -1;

    for (i=0;i<4;i++) {
        if (task->key_bitmap & (1 << i))
            continue;

        task->key_bitmap |= 1 << i;
        *key = i;
        return 0;
    }

    return -1;
}