コード例 #1
0
ファイル: main.c プロジェクト: 8bitgeek/bacnet-stack
int main(
    void)
{
    struct itimer Blink_Timer;

    /*At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
    led_init();
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
        RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE,
        ENABLE);
    timer_init();
    lse_init();
    led_init();
    rs485_init();
    bacnet_init();
    timer_interval_start(&Blink_Timer, 125);
    for (;;) {
        if (timer_interval_expired(&Blink_Timer)) {
            timer_interval_reset(&Blink_Timer);
            led_ld3_toggle();
        }
        led_task();
        bacnet_task();
    }
}
コード例 #2
0
ファイル: main.c プロジェクト: JulienPobot/AVR-RS485
int
main()
{
	char ibuf[256], obuf[1024];
	char *p, *q;
	int n;
	char h[] = "0123456789abcdef";

	rs485_init();
	sei();

	rs485_send("RS485 test program by Y.Kohyama\r\n");

	while ((n = rs485_readln(ibuf, sizeof(ibuf)))) {
		q = obuf;
		for (p = ibuf; p < ibuf + n; p++) {
			*q++ = h[*p/16];
			*q++ = h[*p%16];
		}
		*q++ = '\r';
		*q++ = '\n';
		*q = '\0';
		rs485_send(obuf);
		_delay_ms(1);
	}
}
コード例 #3
0
ファイル: main.c プロジェクト: aniston/node-bacnet
/**
 * \brief Main function.
 *
 * Initializes the board, and runs the application in an infinite loop.
 */
int main(void)
{
    /* hardware initialization */
    sysclk_init();
    board_init();
    pmic_init();
    timer_init();
    rs485_init();
    led_init();
	adc_init();
#ifdef CONF_BOARD_ENABLE_RS485_XPLAINED
    // Enable display backlight
    gpio_set_pin_high(NHD_C12832A1Z_BACKLIGHT);
#endif
    // Workaround for known issue: Enable RTC32 sysclk
    sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_RTC);
    while (RTC32.SYNCCTRL & RTC32_SYNCBUSY_bm) {
        // Wait for RTC32 sysclk to become stable
    }
    cpu_irq_enable();
    /* application initialization */
    rs485_baud_rate_set(38400);
    bacnet_init();
    /*  run forever - timed tasks */
    timer_callback(bacnet_task_timed, 5);
    for (;;) {
        bacnet_task();
        led_task();
    }
}
コード例 #4
0
ファイル: token-ring.c プロジェクト: bobmittmann/thinkos
void net_init(void)
{
	printf("%s():...\n", __func__);

	/* IO init */
	stm32_gpio_mode(USART2_TX, ALT_FUNC, PUSH_PULL | SPEED_LOW);
	stm32_gpio_mode(USART2_RX, ALT_FUNC, PULL_UP);
	stm32_gpio_af(USART2_RX, GPIO_AF7);
	stm32_gpio_af(USART2_TX, GPIO_AF7);

	stm32_gpio_mode(LINK_TXEN, OUTPUT, PUSH_PULL | SPEED_LOW);
	stm32_gpio_mode(LINK_LOOP, OUTPUT, PUSH_PULL | SPEED_LOW);

	stm32_gpio_set(LINK_LOOP);
	stm32_gpio_set(LINK_TXEN);

	/* initialize the packet buffer pool */
	pktbuf_pool_init();

	/* DMA configuration for USART2 
	 * TX: DMA1, Stream6, Channel 4
	 * RX: DMA1, Stream5, Channel 4 
	 */

	/* Link init */
	rs485_init(&link, STM32_USART2, 1000, STM32F_DMA1, 
			   USART2_DMA_STRM_RX, USART2_DMA_CHAN_RX,
			   USART2_DMA_STRM_TX, USART2_DMA_CHAN_TX);

	cm3_irq_enable(STM32_IRQ_USART2);
}
コード例 #5
0
ファイル: net.c プロジェクト: powertang/yard-ice
int net_init(void)
{
	tracef("%s():...", __func__);

	if (lattice_ice40_configure(ice40lp384_bin, sizeof_ice40lp384_bin) < 0) {
		trace("lattice_ice40_configure() failed!");
		return -1;
	}

	/* IO init */
	stm32_gpio_mode(RS485_RX, ALT_FUNC, PULL_UP);
	stm32_gpio_af(RS485_RX, GPIO_AF7);

	stm32_gpio_mode(RS485_TX, ALT_FUNC, PUSH_PULL | SPEED_MED);
	stm32_gpio_af(RS485_TX, GPIO_AF7);

#ifdef RS485_CK
	stm32_gpio_mode(RS485_CK, ALT_FUNC, PUSH_PULL | SPEED_MED);
	stm32_gpio_af(RS485_CK, GPIO_AF7);
#endif

#ifdef RS485_TRIG
	stm32_gpio_mode(RS485_TRIG, INPUT, PULL_UP);
#endif

#ifdef RS485_TXEN
	stm32_gpio_mode(RS485_TXEN, OUTPUT, PUSH_PULL | SPEED_MED);
	stm32_gpio_set(RS485_TXEN);
#endif

#ifdef RS485_LOOP
	stm32_gpio_mode(RS485_LOOP, OUTPUT, PUSH_PULL | SPEED_MED);
	stm32_gpio_set(RS485_LOOP);
#endif

#ifdef RS485_MODE
	stm32_gpio_mode(RS485_MODE, OUTPUT, PUSH_PULL | SPEED_LOW);
	stm32_gpio_set(RS485_MODE);
#endif


	if (!net.initialized) {
		/* Link init */
		rs485_init(&net.link, RS485_USART, RS485_LINK_SPEED, 
				   USART1_DMA, USART1_DMA_CHAN,
				   USART1_RX_DMA_STRM, USART1_TX_DMA_STRM);

		/* initialize the packet buffer pool */
		pktbuf_pool_init();

		net_recv_init();

		net.probe_flag = thinkos_flag_alloc();

		net.initialized = true;
	}


	return 0;
}
コード例 #6
0
ファイル: tasks.c プロジェクト: barriquello/uFSM_OS
void Tarefa_RS485(void)
{

	CHAR8 c;
	
	rs485_init(9600,UART1_PTD6_PTD7,FALSE,0);
	for(;;)
	{
		rx_rs485(&c);
		putchar_rs485(c);
		DelayTask(10); /* 10 ms */
	}
}
コード例 #7
0
ファイル: demo.c プロジェクト: CKMagenta/UPennalizers
// Setup the main loop
int main(void) {

    // Set the system clock:
    rcc_clock_setup_in_hse_16mhz_out_72mhz();
    systick_init();

    // Setup the GPIO for the Indicator LED
    rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_IOPCEN);
    gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO12);

    // Set the memory in the stack
    char dyn_on[8] = "\xFF\xFF\xFE\x04\x03\x19\x01\xE0";
    char dyn_off[8] = "\xFF\xFF\xFE\x04\x03\x19\x00\xE1";

    // Initialize the RS485 communication system
    // This requires use of DMA1 Channel 4 and USART1
    rs485_init( 2000000 );

    while(1) {

        // Init on every loop
        rs485_init( 2000000 );

        // On for half a second, off for half a second
        gpio_clear(GPIOC, GPIO12);
        rs485_putstrn( (u32) &dyn_on, 8);
        _delay_us( 250000 );

        // Off...
        gpio_set(GPIOC, GPIO12);
        rs485_putstrn( (u32) &dyn_off, 8);
        _delay_us( 250000 );

    }

    return 0;

}
コード例 #8
0
ファイル: waterfallswing.c プロジェクト: iancharnas/Waterfall
void initialize_board() {
	// Configure SPI
	init_spi();
	
	// Shift all Zeroes out the SPI line
	for (int i = 0; i < 12; i++) {
		spi_shift_out(0x00);
		spi_latch();
	}
	
    rs485_init(BAUD(1000000));
    sei();
	buttons_init();
    diagled_init();
    boardaddr_init();
    diagled_blink(board_address); // Blink out this board's address
}
コード例 #9
0
ファイル: BSP_Modbus_main.c プロジェクト: shkodina/for-quest
int main(void) {

	uint8_t oldStatus = 0;

	initSysVars();
	initPorts();

	// we use RS485 here, to go with RS232 just have a look at Modbus_uart.c/.h
	// and use the rs232 init function
	rs485_init(UART_BAUD_SELECT(9600,F_CPU));
	initInterrupts();
	sei();

//	actProfileData[IDX_DW_Debug02] = 2;
	actProfileData[IDX_DW_Debug01] = 101;
	actProfileData[IDX_DW_Debug02] = 102;
	actProfileData[IDX_DW_Debug03] = 103;

	actProfileData[IDX_DW_EncSteps] = 200;
	actProfileData[IDX_DW_EncHyst] = 4;
	setBitValForSysBit(IDX_AB_EncSync, ON);


	for (;;) {


		if (oldStatus != uart0_status.status) {
			oldStatus = uart0_status.status;

			if (uart0_status.status == RS_FrameComplete) {
				if (UART_RxHead) {
					modbus_processSlaveFrame((uint8_t*) UART_RxBuf, UART_RxHead);
				}
				uart_flush();
				uart0_status.status = RS_Wait;
			}
		}

		if (changedBit.cBit != 99) {
			performBitActions();
		}
	}

}
コード例 #10
0
ファイル: main.c プロジェクト: Lexatagan/M14B26
int main()
{
u32 R;
uint16_t a, b;
  Set_System();
  TMet_Init();
  DBG_Init();
  rs485_init();
  while(1)
  {
    TMet_Delay(100);
    for (a = 0; a < 3; a++)
      for (b = 0; b < 3; b++)
      {
        If_PrintCylCell(a + b * 3, cl[a + b * 3]);
      }
    If_PrintOilTemp(ot);
    If_PrintOilPressure(op);
    If_PrintMetal(mt);
  };
}
コード例 #11
0
ファイル: main_relay.c プロジェクト: Arista12/UPennalizers
void init(void)
{
  // Enable outputs
  DDRC = 0b11111111;
  PORTC = 0xFF;
  // Turn on PWR Led
  PORTC &= ~(_BV(PORTC0));

  //  adc_init();

  uart1_init();
  uart1_setbaud(57600);

  rs485_init();
  rs485_setbaud(1000000);

  timer1_init();
  timer1_set_ovf_callback(t1_ovf_callback);

  sei();
}
コード例 #12
0
ファイル: main.c プロジェクト: Arista12/UPennalizers
void init(void)
{
  // Enable outputs
  DDRC = 0b11111111;
  PORTC = 0xFF;
  // Turn on PWR Led
  cbi(PORTC, PORTC0);

  InitLeds();
  	
  uart0_init();
  uart0_setbaud(HOST_BAUD_RATE);

  rs485_init();
  rs485_setbaud(BUS_BAUD_RATE);

  ctable_init();
  adc_init();
  
  //timer1_init();
  //timer1_set_overflow_callback(timer1_callback);

  sei();
}
コード例 #13
0
ファイル: fnordlicht.c プロジェクト: nordlicht81/moodlamp-rf
/** main function
 */
int main(void) {
//    SPCR &= ~(1<<SPE);
//    TIMSK0 &= ~(1<<TOIE1);
    wdt_disable();
    /* Clear WDRF in MCUSR */
    MCUSR &= ~(1<<WDRF);
    /* Write logical one to WDCE and WDE */
    /* Keep old prescaler setting to prevent unintentional time-out */
    WDTCSR |= (1<<WDCE) | (1<<WDE);
    /* Turn off WDT */
    WDTCSR = 0x00;
    //volatile long l;
//    for(l=0;l<1000000;l++);
    DDR_CONFIG_IN(CONFIG1);
    PIN_SET(CONFIG1);
    wdt_enable(WDTO_2S);
    wdt_reset();
    volatile unsigned long l;     
    for(l=0;l<10;l++);

    if( !PIN_HIGH(CONFIG1) ){
        global.config = 30;
    }else{
        global.config = 21;
    }
    
    leds_init();

    wdt_reset();
    if( global.config == 21 ){
        DDR_CONFIG_IN(JUMPER1C1);
        PIN_SET(JUMPER1C1);
    }else if( global.config == 30 ){
        DDR_CONFIG_IN(JUMPER1C2);
        PIN_SET(JUMPER1C2);
        adc_init();
        uint16_t bat = adc_getChannel(6);
        if( bat < ADC_MINBATIDLE ){
            //global.flags.lowbat = 1;
        }
    }
    
    wdt_reset();
    init_pwm();
#if SERIAL_UART
    uart1_init( UART_BAUD_SELECT(UART_BAUDRATE,F_CPU));
    stdout = &mystdout;
#endif

#if RC5_DECODER
    rc5_init();
#endif

    wdt_reset();
#if STATIC_SCRIPTS
    init_script_threads();
#endif
    settings_read();
    //if((global.config == 21 && !PIN_HIGH(JUMPER1C1)) || (global.config== 30 && !PIN_HIGH(JUMPER1C2)))
    //    interfaces_setEnabled(IFACE_RF,0);

    control_init();

    wdt_reset();
#if RS485_CTRL
    rs485_init();
    zbus_core_init();
#endif
    //rf_init();
    packet_init(idbuf[0],0);

    wdt_reset();
    srandom(random_seed);
    random_seed = random();

    /* enable interrupts globally */
    sei();
//    global.state = STATE_RUNNING;
//    global.state = STATE_PAUSE;
//    global.flags.running = 0;
    while (1) {
        wdt_reset();
        //leds_main();

        #if 1
        packet_tick();
        #else
        if(packetbase ){//> 32){
            packetbase = 0;

            packet_tick();
            //if(main_reset++ > 16000)
            //    jump_to_bootloader(); 
            //uint16_t bat = adc_getChannel(6);
            /*if( bat < ADC_MINBATIDLE ){
                global.flags.lowbat = 1;
            }*/
        }
        #endif
        //if( global.flags.lowbat ){
        //    control_lowbat();
        //}

        if( global.flags.timebase ){
            //control_tick();
            global.flags.timebase=0;
        }
        /* after the last pwm timeslot, rebuild the timeslot table */
        
        //if (global.flags.last_pulse) {
        //    global.flags.last_pulse = 0;
            //if(global.flags.running)
            //update_pwm_timeslots();
        //}
        /* at the beginning of each pwm cycle, call the fading engine and
         * execute all script threads */
        if (global.flags.new_cycle) {
            global.flags.new_cycle = 0;
            if(control_faderunning)
                update_brightness();

            if(global.flags.running){
#if STATIC_SCRIPTS
//                execute_script_threads();
#endif
            }
            //continue;
        }
#if RC5_DECODER
#endif
#if RS485_CTRL
        rs485_process();
#endif
#if SERIAL_UART
//serial_process();
#endif
    }
}
コード例 #14
0
ファイル: AM_model.c プロジェクト: fourier49/SolarM4
/*
 *  ======== uartHandler ========
 *  Creates new Task to handle new UART connections.
 */
Void uartHandler(UArg arg0, UArg arg1) {
	int i = 0;
	int j = 0;
	//int start_time,end_time;
	int packet_num;
	JB_DVAL = 1;

	rs485_init();

	rs485_write((const uint8*) "RS-485 testing message", 22);
	UARTprintf((const char*) "Debug testing message \n");

	//Reset JB
	for (i = 0; i < 3; i++) {
		Reset_JB();
		TaskSleep(500);
	}
	for (j = 0; j < Number_of_JB; j++) {
		pv_value_table[j].Diode_Temperature = 0xFF;
		for (i = 0; i < 2; i++)
			pv_value_table[j].Voltage[i] = 0xFF;
		for (i = 0; i < 2; i++)
			pv_value_table[j].Current[i] = 0xFF;
		for (i = 0; i < 4; i++)
			pv_value_table[j].Power_Energy[i] = 0xFF;
		for (i = 0; i < 4; i++)
			pv_value_table[j].Alert_State[i] = 0xFF;
		for (i = 0; i < 6; i++)
			pv_info_table[j].MAC[i] = 0xFF;
		for (i = 6; i < 30; i++)
			pv_info_table[j].Serial_Number[i - 6] = 0xFF;
		for (i = 30; i < 54; i++)
			pv_info_table[j].Firmware_Version[i - 30] = 0xFF;
		for (i = 54; i < 78; i++)
			pv_info_table[j].Hardware_Version[i - 54] = 0xFF;
		for (i = 78; i < 102; i++)
			pv_info_table[j].Device_Specification[i - 78] = 0xFF;
		for (i = 102; i < 110; i++)
			pv_info_table[j].Manufacture_Date[i - 102] = 0xFF;
		for (i = 0; i < 6; i++)
			member_table[j].MAC[i] = 0x00;
		member_table[j].Valid = 0;
		member_table[j].state = JB_Free;
	}
	j = 0;

	while (1) {
		if (JB_DVAL == 1) {
			JB_DVAL = 0;
			//UARTprintf((const char*)"P[0] = %d\t P[1] = %d\n",G_ENVCONFIG.Pollingtime[0],G_ENVCONFIG.Pollingtime[1]);
			UARTprintf((const char*) "----Test_merge = %d----\n", test_merge);
			UARTprintf(
					(const char*) "\n\n\n--Update_Time: %d/%d/%d-%d:%d:%d --\n\n\n",
					AM_time.year, AM_time.mon, AM_time.mday, AM_time.hour,
					AM_time.min, AM_time.sec);
			UARTprintf((const char*) "----Start JB Join (JBtoAM)----\n");
			//start_time =  Clock_getTicks();  //calculate JB Join AM Time
			for (i = 0; i < 3; i++)					// Broadcast n times
					{
				//Broadcast_Packet();
				New_Broadcast_Packet_with_Pollingtime();
				packet_num = Rs4852Array(total_array);
				Array2Packet(packet_num, uart);
			}
			//end_time =  Clock_getTicks(); //calculate JB Join AM Time

			//UARTprintf((const char*)"execution time=%d \n",end_time-start_time);

			Check_JB_Number();
			UARTprintf((const char*) "\n----=JB_Number=%d JB_Count=%d=----\n",
					JB_Number, JB_Count);
//			UARTprintf((const char*)"\n----Number_of_JB=%d ----\n",JB_Number);
			UARTprintf((const char*) "----END JB Join (JBtoAM)---- \n");

			UARTprintf((const char*) "----Start PV Info (JB & AM)----\n");
			Request_PV_Info(uart);
			UARTprintf((const char*) "----End PV Info (JB & AM)----\n");

			//start JB Join (JBtoServer)
			while (task_Event != Nothing)
				;
			task_Event = JB_Join;

			UARTprintf((const char*) "----Start PV Value (JB & AM)----\n");
			Periodic_Update_time.year = AM_time.year;
			Periodic_Update_time.mon = AM_time.mon;
			Periodic_Update_time.mday = AM_time.mday;
			Periodic_Update_time.hour = AM_time.hour;
			Periodic_Update_time.min = AM_time.min;
			Periodic_Update_time.sec = AM_time.sec;
			Request_PV_Value(uart);
			UARTprintf((const char*) "----End PV Value (JB & AM)----\n");

			//start PV_Periodic(JBtoServer)
			while (task_Event != Nothing)
				;
			task_Event = PV_Periodic;

			//end_time =  Clock_getTicks(); //calculate JB Join AM Time

			//UARTprintf((const char*)"\n\n >>total execution time=%d<< \n\n",end_time-start_time);
			UARTprintf((const char*) "----Delay END----\n");
			/*if(j>Periodic_Count)
			 {
			 task_Event = TCPPeriodicLink;
			 UARTprintf((const char*)"\n\n--Update_Time: %d/%d/%d-%d:%d:%d --\n\n",AM_time.year,AM_time.mon,AM_time.mday,AM_time.hour,AM_time.min,AM_time.sec);
			 //UARTprintf((const char*)"\n\n\n\n----Debug i = %d----\n\n\n\n\n",i);
			 j=0;
			 }
			 else
			 {
			 j++;
			 //UARTprintf((const char*)"\n\n\n\n----Debug j = %d----\n\n\n\n\n",j);
			 }*/

		}
	}
}