summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouis Yung-Chieh Lo <yjlou@chromium.org>2011-10-15 00:07:20 +0800
committerLouis Yung-Chieh Lo <yjlou@chromium.org>2011-10-15 00:17:08 +0800
commit2266c2119e0dd75df824055b0e5f15beaea5d347 (patch)
treed3c146895c50aa59d6ade3e4dae1fa3bea9d674f
downloadchrome-ec-2266c2119e0dd75df824055b0e5f15beaea5d347.tar.gz
Initial commit
-rw-r--r--chip_interface/README10
-rw-r--r--chip_interface/ac_present.h44
-rw-r--r--chip_interface/battery.h69
-rw-r--r--chip_interface/flash.h29
-rw-r--r--chip_interface/keyboard_backlight.h22
-rw-r--r--chip_interface/lid.h38
-rw-r--r--chip_interface/power_button.h49
-rw-r--r--chip_interface/timer.h16
-rw-r--r--cros_ec/Google_features_go_here0
-rw-r--r--cros_ec/chip_stub/fake_EC_OS_APIs_here0
-rw-r--r--cros_ec/host_command.c0
-rw-r--r--cros_ec/keyboard.h17
-rw-r--r--cros_ec/main.c0
-rw-r--r--ec_common.h29
-rw-r--r--ec_console.h34
-rw-r--r--ec_uart.h102
16 files changed, 459 insertions, 0 deletions
diff --git a/chip_interface/README b/chip_interface/README
new file mode 100644
index 0000000000..3f80cc6297
--- /dev/null
+++ b/chip_interface/README
@@ -0,0 +1,10 @@
+Caller: Chrome OS EC main dispatcher
+
+This directory stores *.h files of those functions that partner implements.
+
+The actual implementation (.c files) resides under S*Ware/eclib/, which
+is under partner's licensed and wraps S*Ware/drivelib/ chip-specific code.
+
+This directory is under Chromium license so that the main loop can include these
+files and call the code implemented by partner.
+
diff --git a/chip_interface/ac_present.h b/chip_interface/ac_present.h
new file mode 100644
index 0000000000..c2bb0d9d77
--- /dev/null
+++ b/chip_interface/ac_present.h
@@ -0,0 +1,44 @@
+/* power_button.h - Power button function.
+ * Hides chip-specific implementation behind this interface.
+ *
+ * (Chromium license) */
+
+#ifndef __CHIP_INTERFACE_AC_PRESENT_H
+#define __CHIP_INTERFACE_AC_PRESENT_H
+
+/*
+ * Initialize the AC present as GPIO input pin and enable interrupt for
+ * callback.
+ */
+EcError CrAcPresentInit(void);
+
+
+/* Calls GPIOPinRead() to read the GPIO state. */
+/* TODO: has the state been debounced? */
+EcError CrAcPrensentState(void);
+
+
+/* Register a calback function. It is called while AC is plugged in or
+ * unplugged.
+ */
+EcError CrAcPresentRegister(void (*callback)(void));
+
+/* Below is the example code to register this function. */
+#if 0
+/* This callback function is implemented in Chrome OS features layer. */
+void CrAcStateChanged(void) {
+ int ac_present = CrAcPrensentState();
+ if (ac_present) {
+ if (battery_present && authenticated) {
+ // start to charge battery;
+ }
+ } else {
+ // stop charge battery;
+ }
+}
+ ... somewhere in init code ...
+ CrAcPresentRegister(CrACStateChanged);
+
+#endif /* #if 0 */
+
+#endif /* __CHIP_INTERFACE_AC_PRESENT_H */
diff --git a/chip_interface/battery.h b/chip_interface/battery.h
new file mode 100644
index 0000000000..e5c3337a9c
--- /dev/null
+++ b/chip_interface/battery.h
@@ -0,0 +1,69 @@
+/* power_button.h - Power button function.
+ * Hides chip-specific implementation behind this interface.
+ *
+ * (Chromium license) */
+
+#ifndef __CHIP_INTERFACE_BATTERY_H
+#define __CHIP_INTERFACE_BATTERY_H
+
+
+/*********** Battery SMBus *********************************************/
+/* Initialize the SMBus */
+EcError CrBatteryInit(void);
+
+/* Send a command to battery. Blocking */
+EcError CrBatterySendCommand(...);
+
+/* non-blocking read so that it can support both polling mode
+ * and interrupt callback.
+ */
+EcError CrBatteryRecvCommand(...);
+
+/* Register a callback when a packet comes from SMBus */
+EcError CrRegisterBatteryInterrupt(void (*isr)(...));
+
+#if 0 /* example code */
+void BatteryPacketArrive(...) {
+ CrBatteryRecvCommand(); // read the packet.
+}
+
+ ... somewhere in code ...
+ CrRegisterBatteryInterrupt(BatteryPacketArrive);
+
+#endif
+
+
+/*********** Battery Present *********************************************/
+/*
+ * Initialize the battery present as GPIO input pin and enable interrupt for
+ * callback.
+ */
+EcError CrBatteryPresentInit(void);
+
+/* Calls GPIOPinRead() to read the GPIO state. */
+/* TODO: has the state been debounced? */
+EcError CrBatteryPrensentState(void);
+
+/* Register a calback function. It is called while AC is plugged in or
+ * unplugged.
+ */
+EcError CrBatteryPresentRegister(void (*callback)(void));
+
+/* Below is the example code to register this function. */
+#if 0
+/* This callback function is implemented in Chrome OS features layer. */
+void BatteryStateChanged(void) {
+ int battery_present = CrBatteryPresentState();
+ if (battery_present) {
+ // start to authenticate battery;
+ // once authenticated, charge the battery;
+ } else {
+ // stop charge battery;
+ }
+}
+ ... somewhere in init code ...
+ CrBatteryPresentRegister(BatteryStateChanged);
+
+#endif /* #if 0 */
+
+#endif /* __CHIP_INTERFACE_BATTERY_H */
diff --git a/chip_interface/flash.h b/chip_interface/flash.h
new file mode 100644
index 0000000000..ec622a0863
--- /dev/null
+++ b/chip_interface/flash.h
@@ -0,0 +1,29 @@
+/* flash.h - flash interface
+ *
+ * (Chromium license) */
+
+#ifndef __CHIP_INTERFACE_FLASH_H
+#define __CHIP_INTERFACE_FLASH_H
+
+/* returns the flash size and erase clock structure. */
+EcError CrFlashQuery(*size, *erase_block) {
+
+EcError CrFlashRead(addr_t offset, length, uint8_t *data);
+
+EcError CrFlashWrite(addr_t offset, length, uint8_t *data);
+
+EcError CrFlashErase(addr_t offset, length);
+
+EcError CrFlashSetWriteProtectRange(addr_t offset, length);
+
+/* TODO: change to Randall's new model */
+/* Set lock bit (the SRP bit in SPI) */
+EcError CrFlashEnableWriteProtect(void);
+
+/* TODO: change to Randall's new model */
+/* Always return FAILED because FMPPEn cannot be reset to 1
+ * until a power-on reset or after committed (see p. 577).
+ */
+int CrFlashDisableWriteProtect(void);
+
+#endif /* __CHIP_INTERFACE_FLASH_H */
diff --git a/chip_interface/keyboard_backlight.h b/chip_interface/keyboard_backlight.h
new file mode 100644
index 0000000000..cb3735de44
--- /dev/null
+++ b/chip_interface/keyboard_backlight.h
@@ -0,0 +1,22 @@
+/* keyboard_backlight.h - Keyboard backlight
+ *
+ * (Chromium license) */
+
+#ifndef __CHIP_INTERFACE_KEYBOARD_BACKLIGHT_H
+#define __CHIP_INTERFACE_KEYBOARD_BACKLIGHT_H
+
+/*
+ * The lightness value in this interface:
+ *
+ * 0 - off
+ * 255 - full
+ * others - undefined
+ */
+
+/* Configure PWM port and set the initial backlight value. */
+EcError CrKeyboardBacklightInit(uint16_t init_lightness);
+
+/* Set the mapped PWM value */
+EcError CrKeyboardBacklightSet(uint16_t lightness);
+
+#endif /* __CHIP_INTERFACE_KEYBOARD_BACKLIGHT_H */
diff --git a/chip_interface/lid.h b/chip_interface/lid.h
new file mode 100644
index 0000000000..cffa35c4f4
--- /dev/null
+++ b/chip_interface/lid.h
@@ -0,0 +1,38 @@
+/* lid.h - handle lid open/close
+ *
+ * (Chromium license) */
+
+#ifndef __CHIP_INTERFACE_LID_H
+#define __CHIP_INTERFACE_LID_H
+
+/* Initialize the GPIO pin */
+EcError CrLidSwitchInit(void);
+
+/* Calls GPIOPinRead() to read the GPIO state. */
+/* TODO: has the state been debounced? */
+EcError CrLidSwitchState(void);
+
+/* Register a calback function. It is called while lid state is changed.
+ */
+EcError CrLidSwitchRegister(void (*callback)(void));
+
+/* Below is the example code to register this function. */
+#if 0
+/* This callback function is implemented in Chrome OS features layer. */
+void LidSwitchChanged(void) {
+ int lid_open = CrLidSwitchState();
+ if (lid_open) {
+ if (system is in S3) {
+ // resume system
+ }
+ } else {
+ if (system is in S0) {
+ // suspend system
+ }
+ }
+}
+ ... somewhere in init code ...
+ CrLidSwitchRegister(LidSwitchChanged);
+#endif
+
+#endif /* __CHIP_INTERFACE_LID_H */
diff --git a/chip_interface/power_button.h b/chip_interface/power_button.h
new file mode 100644
index 0000000000..bc6d43e2d1
--- /dev/null
+++ b/chip_interface/power_button.h
@@ -0,0 +1,49 @@
+/* power_button.h - Power button function.
+ * Hides chip-specific implementation behind this interface.
+ *
+ * (Chromium license) */
+
+#ifndef __CHIP_INTERFACE_POWER_BUTTON_H
+#define __CHIP_INTERFACE_POWER_BUTTON_H
+
+/*
+ * Initialize the power button as GPIO input pin and enable interrupt for
+ * keyboard scanner code.
+ */
+EcError CrPowerButtonInit(void);
+
+
+/* Calls GPIOPinRead() to read the GPIO state. */
+/* TODO: has the state been debounced? */
+EcError CrPowerButtonGetState(void);
+
+
+/* Register a calback function. It is called while power button is changing its
+ * state (pressed or released ).
+ */
+EcError CrPowerButtonRegister(void (*callback)(void));
+
+/* Below is the example code to register this function. */
+#if 0
+/* This callback function is implemented in Chrome OS features layer. */
+void PowerButtonCallback(void) {
+ int pressed = CrPowerButtonGetState();
+ if (!prev_status) {
+ if (pressed) {
+ // Power button is just pressed. Generate scan code,
+ // and kick off the state machine for PWRBTN# signal.
+ }
+ } else {
+ if (!pressed) {
+ // Power button is just released. Generate scan code,
+ // and clear the state machine.
+ }
+ }
+}
+
+ ... somewhere in init code ...
+ CrPowerButtonRegister(PowerButtonCallback);
+
+#endif /* #if 0 */
+
+#endif /* __CHIP_INTERFACE_POWER_BUTTON_H */
diff --git a/chip_interface/timer.h b/chip_interface/timer.h
new file mode 100644
index 0000000000..fa290abef5
--- /dev/null
+++ b/chip_interface/timer.h
@@ -0,0 +1,16 @@
+/* timer.h - periodical timer
+ *
+ * (Chromium license) */
+
+#ifndef __CHIP_INTERFACE_TIMER_H
+#define __CHIP_INTERFACE_TIMER_H
+
+/* init hardware and prepare ISR */
+EcError CrPeriodicalTimerInit(void);
+
+EcError CrPeriodicalTimerRegister(
+ int interval /* ms */,
+ int (*timer)(int /* delta ms from last call */));
+
+
+#endif /* __CHIP_INTERFACE_TIMER_H */
diff --git a/cros_ec/Google_features_go_here b/cros_ec/Google_features_go_here
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/cros_ec/Google_features_go_here
diff --git a/cros_ec/chip_stub/fake_EC_OS_APIs_here b/cros_ec/chip_stub/fake_EC_OS_APIs_here
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/cros_ec/chip_stub/fake_EC_OS_APIs_here
diff --git a/cros_ec/host_command.c b/cros_ec/host_command.c
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/cros_ec/host_command.c
diff --git a/cros_ec/keyboard.h b/cros_ec/keyboard.h
new file mode 100644
index 0000000000..ad9ef6c220
--- /dev/null
+++ b/cros_ec/keyboard.h
@@ -0,0 +1,17 @@
+/* keyboard.h -
+ *
+ * (Chromium license) */
+
+#ifndef __CROS_EC_KEYBOARD_H
+#define __CROS_EC_KEYBOARD_H
+
+/* Register the board-specific keyboard matrix translation function.
+ * The callback function accepts col/row and returns the scan code.
+ */
+EcError CrKeyboardMatrixRegister(
+ int8_t col_num, int8_t row_num,
+ EcError (*callback)(
+ int8_t column, int8_t row, int8_t pressed,
+ uint8_t *scan_code, int32_t* len));
+
+#endif /* __CROS_EC_KEYBOARD_H */
diff --git a/cros_ec/main.c b/cros_ec/main.c
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/cros_ec/main.c
diff --git a/ec_common.h b/ec_common.h
new file mode 100644
index 0000000000..a7ce19b21c
--- /dev/null
+++ b/ec_common.h
@@ -0,0 +1,29 @@
+/* ec_common.h - Common includes for Chrome EC
+ *
+ * (Chromium license) */
+
+#ifndef __EC_COMMON_H
+#define __EC_COMMON_H
+
+#include <stdint.h>
+
+typedef int EcError; /* Functions which return error return one of these */
+/* YJLOU: why not "typedef enum EcErrorListe EcError"? */
+
+/* List of common EcError codes that can be returned */
+enum EcErrorList {
+ /* 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,
+
+ /* Module-internal error codes may use this range. */
+ EC_ERROR_INTERNAL_FIRST = 0x10000,
+ EC_ERROR_INTERNAL_LAST = 0x1FFFF
+};
+
+#endif /* __EC_COMMON_H */
diff --git a/ec_console.h b/ec_console.h
new file mode 100644
index 0000000000..64e38eda09
--- /dev/null
+++ b/ec_console.h
@@ -0,0 +1,34 @@
+/* ec_console.h - Debug console for Chrome EC
+ *
+ * (Chromium license) */
+
+#ifndef __CROS_EC_CONSOLE_H
+#define __CROS_EC_CONSOLE_H
+
+#include "ec_common.h"
+
+/* Console command */
+typedef struct EcConsoleCommand {
+ /* Command name. Case-insensitive. */
+ const char* name;
+ /* Handler for the command. argv[0] will be the command name. */
+ EcError (*handler)(int argc, char** argv);
+} EcConsoleCommand;
+
+
+/* Console command group */
+typedef struct EcConsoleCommandGroup {
+ const char* group_name; /* Name of the command group */
+ const EcConsoleCommand* commands; /* List of commands */
+ int command_count; /* Number of commands in list */
+} EcConsoleCommandGroup;
+
+
+/* Initializes the console module. */
+EcError ConsoleInit(void);
+
+
+/* Registers a group of console commands. */
+EcError ConsoleRegisterCommands(const EcConsoleCommandGroup* group);
+
+#endif /* __CROS_EC_CONSOLE_H */
diff --git a/ec_uart.h b/ec_uart.h
new file mode 100644
index 0000000000..78d1b18764
--- /dev/null
+++ b/ec_uart.h
@@ -0,0 +1,102 @@
+/* ec_uart.h - UART module for Chrome EC
+ *
+ * (Chromium license) */
+
+#ifndef __CROS_EC_UART_H
+#define __CROS_EC_UART_H
+
+#include "ec_common.h"
+
+/*****************************************************************************/
+/* Output functions */
+
+/* Print formatted output to the UART, like printf().
+ *
+ * Returns error if output was truncated.
+ *
+ * Must support format strings for:
+ * char (%c)
+ * string (%s)
+ * native int (signed/unsigned) (%d / %u / %x)
+ * int32_t / uint32_t (%d / %x)
+ * int64_t / uint64_t (%ld / %lu / %lx)
+ * pointer (%p)
+ * including padding (%-5s, %8d, %08x)
+ *
+ * Note: Floating point output (%f / %g) is not required.
+ */
+EcError UartPrintf(const char* format, ...);
+
+/* Put a null-terminated string to the UART, like puts().
+ *
+ * Returns error if output was truncated. */
+EcError UartPuts(const char* outstr);
+
+/* Flushes output. Blocks until UART has transmitted all output. */
+void UartFlush(void);
+
+/*****************************************************************************/
+/* Input functions */
+
+/* Flushes input buffer, discarding all input. */
+void UartFlushInput(void);
+
+/* Non-destructively checks for a character in the input buffer.
+ *
+ * Returns non-zero if the character <c> is in the input buffer. If
+ * c<0, returns non-zero if any character is in the input buffer. */
+/* TODO: add boolean type? */
+/* TODO: return offset of the character? That is, how many bytes of
+ * input up to and including the character. */
+int UartPeek(int c);
+
+/* Reads characters from the UART, similar to fgets().
+ *
+ * Reads input until one of the following conditions is met:
+ * (1) <size-1> characters have been read.
+ * (2) A newline ('\n') has been read.
+ * (3) The input buffer is empty.
+ *
+ * Condition (3) means this call never blocks. This is important
+ * because it prevents a race condition where the caller calls
+ * UartPeek() to see if input is waiting, or is notified by the
+ * callack that input is waiting, but then the input buffer overflows
+ * or someone else grabs the input before UartGets() is called.
+ *
+ * Characters are stored in <dest> and are null-terminated, and
+ * include the newline if present.
+ *
+ * Returns the number of characters read (not counting the terminating
+ * null). */
+int UartGets(char* dest, int size);
+
+/* Callback handler prototype, called when the UART has input. */
+typedef void (*UartHasInputCallback)(void);
+
+/* Registers an input callback handler, replacing any existing
+ * callback handler. If callback==NULL, disables callbacks.
+ *
+ * Callback will be called whenever the UART receives character <c>.
+ * If c<0, callback will be called when the UART receives any
+ * character. */
+void UartRegisterHasInputCallback(UartHasInputCallback callback, int c);
+
+/* TODO: what to do about input overflow? That is, what if the input
+ * buffer fills with 'A', and we're still waiting for a newline? Do
+ * we drop the oldest output, flush the whole thing, or call the input
+ * callback with a message code? Alternately, should the callback be able
+ * to specify a buffer-full-threshold where it gets called?
+ *
+ * Simplest just to flush the input buffer on overflow. */
+/* YJLOU: are you talking about the UartRegisterHasInputCallback()?
+ * If yes, this is not a problem because for every input key, we can drop it
+ * if there is no callback registered for it.
+ * Else if you are talking about the UartGets() function, I think you can add
+ * the third return critiria: internal key buffer reaches full.
+ */
+
+/* TODO: getc(), putc() equivalents? */
+
+/* TODO: input handler assumes debug input new lines are '\n'-delimited? */
+
+#endif /* __CROS_EC_UART_H */