Commit from zer0 (2007-08-21 23:51 CEST)
----------------
update for i2c
aversive_projects microb2008/extension/main.c 1.5
aversive_projects microb2008/main/.config 1.4
aversive_projects microb2008/main/i2c_protocol.c 1.4
aversive_projects microb2008/main/main.c 1.5
---------------------------------------------
aversive_projects/microb2008/extension/main.c (1.4 -> 1.5)
---------------------------------------------
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: main.c,v 1.4 2007-08-19 10:41:41 zer0 Exp $
+ * Revision : $Id: main.c,v 1.5 2007-08-21 21:51:34 zer0 Exp $
*
*/
@@ -70,8 +70,8 @@
/* i2c */
i2c_init(I2C_MODE_SLAVE, I2C_EXTENSION_ADDR);
i2c_register_recv_event(i2c_recvevent);
- i2c_register_send_event(i2c_sendevent);
- i2c_register_recv_byte_event(i2c_recvbyteevent);
+ //i2c_register_send_event(i2c_sendevent);
+ //i2c_register_recv_byte_event(i2c_recvbyteevent);
/* debug via i2c (um zu gut zu machen) */
fdevopen(debug_send, NULL);
-----------------------------------------
aversive_projects/microb2008/main/.config (1.3 -> 1.4)
-----------------------------------------
@@ -1,5 +1,5 @@
#
-# Automatically generated by make menuconfig: don't edit
+# Automatically generated make config: don't edit
#
#
@@ -70,6 +70,10 @@
#
# Base modules
#
+
+#
+# Enable math library in generation options to see all modules
+#
CONFIG_MODULE_CIRBUF=y
CONFIG_MODULE_FIXED_POINT=y
CONFIG_MODULE_VECT2=y
@@ -82,6 +86,10 @@
#
# Communication modules
#
+
+#
+# uart needs circular buffer, mf2 client may need scheduler
+#
CONFIG_MODULE_UART=y
CONFIG_MODULE_UART_CREATE_CONFIG=y
CONFIG_MODULE_I2C=y
@@ -145,6 +153,10 @@
# Control system modules
#
CONFIG_MODULE_CONTROL_SYSTEM_MANAGER=y
+
+#
+# Filters
+#
CONFIG_MODULE_PID=y
# CONFIG_MODULE_RAMP is not set
CONFIG_MODULE_QUADRAMP=y
@@ -154,6 +166,10 @@
#
# Crypto modules
#
+
+#
+# Crypto modules depend on utils module
+#
# CONFIG_MODULE_AES is not set
# CONFIG_MODULE_AES_CTR is not set
# CONFIG_MODULE_MD5 is not set
@@ -163,12 +179,20 @@
#
# Encodings modules
#
+
+#
+# Encoding modules depend on utils module
+#
# CONFIG_MODULE_BASE64 is not set
# CONFIG_MODULE_HAMMING is not set
#
# Debug modules
#
+
+#
+# Debug modules depend on utils module
+#
# CONFIG_MODULE_DIAGNOSTIC is not set
# CONFIG_MODULE_DIAGNOSTIC_CREATE_CONFIG is not set
CONFIG_MODULE_ERROR=y
------------------------------------------------
aversive_projects/microb2008/main/i2c_protocol.c (1.3 -> 1.4)
------------------------------------------------
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: i2c_protocol.c,v 1.3 2007-08-19 10:41:41 zer0 Exp $
+ * Revision : $Id: i2c_protocol.c,v 1.4 2007-08-21 21:51:34 zer0 Exp $
*
*/
@@ -35,7 +35,14 @@
#include "main.h"
#include "i2c_protocol.h"
-#define I2C_MAX_CONSECUTIVE_ERRORS 100
+#define I2C_MAX_ERRORS 100
+
+static volatile uint8_t i2c_state = 0;
+static volatile uint16_t i2c_errors = 0;
+static volatile uint8_t poll_is_running = 0;
+
+/* XXX */
+extern volatile uint8_t g_status;
void i2c_protocol_init(void)
{
@@ -44,49 +51,82 @@
void i2c_poll_slaves(void * dummy)
{
- static uint8_t state = 0;
- static uint8_t errors = 0;
+ uint8_t flags;
+ int8_t err;
- switch(state) {
+ IRQ_LOCK(flags);
+ poll_is_running ++;
+ switch(i2c_state) {
/* poll debug buffer */
case 0:
- if(i2c_req_read_debug_buffer())
+ if((err=i2c_req_read_debug_buffer()))
goto error;
break;
case 1:
- if(i2c_recv(I2C_EXTENSION_ADDR,
+ if((err=i2c_recv(I2C_EXTENSION_ADDR,
sizeof(struct i2c_ans_write_debug_buffer),
- I2C_CTRL_GENERIC))
+ I2C_CTRL_GENERIC)))
goto error;
break;
/* nothing, loop to the first request */
default:
- state = 0;
- return;
-
+ i2c_state = 0;
}
-
- state ++;
+ IRQ_UNLOCK(flags);
return;
error:
- errors++;
- if (errors > I2C_MAX_CONSECUTIVE_ERRORS) {
+ poll_is_running --;
+ IRQ_UNLOCK(flags);
+ i2c_errors++;
+ if (i2c_errors > I2C_MAX_ERRORS) {
/* XXX use ERROR() log instead */
- printf("I2C error, slave not ready\n");
- errors = 0;
+ printf("I2C error, cannot send %d %d %x\n", i2c_state, err,
g_status);
+ i2c_errors = 0;
+ }
+}
+
+void i2c_sendevent(int8_t size)
+{
+ if (size > 0) {
+ if (poll_is_running) {
+ i2c_state ++;
+ }
+ }
+ else {
+ i2c_errors++;
+ printf("error %d\n", i2c_state);
+ if (i2c_errors > I2C_MAX_ERRORS) {
+ /* XXX use ERROR() log instead */
+ printf("I2C error, slave not ready\n");
+ i2c_errors = 0;
+ }
}
+ poll_is_running = 0;
}
void i2c_recvevent(uint8_t * buf, int8_t size)
{
- if (size < 1) {
- goto error;
+ if (size > 0) {
+ if (poll_is_running) {
+ i2c_state ++;
+ }
+ }
+ else {
+ i2c_errors++;
+ printf("error %d\n", i2c_state);
+ if (i2c_errors > I2C_MAX_ERRORS) {
+ /* XXX use ERROR() log instead */
+ LED2_ON();
+ printf("I2C error, slave not ready\n");
+ i2c_errors = 0;
+ }
}
+ poll_is_running = 0;
switch (buf[0]) {
case I2C_ANS_WRITE_DEBUG_BUFFER:
@@ -96,7 +136,7 @@
(struct i2c_ans_write_debug_buffer * )buf;
if (size != sizeof (*ans))
- goto error;
+ break;
/* we may loose chars here, if the uart fifo is full */
for (i=0 ; i<sizeof(ans->buf) && ans->buf[i] != 0 ;
i++) {
@@ -106,12 +146,8 @@
}
default:
- goto error;
+ break;
}
-
- error:
- /* log error on a led ? */
- return;
}
void i2c_recvbyteevent(uint8_t hwstatus, uint8_t i, uint8_t c)
@@ -123,10 +159,6 @@
/* } */
}
-void i2c_sendevent(int8_t size)
-{
- printf("send event %d\n", size);
-}
/* ******** ******** ******** ******** */
----------------------------------------
aversive_projects/microb2008/main/main.c (1.4 -> 1.5)
----------------------------------------
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: main.c,v 1.4 2007-08-19 10:45:41 zer0 Exp $
+ * Revision : $Id: main.c,v 1.5 2007-08-21 21:51:34 zer0 Exp $
*
*/
@@ -273,7 +273,7 @@
i2c_register_send_event(i2c_sendevent);
/* i2c_register_recv_byte_event(i2c_recvbyteevent); */ /* not needed */
scheduler_add_periodical_event_priority(i2c_poll_slaves, NULL,
- 1000L / SCHEDULER_UNIT,
I2C_POLL_PRIO);
+ 1300L / SCHEDULER_UNIT,
I2C_POLL_PRIO);
/* XXX also remove sei(), put it after all inits */
Commit from zer0 on branch b_zer0 (2007-08-21 23:51 CEST)
---------------------------------
small fixes
aversive modules/comm/i2c/i2c.c 1.1.2.8
-------------------------------
aversive/modules/comm/i2c/i2c.c (1.1.2.7 -> 1.1.2.8)
-------------------------------
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * Revision : $Id: i2c.c,v 1.1.2.7 2007-08-19 10:38:06 zer0 Exp $
+ * Revision : $Id: i2c.c,v 1.1.2.8 2007-08-21 21:51:59 zer0 Exp $
*
*/
@@ -107,7 +107,8 @@
static void (*g_send_event)(int8_t) = NULL;
static volatile i2c_mode_t g_mode = I2C_MODE_UNINIT;
-static volatile uint8_t g_status = I2C_STATUS_READY;
+volatile uint8_t g_status = I2C_STATUS_READY;/* XXX */
+
static volatile uint8_t g_ctrl = 0; /* ctrl flags */
static volatile uint8_t g_sync_res = 0; /* result of sync send */
static uint8_t g_send_buf[I2C_SEND_BUFFER_SIZE];
@@ -375,19 +376,16 @@
IRQ_UNLOCK(flags);
return ENXIO;
}
- LED2_ON();
if (g_status != I2C_STATUS_READY) {
IRQ_UNLOCK(flags);
return EBUSY;
}
- LED3_ON();
if (size > I2C_SEND_BUFFER_SIZE) { /* XXX is size=0 ok ? */
IRQ_UNLOCK(flags);
return EINVAL;
}
- LED4_ON();
if (g_mode == I2C_MODE_SLAVE || dest_add >= I2C_ADD_MASTER) {
IRQ_UNLOCK(flags);
@@ -522,9 +520,15 @@
{
uint8_t hard_status;
uint8_t command = (1<<TWINT) | (1<<TWEN) | (1<<TWIE);
+ static char a=0;
hard_status = TW_STATUS;
+ if(a)
+ LED7_OFF();
+ else
+ LED7_ON();
+ a = !a;
switch(hard_status) {
#ifdef CONFIG_MODULE_I2C_MASTER
_______________________________________________
Avr-list mailing list
[email protected]
CVSWEB : http://cvsweb.droids-corp.org/cgi-bin/viewcvs.cgi/aversive
WIKI : http://wiki.droids-corp.org/index.php/Aversive
DOXYGEN : http://zer0.droids-corp.org/doxygen_aversive/html/
BUGZILLA : http://bugzilla.droids-corp.org
COMMIT LOGS : http://zer0.droids-corp.org/aversive_commitlog