コード例 #1
0
ファイル: i2c_mcux.c プロジェクト: kraj/zephyr
static int i2c_mcux_configure(struct device *dev, u32_t dev_config_raw)
{
	I2C_Type *base = DEV_BASE(dev);
	const struct i2c_mcux_config *config = DEV_CFG(dev);
	u32_t clock_freq;
	u32_t baudrate;

	if (!(I2C_MODE_MASTER & dev_config_raw)) {
		return -EINVAL;
	}

	if (I2C_ADDR_10_BITS & dev_config_raw) {
		return -EINVAL;
	}

	switch (I2C_SPEED_GET(dev_config_raw)) {
	case I2C_SPEED_STANDARD:
		baudrate = KHZ(100);
		break;
	case I2C_SPEED_FAST:
		baudrate = MHZ(1);
		break;
	default:
		return -EINVAL;
	}

	clock_freq = CLOCK_GetFreq(config->clock_source);
	I2C_MasterSetBaudRate(base, baudrate, clock_freq);

	return 0;
}
コード例 #2
0
ファイル: i2c_mcux.c プロジェクト: rsalveti/zephyr
static int i2c_mcux_configure(struct device *dev, u32_t dev_config_raw)
{
	I2C_Type *base = DEV_BASE(dev);
	const struct i2c_mcux_config *config = DEV_CFG(dev);
	union dev_config dev_config = (union dev_config)dev_config_raw;
	u32_t clock_freq;
	u32_t baudrate;

	if (!dev_config.bits.is_master_device) {
		return -EINVAL;
	}

	if (dev_config.bits.use_10_bit_addr) {
		return -EINVAL;
	}

	switch (dev_config.bits.speed) {
	case I2C_SPEED_STANDARD:
		baudrate = KHZ(100);
		break;
	case I2C_SPEED_FAST:
		baudrate = MHZ(1);
		break;
	default:
		return -EINVAL;
	}

	clock_freq = CLOCK_GetFreq(config->clock_source);
	I2C_MasterSetBaudRate(base, baudrate, clock_freq);

	return 0;
}
コード例 #3
0
ファイル: main.cpp プロジェクト: brucetsao/nano1768
/* ==============================================
	main task routine
   ============================================== */
int main(void) {
	pool_memadd((uint32_t)pool, sizeof(pool));

#ifdef DEBUG
	dbg.start();
#endif

	// TODO: insert code here
	CAdxl345 adxl;
	adxl.assign(I2C0, KHZ(400));
	adxl.powerOn();

	CPin led(P7);
	led.output(NOT_OPEN);

	int x,y,z;

	// Enter an endless loop
	while(1){
		adxl.readAccel(&x, &y, &z);
#ifdef DEBUG
		if ( dbg.isDebugMode() ) {
			dbg.println("X=%d, Y=%d, Z=%d\n", x, y, z);
		}
#endif
		led = !led;
		sleep(200);
	}
	return 0 ;
}
コード例 #4
0
ファイル: i2c_imx.c プロジェクト: milinddeore/zephyr
static int i2c_imx_configure(struct device *dev, u32_t dev_config_raw)
{
	I2C_Type *base = DEV_BASE(dev);
	struct i2c_imx_data *data = DEV_DATA(dev);
	struct i2c_master_transfer *transfer = &data->transfer;
	u32_t baudrate;

	if (!(I2C_MODE_MASTER & dev_config_raw)) {
		return -EINVAL;
	}

	if (I2C_ADDR_10_BITS & dev_config_raw) {
		return -EINVAL;
	}

	/* Initialize I2C state structure content. */
	transfer->txBuff = 0;
	transfer->rxBuff = 0;
	transfer->cmdSize = 0U;
	transfer->txSize = 0U;
	transfer->rxSize = 0U;
	transfer->isBusy = false;
	transfer->currentDir = i2cDirectionReceive;
	transfer->currentMode = i2cModeSlave;

	switch (I2C_SPEED_GET(dev_config_raw)) {
	case I2C_SPEED_STANDARD:
		baudrate = KHZ(100);
		break;
	case I2C_SPEED_FAST:
		baudrate = MHZ(1);
		break;
	default:
		return -EINVAL;
	}

	/* Setup I2C init structure. */
	i2c_init_config_t i2cInitConfig = {
		.baudRate	  = baudrate,
		.slaveAddress = 0x00
	};

	i2cInitConfig.clockRate = get_i2c_clock_freq(base);

	I2C_Init(base, &i2cInitConfig);

	I2C_Enable(base);

	return 0;
}

static int i2c_imx_send_addr(struct device *dev, u16_t addr, u8_t flags)
{
	u8_t byte0 = addr << 1;

	byte0 |= (flags & I2C_MSG_RW_MASK) == I2C_MSG_READ;
	return i2c_imx_write(dev, &byte0, 1);
}
コード例 #5
0
ファイル: sg_serial_rpi.c プロジェクト: branstem/SansGrid
/**
 * \brief Prepare for SPI transfer (API)
 *
 * Note that to use this, you must have an int g_fd file descriptor
 * that this can write to. You must close that file descriptor when
 * transfer is done. You should use spiOpen(), which is a wrapper
 * for this function that returns the file descriptor directly.
 * \returns
 * This function returns 0 on success, and -1 on failure. \n
 * A global file descriptor is stored in the int g_fd field.
 */
int8_t sgSerialOpen(void) {
	// Set up SPI
	if ((g_fd = wiringPiSPISetup (0, KHZ(SPI_SPEED_KHZ))) < 0) {
		syslog(LOG_ERR, "SPI Setup failed: %s\n", strerror (errno));
		return -1;
	} else {
		return 0;
	}
	return 0;
}
コード例 #6
0
ファイル: main.c プロジェクト: patriciocm/ARMCode
static void setupHardware(void) {
	// Se configuran los perifericos por defecto
	SystemInit();

	// Se inicializa las task de comunicaciones
//	taskPcCommunicationInit();

	semSdCardAccess = xSemaphoreCreateMutex();
	xSemaphoreGive(semSdCardAccess);

	// SD Card
	LPC_GPIO0->FIODIR |= 1<<22;
	LPC_GPIO0->FIOCLR |= 1<<22;

	LPC_SC->PCLKSEL0 &= ~(3<<2);
	LPC_SC->PCLKSEL0 |= 1<<2;

	/*
	 * Default values for the SPI clock
	 * Use 400 kHz during init and 1 MHz during data transfer
	 *
	 * These values are believed to be reasonably safe values.
	 */
	SetSPIClocks(KHZ(400), MHZ(1));

	f_mount(0, &fs);

	LPC_GPIO2->FIODIR |= (1<<0); // red
	LPC_GPIO2->FIODIR |= (1<<1); // green

	LPC_GPIO2->FIOCLR = (1<<0); // red
	LPC_GPIO2->FIOCLR = (1<<1); // green


	RTC_Init(LPC_RTC);

	/* Enable rtc (starts increase the tick counter and second counter register) */
	RTC_ResetClockTickCounter(LPC_RTC);
	RTC_Cmd(LPC_RTC, ENABLE);
	RTC_CalibCounterCmd(LPC_RTC, DISABLE);

	/* Set current time for RTC */
	// Current time is 8:00:00PM, 2009-04-24
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_SECOND, 0);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_MINUTE, 0);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_HOUR, 0);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_MONTH, 12);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_YEAR, 2012);
	RTC_SetTime (LPC_RTC, RTC_TIMETYPE_DAYOFMONTH, 19);

	/* Set ALARM time for second */
	RTC_SetAlarmTime (LPC_RTC, RTC_TIMETYPE_SECOND, 10);

}
コード例 #7
0
ファイル: output_text.c プロジェクト: esden/sigrok
static void init(struct output *o, int default_spl)
{
    struct context *ctx;
    struct probe *probe;
    GSList *l;
    uint64_t samplerate;
    int num_probes;

    ctx = malloc(sizeof(struct context));
    o->internal = ctx;
    ctx->num_enabled_probes = 0;
    for(l = o->device->probes; l; l = l->next) {
        probe = l->data;
        if(probe->enabled)
            ctx->probelist[ctx->num_enabled_probes++] = probe->name;
    }
    ctx->probelist[ctx->num_enabled_probes] = 0;
    ctx->unitsize = (ctx->num_enabled_probes + 7) / 8;
    ctx->spl_cnt = 0;
    if(o->param && o->param[0])
        ctx->samples_per_line = strtoul(o->param, NULL, 10);
    else
        ctx->samples_per_line = default_spl;

    ctx->header = malloc(512);
    num_probes = g_slist_length(o->device->probes);
    samplerate = *((uint64_t *) o->device->plugin->get_device_info(o->device->plugin_index, DI_CUR_SAMPLE_RATE));
    snprintf(ctx->header, 512, "Acquisition with %d/%d probes at ", ctx->num_enabled_probes, num_probes);
    if(samplerate >= GHZ(1))
        snprintf(ctx->header + strlen(ctx->header), 512, "%"PRId64" GHz", samplerate / 1000000000);
    else if(samplerate >= MHZ(1))
        snprintf(ctx->header + strlen(ctx->header), 512, "%"PRId64" MHz", samplerate / 1000000);
    else if(samplerate >= KHZ(1))
        snprintf(ctx->header + strlen(ctx->header), 512, "%"PRId64" KHz", samplerate / 1000);
    else
        snprintf(ctx->header + strlen(ctx->header), 512, "%"PRId64" Hz", samplerate);
    snprintf(ctx->header + strlen(ctx->header), 512, "\n");

    ctx->linebuf_len = ctx->samples_per_line * 2;
    ctx->linebuf = calloc(1, num_probes * ctx->linebuf_len);
    ctx->linevalues = calloc(1, num_probes);

}
コード例 #8
0
ファイル: clock.c プロジェクト: mustafak9/photon-android
static int new_pc_clk_set_rate(unsigned id, unsigned rate)
{
// Cotulla: I am too lazy...
#define MHZ(x)  ((x) * 1000 * 1000)
#define KHZ(x)  ((x) * 1000)

    unsigned clk = -1;
    unsigned speed = 0;
    switch (id)
    {
    case UART1DM_CLK:
        	if (rate > 58982400) speed = 14;
        else if (rate > 56000000) speed = 13;
        else if (rate > 54613300) speed = 12;
        else if (rate > 51200000) speed = 11;
        else if (rate > 46400000) speed = 10;
        else if (rate > 48000000) speed = 9;
        else if (rate > 40000000) speed = 8;
        else if (rate > 32000000) speed = 7;
        else if (rate > 24000000) speed = 6;
        else if (rate > 19200000) speed = 5;
        else if (rate > 16000000) speed = 4;
        else if (rate > 14745600) speed = 3;
        else if (rate >  7372800) speed = 2;
        else if (rate >  3686400) speed = 1;
        else speed = 0;
        clk = 112;
        break;
    case UART2DM_CLK:
             if (rate > 58982400) speed = 14;
        else if (rate > 56000000) speed = 13;
        else if (rate > 54613300) speed = 12;
        else if (rate > 51200000) speed = 11;
        else if (rate > 46400000) speed = 10;
        else if (rate > 48000000) speed = 9;
        else if (rate > 40000000) speed = 8;
        else if (rate > 32000000) speed = 7;
        else if (rate > 24000000) speed = 6;
        else if (rate > 19200000) speed = 5;
        else if (rate > 16000000) speed = 4;
        else if (rate > 14745600) speed = 3;
        else if (rate >  7372800) speed = 2;
        else if (rate >  3686400) speed = 1;
        else speed = 0;
        clk = 114;
        break;

 /*
    case VFE_MDC_CLK:
        if (rate == 96000000) speed = 37;
        else if (rate == 48000000) speed = 32;
        else if (rate == 24000000) speed = 22;
        else if (rate == 12000000) speed = 14;
        else if (rate ==  6000000) speed = 6;
        else if (rate ==  3000000) speed = 1;
        else 
        {
            printk("wrong MDC clock %d\n", rate);
            return 0;
        }
        clk = 40;
        break;

    case VFE_CLK:
        if (rate == 36000000) speed = 1;
        else if (rate == 48000000) speed = 2;
        else if (rate == 64000000) speed = 3;
        else if (rate == 78000000) speed = 4;
        else if (rate == 96000000) speed = 5;
        else 
        {
            printk("wrong clock %d\n", rate);
            return 0;
        }
        clk = 41;
        break;

	case SPI_CLK:
		if (rate > 15360000) speed = 5;
		else if (rate > 9600000) speed = 4;
		else if (rate > 4800000) speed = 3;
		else if (rate >  960000) speed = 2;
		else speed = 1;
		clk = 95;
		break;
 */

    case SDC1_CLK:
             if (rate > MHZ(40)) speed = 7;
        else if (rate > MHZ(25)) speed = 6;
        else if (rate > MHZ(20)) speed = 5;
        else if (rate > MHZ(17)) speed = 4;
        else if (rate > MHZ(16)) speed = 3;
        else if (rate > KHZ(400))speed = 2;
        else if (rate > KHZ(144))speed = 1;
        else speed = 0;
        clk = 93;
        break;
    case SDC2_CLK:
             if (rate > MHZ(40)) speed = 7;
        else if (rate > MHZ(25)) speed = 6;
        else if (rate > MHZ(20)) speed = 5;
        else if (rate > MHZ(17)) speed = 4;
        else if (rate > MHZ(16)) speed = 3;
        else if (rate > KHZ(400))speed = 2;
        else if (rate > KHZ(144))speed = 1;
        else speed = 0;
        clk = 94;
        break;

#undef MHZ
#undef KHZ

        // both none
    case SDC1_PCLK:
    case SDC2_PCLK:
        return 0;
        break;

    default:
        return -1;  
    }

#ifdef ENABLE_CLOCK_INFO
	printk("clk_rate %d : %d\n", clk, speed);
#endif
//    msm_proc_comm(PCOM_CLK_REGIME_SEC_SEL_SPEED, &clk, &speed);
    return 0;
}
コード例 #9
0
};

#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))

#define KHZ(x)	((x)*1000)

#define E4K_PLL_Y		65536

struct pll_settings {
	uint32_t freq;
	uint8_t reg_synth7;
	uint8_t mult;
};

static const struct pll_settings pll_vars[] = {
	{KHZ(72400),	(1 << 3) | 7,	48},
	{KHZ(81200),	(1 << 3) | 6,	40},
	{KHZ(108300),	(1 << 3) | 5,	32},
	{KHZ(162500),	(1 << 3) | 4,	24},
	{KHZ(216600),	(1 << 3) | 3,	16},
	{KHZ(325000),	(1 << 3) | 2,	12},
	{KHZ(350000),	(1 << 3) | 1,	8},
	{KHZ(432000),	(0 << 3) | 3,	8},
	{KHZ(667000),	(0 << 3) | 2,	6},
	{KHZ(1200000),	(0 << 3) | 1,	4}
};

/* \brief compute Fvco based on Fosc, Z and X
 * \returns positive value (Fvco in Hz), 0 in case of error */
static uint64_t compute_fvco(uint32_t f_osc, uint8_t z, uint16_t x)
{
コード例 #10
0
ファイル: saleae-logic.c プロジェクト: esden/sigrok
};

/* list of struct usb_device_instance, maintained by opendev() and closedev() */
GSList *usb_devices = NULL;

/* since we can't keep track of a Saleae Logic device after upgrading the
 * firmware -- it re-enumerates into a different device address after the
 * upgrade -- this is like a global lock. No device will open until a proper
 * delay after the last device was upgraded.
 */
GTimeVal firmware_updated = {0};

libusb_context *usb_context = NULL;

uint64_t supported_sample_rates[] = {
	KHZ(200),
	KHZ(250),
	KHZ(500),
	MHZ(1),
	MHZ(2),
	MHZ(4),
	MHZ(8),
	MHZ(12),
	MHZ(16),
	MHZ(24),
	0
};

/* TODO: all of these should go in a device-specific struct */
uint64_t cur_sample_rate = 0;
uint64_t limit_samples = 0;
コード例 #11
0
//
// main task
//
int main(void) {

#ifdef DEBUG
#if __USE_USB
	usbCDC ser;
	ser.connect();
#else
	CSerial ser;
	ser.settings(115200);
#endif
	CDebug dbg(ser);
	dbg.start();
#endif

	/*************************************************************************
	 *
	 *                         your setup code here
	 *
	 **************************************************************************/
	//
	// Load Configuration
	//
	EEPROM::read(0, &config, sizeof(config));
	if ( config.length!=sizeof(config) ) {
		setDefault();
	}

	// class default I2C address is 0x68
	// specific I2C addresses may be passed as a parameter here
	// AD0 low = 0x68 (default for InvenSense evaluation board)
	// AD0 high = 0x69
	MPU6050 mpu;

	// initialize device
	mpu.initialize();
	mpu.setRate(7);
	mpu.setFullScaleGyroRange(MPU6050_GYRO_FS_250);
	mpu.setFullScaleAccelRange(MPU6050_ACCEL_FS_2);

	//
	// check device
	//
	if (mpu.testConnection()) {
	}

	//
	// H-Bridge
	//
	CPwm::frequency(KHZ(20));

	HBridge left(PWM1, P18, P19);
	HBridge right(PWM2, P22, P23);

	left.enable();
	right.enable();

	BalanceRobot robot(mpu, left, right);
	robot.start("Robot", 168, PRI_HIGH);

#ifndef DEBUG
	myMenu menu(mpu, robot);
	menu.start();
#endif


	while (1) {
		/**********************************************************************
		 *
		 *                         your loop code here
		 *
		 **********************************************************************/

		LEDs[0] = !LEDs[0];
		sleep(500);
	}
	return 0;