From 8b142d0af41b9acfb0d8ece6c92cffc50a83a968 Mon Sep 17 00:00:00 2001 From: takemasa Date: Fri, 28 Dec 2012 23:00:23 +0900 Subject: [PATCH] =?utf8?q?I2C=E3=81=AE=E3=82=A8=E3=83=A9=E3=83=BC=E8=A1=A8?= =?utf8?q?=E7=A4=BA=E5=87=A6=E7=90=86=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=97?= =?utf8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- uzume_prototype/kernel/uzume/ad7999.c | 4 ++-- uzume_prototype/kernel/uzume/i2c_subsystem.c | 23 +++++++++++++++++++++++ uzume_prototype/kernel/uzume/i2c_subsystem.h | 21 ++++++++++++++++++--- uzume_prototype/kernel/uzume/ssm2603.c | 2 +- 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/uzume_prototype/kernel/uzume/ad7999.c b/uzume_prototype/kernel/uzume/ad7999.c index 39fc6dc..efc27ab 100644 --- a/uzume_prototype/kernel/uzume/ad7999.c +++ b/uzume_prototype/kernel/uzume/ad7999.c @@ -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); diff --git a/uzume_prototype/kernel/uzume/i2c_subsystem.c b/uzume_prototype/kernel/uzume/i2c_subsystem.c index dc60c11..0736bb1 100644 --- a/uzume_prototype/kernel/uzume/i2c_subsystem.c +++ b/uzume_prototype/kernel/uzume/i2c_subsystem.c @@ -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 ) { diff --git a/uzume_prototype/kernel/uzume/i2c_subsystem.h b/uzume_prototype/kernel/uzume/i2c_subsystem.h index f929ef0..a05f78c 100644 --- a/uzume_prototype/kernel/uzume/i2c_subsystem.h +++ b/uzume_prototype/kernel/uzume/i2c_subsystem.h @@ -42,15 +42,30 @@ /** * \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マスターモードの割り込みサービスルーチン diff --git a/uzume_prototype/kernel/uzume/ssm2603.c b/uzume_prototype/kernel/uzume/ssm2603.c index 9020c71..96a5aca 100644 --- a/uzume_prototype/kernel/uzume/ssm2603.c +++ b/uzume_prototype/kernel/uzume/ssm2603.c @@ -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 )); } } -- 2.11.0