--- embedtools/src/pceng_run.c 2011/07/22 15:03:30 1.1.2.2 +++ embedtools/src/pceng_run.c 2011/07/23 23:41:00 1.1.2.3 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ - * $Id: pceng_run.c,v 1.1.2.2 2011/07/22 15:03:30 misho Exp $ + * $Id: pceng_run.c,v 1.1.2.3 2011/07/23 23:41:00 misho Exp $ * ************************************************************************* The ELWIX and AITNET software is distributed under the following @@ -47,16 +47,96 @@ SUCH DAMAGE. #include "pceng.h" +const u_int led_base[2][4] = {{0xf410, 0xf400, 0xf400, 0xf400}, + {0x61b0, 0x6100, 0x6180, 0x6180}}; +const int led_bit[2][4] = {{8, 2, 3, 18}, {8, 6, 9, 11}}; +const int gpio_off[2] = { 0x4, 0x10 }; + + +static inline board_t +getBoard() +{ + board_t type; + char szStr[STRSIZ]; + + FTRACE(3); + + cfg_LoadAttribute(&cfg, CFG("pceng"), CFG("board"), CFG(szStr), sizeof szStr, DEFAULT_BOARD); + if (!strcasecmp(szStr, "alix")) + type = alix; + else if (!strcasecmp(szStr, "wrap")) + type = wrap; + else { + type = unknown; + syslog(LOG_ERR, "Error:: unknown board type %s", szStr); + } + + return type; +} + +static u_int +gpioRead(u_char ledno, u_char state) +{ + u_int n; + board_t type = getBoard(); + + FTRACE(3); + + switch (type) { + case wrap: + n = inl(led_base[type - 1][ledno] + gpio_off[type - 1]); + if (n & (1 << led_bit[type - 1][ledno])) + n = 1; + else + n = 0; + break; + case alix: + n = inl(led_base[type - 1][ledno]); + if (n & (1 << led_bit[type - 1][ledno])) + n = 0; + else + n = 1; + break; + default: + return -1; + } + + return n; +} + + int -LED(int io, u_char ledno, u_char state) +LED(u_char ledno, u_char state) { + u_int n; + board_t type = getBoard(); + FTRACE(3); + switch (type) { + case wrap: + n = inl(led_base[type - 1][ledno]); + if (state) + n |= (1 << led_bit[type - 1][ledno]); + else + n &= ~(1 << led_bit[type - 1][ledno]); + break; + case alix: + if (state) + n = (1 << (led_bit[type - 1][ledno] + gpio_off[type - 1])); + else + n = (1 << led_bit[type - 1][ledno]); + break; + default: + return -1; + } + + outl(led_base[type - 1][ledno], n); return 0; } int -Run(int io) +Run() { FTRACE(3);