?? lwmon.c
字號(hào):
*D* Design: wd@denx.deC* Coding: wd@denx.deV* Verification: dzu@denx.de ***********************************************************************/static uchar *key_match (uchar *kbd_data){ uchar magic[sizeof (kbd_magic_prefix) + 1]; uchar *suffix; uchar *kbd_magic_keys; /* * The following string defines the characters that can pe appended * to "key_magic" to form the names of environment variables that * hold "magic" key codes, i. e. such key codes that can cause * pre-boot actions. If the string is empty (""), then only * "key_magic" is checked (old behaviour); the string "125" causes * checks for "key_magic1", "key_magic2" and "key_magic5", etc. */ if ((kbd_magic_keys = getenv ("magic_keys")) == NULL) kbd_magic_keys = ""; /* loop over all magic keys; * use '\0' suffix in case of empty string */ for (suffix=kbd_magic_keys; *suffix || suffix==kbd_magic_keys; ++suffix) { sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);#if 0 printf ("### Check magic \"%s\"\n", magic);#endif if (compare_magic(kbd_data, getenv(magic)) == 0) { uchar cmd_name[sizeof (kbd_command_prefix) + 1]; char *cmd; sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix); cmd = getenv (cmd_name);#if 0 printf ("### Set PREBOOT to $(%s): \"%s\"\n", cmd_name, cmd ? cmd : "<<NULL>>");#endif *kbd_data = *suffix; return (cmd); } }#if 0 printf ("### Delete PREBOOT\n");#endif *kbd_data = '\0'; return (NULL);}#endif /* CONFIG_PREBOOT *//*---------------Board Special Commands: PIC read/write ---------------*/#if (CONFIG_COMMANDS & CFG_CMD_BSP)/***********************************************************************F* Function: int do_pic (cmd_tbl_t *cmdtp, int flag,F* int argc, char *argv[]) P*A*Z* *P* Parameters: cmd_tbl_t *cmdtpP* - Pointer to our command table entryP* int flagP* - If the CMD_FLAG_REPEAT bit is set, then this call isP* a repetitionP* int argcP* - Argument countP* char *argv[]P* - Array of the actual argumentsP*P* Returnvalue: intP* - 0 The command was handled successfullyP* 1 An error occurred *Z* Intention: Implement the "pic [read|write]" commands.Z* The read subcommand takes one argument, the register,Z* whereas the write command takes two, the register andZ* the new value. *D* Design: wd@denx.deC* Coding: wd@denx.deV* Verification: dzu@denx.de ***********************************************************************/int do_pic (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){ uchar reg, val; switch (argc) { case 3: /* PIC read reg */ if (strcmp (argv[1], "read") != 0) break; reg = simple_strtoul (argv[2], NULL, 16); printf ("PIC read: reg %02x: %02x\n\n", reg, pic_read (reg)); return 0; case 4: /* PIC write reg val */ if (strcmp (argv[1], "write") != 0) break; reg = simple_strtoul (argv[2], NULL, 16); val = simple_strtoul (argv[3], NULL, 16); printf ("PIC write: reg %02x val 0x%02x: %02x => ", reg, val, pic_read (reg)); pic_write (reg, val); printf ("%02x\n\n", pic_read (reg)); return 0; default: break; } printf ("Usage:\n%s\n", cmdtp->usage); return 1;}U_BOOT_CMD( pic, 4, 1, do_pic, "pic - read and write PIC registers\n", "read reg - read PIC register `reg'\n" "pic write reg val - write value `val' to PIC register `reg'\n");/***********************************************************************F* Function: int do_kbd (cmd_tbl_t *cmdtp, int flag,F* int argc, char *argv[]) P*A*Z* *P* Parameters: cmd_tbl_t *cmdtpP* - Pointer to our command table entryP* int flagP* - If the CMD_FLAG_REPEAT bit is set, then this call isP* a repetitionP* int argcP* - Argument countP* char *argv[]P* - Array of the actual argumentsP*P* Returnvalue: intP* - 0 is always returned. *Z* Intention: Implement the "kbd" command.Z* The keyboard status is read. The result is printed onZ* the console and written into the "keybd" environmentZ* variable. *D* Design: wd@denx.deC* Coding: wd@denx.deV* Verification: dzu@denx.de ***********************************************************************/int do_kbd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){ uchar kbd_data[KEYBD_DATALEN]; uchar keybd_env[2 * KEYBD_DATALEN + 1]; uchar val; int i;#if 0 /* Done in kbd_init */ i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);#endif /* Read keys */ val = KEYBD_CMD_READ_KEYS; i2c_write (kbd_addr, 0, 0, &val, 1); i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_DATALEN); puts ("Keys:"); for (i = 0; i < KEYBD_DATALEN; ++i) { sprintf (keybd_env + i + i, "%02X", kbd_data[i]); printf (" %02x", kbd_data[i]); } putc ('\n'); setenv ("keybd", keybd_env); return 0;}U_BOOT_CMD( kbd, 1, 1, do_kbd, "kbd - read keyboard status\n", NULL);/* Read and set LSB switch */#define CFG_PC_TXD1_ENA 0x0008 /* PC.12 *//***********************************************************************F* Function: int do_lsb (cmd_tbl_t *cmdtp, int flag,F* int argc, char *argv[]) P*A*Z* *P* Parameters: cmd_tbl_t *cmdtpP* - Pointer to our command table entryP* int flagP* - If the CMD_FLAG_REPEAT bit is set, then this call isP* a repetitionP* int argcP* - Argument countP* char *argv[]P* - Array of the actual argumentsP*P* Returnvalue: intP* - 0 The command was handled successfullyP* 1 An error occurred *Z* Intention: Implement the "lsb [on|off]" commands.Z* The lsb is switched according to the first parameter byZ* by signaling the PIC I/O expander.Z* Called with no arguments, the current setting isZ* printed. *D* Design: wd@denx.deC* Coding: wd@denx.deV* Verification: dzu@denx.de ***********************************************************************/int do_lsb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]){ uchar val; immap_t *immr = (immap_t *) CFG_IMMR; switch (argc) { case 1: /* lsb - print setting */ val = pic_read (0x60); printf ("LSB is o%s\n", (val & 0x20) ? "n" : "ff"); return 0; case 2: /* lsb on or lsb off - set switch */ val = pic_read (0x60); if (strcmp (argv[1], "on") == 0) { val |= 0x20; immr->im_ioport.iop_pcpar &= ~(CFG_PC_TXD1_ENA); immr->im_ioport.iop_pcdat |= CFG_PC_TXD1_ENA; immr->im_ioport.iop_pcdir |= CFG_PC_TXD1_ENA; } else if (strcmp (argv[1], "off") == 0) { val &= ~0x20; immr->im_ioport.iop_pcpar &= ~(CFG_PC_TXD1_ENA); immr->im_ioport.iop_pcdat &= ~(CFG_PC_TXD1_ENA); immr->im_ioport.iop_pcdir |= CFG_PC_TXD1_ENA; } else { break; } pic_write (0x60, val); return 0; default: break; } printf ("Usage:\n%s\n", cmdtp->usage); return 1;}U_BOOT_CMD( lsb, 2, 1, do_lsb, "lsb - check and set LSB switch\n", "on - switch LSB on\n" "lsb off - switch LSB off\n" "lsb - print current setting\n");#endif /* CFG_CMD_BSP *//*----------------------------- Utilities -----------------------------*//***********************************************************************F* Function: uchar pic_read (uchar reg) P*A*Z* *P* Parameters: uchar regP* - Register to readP*P* Returnvalue: ucharP* - Value read from register *Z* Intention: Read a register from the PIC I/O expander. *D* Design: wd@denx.deC* Coding: wd@denx.deV* Verification: dzu@denx.de ***********************************************************************/uchar pic_read (uchar reg){ return (i2c_reg_read (CFG_I2C_PICIO_ADDR, reg));}/***********************************************************************F* Function: void pic_write (uchar reg, uchar val) P*A*Z* *P* Parameters: uchar regP* - Register to readP* uchar valP* - Value to writeP*P* Returnvalue: none *Z* Intention: Write to a register on the PIC I/O expander. *D* Design: wd@denx.deC* Coding: wd@denx.deV* Verification: dzu@denx.de ***********************************************************************/void pic_write (uchar reg, uchar val){ i2c_reg_write (CFG_I2C_PICIO_ADDR, reg, val);}/*---------------------- Board Control Functions ----------------------*//***********************************************************************F* Function: void board_poweroff (void) P*A*Z* *P* Parameters: noneP*P* Returnvalue: none *Z* Intention: Turn off the battery power and loop endless, so thisZ* should better be the last function you call... *D* Design: wd@denx.deC* Coding: wd@denx.deV* Verification: dzu@denx.de ***********************************************************************/void board_poweroff (void){ /* Turn battery off */ ((volatile immap_t *)CFG_IMMR)->im_ioport.iop_pcdat &= ~(1 << (31 - 13)); while (1);}#ifdef CONFIG_MODEM_SUPPORTstatic int key_pressed(void){ uchar kbd_data[KEYBD_DATALEN]; uchar val; /* Read keys */ val = KEYBD_CMD_READ_KEYS; i2c_write (kbd_addr, 0, 0, &val, 1); i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_DATALEN); return (compare_magic(kbd_data, CONFIG_MODEM_KEY_MAGIC) == 0);}#endif /* CONFIG_MODEM_SUPPORT */#ifdef CONFIG_POST/* * Returns 1 if keys pressed to start the power-on long-running tests * Called from board_init_f(). */int post_hotkeys_pressed(void){ uchar kbd_data[KEYBD_DATALEN]; uchar val; /* Read keys */ val = KEYBD_CMD_READ_KEYS; i2c_write (kbd_addr, 0, 0, &val, 1); i2c_read (kbd_addr, 0, 0, kbd_data, KEYBD_DATALEN); return (compare_magic(kbd_data, CONFIG_POST_KEY_MAGIC) == 0);}#endif
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -