Files
OpenCellular/include/message.h
David Hendricks 83082746a9 Separate message protocol command types and reserve slots accordingly
This organizes the commands in the messaging protocol so that we have
a more clear distinction between commands which are intended to to
control or get status of the EC itself and those which are intended
to query information about peripherals, such as the obtaining the
keyboard state.

Note: This will require the mkbp code to be updated.

BUG=none
TEST=compile tested for now

Change-Id: I2d5c58fc794563d402da24e19fee146df817472a
Signed-off-by: David Hendricks <dhendrix@chromium.org>
2012-04-25 11:31:42 -07:00

65 lines
1.8 KiB
C

/* Copyright (c) 2012 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.
*/
#ifndef __MESSAGE_IF_H
#define __MESSAGE_IF_H
#include <common.h>
/* Command interface between EC and AP */
enum {
/* Mask to convert a command byte into a command */
MSG_CMD_MASK = 0x7f,
/* The bytes which appear before the header in a message */
MSG_PREAMBLE = 0xff,
/* The header byte, which follows the preamble */
MSG_HEADER = 0xec,
MSG_HEADER_BYTES = 3,
MSG_TRAILER_BYTES = 2,
MSG_PROTO_BYTES = MSG_HEADER_BYTES + MSG_TRAILER_BYTES,
};
/* The command codes that we understand */
enum message_cmd_t {
/* control / status messages */
CMDC_NOP, /* No operation / ping */
CMDC_ID, /* Read EC ID */
/* functional messages */
CMDC_KEY_STATE = 0x20, /* Read key state */
};
/**
* Process a command received and return the response
*
* There is no time to compute a reply. The data should be ready
* immediately. This function can be called in interrupt context.
*
* The format of a reply is a sequence of bytes:
*
* <hdr> <len_lo> <len_hi> <msg bytes> <sum> <preamble bytes>
*
* The hdr byte is just a tag to indicate that the real message follows. It
* signals the end of any preamble required by the interface.
*
* The 16-bit length is the entire packet size, including the header, length
* bytes, message payload, checksum, and postamble byte.
*
* The checksum is calculated as the sum of the header, len byte and message.
*
* @param cmd Command to process (CMD_...)
* @param buff Pointer to buffer to store reponse
* @param max_len Maximum length of buffer
* @return number of bytes in reply, 0 if none, -1 for unknown command
*/
int message_process_cmd(int cmd, uint8_t *buff, int max_len);
#endif