Example #1
0
/**
 * \brief Waits for a start condition on the bus
 *
 * \note This function is only available for 7-bit slave addressing.
 *
 * Waits for the master to issue a start condition on the bus.
 * Note that this function does not check for errors in the last transfer,
 * this will be discovered when reading or writing.
 *
 * \param[in]  module  Pointer to software module structure
 *
 * \return Direction of the current transfer, when in slave mode.
 * \retval I2C_SLAVE_DIRECTION_NONE   No request from master within timeout
 *                                    period
 * \retval I2C_SLAVE_DIRECTION_READ   Write request from master
 * \retval I2C_SLAVE_DIRECTION_WRITE  Read request from master
 */
enum i2c_slave_direction i2c_slave_get_direction_wait(
		struct i2c_slave_module *const module)
{
	/* Sanity check arguments. */
	Assert(module);
	Assert(module->hw);

	SercomI2cs *const i2c_hw = &(module->hw->I2CS);

	enum status_code status;

	/* Wait for address interrupt */
	status = _i2c_slave_wait_for_bus(module);

	if (status != STATUS_OK) {
		/* Timeout, return */
		return I2C_SLAVE_DIRECTION_NONE;
	}

	if (!(i2c_hw->INTFLAG.reg & SERCOM_I2CS_INTFLAG_AMATCH)) {
		/* Not address interrupt, something is wrong */
		return I2C_SLAVE_DIRECTION_NONE;
	}

	/* Check direction */
	if ((i2c_hw->STATUS.reg & SERCOM_I2CS_STATUS_DIR)) {
		/* Read request from master */
		return I2C_SLAVE_DIRECTION_WRITE;
	} else {
		/* Write request from master */
		return I2C_SLAVE_DIRECTION_READ;
	}
}
Example #2
0
//	Must have the same interface as PFn_GridCellGetText()
CString
GridCellGetText(PVDATAROW pvDataRow, const CGridColumn * pColumn, EGridCellText)
	{
	Assert(pvDataRow != NULL);
	Assert(pColumn != NULL);
	return c_sEmpty;
	}
Example #3
0
	virtual void ParseKeyValue( void *pData, const char *pKey, const char *pValue )
	{
		if ( !strcmpi( pKey, "selfcollisions" ) )
		{
			// keys disabled by default
			Assert( atoi(pValue) == 0 );
			m_bSelfCollisions = false;
		}
		else if ( !strcmpi( pKey, "collisionpair" ) )
		{
			if ( m_bSelfCollisions )
			{
				char szToken[256];
				const char *pStr = nexttoken(szToken, pValue, ',');
				int index0 = atoi(szToken);
				nexttoken( szToken, pStr, ',' );
				int index1 = atoi(szToken);

				m_pSet->EnableCollisions( index0, index1 );
			}
			else
			{
				Assert(0);
			}
		}
	}
// Updates the currently selected list entry
void AltShipClassDlg::alt_class_update_entry(alt_class &list_item)
{
	int index; 
	
	// Add a string variable to the list
	if (num_string_variables && m_set_from_variables.GetCurSel() > 0) {
		index = string_variable_indices[m_set_from_variables.GetCurSel() -1]; 

		Assert (index >= 0); 
		list_item.variable_index = index; 
		list_item.ship_class = ship_info_lookup(Sexp_variables[index].text); 
	}
	// Add a ship class to the list
	else {
		index = m_set_from_ship_class.GetCurSel(); 

		// Correct the index if the first entry isn't actually a ship class
		if (num_string_variables) {
			Assert (index > 0);
			index--;
		}
		
		list_item.variable_index = -1;
		list_item.ship_class = ship_class_indices[index];		
	}
	
	// check the default tickbox
	list_item.default_to_this_class = m_default_to_class.GetCheck() ? true:false;
}
Example #5
0
/**
 * \internal
 * Address response. Called when address is answered or timed out.
 *
 * \param[in,out] module  Pointer to software module structure
 *
 * \return Status of address response.
 * \retval STATUS_OK                    No error has occurred
 * \retval STATUS_ERR_DENIED            If error on bus
 * \retval STATUS_ERR_PACKET_COLLISION  If arbitration is lost
 * \retval STATUS_ERR_BAD_ADDRESS       If slave is busy, or no slave
 *                                      acknowledged the address
 */
static enum status_code _i2c_master_address_response(
		struct i2c_master_module *const module)
{
	/* Sanity check arguments */
	Assert(module);
	Assert(module->hw);

	SercomI2cm *const i2c_module = &(module->hw->I2CM);

	/* Check for error and ignore bus-error; workaround for BUSSTATE stuck in
	 * BUSY */
	if (i2c_module->INTFLAG.reg & SERCOM_I2CM_INTFLAG_SB) {

		/* Clear write interrupt flag */
		i2c_module->INTFLAG.reg = SERCOM_I2CM_INTFLAG_SB;

		/* Check arbitration. */
		if (i2c_module->STATUS.reg & SERCOM_I2CM_STATUS_ARBLOST) {
			/* Return packet collision. */
			return STATUS_ERR_PACKET_COLLISION;
		}
	/* Check that slave responded with ack. */
	} else if (i2c_module->STATUS.reg & SERCOM_I2CM_STATUS_RXNACK) {
		/* Slave busy. Issue ack and stop command. */
		i2c_module->CTRLB.reg |= SERCOM_I2CM_CTRLB_CMD(3);

		/* Return bad address value. */
		return STATUS_ERR_BAD_ADDRESS;
	}

	return STATUS_OK;
}
//
// Returns the next thunk. Batch allocated PageCount pages of thunks and issue them one at a time
//
BYTE* InterpreterThunkEmitter::GetNextThunk(PVOID* ppDynamicInterpreterThunk)
{
    Assert(ppDynamicInterpreterThunk);
    Assert(*ppDynamicInterpreterThunk == nullptr);

    if(thunkCount == 0)
    {
        if(!this->freeListedThunkBlocks.Empty())
        {
            return AllocateFromFreeList(ppDynamicInterpreterThunk);
        }
        NewThunkBlock();
    }

    Assert(this->thunkBuffer != nullptr);
    BYTE* thunk = this->thunkBuffer;
#if _M_ARM
    thunk = (BYTE*)((DWORD)thunk | 0x01);
#endif
    *ppDynamicInterpreterThunk = thunk + HeaderSize + ((--thunkCount) * ThunkSize);
#if _M_ARM
    AssertMsg(((uintptr_t)(*ppDynamicInterpreterThunk) & 0x6) == 0, "Not 8 byte aligned?");
#else
    AssertMsg(((uintptr_t)(*ppDynamicInterpreterThunk) & 0x7) == 0, "Not 8 byte aligned?");
#endif
    return thunk;
}
Example #7
0
void LZ4Segment<T>::_decompress_block_to_bytes(const size_t block_index, std::vector<char>& decompressed_data,
                                               const size_t write_offset) const {
  const auto decompressed_block_size = block_index + 1 != _lz4_blocks.size() ? _block_size : _last_block_size;
  auto& compressed_block = _lz4_blocks[block_index];
  const auto compressed_block_size = compressed_block.size();

  int decompressed_result;
  if (_dictionary.empty()) {
    /**
     * If the dictionary is empty, we either have only a single block or had not enough data for a dictionary.
     * When decoding without a dictionary LZ4 needs a stream decode pointer (which would be used to decode the
     * following blocks).
     * A new decoder needs to be created for every block (in the case of multiple blocks being compressed without a
     * dictionary) since the blocks were compressed independently.
     * This decoder needs to be reset via LZ4_setStreamDecode since LZ4 reuses the previous state instead.
     */
    LZ4_streamDecode_t lz4_stream_decoder;
    auto lz4_stream_decoder_ptr = std::make_unique<LZ4_streamDecode_t>(lz4_stream_decoder);
    const auto reset_decoder_status = LZ4_setStreamDecode(lz4_stream_decoder_ptr.get(), nullptr, 0);
    Assert(reset_decoder_status == 1, "LZ4 decompression failed to reset stream decoder.");

    decompressed_result = LZ4_decompress_safe_continue(
        lz4_stream_decoder_ptr.get(), compressed_block.data(), decompressed_data.data() + write_offset,
        static_cast<int>(compressed_block_size), static_cast<int>(decompressed_block_size));
  } else {
    decompressed_result = LZ4_decompress_safe_usingDict(
        compressed_block.data(), decompressed_data.data() + write_offset, static_cast<int>(compressed_block_size),
        static_cast<int>(decompressed_block_size), _dictionary.data(), static_cast<int>(_dictionary.size()));
  }

  Assert(decompressed_result > 0, "LZ4 stream decompression failed");
  DebugAssert(static_cast<size_t>(decompressed_result) == decompressed_block_size,
              "Decompressed LZ4 block has different size than the initial source data.");
}
Example #8
0
static void vrdpReportCachedBitmap (PVBOXDISPDEV pDev,
                                    SURFOBJ *psoSrc,
                                    const VRDPBCHASH *phash)
{
    BOOL bRc;

    VRDEORDERCACHEDBITMAP order;

    Assert(sizeof (*phash) == sizeof (order.hash));
    memcpy (order.hash, phash, sizeof (*phash));

    bRc = vrdpReportOrder (pDev, &order, sizeof (order), VRDE_ORDER_CACHED_BITMAP);

    if (bRc)
    {
        int bytesPerPixel = format2BytesPerPixel(psoSrc);

        uint8_t *pu8Bits = (uint8_t *)psoSrc->pvScan0;
        int32_t lDelta   = psoSrc->lDelta;
        uint32_t cWidth  = psoSrc->sizlBitmap.cx;
        uint32_t cHeight = psoSrc->sizlBitmap.cy;

        Assert(cWidth != 0 && cHeight != 0 && bytesPerPixel != 0);

        vrdpWriteBits (pDev, pu8Bits, lDelta, 0, 0, cWidth, cHeight, bytesPerPixel);
    }
}
Example #9
0
/*
 * Add a resource to ResourceArray
 *
 * Caller must have previously done ResourceArrayEnlarge()
 */
static void
ResourceArrayAdd(ResourceArray *resarr, Datum value)
{
	uint32		idx;

	Assert(value != resarr->invalidval);
	Assert(resarr->nitems < resarr->maxitems);

	if (RESARRAY_IS_ARRAY(resarr))
	{
		/* Append to linear array. */
		idx = resarr->nitems;
	}
	else
	{
		/* Insert into first free slot at or after hash location. */
		uint32		mask = resarr->capacity - 1;

		idx = DatumGetUInt32(hash_any((void *) &value, sizeof(value))) & mask;
		for (;;)
		{
			if (resarr->itemsarr[idx] == resarr->invalidval)
				break;
			idx = (idx + 1) & mask;
		}
	}
	resarr->lastidx = idx;
	resarr->itemsarr[idx] = value;
	resarr->nitems++;
}
Example #10
0
static BOOL vrdpIntersectRectWithBounds (RECTL *prclIntersect,
                                         const RECTL *prcl,
                                         const VRDEORDERBOUNDS *pBounds)
{
    if (   prcl->left   < pBounds->pt2.x     /* left < bounds_right */
        && prcl->right  > pBounds->pt1.x     /* right < bounds_left */
        && prcl->top    < pBounds->pt2.y     /* top < bounds_bottom */
        && prcl->bottom > pBounds->pt1.y     /* bottom < bounds_top */
        )
    {
        /* There is intersection. */
        prclIntersect->left   = max(prcl->left, pBounds->pt1.x);
        prclIntersect->right  = min(prcl->right, pBounds->pt2.x);
        prclIntersect->top    = max(prcl->top, pBounds->pt1.y);
        prclIntersect->bottom = min(prcl->bottom, pBounds->pt2.y);

        Assert(prclIntersect->left < prclIntersect->right);
        Assert(prclIntersect->top < prclIntersect->bottom);

        return TRUE;
    }

    /* No intersection. */
    return FALSE;
}
Example #11
0
static void vrdpReportMemBlt (PVBOXDISPDEV pDev,
                              VRDPCLIPRECTS *pClipRects,
                              POINTL *pptlSrc,
                              const uint8_t rop3,
                              const VRDPBCHASH *phash)
{
    if (pClipRects->rects.c == 0)
    {
        int xShift = pClipRects->rclDst.left - pClipRects->rclDstOrig.left;
        int yShift = pClipRects->rclDst.top - pClipRects->rclDstOrig.top;

        Assert(xShift >= 0 && yShift >= 0);

        vrdpReportMemBltRect (pDev, &pClipRects->rclDst, pptlSrc->x + xShift, pptlSrc->y + yShift, rop3, phash);
    }
    else
    {
        ULONG i;
        for (i = 0; i < pClipRects->rects.c; i++)
        {
            int xShift = pClipRects->rects.arcl[i].left - pClipRects->rclDstOrig.left;
            int yShift = pClipRects->rects.arcl[i].top - pClipRects->rclDstOrig.top;

            Assert(xShift >= 0 && yShift >= 0);

            vrdpReportMemBltRect (pDev, &pClipRects->rects.arcl[i], pptlSrc->x + xShift, pptlSrc->y + yShift, rop3, phash);
        }
    }
}
Example #12
0
static int console_pack(struct userrec *u, struct user_entry *e)
{
  char work[1024];
  struct console_info *ci;
  int l;

  Assert(e);
  Assert(e->u.extra);
  Assert(!e->name);

  ci = (struct console_info *) e->u.extra;

  l = simple_sprintf(work, "%s %s %s %d %d %d",
		     ci->channel, masktype(ci->conflags),
		     stripmasktype(ci->stripflags), ci->echoflags,
		     ci->page, ci->conchan);

  e->u.list = user_malloc(sizeof(struct list_type));
  e->u.list->next = NULL;
  e->u.list->extra = user_malloc(l + 1);
  strcpy(e->u.list->extra, work);

  nfree(ci->channel);
  nfree(ci);
  return 1;
}
Example #13
0
static int console_unpack(struct userrec *u, struct user_entry *e)
{
  struct console_info *ci = user_malloc(sizeof(struct console_info));
  char *par, *arg;

  Context;
  Assert(e);
  Assert(e->name);
  par = e->u.list->extra;
  arg = newsplit(&par);
  ci->channel = user_malloc(strlen(arg) + 1);
  strcpy(ci->channel, arg);
  arg = newsplit(&par);
  ci->conflags = logmodes(arg);
  arg = newsplit(&par);
  ci->stripflags = stripmodes(arg);
  arg = newsplit(&par);
  ci->echoflags = (arg[0] == '1') ? 1 : 0;
  arg = newsplit(&par);
  ci->page = atoi(arg);
  arg = newsplit(&par);
  ci->conchan = atoi(arg);
  list_type_kill(e->u.list);
  e->u.extra = ci;
  return 1;
}
Example #14
0
/**
 * \brief Clears a module status flag
 *
 * Clears the given status flag of the module.
 *
 * \note Not all status flags can be cleared.
 *
 * \param[in] module         Pointer to the I2C software device struct
 * \param[in] status_flags   Bit mask of status flags to clear
 *
 */
void i2c_slave_clear_status(
		struct i2c_slave_module *const module,
		uint32_t status_flags)
{
	/* Sanity check arguments */
	Assert(module);
	Assert(module->hw);

	SercomI2cs *const i2c_hw = &(module->hw->I2CS);

	/* Clear Address Match flag */
	if (status_flags & I2C_SLAVE_STATUS_ADDRESS_MATCH) {
		i2c_hw->INTFLAG.reg = SERCOM_I2CS_INTFLAG_AMATCH;
	}
	/* Clear Data Ready flag */
	if (status_flags & I2C_SLAVE_STATUS_DATA_READY) {
		i2c_hw->INTFLAG.reg = SERCOM_I2CS_INTFLAG_DRDY;
	}
	/* Clear Stop flag */
	if (status_flags & I2C_SLAVE_STATUS_STOP_RECEIVED) {
		i2c_hw->INTFLAG.reg = SERCOM_I2CS_INTFLAG_PREC;
	}
	/* Clear SCL Low Timeout */
	if (status_flags & I2C_SLAVE_STATUS_SCL_LOW_TIMEOUT) {
		i2c_hw->STATUS.reg = SERCOM_I2CS_STATUS_LOWTOUT;
	}
	/* Clear Transmit Collision */
	if (status_flags & I2C_SLAVE_STATUS_COLLISION) {
		i2c_hw->STATUS.reg = SERCOM_I2CS_STATUS_COLL;
	}
	/* Clear Bus Error */
	if (status_flags & I2C_SLAVE_STATUS_BUS_ERROR) {
		i2c_hw->STATUS.reg = SERCOM_I2CS_STATUS_BUSERR;
	}
}
Example #15
0
File: ac.c Project: Gussy/sam0
/** \brief Determines the state of a specified Window Comparator.
 *
 *  Retrieves the current window detection state, indicating what the input
 *  signal is currently comparing to relative to the window boundaries.
 *
 *  \param[in] module_inst  Software instance for the Analog Comparator peripheral
 *  \param[in] win_channel  Comparator Window channel to test
 *
 *  \return Bit mask of Analog Comparator window channel status flags.
 */
uint8_t ac_win_get_status(
    struct ac_module *const module_inst,
    const enum ac_win_channel win_channel)
{
    /* Sanity check arguments */
    Assert(module_inst);
    Assert(module_inst->hw);

    Ac *const ac_module = module_inst->hw;

    uint32_t win_status = 0;

    /* Check if interrupt flag is set */
    if (ac_module->INTFLAG.reg & (AC_INTFLAG_WIN0 << win_channel)) {
        win_status |= AC_WIN_STATUS_INTERRUPT_SET;
    }

    /* If one or both window comparators not ready, return unknown result */
    if (ac_win_is_ready(module_inst, win_channel) == false) {
        win_status |= AC_WIN_STATUS_UNKNOWN;
        return win_status;
    }

    uint8_t statusa_tmp = ac_module->STATUSA.reg;

    /* Map hardware comparison states to logical window states */
    if (statusa_tmp & (AC_STATUSA_WSTATE0_BELOW << win_channel)) {
        return win_status | AC_WIN_STATUS_BELOW;
    } else if (statusa_tmp & (AC_STATUSA_WSTATE0_INSIDE << win_channel)) {
        return win_status | AC_WIN_STATUS_INSIDE;
    } else {
        return win_status | AC_WIN_STATUS_ABOVE;
    }

}
Example #16
0
// -----------------------------------------------------------------------------
//	Return light intensity at an instance of a vertex on a side in a segment.
fix get_light_intensity(segment *segp, int sidenum, int vert)
{
    Assert(sidenum <= MAX_SIDES_PER_SEGMENT);
    Assert(vert <= 3);

    return segp->sides[sidenum].uvls[vert].l;
}
Example #17
0
File: ac.c Project: Gussy/sam0
static enum status_code _ac_set_config(
    struct ac_module *const module_inst,
    struct ac_config *const config)
{
    /* Sanity check arguments */
    Assert(module_inst);
    Assert(module_inst->hw);
    Assert(config);

    UNUSED(module_inst);

    /* Set up GCLK */
    struct system_gclk_chan_config gclk_chan_conf;
    system_gclk_chan_get_config_defaults(&gclk_chan_conf);
    gclk_chan_conf.source_generator = config->source_generator;
#if (SAMC21) || (SAMC20)
    /* The Analog Comparators and ADC1 use the same generic clock configuration.
     * GCLK_ADC1 must be used to configure the clock for AC as GCLK_AC is not
     * functional. Errata reference: 13404
     */
    system_gclk_chan_set_config(ADC1_GCLK_ID, &gclk_chan_conf);
    system_gclk_chan_enable(ADC1_GCLK_ID);
#else
    system_gclk_chan_set_config(AC_GCLK_ID, &gclk_chan_conf);
    system_gclk_chan_enable(AC_GCLK_ID);
#endif

    return STATUS_OK;
}
Example #18
0
/**
 * Unblocks a thread.
 *
 * This function is paired with rtThreadBlocking.
 *
 * @param   hThread     The current thread.
 * @param   enmCurState The current state, used to check for nested blocking.
 *                      The new state will be running.
 */
RTDECL(void) RTThreadUnblocked(RTTHREAD hThread, RTTHREADSTATE enmCurState)
{
    PRTTHREADINT pThread = hThread;
    if (pThread != NIL_RTTHREAD)
    {
        Assert(pThread == RTThreadSelf());
        ASMAtomicWriteBool(&pThread->fReallySleeping, false);

        RTTHREADSTATE enmActualState = rtThreadGetState(pThread);
        if (enmActualState == enmCurState)
        {
            rtThreadSetState(pThread, RTTHREADSTATE_RUNNING);
            if (   pThread->LockValidator.pRec
                && pThread->LockValidator.enmRecState == enmCurState)
                ASMAtomicWriteNullPtr(&pThread->LockValidator.pRec);
        }
        /* This is a bit ugly... :-/ */
        else if (   (   enmActualState == RTTHREADSTATE_TERMINATED
                     || enmActualState == RTTHREADSTATE_INITIALIZING)
                 && pThread->LockValidator.pRec)
            ASMAtomicWriteNullPtr(&pThread->LockValidator.pRec);
        Assert(   pThread->LockValidator.pRec == NULL
               || RTTHREAD_IS_SLEEPING(enmActualState));
    }
}
/*
 * createInverseContext
 *   Create the context for gp_partition_inverse for a given parent oid.
 */
static InverseContext*
createInverseContext(Oid parentOid)
{
	InverseContext *inverseContext = NULL;

	PartitionIterator *partitionIterator = createPartitionIterator(parentOid);

	Assert(NULL != partitionIterator->partsAndRules);
	Assert(NULL != partitionIterator->partsAndRules->part);
	switch(partitionIterator->partsAndRules->part->parkind)
	{
		case 'r':
			inverseContext = palloc(sizeof(InverseContextForRange));
			inverseContext->partitionIterator = partitionIterator;
			inverseContext->findNextRecord = findNextRecordForRange;
			break;

		case 'l':
			inverseContext = palloc(sizeof(InverseContextForList));
			inverseContext->partitionIterator = partitionIterator;
			inverseContext->findNextRecord = findNextRecordForList;
			((InverseContextForList *)inverseContext)->listValueCell = NULL;
			break;

		default:
			elog(ERROR, "partitioning kind '%c' not allowed",
					partitionIterator->partsAndRules->part->parkind);
	}

	return inverseContext;
}
//
// This method starts the parser that will either load one file
//	or many based on pszFilePath.
// Input: pszFilePath - FS path to KeyValue file(s) for parsing.
//						extentions are defined using .X
//
void CScriptParser::InitParser( const char *pszPath, bool bAllowNonEncryptedSearch /*=true*/, bool bAllowEncryptedSearch /*=true*/ )
{
	// If you hit this assert, check to see where your instancing 
	// CScriptParser, make sure it isn't before the filesystem inits
	Assert( filesystem );
	Assert( pszPath );

	// Have we already been parsed?
	// TODO: Maybe just issue a DevWarning here instead of bailing
	if( m_bParsed )
		return;

	// Copy the file path to tweak the extensions and fix it up
	char szFilePath[FILE_PATH_MAX_LENGTH];
	V_FixupPathName( szFilePath, FILE_PATH_MAX_LENGTH, pszPath );

	//Search for unencrypted files
	if( bAllowNonEncryptedSearch )
	{
		Q_SetExtension( szFilePath, GetNonEncryptedEXT(), FILE_PATH_MAX_LENGTH );
		SearchForFiles( szFilePath );
	}

	//Search for encrypted files
	if( bAllowEncryptedSearch )
	{
		Q_SetExtension( szFilePath, GetEncryptedEXT(), FILE_PATH_MAX_LENGTH );
		SearchForFiles( szFilePath );
	}

	m_bParsed = true;
}
int gr_opengl_bm_make_render_target(int n, int *width, int *height, ubyte *bpp, int *mm_lvl, int flags)
{
	Assert( (n >= 0) && (n < MAX_BITMAPS) );

	if ( !Is_Extension_Enabled(OGL_EXT_FRAMEBUFFER_OBJECT) || Cmdline_no_fbo ) {
		return 0;
	}

	if ( (flags & BMP_FLAG_CUBEMAP) && !Is_Extension_Enabled(OGL_ARB_TEXTURE_CUBE_MAP) ) {
		return 0;
	}

	if ( (flags & BMP_FLAG_CUBEMAP) && (*width != *height) ) {
		MIN(*width, *height) = MAX(*width, *height);
	}

	// Only enforce power of two size if not supported
	if (!(Is_Extension_Enabled(OGL_ARB_TEXTURE_NON_POWER_OF_TWO)))
	{
		Assert( is_power_of_two(*width, *height) );
	}

	if ( opengl_make_render_target(bm_bitmaps[n].handle, n, width, height, bpp, mm_lvl, flags) ) {
		return 1;
	}

	return 0;
}
void opengl_shader_set_current(int handle)
{
	Assert(handle >= 0);
	Assert(handle < (int)GL_shader.size());

	opengl_shader_set_current(&GL_shader[handle]);
}
Example #23
0
/**
 * \brief Resets the hardware module
 *
 * Reset the module to hardware defaults.
 *
 * \param[in,out] module Pointer to software module structure
 */
void i2c_master_reset(struct i2c_master_module *const module)
{
	/* Sanity check arguments */
	Assert(module);
	Assert(module->hw);

	SercomI2cm *const i2c_module = &(module->hw->I2CM);

	/* Wait for sync */
	_i2c_master_wait_for_sync(module);

	/* Disable module */
	i2c_master_disable(module);

#if I2C_MASTER_CALLBACK_MODE == true
	/* Clear all pending interrupts */
	system_interrupt_enter_critical_section();
	system_interrupt_clear_pending(_sercom_get_interrupt_vector(module->hw));
	system_interrupt_leave_critical_section();
#endif

	/* Wait for sync */
	_i2c_master_wait_for_sync(module);

	/* Reset module */
	i2c_module->CTRLA.reg = SERCOM_I2CM_CTRLA_SWRST;
}
Example #24
0
/*
 * generator_init
 *		initialize the generator of combinations
 *
 * The generator produces combinations of K elements in the interval (0..N).
 * We prebuild all the combinations in this method, which is simpler than
 * generating them on the fly.
 */
static CombinationGenerator *
generator_init(int n, int k)
{
	CombinationGenerator *state;

	Assert((n >= k) && (k > 0));

	/* allocate the generator state as a single chunk of memory */
	state = (CombinationGenerator *) palloc(sizeof(CombinationGenerator));

	state->ncombinations = n_choose_k(n, k);

	/* pre-allocate space for all combinations */
	state->combinations = (int *) palloc(sizeof(int) * k * state->ncombinations);

	state->current = 0;
	state->k = k;
	state->n = n;

	/* now actually pre-generate all the combinations of K elements */
	generate_combinations(state);

	/* make sure we got the expected number of combinations */
	Assert(state->current == state->ncombinations);

	/* reset the number, so we start with the first one */
	state->current = 0;

	return state;
}
Example #25
0
CAMLexport value caml_callbackN_exn(value closure, int narg, value args[])
{
  CAMLparam0();
  CAMLlocal1(parent_stack);
  int i;
  value res;
  parent_stack = Stack_parent(caml_current_stack);
  Stack_parent(caml_current_stack) = Val_unit;

  Assert(narg + 4 <= 256);
  caml_extern_sp -= narg + 4;
  for (i = 0; i < narg; i++) caml_extern_sp[i] = args[i]; /* arguments */

  opcode_t code[7] = {
    callback_code[0], narg + 3,
    callback_code[2], narg,
    callback_code[4], callback_code[5], callback_code[6]
  };

  caml_extern_sp[narg] = Val_pc (code + 4); /* return address */
  caml_extern_sp[narg + 1] = Val_unit;    /* environment */
  caml_extern_sp[narg + 2] = Val_long(0); /* extra args */
  caml_extern_sp[narg + 3] = closure;
  res = caml_interprete(code, sizeof(code));
  if (Is_exception_result(res)) caml_extern_sp += narg + 4; /* PR#1228 */

  Assert(Stack_parent(caml_current_stack) == Val_unit);
  Stack_parent(caml_current_stack) = parent_stack;
  CAMLreturn (res);
}
Example #26
0
File: ac.c Project: Gussy/sam0
/**
 * \brief Function used to setup interrupt selection of a window.
 *
 * This function is used to setup when an interrupt should occur
 * for a given window.
 *
 * \note This must be done before enabling the channel.
 *
 * \param[in]  module_inst  Pointer to software instance struct
 * \param[in]  win_channel  Window channel to setup
 * \param[in]  config       Configuration for the given window channel
 *
 * \retval  STATUS_OK               Function exited successful
 * \retval  STATUS_ERR_INVALID_ARG  win_channel argument incorrect
 */
enum status_code ac_win_set_config(
    struct ac_module *const module_inst,
    enum ac_win_channel const win_channel,
    struct ac_win_config *const config)
{
    Assert(module_inst);
    Assert(module_inst->hw);
    Assert(config);

    uint8_t winctrl_mask;

    winctrl_mask = module_inst->hw->WINCTRL.reg;

    if (win_channel == AC_WIN_CHANNEL_0) {
        winctrl_mask &= ~AC_WINCTRL_WINTSEL0_Msk;
        winctrl_mask |= config->interrupt_selection;
    }
#if (AC_PAIRS > 1)
    else if (win_channel == AC_WIN_CHANNEL_1) {
        winctrl_mask &= ~AC_WINCTRL_WINTSEL1_Msk;
        winctrl_mask = (config->interrupt_selection << (AC_WINCTRL_WINTSEL1_Pos -
                        AC_WINCTRL_WINTSEL0_Pos));
    }
#endif /* (AC_PAIRS > 1) */
    else {
        return STATUS_ERR_INVALID_ARG ;
    }

    module_inst->hw->WINCTRL.reg = winctrl_mask;

    return STATUS_OK;
}
Example #27
0
/* ----------------------------------------------------------------
 *		ExecMaterialMarkPos
 *
 *		Calls tuplestore to save the current position in the stored file.
 * ----------------------------------------------------------------
 */
void
ExecMaterialMarkPos(MaterialState *node)
{
	Assert(node->randomAccess);

#ifdef DEBUG
	{
		/* share input should never call this */
		Material *ma = (Material *) node->ss.ps.plan;
		Assert(ma->share_type == SHARE_NOTSHARED);
	}
#endif

	/*
	 * if we haven't materialized yet, just return.
	 */
	if (NULL == node->ts_state->matstore)
	{
		return;
	}

	Assert(node->ts_pos);

	if(node->ts_markpos == NULL)
	{
		node->ts_markpos = palloc(sizeof(NTupleStorePos));
	}

	ntuplestore_acc_tell((NTupleStoreAccessor *) node->ts_pos, (NTupleStorePos *) node->ts_markpos);
}
Example #28
0
File: ac.c Project: Gussy/sam0
/** \brief Disables an Analog Comparator window channel that was previously enabled.
 *
 *  Stops an Analog Comparator window channel that was previously started via a
 *  call to \ref ac_win_enable().
 *
 *  \param[in] module_inst  Software instance for the Analog Comparator peripheral
 *  \param[in] win_channel  Comparator window channel to disable
 */
void ac_win_disable(
    struct ac_module *const module_inst,
    const enum ac_win_channel win_channel)
{
    /* Sanity check arguments */
    Assert(module_inst);
    Assert(module_inst->hw);

    Ac *const ac_module = module_inst->hw;

    while (ac_is_syncing(module_inst)) {
        /* Wait until synchronization is complete */
    }

    /* Disable the requested window comparator */
    switch (win_channel)
    {
    case AC_WIN_CHANNEL_0:
        ac_module->WINCTRL.reg &= ~AC_WINCTRL_WEN0;
        break;

#if (AC_PAIRS > 1)
    case AC_WIN_CHANNEL_1:
        ac_module->WINCTRL.reg &= ~AC_WINCTRL_WEN1;
        break;
#endif
    }
}
Example #29
0
Datum
utf8_to_win(PG_FUNCTION_ARGS)
{
	int			encoding = PG_GETARG_INT32(1);
	unsigned char *src = (unsigned char *) PG_GETARG_CSTRING(2);
	unsigned char *dest = (unsigned char *) PG_GETARG_CSTRING(3);
	int			len = PG_GETARG_INT32(4);
	int			i;

	Assert(PG_GETARG_INT32(0) == PG_UTF8);
	Assert(len >= 0);

	for (i = 0; i < sizeof(maps) / sizeof(pg_conv_map); i++)
	{
		if (encoding == maps[i].encoding)
		{
			UtfToLocal(src, dest, maps[i].map2, maps[i].size2, encoding, len);
			PG_RETURN_VOID();
		}
	}

	ereport(ERROR,
			(errcode(ERRCODE_INTERNAL_ERROR),
			 errmsg("unexpected encoding ID %d for WIN character sets", encoding)));

	PG_RETURN_VOID();
}
Example #30
0
/**
 * \brief Resets the hardware module
 *
 * This will reset the module to hardware defaults.
 *
 * \param[in,out] module  Pointer to software module structure
 */
void i2c_slave_reset(
		struct i2c_slave_module *const module)
{
	/* Sanity check arguments. */
	Assert(module);
	Assert(module->hw);

	SercomI2cs *const i2c_hw = &(module->hw->I2CS);

#if I2C_SLAVE_CALLBACK_MODE == true
	/* Reset module instance. */
	module->registered_callback = 0;
	module->enabled_callback = 0;
	module->buffer_length = 0;
	module->buffer_remaining = 0;
	module->buffer = NULL;
#endif

	/* Disable module */
	i2c_slave_disable(module);

#if I2C_SLAVE_CALLBACK_MODE == true
	/* Clear all pending interrupts. */
	system_interrupt_enter_critical_section();
	system_interrupt_clear_pending(_sercom_get_interrupt_vector(module->hw));
	system_interrupt_leave_critical_section();
#endif

	/* Wait for sync. */
	_i2c_slave_wait_for_sync(module);

	/* Reset module. */
	i2c_hw->CTRLA.reg = SERCOM_I2CS_CTRLA_SWRST;
}