📄 trab_fkt.c
字号:
if ((result & (1 << i)) == 0) printf("0"); else printf("1"); } printf("\n"); return 0;}int do_power_switch (void){ int result; S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO(); /* configure GPE7 as input */ gpio->PECON &= ~(0x3 << (2 * 7)); /* signal GPE7 from power switch is low active: 0=on , 1=off */ result = ((gpio->PEDAT & (1 << 7)) == (1 << 7)) ? 0 : 1; print_identifier (); printf("%d\n", result); return 0;}int do_fill_level (void){ int result; result = *CPLD_FILL_LEVEL; /* read CPLD */ debug ("%s: cpld_fuellstand (32 bit) %#x\n", __FUNCTION__, result); /* print result to console */ print_identifier (); if ((result & (1 << 16)) == 0) printf("0\n"); else printf("1\n"); return 0;}int do_rotary_switch (void){ int result; /* * Please note, that the default values of the direction bits are * undefined after reset. So it is a good idea, to make first a dummy * call to this function, to clear the direction bits and set so to * proper values. */ result = *CPLD_ROTARY_SWITCH; /* read CPLD */ debug ("%s: cpld_inc (32 bit) %#x\n", __FUNCTION__, result); *CPLD_ROTARY_SWITCH |= (3 << 16); /* clear direction bits in CPLD */ /* print result to console */ print_identifier (); if ((result & (1 << 16)) == (1 << 16)) printf("R"); if ((result & (1 << 17)) == (1 << 17)) printf("L"); if (((result & (1 << 16)) == 0) && ((result & (1 << 17)) == 0)) printf("0"); if ((result & (1 << 18)) == 0) printf("0\n"); else printf("1\n"); return 0;}int do_vfd_id (void){ int i; long int pcup_old, pccon_old; int vfd_board_id; S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO(); /* try to red vfd board id from the value defined by pull-ups */ pcup_old = gpio->PCUP; pccon_old = gpio->PCCON; gpio->PCUP = (gpio->PCUP & 0xFFF0); /* activate GPC0...GPC3 pull-ups */ gpio->PCCON = (gpio->PCCON & 0xFFFFFF00); /* configure GPC0...GPC3 as * inputs */ udelay (10); /* allow signals to settle */ vfd_board_id = (~gpio->PCDAT) & 0x000F; /* read GPC0...GPC3 port pins */ gpio->PCCON = pccon_old; gpio->PCUP = pcup_old; /* print vfd_board_id to console */ print_identifier (); for (i = 0; i < 4; i++) { if ((vfd_board_id & (1 << i)) == 0) printf("0"); else printf("1"); } printf("\n"); return 0;}int do_buzzer (char **argv){ int counter; S3C24X0_TIMERS * const timers = S3C24X0_GetBase_TIMERS(); S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO(); /* set prescaler for timer 2, 3 and 4 */ timers->TCFG0 &= ~0xFF00; timers->TCFG0 |= 0x0F00; /* set divider for timer 2 */ timers->TCFG1 &= ~0xF00; timers->TCFG1 |= 0x300; /* set frequency */ counter = (PCLK / BUZZER_FREQ) >> 9; timers->ch[2].TCNTB = counter; timers->ch[2].TCMPB = counter / 2; if (strcmp (argv[2], "on") == 0) { debug ("%s: frequency: %d\n", __FUNCTION__, BUZZER_FREQ); /* configure pin GPD7 as TOUT2 */ gpio->PDCON &= ~0xC000; gpio->PDCON |= 0x8000; /* start */ timers->TCON = (timers->TCON | UPDATE2 | RELOAD2) & ~INVERT2; timers->TCON = (timers->TCON | START2) & ~UPDATE2; return (0); } else if (strcmp (argv[2], "off") == 0) { /* stop */ timers->TCON &= ~(START2 | RELOAD2); /* configure GPD7 as output and set to low */ gpio->PDCON &= ~0xC000; gpio->PDCON |= 0x4000; gpio->PDDAT &= ~0x80; return (0); } printf ("%s: invalid parameter %s\n", __FUNCTION__, argv[2]); return 1;}int do_led (char **argv){ S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO(); /* configure PC14 and PC15 as output */ gpio->PCCON &= ~(0xF << 28); gpio->PCCON |= (0x5 << 28); /* configure PD0 and PD4 as output */ gpio->PDCON &= ~((0x3 << 8) | 0x3); gpio->PDCON |= ((0x1 << 8) | 0x1); switch (simple_strtoul(argv[2], NULL, 10)) { case 0: case 1: break; case 2: if (strcmp (argv[3], "on") == 0) gpio->PCDAT |= (1 << 14); else gpio->PCDAT &= ~(1 << 14); return 0; case 3: if (strcmp (argv[3], "on") == 0) gpio->PCDAT |= (1 << 15); else gpio->PCDAT &= ~(1 << 15); return 0; case 4: if (strcmp (argv[3], "on") == 0) gpio->PDDAT |= (1 << 0); else gpio->PDDAT &= ~(1 << 0); return 0; case 5: if (strcmp (argv[3], "on") == 0) gpio->PDDAT |= (1 << 4); else gpio->PDDAT &= ~(1 << 4); return 0; default: break; } printf ("%s: invalid parameter %s\n", __FUNCTION__, argv[2]); return 1;}int do_full_bridge (char **argv){ S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO(); /* configure PD5 and PD6 as output */ gpio->PDCON &= ~((0x3 << 5*2) | (0x3 << 6*2)); gpio->PDCON |= ((0x1 << 5*2) | (0x1 << 6*2)); if (strcmp (argv[2], "+") == 0) { gpio->PDDAT |= (1 << 5); gpio->PDDAT |= (1 << 6); return 0; } else if (strcmp (argv[2], "-") == 0) { gpio->PDDAT &= ~(1 << 5); gpio->PDDAT |= (1 << 6); return 0; } else if (strcmp (argv[2], "off") == 0) { gpio->PDDAT &= ~(1 << 5); gpio->PDDAT &= ~(1 << 6); return 0; } printf ("%s: invalid parameter %s\n", __FUNCTION__, argv[2]); return 1;}/* val must be in [0, 4095] */static inline unsigned long tsc2000_to_uv (u16 val){ return ((250000 * val) / 4096) * 10;}int do_dac (char **argv){ int brightness; /* initialize SPI */ spi_init (); if (((brightness = simple_strtoul (argv[2], NULL, 10)) < 0) || (brightness > 255)) { printf ("%s: invalid parameter %s\n", __FUNCTION__, argv[2]); return 1; } tsc2000_write(TSC2000_REG_DACCTL, 0x0); /* Power up DAC */ tsc2000_write(TSC2000_REG_DAC, brightness & 0xff); return 0;}int do_v_bat (void){ unsigned long ret, res; /* initialize SPI */ spi_init (); tsc2000_write(TSC2000_REG_ADC, 0x1836); /* now wait for data available */ adc_wait_conversion_done(); ret = tsc2000_read(TSC2000_REG_BAT1); res = (tsc2000_to_uv(ret) + 1250) / 2500; res += (ERROR_BATTERY * res) / 1000; print_identifier (); printf ("%ld", (res / 100)); printf (".%ld", ((res % 100) / 10)); printf ("%ld V\n", (res % 10)); return 0;}int do_pressure (void){ /* initialize SPI */ spi_init (); tsc2000_write(TSC2000_REG_ADC, 0x2436); /* now wait for data available */ adc_wait_conversion_done(); print_identifier (); printf ("%d\n", tsc2000_read(TSC2000_REG_AUX2)); return 0;}int do_motor_contact (void){ int result; result = *CPLD_FILL_LEVEL; /* read CPLD */ debug ("%s: cpld_fuellstand (32 bit) %#x\n", __FUNCTION__, result); /* print result to console */ print_identifier (); if ((result & (1 << 17)) == 0) printf("0\n"); else printf("1\n"); return 0;}int do_motor (char **argv){ S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO(); /* Configure I/O port */ gpio->PGCON &= ~(0x3 << 0); gpio->PGCON |= (0x1 << 0); if (strcmp (argv[2], "on") == 0) { gpio->PGDAT &= ~(1 << 0); return 0; } if (strcmp (argv[2], "off") == 0) { gpio->PGDAT |= (1 << 0); return 0; } printf ("%s: invalid parameter %s\n", __FUNCTION__, argv[2]); return 1;}static void print_identifier (void){ printf ("## FKT: ");}int do_pwm (char **argv){ int counter; S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO(); S3C24X0_TIMERS * const timers = S3C24X0_GetBase_TIMERS(); if (strcmp (argv[2], "on") == 0) { /* configure pin GPD8 as TOUT3 */ gpio->PDCON &= ~(0x3 << 8*2); gpio->PDCON |= (0x2 << 8*2); /* set prescaler for timer 2, 3 and 4 */ timers->TCFG0 &= ~0xFF00; timers->TCFG0 |= 0x0F00; /* set divider for timer 3 */ timers->TCFG1 &= ~(0xf << 12); timers->TCFG1 |= (0x3 << 12); /* set frequency */ counter = (PCLK / PWM_FREQ) >> 9; timers->ch[3].TCNTB = counter; timers->ch[3].TCMPB = counter / 2; /* start timer */ timers->TCON = (timers->TCON | UPDATE3 | RELOAD3) & ~INVERT3; timers->TCON = (timers->TCON | START3) & ~UPDATE3; return 0; } if (strcmp (argv[2], "off") == 0) { /* stop timer */ timers->TCON &= ~(START2 | RELOAD2); /* configure pin GPD8 as output and set to 0 */ gpio->PDCON &= ~(0x3 << 8*2); gpio->PDCON |= (0x1 << 8*2); gpio->PDDAT &= ~(1 << 8); return 0; } printf ("%s: invalid parameter %s\n", __FUNCTION__, argv[2]); return 1;}int do_thermo (char **argv){ int channel, res; tsc2000_reg_init (); if (strcmp (argv[2], "all") == 0) { int i; for (i=0; i <= 15; i++) { res = tsc2000_read_channel(i); print_identifier (); printf ("c%d: %d\n", i, res); } return 0; } channel = simple_strtoul (argv[2], NULL, 10); res = tsc2000_read_channel(channel); print_identifier (); printf ("%d\n", res); return 0; /* return OK */}int do_touch (char **argv){ int x, y; if (strcmp (argv[2], "tl") == 0) {#ifdef CONFIG_TOUCH_WAIT_PRESSED touch_wait_pressed();#else { int i; for (i = 0; i < (TOUCH_TIMEOUT * 1000); i++) { if (touch_check_pressed ()) { break; } udelay (1000); /* pause 1 ms */ } } if (!touch_check_pressed()) { print_identifier (); printf ("error: touch not pressed\n"); return 1; }#endif /* CONFIG_TOUCH_WAIT_PRESSED */ touch_read_x_y (&x, &y); print_identifier (); printf ("x=%d y=%d\n", x, y); return touch_write_clibration_values (CALIB_TL, x, y); } else if (strcmp (argv[2], "dr") == 0) {#ifdef CONFIG_TOUCH_WAIT_PRESSED touch_wait_pressed();#else { int i; for (i = 0; i < (TOUCH_TIMEOUT * 1000); i++) { if (touch_check_pressed ()) { break; } udelay (1000); /* pause 1 ms */ } } if (!touch_check_pressed()) { print_identifier (); printf ("error: touch not pressed\n"); return 1; }#endif /* CONFIG_TOUCH_WAIT_PRESSED */ touch_read_x_y (&x, &y); print_identifier (); printf ("x=%d y=%d\n", x, y); return touch_write_clibration_values (CALIB_DR, x, y); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -