Squashed 'tmk_core/' changes from 7967731..b9e0ea0
b9e0ea0 Merge commit '7fa9d8bdea3773d1195b04d98fcf27cf48ddd81d' as 'tool/mbed/mbed-sdk' 7fa9d8b Squashed 'tool/mbed/mbed-sdk/' content from commit 7c21ce5 git-subtree-dir: tmk_core git-subtree-split: b9e0ea08cb940de20b3610ecdda18e9d8cd7c552
This commit is contained in:
parent
a20ef7052c
commit
1fe4406f37
4198 changed files with 2016457 additions and 0 deletions
48
tool/mbed/mbed-sdk/libraries/tests/KL25Z/lptmr/main.cpp
Normal file
48
tool/mbed/mbed-sdk/libraries/tests/KL25Z/lptmr/main.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include "mbed.h"
|
||||
|
||||
volatile unsigned int ticks = 0;
|
||||
|
||||
DigitalOut led(LED_BLUE);
|
||||
|
||||
extern "C" void lptmr_isr(void) {
|
||||
// write 1 to TCF to clear the LPT timer compare flag
|
||||
LPTMR0->CSR |= LPTMR_CSR_TCF_MASK;
|
||||
|
||||
ticks++;
|
||||
}
|
||||
|
||||
int main() {
|
||||
/* Clock the timer */
|
||||
SIM->SCGC5 |= SIM_SCGC5_LPTMR_MASK;
|
||||
|
||||
/* Reset */
|
||||
LPTMR0->CSR = 0;
|
||||
|
||||
/* Compare value */
|
||||
LPTMR0->CMR = 1000;
|
||||
|
||||
/* Enable interrupt */
|
||||
LPTMR0->CSR |= LPTMR_CSR_TIE_MASK;
|
||||
|
||||
/* Set interrupt handler */
|
||||
NVIC_SetVector(LPTimer_IRQn, (uint32_t)lptmr_isr);
|
||||
NVIC_EnableIRQ(LPTimer_IRQn);
|
||||
|
||||
/* select LPO for RTC and LPTMR */
|
||||
LPTMR0->PSR = LPTMR_PSR_PCS(3); // ERCLK32K -> 8MHz
|
||||
LPTMR0->PSR |= LPTMR_PSR_PRESCALE(2); // divide by 8
|
||||
|
||||
/* Start the timer */
|
||||
LPTMR0->CSR |= LPTMR_CSR_TEN_MASK;
|
||||
|
||||
led = 0;
|
||||
while (true) {
|
||||
wait(1);
|
||||
led = 1;
|
||||
printf("%d\n", ticks);
|
||||
|
||||
wait(1);
|
||||
led = 0;
|
||||
printf("%d\n", ticks);
|
||||
}
|
||||
}
|
48
tool/mbed/mbed-sdk/libraries/tests/KL25Z/pit/main.cpp
Normal file
48
tool/mbed/mbed-sdk/libraries/tests/KL25Z/pit/main.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include "mbed.h"
|
||||
|
||||
extern "C" {
|
||||
volatile uint32_t msTicks;
|
||||
|
||||
void SysTick_Handler(void) {
|
||||
msTicks++;
|
||||
}
|
||||
|
||||
void Delay(uint32_t dlyTicks) {
|
||||
uint32_t curTicks;
|
||||
|
||||
curTicks = msTicks;
|
||||
while ((msTicks - curTicks) < dlyTicks);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
SysTick_Config(SystemCoreClock / 1000);
|
||||
|
||||
SIM->SCGC6 |= SIM_SCGC6_PIT_MASK; // Clock PIT
|
||||
PIT->MCR = 0; // Enable PIT
|
||||
|
||||
// Timer 1
|
||||
PIT->CHANNEL[1].LDVAL = 0xFFFFFFFF;
|
||||
PIT->CHANNEL[1].TCTRL = 0x0; // Disable Interrupts
|
||||
PIT->CHANNEL[1].TCTRL |= PIT_TCTRL_CHN_MASK; // Chain to timer 0
|
||||
PIT->CHANNEL[1].TCTRL |= PIT_TCTRL_TEN_MASK; // Start timer 1
|
||||
|
||||
// Timer 2
|
||||
PIT->CHANNEL[0].LDVAL = 0xFFFFFFFF;
|
||||
PIT->CHANNEL[0].TCTRL = PIT_TCTRL_TEN_MASK; // Start timer 0, disable interrupts
|
||||
|
||||
DigitalOut led(LED_BLUE);
|
||||
while (true) {
|
||||
Delay(1000);
|
||||
led = !led;
|
||||
|
||||
uint64_t ticks = (uint64_t)PIT->LTMR64H << 32;
|
||||
ticks |= (uint64_t)PIT->LTMR64L;
|
||||
printf("ticks: 0x%x%x\n", (uint32_t)(ticks>>32), (uint32_t)(ticks & 0xFFFFFFFF));
|
||||
|
||||
ticks = (~ticks) / 24;
|
||||
uint32_t us = (uint32_t)(0xFFFFFFFF & ticks);
|
||||
|
||||
printf("us : 0x%x\n", us);
|
||||
}
|
||||
}
|
72
tool/mbed/mbed-sdk/libraries/tests/KL25Z/rtc/main.cpp
Normal file
72
tool/mbed/mbed-sdk/libraries/tests/KL25Z/rtc/main.cpp
Normal file
|
@ -0,0 +1,72 @@
|
|||
#include "mbed.h"
|
||||
|
||||
DigitalOut status_led(LED_BLUE);
|
||||
DigitalOut error_led(LED_RED);
|
||||
|
||||
extern "C" void RTC_IRQHandler(void) {
|
||||
error_led = 0;
|
||||
}
|
||||
|
||||
extern "C" void RTC_Seconds_IRQHandler(void) {
|
||||
error_led = 0;
|
||||
}
|
||||
|
||||
extern "C" void HardFault_Handler(void) {
|
||||
error_led = 0;
|
||||
}
|
||||
|
||||
extern "C" void NMI_Handler_Handler(void) {
|
||||
error_led = 0;
|
||||
}
|
||||
|
||||
void rtc_init(void) {
|
||||
// enable the clock to SRTC module register space
|
||||
SIM->SCGC6 |= SIM_SCGC6_RTC_MASK;
|
||||
SIM->SOPT1 = (SIM->SOPT1 & ~SIM_SOPT1_OSC32KSEL_MASK) | SIM_SOPT1_OSC32KSEL(0);
|
||||
|
||||
// disable interrupts
|
||||
NVIC_DisableIRQ(RTC_Seconds_IRQn);
|
||||
NVIC_DisableIRQ(RTC_IRQn);
|
||||
|
||||
// Reset
|
||||
RTC->CR = RTC_CR_SWR_MASK;
|
||||
RTC->CR &= ~RTC_CR_SWR_MASK;
|
||||
|
||||
// Allow write
|
||||
RTC->CR = RTC_CR_UM_MASK | RTC_CR_SUP_MASK;
|
||||
|
||||
NVIC_EnableIRQ(RTC_Seconds_IRQn);
|
||||
NVIC_EnableIRQ(RTC_Seconds_IRQn);
|
||||
|
||||
printf("LR: 0x%x\n", RTC->LR);
|
||||
printf("CR: 0x%x\n", RTC->CR);
|
||||
wait(1);
|
||||
if (RTC->SR & RTC_SR_TIF_MASK){
|
||||
RTC->TSR = 0;
|
||||
}
|
||||
RTC->TCR = 0;
|
||||
|
||||
// After setting this bit, wait the oscillator startup time before enabling
|
||||
// the time counter to allow the clock time to stabilize
|
||||
RTC->CR |= RTC_CR_OSCE_MASK;
|
||||
for (volatile int i=0; i<0x600000; i++);
|
||||
|
||||
//enable seconds interrupts
|
||||
RTC->IER |= RTC_IER_TSIE_MASK;
|
||||
|
||||
// enable time counter
|
||||
RTC->SR |= RTC_SR_TCE_MASK;
|
||||
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
error_led = 1;
|
||||
rtc_init();
|
||||
|
||||
while (true) {
|
||||
wait(1);
|
||||
status_led = !status_led;
|
||||
printf("%u\n", RTC->TSR);
|
||||
}
|
||||
}
|
19
tool/mbed/mbed-sdk/libraries/tests/benchmarks/all/main.cpp
Normal file
19
tool/mbed/mbed-sdk/libraries/tests/benchmarks/all/main.cpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include "mbed.h"
|
||||
|
||||
DigitalOut out(p5);
|
||||
#if defined(TARGET_LPC1114)
|
||||
AnalogIn in(p20);
|
||||
#else
|
||||
AnalogIn in(p19);
|
||||
#endif
|
||||
|
||||
volatile float w, x, y, z;
|
||||
int main() {
|
||||
while(1) {
|
||||
z = x * y / w;
|
||||
printf("Hello World %d %f\n", out.read(), z);
|
||||
if(in > 0.5) {
|
||||
out = !out;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
#include "mbed.h"
|
||||
|
||||
volatile int x, y, z;
|
||||
int main() {
|
||||
while(1) {
|
||||
z = x * y;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
#include "mbed.h"
|
||||
|
||||
volatile float w, x, y, z;
|
||||
int main() {
|
||||
while (1) {
|
||||
z = x * y / w;
|
||||
}
|
||||
}
|
16
tool/mbed/mbed-sdk/libraries/tests/benchmarks/mbed/main.cpp
Normal file
16
tool/mbed/mbed-sdk/libraries/tests/benchmarks/mbed/main.cpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include "mbed.h"
|
||||
|
||||
DigitalOut out(p5);
|
||||
#if defined(TARGET_LPC1114)
|
||||
AnalogIn in(p20);
|
||||
#else
|
||||
AnalogIn in(p19);
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
while(1) {
|
||||
if(in > 0.5) {
|
||||
out = !out;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
#include "mbed.h"
|
||||
|
||||
int main() {
|
||||
printf("Hello World!");
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
#include "arm_math.h"
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
** Test input signal contains 1000Hz + 15000 Hz
|
||||
** ------------------------------------------------------------------- */
|
||||
|
||||
float32_t testInput_f32_1kHz_15kHz[320] =
|
||||
{
|
||||
+0.0000000000f, +0.5924659585f, -0.0947343455f, +0.1913417162f, +1.0000000000f, +0.4174197128f, +0.3535533906f, +1.2552931065f,
|
||||
+0.8660254038f, +0.4619397663f, +1.3194792169f, +1.1827865776f, +0.5000000000f, +1.1827865776f, +1.3194792169f, +0.4619397663f,
|
||||
+0.8660254038f, +1.2552931065f, +0.3535533906f, +0.4174197128f, +1.0000000000f, +0.1913417162f, -0.0947343455f, +0.5924659585f,
|
||||
-0.0000000000f, -0.5924659585f, +0.0947343455f, -0.1913417162f, -1.0000000000f, -0.4174197128f, -0.3535533906f, -1.2552931065f,
|
||||
-0.8660254038f, -0.4619397663f, -1.3194792169f, -1.1827865776f, -0.5000000000f, -1.1827865776f, -1.3194792169f, -0.4619397663f,
|
||||
-0.8660254038f, -1.2552931065f, -0.3535533906f, -0.4174197128f, -1.0000000000f, -0.1913417162f, +0.0947343455f, -0.5924659585f,
|
||||
+0.0000000000f, +0.5924659585f, -0.0947343455f, +0.1913417162f, +1.0000000000f, +0.4174197128f, +0.3535533906f, +1.2552931065f,
|
||||
+0.8660254038f, +0.4619397663f, +1.3194792169f, +1.1827865776f, +0.5000000000f, +1.1827865776f, +1.3194792169f, +0.4619397663f,
|
||||
+0.8660254038f, +1.2552931065f, +0.3535533906f, +0.4174197128f, +1.0000000000f, +0.1913417162f, -0.0947343455f, +0.5924659585f,
|
||||
+0.0000000000f, -0.5924659585f, +0.0947343455f, -0.1913417162f, -1.0000000000f, -0.4174197128f, -0.3535533906f, -1.2552931065f,
|
||||
-0.8660254038f, -0.4619397663f, -1.3194792169f, -1.1827865776f, -0.5000000000f, -1.1827865776f, -1.3194792169f, -0.4619397663f,
|
||||
-0.8660254038f, -1.2552931065f, -0.3535533906f, -0.4174197128f, -1.0000000000f, -0.1913417162f, +0.0947343455f, -0.5924659585f,
|
||||
+0.0000000000f, +0.5924659585f, -0.0947343455f, +0.1913417162f, +1.0000000000f, +0.4174197128f, +0.3535533906f, +1.2552931065f,
|
||||
+0.8660254038f, +0.4619397663f, +1.3194792169f, +1.1827865776f, +0.5000000000f, +1.1827865776f, +1.3194792169f, +0.4619397663f,
|
||||
+0.8660254038f, +1.2552931065f, +0.3535533906f, +0.4174197128f, +1.0000000000f, +0.1913417162f, -0.0947343455f, +0.5924659585f,
|
||||
+0.0000000000f, -0.5924659585f, +0.0947343455f, -0.1913417162f, -1.0000000000f, -0.4174197128f, -0.3535533906f, -1.2552931065f,
|
||||
-0.8660254038f, -0.4619397663f, -1.3194792169f, -1.1827865776f, -0.5000000000f, -1.1827865776f, -1.3194792169f, -0.4619397663f,
|
||||
-0.8660254038f, -1.2552931065f, -0.3535533906f, -0.4174197128f, -1.0000000000f, -0.1913417162f, +0.0947343455f, -0.5924659585f,
|
||||
-0.0000000000f, +0.5924659585f, -0.0947343455f, +0.1913417162f, +1.0000000000f, +0.4174197128f, +0.3535533906f, +1.2552931065f,
|
||||
+0.8660254038f, +0.4619397663f, +1.3194792169f, +1.1827865776f, +0.5000000000f, +1.1827865776f, +1.3194792169f, +0.4619397663f,
|
||||
+0.8660254038f, +1.2552931065f, +0.3535533906f, +0.4174197128f, +1.0000000000f, +0.1913417162f, -0.0947343455f, +0.5924659585f,
|
||||
-0.0000000000f, -0.5924659585f, +0.0947343455f, -0.1913417162f, -1.0000000000f, -0.4174197128f, -0.3535533906f, -1.2552931065f,
|
||||
-0.8660254038f, -0.4619397663f, -1.3194792169f, -1.1827865776f, -0.5000000000f, -1.1827865776f, -1.3194792169f, -0.4619397663f,
|
||||
-0.8660254038f, -1.2552931065f, -0.3535533906f, -0.4174197128f, -1.0000000000f, -0.1913417162f, +0.0947343455f, -0.5924659585f,
|
||||
+0.0000000000f, +0.5924659585f, -0.0947343455f, +0.1913417162f, +1.0000000000f, +0.4174197128f, +0.3535533906f, +1.2552931065f,
|
||||
+0.8660254038f, +0.4619397663f, +1.3194792169f, +1.1827865776f, +0.5000000000f, +1.1827865776f, +1.3194792169f, +0.4619397663f,
|
||||
+0.8660254038f, +1.2552931065f, +0.3535533906f, +0.4174197128f, +1.0000000000f, +0.1913417162f, -0.0947343455f, +0.5924659585f,
|
||||
+0.0000000000f, -0.5924659585f, +0.0947343455f, -0.1913417162f, -1.0000000000f, -0.4174197128f, -0.3535533906f, -1.2552931065f,
|
||||
-0.8660254038f, -0.4619397663f, -1.3194792169f, -1.1827865776f, -0.5000000000f, -1.1827865776f, -1.3194792169f, -0.4619397663f,
|
||||
-0.8660254038f, -1.2552931065f, -0.3535533906f, -0.4174197128f, -1.0000000000f, -0.1913417162f, +0.0947343455f, -0.5924659585f,
|
||||
-0.0000000000f, +0.5924659585f, -0.0947343455f, +0.1913417162f, +1.0000000000f, +0.4174197128f, +0.3535533906f, +1.2552931065f,
|
||||
+0.8660254038f, +0.4619397663f, +1.3194792169f, +1.1827865776f, +0.5000000000f, +1.1827865776f, +1.3194792169f, +0.4619397663f,
|
||||
+0.8660254038f, +1.2552931065f, +0.3535533906f, +0.4174197128f, +1.0000000000f, +0.1913417162f, -0.0947343455f, +0.5924659585f,
|
||||
+0.0000000000f, -0.5924659585f, +0.0947343455f, -0.1913417162f, -1.0000000000f, -0.4174197128f, -0.3535533906f, -1.2552931065f,
|
||||
-0.8660254038f, -0.4619397663f, -1.3194792169f, -1.1827865776f, -0.5000000000f, -1.1827865776f, -1.3194792169f, -0.4619397663f,
|
||||
-0.8660254038f, -1.2552931065f, -0.3535533906f, -0.4174197128f, -1.0000000000f, -0.1913417162f, +0.0947343455f, -0.5924659585f,
|
||||
-0.0000000000f, +0.5924659585f, -0.0947343455f, +0.1913417162f, +1.0000000000f, +0.4174197128f, +0.3535533906f, +1.2552931065f,
|
||||
+0.8660254038f, +0.4619397663f, +1.3194792169f, +1.1827865776f, +0.5000000000f, +1.1827865776f, +1.3194792169f, +0.4619397663f,
|
||||
+0.8660254038f, +1.2552931065f, +0.3535533906f, +0.4174197128f, +1.0000000000f, +0.1913417162f, -0.0947343455f, +0.5924659585f,
|
||||
+0.0000000000f, -0.5924659585f, +0.0947343455f, -0.1913417162f, -1.0000000000f, -0.4174197128f, -0.3535533906f, -1.2552931065f,
|
||||
};
|
||||
|
||||
float32_t refOutput[320] =
|
||||
{
|
||||
+0.0000000000f, -0.0010797829f, -0.0007681386f, -0.0001982932f, +0.0000644313f, +0.0020854271f, +0.0036891871f, +0.0015855941f,
|
||||
-0.0026280805f, -0.0075907658f, -0.0119390538f, -0.0086665968f, +0.0088981202f, +0.0430539279f, +0.0974468742f, +0.1740405600f,
|
||||
+0.2681416601f, +0.3747720089f, +0.4893362230f, +0.6024154672f, +0.7058740791f, +0.7968348987f, +0.8715901940f, +0.9277881093f,
|
||||
+0.9682182661f, +0.9934674267f, +1.0012052245f, +0.9925859371f, +0.9681538347f, +0.9257026822f, +0.8679010068f, +0.7952493046f,
|
||||
+0.7085021596f, +0.6100062330f, +0.5012752767f, +0.3834386057f, +0.2592435399f, +0.1309866321f, -0.0000000000f, -0.1309866321f,
|
||||
-0.2592435399f, -0.3834386057f, -0.5012752767f, -0.6100062330f, -0.7085021596f, -0.7952493046f, -0.8679010068f, -0.9257026822f,
|
||||
-0.9681538347f, -0.9936657199f, -1.0019733630f, -0.9936657199f, -0.9681538347f, -0.9257026822f, -0.8679010068f, -0.7952493046f,
|
||||
-0.7085021596f, -0.6100062330f, -0.5012752767f, -0.3834386057f, -0.2592435399f, -0.1309866321f, +0.0000000000f, +0.1309866321f,
|
||||
+0.2592435399f, +0.3834386057f, +0.5012752767f, +0.6100062330f, +0.7085021596f, +0.7952493046f, +0.8679010068f, +0.9257026822f,
|
||||
+0.9681538347f, +0.9936657199f, +1.0019733630f, +0.9936657199f, +0.9681538347f, +0.9257026822f, +0.8679010068f, +0.7952493046f,
|
||||
+0.7085021596f, +0.6100062330f, +0.5012752767f, +0.3834386057f, +0.2592435399f, +0.1309866321f, -0.0000000000f, -0.1309866321f,
|
||||
-0.2592435399f, -0.3834386057f, -0.5012752767f, -0.6100062330f, -0.7085021596f, -0.7952493046f, -0.8679010068f, -0.9257026822f,
|
||||
-0.9681538347f, -0.9936657199f, -1.0019733630f, -0.9936657199f, -0.9681538347f, -0.9257026822f, -0.8679010068f, -0.7952493046f,
|
||||
-0.7085021596f, -0.6100062330f, -0.5012752767f, -0.3834386057f, -0.2592435399f, -0.1309866321f, +0.0000000000f, +0.1309866321f,
|
||||
+0.2592435399f, +0.3834386057f, +0.5012752767f, +0.6100062330f, +0.7085021596f, +0.7952493046f, +0.8679010068f, +0.9257026822f,
|
||||
+0.9681538347f, +0.9936657199f, +1.0019733630f, +0.9936657199f, +0.9681538347f, +0.9257026822f, +0.8679010068f, +0.7952493046f,
|
||||
+0.7085021596f, +0.6100062330f, +0.5012752767f, +0.3834386057f, +0.2592435399f, +0.1309866321f, -0.0000000000f, -0.1309866321f,
|
||||
-0.2592435399f, -0.3834386057f, -0.5012752767f, -0.6100062330f, -0.7085021596f, -0.7952493046f, -0.8679010068f, -0.9257026822f,
|
||||
-0.9681538347f, -0.9936657199f, -1.0019733630f, -0.9936657199f, -0.9681538347f, -0.9257026822f, -0.8679010068f, -0.7952493046f,
|
||||
-0.7085021596f, -0.6100062330f, -0.5012752767f, -0.3834386057f, -0.2592435399f, -0.1309866321f, +0.0000000000f, +0.1309866321f,
|
||||
+0.2592435399f, +0.3834386057f, +0.5012752767f, +0.6100062330f, +0.7085021596f, +0.7952493046f, +0.8679010068f, +0.9257026822f,
|
||||
+0.9681538347f, +0.9936657199f, +1.0019733630f, +0.9936657199f, +0.9681538347f, +0.9257026822f, +0.8679010068f, +0.7952493046f,
|
||||
+0.7085021596f, +0.6100062330f, +0.5012752767f, +0.3834386057f, +0.2592435399f, +0.1309866321f, +0.0000000000f, -0.1309866321f,
|
||||
-0.2592435399f, -0.3834386057f, -0.5012752767f, -0.6100062330f, -0.7085021596f, -0.7952493046f, -0.8679010068f, -0.9257026822f,
|
||||
-0.9681538347f, -0.9936657199f, -1.0019733630f, -0.9936657199f, -0.9681538347f, -0.9257026822f, -0.8679010068f, -0.7952493046f,
|
||||
-0.7085021596f, -0.6100062330f, -0.5012752767f, -0.3834386057f, -0.2592435399f, -0.1309866321f, +0.0000000000f, +0.1309866321f,
|
||||
+0.2592435399f, +0.3834386057f, +0.5012752767f, +0.6100062330f, +0.7085021596f, +0.7952493046f, +0.8679010068f, +0.9257026822f,
|
||||
+0.9681538347f, +0.9936657199f, +1.0019733630f, +0.9936657199f, +0.9681538347f, +0.9257026822f, +0.8679010068f, +0.7952493046f,
|
||||
+0.7085021596f, +0.6100062330f, +0.5012752767f, +0.3834386057f, +0.2592435399f, +0.1309866321f, +0.0000000000f, -0.1309866321f,
|
||||
-0.2592435399f, -0.3834386057f, -0.5012752767f, -0.6100062330f, -0.7085021596f, -0.7952493046f, -0.8679010068f, -0.9257026822f,
|
||||
-0.9681538347f, -0.9936657199f, -1.0019733630f, -0.9936657199f, -0.9681538347f, -0.9257026822f, -0.8679010068f, -0.7952493046f,
|
||||
-0.7085021596f, -0.6100062330f, -0.5012752767f, -0.3834386057f, -0.2592435399f, -0.1309866321f, -0.0000000000f, +0.1309866321f,
|
||||
+0.2592435399f, +0.3834386057f, +0.5012752767f, +0.6100062330f, +0.7085021596f, +0.7952493046f, +0.8679010068f, +0.9257026822f,
|
||||
+0.9681538347f, +0.9936657199f, +1.0019733630f, +0.9936657199f, +0.9681538347f, +0.9257026822f, +0.8679010068f, +0.7952493046f,
|
||||
+0.7085021596f, +0.6100062330f, +0.5012752767f, +0.3834386057f, +0.2592435399f, +0.1309866321f, +0.0000000000f, -0.1309866321f,
|
||||
-0.2592435399f, -0.3834386057f, -0.5012752767f, -0.6100062330f, -0.7085021596f, -0.7952493046f, -0.8679010068f, -0.9257026822f,
|
||||
-0.9681538347f, -0.9936657199f, -1.0019733630f, -0.9936657199f, -0.9681538347f, -0.9257026822f, -0.8679010068f, -0.7952493046f,
|
||||
-0.7085021596f, -0.6100062330f, -0.5012752767f, -0.3834386057f, -0.2592435399f, -0.1309866321f, +0.0000000000f, +0.1309866321f,
|
||||
+0.2592435399f, +0.3834386057f, +0.5012752767f, +0.6100062330f, +0.7085021596f, +0.7952493046f, +0.8679010068f, +0.9257026822f,
|
||||
+0.9681538347f, +0.9936657199f, +1.0019733630f, +0.9936657199f, +0.9681538347f, +0.9257026822f, +0.8679010068f, +0.7952493046f
|
||||
};
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
#include "arm_math.h"
|
||||
#include "math_helper.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define BLOCK_SIZE 32
|
||||
#define NUM_BLOCKS 10
|
||||
|
||||
#define TEST_LENGTH_SAMPLES (BLOCK_SIZE * NUM_BLOCKS)
|
||||
|
||||
#define SNR_THRESHOLD_F32 140.0f
|
||||
#define NUM_TAPS 29
|
||||
|
||||
/* -------------------------------------------------------------------
|
||||
* The input signal and reference output (computed with MATLAB)
|
||||
* are defined externally in arm_fir_lpf_data.c.
|
||||
* ------------------------------------------------------------------- */
|
||||
extern float32_t testInput_f32_1kHz_15kHz[TEST_LENGTH_SAMPLES];
|
||||
extern float32_t refOutput[TEST_LENGTH_SAMPLES];
|
||||
|
||||
/* -------------------------------------------------------------------
|
||||
* Declare State buffer of size (numTaps + blockSize - 1)
|
||||
* ------------------------------------------------------------------- */
|
||||
static float32_t firStateF32[BLOCK_SIZE + NUM_TAPS - 1];
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* FIR Coefficients buffer generated using fir1() MATLAB function.
|
||||
* fir1(28, 6/24)
|
||||
* ------------------------------------------------------------------- */
|
||||
const float32_t firCoeffs32[NUM_TAPS] = {
|
||||
-0.0018225230f, -0.0015879294f, +0.0000000000f, +0.0036977508f, +0.0080754303f,
|
||||
+0.0085302217f, -0.0000000000f, -0.0173976984f, -0.0341458607f, -0.0333591565f,
|
||||
+0.0000000000f, +0.0676308395f, +0.1522061835f, +0.2229246956f, +0.2504960933f,
|
||||
+0.2229246956f, +0.1522061835f, +0.0676308395f, +0.0000000000f, -0.0333591565f,
|
||||
-0.0341458607f, -0.0173976984f, -0.0000000000f, +0.0085302217f, +0.0080754303f,
|
||||
+0.0036977508f, +0.0000000000f, -0.0015879294f, -0.0018225230f
|
||||
};
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* FIR LPF Example
|
||||
* ------------------------------------------------------------------- */
|
||||
int main(void) {
|
||||
/* Call FIR init function to initialize the instance structure. */
|
||||
arm_fir_instance_f32 S;
|
||||
arm_fir_init_f32(&S, NUM_TAPS, (float32_t *)&firCoeffs32[0], &firStateF32[0], BLOCK_SIZE);
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Call the FIR process function for every blockSize samples
|
||||
* ------------------------------------------------------------------- */
|
||||
for (uint32_t i=0; i < NUM_BLOCKS; i++) {
|
||||
float32_t* signal = testInput_f32_1kHz_15kHz + (i * BLOCK_SIZE);
|
||||
arm_fir_f32(&S, signal, signal, BLOCK_SIZE);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Compare the generated output against the reference output computed
|
||||
* in MATLAB.
|
||||
* ------------------------------------------------------------------- */
|
||||
float32_t snr = arm_snr_f32(refOutput, testInput_f32_1kHz_15kHz, TEST_LENGTH_SAMPLES);
|
||||
printf("snr: %f\n\r", snr);
|
||||
if (snr < SNR_THRESHOLD_F32) {
|
||||
printf("Failed\n\r");
|
||||
} else {
|
||||
printf("Success\n\r");
|
||||
}
|
||||
}
|
53
tool/mbed/mbed-sdk/libraries/tests/dsp/mbed/fir_f32/main.cpp
Normal file
53
tool/mbed/mbed-sdk/libraries/tests/dsp/mbed/fir_f32/main.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
#include "mbed.h"
|
||||
#include "dsp.h"
|
||||
|
||||
#define BLOCK_SIZE (32)
|
||||
#define NUM_BLOCKS (10)
|
||||
#define TEST_LENGTH_SAMPLES (BLOCK_SIZE * NUM_BLOCKS)
|
||||
|
||||
#define SAMPLE_RATE (48000)
|
||||
|
||||
#define SNR_THRESHOLD_F32 (50.0f)
|
||||
|
||||
float32_t expected_output[TEST_LENGTH_SAMPLES];
|
||||
float32_t output[TEST_LENGTH_SAMPLES];
|
||||
|
||||
/* FIR Coefficients buffer generated using fir1() MATLAB function: fir1(28, 6/24) */
|
||||
#define NUM_TAPS 29
|
||||
const float32_t firCoeffs32[NUM_TAPS] = {
|
||||
-0.0018225230f, -0.0015879294f, +0.0000000000f, +0.0036977508f, +0.0080754303f,
|
||||
+0.0085302217f, -0.0000000000f, -0.0173976984f, -0.0341458607f, -0.0333591565f,
|
||||
+0.0000000000f, +0.0676308395f, +0.1522061835f, +0.2229246956f, +0.2504960933f,
|
||||
+0.2229246956f, +0.1522061835f, +0.0676308395f, +0.0000000000f, -0.0333591565f,
|
||||
-0.0341458607f, -0.0173976984f, -0.0000000000f, +0.0085302217f, +0.0080754303f,
|
||||
+0.0036977508f, +0.0000000000f, -0.0015879294f, -0.0018225230f
|
||||
};
|
||||
#define WARMUP (NUM_TAPS-1)
|
||||
#define DELAY (WARMUP/2)
|
||||
|
||||
int main() {
|
||||
Sine_f32 sine_1KHz( 1000, SAMPLE_RATE, 1.0);
|
||||
Sine_f32 sine_15KHz(15000, SAMPLE_RATE, 0.5);
|
||||
FIR_f32<NUM_TAPS> fir(firCoeffs32);
|
||||
|
||||
float32_t buffer_a[BLOCK_SIZE];
|
||||
float32_t buffer_b[BLOCK_SIZE];
|
||||
for (float32_t *sgn=output; sgn<(output+TEST_LENGTH_SAMPLES); sgn += BLOCK_SIZE) {
|
||||
sine_1KHz.generate(buffer_a); // Generate a 1KHz sine wave
|
||||
sine_15KHz.process(buffer_a, buffer_b); // Add a 15KHz sine wave
|
||||
fir.process(buffer_b, sgn); // FIR low pass filter: 6KHz cutoff
|
||||
}
|
||||
|
||||
sine_1KHz.reset();
|
||||
for (float32_t *sgn=expected_output; sgn<(expected_output+TEST_LENGTH_SAMPLES); sgn += BLOCK_SIZE) {
|
||||
sine_1KHz.generate(sgn); // Generate a 1KHz sine wave
|
||||
}
|
||||
|
||||
float snr = arm_snr_f32(&expected_output[DELAY-1], &output[WARMUP-1], TEST_LENGTH_SAMPLES-WARMUP);
|
||||
printf("snr: %f\n\r", snr);
|
||||
if (snr < SNR_THRESHOLD_F32) {
|
||||
printf("Failed\n\r");
|
||||
} else {
|
||||
printf("Success\n\r");
|
||||
}
|
||||
}
|
24
tool/mbed/mbed-sdk/libraries/tests/export/mcb1700/main.cpp
Normal file
24
tool/mbed/mbed-sdk/libraries/tests/export/mcb1700/main.cpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
#include "mbed.h"
|
||||
|
||||
BusOut leds(P1_28, P1_29, P1_31, P2_2, P2_3, P2_4, P2_5, P2_6);
|
||||
AnalogIn in(P0_25);
|
||||
|
||||
int main() {
|
||||
while (true) {
|
||||
float value = 8.0 * in.read();
|
||||
printf("analog in: %f\n\r", value);
|
||||
|
||||
int led_mask = 0;
|
||||
if (value > 0.5) led_mask |= 1 << 0;
|
||||
if (value > 1.5) led_mask |= 1 << 1;
|
||||
if (value > 2.5) led_mask |= 1 << 2;
|
||||
if (value > 3.5) led_mask |= 1 << 3;
|
||||
if (value > 4.5) led_mask |= 1 << 4;
|
||||
if (value > 5.5) led_mask |= 1 << 5;
|
||||
if (value > 6.5) led_mask |= 1 << 6;
|
||||
if (value > 7.5) led_mask |= 1 << 7;
|
||||
leds = led_mask;
|
||||
|
||||
wait(1);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/* mbed Microcontroller Library - SPIHalfDuplex
|
||||
* Copyright (c) 2010-2011 ARM Limited. All rights reserved.
|
||||
*/
|
||||
#include "SPIHalfDuplex.h"
|
||||
|
||||
#if DEVICE_SPI
|
||||
|
||||
#include "spi_api.h"
|
||||
#include "pinmap.h"
|
||||
|
||||
#define GPIO_MODE 0
|
||||
#define SPI_MODE 2
|
||||
|
||||
namespace mbed {
|
||||
|
||||
SPIHalfDuplex::SPIHalfDuplex(PinName mosi, PinName miso, PinName sclk) : SPI(mosi, miso, sclk) {
|
||||
_mosi = mosi;
|
||||
_miso = miso;
|
||||
_sbits = _bits;
|
||||
}
|
||||
|
||||
void SPIHalfDuplex::slave_format(int sbits) {
|
||||
_sbits = sbits;
|
||||
}
|
||||
|
||||
int SPIHalfDuplex::write(int value) {
|
||||
int t_bits = _bits;
|
||||
pin_function(_mosi, SPI_MODE);
|
||||
int ret_val = SPI::write(value);
|
||||
if (ret_val != value) {
|
||||
return -1;
|
||||
}
|
||||
format(_sbits, _mode);
|
||||
pin_function(_mosi, GPIO_MODE);
|
||||
ret_val = SPI::write(0x55);
|
||||
format(t_bits, _mode);
|
||||
pin_function(_mosi, SPI_MODE);
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
} // end namespace mbed
|
||||
|
||||
#endif
|
|
@ -0,0 +1,85 @@
|
|||
/* mbed Microcontroller Library - SPIHalfDuplex
|
||||
* Copyright (c) 2010-2011 ARM Limited. All rights reserved.
|
||||
*/
|
||||
#ifndef MBED_SPIHALFDUPLEX_H
|
||||
#define MBED_SPIHALFDUPLEX_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if DEVICE_SPI
|
||||
|
||||
#include "SPI.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A SPI half-duplex master, used for communicating with SPI slave devices
|
||||
* over a shared data line.
|
||||
*
|
||||
* The default format is set to 8-bits for both master and slave, and a
|
||||
* clock frequency of 1MHz
|
||||
*
|
||||
* Most SPI devies will also require Chip Select and Reset signals. These
|
||||
* can be controlled using <DigitalOut> pins.
|
||||
*
|
||||
* Although this is for a shared data line, both MISO and MOSI are defined,
|
||||
* and should be tied together externally to the mbed. This class handles
|
||||
* the tri-stating of the MOSI pin.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* // Send a byte to a SPI half-duplex slave, and record the response
|
||||
*
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* SPIHalfDuplex device(p5, p6, p7) // mosi, miso, sclk
|
||||
*
|
||||
* int main() {
|
||||
* int respone = device.write(0xAA);
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
|
||||
class SPIHalfDuplex : public SPI {
|
||||
|
||||
public:
|
||||
|
||||
/** Create a SPI half-duplex master connected to the specified pins
|
||||
*
|
||||
* Pin Options:
|
||||
* (5, 6, 7) or (11, 12, 13)
|
||||
*
|
||||
* mosi or miso can be specfied as NC if not used
|
||||
*
|
||||
* @param mosi SPI Master Out, Slave In pin
|
||||
* @param miso SPI Master In, Slave Out pin
|
||||
* @param sclk SPI Clock pin
|
||||
* @param name (optional) A string to identify the object
|
||||
*/
|
||||
SPIHalfDuplex(PinName mosi, PinName miso, PinName sclk);
|
||||
|
||||
/** Write to the SPI Slave and return the response
|
||||
*
|
||||
* @param value Data to be sent to the SPI slave
|
||||
*
|
||||
* @returns
|
||||
* Response from the SPI slave
|
||||
*/
|
||||
virtual int write(int value);
|
||||
|
||||
/** Set the number of databits expected from the slave, from 4-16
|
||||
*
|
||||
* @param sbits Number of expected bits in the slave response
|
||||
*/
|
||||
void slave_format(int sbits);
|
||||
|
||||
protected:
|
||||
PinName _mosi;
|
||||
PinName _miso;
|
||||
int _sbits;
|
||||
}; // End of class
|
||||
|
||||
} // End of namespace mbed
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,52 @@
|
|||
/* mbed Microcontroller Library - SerialHalfDuplex
|
||||
* Copyright (c) 2010-2011 ARM Limited. All rights reserved.
|
||||
*/
|
||||
#include "SerialHalfDuplex.h"
|
||||
|
||||
#if DEVICE_SERIAL
|
||||
|
||||
#include "pinmap.h"
|
||||
#include "serial_api.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
SerialHalfDuplex::SerialHalfDuplex(PinName tx, PinName rx)
|
||||
: Serial(tx, rx) {
|
||||
|
||||
gpio_init(&gpio, tx, PIN_INPUT);
|
||||
gpio_mode(&gpio, PullNone); // no pull
|
||||
}
|
||||
|
||||
// To transmit a byte in half duplex mode:
|
||||
// 1. Disable interrupts, so we don't trigger on loopback byte
|
||||
// 2. Set tx pin to UART out
|
||||
// 3. Transmit byte as normal
|
||||
// 4. Read back byte from looped back tx pin - this both confirms that the
|
||||
// transmit has occurred, and also clears the byte from the buffer.
|
||||
// 5. Return pin to input mode
|
||||
// 6. Re-enable interrupts
|
||||
int SerialHalfDuplex::_putc(int c) {
|
||||
int retc;
|
||||
|
||||
// TODO: We should not disable all interrupts
|
||||
__disable_irq();
|
||||
|
||||
serial_pinout_tx(gpio.pin);
|
||||
|
||||
Serial::_putc(c);
|
||||
retc = Serial::getc(); // reading also clears any interrupt
|
||||
|
||||
pin_function(gpio.pin, 0);
|
||||
|
||||
__enable_irq();
|
||||
|
||||
return retc;
|
||||
}
|
||||
|
||||
int SerialHalfDuplex::_getc(void) {
|
||||
return Serial::_getc();
|
||||
}
|
||||
|
||||
} // End namespace
|
||||
|
||||
#endif
|
|
@ -0,0 +1,82 @@
|
|||
/* mbed Microcontroller Library - SerialHalfDuplex
|
||||
* Copyright (c) 2010-2011 ARM Limited. All rights reserved.
|
||||
*/
|
||||
#ifndef MBED_SERIALHALFDUPLEX_H
|
||||
#define MBED_SERIALHALFDUPLEX_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if DEVICE_SERIAL
|
||||
|
||||
#include "Serial.h"
|
||||
#include "gpio_api.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A serial port (UART) for communication with other devices using
|
||||
* Half-Duplex, allowing transmit and receive on a single
|
||||
* shared transmit and receive line. Only one end should be transmitting
|
||||
* at a time.
|
||||
*
|
||||
* Both the tx and rx pin should be defined, and wired together.
|
||||
* This is in addition to them being wired to the other serial
|
||||
* device to allow both read and write functions to operate.
|
||||
*
|
||||
* For Simplex and Full-Duplex Serial communication, see Serial()
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* // Send a byte to a second HalfDuplex device, and read the response
|
||||
*
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* // p9 and p10 should be wired together to form "a"
|
||||
* // p28 and p27 should be wired together to form "b"
|
||||
* // p9/p10 should be wired to p28/p27 as the Half Duplex connection
|
||||
*
|
||||
* SerialHalfDuplex a(p9, p10);
|
||||
* SerialHalfDuplex b(p28, p27);
|
||||
*
|
||||
* void b_rx() { // second device response
|
||||
* b.putc(b.getc() + 4);
|
||||
* }
|
||||
*
|
||||
* int main() {
|
||||
* b.attach(&b_rx);
|
||||
* for (int c = 'A'; c < 'Z'; c++) {
|
||||
* a.putc(c);
|
||||
* printf("sent [%c]\n", c);
|
||||
* wait(0.5); // b should respond
|
||||
* if (a.readable()) {
|
||||
* printf("received [%c]\n", a.getc());
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class SerialHalfDuplex : public Serial {
|
||||
|
||||
public:
|
||||
/** Create a half-duplex serial port, connected to the specified transmit
|
||||
* and receive pins.
|
||||
*
|
||||
* These pins should be wired together, as well as to the target device
|
||||
*
|
||||
* @param tx Transmit pin
|
||||
* @param rx Receive pin
|
||||
*/
|
||||
SerialHalfDuplex(PinName tx, PinName rx);
|
||||
|
||||
protected:
|
||||
gpio_object gpio;
|
||||
|
||||
virtual int _putc(int c);
|
||||
virtual int _getc(void);
|
||||
|
||||
}; // End class SerialHalfDuplex
|
||||
|
||||
} // End namespace
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
82
tool/mbed/mbed-sdk/libraries/tests/mbed/analog/main.cpp
Normal file
82
tool/mbed/mbed-sdk/libraries/tests/mbed/analog/main.cpp
Normal file
|
@ -0,0 +1,82 @@
|
|||
#include "test_env.h"
|
||||
|
||||
#if defined(TARGET_K64F) | defined (TARGET_K22F)
|
||||
AnalogIn in(A0);
|
||||
AnalogOut out(DAC0_OUT);
|
||||
|
||||
#elif defined(TARGET_KL25Z)
|
||||
AnalogIn in(PTC2);
|
||||
AnalogOut out(PTE30);
|
||||
|
||||
#elif defined(TARGET_KL05Z)
|
||||
AnalogIn in(PTB11); // D9
|
||||
AnalogOut out(PTB1); // D1
|
||||
|
||||
#elif defined(TARGET_KL46Z)
|
||||
AnalogIn in(PTB0);
|
||||
AnalogOut out(PTE30);
|
||||
|
||||
#elif defined(TARGET_LPC1549)
|
||||
AnalogIn in(A0);
|
||||
AnalogOut out(D12); //D12 is P0_12, the DAC output pin
|
||||
|
||||
// No DAC on these targets:
|
||||
//TARGET_NUCLEO_F030R8
|
||||
//TARGET_NUCLEO_F070RB
|
||||
//TARGET_NUCLEO_F103RB
|
||||
//TARGET_NUCLEO_F401RE
|
||||
//TARGET_NUCLEO_F411RE
|
||||
#elif defined(TARGET_NUCLEO_F072RB) || \
|
||||
defined(TARGET_NUCLEO_F091RC) || \
|
||||
defined(TARGET_NUCLEO_F302R8) || \
|
||||
defined(TARGET_NUCLEO_F303RE) || \
|
||||
defined(TARGET_NUCLEO_F334R8) || \
|
||||
defined(TARGET_NUCLEO_L053R8) || \
|
||||
defined(TARGET_NUCLEO_L073RZ) || \
|
||||
defined(TARGET_NUCLEO_L152RE)
|
||||
AnalogIn in(A0);
|
||||
AnalogOut out(A2); // DAC output
|
||||
|
||||
#elif defined(TARGET_ARCH_MAX)
|
||||
AnalogIn in(PA_0);
|
||||
AnalogOut out(PA_4);
|
||||
|
||||
#elif defined(TARGET_DISCO_F407VG)
|
||||
AnalogIn in(PC_5);
|
||||
AnalogOut out(PA_4);
|
||||
|
||||
#elif defined(TARGET_DISCO_F429ZI)
|
||||
AnalogIn in(PC_3);
|
||||
AnalogOut out(PA_5);
|
||||
|
||||
#elif defined(TARGET_MAX32600MBED)
|
||||
AnalogIn in(AIN_7P);
|
||||
AnalogOut out(AOUT_DO);
|
||||
|
||||
#else
|
||||
AnalogIn in(p17);
|
||||
AnalogOut out(p18);
|
||||
|
||||
#endif
|
||||
|
||||
#define ERROR_TOLLERANCE 0.05
|
||||
|
||||
int main() {
|
||||
bool check = true;
|
||||
|
||||
for (float out_value=0.0; out_value<1.1; out_value+=0.1) {
|
||||
out.write(out_value);
|
||||
wait(0.1);
|
||||
|
||||
float in_value = in.read();
|
||||
float diff = fabs(out_value - in_value);
|
||||
if (diff > ERROR_TOLLERANCE) {
|
||||
check = false;
|
||||
printf("ERROR (out:%.4f) - (in:%.4f) = (%.4f)"NL, out_value, in_value, diff);
|
||||
} else {
|
||||
printf("OK (out:%.4f) - (in:%.4f) = (%.4f)"NL, out_value, in_value, diff);
|
||||
}
|
||||
}
|
||||
|
||||
notify_completion(check);
|
||||
}
|
58
tool/mbed/mbed-sdk/libraries/tests/mbed/analog_in/main.cpp
Normal file
58
tool/mbed/mbed-sdk/libraries/tests/mbed/analog_in/main.cpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Version of the Analog test,
|
||||
* Intended for use by devices which
|
||||
* don't have analog out.
|
||||
*
|
||||
* Connect 'control' to pin 21 of an mbed LPC1768
|
||||
* Connect 'analogInput' to pin 18 of an mbed LPC1768
|
||||
* Connect 'TX/RX' to pins 27 and 28 of an mbed LPC1768
|
||||
*
|
||||
* Upload:
|
||||
*/
|
||||
#include "test_env.h"
|
||||
|
||||
#define ERROR_TOLERANCE 0.05
|
||||
|
||||
#if defined(TARGET_LPC1114)
|
||||
|
||||
AnalogIn analogInput(dp4);
|
||||
DigitalOut control(dp5);
|
||||
DigitalOut indicator(LED1);
|
||||
|
||||
#else
|
||||
|
||||
#endif
|
||||
|
||||
uint8_t successes = 0;
|
||||
|
||||
int main() {
|
||||
control = 0;
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
// Read value,
|
||||
float expectedValue = i * 0.1;
|
||||
float value = analogInput.read();
|
||||
|
||||
if (value > expectedValue + ERROR_TOLERANCE || value < expectedValue - ERROR_TOLERANCE) {
|
||||
// Failure.
|
||||
printf("ERROR (out:%.4f) - (in:%.4f) = (%.4f)"NL, expectedValue, value, fabs(expectedValue - value));
|
||||
}
|
||||
else {
|
||||
printf("OK (out:%.4f) - (in:%.4f) = (%.4f)"NL, out_value, in_value, diff);
|
||||
successes++;
|
||||
}
|
||||
|
||||
control = 1;
|
||||
indicator = 1;
|
||||
wait(0.1);
|
||||
control = 0;
|
||||
indicator = 0;
|
||||
}
|
||||
|
||||
if (successes > 8) {
|
||||
notify_success(true);
|
||||
}
|
||||
else {
|
||||
notify_success(false);
|
||||
}
|
||||
}
|
29
tool/mbed/mbed-sdk/libraries/tests/mbed/analog_pot/main.cpp
Normal file
29
tool/mbed/mbed-sdk/libraries/tests/mbed/analog_pot/main.cpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include "mbed.h"
|
||||
#include "test_env.h"
|
||||
|
||||
AnalogIn pot1(A0);
|
||||
AnalogIn pot2(A1);
|
||||
|
||||
#define TEST_ITERATIONS 20
|
||||
#define MEASURE_MIN 0.01
|
||||
|
||||
int main(void) {
|
||||
MBED_HOSTTEST_TIMEOUT(10);
|
||||
MBED_HOSTTEST_SELECT(default_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(AnalogIn potentiometer test);
|
||||
MBED_HOSTTEST_START("analog_pot");
|
||||
|
||||
bool result = false;
|
||||
float val1, val2;
|
||||
|
||||
for (int i = 0; i < TEST_ITERATIONS; i++) {
|
||||
val1 = pot1.read();
|
||||
val2 = pot2.read();
|
||||
|
||||
const char *succes_str = val1 > MEASURE_MIN || val2 > MEASURE_MIN ? "[OK]" : "[FAIL]";
|
||||
result = result || (val1 > MEASURE_MIN || val2 > MEASURE_MIN);
|
||||
printf("Pot values %f, %f\r\n", val1, val2);
|
||||
wait(0.001);
|
||||
}
|
||||
MBED_HOSTTEST_RESULT(result);
|
||||
}
|
9
tool/mbed/mbed-sdk/libraries/tests/mbed/basic/main.cpp
Normal file
9
tool/mbed/mbed-sdk/libraries/tests/mbed/basic/main.cpp
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include "test_env.h"
|
||||
|
||||
int main() {
|
||||
MBED_HOSTTEST_TIMEOUT(20);
|
||||
MBED_HOSTTEST_SELECT(default_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(Basic);
|
||||
MBED_HOSTTEST_START("MBED_A1");
|
||||
MBED_HOSTTEST_RESULT(true);
|
||||
}
|
12
tool/mbed/mbed-sdk/libraries/tests/mbed/blinky/main.cpp
Normal file
12
tool/mbed/mbed-sdk/libraries/tests/mbed/blinky/main.cpp
Normal file
|
@ -0,0 +1,12 @@
|
|||
#include "mbed.h"
|
||||
|
||||
DigitalOut myled(LED1);
|
||||
|
||||
int main() {
|
||||
while(1) {
|
||||
myled = 1;
|
||||
wait(0.2);
|
||||
myled = 0;
|
||||
wait(0.2);
|
||||
}
|
||||
}
|
19
tool/mbed/mbed-sdk/libraries/tests/mbed/bus/main.cpp
Normal file
19
tool/mbed/mbed-sdk/libraries/tests/mbed/bus/main.cpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include "mbed.h"
|
||||
#include "test_env.h"
|
||||
|
||||
BusOut bus1(D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15);
|
||||
BusOut bus2(A5, A4, A3, A2, A1, A0);
|
||||
int i;
|
||||
|
||||
int main()
|
||||
{
|
||||
notify_start();
|
||||
|
||||
for (i=0; i<=65535; i++) {
|
||||
bus1 = i;
|
||||
bus2 = i;
|
||||
wait(0.0001);
|
||||
}
|
||||
|
||||
notify_completion(true);
|
||||
}
|
82
tool/mbed/mbed-sdk/libraries/tests/mbed/bus_out/main.cpp
Normal file
82
tool/mbed/mbed-sdk/libraries/tests/mbed/bus_out/main.cpp
Normal file
|
@ -0,0 +1,82 @@
|
|||
#include "mbed.h"
|
||||
#include "test_env.h"
|
||||
|
||||
namespace {
|
||||
BusOut bus_out(LED1, LED2, LED3, LED4);
|
||||
PinName led_pins[4] = {LED1, LED2, LED3, LED4}; // Temp, used to map pins in bus_out
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
notify_start();
|
||||
|
||||
bool result = false;
|
||||
|
||||
for (;;) {
|
||||
const int mask = bus_out.mask();
|
||||
int led_mask = 0x00;
|
||||
if (LED1 != NC) led_mask |= 0x01;
|
||||
if (LED2 != NC) led_mask |= 0x02;
|
||||
if (LED3 != NC) led_mask |= 0x04;
|
||||
if (LED4 != NC) led_mask |= 0x08;
|
||||
|
||||
printf("MBED: BusIn mask: 0x%X\r\n", mask);
|
||||
printf("MBED: BusIn LED mask: 0x%X\r\n", led_mask);
|
||||
|
||||
// Let's check bus's connected pins mask
|
||||
if (mask != led_mask) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Checking if DigitalOut is correctly set as connected
|
||||
for (int i=0; i < 4; i++) {
|
||||
printf("MBED: BusOut.bit[%d] is %s\r\n",
|
||||
i,
|
||||
(led_pins[i] != NC && bus_out[i].is_connected())
|
||||
? "connected"
|
||||
: "not connected");
|
||||
}
|
||||
|
||||
for (int i=0; i < 4; i++) {
|
||||
if (led_pins[i] != NC && bus_out[0].is_connected() == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Write mask all LEDs
|
||||
bus_out.write(mask); // Set all LED's pins in high state
|
||||
if (bus_out.read() != mask) {
|
||||
break;
|
||||
}
|
||||
// Zero all LEDs and see if mask is correctly cleared on all bits
|
||||
bus_out.write(~mask);
|
||||
if (bus_out.read() != 0x00) {
|
||||
break;
|
||||
}
|
||||
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
|
||||
printf("MBED: Blinking LEDs: \r\n");
|
||||
|
||||
// Just a quick LED blinking...
|
||||
for (int i=0; i<4; i++) {
|
||||
if (led_pins[i] != NC && bus_out[i].is_connected()) {
|
||||
bus_out[i] = 1;
|
||||
printf("%c", 'A' + i);
|
||||
} else {
|
||||
printf(".");
|
||||
}
|
||||
wait(0.2);
|
||||
if (led_pins[i] != NC && bus_out[i].is_connected()) {
|
||||
bus_out[i] = 0;
|
||||
printf("%c", 'a' + i);
|
||||
} else {
|
||||
printf(".");
|
||||
}
|
||||
}
|
||||
printf("\r\n");
|
||||
|
||||
notify_completion(result);
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
#include "test_env.h"
|
||||
|
||||
namespace {
|
||||
bool mbed_main_called = false;
|
||||
}
|
||||
|
||||
extern "C" void mbed_main() {
|
||||
printf("MBED: mbed_main() call before main()\r\n");
|
||||
mbed_main_called = true;
|
||||
}
|
||||
|
||||
int main() {
|
||||
MBED_HOSTTEST_TIMEOUT(20);
|
||||
MBED_HOSTTEST_SELECT(default_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(Call function mbed_main before main);
|
||||
MBED_HOSTTEST_START("MBED_A21");
|
||||
|
||||
printf("MBED: main() starts now!\r\n");
|
||||
|
||||
MBED_HOSTTEST_RESULT(mbed_main_called);
|
||||
}
|
53
tool/mbed/mbed-sdk/libraries/tests/mbed/can/main.cpp
Normal file
53
tool/mbed/mbed-sdk/libraries/tests/mbed/can/main.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
#include "mbed.h"
|
||||
|
||||
Ticker ticker;
|
||||
DigitalOut led1(LED1);
|
||||
DigitalOut led2(LED2);
|
||||
|
||||
#if defined(TARGET_LPC1549)
|
||||
// LPC1549 support only single CAN channel
|
||||
CAN can1(D2, D3);
|
||||
#else
|
||||
CAN can1(p9, p10);
|
||||
#endif
|
||||
|
||||
#if defined(TARGET_LPC4088) || defined(TARGET_LPC4088_DM)
|
||||
CAN can2(p34, p33);
|
||||
#elif defined (TARGET_LPC1768)
|
||||
CAN can2(p30, p29);
|
||||
#endif
|
||||
char counter = 0;
|
||||
|
||||
void printmsg(char *title, CANMessage *msg) {
|
||||
printf("%s [%03X]", title, msg->id);
|
||||
for(char i = 0; i < msg->len; i++) {
|
||||
printf(" %02X", msg->data[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void send() {
|
||||
printf("send()\n");
|
||||
CANMessage msg = CANMessage(1337, &counter, 1);
|
||||
if(can1.write(msg)) {
|
||||
printmsg("Tx message:", &msg);
|
||||
counter++;
|
||||
}
|
||||
led1 = !led1;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("main()\n");
|
||||
ticker.attach(&send, 1);
|
||||
CANMessage msg;
|
||||
while(1) {
|
||||
#if !defined(TARGET_LPC1549)
|
||||
printf("loop()\n");
|
||||
if(can2.read(msg)) {
|
||||
printmsg("Rx message:", &msg);
|
||||
led2 = !led2;
|
||||
}
|
||||
#endif
|
||||
wait(0.2);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
#include "mbed.h"
|
||||
|
||||
Ticker ticker;
|
||||
DigitalOut led1(LED1);
|
||||
DigitalOut led2(LED2);
|
||||
|
||||
#if defined(TARGET_LPC1549)
|
||||
// LPC1549 support only single CAN channel
|
||||
CAN can1(D2, D3);
|
||||
#else
|
||||
CAN can1(p9, p10);
|
||||
#endif
|
||||
|
||||
#if defined(TARGET_LPC4088)
|
||||
CAN can2(p34, p33);
|
||||
#elif defined (TARGET_LPC1768)
|
||||
CAN can2(p30, p29);
|
||||
#endif
|
||||
char counter = 0;
|
||||
|
||||
void printmsg(char *title, CANMessage *msg) {
|
||||
printf("%s [%03X]", title, msg->id);
|
||||
for(char i = 0; i < msg->len; i++) {
|
||||
printf(" %02X", msg->data[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void send() {
|
||||
printf("send()\n");
|
||||
CANMessage msg = CANMessage(1337, &counter, 1);
|
||||
if(can1.write(msg)) {
|
||||
printmsg("Tx message:", &msg);
|
||||
counter++;
|
||||
}
|
||||
led1 = !led1;
|
||||
}
|
||||
|
||||
#if !defined (TARGET_LPC1549)
|
||||
void read() {
|
||||
CANMessage msg;
|
||||
printf("rx()\n");
|
||||
if(can2.read(msg)) {
|
||||
printmsg("Rx message:", &msg);
|
||||
led2 = !led2;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
printf("main()\n");
|
||||
ticker.attach(&send, 1);
|
||||
#if !defined (TARGET_LPC1549)
|
||||
can2.attach(&read);
|
||||
#endif
|
||||
while(1) {
|
||||
printf("loop()\n");
|
||||
wait(1);
|
||||
}
|
||||
}
|
86
tool/mbed/mbed-sdk/libraries/tests/mbed/cpp/main.cpp
Normal file
86
tool/mbed/mbed-sdk/libraries/tests/mbed/cpp/main.cpp
Normal file
|
@ -0,0 +1,86 @@
|
|||
#include "test_env.h"
|
||||
|
||||
#define PATTERN_CHECK_VALUE 0xF0F0ADAD
|
||||
|
||||
class Test {
|
||||
|
||||
private:
|
||||
const char* name;
|
||||
const int pattern;
|
||||
|
||||
public:
|
||||
Test(const char* _name) : name(_name), pattern(PATTERN_CHECK_VALUE) {
|
||||
print("init");
|
||||
}
|
||||
|
||||
void print(const char *message) {
|
||||
printf("%s::%s\n", name, message);
|
||||
}
|
||||
|
||||
bool check_init(void) {
|
||||
bool result = (pattern == PATTERN_CHECK_VALUE);
|
||||
print(result ? "check_init: OK" : "check_init: ERROR");
|
||||
return result;
|
||||
}
|
||||
|
||||
void stack_test(void) {
|
||||
print("stack_test");
|
||||
Test t("Stack");
|
||||
t.hello();
|
||||
}
|
||||
|
||||
void hello(void) {
|
||||
print("hello");
|
||||
}
|
||||
|
||||
~Test() {
|
||||
print("destroy");
|
||||
}
|
||||
};
|
||||
|
||||
/* Check C++ startup initialisation */
|
||||
Test s("Static");
|
||||
|
||||
/* EXPECTED OUTPUT:
|
||||
*******************
|
||||
Static::init
|
||||
Static::stack_test
|
||||
Stack::init
|
||||
Stack::hello
|
||||
Stack::destroy
|
||||
Static::check_init: OK
|
||||
Heap::init
|
||||
Heap::hello
|
||||
Heap::destroy
|
||||
*******************/
|
||||
int main (void) {
|
||||
MBED_HOSTTEST_TIMEOUT(10);
|
||||
MBED_HOSTTEST_SELECT(default_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(C++);
|
||||
MBED_HOSTTEST_START("MBED_12");
|
||||
|
||||
bool result = true;
|
||||
for (;;)
|
||||
{
|
||||
// Global stack object simple test
|
||||
s.stack_test();
|
||||
if (s.check_init() == false)
|
||||
{
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// Heap test object simple test
|
||||
Test *m = new Test("Heap");
|
||||
m->hello();
|
||||
|
||||
if (m->check_init() == false)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
delete m;
|
||||
break;
|
||||
}
|
||||
|
||||
MBED_HOSTTEST_RESULT(result);
|
||||
}
|
100
tool/mbed/mbed-sdk/libraries/tests/mbed/cstring/main.cpp
Normal file
100
tool/mbed/mbed-sdk/libraries/tests/mbed/cstring/main.cpp
Normal file
|
@ -0,0 +1,100 @@
|
|||
#include "mbed.h"
|
||||
#include "test_env.h"
|
||||
#include <string.h>
|
||||
|
||||
#define BUFFER_SIZE 256
|
||||
#define CLEAN_BUFFER(BUFF) memset(BUFF, 0x00, BUFFER_SIZE)
|
||||
|
||||
#define NEGATIVE_INTEGERS -32768,-3214,-999,-100,-1,0,-1,-4231,-999,-4123,-32760,-99999
|
||||
#define POSITIVE_INTEGERS 32768,3214,999,100,1,0,1,4231,999,4123,32760,99999
|
||||
#define FLOATS 0.002,0.92430,15.91320,791.77368,6208.2,25719.4952,426815.982588,6429271.046,42468024.93,212006462.910
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
char buffer[BUFFER_SIZE] = {0};
|
||||
bool result = true;
|
||||
bool cmp_result;
|
||||
|
||||
{
|
||||
CLEAN_BUFFER(buffer);
|
||||
sprintf(buffer, "%i %d %i %d %i %d %i %d %i %d %i %i", NEGATIVE_INTEGERS);
|
||||
cmp_result = TESTENV_STRCMP(buffer, "-32768 -3214 -999 -100 -1 0 -1 -4231 -999 -4123 -32760 -99999");
|
||||
printf("[%s] %s\r\n", cmp_result ? "OK" : "FAIL", buffer);
|
||||
result = result && cmp_result;
|
||||
}
|
||||
|
||||
{
|
||||
CLEAN_BUFFER(buffer);
|
||||
sprintf(buffer, "%u %d %u %d %u %d %u %d %u %d %u %d", POSITIVE_INTEGERS);
|
||||
cmp_result = TESTENV_STRCMP(buffer, "32768 3214 999 100 1 0 1 4231 999 4123 32760 99999");
|
||||
printf("[%s] %s\r\n", cmp_result ? "OK" : "FAIL", buffer);
|
||||
result = result && cmp_result;
|
||||
}
|
||||
|
||||
{
|
||||
CLEAN_BUFFER(buffer);
|
||||
sprintf(buffer, "%x %X %x %X %x %X %x %X %x %X %x %X", POSITIVE_INTEGERS);
|
||||
cmp_result = TESTENV_STRCMP(buffer, "8000 C8E 3e7 64 1 0 1 1087 3e7 101B 7ff8 1869F");
|
||||
printf("[%s] %s\r\n", cmp_result ? "OK" : "FAIL", buffer);
|
||||
result = result && cmp_result;
|
||||
}
|
||||
|
||||
{
|
||||
CLEAN_BUFFER(buffer);
|
||||
sprintf(buffer, "%f %f %f %f %f %f %f %f %f %f", FLOATS);
|
||||
cmp_result = TESTENV_STRCMP(buffer, "0.002000 0.924300 15.913200 791.773680 6208.200000 25719.495200 426815.982588 6429271.046000 42468024.930000 212006462.910000");
|
||||
printf("[%s] %s\r\n", cmp_result ? "OK" : "FAIL", buffer);
|
||||
result = result && cmp_result;
|
||||
}
|
||||
|
||||
{
|
||||
CLEAN_BUFFER(buffer);
|
||||
sprintf(buffer, "%g %g %g %g %g %g %g %g %g %g", FLOATS);
|
||||
cmp_result = TESTENV_STRCMP(buffer, "0.002 0.9243 15.9132 791.774 6208.2 25719.5 426816 6.42927e+006 4.2468e+007 2.12006e+008");
|
||||
cmp_result = cmp_result || TESTENV_STRCMP(buffer, "0.002 0.9243 15.9132 791.774 6208.2 25719.5 426816 6.42927e+06 4.2468e+07 2.12006e+08");
|
||||
printf("[%s] %s\r\n", cmp_result ? "OK" : "FAIL", buffer);
|
||||
result = result && cmp_result;
|
||||
}
|
||||
|
||||
{
|
||||
CLEAN_BUFFER(buffer);
|
||||
sprintf(buffer, "%e %E %e %E %e %E %e %E %e %E", FLOATS);
|
||||
cmp_result = TESTENV_STRCMP(buffer, "2.000000e-003 9.243000E-001 1.591320e+001 7.917737E+002 6.208200e+003 2.571950E+004 4.268160e+005 6.429271E+006 4.246802e+007 2.120065E+008");
|
||||
cmp_result = cmp_result || TESTENV_STRCMP(buffer, "2.000000e-03 9.243000E-01 1.591320e+01 7.917737E+02 6.208200e+03 2.571950E+04 4.268160e+05 6.429271E+06 4.246802e+07 2.120065E+08");
|
||||
printf("[%s] %s\r\n", cmp_result ? "OK" : "FAIL", buffer);
|
||||
result = result && cmp_result;
|
||||
}
|
||||
|
||||
{
|
||||
CLEAN_BUFFER(buffer);
|
||||
char str[] ="- This, a sample string.";
|
||||
char * pch = strtok (str," ,.-");
|
||||
while (pch != NULL) {
|
||||
strcat(buffer, pch);
|
||||
pch = strtok (NULL, " ,.-");
|
||||
}
|
||||
cmp_result = TESTENV_STRCMP(buffer, "Thisasamplestring");
|
||||
printf("[%s] %s\r\n", cmp_result ? "OK" : "FAIL", buffer);
|
||||
result = result && cmp_result;
|
||||
}
|
||||
|
||||
{
|
||||
CLEAN_BUFFER(buffer);
|
||||
char str[] = "This is a sample string";
|
||||
char key[] = "aeiou";
|
||||
char *pch = strpbrk(str, key);
|
||||
while (pch != NULL)
|
||||
{
|
||||
char buf[2] = {*pch, '\0'};
|
||||
strcat(buffer, buf);
|
||||
pch = strpbrk(pch + 1,key);
|
||||
}
|
||||
cmp_result = TESTENV_STRCMP(buffer, "iiaaei");
|
||||
printf("[%s] %s\r\n", cmp_result ? "OK" : "FAIL", buffer);
|
||||
result = result && cmp_result;
|
||||
}
|
||||
|
||||
notify_completion(result);
|
||||
return 0;
|
||||
}
|
15
tool/mbed/mbed-sdk/libraries/tests/mbed/detect/main.cpp
Normal file
15
tool/mbed/mbed-sdk/libraries/tests/mbed/detect/main.cpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include "mbed.h"
|
||||
#include "test_env.h"
|
||||
|
||||
int main() {
|
||||
MBED_HOSTTEST_TIMEOUT(10);
|
||||
MBED_HOSTTEST_SELECT(detect_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(Simple detect test);
|
||||
MBED_HOSTTEST_START("DTCT_1");
|
||||
|
||||
notify_start();
|
||||
printf("MBED: Target '%s'\r\n", TEST_SUITE_TARGET_NAME);
|
||||
printf("MBED: Test ID '%s'\r\n", TEST_SUITE_TEST_ID);
|
||||
printf("MBED: UUID '%s'\r\n", TEST_SUITE_UUID);
|
||||
MBED_HOSTTEST_RESULT(true);
|
||||
}
|
30
tool/mbed/mbed-sdk/libraries/tests/mbed/dev_null/main.cpp
Normal file
30
tool/mbed/mbed-sdk/libraries/tests/mbed/dev_null/main.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include "mbed.h"
|
||||
#include "test_env.h"
|
||||
|
||||
class DevNull : public Stream {
|
||||
public:
|
||||
DevNull(const char *name = NULL) : Stream(name) {}
|
||||
|
||||
protected:
|
||||
virtual int _getc() {
|
||||
return 0;
|
||||
}
|
||||
virtual int _putc(int c) {
|
||||
return c;
|
||||
}
|
||||
};
|
||||
|
||||
DevNull null("null");
|
||||
|
||||
int main() {
|
||||
MBED_HOSTTEST_TIMEOUT(20);
|
||||
MBED_HOSTTEST_SELECT(dev_null_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(stdout redirected to dev null);
|
||||
MBED_HOSTTEST_START("EXAMPLE_1");
|
||||
|
||||
printf("MBED: re-routing stdout to /null\r\n");
|
||||
freopen("/null", "w", stdout);
|
||||
printf("MBED: printf redirected to /null\r\n"); // This shouldn't appear
|
||||
// If failure message can be seen test should fail :)
|
||||
MBED_HOSTTEST_RESULT(false); // This is 'false' on purpose
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
#include "test_env.h"
|
||||
|
||||
#if defined(TARGET_LPC1114)
|
||||
DigitalOut out(dp1);
|
||||
DigitalIn in(dp2);
|
||||
|
||||
#elif defined(TARGET_LPC1549)
|
||||
// TARGET_FF_ARDUINO cannot be used, because D0 is used as USBRX (USB serial
|
||||
// port pin), D1 is used as USBTX
|
||||
DigitalOut out(D7);
|
||||
DigitalIn in(D2);
|
||||
|
||||
#elif defined(TARGET_NUCLEO_F030R8) || \
|
||||
defined(TARGET_NUCLEO_F070RB) || \
|
||||
defined(TARGET_NUCLEO_F072RB) || \
|
||||
defined(TARGET_NUCLEO_F091RC) || \
|
||||
defined(TARGET_NUCLEO_F103RB) || \
|
||||
defined(TARGET_NUCLEO_F302R8) || \
|
||||
defined(TARGET_NUCLEO_F303RE) || \
|
||||
defined(TARGET_NUCLEO_F334R8) || \
|
||||
defined(TARGET_NUCLEO_F401RE) || \
|
||||
defined(TARGET_NUCLEO_F411RE) || \
|
||||
defined(TARGET_NUCLEO_L053R8) || \
|
||||
defined(TARGET_NUCLEO_L073RZ) || \
|
||||
defined(TARGET_NUCLEO_L152RE)
|
||||
DigitalOut out(PC_7);
|
||||
DigitalIn in(PB_8);
|
||||
|
||||
#elif defined(TARGET_ARCH_MAX) || \
|
||||
defined(TARGET_DISCO_F407VG) || \
|
||||
defined(TARGET_DISCO_F429ZI)|| \
|
||||
defined(TARGET_DISCO_F401VC)
|
||||
DigitalOut out(PC_12);
|
||||
DigitalIn in(PD_0);
|
||||
|
||||
#elif defined(TARGET_FF_ARDUINO)
|
||||
DigitalOut out(D7);
|
||||
DigitalIn in(D0);
|
||||
|
||||
#elif defined(TARGET_MAXWSNENV)
|
||||
DigitalOut out(TP3);
|
||||
DigitalIn in(TP4);
|
||||
|
||||
#elif defined(TARGET_MAX32600MBED)
|
||||
DigitalOut out(P1_0);
|
||||
DigitalIn in(P4_7);
|
||||
|
||||
#else
|
||||
DigitalOut out(p5);
|
||||
DigitalIn in(p25);
|
||||
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
MBED_HOSTTEST_TIMEOUT(10);
|
||||
MBED_HOSTTEST_SELECT(default_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(DigitalIn DigitalOut);
|
||||
MBED_HOSTTEST_START("MBED_A5");
|
||||
|
||||
out = 0;
|
||||
wait(0.1);
|
||||
if (in != 0) {
|
||||
printf("ERROR: in != 0\n");
|
||||
MBED_HOSTTEST_RESULT(false);
|
||||
}
|
||||
out = 1;
|
||||
wait(0.1);
|
||||
if (in != 1) {
|
||||
printf("ERROR: in != 1\n");
|
||||
MBED_HOSTTEST_RESULT(false);
|
||||
}
|
||||
|
||||
MBED_HOSTTEST_RESULT(true);
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
#include "test_env.h"
|
||||
|
||||
#if defined(TARGET_LPC1114)
|
||||
DigitalInOut d1(dp1);
|
||||
DigitalInOut d2(dp2);
|
||||
|
||||
#elif defined(TARGET_LPC1549)
|
||||
// TARGET_FF_ARDUINO cannot be used, because D0 is used as USBRX (USB serial
|
||||
// port pin), D1 is used as USBTX
|
||||
DigitalInOut d1(D2);
|
||||
DigitalInOut d2(D7);
|
||||
|
||||
#elif defined(TARGET_NUCLEO_F030R8) || \
|
||||
defined(TARGET_NUCLEO_F070RB) || \
|
||||
defined(TARGET_NUCLEO_F072RB) || \
|
||||
defined(TARGET_NUCLEO_F091RC) || \
|
||||
defined(TARGET_NUCLEO_F103RB) || \
|
||||
defined(TARGET_NUCLEO_F302R8) || \
|
||||
defined(TARGET_NUCLEO_F303RE) || \
|
||||
defined(TARGET_NUCLEO_F334R8) || \
|
||||
defined(TARGET_NUCLEO_F401RE) || \
|
||||
defined(TARGET_NUCLEO_F411RE) || \
|
||||
defined(TARGET_NUCLEO_L053R8) || \
|
||||
defined(TARGET_NUCLEO_L073RZ) || \
|
||||
defined(TARGET_NUCLEO_L152RE)
|
||||
DigitalInOut d1(PC_7);
|
||||
DigitalInOut d2(PB_8);
|
||||
|
||||
#elif defined(TARGET_ARCH_MAX) || \
|
||||
defined(TARGET_DISCO_F407VG) || \
|
||||
defined(TARGET_DISCO_F429ZI)|| \
|
||||
defined(TARGET_DISCO_F401VC)
|
||||
DigitalInOut d1(PC_12);
|
||||
DigitalInOut d2(PD_0);
|
||||
|
||||
#elif defined(TARGET_FF_ARDUINO)
|
||||
DigitalInOut d1(D0);
|
||||
DigitalInOut d2(D7);
|
||||
|
||||
#elif defined(TARGET_MAXWSNENV)
|
||||
DigitalInOut d1(TP3);
|
||||
DigitalInOut d2(TP4);
|
||||
|
||||
#elif defined(TARGET_MAX32600MBED)
|
||||
DigitalInOut d1(P1_0);
|
||||
DigitalInOut d2(P4_7);
|
||||
|
||||
#else
|
||||
DigitalInOut d1(p5);
|
||||
DigitalInOut d2(p25);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
MBED_HOSTTEST_TIMEOUT(10);
|
||||
MBED_HOSTTEST_SELECT(default_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(DigitalInOut);
|
||||
MBED_HOSTTEST_START("MBED_A6");
|
||||
|
||||
bool check = true;
|
||||
|
||||
d1.output();
|
||||
d2.input();
|
||||
d1 = 1;
|
||||
wait(0.1);
|
||||
if (d2 != 1) {
|
||||
printf("MBED: First check failed! d2 is %d\n", (int)d2);
|
||||
check = false;
|
||||
}
|
||||
d1 = 0;
|
||||
wait(0.1);
|
||||
if (d2 != 0) {
|
||||
printf("MBED: Second check failed! d2 is %d\n", (int)d2);
|
||||
check = false;
|
||||
}
|
||||
|
||||
d1.input();
|
||||
d2.output();
|
||||
d2 = 1;
|
||||
wait(0.1);
|
||||
if (d1 != 1) {
|
||||
printf("MBED: Third check failed! d1 is %d\n", (int)d1);
|
||||
check = false;
|
||||
}
|
||||
d2 = 0;
|
||||
wait(0.1);
|
||||
if (d1 != 0) {
|
||||
printf("MBED: Fourth check failed! d1 is %d\n", (int)d1);
|
||||
check = false;
|
||||
}
|
||||
|
||||
MBED_HOSTTEST_RESULT(check);
|
||||
}
|
78
tool/mbed/mbed-sdk/libraries/tests/mbed/dir/main.cpp
Normal file
78
tool/mbed/mbed-sdk/libraries/tests/mbed/dir/main.cpp
Normal file
|
@ -0,0 +1,78 @@
|
|||
#include "mbed.h"
|
||||
|
||||
void led_blink(PinName led) {
|
||||
DigitalOut myled(led);
|
||||
while (1) {
|
||||
myled = !myled;
|
||||
wait(1.0);
|
||||
}
|
||||
}
|
||||
|
||||
void notify_completion(bool success) {
|
||||
if (success) {
|
||||
printf("{success}\n");
|
||||
} else {
|
||||
printf("{failure}\n");
|
||||
}
|
||||
|
||||
printf("{end}\n");
|
||||
led_blink(success ? LED1 : LED4);
|
||||
}
|
||||
|
||||
#define TEST_STRING "Hello World!"
|
||||
|
||||
FILE* test_open(char* path, const char* mode) {
|
||||
FILE *f;
|
||||
f = fopen(path, mode);
|
||||
if (f == NULL) {
|
||||
printf("Error opening file\n");
|
||||
notify_completion(false);
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
void test_write(FILE* f, const char* str) {
|
||||
int n = fprintf(f, str);
|
||||
if (n != strlen(str)) {
|
||||
printf("Error writing file\n");
|
||||
notify_completion(false);
|
||||
}
|
||||
}
|
||||
|
||||
void test_close(FILE* f) {
|
||||
int rc = fclose(f);
|
||||
if (rc != 0) {
|
||||
printf("Error closing file\n");
|
||||
notify_completion(false);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
LocalFileSystem local("local");
|
||||
|
||||
FILE *f;
|
||||
char* str = TEST_STRING;
|
||||
char* buffer = (char*) malloc(sizeof(unsigned char)*strlen(TEST_STRING));
|
||||
int str_len = strlen(TEST_STRING);
|
||||
|
||||
printf("Write files\n");
|
||||
char filename[32];
|
||||
for (int i=0; i<10; i++) {
|
||||
sprintf(filename, "/local/test_%d.txt", i);
|
||||
printf("Creating file: %s\n", filename);
|
||||
f = test_open(filename, "w");
|
||||
test_write(f, str);
|
||||
test_close(f);
|
||||
}
|
||||
|
||||
printf("List files:\n");
|
||||
DIR *d = opendir("/local");
|
||||
struct dirent *p;
|
||||
while((p = readdir(d)) != NULL) {
|
||||
printf("%s\n", p->d_name);
|
||||
}
|
||||
closedir(d);
|
||||
|
||||
notify_completion(true);
|
||||
}
|
119
tool/mbed/mbed-sdk/libraries/tests/mbed/dir_sd/main.cpp
Normal file
119
tool/mbed/mbed-sdk/libraries/tests/mbed/dir_sd/main.cpp
Normal file
|
@ -0,0 +1,119 @@
|
|||
#include "mbed.h"
|
||||
#include "SDFileSystem.h"
|
||||
|
||||
void led_blink(PinName led)
|
||||
{
|
||||
DigitalOut myled(led);
|
||||
|
||||
while (1) {
|
||||
myled = !myled;
|
||||
wait(1.0);
|
||||
}
|
||||
}
|
||||
|
||||
void notify_completion(bool success)
|
||||
{
|
||||
if (success)
|
||||
printf("{success}\n");
|
||||
else
|
||||
printf("{failure}\n");
|
||||
|
||||
printf("{end}\n");
|
||||
led_blink(success ? LED1 : LED4);
|
||||
}
|
||||
|
||||
#define TEST_STRING "Hello World!"
|
||||
|
||||
FILE *test_open(char *path, const char *mode)
|
||||
{
|
||||
FILE *f;
|
||||
|
||||
f = fopen(path, mode);
|
||||
if (f == NULL) {
|
||||
printf("Error opening file\n");
|
||||
notify_completion(false);
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
void test_write(FILE *f, const char *str)
|
||||
{
|
||||
int n = fprintf(f, str);
|
||||
|
||||
if (n != strlen(str)) {
|
||||
printf("Error writing file\n");
|
||||
notify_completion(false);
|
||||
}
|
||||
}
|
||||
|
||||
void test_close(FILE *f)
|
||||
{
|
||||
int rc = fclose(f);
|
||||
|
||||
if (rc != 0) {
|
||||
printf("Error closing file\n");
|
||||
notify_completion(false);
|
||||
}
|
||||
}
|
||||
|
||||
DigitalOut led2(LED2);
|
||||
|
||||
int main()
|
||||
{
|
||||
#if defined(TARGET_KL25Z)
|
||||
SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");
|
||||
#elif defined(TARGET_nRF51822)
|
||||
//SDFileSystem sd(p20, p22, p25, p24, "sd");
|
||||
SDFileSystem sd(p12, p13, p15, p14, "sd");
|
||||
#elif defined(TARGET_NUCLEO_F030R8) || \
|
||||
defined(TARGET_NUCLEO_F070RB) || \
|
||||
defined(TARGET_NUCLEO_F072RB) || \
|
||||
defined(TARGET_NUCLEO_F091RC) || \
|
||||
defined(TARGET_NUCLEO_F103RB) || \
|
||||
defined(TARGET_NUCLEO_F302R8) || \
|
||||
defined(TARGET_NUCLEO_F303RE) || \
|
||||
defined(TARGET_NUCLEO_F334R8) || \
|
||||
defined(TARGET_NUCLEO_F401RE) || \
|
||||
defined(TARGET_NUCLEO_F411RE) || \
|
||||
defined(TARGET_NUCLEO_L053R8) || \
|
||||
defined(TARGET_NUCLEO_L073RZ) || \
|
||||
defined(TARGET_NUCLEO_L152RE)
|
||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
||||
#elif defined(TARGET_LPC11U37H_401)
|
||||
SDFileSystem sd(SDMOSI, SDMISO, SDSCLK, SDSSEL, "sd");
|
||||
#else
|
||||
SDFileSystem sd(p11, p12, p13, p14, "sd");
|
||||
#endif
|
||||
led2 = 1;
|
||||
wait(0.5);
|
||||
FILE *f;
|
||||
char *str = TEST_STRING;
|
||||
char *buffer = (char *)malloc(sizeof(unsigned char) * strlen(TEST_STRING));
|
||||
int str_len = strlen(TEST_STRING);
|
||||
|
||||
printf("Write files\n");
|
||||
char filename[32];
|
||||
for (int i = 0; i < 10; i++) {
|
||||
sprintf(filename, "/sd/test_%d.txt", i);
|
||||
printf("Creating file: %s\n", filename);
|
||||
f = test_open(filename, "w");
|
||||
led2 = 0;
|
||||
test_write(f, str);
|
||||
test_close(f);
|
||||
}
|
||||
|
||||
printf("List files:\n");
|
||||
DIR *d = opendir("/sd");
|
||||
if (d == NULL) {
|
||||
printf("Error opening directory\n");
|
||||
notify_completion(false);
|
||||
}
|
||||
|
||||
struct dirent *p;
|
||||
while ((p = readdir(d)) != NULL)
|
||||
printf("%s\n", p->d_name);
|
||||
closedir(d);
|
||||
|
||||
notify_completion(true);
|
||||
}
|
44
tool/mbed/mbed-sdk/libraries/tests/mbed/div/main.cpp
Normal file
44
tool/mbed/mbed-sdk/libraries/tests/mbed/div/main.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include <utility> // std::pair
|
||||
#include "mbed.h"
|
||||
#include "test_env.h"
|
||||
|
||||
uint32_t test_64(uint64_t ticks) {
|
||||
ticks >>= 3; // divide by 8
|
||||
if (ticks > 0xFFFFFFFF) {
|
||||
ticks /= 3;
|
||||
} else {
|
||||
ticks = (ticks * 0x55555556) >> 32; // divide by 3
|
||||
}
|
||||
return (uint32_t)(0xFFFFFFFF & ticks);
|
||||
}
|
||||
|
||||
const char *result_str(bool result) {
|
||||
return result ? "[OK]" : "[FAIL]";
|
||||
}
|
||||
|
||||
int main() {
|
||||
MBED_HOSTTEST_TIMEOUT(20);
|
||||
MBED_HOSTTEST_SELECT(default_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(Integer constant division);
|
||||
MBED_HOSTTEST_START("MBED_26");
|
||||
|
||||
bool result = true;
|
||||
|
||||
{ // 0xFFFFFFFF * 8 = 0x7fffffff8
|
||||
std::pair<uint32_t, uint64_t> values = std::make_pair(0x55555555, 0x7FFFFFFF8);
|
||||
uint32_t test_ret = test_64(values.second);
|
||||
bool test_res = values.first == test_ret;
|
||||
result = result && test_res;
|
||||
printf("64bit: 0x7FFFFFFF8: expected 0x%lX got 0x%lX ... %s\r\n", values.first, test_ret, result_str(test_res));
|
||||
}
|
||||
|
||||
{ // 0xFFFFFFFF * 24 = 0x17ffffffe8
|
||||
std::pair<uint32_t, uint64_t> values = std::make_pair(0xFFFFFFFF, 0x17FFFFFFE8);
|
||||
uint32_t test_ret = test_64(values.second);
|
||||
bool test_res = values.first == test_ret;
|
||||
result = result && test_res;
|
||||
printf("64bit: 0x17FFFFFFE8: expected 0x%lX got 0x%lX ... %s\r\n", values.first, test_ret, result_str(test_res));
|
||||
}
|
||||
|
||||
MBED_HOSTTEST_RESULT(result);
|
||||
}
|
26
tool/mbed/mbed-sdk/libraries/tests/mbed/echo/main.cpp
Normal file
26
tool/mbed/mbed-sdk/libraries/tests/mbed/echo/main.cpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include "mbed.h"
|
||||
#include "test_env.h"
|
||||
|
||||
#define TXPIN USBTX
|
||||
#define RXPIN USBRX
|
||||
|
||||
|
||||
namespace {
|
||||
const int BUFFER_SIZE = 48;
|
||||
char buffer[BUFFER_SIZE] = {0};
|
||||
}
|
||||
|
||||
int main() {
|
||||
MBED_HOSTTEST_TIMEOUT(20);
|
||||
MBED_HOSTTEST_SELECT(echo);
|
||||
MBED_HOSTTEST_DESCRIPTION(Serial Echo at 115200);
|
||||
MBED_HOSTTEST_START("MBED_A9");
|
||||
|
||||
Serial pc(TXPIN, RXPIN);
|
||||
pc.baud(115200);
|
||||
|
||||
while (1) {
|
||||
pc.gets(buffer, BUFFER_SIZE - 1);
|
||||
pc.printf("%s", buffer);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
#include "mbed.h"
|
||||
|
||||
#if defined(TARGET_LPC1768)
|
||||
#define UART_TX p9
|
||||
#define UART_RX p10
|
||||
#define FLOW_CONTROL_RTS p30
|
||||
#define FLOW_CONTROL_CTS p29
|
||||
#define RTS_CHECK_PIN p8
|
||||
#else
|
||||
#error This test is not supported on this target
|
||||
#endif
|
||||
|
||||
Serial pc(UART_TX, UART_RX);
|
||||
|
||||
#ifdef RTS_CHECK_PIN
|
||||
InterruptIn in(RTS_CHECK_PIN);
|
||||
DigitalOut led(LED1);
|
||||
static void checker(void) {
|
||||
led = !led;
|
||||
}
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
char buf[256];
|
||||
|
||||
pc.set_flow_control(Serial::RTSCTS, FLOW_CONTROL_RTS, FLOW_CONTROL_CTS);
|
||||
#ifdef RTS_CHECK_PIN
|
||||
in.fall(checker);
|
||||
#endif
|
||||
while (1) {
|
||||
pc.gets(buf, 256);
|
||||
pc.printf("%s", buf);
|
||||
}
|
||||
}
|
92
tool/mbed/mbed-sdk/libraries/tests/mbed/env/test_env.cpp
vendored
Normal file
92
tool/mbed/mbed-sdk/libraries/tests/mbed/env/test_env.cpp
vendored
Normal file
|
@ -0,0 +1,92 @@
|
|||
#include "test_env.h"
|
||||
|
||||
// Const strings used in test_end
|
||||
const char* TEST_ENV_START = "start";
|
||||
const char* TEST_ENV_SUCCESS = "success";
|
||||
const char* TEST_ENV_FAILURE = "failure";
|
||||
const char* TEST_ENV_MEASURE = "measure";
|
||||
const char* TEST_ENV_END = "end";
|
||||
|
||||
|
||||
static void led_blink(PinName led, float delay)
|
||||
{
|
||||
if (led != NC) {
|
||||
DigitalOut myled(led);
|
||||
while (1) {
|
||||
myled = !myled;
|
||||
wait(delay);
|
||||
}
|
||||
}
|
||||
while(1);
|
||||
}
|
||||
|
||||
void notify_start()
|
||||
{
|
||||
printf("{{%s}}" NL, TEST_ENV_START);
|
||||
}
|
||||
|
||||
void notify_performance_coefficient(const char* measurement_name, const int value)
|
||||
{
|
||||
printf("{{%s;%s;%d}}" RCNL, TEST_ENV_MEASURE, measurement_name, value);
|
||||
}
|
||||
|
||||
void notify_performance_coefficient(const char* measurement_name, const unsigned int value)
|
||||
{
|
||||
printf("{{%s;%s;%u}}" RCNL, TEST_ENV_MEASURE, measurement_name, value);
|
||||
}
|
||||
|
||||
void notify_performance_coefficient(const char* measurement_name, const double value)
|
||||
{
|
||||
printf("{{%s;%s;%f}}" RCNL, TEST_ENV_MEASURE, measurement_name, value);
|
||||
}
|
||||
|
||||
void notify_completion(bool success)
|
||||
{
|
||||
printf("{{%s}}" NL "{{%s}}" NL, success ? TEST_ENV_SUCCESS : TEST_ENV_FAILURE, TEST_ENV_END);
|
||||
led_blink(LED1, success ? 1.0 : 0.1);
|
||||
}
|
||||
|
||||
bool notify_completion_str(bool success, char* buffer)
|
||||
{
|
||||
bool result = false;
|
||||
if (buffer) {
|
||||
sprintf(buffer, "{{%s}}" NL "{{%s}}" NL, success ? TEST_ENV_SUCCESS : TEST_ENV_FAILURE, TEST_ENV_END);
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Host test auto-detection API
|
||||
void notify_host_test_name(const char *host_test) {
|
||||
if (host_test) {
|
||||
printf("{{host_test_name;%s}}" NL, host_test);
|
||||
}
|
||||
}
|
||||
|
||||
void notify_timeout(int timeout) {
|
||||
printf("{{timeout;%d}}" NL, timeout);
|
||||
}
|
||||
|
||||
void notify_test_id(const char *test_id) {
|
||||
if (test_id) {
|
||||
printf("{{test_id;%s}}" NL, test_id);
|
||||
}
|
||||
}
|
||||
|
||||
void notify_test_description(const char *description) {
|
||||
if (description) {
|
||||
printf("{{description;%s}}" NL, description);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -DMBED_BUILD_TIMESTAMP=1406208182.13
|
||||
unsigned int testenv_randseed()
|
||||
{
|
||||
unsigned int seed = 0;
|
||||
#ifdef MBED_BUILD_TIMESTAMP
|
||||
long long_seed = static_cast<long>(MBED_BUILD_TIMESTAMP);
|
||||
seed = long_seed & 0xFFFFFFFF;
|
||||
#endif /* MBED_BUILD_TIMESTAMP */
|
||||
return seed;
|
||||
}
|
74
tool/mbed/mbed-sdk/libraries/tests/mbed/env/test_env.h
vendored
Normal file
74
tool/mbed/mbed-sdk/libraries/tests/mbed/env/test_env.h
vendored
Normal file
|
@ -0,0 +1,74 @@
|
|||
#ifndef TEST_ENV_H_
|
||||
#define TEST_ENV_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include "mbed.h"
|
||||
|
||||
#define NL "\n"
|
||||
#define RCNL "\r\n"
|
||||
|
||||
// Const strings used in test_end
|
||||
extern const char* TEST_ENV_START;
|
||||
extern const char* TEST_ENV_SUCCESS;
|
||||
extern const char* TEST_ENV_FAILURE;
|
||||
extern const char* TEST_ENV_MEASURE;
|
||||
extern const char* TEST_ENV_END;
|
||||
|
||||
// Test result related notification functions
|
||||
void notify_start();
|
||||
void notify_completion(bool success);
|
||||
bool notify_completion_str(bool success, char* buffer);
|
||||
void notify_performance_coefficient(const char* measurement_name, const int value);
|
||||
void notify_performance_coefficient(const char* measurement_name, const unsigned int value);
|
||||
void notify_performance_coefficient(const char* measurement_name, const double value);
|
||||
|
||||
// Host test auto-detection API
|
||||
void notify_host_test_name(const char *host_test);
|
||||
void notify_timeout(int timeout);
|
||||
void notify_test_id(const char *test_id);
|
||||
void notify_test_description(const char *description);
|
||||
|
||||
// Host test auto-detection API
|
||||
#define MBED_HOSTTEST_START(TESTID) notify_test_id(TESTID); notify_start()
|
||||
#define MBED_HOSTTEST_SELECT(NAME) notify_host_test_name(#NAME)
|
||||
#define MBED_HOSTTEST_TIMEOUT(SECONDS) notify_timeout(SECONDS)
|
||||
#define MBED_HOSTTEST_DESCRIPTION(DESC) notify_test_description(#DESC)
|
||||
#define MBED_HOSTTEST_RESULT(RESULT) notify_completion(RESULT)
|
||||
|
||||
/**
|
||||
Test auto-detection preamble example:
|
||||
main() {
|
||||
MBED_HOSTTEST_TIMEOUT(10);
|
||||
MBED_HOSTTEST_SELECT( host_test );
|
||||
MBED_HOSTTEST_DESCRIPTION(Hello World);
|
||||
MBED_HOSTTEST_START("MBED_10");
|
||||
// Proper 'host_test.py' should take over supervising of this test
|
||||
|
||||
// Test code
|
||||
bool result = ...;
|
||||
|
||||
MBED_HOSTTEST_RESULT(result);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// Test functionality useful during testing
|
||||
unsigned int testenv_randseed();
|
||||
|
||||
// Macros, unit test like to provide basic comparisons
|
||||
#define TESTENV_STRCMP(GIVEN,EXPECTED) (strcmp(GIVEN,EXPECTED) == 0)
|
||||
|
||||
// macros passed via test suite
|
||||
#ifndef TEST_SUITE_TARGET_NAME
|
||||
#define TEST_SUITE_TARGET_NAME "Unknown"
|
||||
#endif
|
||||
|
||||
#ifndef TEST_SUITE_TEST_ID
|
||||
#define TEST_SUITE_TEST_ID "Unknown"
|
||||
#endif
|
||||
|
||||
#ifndef TEST_SUITE_UUID
|
||||
#define TEST_SUITE_UUID "Unknown"
|
||||
#endif
|
||||
|
||||
#endif
|
78
tool/mbed/mbed-sdk/libraries/tests/mbed/file/main.cpp
Normal file
78
tool/mbed/mbed-sdk/libraries/tests/mbed/file/main.cpp
Normal file
|
@ -0,0 +1,78 @@
|
|||
#include "test_env.h"
|
||||
#include "semihost_api.h"
|
||||
|
||||
Serial pc(USBTX, USBRX);
|
||||
|
||||
#define FILENAME "/local/out.txt"
|
||||
#define TEST_STRING "Hello World!"
|
||||
|
||||
FILE *test_open(const char *mode) {
|
||||
FILE *f = fopen(FILENAME, mode);
|
||||
if (f == NULL) {
|
||||
printf("Error opening file"NL);
|
||||
notify_completion(false);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
void test_write(FILE *f, char *str, int str_len) {
|
||||
int n = fprintf(f, str);
|
||||
|
||||
if (n != str_len) {
|
||||
printf("Error writing file"NL);
|
||||
notify_completion(false);
|
||||
}
|
||||
}
|
||||
|
||||
void test_read(FILE *f, char *str, int str_len) {
|
||||
int n = fread(str, sizeof(unsigned char), str_len, f);
|
||||
|
||||
if (n != str_len) {
|
||||
printf("Error reading file"NL);
|
||||
notify_completion(false);
|
||||
}
|
||||
}
|
||||
|
||||
void test_close(FILE *f) {
|
||||
int rc = fclose(f);
|
||||
|
||||
if (rc != 0) {
|
||||
printf("Error closing file"NL);
|
||||
notify_completion(false);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
MBED_HOSTTEST_TIMEOUT(20);
|
||||
MBED_HOSTTEST_SELECT(default_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(Semihost file system);
|
||||
MBED_HOSTTEST_START("MBED_A2");
|
||||
|
||||
pc.printf("Test the Stream class\n");
|
||||
|
||||
printf("connected: %s\n", (semihost_connected()) ? ("Yes") : ("No"));
|
||||
|
||||
char mac[16];
|
||||
mbed_mac_address(mac);
|
||||
printf("mac address: %02x,%02x,%02x,%02x,%02x,%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
|
||||
LocalFileSystem local("local");
|
||||
|
||||
FILE *f;
|
||||
char *str = TEST_STRING;
|
||||
char *buffer = (char *)malloc(sizeof(unsigned char) * strlen(TEST_STRING));
|
||||
int str_len = strlen(TEST_STRING);
|
||||
|
||||
// Write
|
||||
f = test_open("w");
|
||||
test_write(f, str, str_len);
|
||||
test_close(f);
|
||||
|
||||
// Read
|
||||
f = test_open("r");
|
||||
test_read(f, buffer, str_len);
|
||||
test_close(f);
|
||||
|
||||
// Check the two strings are equal
|
||||
MBED_HOSTTEST_RESULT((strncmp(buffer, str, str_len) == 0));
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/* mbed TextDisplay Display Library Base Class
|
||||
* Copyright (c) 2007-2009 sford
|
||||
* Released under the MIT License: http://mbed.org/license/mit
|
||||
*/
|
||||
|
||||
#include "TextDisplay.h"
|
||||
|
||||
TextDisplay::TextDisplay(const char *name) : Stream(name) {
|
||||
_row = 0;
|
||||
_column = 0;
|
||||
}
|
||||
|
||||
int TextDisplay::_putc(int value) {
|
||||
if(value == '\n') {
|
||||
_column = 0;
|
||||
_row++;
|
||||
if(_row >= rows()) {
|
||||
_row = 0;
|
||||
}
|
||||
} else {
|
||||
character(_column, _row, value);
|
||||
_column++;
|
||||
if(_column >= columns()) {
|
||||
_column = 0;
|
||||
_row++;
|
||||
if(_row >= rows()) {
|
||||
_row = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
// crude cls implementation, should generally be overwritten in derived class
|
||||
void TextDisplay::cls() {
|
||||
locate(0, 0);
|
||||
for(int i=0; i<columns()*rows(); i++) {
|
||||
putc(' ');
|
||||
}
|
||||
}
|
||||
|
||||
void TextDisplay::locate(int column, int row) {
|
||||
_column = column;
|
||||
_row = row;
|
||||
}
|
||||
|
||||
int TextDisplay::_getc() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
void TextDisplay::foreground(int colour) {
|
||||
_foreground = colour;
|
||||
}
|
||||
|
||||
void TextDisplay::background(int colour) {
|
||||
_background = colour;
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/* mbed TextDisplay Library Base Class
|
||||
* Copyright (c) 2007-2009 sford
|
||||
* Released under the MIT License: http://mbed.org/license/mit
|
||||
*
|
||||
* A common base class for Text displays
|
||||
* To port a new display, derive from this class and implement
|
||||
* the constructor (setup the display), character (put a character
|
||||
* at a location), rows and columns (number of rows/cols) functions.
|
||||
* Everything else (locate, printf, putc, cls) will come for free
|
||||
*
|
||||
* The model is the display will wrap at the right and bottom, so you can
|
||||
* keep writing and will always get valid characters. The location is
|
||||
* maintained internally to the class to make this easy
|
||||
*/
|
||||
|
||||
#ifndef MBED_TEXTDISPLAY_H
|
||||
#define MBED_TEXTDISPLAY_H
|
||||
|
||||
#include "mbed.h"
|
||||
|
||||
class TextDisplay : public Stream {
|
||||
public:
|
||||
|
||||
// functions needing implementation in derived implementation class
|
||||
TextDisplay(const char *name = NULL);
|
||||
virtual void character(int column, int row, int c) = 0;
|
||||
virtual int rows() = 0;
|
||||
virtual int columns() = 0;
|
||||
|
||||
// functions that come for free, but can be overwritten
|
||||
virtual void cls();
|
||||
virtual void locate(int column, int row);
|
||||
virtual void foreground(int colour);
|
||||
virtual void background(int colour);
|
||||
// putc (from Stream)
|
||||
// printf (from Stream)
|
||||
|
||||
protected:
|
||||
|
||||
virtual int _putc(int value);
|
||||
virtual int _getc();
|
||||
|
||||
// character location
|
||||
short _column;
|
||||
short _row;
|
||||
|
||||
// colours
|
||||
int _foreground;
|
||||
int _background;
|
||||
};
|
||||
|
||||
#endif
|
98
tool/mbed/mbed-sdk/libraries/tests/mbed/freopen/TextLCD.cpp
Normal file
98
tool/mbed/mbed-sdk/libraries/tests/mbed/freopen/TextLCD.cpp
Normal file
|
@ -0,0 +1,98 @@
|
|||
/* mbed TextLCD Library
|
||||
* Copyright (c) 2007-2009 sford
|
||||
* Released under the MIT License: http://mbed.org/license/mit
|
||||
*/
|
||||
|
||||
#include "TextLCD.h"
|
||||
#include "mbed.h"
|
||||
|
||||
/*
|
||||
* useful info found at http://www.a-netz.de/lcd.en.php
|
||||
*
|
||||
* Initialisation
|
||||
* ==============
|
||||
*
|
||||
* After attaching the supply voltage/after a reset, the display needs to be brought in to a defined state
|
||||
*
|
||||
* - wait approximately 15 ms so the display is ready to execute commands
|
||||
* - Execute the command 0x30 ("Display Settings") three times (wait 1,64ms after each command, the busy flag cannot be queried now).
|
||||
* - The display is in 8 bit mode, so if you have only connected 4 data pins you should only transmit the higher nibble of each command.
|
||||
* - If you want to use the 4 bit mode, now you can execute the command to switch over to this mode now.
|
||||
* - Execute the "clear display" command
|
||||
*
|
||||
* Timing
|
||||
* ======
|
||||
*
|
||||
* Nearly all commands transmitted to the display need 40us for execution.
|
||||
* Exceptions are the commands "Clear Display and Reset" and "Set Cursor to Start Position"
|
||||
* These commands need 1.64ms for execution. These timings are valid for all displays working with an
|
||||
* internal clock of 250kHz. But I do not know any displays that use other frequencies. Any time you
|
||||
* can use the busy flag to test if the display is ready to accept the next command.
|
||||
*
|
||||
* _e is kept high apart from calling clock
|
||||
* _rw is kept 0 (write) apart from actions that uyse it differently
|
||||
* _rs is set by the data/command writes
|
||||
*/
|
||||
|
||||
TextLCD::TextLCD(PinName rs, PinName rw, PinName e, PinName d0, PinName d1,
|
||||
PinName d2, PinName d3, const char *name) : TextDisplay(name), _rw(rw), _rs(rs),
|
||||
_e(e), _d(d0, d1, d2, d3) {
|
||||
|
||||
_rw = 0;
|
||||
_e = 1;
|
||||
_rs = 0; // command mode
|
||||
|
||||
// Should theoretically wait 15ms, but most things will be powered up pre-reset
|
||||
// so i'll disable that for the minute. If implemented, could wait 15ms post reset
|
||||
// instead
|
||||
// wait(0.015);
|
||||
|
||||
// send "Display Settings" 3 times (Only top nibble of 0x30 as we've got 4-bit bus)
|
||||
for(int i=0; i<3; i++) {
|
||||
writeByte(0x3);
|
||||
wait(0.00164); // this command takes 1.64ms, so wait for it
|
||||
}
|
||||
writeByte(0x2); // 4-bit mode
|
||||
|
||||
writeCommand(0x28); // Function set 001 BW N F - -
|
||||
writeCommand(0x0C);
|
||||
writeCommand(0x6); // Cursor Direction and Display Shift : 0000 01 CD S (CD 0-left, 1-right S(hift) 0-no, 1-yes
|
||||
cls();
|
||||
}
|
||||
|
||||
void TextLCD::character(int column, int row, int c) {
|
||||
int address = 0x80 + (row * 40) + column; // memory starts at 0x80, and is 40 chars long per row
|
||||
writeCommand(address);
|
||||
writeData(c);
|
||||
}
|
||||
|
||||
int TextLCD::columns() {
|
||||
return 16;
|
||||
}
|
||||
|
||||
int TextLCD::rows() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
void TextLCD::writeByte(int value) {
|
||||
_d = value >> 4;
|
||||
wait(0.000040f); // most instructions take 40us
|
||||
_e = 0;
|
||||
wait(0.000040f);
|
||||
_e = 1;
|
||||
_d = value >> 0;
|
||||
wait(0.000040f);
|
||||
_e = 0;
|
||||
wait(0.000040f); // most instructions take 40us
|
||||
_e = 1;
|
||||
}
|
||||
|
||||
void TextLCD::writeCommand(int command) {
|
||||
_rs = 0;
|
||||
writeByte(command);
|
||||
}
|
||||
|
||||
void TextLCD::writeData(int data) {
|
||||
_rs = 1;
|
||||
writeByte(data);
|
||||
}
|
30
tool/mbed/mbed-sdk/libraries/tests/mbed/freopen/TextLCD.h
Normal file
30
tool/mbed/mbed-sdk/libraries/tests/mbed/freopen/TextLCD.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
/* mbed TextLCD Library Base Class
|
||||
* Copyright (c) 2007-2009 sford
|
||||
* Released under the MIT License: http://mbed.org/license/mit
|
||||
*/
|
||||
#include "TextDisplay.h"
|
||||
|
||||
#ifndef MBED_TEXTLCD_H
|
||||
#define MBED_TEXTLCD_H
|
||||
|
||||
class TextLCD : public TextDisplay {
|
||||
public:
|
||||
|
||||
TextLCD(PinName rs, PinName rw, PinName e, PinName d0, PinName d1, PinName d2, PinName d3, const char *name = NULL);
|
||||
virtual void character(int column, int row, int c);
|
||||
virtual int rows();
|
||||
virtual int columns();
|
||||
|
||||
// locate, cls, putc, printf come from derived class
|
||||
|
||||
protected:
|
||||
|
||||
void writeByte(int value);
|
||||
void writeCommand(int command);
|
||||
void writeData(int data);
|
||||
|
||||
DigitalOut _rw, _rs, _e;
|
||||
BusOut _d;
|
||||
};
|
||||
|
||||
#endif
|
30
tool/mbed/mbed-sdk/libraries/tests/mbed/freopen/main.cpp
Normal file
30
tool/mbed/mbed-sdk/libraries/tests/mbed/freopen/main.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include "mbed.h"
|
||||
#include "TextLCD.h"
|
||||
|
||||
int main() {
|
||||
printf("printf to stdout\n");
|
||||
|
||||
// printf to specific peripherals
|
||||
Serial pc(USBTX, USBRX);
|
||||
pc.printf("Serial(USBTX, USBRX).printf\n");
|
||||
|
||||
TextLCD lcd(p14, p15, p16, p17, p18, p19, p20, "lcd"); // rs, rw, e, d0-d3, name
|
||||
lcd.printf("TextLCD.printf\n");
|
||||
|
||||
// change stdout to file
|
||||
LocalFileSystem local("local");
|
||||
freopen("/local/output.txt", "w", stdout);
|
||||
printf("printf redirected to LocalFileSystem\n");
|
||||
fclose(stdout);
|
||||
|
||||
// change stdout to LCD
|
||||
freopen("/lcd", "w", stdout);
|
||||
printf("printf redirected to TextLCD\n");
|
||||
fclose(stdout);
|
||||
|
||||
DigitalOut led(LED1);
|
||||
while (true) {
|
||||
led = !led;
|
||||
wait(1);
|
||||
}
|
||||
}
|
32
tool/mbed/mbed-sdk/libraries/tests/mbed/fs/main.cpp
Normal file
32
tool/mbed/mbed-sdk/libraries/tests/mbed/fs/main.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include "mbed.h"
|
||||
#include "rtos.h"
|
||||
#include "SDFileSystem.h"
|
||||
|
||||
#define FILE_LOC "/sd/test.txt"
|
||||
|
||||
Serial pc(USBTX, USBRX);
|
||||
Serial gps(p28, p27);
|
||||
Serial test(p9,p10);
|
||||
|
||||
SDFileSystem sd(p11, p12, p13, p14, "sd");
|
||||
|
||||
DigitalOut myled(LED1);
|
||||
DigitalOut sdled(LED2);
|
||||
|
||||
void sd_thread(void const *argument) {
|
||||
while (true) {
|
||||
sdled = !sdled;
|
||||
FILE *fp = NULL;
|
||||
fp = fopen(FILE_LOC, "w");
|
||||
if( fp != NULL ) fclose(fp);
|
||||
Thread::wait(1000);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
Thread sdTask(sd_thread, NULL, osPriorityNormal, DEFAULT_STACK_SIZE * 2.25);
|
||||
while (true) {
|
||||
myled = !myled;
|
||||
Thread::wait(1000);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
#include "test_env.h"
|
||||
|
||||
static char *initial_stack_p;
|
||||
static char *initial_heap_p;
|
||||
|
||||
static char line[256];
|
||||
static unsigned int iterations = 0;
|
||||
|
||||
void report_iterations(void) {
|
||||
unsigned int tot = (0x100 * iterations)*2;
|
||||
printf("\nAllocated (%d)Kb in (%u) iterations\n", tot/1024, iterations);
|
||||
#if !defined(TOOLCHAIN_GCC_CR)
|
||||
// EA: This causes a crash when compiling with GCC_CR???
|
||||
printf("%.2f\n", ((float)(tot)/(float)(initial_stack_p - initial_heap_p))*100.);
|
||||
#endif
|
||||
#ifdef TOOLCHAIN_ARM
|
||||
#ifndef __MICROLIB
|
||||
__heapvalid((__heapprt) fprintf, stdout, 1);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void stack_test(char *latest_heap_pointer) {
|
||||
char stack_line[256];
|
||||
iterations++;
|
||||
|
||||
sprintf(stack_line, "\nstack pointer: %p", &stack_line[255]);
|
||||
puts(stack_line);
|
||||
|
||||
char *heap_pointer = (char*)malloc(0x100);
|
||||
|
||||
if (heap_pointer == NULL) {
|
||||
int diff = (&stack_line[255] - latest_heap_pointer);
|
||||
if (diff > 0x200) {
|
||||
sprintf(stack_line, "\n[WARNING] Malloc failed to allocate memory too soon. There are (0x%x) free bytes", diff);
|
||||
report_iterations();
|
||||
puts(stack_line);
|
||||
} else {
|
||||
puts("\n[SUCCESS] Stack/Heap collision detected");
|
||||
report_iterations();
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
heap_pointer += 0x100;
|
||||
sprintf(line, "heap pointer: %p", heap_pointer);
|
||||
puts(line);
|
||||
}
|
||||
|
||||
if ((&stack_line[255]) > heap_pointer) {
|
||||
stack_test(heap_pointer);
|
||||
} else {
|
||||
puts("\n[WARNING] The Stack/Heap collision was not detected");
|
||||
report_iterations();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main (void) {
|
||||
char c;
|
||||
initial_stack_p = &c;
|
||||
|
||||
initial_heap_p = (char*)malloc(1);
|
||||
if (initial_heap_p == NULL) {
|
||||
printf("Unable to malloc a single byte\n");
|
||||
notify_completion(false);
|
||||
}
|
||||
|
||||
printf("Initial stack/heap geometry:\n");
|
||||
printf(" stack pointer:V %p\n", initial_stack_p);
|
||||
printf(" heap pointer :^ %p\n", initial_heap_p);
|
||||
|
||||
initial_heap_p++;
|
||||
stack_test(initial_heap_p);
|
||||
|
||||
notify_completion(true);
|
||||
}
|
13
tool/mbed/mbed-sdk/libraries/tests/mbed/hello/main.cpp
Normal file
13
tool/mbed/mbed-sdk/libraries/tests/mbed/hello/main.cpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include "test_env.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
MBED_HOSTTEST_TIMEOUT(5);
|
||||
MBED_HOSTTEST_SELECT(hello_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(Hello World);
|
||||
MBED_HOSTTEST_START("MBED_10");
|
||||
|
||||
printf("Hello World\r\n");
|
||||
|
||||
while(1);
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
#include "mbed.h"
|
||||
#include "MMA8451Q.h"
|
||||
#include "test_env.h"
|
||||
|
||||
#ifdef TARGET_KL05Z
|
||||
#define SDA PTB4
|
||||
#define SCL PTB3
|
||||
|
||||
#elif TARGET_K20D50M
|
||||
#define SDA PTB1
|
||||
#define SCL PTB0
|
||||
|
||||
#else
|
||||
#define SDA PTE25
|
||||
#define SCL PTE24
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
const int MMA8451_I2C_ADDRESS = 0x1D << 1; // I2C bus address
|
||||
const float MMA8451_DIGITAL_SENSITIVITY = 4096.0; // Counts/g
|
||||
}
|
||||
|
||||
float calc_3d_vector_len(float x, float y, float z) {
|
||||
return sqrt(x*x + y*y + z*z);
|
||||
}
|
||||
|
||||
#define TEST_ITERATIONS 25
|
||||
#define TEST_ITERATIONS_SKIP 5
|
||||
#define MEASURE_DEVIATION_TOLERANCE 0.025 // 2.5%
|
||||
|
||||
int main(void) {
|
||||
MBED_HOSTTEST_TIMEOUT(15);
|
||||
MBED_HOSTTEST_SELECT(default_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(MMA8451Q accelerometer);
|
||||
MBED_HOSTTEST_START("KL25Z_5");
|
||||
|
||||
DigitalOut led(LED_GREEN);
|
||||
MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
|
||||
bool result = true;
|
||||
printf("WHO AM I: 0x%2X\r\n\n", acc.getWhoAmI());
|
||||
|
||||
for (int i = 0; i < TEST_ITERATIONS; i++) {
|
||||
if (i < TEST_ITERATIONS_SKIP) {
|
||||
// Skip first 5 measurements
|
||||
continue;
|
||||
}
|
||||
const float g_vect_len = calc_3d_vector_len(acc.getAccX(), acc.getAccY(), acc.getAccZ()) / MMA8451_DIGITAL_SENSITIVITY;
|
||||
const float deviation = fabs(g_vect_len - 1.0);
|
||||
const char *succes_str = deviation <= MEASURE_DEVIATION_TOLERANCE ? "[OK]" : "[FAIL]";
|
||||
result = result && (deviation <= MEASURE_DEVIATION_TOLERANCE);
|
||||
printf("X:% 6d Y:% 6d Z:% 5d GF:%0.3fg, dev:%0.3f ... %s\r\n", acc.getAccX(), acc.getAccY(), acc.getAccZ(), g_vect_len, deviation, succes_str);
|
||||
wait(0.5);
|
||||
led = !led;
|
||||
}
|
||||
MBED_HOSTTEST_RESULT(result);
|
||||
}
|
15
tool/mbed/mbed-sdk/libraries/tests/mbed/i2c_SRF08/main.cpp
Normal file
15
tool/mbed/mbed-sdk/libraries/tests/mbed/i2c_SRF08/main.cpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include "mbed.h"
|
||||
#include "SRF08.h"
|
||||
|
||||
DigitalOut led(LED1);
|
||||
|
||||
SRF08 srf08(p28, p27, 0xE0); // SDA, SCL pin and I2C address
|
||||
|
||||
int main() {
|
||||
printf("started\n");
|
||||
while (1) {
|
||||
printf("Measured range : %.2f cm\n",srf08.read());
|
||||
wait(1.0);
|
||||
led = !led;
|
||||
}
|
||||
}
|
51
tool/mbed/mbed-sdk/libraries/tests/mbed/i2c_TMP102/main.cpp
Normal file
51
tool/mbed/mbed-sdk/libraries/tests/mbed/i2c_TMP102/main.cpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
#include "test_env.h"
|
||||
#include "TMP102.h"
|
||||
|
||||
#if defined(TARGET_KL25Z)
|
||||
TMP102 temperature(PTC9, PTC8, 0x90);
|
||||
|
||||
#elif defined(TARGET_LPC812)
|
||||
TMP102 temperature(D10, D11, 0x90);
|
||||
|
||||
#elif defined(TARGET_LPC4088)
|
||||
TMP102 temperature(p9, p10, 0x90);
|
||||
|
||||
#elif defined(TARGET_LPC2368)
|
||||
TMP102 temperature(p28, p27, 0x90);
|
||||
|
||||
#elif defined(TARGET_NUCLEO_F030R8) || \
|
||||
defined(TARGET_NUCLEO_F070RB) || \
|
||||
defined(TARGET_NUCLEO_F072RB) || \
|
||||
defined(TARGET_NUCLEO_F091RC) || \
|
||||
defined(TARGET_NUCLEO_F103RB) || \
|
||||
defined(TARGET_NUCLEO_F302R8) || \
|
||||
defined(TARGET_NUCLEO_F303RE) || \
|
||||
defined(TARGET_NUCLEO_F334R8) || \
|
||||
defined(TARGET_NUCLEO_F401RE) || \
|
||||
defined(TARGET_NUCLEO_F411RE) || \
|
||||
defined(TARGET_NUCLEO_L053R8) || \
|
||||
defined(TARGET_NUCLEO_L073RZ) || \
|
||||
defined(TARGET_NUCLEO_L152RE) || \
|
||||
defined(TARGET_LPC824) || \
|
||||
defined(TARGET_FF_ARDUINO) || \
|
||||
defined(TARGET_MAXWSNENV)
|
||||
TMP102 temperature(I2C_SDA, I2C_SCL, 0x90);
|
||||
|
||||
#else
|
||||
TMP102 temperature(p28, p27, 0x90);
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
MBED_HOSTTEST_TIMEOUT(10);
|
||||
MBED_HOSTTEST_SELECT(default_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(DigitalIn DigitalOut);
|
||||
MBED_HOSTTEST_START("MBED_A4");
|
||||
|
||||
float t = temperature.read();
|
||||
|
||||
printf("TMP102: Temperature: %f\n\r", t);
|
||||
// In our test environment (ARM office) we should get a temperature within
|
||||
// the range ]15, 30[C
|
||||
bool result = (t > 15.0) && (t < 30.0);
|
||||
MBED_HOSTTEST_RESULT(result);
|
||||
}
|
155
tool/mbed/mbed-sdk/libraries/tests/mbed/i2c_eeprom/main.cpp
Normal file
155
tool/mbed/mbed-sdk/libraries/tests/mbed/i2c_eeprom/main.cpp
Normal file
|
@ -0,0 +1,155 @@
|
|||
#include "test_env.h"
|
||||
|
||||
/******************************************************************************
|
||||
* This will test an I2C EEPROM connected to mbed by writing a predefined byte at
|
||||
* address 0 and then reading it back and comparing it with the known byte value a
|
||||
* number of times. This test was written specifically for reproducing the bug
|
||||
* reported here:
|
||||
*
|
||||
* https://mbed.org/forum/bugs-suggestions/topic/4128/
|
||||
*
|
||||
* Test configuration:
|
||||
*
|
||||
* set 'ntests' to the number of iterations
|
||||
* set 'i2c_speed_hz' to the desired speed of the I2C interface
|
||||
* set 'i2c_delay_us' to the delay that will be inserted between 'write' and
|
||||
* 'read' I2C operations (https://mbed.org/users/mbed_official/code/mbed/issues/1
|
||||
* for more details). '0' disables the delay.
|
||||
* define I2C_EEPROM_VERBOSE to get verbose output
|
||||
*
|
||||
* The test ran with a 24LC256 external EEPROM memory, but any I2C EEPROM memory
|
||||
* that uses two byte addresses should work.
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(TARGET_KL25Z)
|
||||
I2C i2c(PTC9, PTC8);
|
||||
|
||||
#elif defined(TARGET_KL46Z)
|
||||
I2C i2c(PTC9, PTC8);
|
||||
|
||||
#elif defined(TARGET_K64F)
|
||||
I2C i2c(PTE25, PTE24);
|
||||
|
||||
#elif defined(TARGET_K22F)
|
||||
I2C i2c(PTE0, PTE1);
|
||||
|
||||
#elif defined(TARGET_K20D50M)
|
||||
I2C i2c(PTB3, PTB2);
|
||||
|
||||
#elif defined(TARGET_LPC812)
|
||||
I2C i2c(P0_10, P0_11);
|
||||
|
||||
#elif defined(TARGET_LPC1549)
|
||||
I2C i2c(P0_23, P0_22);
|
||||
|
||||
#elif defined(TARGET_LPC11U68)
|
||||
I2C i2c(SDA, SCL);
|
||||
|
||||
#elif defined(TARGET_DELTA_DFCM_NNN40)
|
||||
I2C i2c(I2C_SDA0, I2C_SCL0);
|
||||
|
||||
#elif defined(TARGET_NUCLEO_F030R8) || \
|
||||
defined(TARGET_NUCLEO_F070RB) || \
|
||||
defined(TARGET_NUCLEO_F072RB) || \
|
||||
defined(TARGET_NUCLEO_F091RC) || \
|
||||
defined(TARGET_NUCLEO_F103RB) || \
|
||||
defined(TARGET_NUCLEO_F302R8) || \
|
||||
defined(TARGET_NUCLEO_F303RE) || \
|
||||
defined(TARGET_NUCLEO_F334R8) || \
|
||||
defined(TARGET_NUCLEO_F401RE) || \
|
||||
defined(TARGET_NUCLEO_F411RE) || \
|
||||
defined(TARGET_NUCLEO_L053R8) || \
|
||||
defined(TARGET_NUCLEO_L073RZ) || \
|
||||
defined(TARGET_NUCLEO_L152RE) || \
|
||||
defined(TARGET_FF_ARDUINO)
|
||||
I2C i2c(I2C_SDA, I2C_SCL);
|
||||
|
||||
#else
|
||||
I2C i2c(p28, p27);
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
const int ntests = 10000;
|
||||
const int i2c_freq_hz = 400000;
|
||||
const int i2c_delay_us = 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
MBED_HOSTTEST_TIMEOUT(15);
|
||||
MBED_HOSTTEST_SELECT(default_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(I2C EEPROM read write test);
|
||||
MBED_HOSTTEST_START("MBED_A19");
|
||||
|
||||
const int EEPROM_MEM_ADDR = 0xA0;
|
||||
const char MARK = 0x66;
|
||||
int fw = 0;
|
||||
int fr = 0;
|
||||
int fc = 0;
|
||||
int i2c_stat = 0;
|
||||
bool result = true;
|
||||
|
||||
i2c.frequency(i2c_freq_hz);
|
||||
printf("I2C: I2C Frequency: %d Hz\r\n", i2c_freq_hz);
|
||||
|
||||
printf("I2C: Write 0x%2X at address 0x0000 test ... \r\n", MARK);
|
||||
// Data write
|
||||
{
|
||||
char data[] = { 0, 0, MARK };
|
||||
if ((i2c_stat = i2c.write(EEPROM_MEM_ADDR, data, sizeof(data))) != 0) {
|
||||
printf("Unable to write data to EEPROM (i2c_stat = 0x%02X), aborting\r\n", i2c_stat);
|
||||
notify_completion(false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ACK polling (assumes write will be successful eventually)
|
||||
while (i2c.write(EEPROM_MEM_ADDR, data, 0) != 0)
|
||||
;
|
||||
}
|
||||
|
||||
printf("I2C: Read data from address 0x0000 test ... \r\n");
|
||||
// Data read (actual test)
|
||||
for (int i = 0; i < ntests; i++) {
|
||||
// Write data to EEPROM memory
|
||||
{
|
||||
char data[] = { 0, 0 };
|
||||
if ((i2c_stat = i2c.write(EEPROM_MEM_ADDR, data, 2, true)) != 0) {
|
||||
printf("Test %d failed at write, i2c_stat is 0x%02X\r\n", i, i2c_stat);
|
||||
fw++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// us delay if specified
|
||||
if (i2c_delay_us != 0)
|
||||
wait_us(i2c_delay_us);
|
||||
|
||||
// Read data
|
||||
{
|
||||
char data[1] = { 0 };
|
||||
if ((i2c_stat = i2c.read(EEPROM_MEM_ADDR, data, 1)) != 0) {
|
||||
printf("Test %d failed at read, i2c_stat is 0x%02X\r\n", i, i2c_stat);
|
||||
fr++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (data[0] != MARK) {
|
||||
printf("Test %d failed at data match\r\n", i);
|
||||
fc++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = (fw + fr + fc == 0);
|
||||
printf("EEPROM: Test result ... [%s]\r\n", result ? "OK" : "FAIL");
|
||||
|
||||
if (!result) {
|
||||
printf("Test Statistics:\r\n");
|
||||
printf("\tTotal tests: %d\r\n", ntests);
|
||||
printf("\tFailed at write: %d\r\n", fw);
|
||||
printf("\tFailed at read: %d\r\n", fr);
|
||||
printf("\tData mismatch: %d\r\n", fc);
|
||||
printf("\tTotal failures: %d\r\n", fw + fr + fc);
|
||||
}
|
||||
|
||||
MBED_HOSTTEST_RESULT(result);
|
||||
}
|
147
tool/mbed/mbed-sdk/libraries/tests/mbed/i2c_eeprom_line/main.cpp
Normal file
147
tool/mbed/mbed-sdk/libraries/tests/mbed/i2c_eeprom_line/main.cpp
Normal file
|
@ -0,0 +1,147 @@
|
|||
#include "test_env.h"
|
||||
|
||||
/******************************************************************************
|
||||
* This will test an I2C EEPROM connected to mbed by writing a predefined byte at
|
||||
* address 0 and then reading it back and comparing it with the known byte value a
|
||||
* number of times. This test was written specifically for reproducing the bug
|
||||
* reported here:
|
||||
*
|
||||
* https://mbed.org/forum/bugs-suggestions/topic/4128/
|
||||
*
|
||||
* Test configuration:
|
||||
*
|
||||
* set 'ntests' to the number of iterations
|
||||
* set 'i2c_speed_hz' to the desired speed of the I2C interface
|
||||
* set 'i2c_delay_us' to the delay that will be inserted between 'write' and
|
||||
* 'read' I2C operations (https://mbed.org/users/mbed_official/code/mbed/issues/1
|
||||
* for more details). '0' disables the delay.
|
||||
* define I2C_EEPROM_VERBOSE to get verbose output
|
||||
*
|
||||
* The test ran with a 24LC256 external EEPROM memory, but any I2C EEPROM memory
|
||||
* that uses two byte addresses should work.
|
||||
******************************************************************************/
|
||||
|
||||
// Test configuration block
|
||||
namespace {
|
||||
const int ntests = 1000;
|
||||
const int i2c_freq_hz = 400000;
|
||||
const int i2c_delay_us = 0;
|
||||
// const int EEPROM_24LC256_SIZE = (256 * 1024 / 8); // 256 kbit memory
|
||||
}
|
||||
|
||||
// End of test configuration block
|
||||
|
||||
#if defined(TARGET_KL25Z)
|
||||
I2C i2c(PTC9, PTC8);
|
||||
|
||||
#elif defined(TARGET_KL46Z)
|
||||
I2C i2c(PTC9, PTC8);
|
||||
|
||||
#elif defined(TARGET_K64F)
|
||||
I2C i2c(PTE25, PTE24);
|
||||
|
||||
#elif defined(TARGET_K22F)
|
||||
I2C i2c(PTE0, PTE1);
|
||||
|
||||
#elif defined(TARGET_K20D50M)
|
||||
I2C i2c(PTB3, PTB2);
|
||||
|
||||
#elif defined(TARGET_LPC812)
|
||||
I2C i2c(P0_10, P0_11);
|
||||
|
||||
#elif defined(TARGET_LPC1549)
|
||||
I2C i2c(P0_23, P0_22);
|
||||
|
||||
#elif defined(TARGET_LPC11U68)
|
||||
I2C i2c(SDA, SCL);
|
||||
|
||||
#elif defined(TARGET_DELTA_DFCM_NNN40)
|
||||
I2C i2c(I2C_SDA0, I2C_SCL0);
|
||||
|
||||
#elif defined(TARGET_NUCLEO_F030R8) || \
|
||||
defined(TARGET_NUCLEO_F070RB) || \
|
||||
defined(TARGET_NUCLEO_F072RB) || \
|
||||
defined(TARGET_NUCLEO_F091RC) || \
|
||||
defined(TARGET_NUCLEO_F103RB) || \
|
||||
defined(TARGET_NUCLEO_F302R8) || \
|
||||
defined(TARGET_NUCLEO_F303RE) || \
|
||||
defined(TARGET_NUCLEO_F334R8) || \
|
||||
defined(TARGET_NUCLEO_F401RE) || \
|
||||
defined(TARGET_NUCLEO_F411RE) || \
|
||||
defined(TARGET_NUCLEO_L053R8) || \
|
||||
defined(TARGET_NUCLEO_L073RZ) || \
|
||||
defined(TARGET_NUCLEO_L152RE) || \
|
||||
defined(TARGET_FF_ARDUINO)
|
||||
I2C i2c(I2C_SDA, I2C_SCL);
|
||||
|
||||
#else
|
||||
I2C i2c(p28, p27);
|
||||
#endif
|
||||
|
||||
#define PATTERN_MASK 0x66, ~0x66, 0x00, 0xFF, 0xA5, 0x5A, 0xF0, 0x0F
|
||||
|
||||
int main() {
|
||||
MBED_HOSTTEST_TIMEOUT(15);
|
||||
MBED_HOSTTEST_SELECT(default_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(I2C EEPROM line read write test);
|
||||
MBED_HOSTTEST_START("MBED_A25");
|
||||
|
||||
const int EEPROM_MEM_ADDR = 0xA0;
|
||||
bool result = true;
|
||||
|
||||
i2c.frequency(i2c_freq_hz);
|
||||
printf("I2C: I2C Frequency: %d Hz\r\n", i2c_freq_hz);
|
||||
|
||||
printf("I2C: Lines pattern write test ... ");
|
||||
int write_errors = 0;
|
||||
for (int i = 0; i < ntests; i++) {
|
||||
char data[] = { 0 /*MSB*/, 0 /*LSB*/, PATTERN_MASK };
|
||||
const int addr = i * 8; // 8 bytes of data in data array
|
||||
data[0] = ((0xFF00 & addr) >> 8) & 0x00FF;
|
||||
data[1] = (addr & 0x00FF);
|
||||
|
||||
if (i2c.write(EEPROM_MEM_ADDR, data, sizeof(data)) != 0) {
|
||||
write_errors++;
|
||||
}
|
||||
|
||||
while (i2c.write(EEPROM_MEM_ADDR, NULL, 0)) ; // wait to complete
|
||||
|
||||
// us delay if specified
|
||||
if (i2c_delay_us != 0) {
|
||||
wait_us(i2c_delay_us);
|
||||
}
|
||||
}
|
||||
|
||||
printf("[%s]\r\n", write_errors ? "FAIL" : "OK");
|
||||
printf("I2C: Write errors: %d ... [%s]\r\n", write_errors, write_errors ? "FAIL" : "OK");
|
||||
|
||||
printf("I2C: Lines pattern read test ... ");
|
||||
int read_errors = 0;
|
||||
int pattern_errors = 0;
|
||||
for (int i = 0; i < ntests; i++) {
|
||||
char data[8] = { 0 }; // General puspose buffer
|
||||
const int addr = i * 8; // 8 bytes of data in data array
|
||||
data[0] = ((0xFF00 & addr) >> 8) & 0x00FF;
|
||||
data[1] = (addr & 0x00FF);
|
||||
|
||||
// Set address for read
|
||||
if (i2c.write(EEPROM_MEM_ADDR, data, 2, true) != 0) {
|
||||
}
|
||||
|
||||
if (i2c.read(EEPROM_MEM_ADDR, data, 8) != 0) {
|
||||
read_errors++;
|
||||
}
|
||||
|
||||
static char pattern[] = { PATTERN_MASK };
|
||||
if (memcmp(pattern, data, sizeof(data))) {
|
||||
pattern_errors++;
|
||||
}
|
||||
}
|
||||
|
||||
printf("[%s]\r\n", read_errors ? "FAIL" : "OK");
|
||||
printf("I2C: Read errors: %d/%d ... [%s]\r\n", read_errors, ntests, read_errors ? "FAIL" : "OK");
|
||||
printf("EEPROM: Pattern match errors: %d/%d ... [%s]\r\n", pattern_errors, ntests, pattern_errors ? "FAIL" : "OK");
|
||||
|
||||
result = write_errors == 0 && read_errors == 0;
|
||||
MBED_HOSTTEST_RESULT(result);
|
||||
}
|
45
tool/mbed/mbed-sdk/libraries/tests/mbed/i2c_master/main.cpp
Normal file
45
tool/mbed/mbed-sdk/libraries/tests/mbed/i2c_master/main.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include "mbed.h"
|
||||
#include "test_env.h"
|
||||
|
||||
#define SIZE (10)
|
||||
#define ADDR (0x90)
|
||||
|
||||
#if defined(TARGET_KL25Z)
|
||||
I2C i2c(PTE0, PTE1);
|
||||
#elif defined(TARGET_nRF51822)
|
||||
I2C i2c(p22,p20);
|
||||
#elif defined(TARGET_FF_ARDUINO) || defined(TARGET_MAXWSNENV)
|
||||
I2C i2c(I2C_SDA, I2C_SCL);
|
||||
#else
|
||||
I2C i2c(p28, p27);
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
bool success = true;
|
||||
char buf[] = {3, 2, 1, 4, 5, 6, 7, 8, 9, 10};
|
||||
char res[SIZE];
|
||||
|
||||
i2c.write(ADDR, buf, SIZE);
|
||||
i2c.read(ADDR, res, SIZE);
|
||||
|
||||
// here should be buf[all]++
|
||||
i2c.write(ADDR, res, SIZE);
|
||||
i2c.read(ADDR, res, SIZE);
|
||||
|
||||
// here should be buf[all]+=2
|
||||
i2c.write(ADDR, res, SIZE);
|
||||
i2c.write(ADDR, res, SIZE);
|
||||
|
||||
// here should be buf[all]+=3
|
||||
i2c.read(ADDR, res, SIZE);
|
||||
i2c.read(ADDR, res, SIZE);
|
||||
|
||||
for(int i = 0; i < SIZE; i++) {
|
||||
if (res[i] != (buf[i] + 3)) {
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
notify_completion(success);
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
#include "mbed.h"
|
||||
#include "test_env.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define ADDR (0xA0)
|
||||
#define FREQ 100000
|
||||
|
||||
// ********************************************************
|
||||
// This tests data transfer between two I2C interfaces on
|
||||
// the same chip, one configured as master, the other as
|
||||
// slave. Works on the LPC1768 mbed.
|
||||
//
|
||||
// Wiring:
|
||||
// p28 <-> p9
|
||||
// p27 <-> p10
|
||||
// pull-up resistors on both lines
|
||||
// ********************************************************
|
||||
|
||||
I2CSlave slave(p9, p10);
|
||||
I2C master(p28, p27);
|
||||
|
||||
int main()
|
||||
{
|
||||
char sent = 'T', received;
|
||||
|
||||
master.frequency(FREQ);
|
||||
slave.frequency(FREQ);
|
||||
slave.address(ADDR);
|
||||
|
||||
// First transfer: master to slave
|
||||
master.start();
|
||||
master.write(ADDR);
|
||||
master.write(sent);
|
||||
if(slave.receive() != I2CSlave::WriteAddressed)
|
||||
{
|
||||
notify_completion(false);
|
||||
return 1;
|
||||
}
|
||||
slave.read(&received, 1);
|
||||
if(sent != received)
|
||||
{
|
||||
notify_completion(false);
|
||||
return 1;
|
||||
}
|
||||
master.stop();
|
||||
|
||||
// Second transfer: slave to master
|
||||
master.start();
|
||||
master.write(ADDR | 1);
|
||||
if(slave.receive() != I2CSlave::ReadAddressed)
|
||||
{
|
||||
notify_completion(false);
|
||||
return 1;
|
||||
}
|
||||
slave.write(received);
|
||||
received = master.read(0);
|
||||
slave.stop();
|
||||
notify_completion(received == sent);
|
||||
}
|
||||
|
26
tool/mbed/mbed-sdk/libraries/tests/mbed/i2c_mma7660/main.cpp
Normal file
26
tool/mbed/mbed-sdk/libraries/tests/mbed/i2c_mma7660/main.cpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include "mbed.h"
|
||||
#include "test_env.h"
|
||||
#include "MMA7660.h"
|
||||
|
||||
#if defined(TARGET_FF_ARDUINO)
|
||||
MMA7660 MMA(I2C_SDA, I2C_SCL);
|
||||
#else
|
||||
MMA7660 MMA(p28, p27);
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
MBED_HOSTTEST_TIMEOUT(15);
|
||||
MBED_HOSTTEST_SELECT(default_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(I2C MMA7660 accelerometer);
|
||||
MBED_HOSTTEST_START("MBED_A13");
|
||||
|
||||
if (!MMA.testConnection())
|
||||
MBED_HOSTTEST_RESULT(false);
|
||||
|
||||
for(int i = 0; i < 5; i++) {
|
||||
printf("x: %f, y: %f, z: %f\r\n", MMA.x(), MMA.y(), MMA.z());
|
||||
wait(0.2);
|
||||
}
|
||||
|
||||
MBED_HOSTTEST_RESULT(true);
|
||||
}
|
36
tool/mbed/mbed-sdk/libraries/tests/mbed/i2c_slave/main.cpp
Normal file
36
tool/mbed/mbed-sdk/libraries/tests/mbed/i2c_slave/main.cpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
#include "mbed.h"
|
||||
#include "test_env.h"
|
||||
|
||||
#define SIZE (10)
|
||||
#define ADDR (0x90)
|
||||
|
||||
#if defined(TARGET_KL25Z)
|
||||
I2CSlave slave(PTE0, PTE1);
|
||||
#elif defined(TARGET_LPC4088)
|
||||
I2CSlave slave(p9, p10);
|
||||
#else
|
||||
I2CSlave slave(p28, p27);
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
char buf[SIZE];
|
||||
|
||||
slave.address(ADDR);
|
||||
|
||||
while (1) {
|
||||
int i = slave.receive();
|
||||
switch (i) {
|
||||
case I2CSlave::ReadAddressed:
|
||||
slave.write(buf, SIZE);
|
||||
for(int i = 0; i < SIZE; i++){
|
||||
}
|
||||
break;
|
||||
case I2CSlave::WriteAddressed:
|
||||
slave.read(buf, SIZE);
|
||||
for(int i = 0; i < SIZE; i++){
|
||||
buf[i]++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
#include "mbed.h"
|
||||
#include "InterruptManager.h"
|
||||
#include "cmsis.h"
|
||||
#include "test_env.h"
|
||||
|
||||
#if defined(TARGET_LPC1768) || defined(TARGET_LPC4088)
|
||||
#define TIMER_IRQ TIMER3_IRQn
|
||||
#elif defined(TARGET_LPC11U24) || defined(TARGET_LPC1114)
|
||||
#define TIMER_IRQ TIMER_32_1_IRQn
|
||||
#elif defined(TARGET_KL25Z)
|
||||
#define TIMER_IRQ LPTimer_IRQn
|
||||
#elif defined(TARGET_LPC2368)
|
||||
#define TIMER_IRQ TIMER3_IRQn
|
||||
#else
|
||||
#error This test can't run on this target.
|
||||
#endif
|
||||
|
||||
Serial pc(USBTX, USBRX);
|
||||
|
||||
Ticker flipper_1;
|
||||
DigitalOut led1(LED1);
|
||||
int led1_state = 0;
|
||||
void flip_1() {
|
||||
if (led1_state) {
|
||||
led1 = 0; led1_state = 0;
|
||||
} else {
|
||||
led1 = 1; led1_state = 1;
|
||||
}
|
||||
}
|
||||
|
||||
class Sender {
|
||||
public:
|
||||
Sender(Serial&s, char c): _s(s), _c(c) {}
|
||||
void send() { _s.putc(_c); }
|
||||
private:
|
||||
Serial& _s;
|
||||
char _c;
|
||||
};
|
||||
Ticker flipper_2;
|
||||
Sender s1(pc, '1');
|
||||
Sender s2(pc, '2');
|
||||
|
||||
#if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC4088) || defined(TARGET_LPC2368) || defined(TARGET_LPC1114)
|
||||
# define LED_NAME LED2
|
||||
#elif defined(TARGET_KL05Z)
|
||||
# define LED_NAME LED2
|
||||
#else
|
||||
# define LED_NAME PTE31
|
||||
#endif
|
||||
|
||||
DigitalOut led2(LED_NAME);
|
||||
int led2_state = 0;
|
||||
void flip_2() {
|
||||
if (led2_state) {
|
||||
led2 = 0; led2_state = 0;
|
||||
} else {
|
||||
led2 = 1; led2_state = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void testme(void) {
|
||||
pc.putc('!');
|
||||
}
|
||||
|
||||
class Counter {
|
||||
public:
|
||||
void inc(void) {
|
||||
count ++;
|
||||
}
|
||||
int get_count(void) const {
|
||||
return count;
|
||||
}
|
||||
private:
|
||||
static int count;
|
||||
};
|
||||
|
||||
int Counter::count = 0;
|
||||
|
||||
int main() {
|
||||
led1 = 0;
|
||||
led2 = 0;
|
||||
uint32_t initial_handler, final_handler;
|
||||
Counter c;
|
||||
|
||||
// Test chaining inside Serial class
|
||||
flipper_1.attach(&flip_1, 1.0); // the address of the function to be attached (flip) and the interval (1 second)
|
||||
flipper_2.attach(&flip_2, 2.0); // the address of the function to be attached (flip) and the interval (2 seconds)
|
||||
|
||||
// Test global chaining (InterruptManager)
|
||||
printf("Handler initially: %08X\n", initial_handler = NVIC_GetVector(TIMER_IRQ));
|
||||
InterruptManager *pManager = InterruptManager::get();
|
||||
pFunctionPointer_t ptm = pManager->add_handler(testme, TIMER_IRQ);
|
||||
pFunctionPointer_t pinc = pManager->add_handler_front(&c, &Counter::inc, TIMER_IRQ);
|
||||
printf("Handler after calling InterruptManager: %08X\n", NVIC_GetVector(TIMER_IRQ));
|
||||
|
||||
wait(4.0);
|
||||
|
||||
if (!pManager->remove_handler(ptm, TIMER_IRQ) || !pManager->remove_handler(pinc, TIMER_IRQ)) {
|
||||
printf ("remove handler failed.\n");
|
||||
notify_completion(false);
|
||||
}
|
||||
printf("Interrupt handler calls: %d\n", c.get_count());
|
||||
printf("Handler after removing previously added functions: %08X\n", final_handler = NVIC_GetVector(TIMER_IRQ));
|
||||
|
||||
if (initial_handler != final_handler) {
|
||||
printf( "InteruptManager test failed.\n");
|
||||
notify_completion(false);
|
||||
}
|
||||
|
||||
while(1);
|
||||
}
|
146
tool/mbed/mbed-sdk/libraries/tests/mbed/interruptin/main.cpp
Normal file
146
tool/mbed/mbed-sdk/libraries/tests/mbed/interruptin/main.cpp
Normal file
|
@ -0,0 +1,146 @@
|
|||
#include "test_env.h"
|
||||
|
||||
DigitalOut myled(LED1);
|
||||
DigitalOut led2(LED2);
|
||||
|
||||
volatile int checks = 0;
|
||||
void in_handler() {
|
||||
checks++;
|
||||
led2 = !led2;
|
||||
}
|
||||
|
||||
#if defined(TARGET_KL25Z)
|
||||
#define PIN_OUT PTC6
|
||||
#define PIN_IN PTA5
|
||||
|
||||
#elif defined(TARGET_KL05Z)
|
||||
#define PIN_OUT PTB11
|
||||
#define PIN_IN PTB1
|
||||
|
||||
#elif defined(TARGET_LPC812)
|
||||
#define PIN_OUT D10
|
||||
#define PIN_IN D11
|
||||
|
||||
#elif defined(TARGET_LPC1114)
|
||||
#define PIN_OUT dp1
|
||||
#define PIN_IN dp2
|
||||
|
||||
#elif defined(TARGET_LPC1549)
|
||||
// TARGET_FF_ARDUINO cannot be used, because D0 is used as USBRX (USB serial
|
||||
// port pin), D1 is used as USBTX
|
||||
#define PIN_OUT D2
|
||||
#define PIN_IN D7
|
||||
|
||||
#elif defined(TARGET_LPC4088)
|
||||
#define PIN_IN (p11)
|
||||
#define PIN_OUT (p12)
|
||||
|
||||
#elif defined(TARGET_NUCLEO_F030R8) || \
|
||||
defined(TARGET_NUCLEO_F070RB) || \
|
||||
defined(TARGET_NUCLEO_F072RB) || \
|
||||
defined(TARGET_NUCLEO_F091RC) || \
|
||||
defined(TARGET_NUCLEO_F103RB) || \
|
||||
defined(TARGET_NUCLEO_F302R8) || \
|
||||
defined(TARGET_NUCLEO_F303RE) || \
|
||||
defined(TARGET_NUCLEO_F334R8) || \
|
||||
defined(TARGET_NUCLEO_F401RE) || \
|
||||
defined(TARGET_NUCLEO_F411RE) || \
|
||||
defined(TARGET_NUCLEO_L053R8) || \
|
||||
defined(TARGET_NUCLEO_L073RZ) || \
|
||||
defined(TARGET_NUCLEO_L152RE)
|
||||
#define PIN_IN PB_8
|
||||
#define PIN_OUT PC_7
|
||||
|
||||
#elif defined(TARGET_ARCH_MAX) || \
|
||||
defined(TARGET_DISCO_F407VG) || \
|
||||
defined(TARGET_DISCO_F429ZI)|| \
|
||||
defined(TARGET_DISCO_F401VC)
|
||||
#define PIN_OUT PC_12
|
||||
#define PIN_IN PD_0
|
||||
|
||||
#elif defined(TARGET_RZ_A1H)
|
||||
#define PIN_OUT D1
|
||||
#define PIN_IN D5
|
||||
|
||||
#elif defined(TARGET_FF_ARDUINO)
|
||||
#define PIN_OUT D0
|
||||
#define PIN_IN D7
|
||||
|
||||
#elif defined(TARGET_MAXWSNENV)
|
||||
#define PIN_OUT P0_0
|
||||
#define PIN_IN P0_1
|
||||
|
||||
#elif defined(TARGET_MAX32600MBED)
|
||||
#define PIN_OUT P1_0
|
||||
#define PIN_IN P4_7
|
||||
|
||||
#else
|
||||
#define PIN_IN (p5)
|
||||
#define PIN_OUT (p25)
|
||||
|
||||
#endif
|
||||
|
||||
DigitalOut out(PIN_OUT);
|
||||
InterruptIn in(PIN_IN);
|
||||
|
||||
#define IN_OUT_SET out = 1; myled = 1;
|
||||
#define IN_OUT_CLEAR out = 0; myled = 0;
|
||||
|
||||
void flipper() {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
IN_OUT_SET;
|
||||
wait(0.2);
|
||||
IN_OUT_CLEAR;
|
||||
wait(0.2);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
MBED_HOSTTEST_TIMEOUT(15);
|
||||
MBED_HOSTTEST_SELECT(default_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(InterruptIn);
|
||||
MBED_HOSTTEST_START("MBED_A7");
|
||||
|
||||
IN_OUT_CLEAR;
|
||||
//Test falling edges first
|
||||
in.rise(NULL);
|
||||
in.fall(in_handler);
|
||||
flipper();
|
||||
|
||||
if(checks != 5) {
|
||||
printf("MBED: falling edges test failed: %d\r\n",checks);
|
||||
MBED_HOSTTEST_RESULT(false);
|
||||
}
|
||||
|
||||
//Now test rising edges
|
||||
in.rise(in_handler);
|
||||
in.fall(NULL);
|
||||
flipper();
|
||||
|
||||
if (checks != 10) {
|
||||
printf("MBED: raising edges test failed: %d\r\n", checks);
|
||||
MBED_HOSTTEST_RESULT(false);
|
||||
}
|
||||
|
||||
//Now test switch off edge detection
|
||||
in.rise(NULL);
|
||||
in.fall(NULL);
|
||||
flipper();
|
||||
|
||||
if (checks != 10) {
|
||||
printf("MBED: edge detection switch off test failed: %d\r\n", checks);
|
||||
MBED_HOSTTEST_RESULT(false);
|
||||
}
|
||||
|
||||
//Finally test both
|
||||
in.rise(in_handler);
|
||||
in.fall(in_handler);
|
||||
flipper();
|
||||
|
||||
if (checks != 20) {
|
||||
printf("MBED: Simultaneous rising and falling edges failed: %d\r\n", checks);
|
||||
MBED_HOSTTEST_RESULT(false);
|
||||
}
|
||||
|
||||
MBED_HOSTTEST_RESULT(true);
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
#include "mbed.h"
|
||||
|
||||
#if defined(TARGET_LPC4088)
|
||||
InterruptIn button(p18);
|
||||
InterruptIn button1(p17);
|
||||
InterruptIn button2(p16);
|
||||
InterruptIn button3(p15);
|
||||
InterruptIn button4(p14);
|
||||
InterruptIn button5(p13);
|
||||
InterruptIn button6(p12);
|
||||
InterruptIn button7(p11);
|
||||
InterruptIn button8(p10);
|
||||
InterruptIn button9(p9);
|
||||
DigitalOut led(LED1);
|
||||
DigitalOut flash(LED4);
|
||||
|
||||
#elif defined(TARGET_LPC1114)
|
||||
InterruptIn button(p30); // SW2 (User switch)
|
||||
InterruptIn button1(p5);
|
||||
InterruptIn button2(p6);
|
||||
InterruptIn button3(p7);
|
||||
InterruptIn button4(p9);
|
||||
InterruptIn button5(p10);
|
||||
InterruptIn button6(p12);
|
||||
InterruptIn button7(p13);
|
||||
InterruptIn button8(p14);
|
||||
InterruptIn button9(p15);
|
||||
DigitalOut led(LED1);
|
||||
DigitalOut flash(LED2);
|
||||
|
||||
#else
|
||||
InterruptIn button(p30);
|
||||
InterruptIn button1(p29);
|
||||
InterruptIn button2(p28);
|
||||
InterruptIn button3(p27);
|
||||
InterruptIn button4(p26);
|
||||
InterruptIn button5(p25);
|
||||
InterruptIn button6(p24);
|
||||
InterruptIn button7(p23);
|
||||
InterruptIn button8(p22);
|
||||
InterruptIn button9(p21);
|
||||
DigitalOut led(LED1);
|
||||
DigitalOut flash(LED4);
|
||||
#endif
|
||||
|
||||
void flip() {
|
||||
led = !led;
|
||||
}
|
||||
|
||||
int main() {
|
||||
flash = 0;
|
||||
led = 0;
|
||||
#if defined(TARGET_LPC1114)
|
||||
button.mode(PullUp);
|
||||
#endif
|
||||
button.rise(&flip); // attach the address of the flip function to the rising edge
|
||||
button1.rise(&flip);
|
||||
button2.rise(&flip);
|
||||
button3.rise(&flip);
|
||||
button4.rise(&flip);
|
||||
button5.rise(&flip);
|
||||
button6.rise(&flip);
|
||||
button7.rise(&flip);
|
||||
button8.rise(&flip);
|
||||
button9.rise(&flip);
|
||||
|
||||
while(1) { // wait around, interrupts will interrupt this!
|
||||
flash = !flash;
|
||||
wait(0.25);
|
||||
}
|
||||
}
|
115
tool/mbed/mbed-sdk/libraries/tests/mbed/modserial/main.cpp
Normal file
115
tool/mbed/mbed-sdk/libraries/tests/mbed/modserial/main.cpp
Normal file
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* To run this test program, link p9 to p10 so the Serial loops
|
||||
* back and receives characters it sends.
|
||||
*/
|
||||
#include "mbed.h"
|
||||
#include "MODSERIAL.h"
|
||||
|
||||
DigitalOut led1(LED1);
|
||||
DigitalOut led2(LED2);
|
||||
DigitalOut led3(LED3);
|
||||
DigitalOut led4(LED4);
|
||||
|
||||
MODSERIAL pc(USBTX, USBRX);
|
||||
|
||||
/*
|
||||
* As experiement, you can define MODSERIAL as show here and see what
|
||||
* effects it has on the LEDs.
|
||||
*
|
||||
* MODSERIAL uart(TX_PIN, RX_PIN, 512);
|
||||
* With this, the 512 characters sent can straight into the buffer
|
||||
* vary quickly. This means LED1 is only on briefly as the TX buffer
|
||||
* fills.
|
||||
*
|
||||
* MODSERIAL uart(TX_PIN, RX_PIN, 32);
|
||||
* With this, the buffer is smaller than the default 256 bytes and
|
||||
* therefore LED1 stays on much longer while the system waits for
|
||||
* room in the TX buffer.
|
||||
*/
|
||||
MODSERIAL uart(p9, p10);
|
||||
|
||||
// This function is called when a character goes from the TX buffer
|
||||
// to the Uart THR FIFO register.
|
||||
void txCallback(MODSERIAL_IRQ_INFO *q) {
|
||||
led2 = !led2;
|
||||
}
|
||||
|
||||
// This function is called when TX buffer goes empty
|
||||
void txEmpty(MODSERIAL_IRQ_INFO *q) {
|
||||
led2 = 0;
|
||||
pc.puts(" Done. ");
|
||||
}
|
||||
|
||||
// This function is called when a character goes into the RX buffer.
|
||||
void rxCallback(MODSERIAL_IRQ_INFO *q) {
|
||||
led3 = !led3;
|
||||
pc.putc(uart.getc());
|
||||
}
|
||||
|
||||
int main() {
|
||||
int c = 'A';
|
||||
|
||||
// Ensure the baud rate for the PC "USB" serial is much
|
||||
// higher than "uart" baud rate below. (default: 9600)
|
||||
// pc.baud(9600);
|
||||
|
||||
// Use a deliberatly slow baud to fill up the TX buffer
|
||||
uart.baud(1200);
|
||||
|
||||
uart.attach(&txCallback, MODSERIAL::ModTxIrq);
|
||||
uart.attach(&rxCallback, MODSERIAL::ModRxIrq);
|
||||
uart.attach(&txEmpty, MODSERIAL::ModTxEmpty);
|
||||
|
||||
// Loop sending characters. We send 512
|
||||
// which is twice the default TX/RX buffer size.
|
||||
|
||||
led1 = 1; // Show start of sending with LED1.
|
||||
|
||||
for (int loop = 0; loop < 512; loop++) {
|
||||
uart.printf("%c", c);
|
||||
c++;
|
||||
if (c > 'Z') c = 'A';
|
||||
}
|
||||
|
||||
led1 = 0; // Show the end of sending by switching off LED1.
|
||||
|
||||
// End program. Flash LED4. Notice how LED 2 and 3 continue
|
||||
// to flash for a short period while the interrupt system
|
||||
// continues to send the characters left in the TX buffer.
|
||||
|
||||
while(1) {
|
||||
led4 = !led4;
|
||||
wait(0.25);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Notes. Here is the sort of output you can expect on your PC/Mac/Linux host
|
||||
* machine that is connected to the "pc" USB serial port.
|
||||
*
|
||||
* ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUV
|
||||
* WXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQR
|
||||
* STUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMN
|
||||
* OPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJ
|
||||
* KLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEF
|
||||
* GHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZAB
|
||||
* CDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQ Done. R
|
||||
*
|
||||
* Of interest is that last "R" character after the system has said "Done."
|
||||
* This comes from the fact that the TxEmpty callback is made when the TX buffer
|
||||
* becomes empty. MODSERIAL makes use of the fact that the Uarts built into the
|
||||
* LPC17xx device use a 16 byte FIFO on both RX and TX channels. This means that
|
||||
* when the TxEmpty callback is made, the TX buffer is empty, but that just means
|
||||
* the "last few characters" were written to the TX FIFO. So although the TX
|
||||
* buffer has gone empty, the Uart's transmit system is still sending any remaining
|
||||
* characters from it's TX FIFO. If you want to be truely sure all the characters
|
||||
* you have sent have left the Mbed then call txIsBusy(); This function will
|
||||
* return true if characters are still being sent. If it returns false after
|
||||
* the Tx buffer is empty then all your characters have been sent.
|
||||
*
|
||||
* In a similar way, when characters are received into the RX FIFO, the entire
|
||||
* FIFO contents is moved to the RX buffer, assuming there is room left in the
|
||||
* RX buffer. If there is not, any remaining characters are left in the RX FIFO
|
||||
* and will be moved to the RX buffer on the next interrupt or when the running
|
||||
* program removes a character(s) from the RX buffer with the getc() method.
|
||||
*/
|
|
@ -0,0 +1,10 @@
|
|||
#include "mbed.h"
|
||||
|
||||
DigitalOut out(p5);
|
||||
|
||||
int main() {
|
||||
while (true) {
|
||||
out = 1;
|
||||
out = 0;
|
||||
}
|
||||
}
|
139
tool/mbed/mbed-sdk/libraries/tests/mbed/portinout/main.cpp
Normal file
139
tool/mbed/mbed-sdk/libraries/tests/mbed/portinout/main.cpp
Normal file
|
@ -0,0 +1,139 @@
|
|||
#include "test_env.h"
|
||||
|
||||
#if defined(TARGET_K64F)
|
||||
#define P1_1 (1 << 16)
|
||||
#define P1_2 (1 << 17)
|
||||
#define PORT_1 PortC
|
||||
|
||||
#define P2_1 (1 << 2)
|
||||
#define P2_2 (1 << 3)
|
||||
#define PORT_2 PortC
|
||||
|
||||
#elif defined(TARGET_LPC11U24)
|
||||
#define P1_1 (1 << 9) // p0.9
|
||||
#define P1_2 (1 << 8) // p0.8
|
||||
#define PORT_1 Port0
|
||||
|
||||
#define P2_1 (1 << 24) // p1.24
|
||||
#define P2_2 (1 << 25) // p1.25
|
||||
#define PORT_2 Port1
|
||||
|
||||
#elif defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
|
||||
#define P1_1 (1 << 9) // p0.9 -> p5
|
||||
#define P1_2 (1 << 8) // p0.8 -> p6
|
||||
#define PORT_1 Port0
|
||||
|
||||
#define P2_1 (1 << 1) // p2.1 -> p25
|
||||
#define P2_2 (1 << 0) // p2.0 -> p26
|
||||
#define PORT_2 Port2
|
||||
|
||||
#elif defined(TARGET_LPC4088)
|
||||
#define P1_1 (1 << 7) // p0.7 -> p13
|
||||
#define P1_2 (1 << 6) // p0.6 -> p14
|
||||
#define PORT_1 Port0
|
||||
|
||||
#define P2_1 (1 << 2) // p1.2 -> p30
|
||||
#define P2_2 (1 << 3) // p1.3 -> p29
|
||||
#define PORT_2 Port1
|
||||
|
||||
#elif defined(TARGET_LPC1114)
|
||||
#define P1_1 (1 << 9) // p0.9
|
||||
#define P1_2 (1 << 8) // p0.8
|
||||
#define PORT_1 Port0
|
||||
|
||||
#define P2_1 (1 << 1) // p1.1
|
||||
#define P2_2 (1 << 0) // p1.0
|
||||
#define PORT_2 Port1
|
||||
|
||||
#elif defined(TARGET_KL25Z)
|
||||
#define P1_1 (1 << 4) // PTA4
|
||||
#define P1_2 (1 << 5) // PTA5
|
||||
#define PORT_1 PortA
|
||||
|
||||
#define P2_1 (1 << 5) // PTC5
|
||||
#define P2_2 (1 << 6) // PTC6
|
||||
#define PORT_2 PortC
|
||||
|
||||
#elif defined(TARGET_nRF51822)
|
||||
#define P1_1 (1 << 4) // p4
|
||||
#define P1_2 (1 << 5) // p5
|
||||
#define PORT_1 Port0
|
||||
|
||||
#define P2_1 (1 << 24) // p24
|
||||
#define P2_2 (1 << 25) // p25
|
||||
#define PORT_2 Port0
|
||||
|
||||
#elif defined(TARGET_MAXWSNENV)
|
||||
#define P1_1 (1 << 0)
|
||||
#define P1_2 (1 << 1)
|
||||
#define PORT_1 Port0
|
||||
|
||||
#define P2_1 (1 << 0)
|
||||
#define P2_2 (1 << 1)
|
||||
#define PORT_2 Port1
|
||||
|
||||
#elif defined(TARGET_MAX32600MBED)
|
||||
#define P1_1 (1 << 0) // P1_0
|
||||
#define P1_2 (1 << 1) // P1_1
|
||||
#define PORT_1 Port1
|
||||
|
||||
#define P2_1 (1 << 7) // P4_7
|
||||
#define P2_2 (1 << 6) // P4_6
|
||||
#define PORT_2 Port4
|
||||
|
||||
#elif defined(TARGET_NUCLEO_F030R8) || \
|
||||
defined(TARGET_NUCLEO_F070RB) || \
|
||||
defined(TARGET_NUCLEO_F072RB) || \
|
||||
defined(TARGET_NUCLEO_F091RC) || \
|
||||
defined(TARGET_NUCLEO_F103RB) || \
|
||||
defined(TARGET_NUCLEO_F302R8) || \
|
||||
defined(TARGET_NUCLEO_F303RE) || \
|
||||
defined(TARGET_NUCLEO_F334R8) || \
|
||||
defined(TARGET_NUCLEO_F401RE) || \
|
||||
defined(TARGET_NUCLEO_F411RE) || \
|
||||
defined(TARGET_NUCLEO_L053R8) || \
|
||||
defined(TARGET_NUCLEO_L073RZ) || \
|
||||
defined(TARGET_NUCLEO_L152RE)
|
||||
#define P1_1 (1 << 6) // PC_6
|
||||
#define P1_2 (1 << 5) // PC_5
|
||||
#define PORT_1 PortC
|
||||
|
||||
#define P2_1 (1 << 8) // PB_8
|
||||
#define P2_2 (1 << 9) // PB_9
|
||||
#define PORT_2 PortB
|
||||
#endif
|
||||
|
||||
#define MASK_1 (P1_1 | P1_2)
|
||||
#define MASK_2 (P2_1 | P2_2)
|
||||
|
||||
PortInOut port1(PORT_1, MASK_1);
|
||||
PortInOut port2(PORT_2, MASK_2);
|
||||
|
||||
int main() {
|
||||
MBED_HOSTTEST_TIMEOUT(20);
|
||||
MBED_HOSTTEST_SELECT(default_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(PortInOut);
|
||||
MBED_HOSTTEST_START("MBED_A11");
|
||||
|
||||
bool check = true;
|
||||
|
||||
port1.output();
|
||||
port2.input();
|
||||
|
||||
port1 = MASK_1; wait(0.1);
|
||||
if (port2 != MASK_2) check = false;
|
||||
|
||||
port1 = 0; wait(0.1);
|
||||
if (port2 != 0) check = false;
|
||||
|
||||
port1.input();
|
||||
port2.output();
|
||||
|
||||
port2 = MASK_2; wait(0.1);
|
||||
if (port1 != MASK_1) check = false;
|
||||
|
||||
port2 = 0; wait(0.1);
|
||||
if (port1 != 0) check = false;
|
||||
|
||||
MBED_HOSTTEST_RESULT(check);
|
||||
}
|
47
tool/mbed/mbed-sdk/libraries/tests/mbed/portout/main.cpp
Normal file
47
tool/mbed/mbed-sdk/libraries/tests/mbed/portout/main.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include "mbed.h"
|
||||
|
||||
# if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC4088)
|
||||
# define LED_PORT Port1
|
||||
# define LED1 (1 << 18) // P1.18
|
||||
# define LED2 (1 << 20) // P1.20
|
||||
# define LED3 (1 << 21) // P1.21
|
||||
# define LED4 (1 << 23) // P1.23
|
||||
# elif defined(TARGET_LPC11U24) || defined(TARGET_LPC1114)
|
||||
# define LED_PORT Port1
|
||||
# define LED1 (1 << 8) // P1.8
|
||||
# define LED2 (1 << 9) // P1.9
|
||||
# define LED3 (1 << 10) // P1.10
|
||||
# define LED4 (1 << 11) // P1.11
|
||||
# elif defined(TARGET_MAXWSNENV)
|
||||
# define LED_PORT Port1
|
||||
# define LED1 (1 << 4) // P1.4
|
||||
# define LED2 (1 << 6) // P1.6
|
||||
# define LED3 (1 << 7) // P1.7
|
||||
# define LED4 0
|
||||
# elif defined(TARGET_MAX32600MBED)
|
||||
# define LED_PORT Port7
|
||||
# define LED1 (1 << 0) // P7.0
|
||||
# define LED2 (1 << 6) // P7.6
|
||||
# define LED3 (1 << 4) // P7.4
|
||||
# define LED4 0
|
||||
# endif
|
||||
|
||||
#define LED_MASK (LED1|LED2|LED3|LED4)
|
||||
|
||||
int mask[4] = {
|
||||
(LED1 | LED3),
|
||||
(LED2 | LED4),
|
||||
(LED1 | LED2),
|
||||
(LED3 | LED4)
|
||||
};
|
||||
|
||||
PortOut ledport(LED_PORT, LED_MASK);
|
||||
|
||||
int main() {
|
||||
while (1) {
|
||||
for (int i=0; i<4; i++) {
|
||||
ledport = mask[i];
|
||||
wait(1);
|
||||
}
|
||||
}
|
||||
}
|
135
tool/mbed/mbed-sdk/libraries/tests/mbed/portout_portin/main.cpp
Normal file
135
tool/mbed/mbed-sdk/libraries/tests/mbed/portout_portin/main.cpp
Normal file
|
@ -0,0 +1,135 @@
|
|||
#include "test_env.h"
|
||||
|
||||
#if defined(TARGET_K64F) || defined(TARGET_KL05Z)
|
||||
#define P1_1 (1 << 16)
|
||||
#define P1_2 (1 << 17)
|
||||
#define PORT_1 PortC
|
||||
|
||||
#define P2_1 (1 << 2)
|
||||
#define P2_2 (1 << 3)
|
||||
#define PORT_2 PortC
|
||||
|
||||
#elif defined(TARGET_LPC11U24)
|
||||
#define P1_1 (1 << 9) // p0.9
|
||||
#define P1_2 (1 << 8) // p0.8
|
||||
#define PORT_1 Port0
|
||||
|
||||
#define P2_1 (1 << 24) // p1.24
|
||||
#define P2_2 (1 << 25) // p1.25
|
||||
#define PORT_2 Port1
|
||||
|
||||
#elif defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
|
||||
#define P1_1 (1 << 9) // p0.9 -> p5
|
||||
#define P1_2 (1 << 8) // p0.8 -> p6
|
||||
#define PORT_1 Port0
|
||||
|
||||
#define P2_1 (1 << 1) // p2.1 -> p25
|
||||
#define P2_2 (1 << 0) // p2.0 -> p26
|
||||
#define PORT_2 Port2
|
||||
|
||||
#elif defined(TARGET_LPC4088)
|
||||
#define P1_1 (1 << 7) // p0.7 -> p13
|
||||
#define P1_2 (1 << 6) // p0.6 -> p14
|
||||
#define PORT_1 Port0
|
||||
|
||||
#define P2_1 (1 << 2) // p1.2 -> p30
|
||||
#define P2_2 (1 << 3) // p1.3 -> p29
|
||||
#define PORT_2 Port1
|
||||
|
||||
#elif defined(TARGET_LPC1114)
|
||||
#define P1_1 (1 << 9) // p0.9
|
||||
#define P1_2 (1 << 8) // p0.8
|
||||
#define PORT_1 Port0
|
||||
|
||||
#define P2_1 (1 << 1) // p1.1
|
||||
#define P2_2 (1 << 0) // p1.0
|
||||
#define PORT_2 Port1
|
||||
|
||||
#elif defined(TARGET_KL25Z)
|
||||
#define P1_1 (1 << 4) // PTA4
|
||||
#define P1_2 (1 << 5) // PTA5
|
||||
#define PORT_1 PortA
|
||||
|
||||
#define P2_1 (1 << 5) // PTC5
|
||||
#define P2_2 (1 << 6) // PTC6
|
||||
#define PORT_2 PortC
|
||||
|
||||
#elif defined(TARGET_nRF51822)
|
||||
#define P1_1 (1 << 4) // p4
|
||||
#define P1_2 (1 << 5) // p5
|
||||
#define PORT_1 Port0
|
||||
|
||||
#define P2_1 (1 << 24) // p24
|
||||
#define P2_2 (1 << 25) // p25
|
||||
#define PORT_2 Port0
|
||||
|
||||
#elif defined(TARGET_MAXWSNENV)
|
||||
#define P1_1 (1 << 0)
|
||||
#define P1_2 (1 << 1)
|
||||
#define PORT_1 Port0
|
||||
|
||||
#define P2_1 (1 << 0)
|
||||
#define P2_2 (1 << 1)
|
||||
#define PORT_2 Port1
|
||||
|
||||
#elif defined(TARGET_MAX32600MBED)
|
||||
#define P1_1 (1 << 0) // P1_0
|
||||
#define P1_2 (1 << 1) // P1_1
|
||||
#define PORT_1 Port1
|
||||
|
||||
#define P2_1 (1 << 7) // P4_7
|
||||
#define P2_2 (1 << 6) // P4_6
|
||||
#define PORT_2 Port4
|
||||
|
||||
#elif defined(TARGET_NUCLEO_F030R8) || \
|
||||
defined(TARGET_NUCLEO_F070RB) || \
|
||||
defined(TARGET_NUCLEO_F072RB) || \
|
||||
defined(TARGET_NUCLEO_F091RC) || \
|
||||
defined(TARGET_NUCLEO_F103RB) || \
|
||||
defined(TARGET_NUCLEO_F302R8) || \
|
||||
defined(TARGET_NUCLEO_F303RE) || \
|
||||
defined(TARGET_NUCLEO_F334R8) || \
|
||||
defined(TARGET_NUCLEO_F401RE) || \
|
||||
defined(TARGET_NUCLEO_F411RE) || \
|
||||
defined(TARGET_NUCLEO_L053R8) || \
|
||||
defined(TARGET_NUCLEO_L073RZ) || \
|
||||
defined(TARGET_NUCLEO_L152RE)
|
||||
#define P1_1 (1 << 6) // PC_6
|
||||
#define P1_2 (1 << 5) // PC_5
|
||||
#define PORT_1 PortC
|
||||
|
||||
#define P2_1 (1 << 8) // PB_8
|
||||
#define P2_2 (1 << 9) // PB_9
|
||||
#define PORT_2 PortB
|
||||
#endif
|
||||
|
||||
#define MASK_1 (P1_1 | P1_2)
|
||||
#define MASK_2 (P2_1 | P2_2)
|
||||
|
||||
PortOut port_out(PORT_1, MASK_1);
|
||||
PortIn port_in (PORT_2, MASK_2);
|
||||
|
||||
int main() {
|
||||
MBED_HOSTTEST_TIMEOUT(20);
|
||||
MBED_HOSTTEST_SELECT(default_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(PortOut PortIn);
|
||||
MBED_HOSTTEST_START("MBED_A10");
|
||||
|
||||
port_out = MASK_1;
|
||||
wait(0.1);
|
||||
int value = port_in.read();
|
||||
if (value != MASK_2) {
|
||||
printf("[Test high] expected (0x%x) received (0x%x)\n", MASK_2, value);
|
||||
notify_completion(false);
|
||||
}
|
||||
|
||||
port_out = 0;
|
||||
wait(0.1);
|
||||
value = port_in.read();
|
||||
if (value != 0) {
|
||||
printf("[Test low] expected (0x%x) received (0x%x)\n", 0, value);
|
||||
notify_completion(false);
|
||||
}
|
||||
|
||||
notify_completion(true);
|
||||
}
|
174
tool/mbed/mbed-sdk/libraries/tests/mbed/pwm/main.cpp
Normal file
174
tool/mbed/mbed-sdk/libraries/tests/mbed/pwm/main.cpp
Normal file
|
@ -0,0 +1,174 @@
|
|||
#include "test_env.h"
|
||||
|
||||
/* Timer/Match Register Pinout Options
|
||||
|
||||
CT16B0/MR0 p5 (P0_9)
|
||||
CT16B0/MR1 p6 (P0_8)
|
||||
CT16B0/MR2 p34 (P1_15)
|
||||
|
||||
CT16B1/MR0 p36 (P0_21)
|
||||
CT16B1/MR1 p20 (P0_22) and p14 (P1_23)
|
||||
|
||||
CT32B0/MR0 p25 (P1_24)
|
||||
CT32B0/MR1 p26 (P1_25) and USBTX (P0_19)
|
||||
CT32B0/MR2 p10 (P1_26)
|
||||
*/
|
||||
|
||||
float value = 0.75;
|
||||
|
||||
int main() {
|
||||
#if defined(TARGET_FF_ARDUINO)
|
||||
PwmOut pwm(D9);
|
||||
|
||||
pwm.period_ms(10);
|
||||
pwm.write(value);
|
||||
|
||||
float result = floor(pwm.read() * 100 + 0.5) / 100; // round it to 0.xx
|
||||
printf("Initialize PWM on pin D9 with duty cycle: %.2f\n", result);
|
||||
|
||||
notify_completion(result == value ? true : false);
|
||||
|
||||
#elif defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC11U24) || defined(TARGET_LPC4088)
|
||||
PwmOut pwm_p25(p25);
|
||||
PwmOut pwm_p26(p26);
|
||||
|
||||
pwm_p25.write(0.75);
|
||||
pwm_p26.write(0.50);
|
||||
|
||||
printf("Initialize PWM on pin 25 with duty cycle: %.2f\n", pwm_p25.read());
|
||||
printf("Initialize PWM on pin 26 with duty cycle: %.2f\n", pwm_p26.read());
|
||||
|
||||
#elif defined(TARGET_LPC1114)
|
||||
PwmOut pwm_dp24(dp24); // P0_1
|
||||
PwmOut pwm_dp18(dp18); // P1_9
|
||||
|
||||
pwm_dp24.write(0.75);
|
||||
pwm_dp18.write(0.50);
|
||||
|
||||
printf("Initialize PWM on pin 24 with duty cycle: %.2f\n", pwm_dp24.read());
|
||||
printf("Initialize PWM on pin 18 with duty cycle: %.2f\n", pwm_dp18.read());
|
||||
|
||||
#elif defined(TARGET_nRF51822)
|
||||
PwmOut pwm_p24(p24);
|
||||
PwmOut pwm_p25(p25);
|
||||
|
||||
pwm_p24.write(0.75);
|
||||
pwm_p25.write(0.50);
|
||||
|
||||
printf("Initialize PWM on pin 24 with duty cycle: %.2f\n", pwm_p24.read());
|
||||
printf("Initialize PWM on pin 25 with duty cycle: %.2f\n", pwm_p25.read());
|
||||
|
||||
#elif defined(TARGET_DISCO_F100RB)
|
||||
PwmOut pwm_1(PB_3);
|
||||
PwmOut pwm_2(PB_4);
|
||||
|
||||
pwm_1.write(0.75);
|
||||
pwm_2.write(0.50);
|
||||
|
||||
printf("Initialize PWM on pin PB_3 with duty cycle: %.2f\n", pwm_1.read());
|
||||
printf("Initialize PWM on pin PB_4 with duty cycle: %.2f\n", pwm_2.read());
|
||||
#elif defined(TARGET_DISCO_F051R8)
|
||||
PwmOut pwm_1(PA_7);
|
||||
PwmOut pwm_2(PC_7);
|
||||
|
||||
pwm_1.write(0.75);
|
||||
pwm_2.write(0.50);
|
||||
|
||||
printf("Initialize PWM on pin PA_7 with duty cycle: %.2f\n", pwm_1.read());
|
||||
printf("Initialize PWM on pin PC_7 with duty cycle: %.2f\n", pwm_2.read());
|
||||
#elif defined(TARGET_DISCO_F303VC)
|
||||
PwmOut pwm_1(PA_8);
|
||||
PwmOut pwm_2(PA_9);
|
||||
|
||||
pwm_1.write(0.75);
|
||||
pwm_2.write(0.50);
|
||||
|
||||
printf("Initialize PWM on pin PA_7 with duty cycle: %.2f\n", pwm_1.read());
|
||||
printf("Initialize PWM on pin PC_7 with duty cycle: %.2f\n", pwm_2.read());
|
||||
#elif defined(TARGET_MAXWSNENV)
|
||||
PwmOut pwm_1(TP2);
|
||||
PwmOut pwm_2(TP4);
|
||||
|
||||
pwm_1.write(0.75);
|
||||
pwm_2.write(0.50);
|
||||
|
||||
printf("Initialize PWM on pin TP2 with duty cycle: %.2f\n", pwm_1.read());
|
||||
printf("Initialize PWM on pin TP4 with duty cycle: %.2f\n", pwm_2.read());
|
||||
#elif defined(TARGET_DISCO_F407VG)
|
||||
PwmOut pwm_1(PD_12);
|
||||
PwmOut pwm_2(PD_13);
|
||||
|
||||
pwm_1.write(value);
|
||||
pwm_2.write(0.50);
|
||||
|
||||
float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
|
||||
|
||||
printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
|
||||
printf("Initialize PWM on pin PD_13 with duty cycle: %.2f\n", pwm_2.read());
|
||||
|
||||
notify_completion(result == value ? true : false);
|
||||
#elif defined(TARGET_DISCO_F429ZI)
|
||||
PwmOut pwm_1(PA_0);
|
||||
|
||||
pwm_1.write(value);
|
||||
|
||||
float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
|
||||
|
||||
printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
|
||||
|
||||
notify_completion(result == value ? true : false);
|
||||
#elif defined(TARGET_MTS_MDOT_F405RG)
|
||||
PwmOut pwm_1(PA_0);
|
||||
|
||||
pwm_1.write(value);
|
||||
|
||||
float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
|
||||
|
||||
printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
|
||||
|
||||
notify_completion(result == value ? true : false);
|
||||
#elif defined(TARGET_MTS_DRAGONFLY_F411RE)
|
||||
PwmOut pwm_1(PA_0);
|
||||
|
||||
pwm_1.write(value);
|
||||
|
||||
float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
|
||||
|
||||
printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
|
||||
|
||||
notify_completion(result == value ? true : false);
|
||||
#elif defined(TARGET_MTS_MDOT_F411RE)
|
||||
PwmOut pwm_1(PA_0);
|
||||
|
||||
pwm_1.write(value);
|
||||
|
||||
float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
|
||||
|
||||
printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
|
||||
|
||||
notify_completion(result == value ? true : false);
|
||||
#elif defined(TARGET_UBLOX_C029)
|
||||
PwmOut pwm_1(PA_0);
|
||||
|
||||
pwm_1.write(value);
|
||||
|
||||
float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
|
||||
|
||||
printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
|
||||
|
||||
notify_completion(result == value ? true : false);
|
||||
#elif defined(TARGET_MAX32600MBED)
|
||||
PwmOut pwm_1(P1_2);
|
||||
PwmOut pwm_2(P1_3);
|
||||
|
||||
pwm_1.write(0.75);
|
||||
pwm_2.write(0.50);
|
||||
|
||||
printf("Initialize PWM on pin P1.2 with duty cycle: %.2f\n", pwm_1.read());
|
||||
printf("Initialize PWM on pin P1.3 with duty cycle: %.2f\n", pwm_2.read());
|
||||
#else
|
||||
#error This test is not supported on this target.
|
||||
#endif
|
||||
|
||||
notify_completion(true);
|
||||
}
|
54
tool/mbed/mbed-sdk/libraries/tests/mbed/pwm_led/pwm.cpp
Normal file
54
tool/mbed/mbed-sdk/libraries/tests/mbed/pwm_led/pwm.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
#include "mbed.h"
|
||||
|
||||
#if defined(TARGET_K64F)
|
||||
#define TEST_LED D9
|
||||
|
||||
#elif defined(TARGET_NUCLEO_F030R8) || \
|
||||
defined(TARGET_NUCLEO_F070RB) || \
|
||||
defined(TARGET_NUCLEO_F072RB) || \
|
||||
defined(TARGET_NUCLEO_F091RC) || \
|
||||
defined(TARGET_NUCLEO_F103RB) || \
|
||||
defined(TARGET_NUCLEO_F302R8) || \
|
||||
defined(TARGET_NUCLEO_F303RE) || \
|
||||
defined(TARGET_NUCLEO_F334R8) || \
|
||||
defined(TARGET_NUCLEO_F401RE) || \
|
||||
defined(TARGET_NUCLEO_F411RE) || \
|
||||
defined(TARGET_NUCLEO_L053R8) || \
|
||||
defined(TARGET_NUCLEO_L073RZ) || \
|
||||
defined(TARGET_NUCLEO_L152RE)
|
||||
#define TEST_LED D3
|
||||
|
||||
#elif defined (TARGET_K22F) || \
|
||||
defined (TARGET_LPC824)
|
||||
#define TEST_LED LED_GREEN
|
||||
|
||||
#elif defined (TARGET_MAXWSNENV)
|
||||
#define TEST_LED LED_GREEN
|
||||
|
||||
#elif defined (TARGET_DISCO_F407VG)
|
||||
#define TEST_LED LED1
|
||||
|
||||
#else
|
||||
#error This test is not supported on this target.
|
||||
#endif
|
||||
|
||||
PwmOut led(TEST_LED);
|
||||
|
||||
int main() {
|
||||
float crt = 1.0, delta = 0.05;
|
||||
|
||||
led.period_ms(2); // 500Hz
|
||||
while (true) {
|
||||
led.write(crt);
|
||||
wait_ms(50);
|
||||
crt = crt + delta;
|
||||
if (crt > 1.0) {
|
||||
crt = 1.0;
|
||||
delta = -delta;
|
||||
}
|
||||
else if (crt < 0) {
|
||||
crt = 0;
|
||||
delta = -delta;
|
||||
}
|
||||
}
|
||||
}
|
17
tool/mbed/mbed-sdk/libraries/tests/mbed/reset/main.cpp
Normal file
17
tool/mbed/mbed-sdk/libraries/tests/mbed/reset/main.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include "mbed.h"
|
||||
|
||||
Serial pc(USBTX, USBRX);
|
||||
|
||||
extern "C" void mbed_reset();
|
||||
|
||||
int main() {
|
||||
pc.printf("start\n");
|
||||
wait(1);
|
||||
|
||||
unsigned int counter = 0;
|
||||
while(1) {
|
||||
pc.printf("%u\n",counter++);
|
||||
wait(1);
|
||||
mbed_reset();
|
||||
}
|
||||
}
|
67
tool/mbed/mbed-sdk/libraries/tests/mbed/rpc/main.cpp
Normal file
67
tool/mbed/mbed-sdk/libraries/tests/mbed/rpc/main.cpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include "mbed.h"
|
||||
#include "test_env.h"
|
||||
#include "mbed_rpc.h"
|
||||
|
||||
void foo(Arguments *args, Reply *reply) {
|
||||
reply->putData<float>(args->getArg<float>() * 3.3);
|
||||
}
|
||||
|
||||
bool rpc_test(const char *input, const char *expected) {
|
||||
char outbuf[RPC_MAX_STRING] = {0};
|
||||
bool result = RPC::call(input, outbuf);
|
||||
printf("RPC: %s -> ", input);
|
||||
|
||||
if (result == false) {
|
||||
printf("Procedure call ... [FAIL]\r\n");
|
||||
} else if (strncmp(outbuf, expected, RPC_MAX_STRING) != 0) {
|
||||
printf("'%s' != '%s' ... [FAIL]\r\n", outbuf, expected);
|
||||
result = false;
|
||||
} else {
|
||||
printf("'%s' ... [OK]\r\n", outbuf);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#define RPC_TEST(INPUT,EXPECTED) result = result && rpc_test(INPUT,EXPECTED); if (result == false) { notify_completion(result); exit(1); }
|
||||
|
||||
int main() {
|
||||
float f = 0;
|
||||
bool result = true;
|
||||
// Variable
|
||||
RPCVariable<float> rpc_f(&f, "f");
|
||||
RPC_TEST("/f/write 1", "");
|
||||
RPC_TEST("/f/read", "1");
|
||||
|
||||
// Function
|
||||
RPCFunction rpc_foo(&foo, "foo");
|
||||
#if defined(TOOLCHAIN_ARM_MICRO)
|
||||
RPC_TEST("/foo/run 1", "3.299999952316284");
|
||||
#else
|
||||
RPC_TEST("/foo/run 1", "3.2999999523162842");
|
||||
#endif
|
||||
|
||||
// Class
|
||||
RPC::add_rpc_class<RpcDigitalOut>();
|
||||
RPC_TEST("/DigitalOut/new LED2 led2", "led2");
|
||||
RPC_TEST("/led2/write 1", "");
|
||||
RPC_TEST("/led2/read", "1");
|
||||
|
||||
// Instance
|
||||
RpcDigitalOut rpc_led(LED1, "led1");
|
||||
RPC_TEST("/led1/write 1", "");
|
||||
RPC_TEST("/led1/read", "1");
|
||||
|
||||
// Introspection
|
||||
RPC_TEST("/", "led1 led2 foo f DigitalOut RPC");
|
||||
RPC_TEST("/f", "read write delete");
|
||||
RPC_TEST("/foo", "run delete");
|
||||
RPC_TEST("/DigitalOut", "new");
|
||||
RPC_TEST("/led1", "write read delete");
|
||||
|
||||
// Delete instance
|
||||
RPC_TEST("/led2/delete", "");
|
||||
RPC_TEST("/", "led1 foo f DigitalOut RPC");
|
||||
|
||||
notify_completion(result);
|
||||
return 0;
|
||||
}
|
20
tool/mbed/mbed-sdk/libraries/tests/mbed/rtc/main.cpp
Normal file
20
tool/mbed/mbed-sdk/libraries/tests/mbed/rtc/main.cpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include "mbed.h"
|
||||
#include "test_env.h"
|
||||
|
||||
#define CUSTOM_TIME 1256729737
|
||||
|
||||
int main() {
|
||||
MBED_HOSTTEST_TIMEOUT(20);
|
||||
MBED_HOSTTEST_SELECT(rtc_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(RTC);
|
||||
MBED_HOSTTEST_START("MBED_16");
|
||||
|
||||
char buffer[32] = {0};
|
||||
set_time(CUSTOM_TIME); // Set RTC time to Wed, 28 Oct 2009 11:35:37
|
||||
while(1) {
|
||||
time_t seconds = time(NULL);
|
||||
strftime(buffer, 32, "%Y-%m-%d %H:%M:%S %p", localtime(&seconds));
|
||||
printf("MBED: [%ld] [%s]\r\n", seconds, buffer);
|
||||
wait(1);
|
||||
}
|
||||
}
|
112
tool/mbed/mbed-sdk/libraries/tests/mbed/sd/main.cpp
Normal file
112
tool/mbed/mbed-sdk/libraries/tests/mbed/sd/main.cpp
Normal file
|
@ -0,0 +1,112 @@
|
|||
#include "mbed.h"
|
||||
#include "SDFileSystem.h"
|
||||
#include "test_env.h"
|
||||
|
||||
#if defined(TARGET_KL25Z)
|
||||
SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");
|
||||
|
||||
#elif defined(TARGET_KL46Z)
|
||||
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
|
||||
|
||||
#elif defined(TARGET_K64F)
|
||||
SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
|
||||
|
||||
#elif defined(TARGET_K22F)
|
||||
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
|
||||
|
||||
#elif defined(TARGET_K20D50M)
|
||||
SDFileSystem sd(PTD2, PTD3, PTD1, PTC2, "sd");
|
||||
|
||||
#elif defined(TARGET_nRF51822)
|
||||
SDFileSystem sd(p12, p13, p15, p14, "sd");
|
||||
|
||||
#elif defined(TARGET_NUCLEO_F030R8) || \
|
||||
defined(TARGET_NUCLEO_F070RB) || \
|
||||
defined(TARGET_NUCLEO_F072RB) || \
|
||||
defined(TARGET_NUCLEO_F091RC) || \
|
||||
defined(TARGET_NUCLEO_F103RB) || \
|
||||
defined(TARGET_NUCLEO_F302R8) || \
|
||||
defined(TARGET_NUCLEO_F303RE) || \
|
||||
defined(TARGET_NUCLEO_F334R8) || \
|
||||
defined(TARGET_NUCLEO_F401RE) || \
|
||||
defined(TARGET_NUCLEO_F411RE) || \
|
||||
defined(TARGET_NUCLEO_L053R8) || \
|
||||
defined(TARGET_NUCLEO_L073RZ) || \
|
||||
defined(TARGET_NUCLEO_L152RE)
|
||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
||||
|
||||
#elif defined(TARGET_DISCO_F051R8)
|
||||
SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, "sd");
|
||||
|
||||
#elif defined(TARGET_LPC2368)
|
||||
SDFileSystem sd(p11, p12, p13, p14, "sd");
|
||||
|
||||
#elif defined(TARGET_LPC11U68)
|
||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
||||
|
||||
#elif defined(TARGET_LPC1549)
|
||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
||||
|
||||
#elif defined(TARGET_RZ_A1H)
|
||||
SDFileSystem sd(P8_5, P8_6, P8_3, P8_4, "sd");
|
||||
|
||||
#elif defined(TARGET_LPC11U37H_401)
|
||||
SDFileSystem sd(SDMOSI, SDMISO, SDSCLK, SDSSEL, "sd");
|
||||
|
||||
#else
|
||||
SDFileSystem sd(p11, p12, p13, p14, "sd");
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
const char *sd_file_path = "/sd/out.txt";
|
||||
const int DATA_SIZE = 256;
|
||||
}
|
||||
|
||||
int main() {
|
||||
MBED_HOSTTEST_TIMEOUT(15);
|
||||
MBED_HOSTTEST_SELECT(default_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(SD File System);
|
||||
MBED_HOSTTEST_START("MBED_A12");
|
||||
|
||||
uint8_t data_written[DATA_SIZE] = { 0 };
|
||||
bool result = false;
|
||||
|
||||
// Fill data_written buffer with random data
|
||||
// Write these data into the file
|
||||
bool write_result = false;
|
||||
{
|
||||
printf("SD: Writing ... ");
|
||||
FILE *f = fopen(sd_file_path, "w");
|
||||
if (f) {
|
||||
for (int i = 0; i < DATA_SIZE; i++) {
|
||||
data_written[i] = rand() % 0XFF;
|
||||
fprintf(f, "%c", data_written[i]);
|
||||
}
|
||||
write_result = true;
|
||||
fclose(f);
|
||||
}
|
||||
printf("[%s]\r\n", write_result ? "OK" : "FAIL");
|
||||
}
|
||||
|
||||
// Read back the data from the file and store them in data_read
|
||||
bool read_result = false;
|
||||
{
|
||||
printf("SD: Reading data ... ");
|
||||
FILE *f = fopen(sd_file_path, "r");
|
||||
if (f) {
|
||||
read_result = true;
|
||||
for (int i = 0; i < DATA_SIZE; i++) {
|
||||
uint8_t data = fgetc(f);
|
||||
if (data != data_written[i]) {
|
||||
read_result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
printf("[%s]\r\n", read_result ? "OK" : "FAIL");
|
||||
}
|
||||
|
||||
result = write_result && read_result;
|
||||
MBED_HOSTTEST_RESULT(result);
|
||||
}
|
161
tool/mbed/mbed-sdk/libraries/tests/mbed/sd_perf_fatfs/main.cpp
Normal file
161
tool/mbed/mbed-sdk/libraries/tests/mbed/sd_perf_fatfs/main.cpp
Normal file
|
@ -0,0 +1,161 @@
|
|||
#include "mbed.h"
|
||||
#include "SDFileSystem.h"
|
||||
#include "test_env.h"
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(TARGET_KL25Z)
|
||||
SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");
|
||||
|
||||
#elif defined(TARGET_KL46Z)
|
||||
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
|
||||
|
||||
#elif defined(TARGET_K64F)
|
||||
SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
|
||||
|
||||
#elif defined(TARGET_K22F)
|
||||
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
|
||||
|
||||
#elif defined(TARGET_K20D50M)
|
||||
SDFileSystem sd(PTD2, PTD3, PTD1, PTC2, "sd");
|
||||
|
||||
#elif defined(TARGET_nRF51822)
|
||||
SDFileSystem sd(p12, p13, p15, p14, "sd");
|
||||
|
||||
#elif defined(TARGET_NUCLEO_F030R8) || \
|
||||
defined(TARGET_NUCLEO_F070RB) || \
|
||||
defined(TARGET_NUCLEO_F072RB) || \
|
||||
defined(TARGET_NUCLEO_F091RC) || \
|
||||
defined(TARGET_NUCLEO_F103RB) || \
|
||||
defined(TARGET_NUCLEO_F302R8) || \
|
||||
defined(TARGET_NUCLEO_F303RE) || \
|
||||
defined(TARGET_NUCLEO_F334R8) || \
|
||||
defined(TARGET_NUCLEO_F401RE) || \
|
||||
defined(TARGET_NUCLEO_F411RE) || \
|
||||
defined(TARGET_NUCLEO_L053R8) || \
|
||||
defined(TARGET_NUCLEO_L073RZ) || \
|
||||
defined(TARGET_NUCLEO_L152RE)
|
||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
||||
|
||||
#elif defined(TARGET_DISCO_F051R8)
|
||||
SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, "sd");
|
||||
|
||||
#elif defined(TARGET_LPC2368)
|
||||
SDFileSystem sd(p11, p12, p13, p14, "sd");
|
||||
|
||||
#elif defined(TARGET_LPC11U68)
|
||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
||||
|
||||
#elif defined(TARGET_LPC1549)
|
||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
||||
|
||||
#elif defined(TARGET_LPC11U37H_401)
|
||||
SDFileSystem sd(SDMOSI, SDMISO, SDSCLK, SDSSEL, "sd");
|
||||
|
||||
#else
|
||||
SDFileSystem sd(p11, p12, p13, p14, "sd");
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
char buffer[1024];
|
||||
const int KIB_RW = 128;
|
||||
Timer timer;
|
||||
const char *bin_filename = "0:testfile.bin";
|
||||
}
|
||||
|
||||
bool test_sf_file_write_fatfs(const char *filename, const int kib_rw) {
|
||||
FIL file;
|
||||
bool result = true;
|
||||
FRESULT res = f_open(&file, filename, FA_WRITE | FA_CREATE_ALWAYS);
|
||||
if (res == FR_OK) {
|
||||
int byte_write = 0;
|
||||
unsigned int bytes = 0;
|
||||
timer.start();
|
||||
for (int i = 0; i < kib_rw; i++) {
|
||||
if (f_write(&file, buffer, sizeof(buffer), &bytes) != FR_OK) {
|
||||
result = false;
|
||||
f_close(&file);
|
||||
printf("Write error!\r\n");
|
||||
break;
|
||||
} else {
|
||||
byte_write++;
|
||||
}
|
||||
}
|
||||
timer.stop();
|
||||
f_close(&file);
|
||||
double test_time_sec = timer.read_us() / 1000000.0;
|
||||
double speed = kib_rw / test_time_sec;
|
||||
printf("%d KiB write in %.3f sec with speed of %.4f KiB/s\r\n", byte_write, test_time_sec, speed);
|
||||
notify_performance_coefficient("write_kibps", speed);
|
||||
} else {
|
||||
printf("File '%s' not opened\r\n", filename);
|
||||
result = false;
|
||||
}
|
||||
timer.reset();
|
||||
return result;
|
||||
}
|
||||
|
||||
bool test_sf_file_read_fatfs(const char *filename, const int kib_rw) {
|
||||
FIL file;
|
||||
bool result = true;
|
||||
FRESULT res = f_open(&file, filename, FA_READ | FA_OPEN_EXISTING);
|
||||
if (res == FR_OK) {
|
||||
timer.start();
|
||||
int byte_read = 0;
|
||||
unsigned int bytes = 0;
|
||||
do {
|
||||
res = f_read(&file, buffer, sizeof(buffer), &bytes);
|
||||
byte_read++;
|
||||
} while (res == FR_OK && bytes == sizeof(buffer));
|
||||
timer.stop();
|
||||
f_close(&file);
|
||||
double test_time_sec = timer.read_us() / 1000000.0;
|
||||
double speed = kib_rw / test_time_sec;
|
||||
printf("%d KiB read in %.3f sec with speed of %.4f KiB/s\r\n", byte_read, test_time_sec, speed);
|
||||
notify_performance_coefficient("fs_read_kibps", speed);
|
||||
} else {
|
||||
printf("File '%s' not opened\r\n", filename);
|
||||
result = false;
|
||||
}
|
||||
timer.reset();
|
||||
return result;
|
||||
}
|
||||
|
||||
char RandomChar() {
|
||||
return rand() % 100;
|
||||
}
|
||||
|
||||
int main() {
|
||||
MBED_HOSTTEST_TIMEOUT(15);
|
||||
MBED_HOSTTEST_SELECT(default_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(SD FatFS RW Speed);
|
||||
MBED_HOSTTEST_START("PERF_3");
|
||||
|
||||
// Test header
|
||||
printf("\r\n");
|
||||
printf("SD Card FatFS Performance Test\r\n");
|
||||
printf("File name: %s\r\n", bin_filename);
|
||||
printf("Buffer size: %d KiB\r\n", (KIB_RW * sizeof(buffer)) / 1024);
|
||||
|
||||
// Initialize buffer
|
||||
srand(testenv_randseed());
|
||||
char *buffer_end = buffer + sizeof(buffer);
|
||||
std::generate (buffer, buffer_end, RandomChar);
|
||||
|
||||
bool result = true;
|
||||
for (;;) {
|
||||
printf("Write test...\r\n");
|
||||
if (test_sf_file_write_fatfs(bin_filename, KIB_RW) == false) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
printf("Read test...\r\n");
|
||||
if (test_sf_file_read_fatfs(bin_filename, KIB_RW) == false) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
MBED_HOSTTEST_RESULT(result);
|
||||
}
|
156
tool/mbed/mbed-sdk/libraries/tests/mbed/sd_perf_fhandle/main.cpp
Normal file
156
tool/mbed/mbed-sdk/libraries/tests/mbed/sd_perf_fhandle/main.cpp
Normal file
|
@ -0,0 +1,156 @@
|
|||
#include "mbed.h"
|
||||
#include "SDFileSystem.h"
|
||||
#include "test_env.h"
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(TARGET_KL25Z)
|
||||
SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");
|
||||
|
||||
#elif defined(TARGET_KL46Z)
|
||||
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
|
||||
|
||||
#elif defined(TARGET_K64F)
|
||||
SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
|
||||
|
||||
#elif defined(TARGET_K22F)
|
||||
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
|
||||
|
||||
#elif defined(TARGET_K20D50M)
|
||||
SDFileSystem sd(PTD2, PTD3, PTD1, PTC2, "sd");
|
||||
|
||||
#elif defined(TARGET_nRF51822)
|
||||
SDFileSystem sd(p12, p13, p15, p14, "sd");
|
||||
|
||||
#elif defined(TARGET_NUCLEO_F030R8) || \
|
||||
defined(TARGET_NUCLEO_F070RB) || \
|
||||
defined(TARGET_NUCLEO_F072RB) || \
|
||||
defined(TARGET_NUCLEO_F091RC) || \
|
||||
defined(TARGET_NUCLEO_F103RB) || \
|
||||
defined(TARGET_NUCLEO_F302R8) || \
|
||||
defined(TARGET_NUCLEO_F303RE) || \
|
||||
defined(TARGET_NUCLEO_F334R8) || \
|
||||
defined(TARGET_NUCLEO_F401RE) || \
|
||||
defined(TARGET_NUCLEO_F411RE) || \
|
||||
defined(TARGET_NUCLEO_L053R8) || \
|
||||
defined(TARGET_NUCLEO_L073RZ) || \
|
||||
defined(TARGET_NUCLEO_L152RE)
|
||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
||||
|
||||
#elif defined(TARGET_DISCO_F051R8)
|
||||
SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, "sd");
|
||||
|
||||
#elif defined(TARGET_LPC2368)
|
||||
SDFileSystem sd(p11, p12, p13, p14, "sd");
|
||||
|
||||
#elif defined(TARGET_LPC11U68)
|
||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
||||
|
||||
#elif defined(TARGET_LPC1549)
|
||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
||||
|
||||
#elif defined(TARGET_LPC11U37H_401)
|
||||
SDFileSystem sd(SDMOSI, SDMISO, SDSCLK, SDSSEL, "sd");
|
||||
|
||||
#else
|
||||
SDFileSystem sd(p11, p12, p13, p14, "sd");
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
char buffer[1024];
|
||||
const int KIB_RW = 128;
|
||||
Timer timer;
|
||||
const char *bin_filename = "testfile.bin";
|
||||
}
|
||||
|
||||
bool test_sf_file_write_fhandle(const char *filename, const int kib_rw) {
|
||||
bool result = true;
|
||||
FileHandle* file = sd.open(filename, O_WRONLY | O_CREAT | O_TRUNC);
|
||||
if (file != NULL) {
|
||||
int byte_write = 0;
|
||||
timer.start();
|
||||
for (int i = 0; i < kib_rw; i++) {
|
||||
if (file->write(buffer, sizeof(buffer)) != sizeof(buffer)) {
|
||||
result = false;
|
||||
file->close();
|
||||
printf("Write error!\r\n");
|
||||
break;
|
||||
} else {
|
||||
byte_write++;
|
||||
}
|
||||
}
|
||||
timer.stop();
|
||||
file->close();
|
||||
double test_time_sec = timer.read_us() / 1000000.0;
|
||||
double speed = kib_rw / test_time_sec;
|
||||
printf("%d KiB write in %.3f sec with speed of %.4f KiB/s\r\n", byte_write, test_time_sec, speed);
|
||||
notify_performance_coefficient("write_kibps", speed);
|
||||
} else {
|
||||
printf("File '%s' not opened\r\n", filename);
|
||||
result = false;
|
||||
}
|
||||
timer.reset();
|
||||
return result;
|
||||
}
|
||||
|
||||
bool test_sf_file_read_fhandle(const char *filename, const int kib_rw) {
|
||||
bool result = true;
|
||||
FileHandle* file = sd.open(filename, O_RDONLY);
|
||||
if (file) {
|
||||
timer.start();
|
||||
int byte_read = 0;
|
||||
while (file->read(buffer, sizeof(buffer)) == sizeof(buffer)) {
|
||||
byte_read++;
|
||||
}
|
||||
timer.stop();
|
||||
file->close();
|
||||
double test_time_sec = timer.read_us() / 1000000.0;
|
||||
double speed = kib_rw / test_time_sec;
|
||||
printf("%d KiB read in %.3f sec with speed of %.4f KiB/s\r\n", byte_read, test_time_sec, speed);
|
||||
notify_performance_coefficient("fs_read_kibps", speed);
|
||||
} else {
|
||||
printf("File '%s' not opened\r\n", filename);
|
||||
result = false;
|
||||
}
|
||||
timer.reset();
|
||||
return result;
|
||||
}
|
||||
|
||||
char RandomChar() {
|
||||
return rand() % 100;
|
||||
}
|
||||
|
||||
int main() {
|
||||
MBED_HOSTTEST_TIMEOUT(15);
|
||||
MBED_HOSTTEST_SELECT(default_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(SD FileHandle RW Speed);
|
||||
MBED_HOSTTEST_START("PERF_2");
|
||||
|
||||
// Test header
|
||||
printf("\r\n");
|
||||
printf("SD Card FileHandle Performance Test\r\n");
|
||||
printf("File name: %s\r\n", bin_filename);
|
||||
printf("Buffer size: %d KiB\r\n", (KIB_RW * sizeof(buffer)) / 1024);
|
||||
|
||||
// Initialize buffer
|
||||
srand(testenv_randseed());
|
||||
char *buffer_end = buffer + sizeof(buffer);
|
||||
std::generate (buffer, buffer_end, RandomChar);
|
||||
|
||||
bool result = true;
|
||||
for (;;) {
|
||||
printf("Write test...\r\n");
|
||||
if (test_sf_file_write_fhandle(bin_filename, KIB_RW) == false) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
printf("Read test...\r\n");
|
||||
if (test_sf_file_read_fhandle(bin_filename, KIB_RW) == false) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
MBED_HOSTTEST_RESULT(result);
|
||||
}
|
156
tool/mbed/mbed-sdk/libraries/tests/mbed/sd_perf_stdio/main.cpp
Normal file
156
tool/mbed/mbed-sdk/libraries/tests/mbed/sd_perf_stdio/main.cpp
Normal file
|
@ -0,0 +1,156 @@
|
|||
#include "mbed.h"
|
||||
#include "SDFileSystem.h"
|
||||
#include "test_env.h"
|
||||
#include <algorithm>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(TARGET_KL25Z)
|
||||
SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");
|
||||
|
||||
#elif defined(TARGET_KL46Z)
|
||||
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
|
||||
|
||||
#elif defined(TARGET_K64F)
|
||||
SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
|
||||
|
||||
#elif defined(TARGET_K22F)
|
||||
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
|
||||
|
||||
#elif defined(TARGET_K20D50M)
|
||||
SDFileSystem sd(PTD2, PTD3, PTD1, PTC2, "sd");
|
||||
|
||||
#elif defined(TARGET_nRF51822)
|
||||
SDFileSystem sd(p12, p13, p15, p14, "sd");
|
||||
|
||||
#elif defined(TARGET_NUCLEO_F030R8) || \
|
||||
defined(TARGET_NUCLEO_F070RB) || \
|
||||
defined(TARGET_NUCLEO_F072RB) || \
|
||||
defined(TARGET_NUCLEO_F091RC) || \
|
||||
defined(TARGET_NUCLEO_F103RB) || \
|
||||
defined(TARGET_NUCLEO_F302R8) || \
|
||||
defined(TARGET_NUCLEO_F303RE) || \
|
||||
defined(TARGET_NUCLEO_F334R8) || \
|
||||
defined(TARGET_NUCLEO_F401RE) || \
|
||||
defined(TARGET_NUCLEO_F411RE) || \
|
||||
defined(TARGET_NUCLEO_L053R8) || \
|
||||
defined(TARGET_NUCLEO_L073RZ) || \
|
||||
defined(TARGET_NUCLEO_L152RE)
|
||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
||||
|
||||
#elif defined(TARGET_DISCO_F051R8)
|
||||
SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, "sd");
|
||||
|
||||
#elif defined(TARGET_LPC2368)
|
||||
SDFileSystem sd(p11, p12, p13, p14, "sd");
|
||||
|
||||
#elif defined(TARGET_LPC11U68)
|
||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
||||
|
||||
#elif defined(TARGET_LPC1549)
|
||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
||||
|
||||
#elif defined(TARGET_LPC11U37H_401)
|
||||
SDFileSystem sd(SDMOSI, SDMISO, SDSCLK, SDSSEL, "sd");
|
||||
|
||||
#else
|
||||
SDFileSystem sd(p11, p12, p13, p14, "sd");
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
char buffer[1024];
|
||||
const int KIB_RW = 128;
|
||||
Timer timer;
|
||||
const char *bin_filename = "/sd/testfile.bin";
|
||||
}
|
||||
|
||||
bool test_sf_file_write_stdio(const char *filename, const int kib_rw) {
|
||||
bool result = true;
|
||||
FILE* file = fopen(filename, "w");
|
||||
if (file != NULL) {
|
||||
int byte_write = 0;
|
||||
timer.start();
|
||||
for (int i = 0; i < kib_rw; i++) {
|
||||
if (fwrite(buffer, sizeof(char), sizeof(buffer), file) != sizeof(buffer)) {
|
||||
result = false;
|
||||
fclose(file);
|
||||
printf("Write error!\r\n");
|
||||
break;
|
||||
} else {
|
||||
byte_write++;
|
||||
}
|
||||
}
|
||||
timer.stop();
|
||||
fclose(file);
|
||||
double test_time_sec = timer.read_us() / 1000000.0;
|
||||
double speed = kib_rw / test_time_sec;
|
||||
printf("%d KiB write in %.3f sec with speed of %.4f KiB/s\r\n", byte_write, test_time_sec, speed);
|
||||
notify_performance_coefficient("write_kibps", speed);
|
||||
} else {
|
||||
printf("File '%s' not opened\r\n", filename);
|
||||
result = false;
|
||||
}
|
||||
timer.reset();
|
||||
return result;
|
||||
}
|
||||
|
||||
bool test_sf_file_read_stdio(const char *filename, const int kib_rw) {
|
||||
bool result = true;
|
||||
FILE* file = fopen(filename, "r");
|
||||
if (file) {
|
||||
timer.start();
|
||||
int byte_read = 0;
|
||||
while (fread(buffer, sizeof(char), sizeof(buffer), file) == sizeof(buffer)) {
|
||||
byte_read++;
|
||||
}
|
||||
timer.stop();
|
||||
fclose(file);
|
||||
double test_time_sec = timer.read_us() / 1000000.0;
|
||||
double speed = kib_rw / test_time_sec;
|
||||
printf("%d KiB read in %.3f sec with speed of %.4f KiB/s\r\n", byte_read, test_time_sec, speed);
|
||||
notify_performance_coefficient("fs_read_kibps", speed);
|
||||
} else {
|
||||
printf("File '%s' not opened\r\n", filename);
|
||||
result = false;
|
||||
}
|
||||
timer.reset();
|
||||
return result;
|
||||
}
|
||||
|
||||
char RandomChar() {
|
||||
return rand() % 100;
|
||||
}
|
||||
|
||||
int main() {
|
||||
MBED_HOSTTEST_TIMEOUT(15);
|
||||
MBED_HOSTTEST_SELECT(default_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(SD stdio RW Speed);
|
||||
MBED_HOSTTEST_START("PERF_1");
|
||||
|
||||
// Test header
|
||||
printf("\r\n");
|
||||
printf("SD Card Stdio Performance Test\r\n");
|
||||
printf("File name: %s\r\n", bin_filename);
|
||||
printf("Buffer size: %d KiB\r\n", (KIB_RW * sizeof(buffer)) / 1024);
|
||||
|
||||
// Initialize buffer
|
||||
srand(testenv_randseed());
|
||||
char *buffer_end = buffer + sizeof(buffer);
|
||||
std::generate (buffer, buffer_end, RandomChar);
|
||||
|
||||
bool result = true;
|
||||
for (;;) {
|
||||
printf("Write test...\r\n");
|
||||
if (test_sf_file_write_stdio(bin_filename, KIB_RW) == false) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
printf("Read test...\r\n");
|
||||
if (test_sf_file_read_stdio(bin_filename, KIB_RW) == false) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
MBED_HOSTTEST_RESULT(result);
|
||||
}
|
38
tool/mbed/mbed-sdk/libraries/tests/mbed/semihost/main.cpp
Normal file
38
tool/mbed/mbed-sdk/libraries/tests/mbed/semihost/main.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
#include "test_env.h"
|
||||
#include "semihost_api.h"
|
||||
|
||||
#define MAC_VENDOR_ARM_0 0x00
|
||||
#define MAC_VENDOR_ARM_1 0x02
|
||||
#define MAC_VENDOR_ARM_2 0xF7
|
||||
|
||||
int main() {
|
||||
MBED_HOSTTEST_TIMEOUT(10);
|
||||
MBED_HOSTTEST_SELECT(default_auto);
|
||||
MBED_HOSTTEST_DESCRIPTION(Semihost);
|
||||
MBED_HOSTTEST_START("MBED_22");
|
||||
|
||||
printf("Semihost connected: %s\n", (semihost_connected()) ? ("Yes") : ("No"));
|
||||
|
||||
char uid[DEVICE_ID_LENGTH + 1] = {0};
|
||||
bool result = true;
|
||||
|
||||
const int ret = mbed_interface_uid(uid);
|
||||
if (ret == 0) {
|
||||
printf("UID: %s\r\n", uid);
|
||||
}
|
||||
else {
|
||||
result = false;
|
||||
}
|
||||
|
||||
char mac[6] = {0}; // @param mac A 6-byte array to write the MAC address
|
||||
mbed_mac_address(mac);
|
||||
printf("MAC Address: %02X:%02X:%02X:%02X:%02X:%02X\r\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
|
||||
if (mac[0] == MAC_VENDOR_ARM_0 &&
|
||||
mac[1] == MAC_VENDOR_ARM_1 &&
|
||||
mac[2] == MAC_VENDOR_ARM_2) {
|
||||
printf("MAC Address Prefix: 00:02:F7, Vendor: ARM\r\n");
|
||||
}
|
||||
|
||||
MBED_HOSTTEST_RESULT(result);
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
#include "mbed.h"
|
||||
|
||||
DigitalOut led1(LED1);
|
||||
DigitalOut led2(LED2);
|
||||
|
||||
Serial computer(USBTX, USBRX);
|
||||
|
||||
// This function is called when a character goes into the TX buffer.
|
||||
void txCallback() {
|
||||
led1 = !led1;
|
||||
}
|
||||
|
||||
// This function is called when a character goes into the RX buffer.
|
||||
void rxCallback() {
|
||||
led2 = !led2;
|
||||
computer.putc(computer.getc());
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("start test\n");
|
||||
computer.attach(&txCallback, Serial::TxIrq);
|
||||
computer.attach(&rxCallback, Serial::RxIrq);
|
||||
while (true) {
|
||||
wait(1);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
#include "mbed.h"
|
||||
|
||||
Serial pc(USBTX, USBRX);
|
||||
|
||||
#if defined(TARGET_LPC4088)
|
||||
Serial uart(P4_22, P4_23);
|
||||
#elif defined(TARGET_MAXWSNENV)
|
||||
Serial uart(P0_1, P0_0);
|
||||
#else
|
||||
Serial uart(p9, p10);
|
||||
#endif
|
||||
|
||||
DigitalOut led1(LED1);
|
||||
DigitalOut led2(LED2);
|
||||
|
||||
// This function is called when a character goes into the RX buffer.
|
||||
void rxCallback(void) {
|
||||
led1 = !led1;
|
||||
pc.putc(uart.getc());
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
// Use a deliberatly slow baud to fill up the TX buffer
|
||||
uart.baud(1200);
|
||||
uart.attach(&rxCallback, Serial::RxIrq);
|
||||
|
||||
printf("Starting test loop:\n");
|
||||
wait(1);
|
||||
|
||||
int c = 'A';
|
||||
for (int loop = 0; loop < 512; loop++) {
|
||||
uart.printf("%c", c);
|
||||
c++;
|
||||
if (c > 'Z') c = 'A';
|
||||
}
|
||||
|
||||
while (true) {
|
||||
led2 = !led2;
|
||||
wait(1);
|
||||
}
|
||||
}
|
27
tool/mbed/mbed-sdk/libraries/tests/mbed/sleep/main.cpp
Normal file
27
tool/mbed/mbed-sdk/libraries/tests/mbed/sleep/main.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include "test_env.h"
|
||||
|
||||
#if defined(TARGET_LPC4088)
|
||||
InterruptIn wkp(P2_10);
|
||||
#elif defined(TARGET_K22F)
|
||||
InterruptIn wkp(D0);
|
||||
#elif defined(TARGET_LPC11U68)
|
||||
InterruptIn wkp(P0_16);
|
||||
#else
|
||||
InterruptIn wkp(p14);
|
||||
#endif
|
||||
|
||||
void flip() {
|
||||
printf("button pressed\n");
|
||||
}
|
||||
|
||||
int main() {
|
||||
#if defined(TARGET_LPC11U68)
|
||||
wkp.mode(PullUp);
|
||||
#endif
|
||||
wkp.rise(&flip);
|
||||
|
||||
while (true) {
|
||||
// sleep();
|
||||
deepsleep();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
#include "mbed.h"
|
||||
|
||||
DigitalOut led1(LED1);
|
||||
DigitalOut led2(LED2);
|
||||
Timeout to1;
|
||||
Timeout to2;
|
||||
|
||||
void led1_on() {
|
||||
led1 = !led1;
|
||||
printf("led1\n\r");
|
||||
fflush(stdout);
|
||||
}
|
||||
void led2_on() {
|
||||
led2 = !led2;
|
||||
printf("led2\n\r");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
int main() {
|
||||
led1 = 0;
|
||||
led2 = 0;
|
||||
to1.attach_us(led1_on, 1000000);
|
||||
to2.attach_us(led2_on, 2000000);
|
||||
while (1) {
|
||||
printf("Entering sleep.\n");
|
||||
sleep();
|
||||
}
|
||||
}
|
16
tool/mbed/mbed-sdk/libraries/tests/mbed/spi/main.cpp
Normal file
16
tool/mbed/mbed-sdk/libraries/tests/mbed/spi/main.cpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include "mbed.h"
|
||||
|
||||
SPI spi(p11, p12, p13);
|
||||
DigitalOut latchpin(p10);
|
||||
|
||||
int main() {
|
||||
spi.format(8, 0);
|
||||
spi.frequency(16 * 1000 * 1000);
|
||||
|
||||
latchpin = 0;
|
||||
while (1) {
|
||||
latchpin = 1;
|
||||
spi.write(0);
|
||||
latchpin = 0;
|
||||
}
|
||||
}
|
62
tool/mbed/mbed-sdk/libraries/tests/mbed/spi_ADXL345/main.cpp
Normal file
62
tool/mbed/mbed-sdk/libraries/tests/mbed/spi_ADXL345/main.cpp
Normal 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);
|
||||
}
|
38
tool/mbed/mbed-sdk/libraries/tests/mbed/spi_master/main.cpp
Normal file
38
tool/mbed/mbed-sdk/libraries/tests/mbed/spi_master/main.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
#include "mbed.h"
|
||||
#include "test_env.h"
|
||||
|
||||
#if defined(TARGET_KL25Z)
|
||||
SPI spi(PTD2, PTD3, PTD1); // mosi, miso, sclk
|
||||
DigitalOut cs(PTA13);
|
||||
#elif defined(TARGET_KL05Z)
|
||||
SPI spi(PTA7, PTA6, PTB0); // mosi, miso, sclk
|
||||
DigitalOut cs(PTB1);
|
||||
#elif defined(TARGET_KL46Z)
|
||||
SPI spi(PTD2, PTD3, PTD1); // mosi, miso, sclk
|
||||
DigitalOut cs(PTA13);
|
||||
#elif defined(TARGET_FF_ARDUINO)
|
||||
SPI spi(D11, D12, D13); // mosi, miso, sclk
|
||||
DigitalOut cs(D10);
|
||||
#else
|
||||
SPI spi(p5, p6, p7); // mosi, miso, sclk
|
||||
DigitalOut cs(p8);
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
int data = 0;
|
||||
int res = 0;
|
||||
|
||||
for(int i = 0; i < 30; i++) {
|
||||
|
||||
cs = 0;
|
||||
res = spi.write(data++);
|
||||
cs = 1;
|
||||
|
||||
wait_ms(0.001);
|
||||
|
||||
if ((i > 1) && ((res + 2) != data))
|
||||
notify_completion(false);
|
||||
}
|
||||
|
||||
notify_completion(true);
|
||||
}
|
29
tool/mbed/mbed-sdk/libraries/tests/mbed/spi_slave/main.cpp
Normal file
29
tool/mbed/mbed-sdk/libraries/tests/mbed/spi_slave/main.cpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include "mbed.h"
|
||||
|
||||
#if defined(TARGET_KL25Z)
|
||||
SPISlave device(PTD2, PTD3, PTD1, PTD0); // mosi, miso, sclk, ssel
|
||||
#elif defined(TARGET_nRF51822)
|
||||
SPISlave device(p12, p13, p15, p14); // mosi, miso, sclk, ssel
|
||||
#elif defined(TARGET_LPC812)
|
||||
SPISlave device(P0_14, P0_15, P0_12, P0_13); // mosi, miso, sclk, ssel
|
||||
#elif defined(TARGET_FF_ARDUINO)
|
||||
SPISlave device(D11, D12, D13, D10); // mosi, miso, sclk, ssel
|
||||
#elif defined(TARGET_LPC1114)
|
||||
SPISlave device(dp2, dp1, dp6, dp25); // mosi, miso, sclk, ssel
|
||||
#else
|
||||
SPISlave device(p5, p6, p7, p8); // mosi, miso, sclk, ssel
|
||||
#endif
|
||||
|
||||
|
||||
int main() {
|
||||
uint8_t resp = 0;
|
||||
|
||||
device.reply(resp); // Prime SPI with first reply
|
||||
|
||||
while(1) {
|
||||
if(device.receive()) {
|
||||
resp = device.read(); // Read byte from master and add 1
|
||||
device.reply(resp); // Make this the next reply
|
||||
}
|
||||
}
|
||||
}
|
107
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi1/main.cpp
Normal file
107
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi1/main.cpp
Normal file
|
@ -0,0 +1,107 @@
|
|||
#include "test_env.h"
|
||||
#include "mbed.h"
|
||||
#include "spifi_rom_api.h"
|
||||
|
||||
__attribute__((section("SPIFI_MEM"))) const unsigned char cube_image[] = {
|
||||
137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,
|
||||
0,0,0,150,0,0,0,200,8,2,0,0,0,133,231,143,
|
||||
50,0,0,0,1,115,82,71,66,0,174,206,28,233,0,0,
|
||||
0,4,103,65,77,65,0,0,177,143,11,252,97,5,0,0,
|
||||
0,9,112,72,89,115,0,0,14,195,0,0,14,195,1,199,
|
||||
111,168,100,0,0,156,193,73,68,65,84,120,94,236,253,103,
|
||||
124,27,233,125,54,140,14,48,24,0,51,24,244,94,9,246,
|
||||
0,0,0,0,73,69,78,68,174,66,96,130};
|
||||
|
||||
int cube_image_sz = sizeof(cube_image);
|
||||
|
||||
const unsigned char cube_image_ref[] = {
|
||||
137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,
|
||||
0,0,0,150,0,0,0,200,8,2,0,0,0,133,231,143,
|
||||
50,0,0,0,1,115,82,71,66,0,174,206,28,233,0,0,
|
||||
0,4,103,65,77,65,0,0,177,143,11,252,97,5,0,0,
|
||||
0,9,112,72,89,115,0,0,14,195,0,0,14,195,1,199,
|
||||
111,168,100,0,0,156,193,73,68,65,84,120,94,236,253,103,
|
||||
124,27,233,125,54,140,14,48,24,0,51,24,244,94,9,246,
|
||||
0,0,0,0,73,69,78,68,174,66,96,130};
|
||||
|
||||
int cube_image_ref_sz = sizeof(cube_image_ref);
|
||||
|
||||
/*
|
||||
* The SPIFI_ROM_PTR (0x1FFF1FF8) points to an area where the pointers to
|
||||
* different drivers in ROM are stored.
|
||||
*/
|
||||
typedef struct {
|
||||
/*const*/ unsigned p_usbd; // USBROMD
|
||||
/*const*/ unsigned p_clib;
|
||||
/*const*/ unsigned p_cand;
|
||||
/*const*/ unsigned p_pwrd; // PWRROMD
|
||||
/*const*/ unsigned p_promd; // DIVROMD
|
||||
/*const*/ SPIFI_RTNS *pSPIFID; // SPIFIROMD
|
||||
/*const*/ unsigned p_dev3;
|
||||
/*const*/ unsigned p_dev4;
|
||||
} ROM;
|
||||
|
||||
#define ROM_DRIVERS_PTR ((ROM *)(*((unsigned int *)SPIFI_ROM_PTR)))
|
||||
#define IS_ADDR_IN_SPIFI(__addr) ( (((uint32_t)(__addr)) & 0xff000000) == SPIFI_MEM_BASE )
|
||||
#define IS_ADDR_IN_IFLASH(__addr) ( (((uint32_t)(__addr)) & 0xff000000) == 0x10000000 )
|
||||
|
||||
static void initialize_spifi(void)
|
||||
{
|
||||
SPIFIobj* obj = (SPIFIobj*)malloc(sizeof(SPIFIobj));
|
||||
if (obj == NULL) {
|
||||
// Failed to allocate memory for ROM data
|
||||
notify_completion(false);
|
||||
}
|
||||
|
||||
// Turn on SPIFI block as it is disabled on reset
|
||||
LPC_SC->PCONP |= 0x00010000;
|
||||
|
||||
// pinsel for SPIFI
|
||||
LPC_IOCON->P2_7 = 5; /* SPIFI_CSN @ P2.7 */
|
||||
LPC_IOCON->P0_22 = 5; /* SPIFI_CLK @ P0.22 */
|
||||
LPC_IOCON->P0_15 = 5; /* SPIFI_IO2 @ P0.15 */
|
||||
LPC_IOCON->P0_16 = 5; /* SPIFI_IO3 @ P0.16 */
|
||||
LPC_IOCON->P0_17 = 5; /* SPIFI_IO1 @ P0.17 */
|
||||
LPC_IOCON->P0_18 = 5; /* SPIFI_IO0 @ P0.18 */
|
||||
|
||||
uint32_t spifi_clk_div = (*((volatile uint32_t*)0x400FC1B4)) & 0x1f;
|
||||
uint32_t spifi_clk_mhz = (SystemCoreClock / spifi_clk_div) / 1000000;
|
||||
|
||||
const SPIFI_RTNS* _spifi = ROM_DRIVERS_PTR->pSPIFID;
|
||||
|
||||
/* Typical time tCS is 20 ns min, we give 200 ns to be on safer side */
|
||||
int rc = _spifi->spifi_init (obj, spifi_clk_mhz/5, S_FULLCLK+S_RCVCLK, spifi_clk_mhz);
|
||||
if (rc) {
|
||||
// Failed to initialize SPIFI
|
||||
notify_completion(false);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
initialize_spifi();
|
||||
|
||||
// Make sure that cube_image is placed in SPIFI
|
||||
if (!IS_ADDR_IN_SPIFI(cube_image)) {
|
||||
notify_completion(false);
|
||||
}
|
||||
|
||||
// Make sure that cube_image_ref is in IFLASH
|
||||
if (IS_ADDR_IN_SPIFI(cube_image_ref)) {
|
||||
notify_completion(false);
|
||||
}
|
||||
|
||||
// Compare content
|
||||
if (cube_image_sz != cube_image_ref_sz) {
|
||||
notify_completion(false);
|
||||
} else {
|
||||
int i = 0;
|
||||
for (; i < cube_image_sz; i++) {
|
||||
if (cube_image[i] != cube_image_ref[i]) {
|
||||
notify_completion(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
notify_completion(true);
|
||||
}
|
165
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi1/spifi_rom_api.h
Normal file
165
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi1/spifi_rom_api.h
Normal file
|
@ -0,0 +1,165 @@
|
|||
/* definitions for ROM API for SPIFI in NXP MCUs
|
||||
copyright (c) 2010 NXP Semiconductors
|
||||
written by CAM start 4/16/10
|
||||
first testing 5/12/10
|
||||
OK with first SST & Winbond devices 6/8/10
|
||||
OK with Gigadevice, Numonyx, Atmel,
|
||||
some Macronyx 7/13/10
|
||||
consensus with BK, performance optimized 8/24/10
|
||||
this file is largely platform-independent */
|
||||
|
||||
#ifndef SPIFI_ROM_API_H
|
||||
#define SPIFI_ROM_API_H
|
||||
|
||||
|
||||
#define SPIFI_MEM_BASE 0x28000000
|
||||
/* allocated size of the SPIFI memory area on this device */
|
||||
#define MEM_AREA_SIZE 0x00001000
|
||||
#define SPIFI_ROM_PTR 0x1FFF1FF8
|
||||
|
||||
/* define the symbol TESTING in the environment if test output desired */
|
||||
|
||||
/* maintain LONGEST_PROT >= the length (in bytes) of the largest
|
||||
protection block of any serial flash that this driver handles */
|
||||
#define LONGEST_PROT 68
|
||||
|
||||
/* protection/sector descriptors */
|
||||
typedef struct {
|
||||
unsigned base;
|
||||
uint8_t flags;
|
||||
signed char log2;
|
||||
uint16_t rept;
|
||||
} protEnt;
|
||||
|
||||
typedef union {
|
||||
uint16_t hw;
|
||||
uint8_t byte[2];
|
||||
}stat_t;
|
||||
|
||||
/* the object that init returns, and other routines use as an operand */
|
||||
typedef struct {
|
||||
unsigned base, regbase, devSize, memSize;
|
||||
uint8_t mfger, devType, devID, busy;
|
||||
stat_t stat;
|
||||
uint16_t reserved;
|
||||
uint16_t set_prot, write_prot;
|
||||
unsigned mem_cmd, prog_cmd;
|
||||
uint16_t sectors, protBytes;
|
||||
unsigned opts, errCheck;
|
||||
uint8_t erase_shifts[4], erase_ops[4];
|
||||
protEnt *protEnts;
|
||||
char prot[LONGEST_PROT];
|
||||
} SPIFIobj;
|
||||
|
||||
/* operands of program and erase */
|
||||
typedef struct {
|
||||
char *dest; /* starting address for programming or erasing */
|
||||
unsigned length; /* number of bytes to be programmed or erased */
|
||||
char *scratch; /* address of work area or NULL */
|
||||
int protect; /* protection to apply after programming/erasing is done */
|
||||
unsigned options; /* see the table below */
|
||||
} SPIFIopers;
|
||||
|
||||
|
||||
/* bits in options operands (MODE3, RCVCLK, and FULLCLK
|
||||
have the same relationship as in the Control register) */
|
||||
#define S_MODE3 1
|
||||
#define S_MODE0 0
|
||||
#define S_MINIMAL 2
|
||||
#define S_MAXIMAL 0
|
||||
#define S_FORCE_ERASE 4
|
||||
#define S_ERASE_NOT_REQD 8
|
||||
#define S_CALLER_ERASE 8
|
||||
#define S_ERASE_AS_REQD 0
|
||||
#define S_VERIFY_PROG 0x10
|
||||
#define S_VERIFY_ERASE 0x20
|
||||
#define S_NO_VERIFY 0
|
||||
#define S_RCVCLK 0x80
|
||||
#define S_INTCLK 0
|
||||
#define S_FULLCLK 0x40
|
||||
#define S_HALFCLK 0
|
||||
#define S_DUAL 0x100
|
||||
#define S_CALLER_PROT 0x200
|
||||
#define S_DRIVER_PROT 0
|
||||
|
||||
/* the length of a standard program command is 256 on all devices */
|
||||
#define PROG_SIZE 256
|
||||
|
||||
/* interface to ROM API */
|
||||
typedef struct {
|
||||
int (*spifi_init) (SPIFIobj *obj, unsigned csHigh, unsigned options,
|
||||
unsigned mhz);
|
||||
int (*spifi_program) (SPIFIobj *obj, char *source, SPIFIopers *opers);
|
||||
int (*spifi_erase) (SPIFIobj *obj, SPIFIopers *opers);
|
||||
/* mode switching */
|
||||
void (*cancel_mem_mode)(SPIFIobj *obj);
|
||||
void (*set_mem_mode) (SPIFIobj *obj);
|
||||
|
||||
/* mid level functions */
|
||||
int (*checkAd) (SPIFIobj *obj, SPIFIopers *opers);
|
||||
int (*setProt) (SPIFIobj *obj, SPIFIopers *opers, char *change,
|
||||
char *saveProt);
|
||||
int (*check_block) (SPIFIobj *obj, char *source, SPIFIopers *opers,
|
||||
unsigned check_program);
|
||||
int (*send_erase_cmd) (SPIFIobj *obj, unsigned char op, unsigned addr);
|
||||
unsigned (*ck_erase) (SPIFIobj *obj, unsigned *addr, unsigned length);
|
||||
int (*prog_block) (SPIFIobj *obj, char *source, SPIFIopers *opers,
|
||||
unsigned *left_in_page);
|
||||
unsigned (*ck_prog) (SPIFIobj *obj, char *source, char *dest, unsigned length);
|
||||
|
||||
/* low level functions */
|
||||
void(*setSize) (SPIFIobj *obj, int value);
|
||||
int (*setDev) (SPIFIobj *obj, unsigned opts, unsigned mem_cmd,
|
||||
unsigned prog_cmd);
|
||||
unsigned (*cmd) (uint8_t op, uint8_t addrLen, uint8_t intLen, unsigned short len);
|
||||
unsigned (*readAd) (SPIFIobj *obj, unsigned cmd, unsigned addr);
|
||||
void (*send04) (SPIFIobj *obj, uint8_t op, uint8_t len, unsigned value);
|
||||
void (*wren_sendAd) (SPIFIobj *obj, unsigned cmd, unsigned addr, unsigned value);
|
||||
int (*write_stat) (SPIFIobj *obj, uint8_t len, uint16_t value);
|
||||
int (*wait_busy) (SPIFIobj *obj, uint8_t prog_or_erase);
|
||||
} SPIFI_RTNS;
|
||||
|
||||
//#define define_spifi_romPtr(name) const SPIFI_RTNS *name=*((SPIFI_RTNS **)SPIFI_ROM_PTR)
|
||||
|
||||
/* example of using this interface:
|
||||
#include "spifi_rom_api.h"
|
||||
#define CSHIGH 4
|
||||
#define SPIFI_MHZ 80
|
||||
#define source_data_ad (char *)1234
|
||||
|
||||
int rc;
|
||||
SPIFIopers opers;
|
||||
|
||||
define_spifi_romPtr(spifi);
|
||||
SPIFIobj *obj = malloc(sizeof(SPIFIobj));
|
||||
if (!obj) { can't allocate memory }
|
||||
|
||||
rc = spifi->spifi_init (obj, CSHIGH, S_FULLCLK+S_RCVCLK, SPIFI_MHZ);
|
||||
if (rc) { investigate init error rc }
|
||||
printf ("the serial flash contains %d bytes\n", obj->devSize);
|
||||
|
||||
opers.dest = where_to_program;
|
||||
opers.length = how_many_bytes;
|
||||
opers.scratch = NULL; // unprogrammed data is not saved/restored
|
||||
opers.protect = -1; // save & restore protection
|
||||
opers.options = S_VERIFY_PROG;
|
||||
|
||||
rc = spifi->spifi_program (obj, source_data_ad, &opers);
|
||||
if (rc) { investigate program error rc }
|
||||
*/
|
||||
|
||||
/* these are for normal users, including boot code */
|
||||
int spifi_init (SPIFIobj *obj, unsigned csHigh, unsigned options, unsigned mhz);
|
||||
int spifi_program (SPIFIobj *obj, char *source, SPIFIopers *opers);
|
||||
int spifi_erase (SPIFIobj *obj, SPIFIopers *opers);
|
||||
|
||||
/* these are used by the manufacturer-specific init functions */
|
||||
void setSize (SPIFIobj *obj, int value);
|
||||
int setDev (SPIFIobj *obj, unsigned opts, unsigned mem_cmd, unsigned prog_cmd);
|
||||
unsigned read04(SPIFIobj *obj, uint8_t op, uint8_t len);
|
||||
int write_stat (SPIFIobj *obj, uint8_t len, uint16_t value);
|
||||
void setProtEnts(SPIFIobj *obj, const protEnt *p, unsigned protTabLen);
|
||||
|
||||
#endif
|
||||
|
||||
|
100
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/main.cpp
Normal file
100
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/main.cpp
Normal file
|
@ -0,0 +1,100 @@
|
|||
#include "test_env.h"
|
||||
#include "mbed.h"
|
||||
#include "spifi_rom_api.h"
|
||||
|
||||
extern const unsigned char splash_image1[]; extern int splash_image1_sz;
|
||||
extern const unsigned char splash_image2[]; extern int splash_image2_sz;
|
||||
extern const unsigned char splash_image3[]; extern int splash_image3_sz;
|
||||
extern const unsigned char splash_image4[]; extern int splash_image4_sz;
|
||||
extern const unsigned char splash_image5[]; extern int splash_image5_sz;
|
||||
extern const unsigned char splash_image6[]; extern int splash_image6_sz;
|
||||
extern const unsigned char splash_image7[]; extern int splash_image7_sz;
|
||||
extern const unsigned char splash_image8[]; extern int splash_image8_sz;
|
||||
extern const unsigned char splash_image9[]; extern int splash_image9_sz;
|
||||
extern const unsigned char splash_image10[]; extern int splash_image10_sz;
|
||||
extern const unsigned char splash_image11[]; extern int splash_image11_sz;
|
||||
extern const unsigned char splash_image12[]; extern int splash_image12_sz;
|
||||
extern const unsigned char splash_image13[]; extern int splash_image13_sz;
|
||||
extern const unsigned char splash_image14[]; extern int splash_image14_sz;
|
||||
extern const unsigned char splash_image15[]; extern int splash_image15_sz;
|
||||
|
||||
/*
|
||||
* The SPIFI_ROM_PTR (0x1FFF1FF8) points to an area where the pointers to
|
||||
* different drivers in ROM are stored.
|
||||
*/
|
||||
typedef struct {
|
||||
/*const*/ unsigned p_usbd; // USBROMD
|
||||
/*const*/ unsigned p_clib;
|
||||
/*const*/ unsigned p_cand;
|
||||
/*const*/ unsigned p_pwrd; // PWRROMD
|
||||
/*const*/ unsigned p_promd; // DIVROMD
|
||||
/*const*/ SPIFI_RTNS *pSPIFID; // SPIFIROMD
|
||||
/*const*/ unsigned p_dev3;
|
||||
/*const*/ unsigned p_dev4;
|
||||
} ROM;
|
||||
|
||||
#define ROM_DRIVERS_PTR ((ROM *)(*((unsigned int *)SPIFI_ROM_PTR)))
|
||||
#define IS_ADDR_IN_SPIFI(__addr) ( (((uint32_t)(__addr)) & 0xff000000) == SPIFI_MEM_BASE )
|
||||
#define IS_ADDR_IN_IFLASH(__addr) ( (((uint32_t)(__addr)) & 0xff000000) == 0x10000000 )
|
||||
|
||||
static void initialize_spifi(void)
|
||||
{
|
||||
SPIFIobj* obj = (SPIFIobj*)malloc(sizeof(SPIFIobj));
|
||||
if (obj == NULL) {
|
||||
// Failed to allocate memory for ROM data
|
||||
notify_completion(false);
|
||||
}
|
||||
|
||||
// Turn on SPIFI block as it is disabled on reset
|
||||
LPC_SC->PCONP |= 0x00010000;
|
||||
|
||||
// pinsel for SPIFI
|
||||
LPC_IOCON->P2_7 = 5; /* SPIFI_CSN @ P2.7 */
|
||||
LPC_IOCON->P0_22 = 5; /* SPIFI_CLK @ P0.22 */
|
||||
LPC_IOCON->P0_15 = 5; /* SPIFI_IO2 @ P0.15 */
|
||||
LPC_IOCON->P0_16 = 5; /* SPIFI_IO3 @ P0.16 */
|
||||
LPC_IOCON->P0_17 = 5; /* SPIFI_IO1 @ P0.17 */
|
||||
LPC_IOCON->P0_18 = 5; /* SPIFI_IO0 @ P0.18 */
|
||||
|
||||
uint32_t spifi_clk_div = (*((volatile uint32_t*)0x400FC1B4)) & 0x1f;
|
||||
uint32_t spifi_clk_mhz = (SystemCoreClock / spifi_clk_div) / 1000000;
|
||||
|
||||
const SPIFI_RTNS* _spifi = ROM_DRIVERS_PTR->pSPIFID;
|
||||
|
||||
/* Typical time tCS is 20 ns min, we give 200 ns to be on safer side */
|
||||
int rc = _spifi->spifi_init (obj, spifi_clk_mhz/5, S_FULLCLK+S_RCVCLK, spifi_clk_mhz);
|
||||
if (rc) {
|
||||
// Failed to initialize SPIFI
|
||||
notify_completion(false);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
initialize_spifi();
|
||||
|
||||
// Make sure that most files are placed in IFLASH
|
||||
if (IS_ADDR_IN_SPIFI(splash_image1) ||
|
||||
IS_ADDR_IN_SPIFI(splash_image2) ||
|
||||
IS_ADDR_IN_SPIFI(splash_image3) ||
|
||||
IS_ADDR_IN_SPIFI(splash_image4) ||
|
||||
IS_ADDR_IN_SPIFI(splash_image5) ||
|
||||
IS_ADDR_IN_SPIFI(splash_image6) ||
|
||||
IS_ADDR_IN_SPIFI(splash_image7) ||
|
||||
IS_ADDR_IN_SPIFI(splash_image8) ||
|
||||
IS_ADDR_IN_SPIFI(splash_image9) ||
|
||||
IS_ADDR_IN_SPIFI(splash_image10) ||
|
||||
IS_ADDR_IN_SPIFI(splash_image11) ||
|
||||
IS_ADDR_IN_SPIFI(splash_image12) ||
|
||||
IS_ADDR_IN_SPIFI(splash_image13) ||
|
||||
IS_ADDR_IN_SPIFI(splash_image14)) {
|
||||
notify_completion(false);
|
||||
}
|
||||
|
||||
// Make sure that splash_image15 is placed in SPIFI
|
||||
if (!IS_ADDR_IN_SPIFI(splash_image15)) {
|
||||
notify_completion(false);
|
||||
}
|
||||
|
||||
notify_completion(true);
|
||||
}
|
165
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/spifi_rom_api.h
Normal file
165
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/spifi_rom_api.h
Normal file
|
@ -0,0 +1,165 @@
|
|||
/* definitions for ROM API for SPIFI in NXP MCUs
|
||||
copyright (c) 2010 NXP Semiconductors
|
||||
written by CAM start 4/16/10
|
||||
first testing 5/12/10
|
||||
OK with first SST & Winbond devices 6/8/10
|
||||
OK with Gigadevice, Numonyx, Atmel,
|
||||
some Macronyx 7/13/10
|
||||
consensus with BK, performance optimized 8/24/10
|
||||
this file is largely platform-independent */
|
||||
|
||||
#ifndef SPIFI_ROM_API_H
|
||||
#define SPIFI_ROM_API_H
|
||||
|
||||
|
||||
#define SPIFI_MEM_BASE 0x28000000
|
||||
/* allocated size of the SPIFI memory area on this device */
|
||||
#define MEM_AREA_SIZE 0x00001000
|
||||
#define SPIFI_ROM_PTR 0x1FFF1FF8
|
||||
|
||||
/* define the symbol TESTING in the environment if test output desired */
|
||||
|
||||
/* maintain LONGEST_PROT >= the length (in bytes) of the largest
|
||||
protection block of any serial flash that this driver handles */
|
||||
#define LONGEST_PROT 68
|
||||
|
||||
/* protection/sector descriptors */
|
||||
typedef struct {
|
||||
unsigned base;
|
||||
uint8_t flags;
|
||||
signed char log2;
|
||||
uint16_t rept;
|
||||
} protEnt;
|
||||
|
||||
typedef union {
|
||||
uint16_t hw;
|
||||
uint8_t byte[2];
|
||||
}stat_t;
|
||||
|
||||
/* the object that init returns, and other routines use as an operand */
|
||||
typedef struct {
|
||||
unsigned base, regbase, devSize, memSize;
|
||||
uint8_t mfger, devType, devID, busy;
|
||||
stat_t stat;
|
||||
uint16_t reserved;
|
||||
uint16_t set_prot, write_prot;
|
||||
unsigned mem_cmd, prog_cmd;
|
||||
uint16_t sectors, protBytes;
|
||||
unsigned opts, errCheck;
|
||||
uint8_t erase_shifts[4], erase_ops[4];
|
||||
protEnt *protEnts;
|
||||
char prot[LONGEST_PROT];
|
||||
} SPIFIobj;
|
||||
|
||||
/* operands of program and erase */
|
||||
typedef struct {
|
||||
char *dest; /* starting address for programming or erasing */
|
||||
unsigned length; /* number of bytes to be programmed or erased */
|
||||
char *scratch; /* address of work area or NULL */
|
||||
int protect; /* protection to apply after programming/erasing is done */
|
||||
unsigned options; /* see the table below */
|
||||
} SPIFIopers;
|
||||
|
||||
|
||||
/* bits in options operands (MODE3, RCVCLK, and FULLCLK
|
||||
have the same relationship as in the Control register) */
|
||||
#define S_MODE3 1
|
||||
#define S_MODE0 0
|
||||
#define S_MINIMAL 2
|
||||
#define S_MAXIMAL 0
|
||||
#define S_FORCE_ERASE 4
|
||||
#define S_ERASE_NOT_REQD 8
|
||||
#define S_CALLER_ERASE 8
|
||||
#define S_ERASE_AS_REQD 0
|
||||
#define S_VERIFY_PROG 0x10
|
||||
#define S_VERIFY_ERASE 0x20
|
||||
#define S_NO_VERIFY 0
|
||||
#define S_RCVCLK 0x80
|
||||
#define S_INTCLK 0
|
||||
#define S_FULLCLK 0x40
|
||||
#define S_HALFCLK 0
|
||||
#define S_DUAL 0x100
|
||||
#define S_CALLER_PROT 0x200
|
||||
#define S_DRIVER_PROT 0
|
||||
|
||||
/* the length of a standard program command is 256 on all devices */
|
||||
#define PROG_SIZE 256
|
||||
|
||||
/* interface to ROM API */
|
||||
typedef struct {
|
||||
int (*spifi_init) (SPIFIobj *obj, unsigned csHigh, unsigned options,
|
||||
unsigned mhz);
|
||||
int (*spifi_program) (SPIFIobj *obj, char *source, SPIFIopers *opers);
|
||||
int (*spifi_erase) (SPIFIobj *obj, SPIFIopers *opers);
|
||||
/* mode switching */
|
||||
void (*cancel_mem_mode)(SPIFIobj *obj);
|
||||
void (*set_mem_mode) (SPIFIobj *obj);
|
||||
|
||||
/* mid level functions */
|
||||
int (*checkAd) (SPIFIobj *obj, SPIFIopers *opers);
|
||||
int (*setProt) (SPIFIobj *obj, SPIFIopers *opers, char *change,
|
||||
char *saveProt);
|
||||
int (*check_block) (SPIFIobj *obj, char *source, SPIFIopers *opers,
|
||||
unsigned check_program);
|
||||
int (*send_erase_cmd) (SPIFIobj *obj, unsigned char op, unsigned addr);
|
||||
unsigned (*ck_erase) (SPIFIobj *obj, unsigned *addr, unsigned length);
|
||||
int (*prog_block) (SPIFIobj *obj, char *source, SPIFIopers *opers,
|
||||
unsigned *left_in_page);
|
||||
unsigned (*ck_prog) (SPIFIobj *obj, char *source, char *dest, unsigned length);
|
||||
|
||||
/* low level functions */
|
||||
void(*setSize) (SPIFIobj *obj, int value);
|
||||
int (*setDev) (SPIFIobj *obj, unsigned opts, unsigned mem_cmd,
|
||||
unsigned prog_cmd);
|
||||
unsigned (*cmd) (uint8_t op, uint8_t addrLen, uint8_t intLen, unsigned short len);
|
||||
unsigned (*readAd) (SPIFIobj *obj, unsigned cmd, unsigned addr);
|
||||
void (*send04) (SPIFIobj *obj, uint8_t op, uint8_t len, unsigned value);
|
||||
void (*wren_sendAd) (SPIFIobj *obj, unsigned cmd, unsigned addr, unsigned value);
|
||||
int (*write_stat) (SPIFIobj *obj, uint8_t len, uint16_t value);
|
||||
int (*wait_busy) (SPIFIobj *obj, uint8_t prog_or_erase);
|
||||
} SPIFI_RTNS;
|
||||
|
||||
//#define define_spifi_romPtr(name) const SPIFI_RTNS *name=*((SPIFI_RTNS **)SPIFI_ROM_PTR)
|
||||
|
||||
/* example of using this interface:
|
||||
#include "spifi_rom_api.h"
|
||||
#define CSHIGH 4
|
||||
#define SPIFI_MHZ 80
|
||||
#define source_data_ad (char *)1234
|
||||
|
||||
int rc;
|
||||
SPIFIopers opers;
|
||||
|
||||
define_spifi_romPtr(spifi);
|
||||
SPIFIobj *obj = malloc(sizeof(SPIFIobj));
|
||||
if (!obj) { can't allocate memory }
|
||||
|
||||
rc = spifi->spifi_init (obj, CSHIGH, S_FULLCLK+S_RCVCLK, SPIFI_MHZ);
|
||||
if (rc) { investigate init error rc }
|
||||
printf ("the serial flash contains %d bytes\n", obj->devSize);
|
||||
|
||||
opers.dest = where_to_program;
|
||||
opers.length = how_many_bytes;
|
||||
opers.scratch = NULL; // unprogrammed data is not saved/restored
|
||||
opers.protect = -1; // save & restore protection
|
||||
opers.options = S_VERIFY_PROG;
|
||||
|
||||
rc = spifi->spifi_program (obj, source_data_ad, &opers);
|
||||
if (rc) { investigate program error rc }
|
||||
*/
|
||||
|
||||
/* these are for normal users, including boot code */
|
||||
int spifi_init (SPIFIobj *obj, unsigned csHigh, unsigned options, unsigned mhz);
|
||||
int spifi_program (SPIFIobj *obj, char *source, SPIFIopers *opers);
|
||||
int spifi_erase (SPIFIobj *obj, SPIFIopers *opers);
|
||||
|
||||
/* these are used by the manufacturer-specific init functions */
|
||||
void setSize (SPIFIobj *obj, int value);
|
||||
int setDev (SPIFIobj *obj, unsigned opts, unsigned mem_cmd, unsigned prog_cmd);
|
||||
unsigned read04(SPIFIobj *obj, uint8_t op, uint8_t len);
|
||||
int write_stat (SPIFIobj *obj, uint8_t len, uint16_t value);
|
||||
void setProtEnts(SPIFIobj *obj, const protEnt *p, unsigned protTabLen);
|
||||
|
||||
#endif
|
||||
|
||||
|
2167
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage01.c
Normal file
2167
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage01.c
Normal file
File diff suppressed because it is too large
Load diff
2167
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage02.c
Normal file
2167
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage02.c
Normal file
File diff suppressed because it is too large
Load diff
2167
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage03.c
Normal file
2167
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage03.c
Normal file
File diff suppressed because it is too large
Load diff
2167
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage04.c
Normal file
2167
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage04.c
Normal file
File diff suppressed because it is too large
Load diff
2167
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage05.c
Normal file
2167
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage05.c
Normal file
File diff suppressed because it is too large
Load diff
2167
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage06.c
Normal file
2167
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage06.c
Normal file
File diff suppressed because it is too large
Load diff
2167
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage07.c
Normal file
2167
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage07.c
Normal file
File diff suppressed because it is too large
Load diff
2167
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage08.c
Normal file
2167
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage08.c
Normal file
File diff suppressed because it is too large
Load diff
2167
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage09.c
Normal file
2167
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage09.c
Normal file
File diff suppressed because it is too large
Load diff
2167
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage10.c
Normal file
2167
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage10.c
Normal file
File diff suppressed because it is too large
Load diff
2168
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage11.c
Normal file
2168
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage11.c
Normal file
File diff suppressed because it is too large
Load diff
2168
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage12.c
Normal file
2168
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage12.c
Normal file
File diff suppressed because it is too large
Load diff
2168
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage13.c
Normal file
2168
tool/mbed/mbed-sdk/libraries/tests/mbed/spifi2/splashImage13.c
Normal file
File diff suppressed because it is too large
Load diff
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue