Commit eec21b2ab8534bca63146a72ba5223defc4a1d17
authorMichel Pollet <buserror@gmail.com>
Tue, 2 Jul 2013 11:18:29 +0000 (12:18 +0100)
committerMichel Pollet <buserror@gmail.com>
Thu, 5 Sep 2013 12:58:31 +0000 (13:58 +0100)
Applies naming convention to globals, types etc.

3 files changed:
simavr/sim/avr_twi.c
simavr/sim/sim_avr.c
simavr/sim/sim_avr.h

index 592e7b1d975aea97afdb800dd59ae7d10f295007..1b4b8ea7406f0f8f23ae0f5d14e3274941139537 100644 (file)
@@ -79,7 +79,7 @@ _avr_twi_status_set(
 {
        avr_regbit_setto_raw(p->io.avr, p->twsr, v);
 #if AVR_TWI_DEBUG
-       printf("_avr_twi_status_set %02x\n", v);
+       AVR_TRACE(avr, "%s %02x\n", __func__, v);
 #endif
        avr_raise_irq(p->io.irq + TWI_IRQ_STATUS, v);
        if (interrupt)
@@ -139,7 +139,8 @@ avr_twi_write(
 
        avr_core_watch_write(avr, addr, v);
 #if AVR_TWI_DEBUG
-       printf("avr_twi_write %02x START:%d STOP:%d ACK:%d INT:%d TWSR:%02x (state %02x)\n", v,
+       AVR_TRACE(avr, "%s %02x START:%d STOP:%d ACK:%d INT:%d TWSR:%02x (state %02x)\n", 
+                       __func__, v,
                        avr_regbit_get(avr, p->twsta),
                        avr_regbit_get(avr, p->twsto),
                        avr_regbit_get(avr, p->twea),
@@ -158,9 +159,9 @@ avr_twi_write(
                        p->state = 0;
                        p->peer_addr = 0;
                }
-               printf("TWEN: %d\n", twen);
+               AVR_TRACE(avr, "TWEN: %d\n", twen);
                if (avr->data[p->r_twar]) {
-                       printf("TWEN Slave: %02x & %02x\n", avr->data[p->r_twar], avr->data[p->r_twamr]);
+                       AVR_TRACE(avr, "TWEN Slave: %02x & %02x\n", avr->data[p->r_twar], avr->data[p->r_twamr]);
                }
        }
        if (!twen)
@@ -169,12 +170,12 @@ avr_twi_write(
        uint8_t cleared = avr_regbit_get(avr, p->twi.raised);
 
        /*int cleared = */avr_clear_interrupt_if(avr, &p->twi, twint);
-//     printf("cleared %d\n", cleared);
+//     AVR_TRACE(avr, "cleared %d\n", cleared);
 
        if (!twsto && avr_regbit_get(avr, p->twsto)) {
                // generate a stop condition
 #if AVR_TWI_DEBUG
-               printf("<<<<< I2C stop\n");
+               AVR_TRACE(avr, "<<<<< I2C stop\n");
 #endif
                if (p->state) { // doing stuff
                        if (p->state & TWI_COND_START) {
@@ -186,7 +187,7 @@ avr_twi_write(
        }
        if (!twsta && avr_regbit_get(avr, p->twsta)) {
 #if AVR_TWI_DEBUG
-               printf(">>>>> I2C %sstart\n", p->state & TWI_COND_START ? "RE" : "");
+               AVR_TRACE(avr, ">>>>> I2C %sstart\n", p->state & TWI_COND_START ? "RE" : "");
 #endif
                // generate a start condition
                if (p->state & TWI_COND_START)
@@ -205,9 +206,9 @@ avr_twi_write(
                        int do_read = p->peer_addr & 1;
 #if AVR_TWI_DEBUG
                        if (do_read)
-                               printf("I2C READ byte from %02x\n", p->peer_addr);
+                               AVR_TRACE(avr, "I2C READ byte from %02x\n", p->peer_addr);
                        else
-                               printf("I2C WRITE byte %02x to %02x\n", avr->data[p->r_twdr], p->peer_addr);
+                               AVR_TRACE(avr, "I2C WRITE byte %02x to %02x\n", avr->data[p->r_twdr], p->peer_addr);
 #endif
                        // a normal data byte
                        uint8_t msgv = do_read ? TWI_COND_READ : TWI_COND_WRITE;
@@ -238,11 +239,11 @@ avr_twi_write(
                        }
 #if AVR_TWI_DEBUG
                        else
-                               printf("I2C latch is not ready, do nothing\n");
+                               AVR_TRACE(avr, "I2C latch is not ready, do nothing\n");
 #endif
                } else {
 #if AVR_TWI_DEBUG
-                       printf("I2C Master address %02x\n", avr->data[p->r_twdr]);
+                       AVR_TRACE(avr, "I2C Master address %02x\n", avr->data[p->r_twdr]);
 #endif
                        // send the address
                        p->state |= TWI_COND_ADDR;
@@ -347,7 +348,7 @@ avr_twi_irq_input(
                p->peer_addr = 0;
                if (msg.u.twi.msg & TWI_COND_ADDR) {
                        uint8_t mask = ~avr->data[p->r_twamr] >> 1;
-                       printf("I2C slave start %2x (want %02x&%02x)\n",
+                       AVR_TRACE(avr, "I2C slave start %2x (want %02x&%02x)\n",
                                msg.u.twi.addr, avr->data[p->r_twar] >> 1, mask);
                        p->peer_addr = msg.u.twi.addr & mask;
                        if (p->peer_addr == ((avr->data[p->r_twar] >> 1) & mask)) {
@@ -359,7 +360,7 @@ avr_twi_irq_input(
                        }
                } else {
                        // "general call" address
-                       printf("I2C slave start without address?\n");
+                       AVR_TRACE(avr, "I2C slave start without address?\n");
                        if (avr->data[p->r_twar] & 1) {
                        }
                }
@@ -372,7 +373,7 @@ avr_twi_irq_input(
        // receiving an acknowledge bit
        if (msg.u.twi.msg & TWI_COND_ACK) {
 #if AVR_TWI_DEBUG
-               printf("I2C received ACK:%d\n", msg.u.twi.data & 1);
+               AVR_TRACE(avr, "I2C received ACK:%d\n", msg.u.twi.data & 1);
 #endif
                if (msg.u.twi.data & 1)
                        p->state |= TWI_COND_ACK;
@@ -382,7 +383,7 @@ avr_twi_irq_input(
        // receive a data byte from a slave
        if (msg.u.twi.msg & TWI_COND_READ) {
 #if AVR_TWI_DEBUG
-               printf("I2C received %02x\n", msg.u.twi.data);
+               AVR_TRACE(avr, "I2C received %02x\n", msg.u.twi.data);
 #endif
                avr->data[p->r_twdr] = msg.u.twi.data;
        }
index d8591b0c311d7b12c35a5eafba175d52dcf6e419..6ece88d84790d60710ac1e3e0c9bd91a7fa6aab3 100644 (file)
@@ -36,7 +36,7 @@
 #include "sim_core_decl.h"
 
 static void std_logger(avr_t * avr, const int level, const char * format, ...);
-logger_t global_logger = std_logger;
+avr_logger_p avr_global_logger = std_logger;
 
 int avr_init(avr_t * avr)
 {
@@ -157,8 +157,7 @@ static void _avr_io_console_write(struct avr_t * avr, avr_io_addr_t addr, uint8_
 
        if (v == '\r' && buf) {
                buf[len] = 0;
-               AVR_LOG(avr, LOG_TRACE, "O:" "%s" "" "\n", buf);
-               fflush(stdout);
+               AVR_LOG(avr, LOG_OUTPUT, "O:" "%s" "" "\n", buf);
                len = 0;
                return;
        }
index ceeea52d5a826b907ec3bb6a61839a86ea4f9efa..f391902e31910d366738dc3a5ca6b2997f2d556d 100644 (file)
@@ -66,18 +66,22 @@ enum {
  * The current log level is kept in avr->log.
  */
 enum {
-       LOG_ERROR = 1,
+       LOG_OUTPUT = 0,
+       LOG_ERROR,
        LOG_WARNING,
        LOG_TRACE,
 };
-typedef void (*logger_t)(struct avr_t* avr, const int level, const char * format, ... );
-extern logger_t global_logger;
+
+typedef void (*avr_logger_p)(struct avr_t* avr, const int level, const char * format, ... );
+extern avr_logger_p avr_global_logger;
 #ifndef AVR_LOG
 #define AVR_LOG(avr, level, ...) \
        do { \
-               global_logger(avr, level, __VA_ARGS__); \
+               avr_global_logger(avr, level, __VA_ARGS__); \
        } while(0)
 #endif
+#define AVR_TRACE(avr, ... ) \
+       AVR_LOG(avr, LOG_TRACE, __VA_ARGS__)
 
 /*
  * Core states.
@@ -265,7 +269,7 @@ typedef struct avr_t {
        // DEBUG ONLY -- value ignored if CONFIG_SIMAVR_TRACE = 0
        uint8_t trace : 1,
                        log : 2; // log level, default to 1
-
+       
        // Only used if CONFIG_SIMAVR_TRACE is defined
        struct avr_trace_data_t *trace_data;