aboutsummaryrefslogtreecommitdiffstats
path: root/src/wiring
diff options
context:
space:
mode:
authoriperry <iperry@749a229e-a60e-11de-b98f-4500b42dc123>2009-12-25 08:39:24 +0000
committeriperry <iperry@749a229e-a60e-11de-b98f-4500b42dc123>2009-12-25 08:39:24 +0000
commitb6674cd738cc22e61ea34cb659750ef45ce01df4 (patch)
treebfee2ae84883c32871ee13a6e0f346f144263cf6 /src/wiring
parent3bb04834ffd3f90dc9015997ea11a56d9d150099 (diff)
downloadlibrambutan-b6674cd738cc22e61ea34cb659750ef45ce01df4.tar.gz
librambutan-b6674cd738cc22e61ea34cb659750ef45ce01df4.zip
Fixed delayMicroseconds, changed serial interface, added an (untested) runtime check for pwm/serial collision, moved more headers around.
git-svn-id: https://leaflabs.googlecode.com/svn/trunk/library@79 749a229e-a60e-11de-b98f-4500b42dc123
Diffstat (limited to 'src/wiring')
-rw-r--r--src/wiring/comm/HardwareSerial.cpp3
-rw-r--r--src/wiring/time.c23
-rw-r--r--src/wiring/time.h14
-rw-r--r--src/wiring/wiring.c9
4 files changed, 26 insertions, 23 deletions
diff --git a/src/wiring/comm/HardwareSerial.cpp b/src/wiring/comm/HardwareSerial.cpp
index 84eb4c7..3d0a0ce 100644
--- a/src/wiring/comm/HardwareSerial.cpp
+++ b/src/wiring/comm/HardwareSerial.cpp
@@ -27,6 +27,7 @@
#include "HardwareSerial.h"
#include "usart.h"
#include "gpio.h"
+#include "timers.h"
#define USART1_TX_PORT GPIOA_BASE
#define USART1_TX_PIN 9
@@ -75,6 +76,8 @@ void HardwareSerial::begin(uint32_t baud) {
case 2:
gpio_set_mode(USART2_TX_PORT, USART2_TX_PIN, GPIO_MODE_AF_OUTPUT_PP);
gpio_set_mode(USART2_RX_PORT, USART2_RX_PIN, GPIO_MODE_INPUT_FLOATING);
+ /* Turn off any pwm */
+ timers_disable_channel(2, 3);
break;
case 3:
gpio_set_mode(USART3_TX_PORT, USART3_TX_PIN, GPIO_MODE_AF_OUTPUT_PP);
diff --git a/src/wiring/time.c b/src/wiring/time.c
index 1a91b5e..164d978 100644
--- a/src/wiring/time.c
+++ b/src/wiring/time.c
@@ -28,7 +28,7 @@
#include "time.h"
#define CYCLES_PER_MICROSECOND 72
-#define THE_SECRET_TO_LIFE_THE_UNIVERSE_AND_EVERYTHING 42
+#define FUDGE 42
extern volatile uint32_t systick_timer_millis;
@@ -47,26 +47,13 @@ void delay(unsigned long ms)
}
-#define MAGIC 4096
-/* HZ = 1000
- * n HZ*/
+
+#if 1
void delayMicroseconds(uint32_t us) {
uint32_t target;
uint32_t last, cur, count;
-
-#if 0
- asm volatile("mov r0, %[count] \n\t"
-"1: \n\t"
- "subs r0, r0, #1 \n\t"
- "bne 1b"
- :
- : [count] "r" (count)
- : "r0", "cc");
-#endif
-
-#if 1
/* fudge factor hacky hack hack for function overhead */
- target = us * CYCLES_PER_MICROSECOND - THE_SECRET_TO_LIFE_THE_UNIVERSE_AND_EVERYTHING;
+ target = us * CYCLES_PER_MICROSECOND - FUDGE;
/* Get current count */
last = systick_get_count();
@@ -81,5 +68,5 @@ void delayMicroseconds(uint32_t us) {
}
last = cur;
}
-#endif
}
+#endif
diff --git a/src/wiring/time.h b/src/wiring/time.h
index a97310a..68b3901 100644
--- a/src/wiring/time.h
+++ b/src/wiring/time.h
@@ -41,6 +41,20 @@ void delay(unsigned long ms);
/* Delay for us microseconds */
void delayMicroseconds(uint32_t us);
+#if 0
+static inline void delay_us(uint32 us) {
+ us *= 12;
+ asm volatile("mov r0, %[us] \n\t"
+ "subs r0, #2 \n\t"
+"1: \n\t"
+ "subs r0, r0, #1 \n\t"
+ "bne 1b"
+ :
+ : [us] "r" (us)
+ : "r0", "cc");
+
+}
+#endif
#ifdef __cplusplus
} // extern "C"
#endif
diff --git a/src/wiring/wiring.c b/src/wiring/wiring.c
index cecca20..04de78a 100644
--- a/src/wiring/wiring.c
+++ b/src/wiring/wiring.c
@@ -47,13 +47,12 @@ void init(void) {
gpio_init();
- /* off for debug */
-// adc_init();
+ adc_init();
timer_init(1, 1);
-// timer_init(2, 1);
-// timer_init(3, 1);
-// timer_init(4, 1);
+ timer_init(2, 1);
+ timer_init(3, 1);
+ timer_init(4, 1);
}
void NVIC_Configuration(void) {