示例#1
0
/** @brief The main top level init
 *
 * The main init function to be called from main.c before entering the main
 * loop. This function is simply a delegator to the finer grained special
 * purpose init functions.
 */
void init(){
	ATOMIC_START();         /* Disable ALL interrupts while we configure the board ready for use */
	initPLL();              /* Set up the PLL and use it */
	initGPIO();
	initPWM();
	initADC();
	initAllPagedRAM();      /* Copy table and config blocks of data from flash to the paged RAM blocks for fast data lookup */
	initVariables();        /* Initialise the rest of the running variables etc */
	initFlash();            /* TODO, finalise this */
	initECTTimer();         /* TODO move this to inside config in an organised way. Set up the timer module and its various aspects */
//	initPITTimer();         /* TODO ditto... */
	initSCIStuff();         /* Setup the sci module(s) that we will use. */
	initConfiguration();    /* TODO Set user/feature/config up here! */
#ifdef XGATE
	initXgate();            /* Fred is a legend, for good reason as of now */
#endif
	initInterrupts();       /* still last, reset timers, enable interrupts here TODO move this to inside config in an organised way. Set up the rest of the individual interrupts */
	ATOMIC_END();           /* Re-enable any configured interrupts */
}
/* GPS */
static void usart_device_init_2(size_t bits, size_t parity,
                                size_t stopBits, size_t baud)
{
        volatile struct usart_info* ui = usart_data + UART_GPS;

        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

        initGPIO(GPIOD, (GPIO_Pin_5 | GPIO_Pin_6));
        GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_USART2);
        GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_USART2);

        init_usart(ui->usart, bits, parity, stopBits, baud);
        /* No TX DMA here becasue I2C is using that stream */
        enableRxTxIrq(ui->usart, USART2_IRQn, UART_GPS_IRQ_PRIORITY,
                      UART_TX_IRQ);

        enable_dma_rx(RCC_AHB1Periph_DMA1, DMA1_Stream5_IRQn,
                      DMA_IRQ_PRIORITY, DMA_IT_TC | DMA_IT_HT, ui);
}
/* Auxilary port */
static void usart_device_init_1(size_t bits, size_t parity,
                                size_t stopBits, size_t baud)
{
        volatile struct usart_info* ui = usart_data + UART_AUX;

        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

        initGPIO(GPIOD, (GPIO_Pin_8 | GPIO_Pin_9));
        GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_USART3);
        GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_USART3);

        init_usart(ui->usart, bits, parity, stopBits, baud);

        enable_dma_rx(RCC_AHB1Periph_DMA1, DMA1_Stream1_IRQn,
                      DMA_IRQ_PRIORITY, DMA_IT_TC | DMA_IT_HT, ui);

        enable_dma_tx(RCC_AHB1Periph_DMA1, DMA1_Stream3_IRQn,
                      DMA_IRQ_PRIORITY, DMA_IT_TC, ui);
}
示例#4
0
//*****************************************************************************
// Main
//*****************************************************************************
void main (void)
{
    // Stop watchdog timer
    WDT_A_hold( WDT_A_BASE );

    // Initialize GPIO
    initGPIO();

    // Initialize clocks
    initClocks();

    // Initialize timers
    initTimers();

    __bis_SR_register( GIE );         // Enable interrupts globally

    while(1) {
        __no_operation();             // Placeholder for while loop (not required)
    }
}
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  /* Initialize chip */
  CHIP_Init();

  SegmentLCD_Init(true);

  initRTC();
  initGPIO();

  /* Initial LCD content */
  SegmentLCD_Number(time);

  while (1)
  {
    /* Go to EM2 */
    EMU_EnterEM2(true);
    /* Wait for interrupts */
  }
}
示例#6
0
文件: ch_lcd.c 项目: sergyegorov/CUG
void LCDInit(int line_size){
		LineSize = 20;
		CurStr = 0;
		CurX = 0;
		KeyTime = 0;
		RepeatTime = REPEAT_TIME;
		Key = 0;
		initGPIO();
		RS_Off;
		RS_On;
		setData(0xFF);
		RS_Off;
		RS_On;
		_LCDSendCommand(0x38); // 8-bit,double string,5x8
	    delay_us(1000);//for(i = 0;i<1000 MULT;i++);
	    _LCDSendCommand(0b1100); // Display on
	    delay_us(1000);//for(i = 0;i<1000 MULT;i++);
	    _LCDSendCommand(1); // Reset
	    _LCDSendCommand(0x6); // Increment cursor to 1
	}
/* Cellular */
static void usart_device_init_3(size_t bits, size_t parity,
                                size_t stopBits, size_t baud)
{
        volatile struct usart_info* ui = usart_data + UART_TELEMETRY;

        RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

        initGPIO(GPIOA, (GPIO_Pin_0 | GPIO_Pin_1));
        GPIO_PinAFConfig(GPIOA, GPIO_PinSource0, GPIO_AF_UART4);
        GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_UART4);

        init_usart(ui->usart, bits, parity, stopBits, baud);

        enable_dma_rx(RCC_AHB1Periph_DMA1, DMA1_Stream2_IRQn,
                      DMA_IRQ_PRIORITY, DMA_IT_TC | DMA_IT_HT, ui);

        enable_dma_tx(RCC_AHB1Periph_DMA1, DMA1_Stream4_IRQn,
                      DMA_IRQ_PRIORITY, DMA_IT_TC, ui);
}
/* Bluetooth */
static void usart_device_init_0(size_t bits, size_t parity,
                                size_t stopBits, size_t baud)
{
        volatile struct usart_info* ui = usart_data + UART_WIRELESS;

        RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

        initGPIO(GPIOA, (GPIO_Pin_9 | GPIO_Pin_10));
        GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);
        GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);

        init_usart(ui->usart, bits, parity, stopBits, baud);

        enable_dma_rx(RCC_AHB1Periph_DMA2, DMA2_Stream5_IRQn,
                      DMA_IRQ_PRIORITY, DMA_IT_TC | DMA_IT_HT, ui);

        enable_dma_tx(RCC_AHB1Periph_DMA1, DMA2_Stream7_IRQn,
                      DMA_IRQ_PRIORITY, DMA_IT_TC, ui);

}
示例#9
0
static void initSPI(void) {

  SPI_InitTypeDef  SPI_InitStructure;

  initGPIO();

  /* Set up SPI in bi-directional mode */
  SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;
  SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
  SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
  SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
  SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;

  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
  SPI_InitStructure.SPI_CRCPolynomial = 7;
  SPI_Init(SWD_SPI, &SPI_InitStructure);

  SPI_Cmd(SWD_SPI, ENABLE);
}
示例#10
0
文件: main.c 项目: Veli-Matti/hw1gpio
int main(int argc, char **argv)
{
	printf("myGPIP main called!\n");
	int err = local_init();
	
	if (!err) {
	
		// init GPIO 17 as output
		initGPIO(gpio_direction_output, 17);
	
		// ...and start toggling
		while(1) {
			setGPIO(17, 1);
			sleep(1);
		
			setGPIO(17, 0);
			sleep(1);
		}
	}
	
	return 0;
}
示例#11
0
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  CHIP_Init();

  // initializations
  initGPIO();
  /* Enable LCD without voltage boost */
  SegmentLCD_Init(false);
  setupSWOForPrint();

  updateLCD(getCapsenseCurrent());

  while (1)
  {
    updateGPIO();
    if (getCapsensePrevious() != getCapsenseCurrent())
    {
      updateLCD(getCapsenseCurrent());
      updateSWO();
    }
  }
}
示例#12
0
int main(){
	u8 res;
	initRCC();
	initGPIO();
	initTIM2();
	initUSART3();
	initI2C1();

	__enable_irq();                       // глобальное включение прерывания

	// I2C1_tx(0xD0,0x6B,0x00);
	// I2C1_tx(0xD0,0x1B,0xE0);
	// I2C1_tx(0xD0,0x1C,0xE0);
	read_I2C1(GY521_ADRESS,WHO_I_AM);
	// read_data_acc();
	green_on();
	while(1){
	    while(!number_of_tasks)
	        {}
	    (*buffer_of_tasks[head_of_tasks])();
	    deleteTask();
	    }
	return 0;
}
示例#13
0
//int main()
void initStepper(void)
{
		initGPIO();								//initialize GPIO ports 0-3
		initMotor();							//initialize stepper motors
		MYTIMER_init();							//initialize mytimer (hardware timer)

		//MYTIMER_setOverflowVal(T1_FREQ);
		//MYTIMER_setCompareVal(10000); // 75% duty cycle

		MYTIMER_enable_overflowInt();			//enable overflow interrupts
		//MYTIMER_enable_compareInt();
		//MYTIMER_enable_allInterrupts();

		NVIC_EnableIRQ(Fabric_IRQn);			//enable fabric interrupt

		MYTIMER_enable();						//start hardware timer


		//Fastest seen: 100 accel, 23 speed, 2000000 Tclk
		//move(step,accel,decel,speed);			//move motor based on function call


		return;
}
static void CAN_device_init_2(int baud)
{
    CAN_DeInit(CAN2);

    /* CAN GPIOs configuration ************************************************* */
    /* Enable GPIO clock */
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

    /* Connect CAN pins to Alternate Function */
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource12, GPIO_AF_CAN2);
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_CAN2);
    initGPIO(GPIOB, GPIO_Pin_12 | GPIO_Pin_13);

    /* CAN configuration ******************************************************* */
    /* Enable CAN clock */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN2, ENABLE);

    initCAN(CAN2, baud);

    /* Enable FIFO 0 message pending Interrupt */
    CAN_ITConfig(CAN2, CAN_IT_FMP1, ENABLE);

    initCANInterrupts(CAN2, CAN2_RX1_IRQn);
}
示例#15
0
文件: main.c 项目: blaezec/stm32f4
/**
* @brief  Main program.
* @param  None
* @retval None
*/
int main(void)
{
    uint8_t currentLED=0,idx;
    uint16_t xx,yy;
    uint16_t testWord; 
    uint8_t shifter=0;

  /* Initialize LEDs on STM32F4-Discovery --------------------*/

    __IO uint32_t i = 0;  
    uint8_t buf[255];
    uint8_t len;
    STM_EVAL_LEDInit(LED4);
    STM_EVAL_LEDInit(LED3);
    // You can use these for LEDs if you use the upper 8 bits of the 16b FSMC bus to talk to the ILI9238.
    // STM_EVAL_LEDInit(LED5); //GPIOD 14 -> FSMC D0. Do not use for LED, we need them to talk to the ILI9238
    // STM_EVAL_LEDInit(LED6); //GPIOD 14 -> FSMC D1.

   

    // flash the LEDs in a circle to test delayMillis(uint32_t timedelay)

     STM_EVAL_LEDToggle(currentLED);

    for (idx=0;idx<8;idx++)
    {
        STM_EVAL_LEDToggle(currentLED);
        currentLED=(currentLED+1)%2;
        STM_EVAL_LEDToggle(currentLED);
        delayMillis(250);
    }
    // 
    // USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb);

    // init the printf
    init_printf(0,tft_putc);
    // init_tft_printf(NULL,tft_putc);

    // Get the 32F4 ready to talk to the TFTLCD using FSMC
    initGPIO();
    initFSMC();
    uDelay(1000); // probably don't need this
    reset();
    initDisplay();

    // ** Do the adafruit Demo **
    // fillScreen(BLACK);
    //     setCursor(0, 0);
    //     setTextColor(CYAN);
    //     setTextSize(1);
    //     setRotation(1); 
    //     tft_printf("Please connect to virtual COM port...");
    delayMillis(2000);
    testlines(CYAN);
    delayMillis(2500);
    testfastlines(RED, BLUE);
    delayMillis(2500);
    testdrawrects(GREEN);
    delayMillis(2500);
    testfillrects(YELLOW, MAGENTA);
    delayMillis(2500);
    fillScreen(BLACK);
    testfillcircles(10, MAGENTA);
    testdrawcircles(10, WHITE);
    delayMillis(2500); 
    testtriangles();
    delayMillis(2500); 
    testfilltriangles();
    delayMillis(2500); 
    testRoundRect();
    delayMillis(2500); 
    testFillRoundRect();
    delayMillis(2500); 
    fillScreen(GREEN);
    delayMillis(2500); 
    
    
    // fsmcData        =  0x60020000; // sets a16
    // fsmcRegister    =  0x60000000; // clears a16
    // printf("fsmcData:\t0x%08X\r\n",fsmcData);
    // printf("fsmcRegister:\t0x%08X\r\n",fsmcRegister);

    // fillScreen(BLACK);
    // setCursor(0, 20);
    // setTextColor(color);
    // setTextSize(1);
    // write("Hello World!");
    // setTextSize(2);
    // write(1234.56);
    // setTextSize(3);
    // 
    // println(0xDEADBEEF, HEX);


    // printf("0xFF00>>8 0x%04X\r\n",0xff00>>8);
    // VCP_send_str(&buf[0]);
    // printf("SysTick_Config(SystemCoreClock/1000)\t %d\r\n",SysTick_Config(SystemCoreClock/1000));
    // millisecondCounter=0;
    // for (idx=0;idx<100;idx++)
    // {
    //     printf("millisecondCounter:\t%d",millisecondCounter);
    // }
    // void delayMillis(uint32_t millis) 
    //     {
    //         uint32_t target;
    // 
    //         target=millisecondCounter+millis;
    //         while(millisecondCounter<target);
    //     }

   
    // From stm32f4_discovery.h:
    // typedef enum 
    // {
    // LED4 = 0,
    // LED3 = 1,
    // LED5 = 2,
    // LED6 = 3
    // } Led_TypeDef;
    while(1)
    {
        for (idx=0;idx<8;idx++)
        {
            setRotation(idx%4); 
            testtext(RED);
            delayMillis(1500); 
        }

    }

}
示例#16
0
文件: main_WiLi.c 项目: edesvin/WiLi
void main (void) {
	
	T_UWORD luw_i;
	T_UBYTE lub_CountIndice = 0;
	
	initModesAndClock(); 								/* Initialize mode entries and system clock */
	
	INTC_InstallINTCInterruptHandler(isr,59,1);
	INTC.CPR.R = 0;
	
	initGPIO();

	initPIT(ValTMR_0, ValTMR_1);
	
	while (1) {
		
		if(rub_FlagValUpAut || rub_FlagValUpMan){
			if(rub_Fled){
				rub_Fled = 0;
				SIU.GPDO[lub_CountIndice].B.PDO = 1;
				SIU.GPDO[10].B.PDO = 0;
				SIU.GPDO[11].B.PDO = 1;
				lub_CountIndice++;
				if(lub_CountIndice >= 10){
					lub_CountIndice = 10;
					rub_FlagValUpAut = 0;
					rub_FValAutUP = 0;
				}
			}
		}
/******************************************************************************/
		else if(rub_FlagValDownAut || rub_FlagValDownMan){
			if(rub_Fled){
				rub_Fled = 0;
				if(lub_CountIndice <= 1) {
					lub_CountIndice = 1;
					rub_FlagValDownAut = 0;
					rub_FValAutDown = 0;
					SIU.GPDO[11].B.PDO = 1;
				}
				SIU.GPDO[lub_CountIndice-1].B.PDO = 0;
				SIU.GPDO[10].B.PDO = 1;
				SIU.GPDO[11].B.PDO = 0;
				lub_CountIndice--;
				
				if(lub_CountIndice == 0 && rub_FlagValAnPi){
					SIU.GPDO[11].B.PDO = 1;
					PIT.CH[1].TCTRL.B.TEN = 0;
					PIT.CH[1].TCTRL.B.TEN = 1;
					PIT.CH[1].LDVAL.R = ValTMR_1;
					PIT.CH[1].TFLG.B.TIF = 1;
					rub_FlagValAnPi = 0;
					while(!PIT.CH[1].TFLG.B.TIF);
					PIT.CH[1].TFLG.B.TIF = 1;
					rub_Fled = 0;
					rub_FlagValDownAut = 0;
					rub_FlagValDownMan = 0;
					rub_FlagValUpAut = 0;
					rub_FlagValUpMan = 0;
					rub_FValAutDown = 0;
					rub_FValAutUP = 0;
				}
				
			}
		}
		////////////////////////////////////////////////
		else if(!rub_FlagValUpAut && !rub_FlagValUpMan && !rub_FlagValDownAut && !rub_FlagValDownMan){
			rub_Fled = 0;
			SIU.GPDO[10].B.PDO = 1;
			SIU.GPDO[11].B.PDO = 1;
		}
	}
}
示例#17
0
// Main function
void main(void) {
	reset_peripheral(); initClock(); initTimer(); initDisplay(); initPin();
	initGPIO(); initADC(); initConsole(); int i = 0;
	//init_password();
	send_data();

	initCircBuf (&speed_buffer, BUF_SIZE); init_set_speed_data(&speed_set_data);

	int screen = 0; int screen_prev = 0; float speed = 0; float buffed_speed = 0;
	int fake_speed = 0; float acc = 0; float max_acc = 0; //float fuel_eco = 0;
	float distance = 0;

	bool fix = 0; uint8_t satillite = 0; float quality = 0; clock time;
	int aim_pos = 0; unsigned long adc = 0; //int error_stepper = 0;

	IntMasterEnable();

	while(1){
		//reading data
		read_data = split_data(UART_char_data_old, read_data); 	// decode data
		speed = read_speed();									//read data into variables
		adc = run_adc()/7;

		//calculations
		aim_pos = speed_feedback(buffed_speed, encoder_1/40, speed_set_data.speed);
		if (speed_set_data.enable == 1){
			step_motor_control(encoder_1/40, aim_pos);
		}

		//sending fake data
		fake_speed = (int)adc;//= random_at_most(100/1.852);
		send_info(fake_speed);//knots

		//storing data
		store_speed(speed);
		buffed_speed = analysis_speed();
		acc = read_acceleration(buffed_speed);
		max_acc = max_acc_func(acc, max_acc);
		time = read_time();
		satillite = read_satillite();
		fix = read_fix();
		quality = read_quality();
		debounce_button();										// debounce buttons
		screen = read_button_screen(screen, fix);
		distance = read_distance();
		select_read();											//need a mosfet for turning power off
																// select adds a an on and off switch yo

		if (screen == 1){
			if(screen_prev != 1 && screen == 1){
				speed_set_data.speed = buffed_speed;
			}
			speed_set_data.speed = set_speed(speed_set_data.speed);					// set the speed to cruise at
		}
		if (screen == 2){ //0 to 100
			acceleration_test(speed);
		}
		// refresh chainging
		if (fix == 1 && speed_set_data.old == speed_set_data.speed && refresh_rate < 4){
			UARTSend((unsigned char *)PMTK_SET_NMEA_UPDATE_5HZ, 18, 0);
			refresh_rate += 1;
		}
		if (i >= 50){
			display(screen, buffed_speed, acc, max_acc, speed_set_data.speed, satillite,
					encoder_1/40, time, distance, quality, UART_char_data_old, aim_pos, adc, acc_times);
			i = 0;
		}
		screen_prev = screen;
		i++;
	}
}
示例#18
0
RemoteTransmitter::RemoteTransmitter(unsigned int periodusec, unsigned short repeats) {
	_periodusec=periodusec;
	_repeats=repeats;

	initGPIO();
}
示例#19
0
void initSR() {
	initGPIO(SERIAL_SR_DATA);
	initGPIO(SERIAL_SR_LATCH);
	initGPIO(SERIAL_SR_CLK);
}
示例#20
0
void *startDisplayThread(void *args)
{
    int n,col,row;
    struct timespec sleepTime = { 0, 5000000 };
    struct timespec onTime =    { 0,  200000 };
    uint32_t *pixelData; 

    initGPIO();

    buildGreyCode();

    // Set up buffer pointers.
    PixelsF = Pixels1;
    PixelsB = Pixels2;

    // Set row bits to zero to start with.
    ClearBits( 15 << ROWA);
    row = 0;

    while(displayRunning)
    {

	// Cycle through the rows in a grey code order to minimise changes on address lines.
	// Changing the address lines seems to a part of the cause of the ghosting problems.
	if(greyCodeSet[row])
	{
	    SetBits(greyCodeChange[row] << ROWA);   // Set a bit for the current row 
	}
	else
	{
	    ClearBits(greyCodeChange[row] << ROWA);   // Clear a bit for the current row 
	}

	settleTime(5);
	// Clock one rows worth of pixels into the display
	pixelData = &PixelsF[32*greyCode[row]];
	for(col=0;col<32;col++)
	{
	    ClearBits(pixelClkMask);  // Clk low
	    settleTime(5);
	    SetBits(*pixelData++ & pixelMask);
	    settleTime(5);
	    SetBits(1<<CLK);          // Clk high
	    settleTime(5);
	}

	SetBits(1<<STB);   // Strobe
	//settleTime(5);
	ClearBits(1<<STB);
	settleTime(50);
	ClearBits(1<<OE);  // turn display on	
	nanosleep(&onTime, NULL);   // Fixed on time 
	SetBits(1<<OE);     // turn off the display
	settleTime(5);

	row += 1;
	row &= 15;
#if 1
	// Pause at the end of the frame
	if(row == 0)
	{
	    SetBits(1<<OE);
	    nanosleep(&sleepTime, NULL);
	}
#endif
    }
    // Make sure display is off when we exit the thread
    SetBits(1<<OE);


}
示例#21
0
int main()
{
    int socketServeur;
    int socketClient = -1;
	int clientConnecte = 0;
    int i;
	int ecrit = 0;
	int lu = -1;
	int speed = 500;
	int stopCount = 0;
	int distance = 0;
	int distance_32bits = 0;
    struct sockaddr_in addrServeur;
    socklen_t longueurAdresse; // Nombre d'octets de la structure sockaddr_in
    char nomDuClient[1024], portDuClient[32];
	char commande = 'X';
	char clientONOFF = 'o';
	pthread_t thread1;
	pthread_t thread2;
	
	// Initialisation des GPIO
	initGPIO();
	
	// Initialisation Mutex
	if(pthread_mutex_init(&lock, NULL) != 0)
	{
		perror("mutex");
		exit(-1);
		
	}

    pthread_create(&thread1, NULL, thread_distance, &socketClient);
	pthread_create(&thread2, NULL, thread_speed, &socketClient);
    printf("creation du thread1 et 2\n");
	
    // Cree un socket de communication
	socketServeur = socket(PF_INET, SOCK_STREAM, 0);
    if(socketServeur == -1)
    {
        perror("Socket");
        exit(-1);
    }

    printf("Socket crée avec succès ! (%d)\n", socketServeur);

    addrServeur.sin_addr.s_addr = INADDR_ANY; //toutes
    addrServeur.sin_family = PF_INET;
    addrServeur.sin_port = htons(PORT);
	
	// lose the pesky "Address already in use" error message
	int yes = 1;
	if( setsockopt(socketServeur, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1 ) 
	{
		perror("setsockopt");
		exit(errno);
	}

    // Demande l'attachement local de la socket
    longueurAdresse = sizeof(addrServeur);
    if( bind(socketServeur, (struct sockaddr *)&addrServeur, longueurAdresse) == -1 )
    {
        perror("bind");
        exit(-2);
    }
    printf("Socket attachée avec succès!\n");

    if (listen(socketServeur, CLIENT_MAX) == -1)
    {
        perror("listen");
        exit(errno);
    }
    printf("Socket placée en écoute passive...\n");

	printf("Attente d'une demande de connexion (quitter avec Cltrl-C)\n\n");
		
    while(1)
    {       
		if(clientConnecte == 0)
		{
			socketClient = accept4(socketServeur, (struct sockaddr *)&addrServeur, &longueurAdresse, SOCK_NONBLOCK);
			
			if(socketClient == -1 )
			{
				printf("errno : %d\n", errno);
				perror("accept");
				close(socketClient);
				close(socketServeur);
				exit(errno);
			}
			
			printf("Nouveau client !\n");

			if ( getnameinfo((struct sockaddr*)&addrServeur, sizeof(addrServeur), nomDuClient, sizeof(nomDuClient), portDuClient,
						   sizeof(portDuClient), NI_NUMERICHOST | NI_NUMERICSERV) == 0)
			{
				   printf("client=%s, port=%s\n", nomDuClient, portDuClient);
			}
			
			clientConnecte = 1;
			//ecrits = write(socketClient, &clientONOFF, 1);
		}
		
		
		// nanosleep((struct timespec[]){{0, 10000000}}, NULL);
		lu = read(socketClient, &commande, 1);
		
		if(lu == -1)
		{
			if(errno == EAGAIN) // Nothing to read
			{
				continue;
			}
			else
			{
				printf("Error reading from socketClient ! \n");
				printf("errno = %d \n", errno);
				break;
			}
		}
		
		if(lu == 0)
		{
			printf("Socket closed ! \n");
			speed = 500;
			avancer(0);
			commande = 's';
			close(socketClient);
			clientConnecte = 0;
			continue;
		}
		
		printf("lu = %d\n", lu);
		printf("commande = %c\n", commande);
		
		switch(commande)
		{
			case 'a' :
				//printf("AVANCE\n");
				avancer(speed);
				break;
			case 'r' :
				//printf("RECULE\n");
				reculer(speed);
				break;
			case 'd' :
				//printf("DROITE\n");
				tourner(DROITE, speed);
				break;
			case 'g' :
				//printf("GAUCHE\n");
				tourner(GAUCHE, speed);
				break;
			case '+' :
				speed = speedChange(UP, speed);
				break;
			case '-' :
				speed = speedChange(DOWN, speed);
				break;
			case 's' :
				//printf("REPOS\n");
				avancer(0);
		}
		
		//distance = ultrason();
    }
	
	close(socketClient);
	close(socketServeur);
	
	return 0;
}
示例#22
0
// main loop
int main(void){
	
	uint8_t stateDS18=DS18B20_STATUS_READY;
	
	#ifdef USE_WDT
	WDT_init(WDTO_8S); 
	#endif
	
	
	initGPIO();
	LCD_init();
	
	showLcdSplash();
		
	setLcdInitialFields();
		
	paramLoadFromEeprom();
		
	USART1_config(USART1_MY_UBBRN,USART_DATA_FORMAT_8BITS|USART_STOP_BITS_1,USART_TRANSMIT_ENABLE|USART_RECEIVE_ENABLE| USART_INTERRUPT_ENABLE);
	
	USART1_sendStr("Hello");
	
	schedulerInit();
	
	// check for the default values
	#ifdef USE_WDT
	WDT_init(WDTO_8S);
	#endif
	
	
	sei(); //enable interrups
	
	// loop while	
    while(1){
		
		
		// cintrol zone
		if(flagTaskControl){
			#ifdef USE_WDT
			WDT_reset();
			#endif
			
			
			LED_RUN_OFF;
			// fire the DS
			if(stateDS18==DS18B20_STATUS_READY){
				DS18B20_startConv();
				stateDS18=DS18B20_STATUS_CONV;
			
			// check if convertion ended	
			}else if(stateDS18==DS18B20_STATUS_CONV){
				if(DS18B20_convComplete()){
					stateDS18=DS18B20_STATUS_END_CONV;
				}
			
			// convertion ready	
			}else if (stateDS18==DS18B20_STATUS_END_CONV){
				LED_RUN_ON;
				currentTemp=DS18B20_getTemp();
				stateDS18=DS18B20_STATUS_READY;
				
				currentStatus = checkTempError(currentTemp,currentTempSetPoint,currentHistSetPoint); // chec the out
				setOutputRelay(currentStatus);
				_delay_ms(50);
				LED_RUN_OFF;
					
				
			}
			
			flagTaskControl=0;
		}
		
		// user bottons area
		if(flagTaskReadButtons){
			#ifdef USE_WDT
			WDT_reset();
			#endif
			
			uint8_t portVal = readButtons();
			uint8_t code = decodeButton(portVal);
			code = debounceKey(code);
			
			#ifdef MAIN_DEBUG
			sprintf(debugBuffer,"Key %d",code);
			USART1_sendStr(debugBuffer);
			#endif
			
			stateMachine(code); // go to machine
			
			flagTaskReadButtons=0;
		}
		
		 
		 // lcd update area
		 if(flagTaskUpdateLcd){
			 #ifdef USE_WDT
			 WDT_reset();
			 #endif
			 //showLcdSavedMessage();
			 updateLcd(); // update the lcd
			 
			 flagTaskUpdateLcd=0;
		 }
		 
		 // save to eeprom
		 if(flagSaveParametersEeprom){
			 #ifdef USE_WDT
			 WDT_reset();
			 #endif
			 
			 paramSavetoEeprom(); // save value sto eeprom
			 showLcdSavedMessage();
			 setLcdInitialFields();
			 updateLcd();
			 flagSaveParametersEeprom=0;
		 }
		 
    }
}
示例#23
0
//***** Main Function *********************************************************
void main (void)
{
	uint16_t i = 0;
	uint16_t val = 0;
	uint16_t loc = 0;
	uint16_t status = 0;

    // Stop watchdog timer
    WDT_A_hold( WDT_A_BASE );

    // Initialize GPIO
    initGPIO();

    if ( erase != 0 )                                  // This lets you easily erase the flash by changing the value
    	erase_infoB();                                 // of the "erase" variable before reaching this point in the code

    if ( fill != 0 )                                   // This lets you easily fill the flash by changing the value
    	fill_infoB();                                  // of the "fill" variable before reaching this point in the code

    if (count[ 0 ] == 0xffff )
    {
    	val = 1;
    	loc = 0;
    }
    else if ( count[ NUMBER_OF_WORDS-1 ] != 0xFFFF )
    {
    	val = count[ NUMBER_OF_WORDS-1 ];
    	erase_infoB();
    	loc = 0;
    }
    else
    {
    	for ( i = 1; i < NUMBER_OF_WORDS-2; i++ )
    	{
    		if ( count[ i ] == 0xffff )
    		{
    			val = count[ i - 1 ];
    			val++;
    			loc = i;
    			break;
    		}
    	}
    }

	status = write_infoB_location( val, loc );
	if ( status == 0 )
		while( 1 );

    // Inform the programmer how many times the board has been power-on reset
    //   which isn't possible without some form of non-volaile memory
printf( "This program has been power cycled %d times\n", val );

    // Flash the LED 'count' number of times ... this way you can 'see' how many
    //   times a power-on reset has occured, even if you can't read the printf()
    for ( i = 0; i < val; i++ )
    {
        // Turn on LED
        GPIO_setOutputHighOnPin( GPIO_PORT_P1, GPIO_PIN0 );

        // Wait about a second
        __delay_cycles( ONE_SECOND );

        // Turn off LED
        GPIO_setOutputLowOnPin( GPIO_PORT_P1, GPIO_PIN0 );

        // Wait another second
        __delay_cycles( HALF_SECOND );
    }

    // Trap program here
    while(1);
}
示例#24
0
int main () {

	CHIP_Init();				//Initialize Chip

	initMCU();
	initGPIO();				//Initialize GPIO
	sdi2c_Init();				//Initialize I2C
	initTimer();		//initialize timer for timer interuprt

	/* Setup SysTick Timer for 10 msec interrupts  */
	if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) {
	while (1) ;
	}

	/*Enable all sensors and GPS */
	GPIO_PinOutSet(GPS_PORT, ENABLE);			//Enable GPS Sensor board
	BMP180_GetCalData();		//Enable and get calibration data from BMP180
	initLSM303_LowPower();		//Enable Accel in low power mode
	initL3GD20H_Normal();			//Enable Gyro in normal mode
	GPIO_PinOutToggle(EXT_LED, YEL_LED);

	/* Acceleromter Data */
	Delay(10);
	LSM303_GetAccelData();
	LSM303_PowerOff();
	GPIO_PinOutToggle(EXT_LED, YEL_LED);

	/*Gyroscope Data */
	Delay(10);
	L3GD20H_GetGyroData();
	L3GD20H_PowerOff();
	GPIO_PinOutToggle(EXT_LED, YEL_LED);

	/*Temperature/Barometric Pressure */
	Delay(10);
	BMP180_GetTemp();
	BMP180_GetPressure();
	BMP180_CalcRealTemperature();
	BMP180_CalcRealPressure();
	GPIO_PinOutToggle(EXT_LED, YEL_LED);

	/*Power Sensor*/
	INA219_GetVoltage();
	GPIO_PinOutClear(EXT_LED, YEL_LED);

	GPIO_PinOutToggle(EXT_LED, GRE_LED);
	Delay(100);
	GPIO_PinOutToggle(EXT_LED, GRE_LED);


	/* GPS Information */
	timeout = 0;		//reset timeout
	initGPS();		//Initialize GPS UART
	coldrestart();		//Send cold restart command
	while(fullread == 0) {		//while not a full read, do the following
		if(satfix == 1) {			//if there is a satellite fix, then...
			GPIO_PinOutSet(EXT_LED, YEL_LED);		//toggle LED for debug
			readdata();		//readdata
			timeout = 0;
		}
		if(timeout > 20) {
			GPIO_PinOutClear(EXT_LED, YEL_LED);
			GPStimeout();
			break;
		}
	}

	GPIO_PinOutSet(EXT_LED, GRE_LED);
	Delay(500);

	printGPS(0);		//Print GPS to screen for debug

	concact();


	/* Infinite loop */
	while(1) {
	  if(GPIO_PinInGet(BUT_PORT, RIGHT_BUT) == 0) {
		  r = r + 1;
		  if(r > 2) {		//wrap around to beginning
			  r = 0;
		  }
		  printGPS(r);
	  }
	  if(GPIO_PinInGet(BUT_PORT, LEFT_BUT) == 0) {
			  r = r - 1;
			  if(r < 0) {		//wrap around to beginning
				  r = 2;
			  }
			  printSENSORS();
		  }
//	  if(GPIO_PinInGet(GPS_PORT, FIX) == 1) {
//		  GPIO_PinOutToggle(EXT_LED, RED_LED);
//	  }
	}
}
示例#25
0
文件: usb.cpp 项目: Tilka/epsilon
void init() {
  initGPIO();
  initOTG();
}
示例#26
0
int main(){
//    unsigned int us_start, t0, t1, t2, t3;
//    float x, y, theta;
//    float x2, y2, theta2;
//    float x3, y3, theta3;
//    float beta;
//    point pt;
//    int i=0;
//    float check;

	// For IMU
/*	double tab_acc[3] = {0.0, 0.0, 0.0},
		   tab_gyro[3] = {0.0, 0.0, 0.0},
		   tab_magn[3] = {0.0, 0.0, 0.0};
	int i;
*/


    pthread_t pthread_prop,
              pthread_gpio,
              pthread_led,
              pthread_com;
              



    //gpio init
		initGPIO(GREEN_LED);
		initGPIO(ORANGE_LED);
		initGPIO(WRNG_RED_LED);
		initGPIO(RED_LED_BIC);
		initGPIO(GREEN_LED_BIC);
		initGPIO(BP_STOP);


    idFicI2C = openI2C(FILE_I2C);
    setI2C(ADDR_MD25, idFicI2C);
    
    //Create a thread for prop
    if(pthread_create(&pthread_prop, NULL, threadProp, NULL)!=0){
         printf("ERROR; return code from pthread_create()\n");
         getchar();
         exit(-1);
        }

    //Create a thread control gpio
    if(pthread_create(&pthread_gpio, NULL, threadGpio, NULL)!=0){
         printf("ERROR; return code from pthread_create()\n");
         getchar();
         exit(-1);
        }
        
    //Create a thread control gpio
    if(pthread_create(&pthread_led, NULL, threadLed, NULL)!=0){
         printf("ERROR; return code from pthread_create()\n");
         getchar();
         exit(-1);
        }

    //Create a thread for  com
    if(pthread_create(&pthread_com, NULL, thread_Com, NULL)!=0){ //&sargThreadSttRover
         printf("ERROR; return code from pthread_create()\n");
         getchar();
         exit(-1);
    }
        


//	mpu_init();

	while(1){

	/*	mpu_read(tab_acc, tab_gyro, tab_magn);
		printf("\n");
		for(i=0; i<3; i++) printf("tab_acc[%d] = %.2lf\n", i, tab_acc[i]);
		printf("\n");
		for(i=0; i<3; i++) printf("tab_gyro[%d] = %.2lf\n", i, tab_gyro[i]);
		printf("\n");
		for(i=0; i<3; i++) printf("tab_magn[%d] = %.2lf\n", i,  tab_magn[i]);
		printf("\n\n");

		printf("Distance = %d\n\n", sonar_get_distance_cm());
	*/	
		// Update Info Rover
		float x, y, theta;
		int  dist;
		#ifdef I2C_OK
		pos3(&x, &y, &theta);
		volt = getBatVolt();
		pthread_mutex_lock(&mtx_distSonar);
		distSonar = sonar_get_distance_cm();
		dist = distSonar;
		pthread_mutex_unlock(&mtx_distSonar);
		printf("distSonar = %d\n", dist);
		#else
		x = 0, y = 0, theta = 0;
		bat = 15;
		dist = 1000;
		#endif
		
		//printf("x = %.2f; y  %.2f; theta = %.2f; bat = %.2f; dist = %d\n", x, y , theta, bat, dist);
		updateInfoRover(&argThreadSttRover, &x, &y, &theta, &volt, &dist);
/*		printf("argThreadSttRover.sinf.bat = %d\n"
		       "argThreadSttRover.sinf.son = %.2f\n"
		       "argThreadSttRover.sinf.pos.x = %.2f\n"
		       "argThreadSttRover.sinf.pos.y = %.2f\n"
		       "argThreadSttRover.sinf.ang = %.2f\n\n", (int32_t)argThreadSttRover.sinf.bat, argThreadSttRover.sinf.son, argThreadSttRover.sinf.pos.x, argThreadSttRover.sinf.pos.y, argThreadSttRover.sinf.ang);    
*/
	}





//old test
/* //trajectoire
    while(1){
        usleep(10000);
        nd1 = dist(1);
        nd2 = dist(2);
        pos3(&x3, &y3, &theta3);

        beta=trajCorr(x3, y3, theta3, 500, 500);
        printf("%.2f, %.2f, %.2f°, beta=%f\n", x3, y3, theta3, beta*180./M_PI);
        move(100, beta*180./M_PI);
        if(((fabs(x3-500.)<10.) && (fabs(y3-500.)<10.)))
            {
            move(0,0);
            printf("fin\n");
            return 1;
            }
        }
*/




/*
        while(1){
        usleep(10000);
    us_start = micros();
        nd1 = dist(1);
    t0 = micros() - us_start;
        nd2 = dist(2);

    us_start = micros();
        pos(&x, &y, &theta);
    t1 = micros() - us_start;

    us_start = micros();
        pos2(&x2, &y2, &theta2);
    t2 = micros() - us_start;

    us_start = micros();
        pos3(&x3, &y3, &theta3);
    t3 = micros() - us_start;

    //printf("%u,%u,%u,%u\n", t0, t1, t2, t3);

    printf("%.2f, %.2f, %.2f°, %.2f, %.2f, %.2f°, %.2f, %.2f, %.2f°\n", x, y, theta*180./M_PI, x2, y2, theta2*180./M_PI, x3, y3, theta3*180./M_PI);

    }
   // move(1000,0,idFicI2C);



    sleep(1);




    move(0,0,idFicI2C);
    sleep(1);
    printf("d=%f\n",dist(0));
*/

/*   close(idFicI2C);
    printf("Fermeture du bus i2c\n");
*/
    return 0;
    }