示例#1
0
/*******************************************************************************
* Function Name  : Target_Init
* Description    : STM32各个模块初始化
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void Target_Init(void)
{  
    RCC_Configuration();
    GPIO_config();
    NVIC_Configuration();
    TIM_Init();
    Init_PWM(3600);
    //USART1_Configuration();
    //USART2_Configuration();
    //USART3_Configuration();
    //I2C1_Configuration();
}
示例#2
0
文件: main.c 项目: ddidiy/STC15_LIB
void main(void)
{
    TMOD = (TMOD & 0XF0) | 0X01;
    TL0 = 0x0;
    TH0 = 0x0;
    TR0 = 1;
    ET0 = 1;
    GPIO_config();
    UART1_config();
		EA = 1;
    printf("Hello! World\r\n");
    OSStart();
}
示例#3
0
文件: gpio.c 项目: gefa/CC1101
void gpioInit()
{
	//--------------NOTE------------------
	//	FOR GPIOs TO WORK ON C6713 DSK SPECTRUM DIGITAL BOARD
	//	SWITCH 4 OF THE DIPSWITCH SW3 (NOT SW1!!!) HAS TO BE ON-CLOSED
	//--------------NOTE------------------

	GPIO_Config gpio_config = {
	0x00000000, /* gpgc */
	0x0000FFFF, /* gpen --*/
	0x00000000, /* gdir -*/
	0x00000000, /* gpval */
	0x00000000, /* gphm all interrupts disabled for io pins */
	0x00000000, /* gplm all interrupts to cpu or edma disabled  */
	0x00000000  /* gppol -- default state */
	};

	hGpio  = GPIO_open( GPIO_DEV0, GPIO_OPEN_RESET );

	GPIO_config(hGpio  , &gpio_config );

	/* Enables pins */
	GPIO_pinEnable (hGpio,
			GPIO_PIN0 |
			GPIO_PIN1 |
			GPIO_PIN2 |
			GPIO_PIN3 |
			GPIO_PIN4 |
			GPIO_PIN5 |
			GPIO_PIN6 |
			GPIO_PIN7 |
			GPIO_PIN8 |
			GPIO_PIN9 |
			GPIO_PIN13);//enable here or in MyConfig

	GPIO_pinDirection(hGpio,GPIO_PIN0, GPIO_OUTPUT);	// CS
	GPIO_pinDirection(hGpio,GPIO_PIN1, GPIO_OUTPUT);
	GPIO_pinDirection(hGpio,GPIO_PIN2, GPIO_OUTPUT);
	GPIO_pinDirection(hGpio,GPIO_PIN3, GPIO_OUTPUT);	// MOSI
	GPIO_pinDirection(hGpio,GPIO_PIN13, GPIO_OUTPUT);	// SCK

	GPIO_pinDirection(hGpio,GPIO_PIN8, GPIO_INPUT);	// MISO
	GPIO_pinDirection(hGpio,GPIO_PIN9, GPIO_INPUT);	// GDO0


}
示例#4
0
文件: main.c 项目: westonb/ionophoney
int main(){

	
	
	Delay_init(8928); //1ms period
	GPIO_config();
	led_on();
	RF_config();
	ADC_config();
	SMPS_config();
	RF_enable();
	
	int i = 0;
	while(1){
		//code goes here
		i++;
		//led_on();
		//led_off();

	}


	return 0;
}
/**
 * Initalize the GPIO unit for the leds
 */
void initLeds(void)
{
    GPIO_init(&g_gpio0, COREGPIO_IN_BASE_ADDR, GPIO_APB_32_BITS_BUS);

    // DIP Switches
    GPIO_config(&g_gpio0, GPIO_0, GPIO_INPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_1, GPIO_INPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_2, GPIO_INPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_3, GPIO_INPUT_MODE);

    // Buttons
    GPIO_config(&g_gpio0, GPIO_4, GPIO_INPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_5, GPIO_INPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_6, GPIO_INPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_7, GPIO_INPUT_MODE);

    // LEDs
    GPIO_config(&g_gpio0, GPIO_8, GPIO_OUTPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_9, GPIO_OUTPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_10, GPIO_OUTPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_11, GPIO_OUTPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_12, GPIO_OUTPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_13, GPIO_OUTPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_14, GPIO_OUTPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_15, GPIO_OUTPUT_MODE);

    GPIO_set_outputs(&g_gpio0, 0xFF00);
    led_state = 0;
}
/**
 *  \brief  Tests the configuration of the CSL GPIO module
 *
 *  This function configures the CSL GPIO module using GPIO_config API.
 *  Configured values are verified by reading back using the CSL function
 *  GPIO_getConfig.
 *
 *  \param  none
 *
 *  \return Test result
 */
int gpio_pin_config_test(void)
{
    CSL_Status        status;
    CSL_GpioConfig    config;
	CSL_GpioConfig    getConfig;

    /* Pin Muxing for GPIO Pins
     * Make Serial port 0 and 1 parallel port 8 pin
     * and A15 to A20 pin as GPIO
     */
	CSL_FINST(CSL_SYSCTRL_REGS->EBSR, SYS_EBSR_SP0MODE, MODE2);
    CSL_FINST(CSL_SYSCTRL_REGS->EBSR, SYS_EBSR_SP1MODE, MODE2);
	CSL_FINST(CSL_SYSCTRL_REGS->EBSR, SYS_EBSR_PPMODE, MODE1);
	CSL_FINST(CSL_SYSCTRL_REGS->EBSR, SYS_EBSR_A20_MODE, MODE1);
	CSL_FINST(CSL_SYSCTRL_REGS->EBSR, SYS_EBSR_A19_MODE, MODE1);
	CSL_FINST(CSL_SYSCTRL_REGS->EBSR, SYS_EBSR_A18_MODE, MODE1);
	CSL_FINST(CSL_SYSCTRL_REGS->EBSR, SYS_EBSR_A17_MODE, MODE1);
	CSL_FINST(CSL_SYSCTRL_REGS->EBSR, SYS_EBSR_A16_MODE, MODE1);
	CSL_FINST(CSL_SYSCTRL_REGS->EBSR, SYS_EBSR_A15_MODE, MODE1);

	/* Open GPIO module */
    hGpio = GPIO_open(&gpioObj, &status);
    if(NULL == hGpio || CSL_SOK != status)
    {
        printf("GPIO_open failed\n");
        return(CSL_TEST_FAILED);
    }
	else
	{
		printf("GPIO_open Successful\n");
	}

    /* Reset all the pins */
    GPIO_reset(hGpio);

    /* Configure the GPIO module */
    config.GPIODIRL     = 0xffff;
    config.GPIODIRH     = 0x07e3;
    config.GPIOINTENAL  = 0x0000;
    config.GPIOINTENAH  = 0x0000;
	config.GPIOINTTRIGL = 0x0000;
	config.GPIOINTTRIGH = 0x0000;

    status = GPIO_config(hGpio, &config);
    if(CSL_SOK != status)
    {
        printf("GPIO_config failed\n");
        return(CSL_TEST_FAILED);
    }
	else
	{
		printf("GPIO_config Successful\n");
	}

	/* Read the configured values */
    status = GPIO_getConfig(hGpio, &getConfig);
    if(CSL_SOK != status)
    {
        printf("GPIO_getConfig failed\n");
        return CSL_TEST_FAILED;
    }
	else
	{
		printf("GPIO_getConfig Successful\n");
	}

	/* Compare the configuration values */
	if((getConfig.GPIODIRL != config.GPIODIRL)         ||
	   (getConfig.GPIODIRH != config.GPIODIRH)         ||
	   (getConfig.GPIOINTENAL != config.GPIOINTENAL)   ||
	   (getConfig.GPIOINTENAH != config.GPIOINTENAH)   ||
	   (getConfig.GPIOINTTRIGL != config.GPIOINTTRIGL) ||
	   (getConfig.GPIOINTTRIGH != config.GPIOINTTRIGH))
	{
		printf("Configuration Comparison Failed\n");
   /////INSTRUMENTATION FOR BATCH TESTING -- Part 2 --
   /////  Reseting PaSs_StAtE to 0 if error detected here.
        PaSs_StAtE = 0x0000; // Was intialized to 1 at declaration.
   /////
	}
	else
	{
		printf("Configuration Comparison Successful\n");
	}

    /* Close the GPIO module */
    status = GPIO_close(hGpio);
    if(CSL_SOK != status)
    {
        printf("GPIO_close failed\n");
        return(CSL_TEST_FAILED);
    }

    return(CSL_TEST_PASSED);
}
示例#7
0
文件: main.c 项目: kisieel/cFOF
int main()
{
	uint32_t data1, data2;
	
	SYS_TICK_init();
	
	data1 = SYS_TICK_timeOut(0,0);
	while (SYS_TICK_timeOut(1, data1) < 1000);
	
	// Keep power supply
	RCC->AHBENR |= RCC_AHBENR_GPIOAEN;            // Clock for GPIOA
	GPIO_config(0x0A, 3, GPIO_MODE_GP, GPIO_PULL_Floating, GPIO_TYPE_Pushpull, GPIO_SPEED_400k, 0);	
	GPIO_config(0x0A, 7, GPIO_MODE_GP, GPIO_PULL_Floating, GPIO_TYPE_Pushpull, GPIO_SPEED_400k, 0);
	Power3VOn;
	Power5VOn;
	
	KEY_init();
	MENU_init();
	USART_init();
	
#ifdef USART_debug
	USART_send("Peripherals initialized.\n");
#endif
	
	RFM69W_init();
	_BUZZER_init();
	_LED_init();
	_LED_off();

#ifdef USART_debug
	USART_send("External devices initialized.\n");
#endif


	// Block device while the power button is still pressed
	while(GPIOA->IDR & GPIO_IDR_IDR_0);

	_BUZZER_alarm_set_vol_list(2);
	_BUZZER_alarm_set_tone_list(2);
	_BUZZER_alarm_set_tempo_list(2);

	for(;;) {
		_actual->menu_fun(GetKeys());
		
		// Holding key for GoUpTime will make menu to go up, to level 0
		if (GPIOA->IDR & GPIO_IDR_IDR_2) {
			data2 = SYS_TICK_timeOut(0, 0);
			while (GPIOA->IDR & GPIO_IDR_IDR_2) {
				// Keep blinking
				if (_actual == _Syg_1_menu || _actual->par == _Syg_1_menu)
					_LED_blink_on(MENU_LED_SYG1);
				if (_actual == _Syg_2_menu || _actual->par == _Syg_2_menu)
					_LED_blink_on(MENU_LED_SYG2);
				if (_actual == _Syg_3_menu || _actual->par == _Syg_3_menu)
					_LED_blink_on(MENU_LED_SYG3);
				if (_actual == _Syg_4_menu || _actual->par == _Syg_4_menu)
					_LED_blink_on(MENU_LED_SYG4);
				
				if (SYS_TICK_timeOut(1, data2) > GoUpTime) {
					_LED_set_color(MENU_LED_Menu, 0, 0, 0);
					_LED_on();
	#ifdef USART_debug
					USART_send("Going up to level 0.\n");
	#endif
					_actual = _actual->par;
			}
		}
	}
		
		// Holding key for TurnOffTime will make device to turn off
		if (GPIOA->IDR & GPIO_IDR_IDR_0) {
			data1 = SYS_TICK_timeOut(0, 0);
			while (GPIOA->IDR & GPIO_IDR_IDR_0) {
				// Keep blinking
				if (_actual == _Syg_1_menu || _actual->par == _Syg_1_menu)
					_LED_blink_on(MENU_LED_SYG1);
				if (_actual == _Syg_2_menu || _actual->par == _Syg_2_menu)
					_LED_blink_on(MENU_LED_SYG2);
				if (_actual == _Syg_3_menu || _actual->par == _Syg_3_menu)
					_LED_blink_on(MENU_LED_SYG3);
				if (_actual == _Syg_4_menu || _actual->par == _Syg_4_menu)
					_LED_blink_on(MENU_LED_SYG4);
				
				if (SYS_TICK_timeOut(1, data1) > TurnOffTime) {
					_LED_off();
#ifdef USART_debug
					USART_send("Power off detected. System backed up. Switching off.\n");
#endif
					Power3VOff;
					Power5VOff;
					// Preventing from further code execution
					for (;;);
				}
			}
		}
	}
}