예제 #1
0
void adc_disable_clock(ADC_t *adc)
{
#ifdef ADCA
	if ((uintptr_t)adc == (uintptr_t)(&ADCA)) {
		Assert(adca_enable_count);
		if (!--adca_enable_count) {
			sysclk_disable_module(SYSCLK_PORT_A, SYSCLK_ADC);
		}
	} else
#endif

#ifdef ADCB
	if ((uintptr_t)adc == (uintptr_t)(&ADCB)) {
		Assert(adcb_enable_count);
		if (!--adcb_enable_count) {
			sysclk_disable_module(SYSCLK_PORT_B, SYSCLK_ADC);
		}
	} else
#endif

	{
		Assert(0);
	}
}
예제 #2
0
파일: dma.c 프로젝트: JanOveSaltvedt/ovdmx
/**
 * \brief Disable DMA controller
 */
void dma_disable(void)
{
	DMA.CTRL = 0;
	sysclk_disable_module(SYSCLK_PORT_GEN, SYSCLK_DMA);
	sleepmgr_unlock_mode(SLEEPMGR_IDLE);
}
예제 #3
0
파일: sysclk.c 프로젝트: ErlendLS/TFE4850
/**
 * \brief Disable clock for the USB module
 */
void sysclk_disable_usb(void)
{
	sysclk_disable_module(SYSCLK_PORT_GEN, SYSCLK_USB);
	ccp_write_io((uint8_t *)&CLK.USBCTRL, 0);
}
예제 #4
0
int main( void )
{
	uint8_t i;

	board_init();
	sysclk_init();
	sleepmgr_init();

	/* Assume that everything is ok*/
	success = true;

	/* Enable the AES clock. */
	sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_AES);

	/* Do AES encryption of a single block with DMA support. */
	//********************************************************
	//               CIPHER IN MANUAL MODE:
	//  - 128bit cryptographic key and data
	//  - ECB cipher mode
	//  - XOR disable
	//  - DMA support for AES input and output
	//********************************************************
	/* Before using the AES it is recommended to do an AES software reset to
	 * put the module in known state, in case other parts of your code has
	 * accessed the AES module. */
	aes_software_reset();

	/* Set AES encryption of a single block in manual mode. */
	aes_configure(AES_ENCRYPT, AES_MANUAL, AES_XOR_OFF);

	/* Disable the AES interrupt. */
	aes_isr_configure(AES_INTLVL_OFF);

	/* Set KEY and write STATE using DMA channel 0. */
	aes_dma_input();

	/* Start encryption. */
	aes_start();

	do {
		/* Wait until AES is finished or an error occurs. */
	} while (aes_is_busy());

	/* Store the result if not error. */
	if (!aes_is_error()){
		/* Read STATE using DMA channel 0. */
		aes_dma_output();
	} else {
		success = false;
	}

	/* Check if encrypted answer is equal to cipher result. */
	for (i = 0; i < BLOCK_LENGTH ; i++ ) {
		if (cipher_text[i] != single_ans[i]) {
			success = false;
		}
	}

	/* Disable the AES clock. */
	sysclk_disable_module(SYSCLK_PORT_GEN, SYSCLK_AES);

	/* Indicate final result by lighting LED. */
	if (success) {
		/* If the example ends up here every thing is ok. */
		ioport_set_pin_low(LED0_GPIO);
	} else {
		/* If the example ends up here something is wrong. */
		ioport_set_pin_low(LED1_GPIO);
	}

	while (true) {
		/* Go to sleep. */
		sleepmgr_enter_sleep();
	}
}
예제 #5
0
int main( void )
{
	uint8_t i;

	board_init();
	sysclk_init();
	sleepmgr_init();

	/* Assume that everything is ok */
	success = true;

	/* Enable the AES clock. */
	sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_AES);

	/* Do AES encryption and decryption of a single block. */
	//********************************************************
	//               CIPHER IN MANUAL MODE:
	//  - 128bit cryptographic key and data
	//  - ECB cipher mode
	//  - XOR disable
	//  - Polling AES State Ready Interrupt flag
	//********************************************************
	/* Before using the AES it is recommended to do an AES software reset to
	 * put the module in known state, in case other parts of your code has
	 * accessed the AES module. */
	aes_software_reset();

	/* Set AES encryption of a single block in manual mode. */
	aes_configure(AES_ENCRYPT, AES_MANUAL, AES_XOR_OFF);

	/* Disable the AES interrupt. */
	aes_isr_configure(AES_INTLVL_OFF);

	/* Load key into AES key memory. */
	aes_set_key(key);

	/* Load data into AES state memory. */
	aes_write_inputdata(plain_text);

	/* Start encryption. */
	aes_start();

	do {
		/* Wait until AES is finished or an error occurs. */
	} while (aes_is_busy());

	/* Store the result if not error. */
	if (!aes_is_error()) {
		aes_read_outputdata(single_ans);
	} else {
		success = false;
	}

	/* Check if encrypted answer is equal to cipher result. */
	for (i = 0; i < BLOCK_LENGTH ; i++ ) {
		if (cipher_text[i] != single_ans[i]) {
			success = false;
		}
	}

	//********************************************************
	//               DECIPHER IN AUTO MODE:
	//  - 128bit cryptographic key and data
	//  - ECB cipher mode
	//  - XOR disable
	//  - Polling AES State Ready Interrupt flag
	//********************************************************
	/* Generate last subkey. */
	if (!aes_lastsubkey_generate(key, lastsubkey)) {
		success = false;
	}

	/* Before using the AES it is recommended to do an AES software reset to
	 * put the module in known state, in case other parts of your code has
	 * accessed the AES module. */
	aes_software_reset();

	/* Set AES decryption of a single block in auto mode. */
	aes_configure(AES_DECRYPT, AES_AUTO, AES_XOR_OFF);

	/* Disable the AES interrupt. */
	aes_isr_configure(AES_INTLVL_OFF);

	/* Load key into AES key memory. */
	aes_set_key(lastsubkey);

	/* Load data into AES state memory. */
	aes_write_inputdata(cipher_text);
	// NOTE: since we're in auto mode, the ciphering process will start as soon
	// as the correct number of input data is written. In this case, the
	// process should start when we write the sixteenth byte.

	do {
		/* Wait until AES is finished or an error occurs. */
	} while (aes_is_busy());

	/* Store the result if not error. */
	if (!aes_is_error()) {
		aes_read_outputdata(single_ans);
	} else {
		success = false;
	}

	/* Check if decrypted answer is equal to plaintext. */
	for (i = 0; i < BLOCK_LENGTH ; i++ ) {
		if (plain_text[i] != single_ans[i]) {
			success = false;
		}
	}

	/* Disable the AES clock. */
	sysclk_disable_module(SYSCLK_PORT_GEN, SYSCLK_AES);

	/* Indicate final result by lighting LED. */
	if (success) {
		/* If the example ends up here every thing is ok. */
		ioport_set_pin_low(LED0_GPIO);
	} else {
		/* If the example ends up here something is wrong. */
		ioport_set_pin_low(LED1_GPIO);
	}

	while (true) {
		/* Go to sleep. */
		sleepmgr_enter_sleep();
	}
}
예제 #6
0
int main( void )
{
	uint16_t i;

	/* Enable all three interrupt levels of the PMIC. */
	pmic_init();
	board_init();
	sysclk_init();
	sleepmgr_init();

	/* Assume that everything is ok*/
	success = true;

	/* Enable the AES clock. */
	sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_AES);

	/* Do AES decryption of a single block with AES interrupt handler. */
	//********************************************************
	//               DECIPHER IN MANUAL MODE:
	//  - 128bit cryptographic key and data
	//  - ECB cipher mode
	//  - XOR disable
	//  - Interrupt call back handler
	//********************************************************
	/* Generate last subkey. */
	if (!aes_lastsubkey_generate(key, lastsubkey)) {
		success = false;
	}

	/* Enable global interrupts. */
	cpu_irq_enable();

	/* Assume no interrupt is finished. */
	int_end = false;
	byte_count = 0;

	/* Set AES interrupt call back function. */
	aes_set_callback(&aes_isr_handler);

	/* Before using the AES it is recommended to do an AES software reset to
	 * put the module in known state, in case other parts of your code has
	 * accessed the AES module. */
	aes_software_reset();

	/* Set AES encryption of a single block in manual mode. */
	aes_configure(AES_DECRYPT, AES_MANUAL, AES_XOR_OFF);

	/* Enable the AES low level interrupt. */
	aes_isr_configure(AES_INTLVL_LO);

	/* Load key into AES key memory. */
	aes_set_key(lastsubkey);

	/* Load data into AES state memory. */
	aes_write_inputdata(cipher_text);

	/* Start encryption. */
	aes_start();

	do{
		/* Wait until the AES interrupt is finished. */
	} while (!int_end);

	/* Do AES encryption and decryption of multi blocks. */
	//********************************************************
	//               CIPHER IN AUTO MODE:
	//  - 128bit cryptographic key and data
	//  - CBC cipher mode
	//  - XOR on
	//  - Interrupt call back handler
	//********************************************************
	/* Assume no interrupt is finished. */
	int_end = false;
	byte_count = 0;

	/* Set AES interrupt call back function. */
	aes_set_callback(&aes_isr_cbc_encrypt_handler);

	/* Before using the AES it is recommended to do an AES software reset to
	 * put the module in known state, in case other parts of your code has
	 * accessed the AES module. */
	aes_software_reset();

	/* Load initial vector into AES state memory. */
	aes_write_inputdata(init);

	/* Set AES encryption of a single block in auto mode. */
	aes_configure(AES_ENCRYPT, AES_AUTO, AES_XOR_ON);

	/* Enable the AES low level interrupt. */
	aes_isr_configure(AES_INTLVL_LO);

	/* Load key into AES key memory. */
	aes_set_key(key);

	/* Load data into AES state memory. */
	aes_write_inputdata(data_block);
	// NOTE: since we're in auto mode, the ciphering process will start as soon
	// as the correct number of input data is written. In this case, the
	// process should start when we write the sixteenth byte.

	do{
		/* Wait until the AES interrupt is finished. */
	} while (!int_end);

	//********************************************************
	//               DECIPHER IN AUTO MODE:
	//  - 128bit cryptographic key and data
	//  - CBC cipher mode
	//  - XOR off
	//  - Interrupt call back handler
	//********************************************************
	/* Generate last subkey. */
	if (!aes_lastsubkey_generate(key, lastsubkey)) {
		success = false;
	}

	/* Assume no interrupt is finished. */
	int_end = false;
	byte_count = 0;

	/* Set AES interrupt call back function. */
	aes_set_callback(&aes_isr_cbc_decrypt_handler);

	/* Before using the AES it is recommended to do an AES software reset to
	 * put the module in known state, in case other parts of your code has
	 * accessed the AES module. */
	aes_software_reset();

	/* Set AES decryption of a single block in auto mode. */
	aes_configure(AES_DECRYPT, AES_AUTO, AES_XOR_OFF);

	/* Enable the AES low level interrupt. */
	aes_isr_configure(AES_INTLVL_LO);

	/* Load key into AES key memory. */
	aes_set_key(lastsubkey);

	/* Load data into AES state memory. */
	aes_write_inputdata(cipher_block_ans);
	// NOTE: since we're in auto mode, the ciphering process will start as soon
	// as the correct number of input data is written. In this case, the
	// process should start when we write the sixteenth byte.

	do{
		/* Wait until the AES interrupt is finished. */
	} while (!int_end);

	/* Check if decrypted answer is equal to plaintext. */
	for (i = 0; i < BLOCK_LENGTH * BLOCK_COUNT ; i++) {
		if (data_block[i] != plain_block_ans[i]){
			success = false;
		}
	}
	/* Disable the AES clock. */
	sysclk_disable_module(SYSCLK_PORT_GEN, SYSCLK_AES);

	/* Indicate final result by lighting LED. */
	if (success) {
		/* If the example ends up here every thing is ok. */
		ioport_set_pin_low(LED0_GPIO);
	} else {
		/* If the example ends up here something is wrong. */
		ioport_set_pin_low(LED1_GPIO);
	}

	while (true) {
		/* Go to sleep. */
		sleepmgr_enter_sleep();
	}
}
예제 #7
0
파일: tc.c 프로젝트: KN2C-CanSat/KN2CSat
/**
 * \brief Disable TC
 *
 * Disables the TC.
 *
 * \param tc Pointer to TC module
 *
 * \note
 * mask TC clock (sysclk).
 */
void tc_disable(volatile void *tc)
{
	irqflags_t iflags = cpu_irq_save();

	sleepmgr_unlock_mode(SLEEPMGR_IDLE);

#ifdef TCC0
	if ((uintptr_t) tc == (uintptr_t) & TCC0) {
		sysclk_disable_module(SYSCLK_PORT_C, SYSCLK_TC0);
		sysclk_disable_module(SYSCLK_PORT_C, SYSCLK_HIRES);
	} else
#endif
#ifdef TCC1
	if ((uintptr_t) tc == (uintptr_t) & TCC1) {
		sysclk_disable_module(SYSCLK_PORT_C, SYSCLK_TC1);
		sysclk_disable_module(SYSCLK_PORT_C, SYSCLK_HIRES);
	} else
#endif
#ifdef TCD0
	if ((uintptr_t) tc == (uintptr_t) & TCD0) {
		sysclk_disable_module(SYSCLK_PORT_D, SYSCLK_TC0);
		sysclk_disable_module(SYSCLK_PORT_D, SYSCLK_HIRES);
	} else
#endif
#ifdef TCD1
	if ((uintptr_t) tc == (uintptr_t) & TCD1) {
		sysclk_disable_module(SYSCLK_PORT_D, SYSCLK_TC1);
		sysclk_disable_module(SYSCLK_PORT_D, SYSCLK_HIRES);
	} else
#endif
#ifdef TCE0
	if ((uintptr_t) tc == (uintptr_t) & TCE0) {
		sysclk_disable_module(SYSCLK_PORT_E, SYSCLK_TC0);
		sysclk_disable_module(SYSCLK_PORT_E, SYSCLK_HIRES);
	} else
#endif
#ifdef TCE1
	if ((uintptr_t) tc == (uintptr_t) & TCE1) {
		sysclk_disable_module(SYSCLK_PORT_E, SYSCLK_TC1);
		sysclk_disable_module(SYSCLK_PORT_E, SYSCLK_HIRES);
	} else
#endif
#ifdef TCF0
	if ((uintptr_t) tc == (uintptr_t) & TCF0) {
		sysclk_disable_module(SYSCLK_PORT_F, SYSCLK_TC0);
		sysclk_disable_module(SYSCLK_PORT_F, SYSCLK_HIRES);
	} else
#endif
#ifdef TCF1
	if ((uintptr_t) tc == (uintptr_t) & TCF1) {
		sysclk_disable_module(SYSCLK_PORT_F, SYSCLK_TC1);
		sysclk_disable_module(SYSCLK_PORT_F, SYSCLK_HIRES);
	} else
#endif
	{
		cpu_irq_restore(iflags);
		return;
	}
	cpu_irq_restore(iflags);
}
예제 #8
0
파일: ac.c 프로젝트: AndreyMostovov/asf
/**
 * \brief Write analog comparator configuration to hardware
 *
 * This function will write a \ref ac_config struct to the selected analog
 * comparator hardware and channel.
 *
 * \param ac Pointer to the analog comparator (AC) base address
 * \param channel Number of analog comparator (AC) channel
 * \param config Pointer to a \ref ac_config variable
 */
void ac_write_config(AC_t *ac, uint8_t channel, struct ac_config *config)
{
	enum sysclk_port_id     sysclk_port;
	irqflags_t              iflags = cpu_irq_save();

#ifdef ACA
	if ((uintptr_t)ac == (uintptr_t)&ACA) {
		sysclk_port = SYSCLK_PORT_A;
		if (!ac_aca_opened) {
			sysclk_enable_module(sysclk_port, SYSCLK_AC);
		}
		ac_aca_opened++;
	} else
#endif
#ifdef ACB
	if ((uintptr_t)ac == (uintptr_t)&ACB) {
		sysclk_port = SYSCLK_PORT_B;
		if (!ac_acb_opened) {
			sysclk_enable_module(sysclk_port, SYSCLK_AC);
		}
		ac_acb_opened++;
	} else
#endif
	{
		cpu_irq_restore(iflags);
		return;
	}

	ac->CTRLB               = config->ctrlb;
	ac->WINCTRL             = config->winctrl;

	if (channel == 0) {
		ac->AC0MUXCTRL  = config->acmuxctrl;
		ac->AC0CTRL     = config->acctrl;
	} else {
		ac->AC1MUXCTRL  = config->acmuxctrl;
		ac->AC1CTRL     = config->acctrl;
	}

#ifdef ACA
	if (sysclk_port == SYSCLK_PORT_A) {
		ac_aca_opened--;
		if (!ac_aca_opened) {
			sysclk_disable_module(SYSCLK_PORT_A, SYSCLK_AC);
		}
	} else
#endif
#ifdef ACB
	if (sysclk_port == SYSCLK_PORT_B) {
		ac_acb_opened--;
		if (!ac_acb_opened) {
			sysclk_disable_module(SYSCLK_PORT_B, SYSCLK_AC);
		}
	} else
#endif
	{
		cpu_irq_restore(iflags);
		return;
	}

	cpu_irq_restore(iflags);
}