Ejemplo n.º 1
0
int
PRIMITIVE_CLOSE(int fileID)
{
    interrupt_state istate;

    _LOCK_PRIMIO();
    PrimIOCB.op = PRIM_CLOSE;
    PrimIOCB.fileID = fileID;
    PrimIOCB.flags = 0;          /* (not used) */

    PrimIOCB.more = NULL;

    DISABLE_INTERRUPTS(istate);
#if defined(__ADSPBLACKFIN__)
    FLUSH_CACHE_PRIMIOCB();
    DISABLE_CACHE();
    SYNCH_MEMORY();
#endif
    _primIO();
#if defined(__ADSPBLACKFIN__)
    ENABLE_CACHE();
#endif
    ENABLE_INTERRUPTS(istate);
    _UNLOCK_PRIMIO();

    return 0;
}
Ejemplo n.º 2
0
uint16_t output_buffer_index_write_increment() {
    INTERRUPT_DECLARATION();
    DISABLE_INTERRUPTS();
    openserial_vars.output_buffer_index_write=(openserial_vars.output_buffer_index_write+1)%SERIAL_OUTPUT_BUFFER_SIZE;
    ENABLE_INTERRUPTS();
    return openserial_vars.output_buffer_index_write;
}
Ejemplo n.º 3
0
void schedule_advanceSlot() {
   INTERRUPT_DECLARATION();
   DISABLE_INTERRUPTS();
   // advance to next active slot
   schedule_vars.currentScheduleEntry = schedule_vars.currentScheduleEntry->next;
   ENABLE_INTERRUPTS();
}
Ejemplo n.º 4
0
void StartApplication( void (*StartAddress)() )
{
    PortBooterLoadProgram((void**)&StartAddress);

    hal_printf( "Starting main application at 0x%08x\r\n", (size_t)StartAddress );

    LCD_Clear();

    USART_Flush( ConvertCOM_ComPort(g_State.UsartPort) );

    if(g_State.UsingUsb)
    {
        USB_Flush( ConvertCOM_UsbStream( g_State.UsbPort ) );
        USB_CloseStream( ConvertCOM_UsbStream(g_State.UsbPort) );
        USB_Uninitialize( ConvertCOM_UsbController(g_State.UsbPort) );     //disable the USB for the next application
    }

    DISABLE_INTERRUPTS();

    LCD_Uninitialize();

    CPU_DisableCaches();

    (*StartAddress)();

}
Ejemplo n.º 5
0
error_t openserial_printError(uint8_t calling_component, uint8_t error_code,
                              errorparameter_t arg1,
                              errorparameter_t arg2) {
    leds_error_toggle();
    INTERRUPT_DECLARATION();
    DISABLE_INTERRUPTS();

    openserial_vars.somethingInOutputBuffer=TRUE;
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t)'^';                  //preamble
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t)'^';
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t)'^';
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t)'E';                  //this is an error
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t)((idmanager_getMyID(ADDR_16B))->addr_16b[1]);
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t)((idmanager_getMyID(ADDR_16B))->addr_16b[0]);
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t)calling_component;    //component generating error
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t)error_code;           //error_code
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t)((arg1 & 0xff00)>>8); //arg1
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t) (arg1 & 0x00ff);
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t)((arg2 & 0xff00)>>8); //arg2
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t) (arg2 & 0x00ff);
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t)'$';                  //postamble
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t)'$';
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t)'$';
    ENABLE_INTERRUPTS();

    return E_SUCCESS;
}
Ejemplo n.º 6
0
sRITqueue RITQueue_Get_Element(uint8_t pos)
{
	sRITqueue  elem;

	//EnterCriticalSection
	INTERRUPT_DECLARATION();
	DISABLE_INTERRUPTS();

	if (RITQueue_IsEmpty() == false)
	{
		if ( pos < maxElements)
		{
			elem = pvObjList[pos];
		}
		else
		{
			elem.frameType = 0;
			RITQueue_ClearAddress(&elem.destaddr);
 		}
	}
	else
	{
		elem.frameType = 0;
		RITQueue_ClearAddress(&elem.destaddr);
	}

	//LeaveCriticalSection
	ENABLE_INTERRUPTS();

	return elem;
}
Ejemplo n.º 7
0
/*
 * Verifica se existe algum frame pendente
 */
bool RITQueue_ExistFramePending(void)
{
	bool ret = false;
	uint8_t  i;

	//EnterCriticalSection
	INTERRUPT_DECLARATION();
	DISABLE_INTERRUPTS();

	for (i = 0; i < maxElements; i++)
	{
		if (pvObjList[i].pending)
		{
			if (pvObjList[i].countretry < 3)
			{
				ret = true;
				break;
			}
			else  //REMOVO O ELEMENTO QUE JA ESTA A TEMPOS AQUI
			{
				RITQueue_Free(i);
			}
		}
	}

   if (coappending)
	   ret = true;


	//LeaveCriticalSection
	ENABLE_INTERRUPTS();

	return ret;
}
Ejemplo n.º 8
0
int drvSysTick_getUptime(struct timeval* uptime)
{
    unsigned int sysTickValue; // System Tick counter counts down!

    CHECK_STARTED_INT(&sInstDscr, 0);
    CHECK_POINTER_INT(uptime);

    /* Note that SysTick->VAL counts down and rolls over to SysTick->LOAD
     * when reaching 0 even if interrupts are disabled.
     * Therefore, if SysTick->VAL rolls over while reading out uptime,
     * try again. Could use outdated uptime otherwise.
     */
    do
    {
        SysTick->CTRL &= ~SysTick_CTRL_COUNTFLAG_Msk;
        DISABLE_INTERRUPTS();
        sysTickValue = SysTick->VAL;
        *uptime = sInstDscr.uptime;
        ENABLE_INTERRUPTS();
    } while (SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk);
    sysTickValue = SysTick->LOAD - sysTickValue;
    /* Initial code, when uptime was of type unsigned long long:
     * *uptime += (unsigned long long)sysTickValue * 1000000 / SystemCoreClock;
     * However, this invokes the function __aeabi_uldivmod() for the 64bit
     * integer division. Takes quite long. With a simple trick (divide
     * numerator and divisor by 1000) the division can be kept in the integer
     * range. That causes the compiler to use the UDIV instruction, which is
     * much faster executed than the __aeabi_uldivmod() function.
     */
    uptime->tv_usec += sysTickValue * 1000UL / (SystemCoreClock / 1000UL);
    uptime->tv_sec += uptime->tv_usec / 1000000UL;
    uptime->tv_usec %= 1000000UL;
    return R_SUCCESS;
}
Ejemplo n.º 9
0
int uart0_in (ECTX ectx, WORD count, BYTEPTR pointer)
{
	unsigned short imask;
	int reschedule;
	
	DISABLE_INTERRUPTS (imask);

	if (rx_pending) {
		write_byte (pointer, (BYTE) rx_buffer);
		rx_pending	= 0;
		BARRIER;
		reschedule	= 0;
	} else {
		rx_channel	= ectx->wptr;
		rx_ptr		= pointer;
		BARRIER;
		reschedule	= 1;
	}

	ENABLE_INTERRUPTS (imask);

	if (reschedule) {
		/* Lower (set) CTS */
		*pPORTHIO_CLEAR = CTS_MASK;
		/* Save instruction pointer */
		WORKSPACE_SET (ectx->wptr, WS_IPTR, (WORD) ectx->iptr);
		/* Reschedule */
		return ectx->run_next_on_queue (ectx);
	} else {
		return ECTX_CONTINUE;
	}
}
Ejemplo n.º 10
0
void Gyro_Calculation(Gyro * gyro)
{
	short velocity;
	short angular_velocity;
	CPU_MSR msr;
	//gyro.velocityBack = pid.currentVelocityBack;

	msr = DISABLE_INTERRUPTS();
	velocity = raw_gyro_data.velocity;
	angular_velocity = raw_gyro_data.angular_velocity;
	RESTORE_INTERRUPTS(msr);

	// V_b
	gyro->backVelocity = raw_gyro_data.velocity;

	// W
	gyro->omega = (CONVERT_TO_RAD_SEC * raw_gyro_data.angular_velocity);

	//R_b
	gyro->backRadius = gyro->backVelocity/gyro->omega;
	// K_b
	gyro->backCurvature = gyro->omega/gyro->backVelocity;

	// V_f
	gyro->frontVelocity = gyro->backVelocity * sqrt(1+((gyro->backCurvature)*gyro->backCurvature*(gyro->wheelBase)*gyro->wheelBase));
	// K_f
	gyro->frontCurvature = gyro->omega/gyro->frontVelocity;
	//R_b
	gyro->frontRadius = gyro->frontVelocity/gyro->omega;
	// Delta
	gyro->steeringAngle = asin(gyro->wheelBase * (1/gyro->frontRadius));
}
Ejemplo n.º 11
0
inline int Gyro_GetTotalAngle(){
	CPU_MSR msr = DISABLE_INTERRUPTS();
	int millidegrees = raw_gyro_data.total_angle;
	//raw_gyro_data.total_angle = 0;
	RESTORE_INTERRUPTS(msr);
	return millidegrees * 8.75;
}
Ejemplo n.º 12
0
/**
\brief Indicate the transmission of a packet.
 */
 void schedule_indicateTx(asn_t*   asnTimestamp,
   bool     succesfullTx) {
   
   INTERRUPT_DECLARATION();
   DISABLE_INTERRUPTS();
   // increment usage statistics
   if (schedule_vars.currentScheduleEntry->numTx==0xFF) {
      schedule_vars.currentScheduleEntry->numTx/=2;
      schedule_vars.currentScheduleEntry->numTxACK/=2;
   }
   schedule_vars.currentScheduleEntry->numTx++;
   if (succesfullTx==TRUE) {
      schedule_vars.currentScheduleEntry->numTxACK++;
   }

   // update last used timestamp
   memcpy(&schedule_vars.currentScheduleEntry->lastUsedAsn, asnTimestamp, sizeof(asn_t));

   // update this slot's backoff parameters
   if (succesfullTx==TRUE) {
      // reset backoffExponent
      schedule_vars.currentScheduleEntry->backoffExponent   = MINBE-1;
      // reset backoff
      schedule_vars.currentScheduleEntry->backoff           = 0;
   } else {
      // increase the backoffExponent
      if (schedule_vars.currentScheduleEntry->backoffExponent<MAXBE) {
         schedule_vars.currentScheduleEntry->backoffExponent++;
      }
      // set the backoff to a random value in [0..2^BE]
      schedule_vars.currentScheduleEntry->backoff =
            openrandom_get16b()%(1<<schedule_vars.currentScheduleEntry->backoffExponent);
   }
   ENABLE_INTERRUPTS();
}
Ejemplo n.º 13
0
void GM_Level()
{
_restart:
	v_gamemode |= GameMode_PreLevel; // flag that we're in pre-level sequence

	if(f_demo != DemoMode_Credits)
		PlaySound_Special(BGM_Fade);

	ClearPLC();
	PaletteFadeOut();

	// If we're not doing an ending sequence demo...
	if(f_demo != DemoMode_Credits)
	{
		DISABLE_INTERRUPTS();
			NemDec(Nem_TitleCard, 0xB000);
		ENABLE_INTERRUPTS();

		auto plc1 = LevelHeaders[v_zone].gfx >> 24;

		if(plc1 != 0)
			AddPLC(plc1); // load level patterns

		AddPLC(PLC_Main2); // load standard patterns
	}
Ejemplo n.º 14
0
bool hal_aci_tl_send(hal_aci_data_t *p_aci_cmd)
{
  uint8_t length = p_aci_cmd->buffer[0];
  if (!spi_transmit_requested)
  {
//    ASSERT(ERROR_CODE_HAL_ACI_TL_OVERFLOW,(p_aci_cmd->buffer[0] <= HAL_ACI_MAX_LENGTH));
    if (length > HAL_ACI_MAX_LENGTH)
    {
      return(false);
    }
    {
      bool  is_interrupt_enabled_before_send = ARE_INTERRUPTS_ENABLED();
      DISABLE_INTERRUPTS();                           /*disable interrupts to protects the modification of the buffer pointer*/
      lib_mem_copy((uint8_t *) data_to_send.buffer, p_aci_cmd->buffer, length+1);
      spi_transmit_requested = true; // Request transmission
      if (is_interrupt_enabled_before_send)
      {
        ENABLE_INTERRUPTS();                         /*eventually re-enable the interrupts if they were enabled*/
      }
    }

    digitalWrite(reqn, LOW);

    return(true);
  }
  else
  {
    return(false);
  }
}
Ejemplo n.º 15
0
owerror_t openserial_printData(uint8_t* buffer, uint8_t length) {
   uint8_t  i;
   uint8_t  asn[5];
   INTERRUPT_DECLARATION();
   
   // retrieve ASN
   ieee154e_getAsn(asn);// byte01,byte23,byte4
   
   DISABLE_INTERRUPTS();
   openserial_vars.outputBufFilled  = TRUE;
   outputHdlcOpen();
   outputHdlcWrite(SERFRAME_MOTE2PC_DATA);
   outputHdlcWrite(idmanager_getMyID(ADDR_16B)->addr_16b[1]);
   outputHdlcWrite(idmanager_getMyID(ADDR_16B)->addr_16b[0]);
   outputHdlcWrite(asn[0]);
   outputHdlcWrite(asn[1]);
   outputHdlcWrite(asn[2]);
   outputHdlcWrite(asn[3]);
   outputHdlcWrite(asn[4]);
   for (i=0;i<length;i++){
      outputHdlcWrite(buffer[i]);
   }
   outputHdlcClose();
   ENABLE_INTERRUPTS();
   
   return E_SUCCESS;
}
Ejemplo n.º 16
0
void idmanager_setIsDAGroot(bool newRole) {
   INTERRUPT_DECLARATION();
   DISABLE_INTERRUPTS();
   idmanager_vars.isDAGroot = newRole;
   neighbors_updateMyDAGrankAndNeighborPreference();
   ENABLE_INTERRUPTS();
}
Ejemplo n.º 17
0
/**
\brief Free all the packet buffers owned by a specific module.

\param owner The identifier of the component, taken in COMPONENT_*.
*/
void openqueue_removeAllOwnedBy(uint8_t owner) {
   uint8_t i;
   uint8_t count=0;
   INTERRUPT_DECLARATION();
   DISABLE_INTERRUPTS();
   for (i=0;i<QUEUELENGTH;i++){
      if (openqueue_vars.queue[i].owner==owner) {
    	  count++;
         openqueue_reset_entry(&(openqueue_vars.queue[i]));
      }
   }
   ENABLE_INTERRUPTS();

#if ((ENABLE_DEBUG_RFF ==1)  && (DBG_OPENQUEUE == 1))
	{
		uint8_t pos=0;

		rffbuf[pos++]= RFF_OPENQUEUE_FREE;
		rffbuf[pos++]= 0x03;
		rffbuf[pos++]= owner;
		rffbuf[pos++]= count;

		openserial_printStatus(STATUS_RFF,(uint8_t*)&rffbuf,pos);
	}
#endif
}
Ejemplo n.º 18
0
void idmanager_setIsBridge(bool newRole) {
   INTERRUPT_DECLARATION();
   DISABLE_INTERRUPTS();
   idmanager_vars.isBridge = newRole;
   ENABLE_INTERRUPTS();

}
Ejemplo n.º 19
0
bool RITQueue_PutPending(uint8_t elementpos)
{
	bool ret = false;
	uint8_t  i;

	//EnterCriticalSection
	INTERRUPT_DECLARATION();
	DISABLE_INTERRUPTS();

	if (RITQueue_IsEmpty() == false)
	{
		if (elementpos < maxElements)
		{
			pvObjList[elementpos].pending = 1;
			pvObjList[elementpos].countretry++;
			ret = true;
		}
	}
	else
	{
		//printf("LISTA VAZIA!!!!! \n");
	}


	//LeaveCriticalSection
	ENABLE_INTERRUPTS();

	return ret;
}
Ejemplo n.º 20
0
open_addr_t* idmanager_getMyID(uint8_t type) {
   open_addr_t* res;
   INTERRUPT_DECLARATION();
   DISABLE_INTERRUPTS();
   switch (type) {
     case ADDR_16B:
        res= &idmanager_vars.my16bID;
        break;
     case ADDR_64B:
        res= &idmanager_vars.my64bID;
        break;
     case ADDR_PANID:
        res= &idmanager_vars.myPANID;
        break;
     case ADDR_PREFIX:
        res= &idmanager_vars.myPrefix;
        break;
     case ADDR_128B:
        // you don't ask for my full address, rather for prefix, then 64b
     default:
        openserial_printCritical(COMPONENT_IDMANAGER,ERR_WRONG_ADDR_TYPE,
              (errorparameter_t)type,
              (errorparameter_t)0);
        res= NULL;
        break;
   }
   ENABLE_INTERRUPTS();
   return res;
}
Ejemplo n.º 21
0
bool RITQueue_Free(uint8_t elementpos)
{
	bool ret = false;
	uint8_t  i;

	//EnterCriticalSection
	INTERRUPT_DECLARATION();
	DISABLE_INTERRUPTS();

	if (elementpos < maxElements)
	{
		RITQueue_ClearAddress(&pvObjList[elementpos].destaddr);
		pvObjList[elementpos].timestamp   = 0;
		pvObjList[elementpos].msglength   = 0;
		pvObjList[elementpos].frameType   = 0;
		pvObjList[elementpos].pending     = 0;
		pvObjList[elementpos].numTargetParents     = 0;
		pvObjList[elementpos].countretry  = 0;
		pvObjList[elementpos].lasttxduration  = 0;
		pvObjList[elementpos].isBroadcastMulticast = 0;

		if (numAvailableElements > 0)
			numAvailableElements--;

		ret = true;
	}


	//LeaveCriticalSection
	ENABLE_INTERRUPTS();

	return ret;
}
Ejemplo n.º 22
0
owerror_t idmanager_setMyID(open_addr_t* newID) {
   INTERRUPT_DECLARATION();
   DISABLE_INTERRUPTS();
   switch (newID->type) {
     case ADDR_16B:
        memcpy(&idmanager_vars.my16bID,newID,sizeof(open_addr_t));
        break;
     case ADDR_64B:
        memcpy(&idmanager_vars.my64bID,newID,sizeof(open_addr_t));
        break;
     case ADDR_PANID:
        memcpy(&idmanager_vars.myPANID,newID,sizeof(open_addr_t));
        break;
     case ADDR_PREFIX:
        memcpy(&idmanager_vars.myPrefix,newID,sizeof(open_addr_t));
        break;
     case ADDR_128B:
        //don't set 128b, but rather prefix and 64b
     default:
        openserial_printCritical(COMPONENT_IDMANAGER,ERR_WRONG_ADDR_TYPE,
              (errorparameter_t)newID->type,
              (errorparameter_t)1);
        ENABLE_INTERRUPTS();
        return E_FAIL;
   }
   ENABLE_INTERRUPTS();
   return E_SUCCESS;
}
Ejemplo n.º 23
0
/**
\brief Request a new (free) packet buffer.

Component throughout the protocol stack can call this function is they want to
get a new packet buffer to start creating a new packet.

\note Once a packet has been allocated, it is up to the creator of the packet
      to free it using the openqueue_freePacketBuffer() function.

\returns A pointer to the queue entry when it could be allocated, or NULL when
         it could not be allocated (buffer full or not synchronized).
*/
OpenQueueEntry_t* openqueue_getFreePacketBuffer(uint8_t creator) {
   uint8_t i;
   INTERRUPT_DECLARATION();
   DISABLE_INTERRUPTS();
   
   // refuse to allocate if we're not in sync
   if (ieee154e_isSynch()==FALSE && creator > COMPONENT_IEEE802154E){
     ENABLE_INTERRUPTS();
     return NULL;
   }
   
   // if you get here, I will try to allocate a buffer for you
   
   // walk through queue and find free entry
   for (i=0;i<QUEUELENGTH;i++) {
      if (openqueue_vars.queue[i].owner==COMPONENT_NULL) {
         openqueue_vars.queue[i].creator=creator;
         openqueue_vars.queue[i].owner=COMPONENT_OPENQUEUE;
         ENABLE_INTERRUPTS(); 
         return &openqueue_vars.queue[i];
      }
   }
   ENABLE_INTERRUPTS();
   return NULL;
}
Ejemplo n.º 24
0
/*
 *	Record a usimple_lock just acquired on
 *	the current processor.
 *
 *	MACH_RT:  Preemption has been disabled by lock
 *	acquisition, so it's safe to use the cpu number
 *	specified by the caller.
 */
void
usl_stack_push(
	usimple_lock_t	l,
	int		mycpu)
{
	spl_t		s;

	if (uslock_stack_enabled == FALSE)
		return;

	DISABLE_INTERRUPTS(s);
	assert(uslock_stack_index[mycpu] >= 0);
	assert(uslock_stack_index[mycpu] < USLOCK_STACK_DEPTH);
	if (uslock_stack_index[mycpu] >= USLOCK_STACK_DEPTH) {
		printf("usl_stack_push (cpu 0x%x):  too many locks (%d)",
		       mycpu, uslock_stack_index[mycpu]);
		printf(" disabling stacks\n");
		uslock_stack_enabled = FALSE;
		ENABLE_INTERRUPTS(s);
		return;
	}
	uslock_stack[mycpu][uslock_stack_index[mycpu]] = l;
	uslock_stack_index[mycpu]++;
	ENABLE_INTERRUPTS(s);
}
Ejemplo n.º 25
0
error_t openserial_printData(uint8_t* buffer, uint8_t length) {
    uint8_t counter;
    uint8_t asn[5];
    INTERRUPT_DECLARATION();
    DISABLE_INTERRUPTS();

    openserial_vars.somethingInOutputBuffer=TRUE;
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t)'^';                  //preamble
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t)'^';
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t)'^';
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t)'D';                  //this is data
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t)((idmanager_getMyID(ADDR_16B))->addr_16b[1]);
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t)((idmanager_getMyID(ADDR_16B))->addr_16b[0]);
    //asn to serial ..
    asnWriteToSerial(asn);// byte01,byte23,byte4
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=asn[0];
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=asn[1];
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=asn[2];
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=asn[3];
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=asn[4];

    for (counter=0; counter<length; counter++) {
        openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t)buffer[counter];
    }
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t)'$';                  //postamble
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t)'$';
    openserial_vars.output_buffer[output_buffer_index_write_increment()]=(uint8_t)'$';
    ENABLE_INTERRUPTS();

    return E_SUCCESS;
}
Ejemplo n.º 26
0
/*
 *	Eliminate the entry for a usimple_lock
 *	that had been active on the current processor.
 *
 *	MACH_RT:  Preemption has been disabled by lock
 *	acquisition, and we haven't yet actually
 *	released the hardware lock associated with
 *	this usimple_lock, so it's safe to use the
 *	cpu number supplied by the caller.
 */
void
usl_stack_pop(
	usimple_lock_t	l,
	int		mycpu)
{
	unsigned int	i, index;
	spl_t		s;

	if (uslock_stack_enabled == FALSE)
		return;

	DISABLE_INTERRUPTS(s);
	assert(uslock_stack_index[mycpu] > 0);
	assert(uslock_stack_index[mycpu] <= USLOCK_STACK_DEPTH);
	if (uslock_stack_index[mycpu] == 0) {
		printf("usl_stack_pop (cpu 0x%x):  not enough locks (%d)",
		       mycpu, uslock_stack_index[mycpu]);
		printf(" disabling stacks\n");
		uslock_stack_enabled = FALSE;
		ENABLE_INTERRUPTS(s);
		return;
	}
	index = --uslock_stack_index[mycpu];
	for (i = 0; i <= index; ++i) {
		if (uslock_stack[mycpu][i] == l) {
			if (i != index)
				uslock_stack[mycpu][i] =
					uslock_stack[mycpu][index];
			ENABLE_INTERRUPTS(s);
			return;
		}
	}
	ENABLE_INTERRUPTS(s);
	panic("usl_stack_pop:  can't find usimple_lock 0x%x", l);
}
Ejemplo n.º 27
0
 OpenQueueEntry_t* openqueue_macGetDataPacket(open_addr_t* toNeighbor) {
   uint8_t i;
   INTERRUPT_DECLARATION();
   DISABLE_INTERRUPTS();
   if (toNeighbor->type==ADDR_64B) {
      // a neighbor is specified, look for a packet unicast to that neigbhbor
      for (i=0;i<QUEUELENGTH;i++) {
         if (openqueue_vars.queue[i].owner==COMPONENT_RES_TO_IEEE802154E &&
            packetfunctions_sameAddress(toNeighbor,&openqueue_vars.queue[i].l2_nextORpreviousHop)) {
            ENABLE_INTERRUPTS();
            return &openqueue_vars.queue[i];
         }
      }
   } else if (toNeighbor->type==ADDR_ANYCAST) {
      // anycast case: look for a packet which is either not created by RES
      // or an KA (created by RES, but not broadcast)
      for (i=0;i<QUEUELENGTH;i++) {
         if (openqueue_vars.queue[i].owner==COMPONENT_RES_TO_IEEE802154E &&
             ( openqueue_vars.queue[i].creator!=COMPONENT_RES ||
                (
                   openqueue_vars.queue[i].creator==COMPONENT_RES &&
                   packetfunctions_isBroadcastMulticast(&(openqueue_vars.queue[i].l2_nextORpreviousHop))==FALSE
                )
             )
            ) {
            ENABLE_INTERRUPTS();
            return &openqueue_vars.queue[i];
         }
      }
   }
   ENABLE_INTERRUPTS();
   return NULL;
}
Ejemplo n.º 28
0
owerror_t openserial_printInfoErrorCritical(
      char             severity,
      uint8_t          calling_component,
      uint8_t          error_code,
      errorparameter_t arg1,
      errorparameter_t arg2
   ) {
   INTERRUPT_DECLARATION();
   
   DISABLE_INTERRUPTS();
   openserial_vars.outputBufFilled  = TRUE;
   outputHdlcOpen();
   outputHdlcWrite(severity);
   outputHdlcWrite(idmanager_getMyID(ADDR_16B)->addr_16b[0]);
   outputHdlcWrite(idmanager_getMyID(ADDR_16B)->addr_16b[1]);
   outputHdlcWrite(calling_component);
   outputHdlcWrite(error_code);
   outputHdlcWrite((uint8_t)((arg1 & 0xff00)>>8));
   outputHdlcWrite((uint8_t) (arg1 & 0x00ff));
   outputHdlcWrite((uint8_t)((arg2 & 0xff00)>>8));
   outputHdlcWrite((uint8_t) (arg2 & 0x00ff));
   outputHdlcClose();
   ENABLE_INTERRUPTS();
   
   return E_SUCCESS;
}
Ejemplo n.º 29
0
/**
\brief Check whether I can send on this slot.

This function is called at the beginning of every TX slot.
If the slot is *not* a shared slot, it always return TRUE.
If the slot is a shared slot, it decrements the backoff counter and returns 
TRUE only if it hits 0.

Note that the backoff counter is global, not per slot.

\returns TRUE if it is OK to send on this slot, FALSE otherwise.
 */
bool schedule_getOkToSend() {
   bool returnVal;
   
   INTERRUPT_DECLARATION();
   DISABLE_INTERRUPTS();
   
   if (schedule_vars.currentScheduleEntry->shared==FALSE) {
      // non-shared slot: backoff does not apply
      
      returnVal = TRUE;
   } else {
      // non-shared slot: check backoff before answering
      
      // decrement backoff
      if (schedule_vars.backoff>0) {
         schedule_vars.backoff--;
      }
      
      // only return TRUE if backoff hit 0
      if (schedule_vars.backoff==0) {
         returnVal = TRUE;
      } else {
         returnVal = FALSE;
      }
   }
   
   ENABLE_INTERRUPTS();
   return returnVal;
}
Ejemplo n.º 30
0
//Wakes the thread with the ID tid
void CALLING_CONVENTION CX86Scheduler::wakeThread(pid_t tid, size_t count)
{
	if (count == 0)
		return;
	bool islocked = false;

	DISABLE_INTERRUPTS();	//Turn off preemption
	m_lock.acquireSpinlock();
	iterator_t itr = m_blockedList.findValue((PTHREAD)tid);
	if (!m_blockedList.isEntry(itr))
	{
		m_lock.releaseSpinlock();
		ENABLE_INTERRUPTS();
		return;
	}
	//OK, we found the thread
	PTHREAD thread = (PTHREAD)tid;
	if (count > thread->waitcount)
		thread->waitcount = 0;
	else
		thread->waitcount -= count;
	if (thread->waitcount == 0)
	{
		m_blockedList.removeAt(itr);
		m_runningList.insertToHead(thread);
	}
	m_lock.releaseSpinlock();
	ENABLE_INTERRUPTS();
}