[LPC812] Add us_ticker interrupts, board pin names and tests

pull/3/head
Emilio Monti 2013-04-17 16:32:49 +01:00
parent 0037711cc5
commit a607392724
8 changed files with 141 additions and 11 deletions

View File

@ -47,6 +47,23 @@ typedef enum {
P0_16 = 16,
P0_17 = 17,
D0 = P0_0,
D1 = P0_4,
D2 = P0_6,
D3 = P0_8,
D4 = P0_9,
D7 = P0_7,
D8 = P0_17,
D9 = P0_16,
D10 = P0_13,
D11 = P0_14,
D12 = P0_15,
D13 = P0_12,
A4 = P0_10,
A5 = P0_11,
// LPC800-MAX board
LED_RED = P0_7,
LED_GREEN = P0_17,

View File

@ -41,17 +41,21 @@ void us_ticker_init(void) {
LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 8);
// Clear peripheral reset the SCT:
LPC_SYSCON->PRESETCTRL |= ( 1<< 8);
LPC_SYSCON->PRESETCTRL |= (1 << 8);
// Unified counter
LPC_SCT->CONFIG = 1;
// Unified counter (32 bits)
LPC_SCT->CONFIG |= 1;
// halt and clear the counter
LPC_SCT->CTRL_L |= (1 << 2) | (1 << 3);
// System Clock (12)MHz -> us_ticker (1)MHz
LPC_SCT->CTRL_L |= ((12) << 5);
LPC_SCT->CTRL_L |= ((SystemCoreClock/1000000 - 1) << 5);
// unhalt it: - clearing bit 2 of the CTRL register
// unhalt the counter:
// - clearing bit 2 of the CTRL register
LPC_SCT->CTRL_L &= ~(1 << 2);
#else
#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
LPC_SC->PCONP |= 1 << 23; // Clock TIMER_3
@ -69,11 +73,10 @@ void us_ticker_init(void) {
uint32_t prescale = PCLK / 1000000; // default to 1MHz (1 us ticks)
US_TICKER_TIMER->PR = prescale - 1;
US_TICKER_TIMER->TCR = 1; // enable = 1, reset = 0
#endif
NVIC_SetVector(US_TICKER_TIMER_IRQn, (uint32_t)us_ticker_irq_handler);
NVIC_EnableIRQ(US_TICKER_TIMER_IRQn);
#endif
}
uint32_t us_ticker_read() {
@ -89,11 +92,33 @@ uint32_t us_ticker_read() {
void us_ticker_set_interrupt(unsigned int timestamp) {
#ifdef TARGET_LPC812
// halt the counter:
// - setting bit 2 of the CTRL register
LPC_SCT->CTRL_L |= (1 << 2);
// set timestamp in compare register
LPC_SCT->MATCH[0].U = timestamp;
// [TODO] define the event: LPC_SCT->EVENT[0].CTRL
// unhalt the counter:
// - clearing bit 2 of the CTRL register
LPC_SCT->CTRL_L &= ~(1 << 2);
// if events are not enabled, enable them
if (!(LPC_SCT->EVEN & 0x01)) {
// comb mode = match only
LPC_SCT->EVENT[0].CTRL = (1 << 12);
// ref manual:
// In simple applications that do not
// use states, write 0x01 to this
// register to enable an event
LPC_SCT->EVENT[0].STATE |= 0x1;
// enable events
LPC_SCT->EVEN |= 0x1;
}
LPC_SCT->EVEN |= 1;
#else
// set match value
US_TICKER_TIMER->MR0 = timestamp;

View File

@ -3,6 +3,10 @@
#if defined(TARGET_KL25Z)
TMP102 temperature(PTC9, PTC8, 0x90);
#elif defined(TARGET_LPC812)
TMP102 temperature(D10, D11, 0x90);
#else
TMP102 temperature(p28, p27, 0x90);
#endif

View File

@ -13,6 +13,10 @@ void in_handler() {
#define PIN_OUT PTC7
#define PIN_IN PTA1
#elif defined(TARGET_LPC812)
#define PIN_OUT D10
#define PIN_IN D11
#else
#define PIN_IN (p5)
#define PIN_OUT (p25)

View File

@ -0,0 +1,62 @@
#include "test_env.h"
#include "ADXL345.h"
#if defined(TARGET_LPC812)
ADXL345 accelerometer(D10, D11, D12, D13);
#else
ADXL345 accelerometer(p5, p6, p7, p8);
#endif
// Assume test configuration on a plane (small x and y, z ~ g)
#define MAX_X_Y (50)
#define MIN_Z (200)
#define MAX_Z (300)
void check_X_Y(int v) {
int16_t a = (int16_t)v;
if (abs(a) > MAX_X_Y) {
printf("X/Y acceleration is too big: %d\n", a);
notify_completion(false);
}
}
int main() {
int readings[3] = {0, 0, 0};
printf("Starting ADXL345 test...\n");
printf("Device ID is: 0x%02x\n", accelerometer.getDevId());
//Go into standby mode to configure the device.
accelerometer.setPowerControl(0x00);
//Full resolution, +/-16g, 4mg/LSB.
accelerometer.setDataFormatControl(0x0B);
//3.2kHz data rate.
accelerometer.setDataRate(ADXL345_3200HZ);
//Measurement mode.
accelerometer.setPowerControl(0x08);
for (int i=0; i<3; i++) {
wait(0.1);
//13-bit, sign extended values.
accelerometer.getOutput(readings);
// X and Y
check_X_Y(readings[0]);
check_X_Y(readings[1]);
// Z
int16_t z = (int16_t)readings[2];
if ((z < MIN_Z) || (z > MAX_Z)) {
printf("Z acceleration not within expected range\n", z);
notify_completion(false);
}
}
notify_completion(true);
}

View File

@ -4,6 +4,10 @@ DigitalOut led(LED1);
#ifdef TARGET_KL25Z
DigitalOut out(PTA1);
#elif TARGET_LPC812
DigitalOut out(D10);
#else
DigitalOut out(p5);
#endif
@ -16,5 +20,8 @@ void togglePin (void) {
}
int main() {
tick.attach_us(togglePin, 10000);
tick.attach_us(togglePin, 100000);
while (true) {
wait(1);
}
}

View File

@ -2,6 +2,10 @@
#ifdef TARGET_KL25Z
DigitalOut out(PTD4);
#elif TARGET_LPC812
DigitalOut out(D10);
#else
DigitalOut out(p5);
#endif

View File

@ -301,6 +301,13 @@ TESTS = [
"source_dir": join(TEST_DIR, "mbed", "div"),
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB],
},
{
"id": "MBED_27", "description": "MBED: SPI ADXL345",
"source_dir": join(TEST_DIR, "mbed", "spi_ADXL345"),
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB, join(PERIPHERALS, 'ADXL345')],
"automated": True,
"peripherals": ["ADXL345"]
},
# CMSIS RTOS tests
{