OSDN Git Service

I2Cのエラー表示処理を追加した
authortakemasa <suikan@users.sourceforge.jp>
Fri, 28 Dec 2012 14:00:23 +0000 (23:00 +0900)
committertakemasa <suikan@users.sourceforge.jp>
Fri, 28 Dec 2012 14:00:23 +0000 (23:00 +0900)
uzume_prototype/kernel/uzume/ad7999.c
uzume_prototype/kernel/uzume/i2c_subsystem.c
uzume_prototype/kernel/uzume/i2c_subsystem.h
uzume_prototype/kernel/uzume/ssm2603.c

index 39fc6dc..efc27ab 100644 (file)
@@ -56,11 +56,11 @@ void ad7999_task(VP_INT exinf)
 
     while(1)
     {
-        i2c_master_read(UZUME_AD7999_I2C_PORT, UZUME_AD7999_I2C_ADRS, adcbuf, 2);
+        i2ccall(i2c_master_read(UZUME_AD7999_I2C_PORT, UZUME_AD7999_I2C_ADRS, adcbuf, 2));
 
             /* 上位バイトのbit 5:4 をチャンネル番号として受け取る */
         ch = ( adcbuf[0] & 0x30 ) >> 4;
-            /*上位バイトのbit 3;0と買いバイトから12bitのADCデータを作る。そのデータを32bitに左詰めする */
+            /*上位バイトのbit 3;0と下位バイトから12bitのADCデータを作る。そのデータを32bitに左詰めする */
 
         /* 排他区間開始 */
         wai_sem(AD7999_SEM);
index dc60c11..0736bb1 100644 (file)
@@ -87,6 +87,29 @@ struct I2C_MASTER_CONTROL_TYPE {
  */
 static struct I2C_MASTER_CONTROL_TYPE i2c_control[I2CNUM];
 
+static char * i2c_strerror( ER ercd )
+{
+    ercd &= 0xFFFF0000;
+    switch (ercd)
+    {
+    case I2C_ERR_WRONGPARAM :
+        return("I2C_ERR_WRONGPARAM");
+    case I2C_ERR_TOOLONGBUFFER :
+        return("I2C_ERR_TOOLONGBUFFER");
+    case I2C_ERR_TIMEOUT :
+        return ("I2C_ERR_TIMEOUT");
+    }
+    return ("I2C_ERR_UNKNOWN");
+}
+
+
+void
+i2c_perror(UINT prio, const char *file, int line, const char *expr, ER ercd)
+{
+    syslog_5(prio, "%s reported by `%s' in line %d of `%s'. Interrupt Status = %04x",
+        i2c_strerror(ercd), expr, line, file, ercd & 0xFFFF);
+}
+
 
 int i2c_master_write( int peripheral, int slave, unsigned char write_data[], int write_count )
 {
index f929ef0..a05f78c 100644 (file)
 /**
  * \brief TWIデバイス制御関数への引き数値が間違っている。
  */
-#define I2C_ERR_WRONGPARAM      0x4000
+#define I2C_ERR_WRONGPARAM      0x40000
 /**
  * \brief TWIデバイス制御関数へ指定した送受信データ長が長すぎる。
  */
-#define I2C_ERR_TOOLONGBUFFER   0x2000
+#define I2C_ERR_TOOLONGBUFFER   0x20000
 /**
  * \brief TWIデバイスがタイムアウトした。
  */
-#define I2C_ERR_TIMEOUT     0x1000
+#define I2C_ERR_TIMEOUT     0x10000
+
+extern void i2c_perror(UINT prio, const char *file, int line,
+                    const char *expr, ER ercd) throw();
+
+Inline ER
+_i2c_perror(const char *file, int line, const char *expr, ER ercd)
+{
+    if (ercd < 0) {
+        i2c_perror(LOG_ERROR, file, line, expr, ercd);
+    }
+    return(ercd);
+}
+
+#define i2ccall(s)  _t_perror(__FILE__, __LINE__, #s, (s))
+
 
 /**
  * \brief i2cマスターモードの割り込みサービスルーチン
index 9020c71..96a5aca 100644 (file)
@@ -76,7 +76,7 @@ void init_codec()
 
                 /* TLV320AIC23Bに初期化データを送信する */
         for ( i=0; i< CODECINITDATALEN; i++){
-                i2c_master_write( UZUME_SSM2603_I2C_PORT, UZUME_SSM2603_I2C_ADRS, tlv320aic23init[i], 2 );
+                i2ccall(i2c_master_write( UZUME_SSM2603_I2C_PORT, UZUME_SSM2603_I2C_ADRS, tlv320aic23init[i], 2 ));
         }
 }