Files
OpenCellular/common/port80.c
Vincent Palatin c21f07e58e register console commands at compile-time
Instead of using a runtime callback to register the console commands,
put them in a special linker section. So we can do a macro to "register"
them during the build.

It saves 684 bytes and a few microseconds at startup.

Signed-off-by: Vincent Palatin <vpalatin@chromium.org>

BUG=None
TEST=run a few commands from the BDS command line.

Change-Id: Id33ea210b9035bf76ed720373c74c5dd24ccd1b1
2012-01-24 00:50:08 +00:00

67 lines
1.6 KiB
C

/* Copyright (c) 2011 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.
*/
/* Port 80 module for Chrome EC */
#include "console.h"
#include "port80.h"
#include "uart.h"
#include "util.h"
#define HISTORY_LEN 16
static uint8_t history[HISTORY_LEN];
static int head = 0; /* Next index to use / oldest previous entry */
static int last_data = -1; /* Last data written to port 80 */
void port_80_write(int data)
{
/* Ignore duplicate writes, since the linux kernel writes to port 80
* as a delay mechanism during boot. */
if (data == last_data)
return;
/* TODO: post to SWI and print from there? This currently
* prints from inside the LPC interrupt itself. */
uart_printf("[Port 80: 0x%02x]\n", data);
last_data = data;
history[head] = data;
head = (head + 1) & (HISTORY_LEN - 1);
}
/*****************************************************************************/
/* Console commands */
static int command_port80(int argc, char **argv)
{
int h = head;
int i;
/* Technically, if a port 80 write comes in while we're
* printing this, we could print an incorrect history.
* Probably not worth the complexity to work around that. */
uart_puts("Last port 80 writes:");
for (i = 0; i < HISTORY_LEN; i++)
uart_printf(" %02x", history[(h + i) & (HISTORY_LEN - 1)]);
uart_puts(" <--newest\n");
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(port80, command_port80);
/*****************************************************************************/
/* Initialization */
int port_80_init(void)
{
memset(history, 0, sizeof(history));
return EC_SUCCESS;
}