04bbba6c12
Rename guhRF platform to osd-merkur-256, previous osd-merkur platform is now osd-merkur-128. Also check that everything is consistent. Add both platforms to the regression tests. Move redundant files in platform dev directory of both platforms to cpu/avr/dev. Note that this probably needs some rework. Already discovered some inconsistency in io definitions of both devices in the avr/io.h includes. Added a workaround in the obvious cases. The platform makefiles now set correct parameters for bootloader and for reading mac-address from flash memory. Factor the flash programming into cpu/avr and platform/osd-merkur* and rework *all* osd example makefiles to use the new settings. Also update all the flash.sh and run.sh to use the new settings. The suli ledstrip modules (and osd example) have also been removed.
55 lines
823 B
C
55 lines
823 B
C
#include "contiki.h"
|
|
#include "batmon.h"
|
|
#include <util/delay.h>
|
|
|
|
|
|
|
|
|
|
int8_t batmon_init()
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
int8_t batmon_get_voltage(uint16_t* voltage)
|
|
{
|
|
uint16_t volt = 0;
|
|
uint16_t resolution = 75;
|
|
uint16_t offset = 2550;
|
|
int8_t ctr = 0;
|
|
|
|
BATMON = 0 | _BV(BATMON_HR);
|
|
_delay_us(2);
|
|
|
|
if(BATMON & _BV(BATMON_OK))
|
|
{
|
|
// voltage above 2.550 V
|
|
resolution = 75;
|
|
offset = 2550;
|
|
for(ctr=15; ctr>=0; ctr--)
|
|
{
|
|
BATMON = (BATMON & 0xF0) | (ctr);
|
|
_delay_us(2);
|
|
if(BATMON & _BV(BATMON_OK)) break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// voltage below 2.550 V
|
|
resolution = 50;
|
|
offset = 1700;
|
|
|
|
BATMON &= ~_BV(BATMON_HR);
|
|
|
|
for(ctr=15; ctr>=0; ctr--)
|
|
{
|
|
BATMON = (BATMON & 0xF0) | (ctr);
|
|
_delay_us(2);
|
|
if(BATMON & _BV(BATMON_OK)) break;
|
|
}
|
|
}
|
|
|
|
volt = resolution*ctr+offset;
|
|
*voltage=volt;
|
|
|
|
return 0;
|
|
}
|