/* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); palSetPad(IOPORT1, LED1); WDGConfig WDG_config = { .pause_on_sleep = 0, .pause_on_halt = 0, .timeout_ms = 5000, .callback = timeout_callback }; wdgStart(&WDGD1, &WDG_config); /* * Normal main() thread activity, in this demo it does nothing. */ while (true) { if (palReadPad(IOPORT1, BTN1) == 0) { palTogglePad(IOPORT1, LED1); wdgReset(&WDGD1); } chThdSleepMilliseconds(500); } }
/** * @brief Single word read from the SSI encoder * @return Most recent SSI byte (may also be buffered in stream mode) */ uint32_t ssi_read(void) { uint8_t bit = SSI_LENGTH; // Set length counter uint32_t working_buffer = 0; if(ssi_mode == SSI_MODE_STREAM) { led_count = (led_count+1)%25;// LED handling if(!led_count) led_toggle(); } while(bit > 0) { // Falling edge palClearPad(SSI_SIGNAL_PORT, SSI_CLK_PIN); // Toggle clock ssi_delay(); ssi_delay(); ssi_delay(); // Rising edge palSetPad(SSI_SIGNAL_PORT, SSI_CLK_PIN); // Toggle clock working_buffer = (working_buffer << 1) + palReadPad(SSI_SIGNAL_PORT, SSI_DATA_PIN); ssi_delay(); bit--; // Decrement bit counter } working_buffer = ((1<<SSI_LENGTH) - 1) & (~working_buffer); // Invert bits in buffer to simulate return working_buffer; }
static msg_t Th2(void *p) { (void)p; chRegSetThreadName("Th2"); while (TRUE) { /////DEVICE 2/////////// if(palReadPad(GPIO1_PORT, GPIO1_PAD) != PAL_HIGH) { palWritePad(GPIO22_PORT,GPIO22_PAD,PAL_HIGH); chSemWait(&mySemaphore); chprintf((BaseSequentialStream *)&SD1, "D2ON\r\n"); chSemSignal(&mySemaphore); }else{ palWritePad(GPIO22_PORT,GPIO22_PAD,PAL_LOW); chSemWait(&mySemaphore); chprintf((BaseSequentialStream *)&SD1, "D2OFF\r\n"); chSemSignal(&mySemaphore); } chThdSleepMilliseconds(1000); } return 0; }
/* * Application entry point. */ int main(void) { halInit(); chSysInit(); /* * Serial port initialization. */ sdStart(&SD1, NULL); chprintf((BaseSequentialStream *)&SD1, "BCM2835 GPIO Demonstration\r\n"); ioportid_t ledPort = ONBOARD_LED_PORT; uint32_t ledPad = ONBOARD_LED_PAD; palSetPadMode(ledPort, ledPad, PAL_MODE_OUTPUT); palSetPad(ledPort, ledPad); palSetPadMode(GPIO4_PORT, GPIO4_PAD, PAL_MODE_INPUT_PULLUP); for (;;) { uint32_t button_state = palReadPad(GPIO4_PORT, GPIO4_PAD); if (button_state) { palSetPad(ledPort, ledPad); } else { palClearPad(ledPort, ledPad); } } /* * Events servicing loop. */ chThdWait(chThdSelf()); return 0; }
/* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* * Activates the serial driver 2 using the driver default configuration. */ sdStart(&SD2, NULL); /* * Starts the LED blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); while(TRUE) { if (!palReadPad(IOPORT5, PORTE_BUTTON)) TestThread(&SD2); chThdSleepMilliseconds(500); } return 0; }
/* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* * Activates the serial driver 2 using the driver default configuration. * PA2(TX) and PA3(RX) are routed to USART2. */ sdStart(&SD2, NULL); palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7)); palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7)); /* * Creates the example thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* * Normal main() thread activity, in this demo it just performs * a shell respawn upon its termination. */ while (TRUE) { if (palReadPad(GPIOA, GPIOA_BUTTON)) TestThread(&SD2); chThdSleepMilliseconds(500); } }
/** * @brief SDC card detection. */ bool_t sdc_lld_is_card_inserted(SDCDriver *sdcp) { static bool_t last_status = FALSE; if (blkIsTransferring(sdcp)) return last_status; return last_status = (bool_t)palReadPad(GPIOC, GPIOC_SD_D3); }
/*Callback function for the interrupt on RC Channel 4. */ static void extcb4(EXTDriver *extp, expchannel_t channel) { (void)extp ; (void)channel ; chSysLockFromIsr() ; if(palReadPad(RC4_PORT, RC4_PIN) == PAL_HIGH) { start[3] = halGetCounterValue() ; } else if(start[3] && (palReadPad(RC4_PORT, RC4_PIN) == PAL_LOW)) { float tmp = convertCounterToMilliseconds(start[3], halGetCounterValue()) ; if(RC_IN_RANGE(tmp)) RCInput[3] = tmp ; start[3] = 0 ; } chSysUnlockFromIsr() ; }
/* * Entry point, note, the main() function is already a thread in the system * on entry. */ int main(int argc, char **argv) { (void)argc; (void)argv; /* * Activates the serial driver 2 using the driver default configuration. */ sdStart(&SD2, NULL); /* * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and check the button state. */ while (TRUE) { if (palReadPad(IOPORT1, GPIOA_BUTTON)) TestThread(&SD2); chThdSleepMilliseconds(500); } return 0; }
/* * Application entry point. */ void main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* * Activates the serial driver 1 using the driver default configuration. * The STM8L-Discovery requires USART1 pins remapping on PA2 and PA3. */ SYSCFG->RMPCR1 = 0x1C; sdStart(&SD1, NULL); /* * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* * Normal main() thread activity. */ while (TRUE) { if (palReadPad(GPIOC, PC_BUTTON) == PAL_LOW) TestThread(&SD1); chThdSleepMilliseconds(1000); } }
/** * @brief Function for detecting stuck slaves (SDA = 0 and SCL = 1) and tries to clear the bus. * * @return * @retval false Bus is stuck. * @retval true Bus is clear. */ static void i2c_clear_bus(I2CDriver *i2cp) { const I2CConfig *cfg = i2cp->config; uint8_t i; IOPORT1->PIN_CNF[cfg->scl_pad] = I2C_PIN_CNF; IOPORT1->PIN_CNF[cfg->sda_pad] = I2C_PIN_CNF; I2C_HIGH(cfg->sda_pad); I2C_HIGH(cfg->scl_pad); IOPORT1->PIN_CNF[cfg->scl_pad] = I2C_PIN_CNF_CLR; IOPORT1->PIN_CNF[cfg->sda_pad] = I2C_PIN_CNF_CLR; nrf_delay_us(4); for(i = 0; i < 9; i++) { if (palReadPad(IOPORT1, cfg->sda_pad)) { if(i > 0) break; else return; } I2C_LOW(cfg->scl_pad); nrf_delay_us(4); I2C_HIGH(cfg->scl_pad); nrf_delay_us(4); } I2C_LOW(cfg->sda_pad); nrf_delay_us(4); I2C_HIGH(cfg->sda_pad); }
/* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* * Activates the serial driver 2 using the driver default configuration. */ sdStart(&SD2, NULL); /* * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and check the button state. */ while (true) { if (!palReadPad(GPIOC, GPIOC_BUTTON)) TestThread(&SD2); chThdSleepMilliseconds(500); } }
/** * Reset the encoder counter. Should be called from the index interrupt. */ void encoder_reset(void) { // Only reset if the pin is still high to avoid too short pulses, which // most likely are noise. __NOP(); __NOP(); __NOP(); __NOP(); if (palReadPad(HW_HALL_ENC_GPIO3, HW_HALL_ENC_PIN3)) { const unsigned int cnt = HW_ENC_TIM->CNT; static int bad_pulses = 0; const unsigned int lim = enc_counts / 20; if (index_found) { // Some plausibility filtering. if (cnt > (enc_counts - lim) || cnt < lim) { HW_ENC_TIM->CNT = 0; bad_pulses = 0; } else { bad_pulses++; if (bad_pulses > 5) { index_found = 0; } } } else { HW_ENC_TIM->CNT = 0; index_found = true; bad_pulses = 0; } } }
/* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* * Activates the SD1 and SPI1 drivers. */ sdStart(&SD4, NULL); /* Default: 38400,8,N,1. */ /* * Creates the blinker threads. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* * Normal main() thread activity. */ while (TRUE) { if (!palReadPad(GPIO3, GPIO3_SW_USER1)) { TestThread(&SD4); } chThdSleepMilliseconds(100); } }
bool_t pyro_continuity(uint8_t pad) { if((palReadPad(GPIOE, pad)) == PAL_LOW) return TRUE; else return FALSE; }
int main(void) { halInit(); chSysInit(); /* * This initialization requires the OS already active because it uses delay * APIs inside. */ int active = GPIOB_LED4; int inactive = GPIOB_LED3; palSetPadMode(GPIOB, GPIOB_LED4, PAL_MODE_OUTPUT_PUSHPULL); palSetPadMode(GPIOB, GPIOB_LED3, PAL_MODE_OUTPUT_PUSHPULL); palSetPad(GPIOB, active); palClearPad(GPIOB, inactive); while (1) { if (palReadPad(GPIOA, GPIOA_BUTTON)) { int store = active; active = inactive; inactive = store; palSetPad(GPIOB, active); palClearPad(GPIOB, inactive); } chThdSleepMilliseconds(500); } }
/* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* * Activates the serial driver 1 using the driver default configuration. * PA9(TX) and PA10(RX) are routed to USART1. */ sdStart(&SD2, NULL); /* * Creates the example thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO+1, Thread1, NULL); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and check the button state, when the button is * pressed the test procedure is launched. */ while (TRUE) { if (palReadPad(GPIOA, GPIOA_BUTTON)) TestThread(&SD2); chThdSleepMilliseconds(500); } }
static msg_t ivThread(int param) { chRegSetThreadName("IdleValve"); int currentIdleValve = -1; while (TRUE) { chThdSleepMilliseconds(100); // this value is not used yet idleSwitchState = palReadPad(getHwPort(boardConfiguration->idleSwitchPin), getHwPin(boardConfiguration->idleSwitchPin)); if (!isIdleControlActive) continue; int nowSec = chTimeNowSeconds(); int newValue = getIdle(&idle, getRpm(), nowSec); if (currentIdleValve != newValue) { currentIdleValve = newValue; setIdleValvePwm(newValue); } } #if defined __GNUC__ return -1; #endif }
int isUserButtonPressed(unsigned int timeOut) { const int FIVE_HUNDRED_MILLISECONDS = 500; // User button is connected to PA0. palSetPadMode(GPIOA, 0, PAL_MODE_INPUT); int userButtonPressed = 0; while (timeOut > 0) { timeOut--; if (!userButtonPressed) { userButtonPressed = palReadPad(GPIOA, 0); } // Indicate the checking process by blinking the LEDs if (userButtonPressed) { changeStateLED(RED, ON); chThdSleepMilliseconds(FIVE_HUNDRED_MILLISECONDS); changeStateLED(RED, OFF); chThdSleepMilliseconds(FIVE_HUNDRED_MILLISECONDS); } else { changeStateLED(BLUE, ON); chThdSleepMilliseconds(FIVE_HUNDRED_MILLISECONDS); changeStateLED(BLUE, OFF); chThdSleepMilliseconds(FIVE_HUNDRED_MILLISECONDS); } } return userButtonPressed; }
/* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* * Activates the serial driver 1 using the driver default configuration. */ sdStart(&SD1, NULL); /* * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* * Normal main() thread activity, in this demo it does nothing except * checking a button and run a test suite if button was pressed. */ while (TRUE) { if (!palReadPad(IOPORT6, P6_I_BUTTON)) TestThread(&SD1); chThdSleepMilliseconds(500); } return 0; }
/* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* * Activates the serial driver 1 using the driver default configuration. */ sdStart(&SD1, NULL); /* * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* * Creates the LWIP threads (it changes priority internally). */ chThdCreateStatic(wa_lwip_thread, LWIP_THREAD_STACK_SIZE, NORMALPRIO + 1, lwip_thread, NULL); /* * Creates the HTTP thread (it changes priority internally). */ chThdCreateStatic(wa_http_server, sizeof(wa_http_server), NORMALPRIO + 1, http_server, NULL); /* * Normal main() thread activity. */ while (TRUE) { chThdSleepMilliseconds(500); if (!palReadPad(IOPORT2, PIOB_SW1)) sdWrite(&SD1, (uint8_t *)"Hello World!\r\n", 14); if (!palReadPad(IOPORT2, PIOB_SW2)) TestThread(&SD1); } return 0; }
/** * @brief Function performing read of single bit. * @note It must be callable from any context. */ static ioline_t ow_read_bit(onewireDriver *owp) { #if ONEWIRE_SYNTH_SEARCH_TEST (void)owp; return _synth_ow_read_bit(); #else return palReadPad(owp->config->port, owp->config->pad); #endif }
/* * Card detection through the card internal pull-up on D3. */ bool_t mmc_lld_is_card_inserted(MMCDriver *mmcp) { static bool_t last_status = FALSE; (void)mmcp; if ((palReadLatch(GPIOA) & PAL_PORT_BIT(GPIOA_SPI3_CS_MMC)) == 0) return last_status; return last_status = (bool_t)palReadPad(GPIOA, GPIOA_SPI3_CS_MMC); }
void bus_power_toggle(void) { if (palReadPad(GPIOB, GPIOB_V_BUS_ENABLE)) { bus_power(false); } else { bus_power(true); } }
//----------------------------------------------------------------------------- void btn_1_exti_cb(EXTDriver *extp, expchannel_t channel) { (void)extp; (void)channel; btn_1_state=palReadPad(GPIOA, GPIOA_BTN1); if ( is_btn_1_pressed() ) kbg_setLCDBacklight(!kbg_getLCDBacklight() ); }
/** * @brief MMC_SPI card detection. */ bool mmc_lld_is_card_inserted(MMCDriver *mmcp) { static bool last_status = FALSE; (void)mmcp; if ((palReadLatch(GPIOD) & PAL_PORT_BIT(GPIOD_SPI3_CS)) == 0) return last_status; return last_status = (bool)palReadPad(GPIOD, GPIOD_SPI3_CS); }
/* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* * Initialize USB serial console */ usbcdc_init(commands); /* * Shell manager initialization. */ shellInit(); /* * Activates the serial driver 6 and SDC driver 1 using default * configuration. */ sdStart(&SD6, NULL); chThdSleep(MS2ST(100)); UPRINT("\x1b[1J\x1b[0;0HStarting ChibiOS\r\n"); UPRINT("Start blinker thread ..."); chThdCreateStatic(waThreadBlink, sizeof(waThreadBlink), NORMALPRIO, blinkerThread, NULL); UPRINT( " Done\r\n"); shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and check the button state, when the button is * pressed the test procedure is launched with output on the serial * driver 2. */ while (TRUE) { usbcdc_process(); if (palReadPad(GPIOA, GPIOA_BUTTON)) { palSetPad(GPIOD, GPIOD_LED5); /* Red On*/ usbcdc_print("Button pressed\r\n"); } /* Wait some time, to make the scheduler running tasks with lower prio */ chThdSleep(MS2ST(500)); } }
/* * Application entry point. */ int main(void) { /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); /* * Activates the serial driver 6 using the driver default configuration. */ sdStart(&SD6, NULL); palSetPadMode(GPIOC, 6, PAL_MODE_ALTERNATE(8)); palSetPadMode(GPIOC, 7, PAL_MODE_ALTERNATE(8)); /* * Set Pad Mode to PUSHPULL on D0 */ palSetPadMode(GPIOD, GPIOD_PIN0, PAL_MODE_OUTPUT_PUSHPULL); palClearPad(GPIOD, GPIOD_PIN0); /* * Creates the blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); /* * Creates the LWIP threads (it changes priority internally). */ chThdCreateStatic(wa_lwip_thread, LWIP_THREAD_STACK_SIZE, NORMALPRIO + 1, lwip_thread, NULL); /* * Creates the HTTP thread (it changes priority internally). */ chThdCreateStatic(wa_http_server, sizeof(wa_http_server), NORMALPRIO + 1, http_server, NULL); /* * Creates the MQTT Client thread (it changes priority internally). */ chThdCreateStatic(wa_mqtt_client, sizeof(wa_mqtt_client), NORMALPRIO + 1, mqtt_client, NULL); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and check the button state. */ while (TRUE) { if (palReadPad(GPIOA, GPIOA_BUTTON)) TestThread(&SD6); chThdSleepMilliseconds(500); } }
/* * @brief Checks if touchscreen is pressed or not. * * @return 1 if pressed, 0 otherwise * * @notapi */ uint8_t ts_lld_pressed(void) { palSetPadMode(ts->yd_port, ts->yd_pin, PAL_MODE_INPUT_PULLDOWN); palSetPadMode(ts->yu_port, ts->yu_pin, PAL_MODE_INPUT); palSetPadMode(ts->xl_port, ts->xl_pin, PAL_MODE_INPUT); palSetPadMode(ts->xr_port, ts->xr_pin, PAL_MODE_OUTPUT_PUSHPULL); palSetPad(ts->xr_port, ts->xr_pin); return palReadPad(ts->yd_port, ts->yd_pin); }
static msg_t Thread1(void *arg) { while (TRUE) { if (!palReadPad(IOPORT1, PORTA_BUTTON2)) palTogglePad(IOPORT1, PORTA_RELAY); chThdSleepMilliseconds(1000); } return 0; }