Exemplo n.º 1
0
/**
 * @brief Atualiza o estado do sistema de acordo com as chaves
 */
void updateSystemStatus(estados_t *estados)
{
	UPDATE_BIT(		PIN_aciBomba1,	BIT_aciBomba1,	*estados,	estBomba1		);
	UPDATE_BIT(		PIN_aciBomba2,	BIT_aciBomba2,	*estados,	estBomba2		);
	UPDATE_BIT(		PIN_aciMPPT,	BIT_aciMPPT,	*estados,	estMPPT			);
	UPDATE_BIT(		PIN_aux1,		BIT_aux1,		*estados,	estBomba1		);
	UPDATE_BIT(		PIN_aux2,		BIT_aux2,		*estados,	estBomba1		);
}
Exemplo n.º 2
0
/**
 * PWM configuration.
 *
 * @param  ch    operation channel
 * @return none
 */
void pwm_config(enum pwm_channel ch)
{
	int mdl = pwm_channels[ch].channel;

	/* Disable PWM for module configuration */
	pwm_enable(mdl, 0);

	/* Set PWM heartbeat mode is no heartbeat */
	SET_FIELD(NPCX_PWMCTL(mdl), NPCX_PWMCTL_HB_DC_CTL_FIELD,
			NPCX_PWM_HBM_NORMAL);

	/* Select default CLK or LFCLK clock input to PWM module */
	SET_FIELD(NPCX_PWMCTLEX(mdl), NPCX_PWMCTLEX_FCK_SEL_FIELD,
			NPCX_PWM_CLOCK_APB2_LFCLK);

	/* Set PWM polarity normal first */
	CLEAR_BIT(NPCX_PWMCTL(mdl), NPCX_PWMCTL_INVP);

	/* Select PWM clock source */
	UPDATE_BIT(NPCX_PWMCTL(mdl), NPCX_PWMCTL_CKSEL,
			(pwm_channels[ch].flags & PWM_CONFIG_DSLEEP_CLK));

	/* Set PWM operation frequency */
	pwm_set_freq(ch, pwm_channels[ch].freq, DUTY_CYCLE_RESOLUTION);

}
Exemplo n.º 3
0
int flash_spi_sel_lock(int enable)
{
	/*
	 * F_SPI_QUAD, F_SPI_CS1_1/2, F_SPI_TRIS become read-only
	 * if this bit is set
	 */
	UPDATE_BIT(NPCX_DEV_CTL4, NPCX_DEV_CTL4_F_SPI_SLLK, enable);
	return IS_BIT_SET(NPCX_DEV_CTL4, NPCX_DEV_CTL4_F_SPI_SLLK);
}
Exemplo n.º 4
0
static void i2c_select_port(int port)
{
	/*
	 * I2C0_1 uses port 1 of controller 0. All other I2C pin sets
	 * use port 0.
	 */
	if (port > NPCX_I2C_PORT0_1)
		return;

	/* Select IO pins for multi-ports I2C controllers */
	UPDATE_BIT(NPCX_GLUE_SMBSEL, NPCX_SMBSEL_SMB0SEL,
			(port == NPCX_I2C_PORT0_1));
}
Exemplo n.º 5
0
/* Internal functions */
void init_hw_timer(int itim_no, enum ITIM_SOURCE_CLOCK_T source)
{
	/* Use internal 32K clock/APB2 for ITIM16 */
	UPDATE_BIT(NPCX_ITCTS(itim_no), NPCX_ITCTS_CKSEL,
			source != ITIM_SOURCE_CLOCK_APB2);

	/* Clear timeout status */
	SET_BIT(NPCX_ITCTS(itim_no), NPCX_ITCTS_TO_STS);

	/* ITIM timeout interrupt enable */
	SET_BIT(NPCX_ITCTS(itim_no), NPCX_ITCTS_TO_IE);

	/* ITIM timeout wake-up enable */
	SET_BIT(NPCX_ITCTS(itim_no), NPCX_ITCTS_TO_WUE);
}
Exemplo n.º 6
0
/* flash internal functions */
void flash_pinmux(int enable)
{
	/* Select pin-mux for FIU*/
	UPDATE_BIT(NPCX_DEVALT(0), NPCX_DEVALT0_NO_F_SPI, !enable);

	/* CS0/1 pinmux */
	if (enable) {
#if (FIU_CHIP_SELECT == 1)
		SET_BIT(NPCX_DEVALT(0), NPCX_DEVALT0_F_SPI_CS1_1);
#elif (FIU_CHIP_SELECT == 2)
		SET_BIT(NPCX_DEVALT(0), NPCX_DEVALT0_F_SPI_CS1_2);
#endif
	} else {
		CLEAR_BIT(NPCX_DEVALT(0), NPCX_DEVALT0_F_SPI_CS1_1);
		CLEAR_BIT(NPCX_DEVALT(0), NPCX_DEVALT0_F_SPI_CS1_2);
	}
}
Exemplo n.º 7
0
/**
 * Set PWM duty cycle.
 *
 * @param   ch      operation channel
 * @param   percent duty cycle percent
 * @return  none
 */
void pwm_set_duty(enum pwm_channel ch, int percent)
{
	int mdl = pwm_channels[ch].channel;
	uint32_t dc_res = 0;
	uint16_t dc_cnt = 0;

	/* Checking duty value first */
	if (percent < 0)
		percent = 0;
	else if (percent > 100)
		percent = 100;
	CPRINTS("pwm%d, set duty=%d", mdl, percent);

	/* Assume the fan control is active high and invert it ourselves */
	UPDATE_BIT(NPCX_PWMCTL(mdl), NPCX_PWMCTL_INVP,
			(pwm_channels[ch].flags & PWM_CONFIG_ACTIVE_LOW));

	dc_res = NPCX_CTR(mdl) + 1;
	dc_cnt = (percent*dc_res)/100;
	CPRINTS("freq=0x%x", pwm_channels[ch].freq);
	CPRINTS("duty_cycle_res=%d", dc_res);
	CPRINTS("duty_cycle_cnt=%d", dc_cnt);


	/* Set the duty cycle */
	if (percent > 0) {
		if (percent == 100)
			NPCX_DCR(mdl) = NPCX_CTR(mdl);
		else
			NPCX_DCR(mdl) = (dc_cnt - 1);
		pwm_enable(ch, 1);
	} else {
		/* Output low since DCR > CTR */
		NPCX_DCR(mdl) = NPCX_CTR(mdl) + 1;
		pwm_enable(ch, 0);
	}
}
Exemplo n.º 8
0
void flash_cs_level(int level)
{
	/* Set chip select to high/low level */
	UPDATE_BIT(NPCX_UMA_ECTS, NPCX_UMA_ECTS_SW_CS1, level);
}
Exemplo n.º 9
0
void flash_tristate(int enable)
{
	/* Enable/Disable FIU pins to tri-state */
	UPDATE_BIT(NPCX_DEVCNT, NPCX_DEVCNT_F_SPI_TRIS, enable);
}
Exemplo n.º 10
0
int flash_uma_lock(int enable)
{
	UPDATE_BIT(NPCX_UMA_ECTS, NPCX_UMA_ECTS_UMA_LOCK, enable);
	return EC_SUCCESS;
}
Exemplo n.º 11
0
/**
 * Set PWM enabled.
 *
 * @param   ch      operation channel
 * @param   enabled enabled flag
 * @return  none
 */
void pwm_enable(enum pwm_channel ch, int enabled)
{
	int mdl = pwm_channels[ch].channel;
	/* Start or close PWM module */
	UPDATE_BIT(NPCX_PWMCTL(mdl), NPCX_PWMCTL_PWR, enabled);
}
Exemplo n.º 12
0
Arquivo: lpc.c Projeto: thehobn/ec
/* Put a char to host buffer and send IRQ if specified. */
void lpc_keyboard_put_char(uint8_t chr, int send_irq)
{
	UPDATE_BIT(NPCX_HICTRL, NPCX_HICTRL_OBFKIE, send_irq);
	NPCX_HIKDO = chr;
	task_enable_irq(NPCX_IRQ_KBC_OBF);
}