コード例 #1
0
ファイル: ui.c プロジェクト: AndreyMostovov/asf
/**
 * \name PWM functions
 * @{
 */
void ui_pwm_led_init(uint8_t lednum)
{
	/* Timer waveform options */
	static tc_waveform_opt_t waveform_options = {
		/* Channel selection. */
		.channel  = 1,

		.bswtrg   = TC_EVT_EFFECT_NOOP,
		.beevt    = TC_EVT_EFFECT_NOOP,
		.bcpc     = TC_EVT_EFFECT_NOOP,
		.bcpb     = TC_EVT_EFFECT_NOOP,

		.aswtrg   = TC_EVT_EFFECT_NOOP,
		.aeevt    = TC_EVT_EFFECT_NOOP,
		.acpc     = TC_EVT_EFFECT_NOOP,
		.acpa     = TC_EVT_EFFECT_NOOP,

		/* Waveform selection */
		.wavsel   = TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER,
		/* External event trigger enable. */
		.enetrg   = false,
		/* External event selection (non-zero for Channel B to work) */
		.eevt     = !0,
		/* External event edge selection. */
		.eevtedg  = TC_SEL_NO_EDGE,

		.cpcdis   = false,
		.cpcstop  = false,

		.burst    = false,
		.clki     = false,
		/* Internal source clock 5, fPBA/128. */
		.tcclks   = TC_CLOCK_SOURCE_TC5,
	};
	switch (lednum) {
	case LED0:
		/* Assign output pin to timer/counter 0 channel A */

		/* Channel selection. */
		waveform_options.channel = 1;

		waveform_options.bcpc = TC_EVT_EFFECT_NOOP;

		waveform_options.bcpb = TC_EVT_EFFECT_NOOP;
		/* RC compare effect on TIOA. */
		waveform_options.acpc = TC_EVT_EFFECT_CLEAR;
		/* RA compare effect on TIOA. */
		waveform_options.acpa = TC_EVT_EFFECT_SET;

		/* Setup timer/counter waveform mode */
		sysclk_enable_peripheral_clock(&AVR32_TC0);
		tc_init_waveform(&AVR32_TC0, &waveform_options);

		/* Write the TOP (RC) and COMPARE (RA) values */
		tc_write_ra(&AVR32_TC0, 1, 1);   /* Set RA value. */
		tc_write_rc(&AVR32_TC0, 1, 255); /* Set RC value. */

		/* Start the timer PWM channel */
		tc_start(&AVR32_TC0, 1);
		break;

	case LED1:
		/* Assign output pin to timer/counter 1 channel B */

		/* Channel selection. */
		waveform_options.channel = 2;

		waveform_options.acpc = TC_EVT_EFFECT_NOOP;

		waveform_options.acpa = TC_EVT_EFFECT_NOOP;
		/* RC compare effect on TIOB. */
		waveform_options.bcpc = TC_EVT_EFFECT_CLEAR;
		/* RB compare effect on TIOB. */
		waveform_options.bcpb = TC_EVT_EFFECT_SET;

		/* Setup timer/counter waveform mode */
		sysclk_enable_peripheral_clock(&AVR32_TC1);
		tc_init_waveform(&AVR32_TC1, &waveform_options);

		/* Write the TOP (RC) and COMPARE (RB) values */
		tc_write_rb(&AVR32_TC1, 2, 1);   /* Set RB value. */
		tc_write_rc(&AVR32_TC1, 2, 255); /* Set RC value. */

		/* Start the timer PWM channel */
		tc_start(&AVR32_TC1, 2);
		break;

	default:
		break;
	}
}

void ui_pwm_update(uint8_t channum, uint8_t brightness)
{
	switch (channum) {
	case LED0:
		if (brightness != 0) {
			gpio_enable_module_pin(AVR32_TC0_A1_0_1_PIN,
					AVR32_TC0_A1_0_1_FUNCTION);
			tc_start(&AVR32_TC0, 1);
			tc_write_ra(&AVR32_TC0, 1, brightness);
		} else {
			tc_stop(&AVR32_TC0, 1);
			LED_Off(LED0);
		}

		break;

	case LED1:
		if (brightness != 0) {
			gpio_enable_module_pin(AVR32_TC1_B2_0_PIN,
					AVR32_TC1_B2_0_FUNCTION);
			tc_start(&AVR32_TC1, 2);
			tc_write_rb(&AVR32_TC1, 2, brightness);
		} else {
			tc_stop(&AVR32_TC1, 2);
			LED_Off(LED0);
		}

		break;

	default:
		break;
	}
}

/* End of PWM */
/** @} */

/**
 * \name Display functions
 * @{
 */

static void ui_display_enable(void)
{
	delay_init(sysclk_get_cpu_hz());

	et024006_Init( sysclk_get_cpu_hz(), sysclk_get_hsb_hz());

	/* Clear the display i.e. make it black */
	et024006_DrawFilledRect(0, 0, ET024006_WIDTH, ET024006_HEIGHT, BLACK );

	/* Set the backlight. */
	gpio_set_gpio_pin(ET024006DHU_BL_PIN);

	ui_display_init_rtc();

	ui_display_welcome_msg();
}
コード例 #2
0
ファイル: port.c プロジェクト: spel-uchile/TRX_GOMSPACE
int _init_startup(void)
{
	/* Import the Exception Vector Base Address. */
	extern void _evba;

	#if configHEAP_INIT
		extern void __heap_start__;
		extern void __heap_end__;
		portBASE_TYPE *pxMem;
	#endif

	/* Load the Exception Vector Base Address in the corresponding system register. */
	Set_system_register( AVR32_EVBA, ( int ) &_evba );

    board_init();
    sysclk_init();
    sdramc_init(sysclk_get_hsb_hz());

	/* Enable exceptions. */
	ENABLE_ALL_EXCEPTIONS();

	/* Initialize interrupt handling. */
	INTC_init_interrupts();

	#if configHEAP_INIT

		/* Initialize the heap used by malloc. */
		for( pxMem = &__heap_start__; pxMem < ( portBASE_TYPE * )&__heap_end__; )
		{
			*pxMem++ = 0xA5A5A5A5;
		}

	#endif

	/* Code section present if and only if the debug trace is activated. */
	#if 0 //configDBG
	{
		static const gpio_map_t DBG_USART_GPIO_MAP =
		{
			{ configDBG_USART_RX_PIN, configDBG_USART_RX_FUNCTION },
			{ configDBG_USART_TX_PIN, configDBG_USART_TX_FUNCTION }
		};

		static const usart_options_t DBG_USART_OPTIONS =
		{
			.baudrate = configDBG_USART_BAUDRATE,
			.charlength = 8,
			.paritytype = USART_NO_PARITY,
			.stopbits = USART_1_STOPBIT,
			.channelmode = USART_NORMAL_CHMODE
		};

		/* Initialize the USART used for the debug trace with the configured parameters. */
		extern volatile avr32_usart_t *volatile stdio_usart_base;
		stdio_usart_base = configDBG_USART;
		gpio_enable_module( DBG_USART_GPIO_MAP,
		                    sizeof( DBG_USART_GPIO_MAP ) / sizeof( DBG_USART_GPIO_MAP[0] ) );
		usart_init_rs232(configDBG_USART, &DBG_USART_OPTIONS, configPBA_CLOCK_HZ);
	}
	#endif

  // Don't-care value for GCC.
  return 1;
}
/*-----------------------------------------------------------*/

/*
 * malloc, realloc and free are meant to be called through respectively
 * pvPortMalloc, pvPortRealloc and vPortFree.
 * The latter functions call the former ones from within sections where tasks
 * are suspended, so the latter functions are task-safe. __malloc_lock and
 * __malloc_unlock use the same mechanism to also keep the former functions
 * task-safe as they may be called directly from Newlib's functions.
 * However, all these functions are interrupt-unsafe and SHALL THEREFORE NOT BE
 * CALLED FROM WITHIN AN INTERRUPT, because __malloc_lock and __malloc_unlock do
 * not call portENTER_CRITICAL and portEXIT_CRITICAL in order not to disable
 * interrupts during memory allocation management as this may be a very time-
 * consuming process.
 */

/*
 * Lock routine called by Newlib on malloc / realloc / free entry to guarantee a
 * safe section as memory allocation management uses global data.
 * See the aforementioned details.
 */
void __malloc_lock(struct _reent *ptr);
void __malloc_lock(struct _reent *ptr)
{
	vTaskSuspendAll();
}

/*
 * Unlock routine called by Newlib on malloc / realloc / free exit to guarantee
 * a safe section as memory allocation management uses global data.
 * See the aforementioned details.
 */
void __malloc_unlock(struct _reent *ptr);
void __malloc_unlock(struct _reent *ptr)
{
	xTaskResumeAll();
}
/*-----------------------------------------------------------*/

/* Added as there is no such function in FreeRTOS. */
void *pvPortRealloc( void *pv, size_t xWantedSize )
{
void *pvReturn;

	vTaskSuspendAll();
	{
		pvReturn = realloc( pv, xWantedSize );
	}
	xTaskResumeAll();

	return pvReturn;
}