From fe8d51b3c04c5a83e7cc45efabd0cf7c2cc1e72f Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Tue, 27 Sep 2016 23:44:01 +0200 Subject: [PATCH] Updated Comments Updated according to new header files Updated use of uprintf and UART* instead of snprintf + serial_write(0, ...) --- ultrasonic_sensor/main.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/ultrasonic_sensor/main.c b/ultrasonic_sensor/main.c index 3c71cb4..eadc885 100644 --- a/ultrasonic_sensor/main.c +++ b/ultrasonic_sensor/main.c @@ -1,5 +1,5 @@ /**************************************************************************** - * apps/ultrasonic_sensor/main.c + * apps/base/ultrasonic_sensor/main.c * * Ultrasonic range measurement example * @@ -25,12 +25,9 @@ * Refer to readme file for further information. */ -#include -#include "core/lpc_regs_12xx.h" -#include "core/lpc_core_cm0.h" -#include "core/pio.h" #include "core/system.h" #include "core/systick.h" +#include "core/pio.h" #include "lib/stdio.h" #include "drivers/serial.h" #include "drivers/gpio.h" @@ -67,10 +64,7 @@ void system_init() { /* Stop the watchdog */ startup_watchdog_disable(); /* Do it right now, before it gets a chance to break in */ - - /* Note: Brown-Out detection must be powered to operate the ADC. adc_on() will power - * it back on if called after system_init() */ - system_brown_out_detection_config(0); + system_brown_out_detection_config(0); /* No ADC used */ system_set_default_power_state(); clock_config(SELECTED_FREQ); set_pins(common_pins); @@ -89,10 +83,7 @@ void system_init() */ void fault_info(const char* name, uint32_t len) { - serial_write(0, name, len); - /* Wait for end of Tx */ - serial_flush(0); - /* FIXME : Perform soft reset of the micro-controller ! */ + uprintf(UART0, name); while (1); } @@ -122,18 +113,19 @@ void pulse_feedback(uint32_t gpio) { #define DELAY 50 /***************************************************************************** */ -int main(void) { +int main(void) +{ uint32_t next_time = 0; uint32_t delay = 0; system_init(); - uart_on(0, 115200, NULL); + uart_on(UART0, 115200, NULL); next_time = systick_get_tick_count(); /* Callback on pulse start and end */ set_gpio_callback(pulse_feedback, &sensor, EDGES_BOTH); - uprintf(0, "Ultrasonic distance sensor using GPIO %d.%d\n", sensor.port, sensor.pin); + uprintf(UART0, "Ultrasonic distance sensor using GPIO %d.%d\n", sensor.port, sensor.pin); while (1) { uint32_t distance = 0; @@ -156,7 +148,7 @@ int main(void) { distance = ((pulse_duration * 10) / (get_main_clock() / (1000*1000))); distance = distance / 29; /* Send value on serial */ - uprintf(0, "dist: %dmm\n", distance); + uprintf(UART0, "dist: %dmm\n", distance); /* And wait at least 50ms between loops */ delay = next_time - systick_get_tick_count(); -- 2.43.0