mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-27 18:25:05 +00:00
Ref: http://smbus.org/specs/smbus20.pdf - Support software CRC8 generation and checking. - Support read/write word (2-bytes) - Support read/write blocks (up to 32 bytes) BUG=chrome-os-partner:24741 BRANCH=ToT,glimmer TEST=Verified with smart battery firmware update application on glimmer. Passed LGC & Simplo Battery. Change-Id: Ic2e7f759af80c06741ed49fee1826213429fbf8a Signed-off-by: Sheng-Liang Song <ssl@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/209747 Reviewed-by: Randall Spangler <rspangler@chromium.org>
133 lines
3.7 KiB
C
133 lines
3.7 KiB
C
/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
/* common.h - Common includes for Chrome EC */
|
|
|
|
#ifndef __CROS_EC_COMMON_H
|
|
#define __CROS_EC_COMMON_H
|
|
|
|
#include <stdint.h>
|
|
|
|
/*
|
|
* Macros to concatenate 2 - 4 tokens together to form a single token.
|
|
* Multiple levels of nesting are required to convince the preprocessor to
|
|
* expand currently-defined tokens before concatenation.
|
|
*
|
|
* For example, if you have
|
|
* #define FOO 1
|
|
* #define BAR1 42
|
|
* Then
|
|
* #define BAZ CONCAT2(BAR, FOO)
|
|
* Will evaluate to BAR1, which then evaluates to 42.
|
|
*/
|
|
#define CONCAT_STAGE_1(w, x, y, z) w ## x ## y ## z
|
|
#define CONCAT2(w, x) CONCAT_STAGE_1(w, x, , )
|
|
#define CONCAT3(w, x, y) CONCAT_STAGE_1(w, x, y, )
|
|
#define CONCAT4(w, x, y, z) CONCAT_STAGE_1(w, x, y, z)
|
|
|
|
/*
|
|
* Macros to turn the argument into a string constant.
|
|
*
|
|
* Compared to directly using the preprocessor # operator, this 2-stage macro
|
|
* is safe with regards to using nested macros and defined arguments.
|
|
*/
|
|
#define STRINGIFY0(name) #name
|
|
#define STRINGIFY(name) STRINGIFY0(name)
|
|
|
|
/* Macros to access registers */
|
|
#define REG32(addr) (*(volatile uint32_t *)(addr))
|
|
#define REG16(addr) (*(volatile uint16_t *)(addr))
|
|
#define REG8(addr) (*(volatile uint8_t *)(addr))
|
|
|
|
/*
|
|
* Define __aligned(n) and __packed if someone hasn't beat us to it. Linux
|
|
* kernel style checking prefers these over __attribute__((packed)) and
|
|
* __attribute__((aligned(n))).
|
|
*/
|
|
#ifndef __aligned
|
|
#define __aligned(n) __attribute__((aligned(n)))
|
|
#endif
|
|
|
|
#ifndef __packed
|
|
#define __packed __attribute__((packed))
|
|
#endif
|
|
|
|
/* There isn't really a better place for this */
|
|
#define C_TO_K(temp_c) ((temp_c) + 273)
|
|
#define K_TO_C(temp_c) ((temp_c) - 273)
|
|
#define CELSIUS_TO_DECI_KELVIN(temp_c) ((temp_c) * 10 + 2731)
|
|
#define DECI_KELVIN_TO_CELSIUS(temp_dk) ((temp_dk - 2731) / 10)
|
|
|
|
/* Include top-level configuration file */
|
|
#include "config.h"
|
|
|
|
/* Canonical list of module IDs */
|
|
#include "module_id.h"
|
|
|
|
/* List of common error codes that can be returned */
|
|
enum ec_error_list {
|
|
/* Success - no error */
|
|
EC_SUCCESS = 0,
|
|
/* Unknown error */
|
|
EC_ERROR_UNKNOWN = 1,
|
|
/* Function not implemented yet */
|
|
EC_ERROR_UNIMPLEMENTED = 2,
|
|
/* Overflow error; too much input provided. */
|
|
EC_ERROR_OVERFLOW = 3,
|
|
/* Timeout */
|
|
EC_ERROR_TIMEOUT = 4,
|
|
/* Invalid argument */
|
|
EC_ERROR_INVAL = 5,
|
|
/* Already in use, or not ready yet */
|
|
EC_ERROR_BUSY = 6,
|
|
/* Access denied */
|
|
EC_ERROR_ACCESS_DENIED = 7,
|
|
/* Failed because component does not have power */
|
|
EC_ERROR_NOT_POWERED = 8,
|
|
/* Failed because component is not calibrated */
|
|
EC_ERROR_NOT_CALIBRATED = 9,
|
|
/* Failed because CRC error */
|
|
EC_ERROR_CRC = 10,
|
|
/* Invalid console command param (PARAMn means parameter n is bad) */
|
|
EC_ERROR_PARAM1 = 11,
|
|
EC_ERROR_PARAM2 = 12,
|
|
EC_ERROR_PARAM3 = 13,
|
|
EC_ERROR_PARAM4 = 14,
|
|
EC_ERROR_PARAM5 = 15,
|
|
EC_ERROR_PARAM6 = 16,
|
|
EC_ERROR_PARAM7 = 17,
|
|
EC_ERROR_PARAM8 = 18,
|
|
EC_ERROR_PARAM9 = 19,
|
|
EC_ERROR_PARAM_COUNT = 20, /* Wrong number of params */
|
|
|
|
/* Module-internal error codes may use this range. */
|
|
EC_ERROR_INTERNAL_FIRST = 0x10000,
|
|
EC_ERROR_INTERNAL_LAST = 0x1FFFF
|
|
};
|
|
|
|
/*
|
|
* Define test_mockable and test_mockable_static for mocking
|
|
* functions.
|
|
*/
|
|
#ifdef TEST_BUILD
|
|
#define test_mockable __attribute__((weak))
|
|
#define test_mockable_static __attribute__((weak))
|
|
#define test_export_static
|
|
#else
|
|
#define test_mockable
|
|
#define test_mockable_static static
|
|
#define test_export_static static
|
|
#endif
|
|
|
|
/*
|
|
* accessor allowing to override some read only data accesses.
|
|
* used to workaround a buggy toolchain (cf http://crosbug.com/p/24378)
|
|
*/
|
|
#ifndef RO
|
|
#define RO(var) var
|
|
#endif
|
|
|
|
#endif /* __CROS_EC_COMMON_H */
|