Logging (again!)

2018-07-05 Thread Christopher Collins
Hello all,

My logging obsession continues.  I have submitted a giant PR
(https://github.com/apache/mynewt-core/pull/1249) which changes all
existing packages to use the modlog facility rather than directly call
into the `sys/log` API.  I think this is the right direction, but it is
a somewhat major change, and I am certainly open to feedback.

I see two benefits of this change:

* For simple logging to the console, apps don't need to define and
  register a log.  Just use `MODLOG_DFLT` to log a message.

* Most packages don't need to define and expose a log object, and the
  application doesn't need to register it.  The package just writes log
  messages to its reserved log module ID.  This eliminates the need for
  every app to register the `ble_hs_log` and `oc_log` log objects, for
  example.

Here is what I personally would like to see in Mynewt, going forward:

1. Every package uses modlog; nothing uses the log API directly
(except for modlog itself :) ).

2. Applications that just want to log to the console just use the
`MODLOG_DFLT` macro.  This macro writes a printf-style string to the
"default" module, which routes to the console unless remapped.

3. If a library needs to log messages, it defines a log module syscfg
setting for each module it uses.  It is important that syscfg is used
here so that the user can override them in case two packages choose the
same module ID(s).

4. Newt adds two new syscfg setting types:
* log_module_owner
* log_module

`log_module_owner` is used to stake out a unique module ID.  If two
`log_module_owner` settings specify the same number, that indicates a
conflict in the module number space, and newt can abort the build with a
meaningful error.

`log_module` is used when a package wants to log to "someone else's"
module.  Newt doesn't complain if one or more `log_module` settings have
the same value as a `log_module_owner` setting.

A new command would be added to newt to display all assigned log module
IDs in a target.

All comments welcome.

Thanks,
Chris


Minimising power consumption on the nRF52

2018-07-05 Thread Amr Bekhit
Hello all,

I've been experimenting with mynewt and the nRF52DK board trying to
create a low power application. I've been working off the hello_world
app since it is simple. By default, when running the hello_world app,
the nRF52 consumes around 1.5mA. Disabling the UART (by settings
UART_0: 0 and CONSOLE_UART: 0) reduces this current significantly to
around 460uA. I've since been unable to significantly reduce this
current even further. Disabling TIMER_0 causes a further reduction of
about 15uA, but that's about it. Going through the nRF52832 product
spec, pretty much all the peripherals are turned off by default. The
only one that appears to be on is the radio, but setting
NRF_RADIO->POWER to 0 doesn't seem to decrease the current
consumption.

According to the product spec, in System ON mode with all RAM
retained, the nRF52 should consume around 1.5uA, so 460uA is quite a
big difference. I can't think of what other peripherals could possibly
be on that would consume all that current. As far as I can tell, the
only peripherals turned on by the hello world app are the following:
* A timer
* Uart
* Watchdog (turning that off didn't make a measurable difference,
which makes sense considering it's meant to consume 300nA)

If it's not peripherals, could this extra consumption be due to the
CPU executing the mynewt OS? If so, how can I prove this?

Amr