コード例 #1
0
ファイル: main.c プロジェクト: tkadom/TWBLE
void test_app_init(void)
{
    nrf_gpio_cfg_output(LED_0);
    nrf_gpio_cfg_output(LED_1);

#ifdef BOARD_PCA10000
    nrf_gpio_pin_clear(LED_RGB_RED);
    nrf_gpio_pin_clear(LED_RGB_GREEN);
    nrf_gpio_pin_clear(LED_RGB_BLUE);
#endif

#ifdef BOARD_PCA10031
    nrf_gpio_pin_clear(LED_RGB_RED);
    nrf_gpio_pin_clear(LED_RGB_GREEN);
    nrf_gpio_pin_clear(LED_RGB_BLUE);
#endif

#ifdef BOARD_PCA10001
    nrf_gpio_range_cfg_output(0, 32);
    nrf_gpio_cfg_input(BUTTON_0, BUTTON_PULL);
    nrf_gpio_cfg_input(BUTTON_1, BUTTON_PULL);
    gpiote_init();
#endif

#ifdef BOARD_PCA10031
    nrf_gpio_range_cfg_output(0, 32);
    nrf_gpio_cfg_input(BUTTON_0, BUTTON_PULL);
    nrf_gpio_cfg_input(BUTTON_1, BUTTON_PULL);
    gpiote_init();
#endif

    led_config(1, 0);
    led_config(2, 0);
}
コード例 #2
0
/**
 * \brief Application entry point.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	/* Initialize the SAM3 system */
	SystemInit();

	WDT->WDT_MR = WDT_MR_WDDIS;

	/* Set up SysTick Timer for 1 msec interrupts. */
	if (SysTick_Config(SystemCoreClock / (uint32_t) 1000)) {
		/* Capture error. */
		while (1) {
		}
	}

	led_config();

	/* Flash the LED. */
	while (1) {
		/* Turn on the LED. */
		led_on(LED0_MASK);
		/* Delay  1000 Msec. */
		delay_ms((uint32_t) 1000);

		/* Turn off the LED. */
		led_off(LED0_MASK);
		/* Delay  1000 Msec. */
		delay_ms((uint32_t) 1000);
	}
}
コード例 #3
0
ファイル: led_4_driver.c プロジェクト: kk821521286/kangkai
__init static int led_driver_init (void)
{
	int ret ; 
	dev_t devno = MKDEV (major, minor) ;
	
	ret = register_chrdev_region (devno, MINOR_NR, "led_device") ;
	if (ret) {
		printk (KERN_ALERT"char device num fail!\r\n") ;
		goto err ;
	}
	
	cdev_init (&led_cdev, &led_ops) ;
	ret = cdev_add (&led_cdev, devno, MINOR_NR) ; // mknod /dev/led0 c 249 0 1 2 3
	
	if (ret) {
		printk (KERN_ALERT"CDEV ADD ERROR") ;
		goto err1;
	}

	base = ioremap (0xe03001c0, sizeof (gpg3)) ;
	if (NULL == base) {
		printk (KERN_ALERT"IOREMAP ERR!\r\n") ;
		goto err2;
	}
	led_config () ;

	printk (KERN_ALERT"LED 4 DEVICE DRIVER INSMOD DONE!\n") ; 
	return 0 ; 
err2:
	cdev_del (&led_cdev) ;
err1:
	unregister_chrdev_region (devno, MINOR_NR);
err:
	return ret ;
}
コード例 #4
0
ファイル: main.c プロジェクト: AndreyMostovov/asf
/**
 * \brief Application entry point.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	uint8_t uc_led_bit;

	/* Initialize the SAM3 system */
	SystemInit();

	WDT->WDT_MR = WDT_MR_WDDIS;

	// Set up SysTick Timer for 1 msec interrupts.
	if (SysTick_Config(SystemCoreClock/ 1000)) {
		// Capture error.
		while (1);
	}

	led_config();

	uc_led_bit = (uint8_t) (log10(LED0_MASK) / log10(2));

	// Flash the LED.
	while (1) {
		/* Toggle LED with bit banding. */
		if (*BITBAND_ALIAS_ADDRESS(&LED0_PIO->PIO_ODSR, uc_led_bit)) {
			/* Turn on the LED. */
			*BITBAND_ALIAS_ADDRESS(&LED0_PIO->PIO_CODR, uc_led_bit) = 1;
		} else {
			/* Turn off the LED. */
			*BITBAND_ALIAS_ADDRESS(&LED0_PIO->PIO_SODR, uc_led_bit) = 1;
		}

		delay_ms(1000);
	}
}
コード例 #5
0
ファイル: main.c プロジェクト: Arcko/trochili
/*!
    \brief      main function
    \param[in]  none
    \param[out] none
    \retval     none
*/
int main(void)
{
    can_parameter_struct            can_init_parameter;
    can_filter_parameter_struct     can_filter_parameter;

    receive_flag = RESET;
    /* configure Tamper key */
    gd_eval_keyinit(KEY_TAMPER, KEY_MODE_GPIO);
    /* configure GPIO */
    gpio_config();
    /* configure USART */
    gd_eval_COMinit(EVAL_COM2);
    /* configure NVIC */
    nvic_config();
    /* configure leds */
    led_config();
    /* set all leds off */
    gd_eval_ledoff(LED1);
    gd_eval_ledoff(LED2);
    gd_eval_ledoff(LED3);
    gd_eval_ledoff(LED4);
    /* initialize CAN */
    can_networking_init(can_init_parameter, can_filter_parameter);
    /* enable phy */
#ifdef CAN0_USED 
    can_phy_enable(CANX);
#endif
    /* enable CAN receive FIFO0 not empty interrupt */
    can_interrupt_enable(CANX, CAN_INTEN_RFNEIE0);
    
    /* initialize transmit message */
    transmit_message.can_tx_sfid = 0x321;
    transmit_message.can_tx_efid = 0x01;
    transmit_message.can_tx_ft = CAN_FT_DATA;
    transmit_message.can_tx_ff = CAN_FF_STANDARD;
    transmit_message.can_tx_dlen = 1;
    printf("please press the Tamper key to transmit data!\r\n");
    while(1){
        /* waiting for the Tamper key pressed */
        while(0 == gd_eval_keygetstate(KEY_TAMPER)){
            /* if transmit_number is 0x10, set it to 0x00 */
            if(transmit_number == 0x10){
                transmit_number = 0x00;
            }else{
                transmit_message.can_tx_data[0] = transmit_number++;
                printf("transmit data: %x\r\n", transmit_message.can_tx_data[0]);
                /* transmit message */
                can_transmit_message(CANX, &transmit_message);
                delay();
                /* waiting for Tamper key up */
                while(0 == gd_eval_keygetstate(KEY_TAMPER));
            }
        }
        if(SET == receive_flag){
            gd_eval_ledtoggle(LED1);
            receive_flag = RESET;
            printf("recive data: %x\r\n", receive_message.can_rx_data[0]);
        }
    } 
}
コード例 #6
0
int main(){
	int ledState=0;
	led_config();
	timer2_config();
	
	while(1){
		led_output(ledState);
		timer2_delay_ms(500);
		ledState=(ledState==0)?1:0;
	}
}
コード例 #7
0
/**
 * \brief Application entry point.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	uint8_t uc_key;

	/* Initialize the SAM3 system */
	SystemInit();
	board_init();

	WDT->WDT_MR = WDT_MR_WDDIS;

	/* Initialize the console uart */
	configure_console();

	/* Output example information */
	puts(STRING_HEADER);

	/* configure LED. */
	led_config();

	/* configure push buttons. */
	configure_buttons();

	/* Set default priorities for 2 buttons. */
	puts("Set INT1's priority higher than INT2.\r");
	set_interrupt_priority(INT_PRIOR_HIGH, INT_PRIOR_LOW);

	/* Display the main menu. */
	display_menu();

	// Flash the LED.
	while (1) {
		while (uart_read(CONSOLE_UART, &uc_key));

		switch (uc_key) {
		case '1':
			set_interrupt_priority(INT_PRIOR_LOW, INT_PRIOR_HIGH);
			puts("Set INT2's priority higher than INT1.\n\r\r");
			break;

		case '2':
			set_interrupt_priority(INT_PRIOR_HIGH, INT_PRIOR_LOW);
			puts("Set INT1's priority higher than INT2.\n\r\r");
			break;

		case 'h':
			display_menu();
			break;

		default:
			puts("Invalid input.\r");
			break;
		}
	}
}
コード例 #8
0
ファイル: main.c プロジェクト: tkadom/TWBLE
/**
* @brief Initialize GPIO pins, for LEDs and debugging
*/
void gpio_init(void)
{
#ifdef BOARD_PCA10028
    nrf_gpio_cfg_output(LED_1);
    nrf_gpio_cfg_output(LED_2);

  #ifdef BUTTONS
    nrf_gpio_cfg_input(BUTTON_1, NRF_GPIO_PIN_PULLUP);
    nrf_gpio_cfg_input(BUTTON_2, NRF_GPIO_PIN_PULLUP);
    nrf_gpio_cfg_input(BUTTON_3, NRF_GPIO_PIN_PULLUP);
    nrf_gpio_cfg_input(BUTTON_4, NRF_GPIO_PIN_PULLUP);
  #endif
#endif
#ifdef BOARD_PCA10031
    nrf_gpio_cfg_output(LED_RGB_RED);
    nrf_gpio_cfg_output(LED_RGB_GREEN);
    nrf_gpio_cfg_output(LED_RGB_BLUE);

    nrf_gpio_pin_set(LED_RGB_RED);
    nrf_gpio_pin_set(LED_RGB_GREEN);
    nrf_gpio_pin_set(LED_RGB_BLUE);
#endif

#ifdef BOARD_PCA10000
    nrf_gpio_cfg_output(LED_RGB_RED);
    nrf_gpio_cfg_output(LED_RGB_GREEN);
    nrf_gpio_cfg_output(LED_RGB_BLUE);

    nrf_gpio_pin_set(LED_RGB_RED);
    nrf_gpio_pin_set(LED_RGB_GREEN);
    nrf_gpio_pin_set(LED_RGB_BLUE);
#endif

#ifdef BOARD_PCA10001 
    nrf_gpio_range_cfg_output(0, 32);
#endif

    led_config(1, 0);
    led_config(2, 0);
}
コード例 #9
0
ファイル: startup.c プロジェクト: aspirefhaha/ad7606_stm32107
/**
 * This function will startup RT-Thread RTOS.
 */
void rtthread_startup(void)
{
    /* init board */
    rt_hw_board_init();

    /* show version */
    rt_show_version();

    /* init tick */
    rt_system_tick_init();

    /* init kernel object */
    rt_system_object_init();

    /* init timer system */
    rt_system_timer_init();

#ifdef RT_USING_HEAP
    rt_system_heap_init((void*)STM32_SRAM_BEGIN, (void*)STM32_SRAM_END);
#endif

    /* init scheduler system */
    rt_system_scheduler_init();

#ifdef RT_USING_AD7606
	ad7606_init();
#endif		 
#ifdef RT_USING_M3AD
	m3ad_init();
#endif
	led_config();
	led_turn_off_all();
	iepe_init();
	skf_init();
    /* init all device */
    rt_device_init_all();

    /* init application */
    rt_application_init();

    /* init timer thread */
    rt_system_timer_thread_init();

    /* init idle thread */
    rt_thread_idle_init();

    /* start scheduler */
    rt_system_scheduler_start();

    /* never reach here */
    return ;
}
コード例 #10
0
static void startup_task()
{
	//RCC_ClocksTypeDef rcc_clocks;
	//RCC_GetClocksFreq(&rcc_clocks);
	//SysTick_Config(rcc_clocks.HCLK_Frequency / OS_TICKS_PER_SEC);
	led_config();
	OS_CPU_SysTickInit();
	OSTaskCreate(task1, (void *)0, &task1_stk[TASK1_STK_SIZE - 1], 7);
	OSTaskCreate(task2, (void *)0, &task2_stk[TASK2_STK_SIZE - 1], 6);
	
	
	
	//OSTaskDel(OS_PRIO_SELF);
}
コード例 #11
0
/**
* @brief Initialize GPIO pins, for LEDs and debugging
*/
void gpio_init(void)
{   

#ifdef BOARD_PCA10028
    nrf_gpio_cfg_output(LED_2);
#else
    nrf_gpio_cfg_output(LED_0);
#endif
    nrf_gpio_cfg_output(LED_1);  
    
#ifdef BOARD_PCA10000
    nrf_gpio_cfg_output(LED_RGB_BLUE);  
    nrf_gpio_pin_set(LED_RGB_RED);
    nrf_gpio_pin_set(LED_RGB_GREEN);
    nrf_gpio_pin_set(LED_RGB_BLUE);
#endif

#ifdef BOARD_PCA10001 
    nrf_gpio_range_cfg_output(0, 32);
#endif    

    led_config(1, 0);
    led_config(2, 0);
}
コード例 #12
0
ファイル: main.c プロジェクト: tkadom/TWBLE
void GPIOTE_IRQHandler(void)
{
    NRF_GPIOTE->EVENTS_PORT = 0;
    for (uint8_t i = 0; i < 2; ++i)
    {
        if (NRF_GPIO->IN & (1 << (BUTTON_0 + i)))
        {
            uint8_t val[28];
            uint16_t len;
            APP_ERROR_CHECK(rbc_mesh_value_get(i + 1, val, &len, NULL));
            val[0] = !val[0];
            led_config(i + 1, val[0]);
            APP_ERROR_CHECK(rbc_mesh_value_set(i + 1, &val[0], 1));
        }
    }

}
コード例 #13
0
ファイル: main.c プロジェクト: Arcko/trochili
/*!
    \brief      main function
    \param[in]  none
    \param[out] none
    \retval     none
*/
int main(void)
{	  
    /* systick config */
    systick_config();
    /* led config */
    led_config();
    /* clock enable */
    rcu_periph_clock_enable(RCU_PMU);
    /* wakeup key config */
    gd_eval_keyinit(KEY_WAKEUP,KEY_MODE_GPIO);
    /* tamper key EXTI config */
    gd_eval_keyinit(KEY_TAMPER,KEY_MODE_EXTI);
    /* press wakeup key to enter deepsleep mode and use tamper key generate a exti interrupt to wakeup mcu */
    while(1){
        if(RESET == gpio_input_bit_get(WAKEUP_KEY_GPIO_PORT,WAKEUP_KEY_PIN))
            pmu_to_deepsleepmode(PMU_LDO_LOWPOWER,WFI_CMD);
    }
}
コード例 #14
0
ファイル: main.c プロジェクト: tkadom/TWBLE
/**
* @brief RBC_MESH framework event handler. Defined in rbc_mesh.h. Handles
*   events coming from the mesh. Sets LEDs according to data
*
* @param[in] evt RBC event propagated from framework
*/
void rbc_mesh_event_handler(rbc_mesh_event_t* evt)
{
    TICK_PIN(28);
    switch (evt->event_type)
    {
        case RBC_MESH_EVENT_TYPE_CONFLICTING_VAL:
        case RBC_MESH_EVENT_TYPE_NEW_VAL:
        case RBC_MESH_EVENT_TYPE_UPDATE_VAL:

            if (evt->value_handle > 2)
                break;

            led_config(evt->value_handle, evt->data[0]);
            break;
        default:
            break;
    }
}
コード例 #15
0
ファイル: main.c プロジェクト: Arcko/trochili
/*!
    \brief      main function
    \param[in]  none
    \param[out] none
    \retval     none
*/
int main(void)
{
    SysTick_Config(72000000/1000);
    
    /* configure leds */
    led_config();

    /* configure CMP0 and CMP1 */
    cmp_config();
    
    /* configure CMP0 and CMP1 */
    check_state();
    
    while(1)
    {
        /* input voltage is over the thresholds: higher and lower thresholds */
        if(STATE_OVER_THRESHOLD == check_state()){
            gd_eval_ledon(LED1);
            gd_eval_ledoff(LED2);
            gd_eval_ledon(LED3);
            gd_eval_ledoff(LED4);
        }
        /* input voltage is within the thresholds: higher and lower thresholds */
        if(STATE_WITHIN_THRESHOLD == check_state()){
            delay_ms(500);
            if(STATE_WITHIN_THRESHOLD == check_state()){
                gd_eval_ledoff(LED1);
                gd_eval_ledoff(LED2);
                gd_eval_ledoff(LED3);
                gd_eval_ledoff(LED4);
                /* enter deepsleep mode */
                deepsleep_mode_config();
            }
        }
        /* input voltage is under the thresholds: higher and lower thresholds */
        if(STATE_UNDER_THRESHOLD == check_state()){
            gd_eval_ledoff(LED1);
            gd_eval_ledon(LED2);
            gd_eval_ledoff(LED3);
            gd_eval_ledon(LED4);
        }
    }
}
コード例 #16
0
ファイル: hello_driver.c プロジェクト: kk821521286/kangkai
__init static int hello_driver_init (void)
{
	int ret ; 
	dev_t devno = MKDEV (major, minor) ;
	//
	ret = register_chrdev_region (devno, MINOR_NR, "hello_device") ;
	if (ret) {
		printk (KERN_ALERT"char device num fail!\r\n") ;
		goto err ;
	}
	
#if 0
	for (i = 0; i < MINOR_NR; i++) {
		cdev_init (&hello_cdev[i], &hello_ops) ; // hello_ops -> cdev->ops
		ret = cdev_add (&hello_cdev[i], devno + i, 1) ;
	}
#endif
	cdev_init (&hello_cdev, &hello_ops) ;
	ret = cdev_add (&hello_cdev, devno, MINOR_NR) ;

#if 1
	if (ret) {
		printk (KERN_ALERT"CDEV ADD ERROR") ;
		goto err1;
	}
#endif

	base = ioremap (0xe03001c0, sizeof (gpg3)) ;
	if (NULL == base) {
		printk (KERN_ALERT"IOREMAP ERR!\r\n") ;
		goto err2;
	}
	led_config () ;

	return 0 ;
err2:
	cdev_del (&hello_cdev) ;
err1:
	unregister_chrdev_region (devno, MINOR_NR);
err:
	return ret ;
}
コード例 #17
0
/**
* @brief RBC_MESH framework event handler. Defined in rbc_mesh.h. Handles
*   events coming from the mesh. Sets LEDs according to data
*
* @param[in] evt RBC event propagated from framework
*/
void rbc_mesh_event_handler(rbc_mesh_event_t* evt)
{
    TICK_PIN(28);
    switch (evt->event_type)
    {
        case RBC_MESH_EVENT_TYPE_CONFLICTING_VAL:   
        case RBC_MESH_EVENT_TYPE_NEW_VAL:
        case RBC_MESH_EVENT_TYPE_UPDATE_VAL:
        
            if (evt->value_handle > 2)
                break;
            
            led_config(evt->value_handle, evt->data[0]);
            break;
        case RBC_MESH_EVENT_TYPE_INITIALIZED:
            /* init BLE gateway softdevice application: */
            nrf_adv_conn_init();
            break;  
    }
}
コード例 #18
0
ファイル: main.c プロジェクト: Arcko/trochili
/*!
    \brief      main function
    \param[in]  none
    \param[out] none
    \retval     none
*/
int main(void)
{
    /* clock enable */
    rcu_periph_clock_enable(RCU_PMU);
    /* led configuration and turn on all led */
    led_config();
    gd_eval_ledon(LED1);
    gd_eval_ledon(LED3);
    gd_eval_ledon(LED2);
    gd_eval_ledon(LED4);
    /* tamper key configuration */
    gd_eval_keyinit(KEY_TAMPER,KEY_MODE_GPIO);
    /* wakeup pin enable */
    pmu_wakeup_pin_enable(PMU_WAKEUP_PIN0);
    /* press tamper key to enter standby mode and use wakeup key to wakeup mcu */
    while(1){
        if(RESET == gpio_input_bit_get(TAMPER_KEY_GPIO_PORT,TAMPER_KEY_PIN))
            pmu_to_stdbymode(WFI_CMD);
    }

}
コード例 #19
0
ファイル: kitt.c プロジェクト: built/kitt
void configure_LEDs()
{
    for (int i = 0; i < LED_COUNT; i++) led_config(i + FIRST_LED);
}
コード例 #20
0
ファイル: main.c プロジェクト: Arcko/trochili
/*!
    \brief      main function
    \param[in]  none
    \param[out] none
    \retval     none
*/
int main(void)
{
    int i = 0;
    dma_parameter_struct dma_init_struct;
    /* enable DMA clock */
    rcu_periph_clock_enable(RCU_DMA);
    /* initialize LED */
    led_config();
    /* all LED off */
    gd_eval_ledoff(LED1);
    gd_eval_ledoff(LED3);
    gd_eval_ledoff(LED2);
    gd_eval_ledoff(LED4);
    /* initialize DMA channel1 */
    dma_deinit(DMA_CH1);
    dma_init_struct.direction = DMA_PERIPHERA_TO_MEMORY;
    dma_init_struct.memory_addr = (uint32_t)destination_address1;
    dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
    dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT;
    dma_init_struct.number = DATANUM;
    dma_init_struct.periph_addr = (uint32_t)source_address;
    dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_ENABLE;
    dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT;
    dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH;
    dma_init(DMA_CH1,dma_init_struct);
    /* configure DMA mode */
    dma_circulation_disable(DMA_CH1);
    dma_memory_to_memory_enable(DMA_CH1);
        
    /* initialize DMA channel2 */
    dma_deinit(DMA_CH2);
    dma_init_struct.memory_addr = (uint32_t)destination_address2;
    dma_init(DMA_CH2,dma_init_struct);
    /* configure DMA mode */
    dma_circulation_disable(DMA_CH2);
    dma_memory_to_memory_enable(DMA_CH2);
        
    /* initialize DMA channel3 */
    dma_deinit(DMA_CH3);
    dma_init_struct.memory_addr = (uint32_t)destination_address3;
    dma_init(DMA_CH3,dma_init_struct);
    /* configure DMA mode */
    dma_circulation_disable(DMA_CH3);
    dma_memory_to_memory_enable(DMA_CH3);
        
    /* initialize DMA channel4 */
    dma_deinit(DMA_CH4);
    dma_init_struct.memory_addr = (uint32_t)destination_address4;
    dma_init(DMA_CH4,dma_init_struct);
    /* configure DMA mode */
    dma_circulation_disable(DMA_CH4);
    dma_memory_to_memory_enable(DMA_CH4);

    /* enable DMA channel1~channel4 */
    dma_channel_enable(DMA_CH1);
    dma_channel_enable(DMA_CH2);
    dma_channel_enable(DMA_CH3);
    dma_channel_enable(DMA_CH4);

    /* wait for DMA transfer complete */
    for(i = 0; i < 200; i++);
    /* compare the data of source_address with data of destination_address */
    transferflag1 = memory_compare(source_address, destination_address1, DATANUM);
    transferflag2 = memory_compare(source_address, destination_address2, DATANUM);
    transferflag3 = memory_compare(source_address, destination_address3, DATANUM);
    transferflag4 = memory_compare(source_address, destination_address4, DATANUM);

    /* if DMA channel1 transfer success,light LED1 */
    if(SUCCESS == transferflag1){
        gd_eval_ledon(LED1);
    }
    /* if DMA channel2 transfer success,light LED2 */
    if(SUCCESS == transferflag2){
        gd_eval_ledon(LED2);
    }
    /* if DMA channel3 transfer success,light LED3 */
    if(SUCCESS == transferflag3){
        gd_eval_ledon(LED3);
    }
    /* if DMA channel4 transfer success,light LED4 */
    if(SUCCESS == transferflag4){
        gd_eval_ledon(LED4);
    }
    
    while (1);
}
コード例 #21
0
ファイル: main.c プロジェクト: Arcko/trochili
/*!
    \brief      main function
    \param[in]  none
    \param[out] none
    \retval     none
*/
int main(void)
{
    int i=0;

    /* TSI peripheral and GPIOB periph clock enable */
    rcu_periph_clock_enable(RCU_GPIOB);
    rcu_periph_clock_enable(RCU_TSI);

    /* PB0   TSI_CHCFG_G2P1     SAMPCAP
       PB1   TSI_CHCFG_G2P2     CHANNEL
       PB2   TSI_CHCFG_G2P3     CHANNEL */

    /* configure the GPIO ports */
    gpio_config();

    /* configure the TSI peripheral */
    tsi_config();

    /* configure the LED */
    led_config();

    /* reference cycle value acquisition and processing */
    for(i=0;i<20;i++){
        /* get charge transfer complete cycle number of group2 pin2 */
        tsi_transfer_pin(TSI_CHCFG_G2P2);
        
        /* check the TSI flag:end of acquisition interrupt */
        if(tsi_interrupt_flag_get(TSI_INTF_CTCF) == (uint8_t)SET){
            /* get charge transfer complete cycle number */
            sample_refnum_array2[i] = tsi_group2_cycle_get();
        }

        /* disable the selected pin as channel pin:pin2 */
        tsi_channel_pin_disable(TSI_CHCFG_G2P2);

        /* get charge transfer complete cycle number of group2 pin3 */
        tsi_transfer_pin(TSI_CHCFG_G2P3);
        if(tsi_interrupt_flag_get(TSI_INTF_CTCF) == (uint8_t)SET){
            sample_refnum_array3[i] = tsi_group2_cycle_get();
        }
        tsi_channel_pin_disable(TSI_CHCFG_G2P3);
        /* delay for a period of time while all banks have been acquired */
        delay(0xFFFF);
    }

    /* sum of sample_refnum_array */
    for(i=1;i<20;i++){
        sample_refnum[0] += sample_refnum_array2[i];
        sample_refnum[1] += sample_refnum_array3[i];
    }

    /* average channel cycle value are obtained */
    sample_refnum[0] = sample_refnum[0]/19;
    sample_refnum[1] = sample_refnum[1]/19;

    while (1){
        /* acquisition group2 pin2 */
        tsi_transfer_pin(TSI_CHCFG_G2P2);
     
        /* check the TSI flag end of acquisition interrupt */
        if(tsi_interrupt_flag_get(TSI_INTF_CTCF) == (uint8_t)SET){
            /* get charge transfer complete cycle number */
            samplenum[0] = tsi_group2_cycle_get();
        }

        /* light LED1 */
        if((sample_refnum[0]-samplenum[0]) > THRESHOLD1){
            /* group2 pin2 is touched */
            gd_eval_ledon(LED1);
        }else{
            gd_eval_ledoff(LED1);
        }
        tsi_channel_pin_disable(TSI_CHCFG_G2P2);

        /* acquisition group2 pin3 */
        tsi_transfer_pin(TSI_CHCFG_G2P3);
        if(tsi_interrupt_flag_get(TSI_INTF_CTCF) == (uint8_t)SET){
            samplenum[1] = tsi_group2_cycle_get();
        }

        /* light LED2 */
        if((sample_refnum[1]-samplenum[1]) > THRESHOLD2){
            /* group2 pin3 is touched */
            gd_eval_ledon(LED2);
        }else{
            gd_eval_ledoff(LED2);
        }
        tsi_channel_pin_disable(TSI_CHCFG_G2P3);

        /* delay for a period of time while all banks have been acquired */
        delay(0xFFFF);
    }
}
コード例 #22
0
/**
 * \brief Application entry point.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	uint8_t uc_key;

	/* Initialize the SAM4 system */
	sysclk_init();
	board_init();

	WDT->WDT_MR = WDT_MR_WDDIS;

	/* Enable the pmc clocks of the push buttons for all SAM4. */
	pmc_enable_periph_clk(ID_PIOA);
	pmc_enable_periph_clk(ID_PIOB);
	pmc_enable_periph_clk(ID_PIOC);

	/* Initialize the console uart */
	configure_console();

	/* Output example information */
	puts(STRING_HEADER);

	/* PIO configuration for LEDs and Buttons. */
	pio_handler_set_priority(PIOA, PIOA_IRQn, 0);
	pio_handler_set_priority(PIOB, PIOB_IRQn, 0);
	pio_handler_set_priority(PIOC, PIOC_IRQn, 0);

	/* configure LED. */
	led_config();

	/* configure push buttons. */
	configure_buttons();

	/* Set default priorities for 2 buttons. */
	puts("Set INT1's priority higher than INT2.\r");
	set_interrupt_priority(INT_PRIOR_HIGH, INT_PRIOR_LOW);

	/* Display the main menu. */
	display_menu();

	// Flash the LED.
	while (1) {
		while (uart_read(CONSOLE_UART, &uc_key));

		switch (uc_key) {
		case '1':
			set_interrupt_priority(INT_PRIOR_LOW, INT_PRIOR_HIGH);
			puts("Set INT2's priority higher than INT1.\n\r\r");
			break;

		case '2':
			set_interrupt_priority(INT_PRIOR_HIGH, INT_PRIOR_LOW);
			puts("Set INT1's priority higher than INT2.\n\r\r");
			break;

		case 'h':
			display_menu();
			break;

		default:
			puts("Invalid input.\r");
			break;
		}
	}
}