?? pmbus
字號:
X <one line to give the program's name and a brief idea of what it does.>X Copyright (C) <year> <name of author>XX This program is free software: you can redistribute it and/or modifyX it under the terms of the GNU General Public License as published byX the Free Software Foundation, either version 3 of the License, orX (at your option) any later version.XX This program is distributed in the hope that it will be useful,X but WITHOUT ANY WARRANTY; without even the implied warranty ofX MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theX GNU General Public License for more details.XX You should have received a copy of the GNU General Public LicenseX along with this program. If not, see <http://www.gnu.org/licenses/>.XAlso add information on how to contact you by electronic and paper mail.XX If the program does terminal interaction, make it output a shortnotice like this when it starts in an interactive mode:XX <program> Copyright (C) <year> <name of author>X This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.X This is free software, and you are welcome to redistribute itX under certain conditions; type `show c' for details.XThe hypothetical commands `show w' and `show c' should show the appropriateparts of the General Public License. Of course, your program's commandsmight be different; for a GUI interface, you would use an "about box".XX You should also get your employer (if you work as a programmer) or school,if any, to sign a "copyright disclaimer" for the program, if necessary.For more information on this, and how to apply and follow the GNU GPL, see<http://www.gnu.org/licenses/>.XX The GNU General Public License does not permit incorporating your programinto proprietary programs. If your program is a subroutine library, youmay consider it more useful to permit linking proprietary applications withthe library. If this is what you want to do, use the GNU Lesser GeneralPublic License instead of this License. But first, please read<http://www.gnu.org/philosophy/why-not-lgpl.html>.SHAR_EOF (set 20 08 04 25 10 25 36 'COPYING'; eval "$shar_touch") && chmod 0644 'COPYING' || $echo 'restore of' 'COPYING' 'failed' if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \ && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then md5sum -c << SHAR_EOF >/dev/null 2>&1 \ || $echo 'COPYING:' 'MD5 check failed'd32239bcb673463ab874e80d47fae504 COPYINGSHAR_EOF else shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'COPYING'`" test 35147 -eq "$shar_count" || $echo 'COPYING:' 'original size' '35147,' 'current size' "$shar_count!" fifi# ============= Makefile ==============if test -f 'Makefile' && test "$first_param" != -c; then $echo 'x -' SKIPPING 'Makefile' '(file already exists)'else $echo 'x -' extracting 'Makefile' '(text)' sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&## NOTE that the version of GCC you use might affect whether this code# fits into an ATtiny24 flash (2KB). Also, the current version relies# on AVR-libc 1.6.x features.## GCC 4.3.0 really shrinks the the USI code, especially IRQ handlers,# but needs some "noinline" function attributes to prevent some bad# inlining choices. It needs about 5% less space than GCC 4.2.2 given# those options (or an equivalent commandline option).## GCC 4.2.2 (e.g. WinAVR 2007-12-21) works, but wastes much space.## GCC 4.2.1 and older toolchains don't handle ATtinyX4 chips quite# right (ignoring LPMX, MOVW, etc).#XCC = avr-gccXMCU = attiny24#MCU = attiny84XLDFLAGS = -L/usr/local/avr/libLDFLAGS += -mmcu=$(MCU)XCFLAGS = -I/usr/local/avr/includeCFLAGS += -mmcu=$(MCU)XCFLAGS += -std=gnu99CFLAGS += -OsXCFLAGS += -funsigned-bitfieldsCFLAGS += -funsigned-charCFLAGS += -fpack-structCFLAGS += -fshort-enumsXCFLAGS += -WallCFLAGS += -WextraCFLAGS += -Wstrict-prototypes#CFLAGS += -pedanticXCFLAGS += -DF_CPU=4000000XOBJS = main.o pmbus.o usi_i2c_slave.oXIMAGE = pmbus_slave.elfX$(IMAGE): $(OBJS)X $(CC) -o $(IMAGE) $(LDFLAGS) $(OBJS)Xclean:X -$(RM) -f *.o *.elf Log *.shar.bz2XHEADERS = usi_i2c_slave.h smbus_glue.h prod_misc.hXmain.o: main.c $(HEADERS) Makefilepmbus.o: pmbus.c $(HEADERS) Makefileusi_i2c_slave.o: usi_i2c_slave.c $(HEADERS) MakefileXSHARFILES = README COPYING \X Makefile $(OBJS:.o=.c) $(HEADERS) \X pmbus_peek.c \X $(IMAGE)Xshar: pmbus.shar.bz2Xpmbus.shar.bz2: $(SHARFILES)X shar $(SHARFILES) | bzip2 > pmbus.shar.bz2XSHAR_EOF (set 20 08 04 25 10 25 36 'Makefile'; eval "$shar_touch") && chmod 0644 'Makefile' || $echo 'restore of' 'Makefile' 'failed' if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \ && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then md5sum -c << SHAR_EOF >/dev/null 2>&1 \ || $echo 'Makefile:' 'MD5 check failed'b4453a0a9573fde65b5756fc6795f397 MakefileSHAR_EOF else shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'Makefile'`" test 1569 -eq "$shar_count" || $echo 'Makefile:' 'original size' '1569,' 'current size' "$shar_count!" fifi# ============= main.c ==============if test -f 'main.c' && test "$first_param" != -c; then $echo 'x -' SKIPPING 'main.c' '(file already exists)'else $echo 'x -' extracting 'main.c' '(text)' sed 's/^X//' << 'SHAR_EOF' > 'main.c' &&/*X * main.c - main program for AVR8 PMBus slaveX * Part of PMBus device firmwareX *X * Copyright (C) 2008 David BrownellX *X * This program is free software: you can redistribute it and/or modifyX * it under the terms of the GNU General Public License as published byX * the Free Software Foundation, either version 3 of the License, orX * (at your option) any later version.X *X * This program is distributed in the hope that it will be useful,X * but WITHOUT ANY WARRANTY; without even the implied warranty ofX * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theX * GNU General Public License for more details.X *X * You should have received a copy of the GNU General Public LicenseX * along with this program. If not, see <http://www.gnu.org/licenses/>.X */#include <string.h>X#include <avr/io.h>#include <avr/eeprom.h>#include <avr/interrupt.h>#include <avr/pgmspace.h>#include <avr/sleep.h>#include <avr/wdt.h>X#include "usi_i2c_slave.h"#include "prod_misc.h"XX/*X * This firmware is intended to replace what's found in the NGW100X * ATtiny24 "Board Controller". The firmware provided by Atmel isX * not PMBus conformant.X *X * If we're using an 8 MHz clock we leave CKDIV8 unprogrammed andX * don't bother updating the prescaler.X *X * Program EESAVE so that it's not easy to lose the serial numberX * and temperature offset stored in eeprom. Ideally both valuesX * would be set during board manufacture, along with the flash.X * Failing that, AVR studio lets you write to EEPROM "by hand" ifX * you have DebugWire configured (e.g. program with a Dragon).X */X/* avr-libc-1.6-20080228 vs WinAVR-20071221 */#ifndef CKDIV8#define CKDIV8 FUSE_CKDIV8#define EESAVE FUSE_EESAVE#endifX#ifndef HFUSE_DEFAULT#define HFUSE_DEFAULT FUSE_HFUSE_DEFAULT#endifXFUSES = {#if F_CPU == 8000000X .low = (u8) (LFUSE_DEFAULT | ~CKDIV8),#elseX .low = (u8) LFUSE_DEFAULT,#endifX .high = (u8) (HFUSE_DEFAULT & EESAVE),X .extended = (u8) EFUSE_DEFAULT,};X/*-------------------------------------------------------------------------*/X/*X * EEPROM layout ... this isn't what Atmel's NGW100 firmware uses.X * You should erase the EEPROM before installing this code; init theX * serial number (from the sticker on the board) by hand.X *X * Temperature offset calibration ... TBD. Maybe all the EEPROMX * contents should have write-once commands from the host, until aX * manufacturing-based solution is deployed.X */u8 EEMEM ee_serial[10];u16 EEMEM ee_temp_offset;X/*-------------------------------------------------------------------------*/X/*X * Variables exported to PMBus protocol codeX */u8 board_revision;X/*X * Temp sensor accuracy *really* requires using a per-chip calibration;X * and even at that it's not going to be very accurate. If it mattersX * much, use a better sensor.X *X * Here we simplify the math by assuming that linear sensitivity, atX * 1.12 bits/degree Celsius (typical values, see the ATtinyX4 datasheetX * table 16-2). So a 12-bit sample with range up to VREF (1.1V) givesX *X * T = (ADC - offset)/DIVX *X * with DIV as (1024 * 1.1 bit/degree)/1.1V = 1024 ... so we can treatX * the raw ADC output as being in degrees Celcius (modulo an offset),X * no need to multiply or divide. The big downside: those LSBs areX * noisy; variability of 2-4 degrees is easy to observe.X *X * In PMBus, we can represent that as a LINEAR (fixed point) value,X * or with a (more expensive) DIRECT format using coefficients:X * m = 1 (we provide degrees C)X * b = temp_offsetX * R = 0X */u16 temp_offset;u16 adc_temp; /* ADC8 */X/*X * 3V3 voltage divider measurement:X * = Volts * (10K / (10K + 27K))X * = Volts * 0.27X *X * ADC = (measured / 1.1V) * 1024X * = ((Volts * 0.27) / 1.1V) * 1024X *X * ADC / 1024 = (Volts * 0.27) / 1.1VX * (ADC / 1024) * 1.1V = Volts * 0.27X * (ADC / 1024) * 1.1V / 0.27 = VoltsX * (ADC / 1024) * 4.074 = VoltsX * (ADC * 4.074) / 1024 = VoltsX *X * To represent in in direct format:X * Volts = (ADC * (10^-R) - b) / mX * b == 0X * Volts = (ADC * (10^-R)) / mX * = (ADC * 4.074) / 1024X * = (ADC * 4.074 * 24.54590) / (1024 * 24.54590)X * = (ADC * 100) / (1024 * 24.54590)X * R == -2X * = (ADC * 100) / 25135X * m == 25135X */u16 adc_3v3; /* ADC7 */X// u16 adc_1v8; /* ADC3 */X/*-------------------------------------------------------------------------*/X/*X * Set up just the hardware, without relying on BSS or initializedX * data ... things go here that "need" to be done ASAP on reset.X */Xvoid tnX4_init(void)X __attribute__ ((naked))X __attribute__ ((used))X __attribute__ ((section(".init3")));Xvoid tnX4_init(void){X MCUSR = 0;XX /* in case we didn't get a hard reset... */X WDTCSR = _BV(WDCE);X WDTCSR = 0;XX /* Assume nominal 8 MHz oscillator, with CKDIV8 set unless we'reX * using 8 MHz clock. Don't allow less than 200 KHz, so we canX * always cope with at least 100 KHz for I2C.X *X * Note that there's a fair amount of work going on in some of theX * USI interrupts, and that even at 8 MHz some delays in thoseX * particular I2C responses are observable.X */#if F_CPU == 8000000X /* we're all set */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -