コード例 #1
0
ファイル: divas.c プロジェクト: Gussy/sam0
/**
 * \brief Unsigned division remainder operation overload
 *
 * Run the unsigned division operation and return the remainder.
 * \param[in]  numerator   The dividend of the unsigned division operation
 * \param[in]  denominator The divisor of the unsigned division operation
 *
 * \return The remainder of the DIVAS unsigned division operation.
 */
__value_in_regs uidiv_return __aeabi_uidivmod(unsigned numerator, unsigned denominator)
{
	uidiv_return result;

	/* Disable interrupt. */
	cpu_irq_enter_critical();

	/* Unsigned division. */
	DIVAS->CTRLA.reg &= ~DIVAS_CTRLA_SIGNED;

	/* Write the dividend to DIVIDEND register. */
	DIVAS->DIVIDEND.reg = numerator;
	/* Write the divisor to DIVISOR register. */
	DIVAS->DIVISOR.reg = denominator;

	while(DIVAS->STATUS.bit.BUSY){
		/* Wait the division is complete. */
	}

	/* Read out the result. */
	result.quotient = DIVAS->RESULT.reg;
	result.remainder = DIVAS->REM.reg;

	/* Enable interrupt. */
	cpu_irq_leave_critical();

	return result;
}
コード例 #2
0
ファイル: divas.c プロジェクト: Gussy/sam0
/**
 * \brief Unsigned division remainder operation overload
 *
 * Run the unsigned division operation and return the remainder.
 *
 * \param[in]  numerator   The dividend of the unsigned division operation
 * \param[in]  denominator The divisor of the unsigned division operation
 *
 * \return The remainder of the DIVAS unsigned division operation.
 */
uint64_t __aeabi_uidivmod(uint32_t numerator, uint32_t denominator)
{
	uint64_t uret;
	uint32_t quotient, remainder;

	/* Disable interrupt. */
	cpu_irq_enter_critical();

	/* Unsigned division. */
	DIVAS->CTRLA.reg &= ~DIVAS_CTRLA_SIGNED;

	/* Write the dividend to DIVIDEND register. */
	DIVAS->DIVIDEND.reg = numerator;
	/* Write the divisor to DIVISOR register. */
	DIVAS->DIVISOR.reg = denominator;

	while(DIVAS->STATUS.bit.BUSY){
	/* Wait the division is complete. */
	}

	/* Read out the result. */
	quotient = DIVAS->RESULT.reg;
	remainder = DIVAS->REM.reg;

	/* quotient in r0, remainder in r1 */
	uret = quotient | (((uint64_t)remainder) << 32);

	/* Enable interrupt. */
	cpu_irq_leave_critical();

	return uret;
}
コード例 #3
0
ファイル: divas.c プロジェクト: Gussy/sam0
/**
 * \brief Square root operation
 *
 * Run the square root operation and return the results.
 *
 * \param[in]  radicand  The radicand of the square root operation
 *
 * \return The result of the DIVAS square root operation.
 */
uint32_t  divas_sqrt(uint32_t radicand)
{
	/* Disable interrupt. */
	cpu_irq_enter_critical();

	/* Write the radicand to DIVIDEND register. */
	DIVAS->SQRNUM.reg = radicand;

	while(DIVAS->STATUS.bit.BUSY){
		/* Wait the square root is complete. */
	}

	uint32_t result_sqrt = DIVAS->RESULT.reg;

	/* Enable interrupt. */
	cpu_irq_leave_critical();

	return result_sqrt;
}
コード例 #4
0
/*---------------------------------------------------------------------------*/
void
PendSV_Handler(void)
{
  swi_evt_request_t *req;
  /* Pick the top event request from the event queue. Clear IRQ flag. */
  cpu_irq_enter_critical();
  req = swi_evt_request_pop();
  SCB->ICSR = SCB_ICSR_PENDSVCLR_Msk;
  cpu_irq_leave_critical();
  /* Start timer to mark the end of the pending time slot. */

  /* Execute the handler */  
  if ((req != NULL) && (req->handler != NULL))
  {
    (req->handler)(req->ptr);
  }
  else
  {
    assert(0);
  }
  /* Remove the handler */
}
コード例 #5
0
ファイル: divas.c プロジェクト: Gussy/sam0
/**
 * \brief Signed division operation
 *
 * Run the signed division operation and return the quotient.
 *
 * \param[in]  numerator   The dividend of the signed division operation
 * \param[in]  denominator The divisor of the signed division operation
 *
 * \return The quotient of the DIVAS signed division operation.
 */
int32_t divas_idiv(int32_t numerator, int32_t denominator)
{
	/* Disable interrupt. */
	cpu_irq_enter_critical();

	/* Signed division. */
	DIVAS->CTRLA.reg |= DIVAS_CTRLA_SIGNED;

	/* Write the dividend to DIVIDEND register. */
	DIVAS->DIVIDEND.reg = numerator;
	/* Write the divisor to DIVISOR register. */
	DIVAS->DIVISOR.reg = denominator;

	while(DIVAS->STATUS.bit.BUSY){
		/* Wait the division is complete. */
	}

	int32_t quotient = DIVAS->RESULT.reg;

	/* Enable interrupt. */
	cpu_irq_leave_critical();

	return quotient;
}
コード例 #6
0
ファイル: divas.c プロジェクト: Gussy/sam0
/**
 * \brief Unsigned division remainder operation
 *
 * Run the unsigned division operation and return the remainder.
 *
 * \param[in]  numerator   The dividend of the unsigned division operation
 * \param[in]  denominator The divisor of the unsigned division operation
 *
 * \return The remainder of the DIVAS unsigned division operation.
 */
uint32_t divas_uidivmod(uint32_t numerator, uint32_t denominator)
{
	/* Disable interrupt. */
	cpu_irq_enter_critical();

	/* Unsigned division. */
	DIVAS->CTRLA.reg &= ~DIVAS_CTRLA_SIGNED;

	/* Write the dividend to DIVIDEND register. */
	DIVAS->DIVIDEND.reg = numerator;
	/* Write the divisor to DIVISOR register. */
	DIVAS->DIVISOR.reg = denominator;

	while(DIVAS->STATUS.bit.BUSY){
		/* Wait the division is complete. */
	}

	uint32_t remainder = DIVAS->REM.reg;

	/* Enable interrupt. */
	cpu_irq_leave_critical();

	return remainder;
}