int gpio_request(unsigned gpio, const char *label) { if (check_gpio(gpio) < 0) return -EINVAL; /* * Allow that the identical GPIO can * be requested from the same driver twice * Do nothing and return - */ if (cmp_label(gpio, label) == 0) return 0; if (unlikely(is_reserved(gpio, gpio, 1))) { printf("bfin-gpio: GPIO %d is already reserved by %s !\n", gpio, get_label(gpio)); return -EBUSY; } if (unlikely(is_reserved(peri, gpio, 1))) { printf("bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n", gpio, get_label(gpio)); return -EBUSY; } else { /* Reset POLAR setting when acquiring a gpio for the first time */ set_gpio_polar(gpio, 0); } reserve(gpio, gpio); set_label(gpio, label); port_setup(gpio, GPIO_USAGE); return 0; }
int special_gpio_request(unsigned gpio, const char *label) { /* * Allow that the identical GPIO can * be requested from the same driver twice * Do nothing and return - */ if (cmp_label(gpio, label) == 0) return 0; if (unlikely(is_reserved(special_gpio, gpio, 1))) { printf("bfin-gpio: GPIO %d is already reserved by %s !\n", gpio, get_label(gpio)); return -EBUSY; } if (unlikely(is_reserved(peri, gpio, 1))) { printf("bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n", gpio, get_label(gpio)); return -EBUSY; } reserve(special_gpio, gpio); reserve(peri, gpio); set_label(gpio, label); port_setup(gpio, GPIO_USAGE); return 0; }
int main(void) { int i = 0; uint8_t stat; char buf[10]; char i_buf[33]; port_setup(); uart_init(); stdout = stdin = &uart_str; spi_init(); printf("IQRF v1.0 Press enter...\n"); for(;;) { if (fgets(buf, sizeof buf - 1, stdin) == NULL) break; iqrf_send_byte(buf[0]); if (fRxIQRF) { for (i = 0; i < fRxIQRF; i++) sprintf(&i_buf[i], "%c", iqrfRx[i]); i_buf[fRxIQRF] = '\0'; printf("%s\n", i_buf); fRxIQRF = 0; } } return 0; }
static void endless_loop(void) { val_context_t *context; /* * signal handlers to exit gracefully */ #ifdef SIGTERM signal(SIGTERM, sig_shutdown); #endif #ifdef SIGINT signal(SIGINT, sig_shutdown); #endif /* * open a port and process incoming packets */ port_setup(1153); if (VAL_NO_ERROR != val_create_context(NULL, &context)) { val_log(NULL, LOG_ERR, "Cannot create validator context. Exiting."); return; } while (!done) { wait_for_packet(); process_packet(context); } val_free_context(context); val_free_validator_state(); }
/* If we are booting from SPI and our board lacks a strong enough pull up, * the core can reset and execute the bootrom faster than the resistor can * pull the signal logically high. To work around this (common) error in * board design, we explicitly set the pin back to GPIO mode, force /CS * high, and wait for the electrons to do their thing. * * This function only makes sense to be called from reset code, but it * lives here as we need to force all the GPIO states w/out going through * BUG() checks and such. */ void bfin_reset_boot_spi_cs(unsigned short pin) { unsigned short gpio = P_IDENT(pin); port_setup(gpio, GPIO_USAGE); gpio_array[gpio_bank(gpio)]->data_set = gpio_bit(gpio); AWA_DUMMY_READ(data_set); udelay(1); }
int peripheral_request(unsigned short per, const char *label) { unsigned short ident = P_IDENT(per); /* * Don't cares are pins with only one dedicated function */ if (per & P_DONTCARE) return 0; if (!(per & P_DEFINED)) return -ENODEV; BUG_ON(ident >= MAX_RESOURCES); /* If a pin can be muxed as either GPIO or peripheral, make * sure it is not already a GPIO pin when we request it. */ if (unlikely(!check_gpio(ident) && is_reserved(gpio, ident, 1))) { printf("%s: Peripheral %d is already reserved as GPIO by %s !\n", __func__, ident, get_label(ident)); return -EBUSY; } if (unlikely(is_reserved(peri, ident, 1))) { /* * Pin functions like AMC address strobes my * be requested and used by several drivers */ if (!(per & P_MAYSHARE)) { /* * Allow that the identical pin function can * be requested from the same driver twice */ if (cmp_label(ident, label) == 0) goto anyway; printf("%s: Peripheral %d function %d is already reserved by %s !\n", __func__, ident, P_FUNCT2MUX(per), get_label(ident)); return -EBUSY; } } anyway: reserve(peri, ident); portmux_setup(per); port_setup(ident, PERIPHERAL_USAGE); set_label(ident, label); return 0; }
TM1638::TM1638() : _dotMask(0) { port_setup(); send_cmd(TM_DATA_CMD | TM_WRITE_DISP); send_cmd(TM_DISP_CTRL | TM_DISP_ENABLE | TM_DISP_PWM_MASK); clear(); clearLEDs(); }
void peripheral_free(unsigned short per) { unsigned short ident = P_IDENT(per); if (per & P_DONTCARE) return; if (!(per & P_DEFINED)) return; if (unlikely(!is_reserved(peri, ident, 0))) return; if (!(per & P_MAYSHARE)) port_setup(ident, GPIO_USAGE); unreserve(peri, ident); set_label(ident, "free"); }