Add missing avr prj to nightly test.
[bertos.git] / bertos / cpu / arm / drv / i2c_lpc2.c
index 33ad6cac195b1f8f34ef90dcc7c1e4c8bed85074..fd6a9fda45237c4a47d05225e852485b86101ce7 100644 (file)
@@ -32,6 +32,7 @@
  *
  * \brief Driver for the LPC23xx I2C (implementation)
  *
+ * \author Daniele Basile <asterix@develer.com>
  */
 
 #include "cfg/cfg_i2c.h"
 
 #include <cfg/debug.h>
 #include <cfg/macros.h> // BV()
-#include <cfg/module.h>
 
 #include <cpu/detect.h>
 #include <cpu/irq.h>
+#include <cpu/power.h>
 
 #include <drv/timer.h>
 #include <drv/i2c.h>
-#include <drv/vic_lpc2.h> /* vic_handler_t */
 
 #include <io/lpc23xx.h>
 
-#include <stdarg.h>
-
-
 struct I2cHardware
 {
        uint32_t base;
@@ -77,17 +74,18 @@ struct I2cHardware
  * routine to do in that case.
  */
 #define WAIT_SI(i2c) \
-       do { \
-               ticks_t start = timer_clock(); \
-               while( !(HWREG(i2c->hw->base + I2C_CONSET_OFF) & BV(I2CON_SI)) ) \
-               { \
-                       if (timer_clock() - start > ms_to_ticks(CONFIG_I2C_START_TIMEOUT)) \
+               do { \
+                       ticks_t start = timer_clock(); \
+                       while( !(HWREG(i2c->hw->base + I2C_CONSET_OFF) & BV(I2CON_SI)) ) \
                        { \
-                               LOG_ERR("Timeout SI assert\n"); \
-                               LOG_ERR("[%08lx]\n", HWREG(i2c->hw->base + I2C_STAT_OFF)); \
-                               break; \
+                               if (timer_clock() - start > ms_to_ticks(CONFIG_I2C_START_TIMEOUT)) \
+                               { \
+                                       LOG_ERR("Timeout SI assert\n"); \
+                                       LOG_ERR("[%08lx]\n", HWREG(i2c->hw->base + I2C_STAT_OFF)); \
+                                       break; \
+                               } \
+                               cpu_relax(); \
                        } \
-               } \
        } while (0)
 
 static void i2c_hw_restart(I2c *i2c)
@@ -110,7 +108,7 @@ static void i2c_hw_stop(I2c *i2c)
        HWREG(i2c->hw->base + I2C_CONCLR_OFF) = BV(I2CON_STAC) | BV(I2CON_SIC) | BV(I2CON_AAC);
 }
 
-static void i2c_lpc2_put(I2c *i2c, uint8_t data)
+static void i2c_lpc2_putc(I2c *i2c, uint8_t data)
 {
        HWREG(i2c->hw->base + I2C_DAT_OFF) = data;
        HWREG(i2c->hw->base + I2C_CONCLR_OFF) = BV(I2CON_SIC);
@@ -141,7 +139,7 @@ static void i2c_lpc2_put(I2c *i2c, uint8_t data)
        }
 }
 
-static uint8_t i2c_lpc2_get(I2c *i2c)
+static uint8_t i2c_lpc2_getc(I2c *i2c)
 {
        /*
         * Set ack bit if we want read more byte, otherwise
@@ -184,8 +182,6 @@ static uint8_t i2c_lpc2_get(I2c *i2c)
        return 0xFF;
 }
 
-MOD_DEFINE(i2c);
-
 static void i2c_lpc2_start(struct I2c *i2c, uint16_t slave_addr)
 {
        if (I2C_TEST_START(i2c->flags) == I2C_START_W)
@@ -263,13 +259,13 @@ static void i2c_lpc2_start(struct I2c *i2c, uint16_t slave_addr)
 static const I2cVT i2c_lpc_vt =
 {
        .start = i2c_lpc2_start,
-       .get = i2c_lpc2_get,
-       .put = i2c_lpc2_put,
-       .send = i2c_swSend,
-       .recv = i2c_swRecv,
+       .getc = i2c_lpc2_getc,
+       .putc = i2c_lpc2_putc,
+       .write = i2c_genericWrite,
+       .read = i2c_genericRead,
 };
 
-struct I2cHardware i2c_lpc2_hw[] =
+static struct I2cHardware i2c_lpc2_hw[] =
 {
        { /* I2C0 */
                .base = I2C0_BASE_ADDR,
@@ -337,6 +333,4 @@ void i2c_hw_init(I2c *i2c, int dev, uint32_t clock)
 
        // Enable I2C
        HWREG(i2c->hw->base + I2C_CONSET_OFF) = BV(I2CON_I2EN);
-
-       MOD_INIT(i2c);
 }