Esempio n. 1
0
/**
 *  \brief Recursively calculate the nth Fibonacci number.
 *
 * \param n Indicates which (positive) Fibonacci number to compute.
 *
 * \return The nth Fibonacci number.
 */
static uint32_t recfibo(uint32_t n)
{
	if (n == 0 || n == 1) {
		return n;
	}

	return recfibo(n - 2) + recfibo(n - 1);
}
Esempio n. 2
0
/**
 * \brief The main function.
 */
int main(void)
{
	/* Initialize the SAM system */
	sysclk_init();
	board_init();

	/* Initialize the console  */
	configure_console();

	/* Output example information */
	printf("-- CMCC Example --\r\n");
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

	/* Enable the CMCC module. */
	cmcc_get_config_defaults(&g_cmcc_cfg);
	cmcc_init(CMCC_BASE, &g_cmcc_cfg);
	cmcc_enable(CMCC_BASE);

	/* Do the Fibonacci calculation. */
	recfibo(FIBONACCI_NUM);
	printf("Fibonacci calculation completed \r\n");
	printf("Cache Data hit: %ld \r\n", cmcc_get_monitor_cnt(CMCC_BASE));

	while (true) {
	}
}
Esempio n. 3
0
/**
 *  \brief Reconfigure serial console.
 */
static void reconfigure_com_port(void)
{
	const sam_usart_opt_t opt = {
		.baudrate = CONF_UART_BAUDRATE,
		.char_length = CONF_UART_CHAR_LENGTH,
		.parity_type = CONF_UART_PARITY,
		.stop_bits = CONF_UART_STOP_BITS,
		.channel_mode = US_MR_CHMODE_NORMAL,
		.irda_filter = 0,
	};
	usart_init_rs232(CONF_UART, &opt, LOWER_SYS_CLK);
	usart_enable_tx(CONF_UART);
}

/**
 *  \brief Recursively calculate the nth Fibonacci number.
 *
 * \param n Indicates which (positive) Fibonacci number to compute.
 *
 * \return The nth Fibonacci number.
 */
static uint32_t recfibo(uint32_t n)
{
	if (n == 0 || n == 1) {
		return n;
	}

	return recfibo(n - 2) + recfibo(n - 1);
}

/**
 * \brief This is an example demonstrating Fibonacci calculation
 *         with and without PicoCache.
 *
 * \param caption     Caption to print before running the example.
 * \param pico_enable Enable PicoCache or not.
 */
static void flash_picocache_example(const char *caption, bool pico_enable)
{
	uint32_t tick_start, time_ms;

	printf("\n\r--------------\n\r%s\n\r", caption);

	/* Enable PicoCache if required */
	if (pico_enable) {
		flashcalw_picocache_enable();

		flashcalw_picocache_set_monitor_mode(HCACHE_MCFG_MODE_IHIT);
		flashcalw_picocache_enable_monitor();
		flashcalw_picocache_reset_monitor();
	} else {
		flashcalw_picocache_disable();
		flashcalw_picocache_disable_monitor();
	}

	/* Get current time tick */
	tick_start = time_tick_get();

	/* Do the Fibonacci calculation. */
	recfibo(FIBONACCI_NUM);

	/* Calculate the Fibonacci spent time */
	time_ms = time_tick_calc_delay(tick_start, time_tick_get());
	if (time_ms) {
		printf("Time spent: %u ms\r\n", (unsigned int)time_ms);
	}

	/* Display cache hit counter */
	if (pico_enable) {
		printf("Pico cache instruction hit: %u \r\n",
			(unsigned int)flashcalw_picocache_get_monitor_cnt());
	}
}