x86, galileo: Refactor I2C and GPIO initialization

This patch revises the I2C and GPIO initialization code to always be
run during platform boot rather than within each process that requires
it.

This patch also revises the gpio-output example to use a pin that is
set as an output by the default pinmux configuration.  Previously, it
used a pin that was set as an output by the pinmux configuration that
is in effect when the OS does not change the pinmux configuration.
This commit is contained in:
Michael LeMay 2016-01-05 23:05:09 -08:00
parent 3e64447631
commit 58874ea25d
10 changed files with 54 additions and 70 deletions

View file

@ -54,6 +54,15 @@ typedef enum {
I2C_DIRECTION_WRITE
} I2C_DIRECTION;
struct quarkX1000_i2c_config {
QUARKX1000_I2C_SPEED speed;
QUARKX1000_I2C_ADDR_MODE addressing_mode;
quarkX1000_i2c_callback cb_rx;
quarkX1000_i2c_callback cb_tx;
quarkX1000_i2c_callback cb_err;
};
struct i2c_internal_data {
struct quarkX1000_i2c_config config;
@ -223,17 +232,15 @@ i2c_isr(void)
return handled;
}
int
quarkX1000_i2c_configure(struct quarkX1000_i2c_config *config)
void
quarkX1000_i2c_configure(QUARKX1000_I2C_SPEED speed,
QUARKX1000_I2C_ADDR_MODE addressing_mode)
{
uint32_t hcnt, lcnt;
uint8_t ic_fs_spklen;
device.config.speed = config->speed;
device.config.addressing_mode = config->addressing_mode;
device.config.cb_rx = config->cb_rx;
device.config.cb_tx = config->cb_tx;
device.config.cb_err = config->cb_err;
device.config.speed = speed;
device.config.addressing_mode = addressing_mode;
if (device.config.speed == QUARKX1000_I2C_SPEED_STANDARD) {
lcnt = I2C_STD_LCNT;
@ -252,8 +259,16 @@ quarkX1000_i2c_configure(struct quarkX1000_i2c_config *config)
/* Clear interrupts. */
read(QUARKX1000_IC_CLR_INTR);
}
return 0;
void
quarkX1000_i2c_set_callbacks(quarkX1000_i2c_callback rx,
quarkX1000_i2c_callback tx,
quarkX1000_i2c_callback err)
{
device.config.cb_rx = rx;
device.config.cb_tx = tx;
device.config.cb_err = err;
}
static int

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015, Intel Corporation. All rights reserved.
* Copyright (C) 2015-2016, Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -45,17 +45,12 @@ typedef enum {
typedef void (*quarkX1000_i2c_callback)(void);
struct quarkX1000_i2c_config {
QUARKX1000_I2C_SPEED speed;
QUARKX1000_I2C_ADDR_MODE addressing_mode;
quarkX1000_i2c_callback cb_rx;
quarkX1000_i2c_callback cb_tx;
quarkX1000_i2c_callback cb_err;
};
int quarkX1000_i2c_init(void);
int quarkX1000_i2c_configure(struct quarkX1000_i2c_config *config);
void quarkX1000_i2c_configure(QUARKX1000_I2C_SPEED speed,
QUARKX1000_I2C_ADDR_MODE addressing_mode);
void quarkX1000_i2c_set_callbacks(quarkX1000_i2c_callback rx,
quarkX1000_i2c_callback tx,
quarkX1000_i2c_callback err);
int quarkX1000_i2c_is_available(void);
int quarkX1000_i2c_read(uint8_t *buf, uint8_t len, uint16_t addr);

View file

@ -21,10 +21,10 @@ GPIO
### GPIO Output (EXAMPLE=gpio-output)
This application shows how to use the GPIO driver APIs to manipulate output
pins. This application sets the GPIO 4 pin as output pin and toggles its
pins. This application sets the GPIO 5 pin as output pin and toggles its
state at every half second.
For a visual effect, you should wire shield pin IO1 to a led in a protoboard.
For a visual effect, you should wire shield pin IO2 to a led in a protoboard.
Once the application is running, you should see a blinking LED.
### GPIO Input (EXAMPLE=gpio-input)

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015, Intel Corporation. All rights reserved.
* Copyright (C) 2015-2016, Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -33,16 +33,13 @@
#include "contiki.h"
#include "sys/ctimer.h"
#include "galileo-pinmux.h"
#include "gpio.h"
#include "i2c.h"
#define PIN_OUTPUT 5
#define PIN_INPUT 6
static uint32_t value;
static struct ctimer timer;
static struct quarkX1000_i2c_config i2c_config;
PROCESS(gpio_input_process, "GPIO Input Process");
AUTOSTART_PROCESSES(&gpio_input_process);
@ -70,16 +67,6 @@ PROCESS_THREAD(gpio_input_process, ev, data)
{
PROCESS_BEGIN();
i2c_config.speed = QUARKX1000_I2C_SPEED_STANDARD;
i2c_config.addressing_mode = QUARKX1000_I2C_ADDR_MODE_7BIT;
quarkX1000_i2c_init();
quarkX1000_i2c_configure(&i2c_config);
/* use default pinmux configuration */
galileo_pinmux_initialize();
quarkX1000_gpio_init();
quarkX1000_gpio_config(PIN_OUTPUT, QUARKX1000_GPIO_OUT);
quarkX1000_gpio_config(PIN_INPUT, QUARKX1000_GPIO_IN);

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015, Intel Corporation. All rights reserved.
* Copyright (C) 2015-2016, Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -34,14 +34,11 @@
#include "sys/ctimer.h"
#include "gpio.h"
#include "i2c.h"
#include "galileo-pinmux.h"
#define PIN_OUTPUT 5
#define PIN_INTR 6
static struct ctimer timer;
static struct quarkX1000_i2c_config i2c_config;
PROCESS(gpio_interrupt_process, "GPIO Interrupt Process");
AUTOSTART_PROCESSES(&gpio_interrupt_process);
@ -66,16 +63,6 @@ PROCESS_THREAD(gpio_interrupt_process, ev, data)
{
PROCESS_BEGIN();
i2c_config.speed = QUARKX1000_I2C_SPEED_STANDARD;
i2c_config.addressing_mode = QUARKX1000_I2C_ADDR_MODE_7BIT;
quarkX1000_i2c_init();
quarkX1000_i2c_configure(&i2c_config);
/* use default pinmux configuration */
galileo_pinmux_initialize();
quarkX1000_gpio_init();
quarkX1000_gpio_config(PIN_OUTPUT, QUARKX1000_GPIO_OUT);
quarkX1000_gpio_config(PIN_INTR, QUARKX1000_GPIO_INT | QUARKX1000_GPIO_ACTIVE_HIGH | QUARKX1000_GPIO_EDGE);

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015, Intel Corporation. All rights reserved.
* Copyright (C) 2015-2016, Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -35,7 +35,7 @@
#include "gpio.h"
#define PIN 4 /* IO1 */
#define PIN 5 /* IO2 */
static uint32_t value;
static struct ctimer timer;
@ -57,7 +57,6 @@ PROCESS_THREAD(gpio_output_process, ev, data)
{
PROCESS_BEGIN();
quarkX1000_gpio_init();
quarkX1000_gpio_config(PIN, QUARKX1000_GPIO_OUT);
quarkX1000_gpio_clock_enable();

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015, Intel Corporation. All rights reserved.
* Copyright (C) 2015-2016, Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -34,7 +34,6 @@
#include "contiki.h"
#include "sys/ctimer.h"
#include "galileo-pinmux.h"
#include "i2c.h"
#define LSM9DS0_I2C_ADDR 0x6A
@ -44,7 +43,6 @@
static uint8_t tx_data = WHO_AM_I_ADDR;
static uint8_t rx_data = 0;
static struct ctimer timer;
static struct quarkX1000_i2c_config cfg;
PROCESS(i2c_lsm9ds0_process, "I2C LSM9DS0 Who Am I Process");
AUTOSTART_PROCESSES(&i2c_lsm9ds0_process);
@ -84,19 +82,7 @@ PROCESS_THREAD(i2c_lsm9ds0_process, ev, data)
{
PROCESS_BEGIN();
cfg.speed = QUARKX1000_I2C_SPEED_STANDARD;
cfg.addressing_mode = QUARKX1000_I2C_ADDR_MODE_7BIT;
quarkX1000_i2c_init();
quarkX1000_i2c_configure(&cfg);
galileo_pinmux_initialize();
cfg.cb_rx = rx;
cfg.cb_tx = tx;
cfg.cb_err = err;
quarkX1000_i2c_configure(&cfg);
quarkX1000_i2c_set_callbacks(rx, tx, err);
ctimer_set(&timer, CLOCK_SECOND * 5, timeout, NULL);

View file

@ -30,6 +30,9 @@ Device drivers:
* Real-Time Clock (RTC)
* UART
* Ethernet
* I2C
* GPIO (default pinmux configuration is listed in
platform/galileo/drivers/galileo-pinmux.c)
Contiki APIs:
* Clock module

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015, Intel Corporation. All rights reserved.
* Copyright (C) 2015-2016, Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -34,6 +34,9 @@
#include "contiki-net.h"
#include "cpu.h"
#include "eth-conf.h"
#include "galileo-pinmux.h"
#include "gpio.h"
#include "i2c.h"
#include "interrupt.h"
#include "shared-isr.h"
#include "uart.h"
@ -56,6 +59,15 @@ main(void)
printf("Starting Contiki\n");
quarkX1000_i2c_init();
quarkX1000_i2c_configure(QUARKX1000_I2C_SPEED_STANDARD,
QUARKX1000_I2C_ADDR_MODE_7BIT);
/* use default pinmux configuration */
if(galileo_pinmux_initialize() < 0) {
fprintf(stderr, "Failed to initialize pinmux\n");
}
quarkX1000_gpio_init();
ENABLE_IRQ();
process_init();

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 2015, Intel Corporation. All rights reserved.
* Copyright (C) 2015-2016, Intel Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions