Exemplo n.º 1
0
static inline __attribute__((pure)) dt_daisy_t
__jan00_daisy(unsigned int year)
{
/* daisy's base year is both 1 mod 4 and starts on a monday, so ... */
	unsigned int by = TO_BASE(year);

#if defined WITH_FAST_ARITH
	return by * 365U + by / 4U;
#else  /* !WITH_FAST_ARITH */
	by = by * 365U + by / 4U;
#if DT_DAISY_BASE_YEAR == 1917
	if (UNLIKELY(year > 2100U)) {
		by -= (year - 2001U) / 100U;
		by += (year - 2001U) / 400U;
	}
#elif DT_DAISY_BASE_YEAR == 1753
	by -= (year - 1601U) / 100U;
	by += (year - 1601U) / 400U;
#elif DT_DAISY_BASE_YEAR == 1601
	by -= by / 100U;
	by += by / 400U;
#endif
	return by;
#endif	/* WITH_FAST_ARITH */
}
Exemplo n.º 2
0
static unsigned int
__get_cumwk(unsigned int year)
{
/* return the number of weeks elapsed since 1917 for the first week of YEAR
 * we follow the 28y cycle */
	unsigned int by = TO_BASE(year);
	unsigned int add = 0U;

	switch (by % 28U) {
	case 27/*1944*/:
	case 26/*1943*/:
		add++;
	case 25/*1942*/:
	case 24/*1941*/:
	case 23/*1940*/:
	case 22/*1939*/:
	case 21/*1938*/:
	case 20/*1937*/:
		add++;
	case 19/*1936*/:
	case 18/*1935*/:
	case 17/*1934*/:
	case 16/*1933*/:
	case 15/*1932*/:
		add++;
	case 14/*1931*/:
	case 13/*1930*/:
	case 12/*1929*/:
	case 11/*1928*/:
	case 10/*1927*/:
	case 9/*1926*/:
		add++;
	case 8/*1925*/:
	case 7/*1924*/:
	case 6/*1923*/:
	case 5/*1922*/:
		add++;
	case 4/*1921*/:
	case 3/*1920*/:
	case 2/*1919*/:
	case 1/*1918*/:
	case 0/*1917*/:
	default:
		break;
	}
	return 52U * by + 5U * (by / 28U) + add;
}
Exemplo n.º 3
0
static dt_daisy_t
__ymcw_to_daisy(dt_ymcw_t d)
{
	dt_daisy_t res;
	unsigned int sy = d.y;
	unsigned int sm = d.m;
	unsigned int sd;

	if (UNLIKELY((signed int)TO_BASE(sy) < 0)) {
		return 0;
	}

	sd = __ymcw_get_mday(d);
	res = __jan00_daisy(sy);
	res += __md_get_yday(sy, sm, sd);
	return res;
}
Exemplo n.º 4
0
void gpio_init(int pin, enum gpio_mode mode, int value)
{
	uint32_t base = TO_BASE(pin);
	pin = 1 << (pin & 0x0F);

	switch (mode) {
		case GPIO_OUTPUT:
			MAP_GPIOPinTypeGPIOOutput(base, pin);
			gpio_set(pin, value);
			break;
		case GPIO_OUTPUT_SLOW:
			MAP_GPIOPinTypeGPIOOutput(base, pin);
			MAP_GPIOPadConfigSet(base, pin, GPIO_STRENGTH_8MA_SC,
			    GPIO_PIN_TYPE_STD);
			gpio_set(pin, value);
			break;
		case GPIO_INPUT:
			MAP_GPIOPinTypeGPIOInput(base, pin);
			break;
		case GPIO_INPUT_PD:
			MAP_GPIOPinTypeGPIOInput(base, pin);
			MAP_GPIOPadConfigSet(base, pin, GPIO_STRENGTH_8MA,
			    GPIO_PIN_TYPE_STD_WPD);
			break;
		case GPIO_INPUT_PU:
			MAP_GPIOPinTypeGPIOInput(base, pin);
			MAP_GPIOPadConfigSet(base, pin, GPIO_STRENGTH_8MA,
			    GPIO_PIN_TYPE_STD_WPU);
			break;
		case GPIO_ANALOG:
			MAP_GPIOPinTypeGPIOInput(base, pin);
			MAP_GPIOPadConfigSet(base, pin, GPIO_STRENGTH_8MA,
			    GPIO_PIN_TYPE_ANALOG);
			break;
	}
}
Exemplo n.º 5
0
int gpio_get(int pin)
{
	return MAP_GPIOPinRead(TO_BASE(pin), TO_PIN(pin));
}
Exemplo n.º 6
0
void gpio_set(int pin, int value)
{
	value = !!value;

	MAP_GPIOPinWrite(TO_BASE(pin), TO_PIN(pin), (value << TO_PIN(pin)));
}