Пример #1
0
/*
 * read stoichiometric matrix file and searches exchange reactions
 * exchange reactions are defined as those reactions that have only positive
 * or only negative values
 */
void defineExchangeReactions(int *cols, char** exchange_reaction, double
        threshold, char* filename)
{
    double n_thres = -1 * threshold;
    FILE *rx_file = fopen(filename, "r");
    if (!rx_file)
    {
        quitError("Error in opening file\n", ERROR_FILE);
    }
    int rx_count = getRxCount(rx_file);
    fclose(rx_file);
    char* line = NULL;
    size_t len = 0;
    unsigned long bitarray_size = getBitsize(rx_count);
    char* m_exchange_reaction = calloc(1, bitarray_size);
    char* m_pos = calloc(1, bitarray_size);
    char* m_neg = calloc(1, bitarray_size);
    FILE *file = fopen(filename, "r");
    if (!file)
    {
        quitError("Error in opening file\n", ERROR_FILE);
    }
    while ( getline(&line, &len, file) != -1)
    {
        char *ptr;
        ptr = strtok(line, "\n\t ");
        int i = 0;
        while(ptr != NULL) 
        {
            double val = atof(ptr);
            // positive value
            if (val > threshold)
            {
                BITSET(m_pos, i);
            }
            // negative value
            else if (val < n_thres)
            {
                BITSET(m_neg,i);
            }
            i++;
            ptr = strtok(NULL, "\n\t ");
        }
    }
    free(line);
    line = NULL;
    fclose(file);
    int i;
    for (i = 0; i < rx_count; i++) {
        // check if reaction have positive and negative values
        if ( (BITTEST(m_pos,i) && !BITTEST(m_neg,i)) || (!BITTEST(m_pos,i) && BITTEST(m_neg,i)) )
        {
            BITSET(m_exchange_reaction, i);
        }
    }
    free(m_pos);
    free(m_neg);
    *cols = rx_count;
    *exchange_reaction = m_exchange_reaction;
}
Пример #2
0
/**************************************************************************
DOES:    Determines source of reset.
RETURNS: 0=power-up, 1=external, 2=brown-out, 3=watchdog, 4=J-Tag, 5=jump
**************************************************************************/
static UNSIGNED8 MAIN_Get_Start_Code(void)
{
  UNSIGNED8 return_val;

  if (BITSET(MCUSR,JTRF))
  { 
     return_val = 4;
  }
  else if (BITSET(MCUSR,WDRF))
  { 
     return_val = 3;
  }
  else if (BITSET(MCUSR,BORF))
  { 
    return_val = 2;
  }
  else if (BITSET(MCUSR,EXTRF))
  { 
     return_val = 1;
  }
  else if (BITSET(MCUSR,PORF))
  { 
     return_val = 0;
  }
  else
  { 
    return_val = 5;
  }

  // Reset MCU Status Register
  MCUSR = 0x00;

  return (return_val);
}
Пример #3
0
static void
tcc88xx_osmr0_set_mode(enum clock_event_mode mode, struct clock_event_device *c)
{
	unsigned long flags;

#if defined(TICKLESS_DEBUG_TCC)
	printk("%s: mode %s... %d\n", __func__,
	       mode == CLOCK_EVT_MODE_ONESHOT  ? "ONESHOT"   :
	       mode == CLOCK_EVT_MODE_UNUSED   ? "UNUSED"    :
	       mode == CLOCK_EVT_MODE_SHUTDOWN ? "SHUTDOWN"  :
	       mode == CLOCK_EVT_MODE_RESUME   ? "RESUME"    :
	       mode == CLOCK_EVT_MODE_PERIODIC ? "PERIODIC"  : "non",
	       gTimer_cnt++);
#endif

	switch (mode) {
	case CLOCK_EVT_MODE_ONESHOT:
	case CLOCK_EVT_MODE_UNUSED:
	case CLOCK_EVT_MODE_SHUTDOWN:
		raw_local_irq_save(flags);
		BITCLR(pTIMER->TC32IRQ, Hw16);			/* Disable interrupt when the counter value matched with CMP0 */
		BITSET(pPIC->CLR0, TCC_ENABLE_BIT(INT_TC32));	/* PIC Interrupt clear */
		if(pTIMER->TC32IRQ & Hw31)			/* IRQ clear */
			BITSET(pTIMER->TC32IRQ, Hw31);
		raw_local_irq_restore(flags);
		break;

	case CLOCK_EVT_MODE_RESUME:
	case CLOCK_EVT_MODE_PERIODIC:
		break;
	}
}
Пример #4
0
static int tcc_tsif_dmastart(struct tcc_tsif_handle *h)
{
	volatile PGDMACTRL dma_regs;

	if(h->dma_controller == 0)
		dma_regs = (volatile PGDMACTRL)tcc_p2v(HwGDMA0_BASE);
	else if(h->dma_controller == 1)
		dma_regs = (volatile PGDMACTRL)tcc_p2v(HwGDMA1_BASE);
	else if(h->dma_controller == 2)
		dma_regs = (volatile PGDMACTRL)tcc_p2v(HwGDMA2_BASE);
	
	h->dma_phy_rdpos 	= h->rx_dma.dma_addr;
	h->dma_phy_curpos 	= h->dma_phy_rdpos;
	h->dma_phy_maxaddr	= h->dma_phy_curpos + h->dma_total_size;
	h->dma_virt_rdpos 	= (unsigned int)h->rx_dma.v_addr;
	h->dma_virt_curpos 	= h->dma_virt_rdpos;
	h->dma_virt_maxaddr	= h->dma_virt_curpos + h->dma_total_size;
	h->dma_recv_size	= 0;
	h->dma_intr_cnt		= 0;

	tcc_tsif_dma_init(h);

	if(h->dma_ch == 0)	 		BITSET(dma_regs->CHCTRL0.nREG, 	Hw0);	//dma enable
	else if(h->dma_ch == 1)	BITSET(dma_regs->CHCTRL1.nREG, 	Hw0);	//dma enable
	else						BITSET(dma_regs->CHCTRL2.nREG, 	Hw0);	//dma enable
		
	BITSET(h->regs->TSRXCR, Hw31);								//tsif enable

#ifdef DEBUG_INFO
	printk("%s\n", __func__);
#endif

	return 0;
}
Пример #5
0
void apply_mark_flagstates(struct apply_handle *h) {
    int i;
    struct fsm_state *fsm;

    /* Create bitarray with those states that have a flag symbol on an arc */
    /* This is needed to decide whether we can perform a binary search.    */

    if (!h->has_flags || h->flag_lookup == NULL) {
	return;
    }
    if (h->flagstates) {
	xxfree(h->flagstates);
    }
    h->flagstates = xxcalloc(BITNSLOTS(h->last_net->statecount), sizeof(uint8_t));
    fsm = h->last_net->states;
    for (i=0; (fsm+i)->state_no != -1; i++) {
	if ((fsm+i)->target == -1) { 
	    continue;
	}
	if ((h->flag_lookup+(fsm+i)->in)->type) {
	    BITSET(h->flagstates,(fsm+i)->state_no);
	}
	if ((h->flag_lookup+(fsm+i)->out)->type) {
	    BITSET(h->flagstates,(fsm+i)->state_no);
	}
    }
}
Пример #6
0
static void tcc_tsif_isr(struct tcc_tsif_handle *h)
{
	volatile PGDMACTRL dma_regs;

	if(h->dma_controller == 0)
		dma_regs = (volatile PGDMACTRL)tcc_p2v(HwGDMA0_BASE);
	else if(h->dma_controller == 1)
		dma_regs = (volatile PGDMACTRL)tcc_p2v(HwGDMA1_BASE);
	else if(h->dma_controller == 2)
		dma_regs = (volatile PGDMACTRL)tcc_p2v(HwGDMA2_BASE);

	if(h->dma_ch == 0)
	{
		if(dma_regs->CHCTRL0.nREG & Hw3) {
			BITSET(dma_regs->CHCTRL0.nREG, Hw3);		//dma done flag set
			h->dma_phy_curpos = dma_regs->C_DADR0.nREG;
		}
	}
	else if(h->dma_ch == 1)
	{
		if(dma_regs->CHCTRL1.nREG & Hw3) {
			BITSET(dma_regs->CHCTRL1.nREG, Hw3);		//dma done flag set
			h->dma_phy_curpos = dma_regs->C_DADR1.nREG;
		}
	}
	else
	{
		if(dma_regs->CHCTRL2.nREG & Hw3) {
			BITSET(dma_regs->CHCTRL2.nREG, Hw3);		//dma done flag set
			h->dma_phy_curpos = dma_regs->C_DADR2.nREG;
		}
	}

	h->dma_intr_cnt++;
}
Пример #7
0
BOOL
CHyperLink:: ModifyLinkStyle( DWORD dwRemove, DWORD dwAdd,
                             BOOL bApply /* =TRUE */ )
{
   // Check if we are adding and removing the same style.
   if ( (dwRemove & dwAdd) != 0 )
      return( FALSE );

   // Remove old styles and set the new ones
   CLEARBITS( m_dwStyle, dwRemove );
   SETBITS( m_dwStyle, dwAdd );

   if ( bApply && mIs_hWnd( GetSafeHwnd( ) ) )
   {
      // If possible, APPLY the new styles on the fly.
      if ( BITSET( dwAdd, StyleUnderline ) ||
           BITSET( dwRemove, StyleUnderline ) )
      {
         SwitchUnderline( );
      }

      if ( BITSET( dwAdd, StyleAutoSize ) )
         AdjustWindow( );

      if ( BITSET( dwRemove, StyleUseHover ) )
         Invalidate( );
   }

   return( TRUE );
}
Пример #8
0
void BloomFilter::add(string item){
  int * keys = this->keys(item);
	BITSET(bitarray, ABS(keys[0]));
	BITSET(bitarray, ABS(keys[1]));
	BITSET(bitarray, ABS(keys[2]));
  delete [] keys;
};
Пример #9
0
/*****************************************************************************
* Function Name : tca_i2c_setgpio(int ch)
* Description: I2C port configuration
* input parameter:
* 		int core; 	// I2C Core
*       int ch;   	// I2C master channel
******************************************************************************/
void tca_i2c_setgpio(int core, int ch)
{
	PGPIO gpio = (PGPIO)tcc_p2v(HwGPIO_BASE);

	switch (core) {
		case 0:
		{
			if (ch == 0) {
				BITCSET(gpio->GPAFN0, (Hw8-Hw0), Hw4|Hw0);			/* GPIO_A[1:0] */
				BITSET(gpio->GPAEN, Hw1|Hw0);
				BITCLR(gpio->GPADAT, Hw1|Hw0);
			} else if (ch == 1) {
				BITCSET(gpio->GPAFN0, (Hw32-Hw28), Hw28);			/* GPIO_A[7] */
				BITCSET(gpio->GPAFN1, (Hw4-Hw0), Hw0);			    /* GPIO_A[8] */
				BITSET(gpio->GPAEN, Hw8|Hw7);
				BITCLR(gpio->GPADAT, Hw8|Hw7);
			}
			break;
		}
		case 1:
		{
			if (ch == 0) {
                /* Not used */
			} else if (ch == 1) {
                /* Not used */
			}
			break;
		}
	}
}
Пример #10
0
void CHyperLink::OnLButtonDown(UINT /*nFlags*/, CPoint /*point*/) 
{
	if (BITSET(m_dwStyle,StyleGetFocusOnClick))
		SetFocus();                // Set the focus and make the link active
	if (BITSET(m_dwStyle,StyleDownClick))
		FollowLink();
	m_bLinkActive = TRUE;
}
Пример #11
0
// Move and resize the window so that its client area has the same size
// as the hyperlink text. This prevents the hyperlink cursor being active
// when it is not over the text.
void
CHyperLink::AdjustWindow( )
{
   ASSERT( mIs_hWnd( GetSafeHwnd( ) ) );

   if ( !BITSET( m_dwStyle, StyleAutoSize ) )
        return;

    // Get the current window rect
    CRect rcWnd;
    GetWindowRect( rcWnd );

   // For a child CWnd object, window rect is relative to the
   // upper-left corner of the parent window’s client area.
    CWnd *pParent = GetParent( );
    if ( pParent )
        pParent->ScreenToClient( rcWnd );

   // Get the current client rect
   CRect rcClient;
   GetClientRect( rcClient );

   // Calc border size based on window and client rects.
   int borderWidth = rcWnd.Width( ) - rcClient.Width( );
   int borderHeight = rcWnd.Height( ) - rcClient.Height( );

   // Get the extent of window text
   CString csWndText;
   GetWindowText( csWndText );

   CDC *pDC = GetDC( );
   CFont *pOldFont = pDC->SelectObject( &m_Font );
   CSize Extent = pDC->GetTextExtent( csWndText );
   pDC->SelectObject( pOldFont );
   ReleaseDC( pDC );

   // Get the text justification style.
   DWORD dwStyle = GetStyle( );

   // Recalc window size and position based on text justification.
   if ( BITSET( dwStyle, SS_CENTERIMAGE ) )
      rcWnd.DeflateRect( 0, (rcWnd.Height( ) - Extent.cy) / 2 );
   else
      rcWnd.bottom = rcWnd.top + Extent.cy;

   if ( BITSET( dwStyle, SS_CENTER ) )
      rcWnd.DeflateRect( (rcWnd.Width( ) - Extent.cx) / 2, 0 );
   else
   if ( BITSET( dwStyle, SS_RIGHT ) )
      rcWnd.left  = rcWnd.right - Extent.cx;
   else // SS_LEFT
      rcWnd.right = rcWnd.left + Extent.cx;

   // Move and resize the window.
   MoveWindow( rcWnd.left, rcWnd.top, rcWnd.Width( ) + borderWidth,
               rcWnd.Height( ) + borderHeight );
}
Пример #12
0
static irqreturn_t tcc88xx_timer_interrupt(int irq, void *dev_id)
{
#ifndef CONFIG_GENERIC_CLOCKEVENTS
	timer_tick();
#endif

	BITSET(pPIC->CLR0, TCC_ENABLE_BIT(irq));
	if(pTIMER->TC32IRQ & Hw31)
		BITSET(pTIMER->TC32IRQ, Hw31);

	return IRQ_HANDLED;
}
Пример #13
0
static int eth16i_probe_port(int ioaddr)
{
	int i;
	int retcode;
	unsigned char dummy_packet[64];

	/* Powerup the chip */
	outb(0xc0 | POWERUP, ioaddr + CONFIG_REG_1);

	BITSET(ioaddr + CONFIG_REG_0, DLC_EN);

	eth16i_select_regbank(NODE_ID_RB, ioaddr);

	for(i = 0; i < 6; i++) {
		dummy_packet[i] = inb(ioaddr + NODE_ID_0 + i);
		dummy_packet[i+6] = inb(ioaddr + NODE_ID_0 + i);
	}

	dummy_packet[12] = 0x00;
	dummy_packet[13] = 0x04;
	memset(dummy_packet + 14, 0, sizeof(dummy_packet) - 14);

	eth16i_select_regbank(2, ioaddr);

	for(i = 0; i < 3; i++) {
		BITSET(ioaddr + CONFIG_REG_0, DLC_EN);
		BITCLR(ioaddr + CONFIG_REG_0, DLC_EN);
		eth16i_set_port(ioaddr, i);

		if(eth16i_debug > 1)
			printk(KERN_DEBUG "Set port number %d\n", i);

		retcode = eth16i_send_probe_packet(ioaddr, dummy_packet, 64);
		if(retcode == 0) {
			retcode = eth16i_receive_probe_packet(ioaddr);
			if(retcode != -1) {
				if(eth16i_debug > 1)
					printk(KERN_DEBUG "Eth16i interface port found at %d\n", i);
				return i;
			}
		}
		else {
			if(eth16i_debug > 1)
				printk(KERN_DEBUG "TRANSMIT_DONE timeout when probing interface port\n");
		}
	}

	if( eth16i_debug > 1)
		printk(KERN_DEBUG "Using default port\n");

	return E_PORT_BNC;
}
Пример #14
0
/*
 * stores an EFM into a bitset if it is not an internal loop
 * every reaction is mapped to two bits
 * first bit is if reaction has a positive flux
 * second bit is set if reaction has a negative flux
 * none is set if reaction has no flux
 */
int loadEfm (char* matrix, char* line, char* reversible_reactions, char*
        rxs_fwd, char* rxs_rev, int rx_count, char* exchange_reaction, int
        checkLoops, double threshold)
{
    double n_thres = -1 * threshold;
    char *ptr;
    ptr = strtok(line, "\n\t ");
    int i = 0;
    int j = 0;
    while(ptr != NULL) 
    {
        double x = atof(ptr);
        if (checkLoops > 0 && BITTEST(exchange_reaction, i))
        {
            // check if EFM is an internal loop
            if (x >= threshold || x <= n_thres)
            {
                checkLoops = 0;
            }
        }
        if (BITTEST(reversible_reactions,i))
        {
            // positive flux
            if (x >= threshold)
            {
                BITSET(matrix, 2*j);
                BITSET(rxs_fwd,j);
            }
            // negative flux
            else if (x <= n_thres)
            {
                BITSET(matrix, (2*j)+1);
                BITSET(rxs_rev, j);
            }
            j++;
        }
        i++;
        ptr = strtok(NULL, "\n\t ");
    }
    if (checkLoops > 0)
    {
        // EFM is a loop - free memory
        free(matrix);
        matrix=NULL;
        return(0);
    }
    else
    {
        return(1);
    }
}
Пример #15
0
/*
 * gcc-specific pragmas.
 */
int
pragmas_gcc(char *t)
{
	char u;
	int ign, warn, err, i;
	extern bittype warnary[], werrary[];
	extern char *flagstr[], *pragstore;

	if (strcmp((t = pragtok(NULL)), "diagnostic") == 0) {
		ign = warn = err = 0;
		if (strcmp((t = pragtok(NULL)), "ignored") == 0)
			ign = 1;
		else if (strcmp(t, "warning") == 0)
			warn = 1;
		else if (strcmp(t, "error") == 0)
			err = 1;
		else
			return 1;
		if (eat('\"') || eat('-'))
			return 1;
		for (t = pragstore; *t && *t != '\"'; t++)
			;
		u = *t;
		*t = 0;
		for (i = 0; i < NUMW; i++) {
			if (strcmp(flagstr[i], pragstore+1) != 0)
				continue;
			if (err) {
				BITSET(warnary, i);
				BITSET(werrary, i);
			} else if (warn) {
				BITSET(warnary, i);
				BITCLEAR(werrary, i);
			} else {
				BITCLEAR(warnary, i);
				BITCLEAR(werrary, i);
			}
			return 0;
		}
		*t = u;
	} else if (strcmp(t, "poison") == 0) {
		/* currently ignore */;
	} else if (strcmp(t, "visibility") == 0) {
		/* currently ignore */;
	} else if (strcmp(t, "system_header") == 0) {
		/* currently ignore */;
	} else
		werror("gcc pragma unsupported");
	return 0;
}
Пример #16
0
void
CHyperLink::PreSubclassWindow( )
{
   // If the URL string is empty try to set it to the window text.
   if ( m_csURL.IsEmpty( ) )
      GetWindowText( m_csURL );

   // Check that the window text isn't empty.  If so, set it as URL string.
   CString csWndText;
   GetWindowText( csWndText );
   if ( csWndText.IsEmpty( ) )
   {
      // Set the URL string as the window text
      ASSERT( m_csURL.IsEmpty( ) == FALSE ); // window text and URL both empty!
      CStatic::SetWindowText( m_csURL );
   }

   // Get the current window font
   CFont *pFont = GetFont( );

   if ( pFont )
   {
      LOGFONT lf;
      pFont->GetLogFont( &lf );
      lf.lfUnderline = BITSET( m_dwStyle, StyleUnderline );
      if ( m_Font.CreateFontIndirect( &lf ) )
         CStatic::SetFont( &m_Font );

      // Adjust window size to fit URL if necessary.
      AdjustWindow( );
   }
   else
   {
      // If GetFont returns 0 then the static control is probably not of a
      // text type: it's better to set auto-resizing off.
      CLEARBITS( m_dwStyle, StyleAutoSize );
   }

   if ( !BITSET( m_dwStyle, StyleNoHandCursor ) )
      SetDefaultCursor( );      // try to load a "hand" cursor

    // Create the tooltip.
    CRect rect;
    GetClientRect( rect );
    m_ToolTip.Create( this );
    m_ToolTip.AddTool( this, m_csURL, rect, TOOLTIP_ID );

    CStatic::PreSubclassWindow( );
}
Пример #17
0
static BOOL SerialConsole_PutChar(SIOPCB * cb, INT chr, BOOL rasint)
{
	char	buffer[2];
	int		textlength;
	HANDLE	console;

	assert(cb != NULL);
	assert(BITTEST(cb->Flag, SIO_TYP_CONSOLE));
	assert(cb->Handle != NULL);

	console = GetDlgItem(cb->Handle, IDC_CONSOLE);
	buffer[0] = (char) chr;
	buffer[1] = '\x0';

	textlength = GetWindowTextLength(console);
	if(textlength > BUFSZ_UPPERBOUND)
	{
			/* 古い情報を消す */
		SendMessage(console,EM_SETSEL,0,textlength - BUFSZ_LOWERBOUND);
		SendMessage(console,EM_REPLACESEL,(WPARAM)FALSE,(LPARAM)"");
		textlength = GetWindowTextLength(console);
	}
		/* 末尾に文字を置く */
	SendMessage(console,EM_SETSEL,textlength,textlength);
	SendMessage(console,EM_REPLACESEL,(WPARAM)FALSE,(LPARAM)buffer);

	if(rasint == TRUE)
	{
		BITSET(cb->Flag, SIO_STA_INTSND);
		HALInterruptRequest(INHNO_SERIAL);
	}

	return TRUE;
}
Пример #18
0
/** Change stepper ic controller direction. 1 is CW, 0 is CCW seen from top
*/
void stepper_set_direction( int8_t dir )
{
	if(dir >= 1)
		BITSET(PORTL,PL3);	//Rotation direcion CW
	else
		BITCLR(PORTL,PL3);	//Rotation direcion to CCW
}
Пример #19
0
static void eth16i_set_port(int ioaddr, int porttype)
{ 
	unsigned short temp = 0;

	eth16i_select_regbank(TRANSCEIVER_MODE_RB, ioaddr);
	outb(LOOPBACK_CONTROL, ioaddr + TRANSMIT_MODE_REG);

	temp |= DIS_AUTO_PORT_SEL;

	switch(porttype) {

	case E_PORT_BNC :
		temp |= AUI_SELECT;
		break;

	case E_PORT_TP :
		break;

	case E_PORT_DIX :
		temp |= AUI_SELECT;
		BITSET(ioaddr + TRANSMIT_MODE_REG, CONTROL_OUTPUT);
		break;
	}  

	outb(temp, ioaddr + TRANSCEIVER_MODE_REG);

	if(eth16i_debug > 1) {
		printk(KERN_DEBUG "TRANSMIT_MODE_REG = %x\n", inb(ioaddr + TRANSMIT_MODE_REG));
		printk(KERN_DEBUG "TRANSCEIVER_MODE_REG = %x\n", 
		       inb(ioaddr+TRANSCEIVER_MODE_REG));
	}
}
Пример #20
0
struct node* Node_addchild(struct node* parent, unsigned char label, unsigned short idx) {

    assert(parent);

    struct node* nc;

    if ((nc = Node_getchild(parent, label)))		//child already present
        return nc;

    nc = Node_new(label, idx);

    assert(nc);

    int numChildren = Node_childno(parent);
    int x = Bit_count_set_bits_up_to(parent -> bitarray, sizeof(parent -> bitarray), label);

    int i;

    parent -> child = realloc(parent -> child, (numChildren + 1) * sizeof(struct node*));		//make space for new child ponter
    assert(parent -> child);

    memset(parent -> child + numChildren, 0, sizeof(struct node*)); //initialize just-added space to 0

    for (i = numChildren; i > x; i--)
        parent -> child[i] = parent -> child[i - 1];	//shift child pointer to the right to make room for new child

    parent -> child[x] = nc;

    BITSET(parent -> bitarray, label);

    return nc;
}
Пример #21
0
void tchal_power_on_device(void)
{
#ifdef __USE_TC_CPU__
	tcbd_debug(DEBUG_TCHAL, "\n");
	BITCLR(RGPIO->GPEFN0, Hw16 - Hw12);/* DXB1_PD Set GPIO mode*/

	BITSET(RGPIO->GPEEN,  Hw3);/* DXB1_PD Set GPIO Output mode*/
	BITCLR(RGPIO->GPEDAT, Hw3);/* DXB1_PD Clear*/
	tcpal_msleep(10);
	BITSET(RGPIO->GPEDAT, Hw3);/* DXB1_PD Set*/
	tcpal_msleep(10);

	tchal_reset_device();
	tchal_irq_setup();
#endif
}
Пример #22
0
FUNCTION Msgh *sysbuf ()
{
	register Msgh  *m;
	register int   count = 0;

  Debug

	/* first try to allocate space */
	m = (Msgh *) l_create (msgdefsize);

	if (m == NULLMSGH)
	{  /* no space--get desperate */
		while (BITTST (emergbuf->flags, LOCKED))
		{
			if (count++ == 10000)
			{                   /* Wait for the MI to free the buffer..  */
				_pprintf ("Waiting for emergbuf to be unlocked... %x\n",
						emergbuf);
				send_e_from_q();        /* clear emergbuf */
				count = 0;
			}
		}
		m = emergbuf;   /* grab emergbuf */
	}

	clear ( m, sizeof (Msgh) ); /* clear it */

	if ( m == emergbuf )
		BITSET (m->flags, LOCKED); /* Tell rest of system not to use */

	return m;
}
Пример #23
0
FUNCTION Msgh *output_buf ()
{
	register Msgh  *m;
	register int    count = 0;

  Debug

	/* first try to allocate space */
	m = (Msgh *) l_create (msgdefsize);

	if (m == NULLMSGH)
	{  /* no space--get desperate */
		while (BITTST (report_buf->flags, LOCKED))
		{
			if (count++ == 10000)
			{                   /* Wait for the MI to free the buffer..  */
				dprintf ("Waiting for report buffer to be unlocked...\n");
				count = 0;
			}
		}
		m = report_buf; /* grab report_buf */
	}

	clear ( m, sizeof (Msgh) ); /* clear it */

	if ( m == report_buf )
		BITSET (m->flags, LOCKED); /* Tell rest of system not to use */

	return m;
}
Пример #24
0
static irqreturn_t tcc88xx_ost0_interrupt(int irq, void *dev_id)
{
	struct clock_event_device *c = dev_id;

	BITCLR(pTIMER->TC32IRQ, Hw16);			/* Disable interrupt when the counter value matched with CMP0 */
	BITSET(pPIC->CLR0, TCC_ENABLE_BIT(irq));	/* Interrupt clear */
	if(pTIMER->TC32IRQ & Hw31)			/* IRQ clear */
		BITSET(pTIMER->TC32IRQ, Hw31);
	c->event_handler(c);

#if defined(TICKLESS_DEBUG_TCC)
	gInt_cnt++;
#endif

	return IRQ_HANDLED;
}
Пример #25
0
tri_val_t finish_do_drink(obj_t *otmp, Boolean nothing, Boolean unkn)
{
  Boolean go_on = false;
  if (!otmp) return NO_OP; // bug if that happens
  if (nothing) {
    unkn = true;
    message("You have a peculiar feeling for a moment, then it passes.");
  }
  if ((otmp->bitflags & O_IS_DESCKNOWN) &&
      !BITTEST(oc_name_known, otmp->otype)) {
    if (!unkn) {
      BITSET(oc_name_known, otmp->otype);//objects[otmp->otyp].oc_name_known=1;
      more_experienced(0,10);
    } else if (!oc_has_uname(otmp->otype)) {
      // here's what I'll do instead of do_call/docall(otmp) :
      show_all_messages();
      clone_for_call(otmp); // so we don't have to worry about useup!
      FrmPopupForm(EngraveForm);
      go_on = true;
    }
  }
  useup(otmp);
  if (go_on) return GO_ON;
  else       return DONE;
}
Пример #26
0
void *sieve(void *k)
{
    int ret = 0;
    int tid = (int)k;

    for (long i = 2; i < ceil(sqrt(MAX)); ++i) {
        // Mark all multiples of the number
        if (!BITTEST(bitarray, i)) {
            // Make sure the number we are using is not divisible by
            // any other number currently being processed.
            for (int v = 0; v < NUM_THREADS; ++v) {
                if((i % working[v]) == 0) continue;
            }

            working[tid] = i;

            for(long j = i + i; 0 < j && j < MAX; j += i) {
                ret = pthread_mutex_lock(&mutexes[BITSLOT(j)]);
                if (ret != 0) errExit("pthread_mutex_lock");

                BITSET(bitarray, j);

                ret = pthread_mutex_unlock(&mutexes[BITSLOT(j)]);
                if (ret != 0) errExit("pthread_mutex_lock");
            }
        }
    }

    return NULL;
}
Пример #27
0
//컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴
//Procedure		KeyFake3d
//Author		Jim Taylor
//Date			Fri 3 Nov 1995
//
//Description	Fakes a key press to the 3d
//
//Inputs		Alias to fake
//				set or clear bits
//
//Returns		TRUE	if just pressed
//
//------------------------------------------------------------------------------
void	keytests::KeyFake3d(	KeyVal3D keyval,	//combo to fake
								Bool	held,		//set/clear held flag
								Bool	hit)		//set/clear oneshot flag
{
KeyMap3d*
		keymap=(KeyMap3d*) reftable3d.flat;
		if (held)
			BITSET((keymap->bitflags),keyval);
		else
			BITRESET((keymap->bitflags),keyval);
		if (hit)
			BITSET((keymap->bitflags),keyval+1);
		else
			BITRESET((keymap->bitflags),keyval+1);

}
Пример #28
0
/*
 *  シリアルI/Oポートのオープン
 */
SIOPCB * sio_opn_por(ID siopid, VP_INT exinf)
{
	BOOL     success;
	SIOPCB * siopcb = GET_SIOPCB(siopid);

	assert(siopcb != NULL);

	siopcb->exinf = exinf;

	success = TRUE;
	switch(SIO_TYP(siopcb->Flag))
	{
	case SIO_TYP_CONSOLE:
		HALExecuteProcedure(CreateSerialConsole,siopcb);
		break;
	case SIO_TYP_TTY:
		WinConsole_CreatePort(siopcb);
		break;
	case SIO_TYP_SCRBUF:
		HALExecuteProcedure(ScreenBuffer_CreatePort,siopcb);
		break;
	case SIO_TYP_RAWSIO:
		HALExecuteProcedure(RawSerial_CreatePort,siopcb);
		break;
	default:
		success = FALSE;
	}

	if(success == TRUE)
		BITSET(siopcb->Flag, SIO_STA_OPEN);

	return siopcb;
}
Пример #29
0
static DWORD WINAPI ScreenBuffer_ReceiverThread(LPVOID param)
{
	SIOPCB *		cb = (SIOPCB *)param;
	DWORD			work;
	INPUT_RECORD	input_record;

	assert(cb != NULL);
	assert(cb->Handle != NULL && cb->Handle != 0);

	while((work = WaitForSingleObject(cb->Handle, INFINITE)) != WAIT_FAILED)
	{
		assert(work == WAIT_OBJECT_0);	/* オブジェクトはシグナル状態になった */

		ReadConsoleInput(cb->Handle, &input_record, 1, &work);

		if(input_record.EventType == KEY_EVENT && input_record.Event.KeyEvent.bKeyDown == TRUE)
		{
			cb->ReceiveBuffer = (char)input_record.Event.KeyEvent.uChar.AsciiChar;

			BITSET(cb->Flag, SIO_STA_INTRCV);
			HALInterruptRequest(INHNO_SERIAL);
		}
	}

	return 0;
}
Пример #30
0
static DWORD WINAPI WinConsole_ReceiverThread(LPVOID param)
{
	SIOPCB *		cb = (SIOPCB *)param;
	DWORD			work;
	HANDLE			stdin;
	INPUT_RECORD	input_record;

	assert(cb != NULL);
	assert(cb->Handle != NULL && cb->Handle != 0);

	stdin = GetStdHandle(STD_INPUT_HANDLE);
	FatalAssertion(stdin != 0, "WinConsole_ReceiverThread failed to acquire the handle of standard input.");

	while((work = WaitForSingleObject(cb->Handle, INFINITE)) != WAIT_FAILED)
	{
		assert(work == WAIT_OBJECT_0);	/* オブジェクトはシグナル状態になった */

		ReadConsoleInput(stdin, &input_record, 1, &work);

		if(input_record.EventType == KEY_EVENT && input_record.Event.KeyEvent.bKeyDown == TRUE)
		{
			cb->ReceiveBuffer = (char)input_record.Event.KeyEvent.uChar.AsciiChar;

			BITSET(cb->Flag, SIO_STA_INTRCV);
			HALInterruptRequest(INHNO_SERIAL);
		}
	}

	return 0;
}