You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mynewt.apache.org by Kevin Townsend <ke...@adafruit.com> on 2016/11/10 00:34:23 UTC

I2C Bus Scan Formatting

I'll put this in a pull request with some of these helper test functions 
later, but I'm just starting to poke at a manufacturing test app that 
can be used to validate all the pins, etc.

This will scan the entire I2C bus for devices, which is always a useful 
sanity check before working on drivers, following the Linux 'i2cdetect' 
model:

static int
shell_i2cscan_cmd(int argc, char **argv)
{
     uint8_t addr;
     int32_t timeout = OS_TICKS_PER_SEC / 10
     uint8_t dev_count = 0;

     console_printf("Scanning I2C bus 0\n"
                    "     0  1  2  3  4  5  6  7  8  9  a b  c  d  e  f\n"
                    "00:          ");

     /* Scan all valid I2C addresses (0x03..0x77) */
     for (addr = 0x03; addr < 0x78; addr++) {
         int rc = hal_i2c_master_probe(0, addr, timeout);
         if (!(addr % 16)) {
           console_printf("\n%02x: ", addr);
         }
         if (!rc) {
             console_printf("%02x ", addr);
             dev_count++;
         } else {
             console_printf("-- ");
         }
     }
     console_printf("\nFound %u devices on I2C bus 0\n", dev_count);

     return 0;
}

This results in the following output on the shell:

    5594:Scanning I2C bus 0
          0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    00:          -- -- -- -- -- -- -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 1f
    20: -- 21 -- -- -- -- -- -- -- 29 -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: -- -- -- -- -- -- 76 --
    Found 4 devices on I2C bus 0

My question is ... is there a way to optionally suppress the tick 
counter on 'console_printf' calls for individual instances???

It might get in the way of formatting output with multiple printf lines. 
I had to limit the number of times I used console_printf to avoid the 
tick counter messing the output up.

K.


Re: I2C Bus Scan Formatting

Posted by "David G. Simmons" <sa...@mac.com>.
I just checked in and created a pull request for turning OS Ticks printing on/off.

?
Commands:
     echo         ?    prompt     ticks     tasks  mempools
     date         b
ticks on
248940:Ticks set to:
248940: Console Ticks on
prompt on
249600: Prompt now on.
249600: > ticks off
 Console Ticks off
 > prompt off
 Prompt now off.

I also updated the prompt command to be able to turn it off, which apparently you couldn't do before once it was on. 

This can also be set in syscfg.yml as CONSOLE_TICKS 1 (or 0 to turn it off)

dg


> On Nov 9, 2016, at 7:34 PM, Kevin Townsend <ke...@adafruit.com> wrote:
> 
> I'll put this in a pull request with some of these helper test functions later, but I'm just starting to poke at a manufacturing test app that can be used to validate all the pins, etc.
> 
> This will scan the entire I2C bus for devices, which is always a useful sanity check before working on drivers, following the Linux 'i2cdetect' model:
> 
> static int
> shell_i2cscan_cmd(int argc, char **argv)
> {
>    uint8_t addr;
>    int32_t timeout = OS_TICKS_PER_SEC / 10
>    uint8_t dev_count = 0;
> 
>    console_printf("Scanning I2C bus 0\n"
>                   "     0  1  2  3  4  5  6  7  8  9  a b  c  d  e  f\n"
>                   "00:          ");
> 
>    /* Scan all valid I2C addresses (0x03..0x77) */
>    for (addr = 0x03; addr < 0x78; addr++) {
>        int rc = hal_i2c_master_probe(0, addr, timeout);
>        if (!(addr % 16)) {
>          console_printf("\n%02x: ", addr);
>        }
>        if (!rc) {
>            console_printf("%02x ", addr);
>            dev_count++;
>        } else {
>            console_printf("-- ");
>        }
>    }
>    console_printf("\nFound %u devices on I2C bus 0\n", dev_count);
> 
>    return 0;
> }
> 
> This results in the following output on the shell:
> 
>   5594:Scanning I2C bus 0
>         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
>   00:          -- -- -- -- -- -- -- -- -- -- -- -- --
>   10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 1f
>   20: -- 21 -- -- -- -- -- -- -- 29 -- -- -- -- -- --
>   30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
>   40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
>   50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
>   60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
>   70: -- -- -- -- -- -- 76 --
>   Found 4 devices on I2C bus 0
> 
> My question is ... is there a way to optionally suppress the tick counter on 'console_printf' calls for individual instances???
> 
> It might get in the way of formatting output with multiple printf lines. I had to limit the number of times I used console_printf to avoid the tick counter messing the output up.
> 
> K.
> 

--
David G. Simmons
(919) 534-5099
Web <https://davidgs.com/> • Blog <https://davidgs.com/davidgs_blog> • Linkedin <http://linkedin.com/in/davidgsimmons> • Twitter <http://twitter.com/TechEvangelist1> • GitHub <http://github.com/davidgs>
/** Message digitally signed for security and authenticity.  
* If you cannot read the PGP.sig attachment, please go to 
 * http://www.gnupg.com/ <http://www.gnupg.com/> Secure your email!!!
 * Public key available at keyserver.pgp.com <http://keyserver.pgp.com/>
**/
♺ This email uses 100% recycled electrons. Don't blow it by printing!

There are only 2 hard things in computer science: Cache invalidation, naming things, and off-by-one errors.



Re: I2C Bus Scan Formatting

Posted by "David G. Simmons" <sa...@mac.com>.
> On Nov 9, 2016, at 7:34 PM, Kevin Townsend <ke...@adafruit.com> wrote:
> 
> This results in the following output on the shell:
> 
>   5594:Scanning I2C bus 0
>         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
>   00:          -- -- -- -- -- -- -- -- -- -- -- -- --
>   10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 1f
>   20: -- 21 -- -- -- -- -- -- -- 29 -- -- -- -- -- --
>   30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
>   40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
>   50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
>   60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
>   70: -- -- -- -- -- -- 76 --
>   Found 4 devices on I2C bus 0
> 
> My question is ... is there a way to optionally suppress the tick counter on 'console_printf' calls for individual instances???
> 
> It might get in the way of formatting output with multiple printf lines. I had to limit the number of times I used console_printf to avoid the tick counter messing the output up.


In the first implementation of the console prompt, it did not print the tick counter. Subsequent versions did, and the version that ultimately was incorporated does. I woke up at 2am thinking about this, and thinking that an on/off toggle for the tick counter would be a nice thing to have, since some people won't care about the ticks in general.

Implementing this is pretty straight forward and could be done via a sys config and a shell command, like the prompt. 

dg
--
David G. Simmons
(919) 534-5099
Web <https://davidgs.com/> • Blog <https://davidgs.com/davidgs_blog> • Linkedin <http://linkedin.com/in/davidgsimmons> • Twitter <http://twitter.com/TechEvangelist1> • GitHub <http://github.com/davidgs>
/** Message digitally signed for security and authenticity.  
* If you cannot read the PGP.sig attachment, please go to 
 * http://www.gnupg.com/ <http://www.gnupg.com/> Secure your email!!!
 * Public key available at keyserver.pgp.com <http://keyserver.pgp.com/>
**/
♺ This email uses 100% recycled electrons. Don't blow it by printing!

There are only 2 hard things in computer science: Cache invalidation, naming things, and off-by-one errors.