コード例 #1
0
ファイル: main.c プロジェクト: g8ecj/turbine
static void init(void)
{

	/* Initialize debugging module (allow kprintf(), etc.) */
//	kdbg_init();
	/* Initialize system timer */
	timer_init();

	/*
	 * XXX: Arduino has a single UART port that was previously
	 * initialized for debugging purpose.
	 * In order to activate the serial driver you should disable 
	 * the debugging module.
	 */
	/* Initialize UART0 */
	ser_init(&serial, SER_UART0);
	/* Configure UART0 to work at 115.200 bps */
	ser_setbaudrate(&serial, 115200);

	/* Enable all the interrupts now the basic stuff is initialised */
	IRQ_ENABLE;

	// set clock up using last values from eeprom
	rtc_init();
	// read a few more values out of eeprom and init the display etc
	load_eeprom_values();
	ui_init();
	measure_init();
	control_init();
	rpm_init();
	graph_init();
	log_init();

}
コード例 #2
0
ファイル: main.c プロジェクト: fantasea/APRS
static void init(void)
{
	/* Enable all the interrupts */
	IRQ_ENABLE;

	/* Initialize debugging module (allow kprintf(), etc.) */
	kdbg_init();
	/* Initialize system timer */
	timer_init();
	/* Initialize LED driver */
	LED_INIT();

	ser_init(&ser_port, SER_UART2);
	ser_setbaudrate(&ser_port, 115200L);

	afsk_init(&afsk, 0, 0);

	// timer period = 24000000 hz /100/25 = 9600hz
	AD_Init(&afsk);
	AD_SetTimer(100, 25);
	AD_Start();

	DA_Init(&afsk);
	DA_SetTimer(100, 25);

	kiss_init(&ser_port, &ax25, &afsk);

	ax25_init(&ax25, &afsk.fd, 1, ax25_message_callback);
}
コード例 #3
0
ファイル: ser.c プロジェクト: ZS6TVB/Arduino-APRS-Digipeater
/**
 * Initialize a serial port.
 *
 * \param fd KFile Serial struct interface.
 * \param unit  Serial unit to open. Possible values are architecture dependant.
 */
static struct Serial *ser_open(struct Serial *fd, unsigned int unit)
{
	ASSERT(unit < countof(ser_handles));

	ser_handles[unit] = fd;
	ASSERT(!fd->is_open);
	DB(fd->is_open = true);

	fd->unit = unit;

	fd->hw = ser_hw_getdesc(unit);

	/* Initialize circular buffers */
	ASSERT(fd->hw->txbuffer);
	ASSERT(fd->hw->rxbuffer);
	fifo_init(&fd->txfifo, fd->hw->txbuffer, fd->hw->txbuffer_size);
	fifo_init(&fd->rxfifo, fd->hw->rxbuffer, fd->hw->rxbuffer_size);

	fd->hw->table->init(fd->hw, fd);

	/* Set default values */
#if CONFIG_SER_RXTIMEOUT != -1 || CONFIG_SER_TXTIMEOUT != -1
	ser_settimeouts(fd, CONFIG_SER_RXTIMEOUT, CONFIG_SER_TXTIMEOUT);
#endif
#if CONFIG_SER_DEFBAUDRATE
	ser_setbaudrate(fd, CONFIG_SER_DEFBAUDRATE);
#endif

	/* Clear error flags */
	ser_setstatus(fd, 0);

	return fd;
}
コード例 #4
0
ファイル: main.c プロジェクト: GDXN/MicroModem
// Simple initialization function.
static void init(void)
{
    // Enable interrupts
    IRQ_ENABLE;

    // Initialize hardware timers
    timer_init();

    // Initialize serial comms on UART0,
    // which is the hardware serial on arduino
    ser_init(&ser, SER_UART0);
    ser_setbaudrate(&ser, 9600);

    // For some reason BertOS sets the serial
    // to 7 bit characters by default. We set
    // it to 8 instead.
    UCSR0C = _BV(UCSZ01) | _BV(UCSZ00);

    // Create a modem context
    afsk_init(&afsk, ADC_CH);
    // ... and a protocol context with the modem
    mp1Init(&mp1, &afsk.fd, mp1Callback);

    // That's all!
}
コード例 #5
0
ファイル: main.c プロジェクト: DINKIN/bertos
static void init(void)
{
	/* Enable all the interrupts */
	IRQ_ENABLE;

	/* Initialize debugging module (allow kprintf(), etc.) */
	kdbg_init();
	/* Initialize system timer */
	timer_init();
	/* Initialize LED driver */
	LED_INIT();
	LED_OFF();

	/* Kernel initialization */
	proc_init();

	/* Initialize the serial driver */
	ser_init(&ser_port, SER_UART2);
	/*
	 * Hard-code the baud rate to 115.200 bps.
	 *
	 * TODO: implement the baud rate settings as well as other UART
	 * settings over the USB connection.
	 */
	ser_setbaudrate(&ser_port, 115200);

	/* Initialize usb-serial driver */
	usbser_init(&usb_port, 0);
}
コード例 #6
0
ファイル: main.c プロジェクト: DINKIN/bertos
static void init(void)
{
	/* Enable all the interrupts */
	IRQ_ENABLE;

	/* Initialize debugging module (allow kprintf(), etc.) */
	kdbg_init();
	/* Initialize system timer */
	timer_init();
	/* Initialize UART0 */
	ser_init(&out, SER_UART0);
	/* Configure UART0 to work at 115.200 bps */
	ser_setbaudrate(&out, 115200);
	/* Initialize LED driver */
	LED_INIT();

	/*
	 * Kernel initialization: processes (allow to create and dispatch
	 * processes using proc_new()).
	 */
	proc_init();

	/* Initialize TCP/IP stack */
	tcpip_init(NULL, NULL);

	/* Bring up the network interface */
	netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, tcpip_input);
	netif_set_default(&netif);
	netif_set_up(&netif);
}
コード例 #7
0
ファイル: main.c プロジェクト: mtarek/BeRTOS
static void init(void)
{
	/* Enable all the interrupts */
	IRQ_ENABLE;

	/* Initialize debugging module (allow kprintf(), etc.) */
	kdbg_init();
	/* Initialize system timer */
	timer_init();
	/* Initialize UART1 */
	ser_init(&out, SER_UART1);
	/* Configure UART1 to work at 115.200 bps */
	ser_setbaudrate(&out, 115200);
	/* Initialize LED driver */
	LED_INIT();
	/* Initialize the OLED display (RIT128x96) */
	rit128x96_init();
	/* Draw an empty Bitmap on the screen */
	gfx_bitmapInit(&lcd_bitmap, raster, LCD_WIDTH, LCD_HEIGHT);
	/* Refresh the display */
	rit128x96_blitBitmap(&lcd_bitmap);
	/* Initialize the keypad driver */
	kbd_init();
	/* Initialize the internal flash memory */
	flash_init(&flash, 0);

	/*
	 * Kernel initialization: processes (allow to create and dispatch
	 * processes using proc_new()).
	 */
	proc_init();
}
コード例 #8
0
ファイル: main.c プロジェクト: DINKIN/bertos
static void init(void)
{
	/* Enable all the interrupts */
	IRQ_ENABLE;

	/* Initialize debugging module (allow kprintf(), etc.) */
	kdbg_init();
	/* Initialize system timer */
	timer_init();

	/*
	 * XXX: Arduino has a single UART port that was previously
	 * initialized for debugging purpose.
	 * In order to activate the serial driver you should disable 
	 * the debugging module.
	 */
#if 0
	/* Initialize UART0 */
	ser_init(&out, SER_UART0);
	/* Configure UART0 to work at 115.200 bps */
	ser_setbaudrate(&out, 115200);
#else
	(void)out;
#endif
	/* Initialize LED driver */
	LED_INIT();
}
コード例 #9
0
ファイル: main.c プロジェクト: mtarek/BeRTOS
static void init(void)
{
	IRQ_ENABLE;
	kdbg_init();

	timer_init();
	LOG_INFO("TIMER init..ok\n");

	/*
	 * Init temperature sensor device.
	 * - init the temperature driver
	 * - init the spi communication channel
	 */
	tmp123_init();
	// Init SPI connected to sensor temperature
	spimaster_init(&temp_sensor_bus, SER_SPI1);
	ser_setbaudrate(&temp_sensor_bus, 1000000L);
	LOG_INFO("TMP123 sensor init..ok\n");

	// Init SPI bus to communicate to SD card
	spi_dma_init(&spi_dma);
	spi_dma_setclock(20000000L);
	LOG_INFO("SD SPI init..ok\n");

	adc_init();
	LOG_INFO("ADC init..ok\n");

}
コード例 #10
0
ファイル: hadarp.c プロジェクト: batt/StratoSpera
void hadarp_init(unsigned port, unsigned long baudrate)
{
	ser_init(&ser, port);
	ser_setbaudrate(&ser, baudrate);
	hadarp_cnt = -1;

	hadarp_proc = proc_new(hadarp_process, NULL, KERN_MINSTACKSIZE * 3, NULL);
	ASSERT(hadarp_proc);
}
コード例 #11
0
/**
 * Setup all needed to test dataflash memory
 *
 */
int dataflash_testSetup(void)
{
        kfile_testSetup();
        LOG_INFO("KFILE setup..ok\n");

        LOG_INFO("Check if kernel is enable (if enable you should see the assert message.)\n");
        SILENT_ASSERT("bertos/drv/dataflash_test.c:119: Assertion failed: !CONFIG_KERN");
        ASSERT(!CONFIG_KERN);

        /*
         * This test use a kfile_test module,
         * so should include source in your makefile.
         */
        MOD_CHECK(kfile_test);

        timer_init();
        LOG_INFO("Timer init..ok\n");

        /*
         * Init SPI module and dataflash driver.
         */
        // Open SPI comunication channel
        spimaster_init(&spi_fd, 0);
        LOG_INFO("SPI0 init..ok\n");

        ser_setbaudrate(&spi_fd, 5000000UL);
        LOG_INFO("SPI0 set baudrate..ok\n");

        //Init dataflash memory
        dataflash_hw_init();
        LOG_INFO("DATAFLASH HW..ok\n");

        if (dataflash_init(&dflash_fd, &spi_fd.fd, DATAFLASH_MEM_MODEL, DATAFLASH_FUNC_CS_SET, DATAFLASH_FUNC_RESET))
                LOG_INFO("DATAFLASH init..ok\n");
        else
                LOG_ERR("DATAFLASH init..fail\n");


        //Fill tmp buffer with rand chars.
        for (int i = 0; i < DATAFLASH_TEST_STR_LEN; i++)
        {
                #if DATAFLASH_USE_RAND_FUNC
                        #include <stdlib.h> //Rand()

                        test_buf[i] = (uint8_t)rand();
                #else
                        test_buf[i] = (i & 0xff);
                #endif
        }

        LOG_INFO("Fill tmp buff..ok\n");

	return 0;
}
コード例 #12
0
ファイル: main.c プロジェクト: DINKIN/bertos
static void init(void)
{
	/* Enable all the interrupts */
	IRQ_ENABLE;

	/* Initialize debugging module (allow kprintf(), etc.) */
	kdbg_init();
	/* Initialize system timer */
	timer_init();
	/* Initialize UART0 */
	ser_init(&out, SER_UART0);
	/* Configure UART0 to work at 115.200 bps */
	ser_setbaudrate(&out, 115200);
	/* Initialize LED driver */
	LED_INIT();
}
コード例 #13
0
ファイル: main.c プロジェクト: DINKIN/bertos
static void init(void)
{
	IRQ_ENABLE;
	kdbg_init();
	timer_init();

	/*
	 * Init afsk demodulator. We need to implement the macros defined in hw_afsk.h, which
	 * is the hardware abstraction layer.
	 * We do not need transmission for now, so we set transmission DAC channel to 0.
	 */
	afsk_init(&afsk, ADC_CH, 0);
	/*
	 * Here we initialize AX25 context, the channel (KFile) we are going to read messages
	 * from and the callback that will be called on incoming messages.
	 */
	ax25_init(&ax25, &afsk.fd, message_callback);

	/* Initialize serial port, we are going to use it to show APRS messages*/
	ser_init(&ser, SER_UART0);
	ser_setbaudrate(&ser, 115200L);
}
コード例 #14
0
ファイル: main.c プロジェクト: DINKIN/bertos
static void init(void)
{
	/* Enable all the interrupts */
	IRQ_ENABLE;

	/* Initialize debugging module (allow kprintf(), etc.) */
	kdbg_init();
	/* Initialize system timer */
	timer_init();
	/* Initialize UART1 */
	ser_init(&out, SER_UART1);
	/* Configure UART1 to work at 115.200 bps */
	ser_setbaudrate(&out, 115200);
	/* Initialize LED driver */
	LED_INIT();

	/*
	 * Kernel initialization: processes (allow to create and dispatch
	 * processes using proc_new()).
	 */
	proc_init();
}
コード例 #15
0
ファイル: context_switch.c プロジェクト: 7h0ma5/kiss-avraprs
void NORETURN context_switch(void)
{
	IRQ_ENABLE;
	timer_init();
	proc_init();

	#if CONFIG_USE_HP_TIMER
		ser_init(&out, CONFIG_CTX_DEBUG_PORT);
		ser_setbaudrate(&out, CONFIG_CTX_DEBUG_BAUDRATE);
	#endif

	#if CONFIG_USE_LED
		LED_INIT();
	#endif

	proc_forbid();
	hp_proc = proc_new(hp_process, NULL, PROC_STACK_SIZE, hp_stack);
	lp_proc = proc_new(lp_process, NULL, PROC_STACK_SIZE, lp_stack);
	main_proc = proc_current();
	proc_setPri(hp_proc, 2);
	proc_setPri(lp_proc, 1);
	proc_permit();

	while (1)
	{
		timer_delay(100);

		sig_send(lp_proc, SIG_USER0);
		sig_wait(SIG_USER0);

		#if CONFIG_USE_HP_TIMER
			kfile_printf(&out.fd,
				"Switch: %lu.%lu usec\n\r",
				hptime_to_us((end - start)),
				hptime_to_us((end - start) * 1000) % 1000);
		#endif
	}
}
コード例 #16
0
ファイル: main.c プロジェクト: mtarek/BeRTOS
int main(void)
{
	// SD fat filesystem context
	FATFS fs;

	// Context files that we would manage
	FatFile ini_file;
	FatFile log_file;

	init();

	LOG_INFO("SD fat example project %s: %d times\n", VERS_HOST, VERS_BUILD);

	while (1)
	{
		bool sd_ok = true;
		FRESULT result;

		// Setting info
		INISetting ini_set;
		memset(&ini_set, 0, sizeof(ini_set));

		sd_ok = sd_init(&spi_dma.fd);

		if (sd_ok)
		{
			LOG_INFO("Mount FAT filesystem.\n");
			if ((result = f_mount(0, &fs)) != FR_OK)
			{
				LOG_ERR("Mounting FAT volumes error[%d]\n", result);
				sd_ok = false;
			}

			LOG_INFO("Read setting from ini file: %s\n", INI_FILE_NAME);
			if (sd_ok && ((result = fatfile_open(&ini_file, INI_FILE_NAME, FA_READ)) != FR_OK))
			{
				LOG_ERR("Could not open ini file: %s error[%d,]\n", INI_FILE_NAME, result);
				sd_ok = false;
			}

			if (sd_ok)
			{
				/*
				 * If sd is ok, we read all setting from INI file.
				 * NOTE: if one ini key or section was not found into INI
				 * file, the iniparser return the defaul value.
				 */
				ini_getString(&ini_file.fd, LOG_SECTION, LOG_NAME_KEY, "default.log", ini_set.name, sizeof(ini_set.name));
				LOG_INFO("Log file name [%s]\n", ini_set.name);

				char tmp[25];
				ini_getString(&ini_file.fd, LOG_SECTION, LOG_ON_SERIAL,   "1", tmp, sizeof(tmp));
				ini_set.log_on_serial = atoi(tmp);
				LOG_INFO("Log serial [%d]\n", ini_set.log_on_serial);
				ini_getString(&ini_file.fd, LOG_SECTION, LOG_ON_FILE,     "1", tmp, sizeof(tmp));
				ini_set.log_on_file = atoi(tmp);
				LOG_INFO("Log sd [%d]\n", ini_set.log_on_file);
				ini_getString(&ini_file.fd, LOG_SECTION, LOG_SAMPLE_TIME, "500", tmp, sizeof(tmp));
				ini_set.sample_time = atoi(tmp);
				LOG_INFO("Sample time [%ld]\n", ini_set.sample_time);

				ini_getString(&ini_file.fd, SERIAL_LOG, SERIAL_PORT, "0", tmp, sizeof(tmp));
				ini_set.port = atoi(tmp);
				LOG_INFO("Serial port [%d]\n", ini_set.port);
				ini_getString(&ini_file.fd, SERIAL_LOG, SERIAL_BAUD, "115200", tmp, sizeof(tmp));
				ini_set.baud = atoi(tmp);
				LOG_INFO("Serial buad [%d]\n", ini_set.baud);

				ini_getString(&ini_file.fd, LOG_FORMAT_SEC, FORMAT_LINE_HEADER, "BeRTOS: ", ini_set.line_header, sizeof(ini_set.line_header));
				LOG_INFO("Serial line header[%s]\n", ini_set.line_header);

				ini_getString(&ini_file.fd, LOG_FORMAT_SEC, FORMAT_FIELD_SEP, ",", ini_set.field_sep, sizeof(ini_set.field_sep));
				LOG_INFO("Serial char sep[%s]\n", ini_set.field_sep);

				ini_getString(&ini_file.fd, TEMPERATURE, TEMP_UNIT_LABEL, "C", ini_set.temp_unit_label, sizeof(ini_set.temp_unit_label));
				LOG_INFO("Temp unit label[%s]\n", ini_set.temp_unit_label);

				ini_getString(&ini_file.fd, PRESSURE, PRESS_UNIT_LABEL, "hPa", ini_set.press_unit_label, sizeof(ini_set.press_unit_label));
				LOG_INFO("Press unit label[%s]\n", ini_set.press_unit_label);

				ini_getString(&ini_file.fd, VOLTAGE, VOLTAGE_UNIT_LABEL, "V", ini_set.voltage_unit_label, sizeof(ini_set.voltage_unit_label));
				LOG_INFO("Press unit label[%s]\n", ini_set.voltage_unit_label);

			}
		}

		if (ini_set.log_on_serial)
		{
			// Init serial log port
			ser_init(&log_port, ini_set.port);
			ser_setbaudrate(&log_port, ini_set.baud);
			LOG_INFO("SERIAL init..port[%d] buad[%d]\n", ini_set.port, ini_set.baud);
		}

		char log_string[160];
		memset(log_string, 0, sizeof(log_string));

		// Supplay voltage
		uint16_t vdd = ADC_RANGECONV(adc_read(SUPPLAY_VOLTAGE_CH), 0, ADC_SUPPLAY_VOLTAGE);

		// Read temperature
		int16_t tmp = tmp123_read(&temp_sensor_bus.fd);

		// Read pressure
		uint16_t vout = ADC_RANGECONV(adc_read(PRESSURE_SENSOR_CH), 0, vdd);
		int16_t press = mpxx6115a_press(vout,  vdd);

		/*
		 * Format string whit read data
		 * line_header + temp + temp_unit_label + field_sep + press + press_unit_label + field_sep + vdd + voltage_unit_label
		 */
		int wr_len = sprintf(log_string, "%s%d.%01d%s%s%d%s%s%d.%d%s\r\n", ini_set.line_header,
																tmp / 10, ABS(tmp % 10),
																ini_set.temp_unit_label,
																ini_set.field_sep,
																press,
																ini_set.press_unit_label,
																ini_set.field_sep,
																vdd / 1000, ABS(vdd % 1000),
																ini_set.voltage_unit_label);


		/*
		 * if SD is ok, try to open log file and write our data and, only
		 * if by configuration we have enable the log on file
		 */
		if (sd_ok && ini_set.log_on_file)
		{
			// Open log file and do not overwrite the previous log file
			result = fatfile_open(&log_file, ini_set.name,  FA_OPEN_EXISTING | FA_WRITE);

			// If the log file there isn't we create the new one
			if (result == FR_NO_FILE)
			{
				result = fatfile_open(&log_file, ini_set.name,  FA_CREATE_NEW | FA_WRITE);
				LOG_INFO("Create the log file: %s\n", ini_set.name);
			}

			if ( result == FR_OK)
			{
				LOG_INFO("Opened log file '%s' size %ld\n", ini_set.name, log_file.fat_file.fsize);

				// To append data we should go to end of file before to start to write
				kfile_seek(&log_file.fd, 0, KSM_SEEK_END);

				int len = kfile_write(&log_file.fd, log_string, wr_len);

				// Flush data and close the files.
				kfile_flush(&log_file.fd);
				kfile_close(&log_file.fd);

				// Unmount always to prevent accidental sd remove.
				f_mount(0, NULL);
				LOG_INFO("Wrote [%d]\n", len);
			}
			else
			{
				LOG_ERR("Unable to open file: '%s' error[%d]\n", ini_set.name, result);
			}
		}

		// If by configuration we have enable the log on serial, we log it
		if (ini_set.log_on_serial)
			kfile_write(&log_port.fd, log_string, wr_len);

		timer_delay(ini_set.sample_time);
	}

	return 0;
}
コード例 #17
0
ファイル: main.c プロジェクト: shawnchain/aprs
static void init(void)
{

    IRQ_ENABLE;

	kdbg_init();
	timer_init();

	/* Initialize serial port, we are going to use it to show APRS messages*/
	ser_init(&g_serial, SER_UART0);
	ser_setbaudrate(&g_serial, SER_DEFAULT_BAUD_RATE);
    // For some reason BertOS sets the serial
    // to 7 bit characters by default. We set
    // it to 8 instead.
    UCSR0C = _BV(UCSZ01) | _BV(UCSZ00); // see ATMEGA328P datasheet P197, Table 20-11. UCSZn Bits Settings

    // initialize the reader that wraps the serial
    serialreader_init(&g_serialreader, &g_serial);

    // Load settings first
    settings_load();

	/*
	 * Init afsk demodulator. We need to implement the macros defined in hw_afsk.h, which
	 * is the hardware abstraction layer.
	 * We do not need transmission for now, so we set transmission DAC channel to 0.
	 */
	afsk_init(&g_afsk, ADC_CH, DAC_CH);

	/*
	 * Here we initialize AX25 context, the channel (KFile) we are going to read messages
	 * from and the callback that will be called on incoming messages.
	 */
	ax25_init(&g_ax25, &g_afsk.fd, ax25_msg_callback);
	g_ax25.pass_through = false;

	// Initialize the kiss module
	// NOTE - use shared memory buffer
#if MOD_KISS
	kiss_init(&g_serialreader,&g_ax25);
#endif

#if MOD_BEACON
	// Initialize the beacon module
    beacon_init(beacon_mode_exit_callback);
#endif

    // Initialize the digi module
#if MOD_DIGI
    digi_init();
#endif

#if MOD_RADIO
    // Initialize the soft serial and radio
    radio_init(4310400); //TODO read from settings
#endif

    // Initialize GPS NMEA/GPRMC parser
#if MOD_TRACKER
    tracker_init();
#endif

#if MOD_CONSOLE
    //////////////////////////////////////////////////////////////
    // Initialize the console & commands
    console_init();
    console_add_command(PSTR("MODE"),cmd_switch_mode);			// setup tnc run mode
#if MOD_KISS
    console_add_command(PSTR("KISS"),cmd_enter_kiss_mode);		// enable KISS mode
#endif
#endif
}