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
22
tool/mbed/mbed-sdk/libraries/tests/rtos/cmsis/basic/main.cpp
Normal file
22
tool/mbed/mbed-sdk/libraries/tests/rtos/cmsis/basic/main.cpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
#include "mbed.h"
|
||||
#include "cmsis_os.h"
|
||||
|
||||
DigitalOut led1(LED1);
|
||||
DigitalOut led2(LED2);
|
||||
|
||||
void led2_thread(void const *argument) {
|
||||
while (true) {
|
||||
led2 = !led2;
|
||||
osDelay(1000);
|
||||
}
|
||||
}
|
||||
osThreadDef(led2_thread, osPriorityNormal, DEFAULT_STACK_SIZE);
|
||||
|
||||
int main() {
|
||||
osThreadCreate(osThread(led2_thread), NULL);
|
||||
|
||||
while (true) {
|
||||
led1 = !led1;
|
||||
osDelay(500);
|
||||
}
|
||||
}
|
34
tool/mbed/mbed-sdk/libraries/tests/rtos/cmsis/isr/main.cpp
Normal file
34
tool/mbed/mbed-sdk/libraries/tests/rtos/cmsis/isr/main.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
#include "mbed.h"
|
||||
#include "rtos.h"
|
||||
|
||||
Queue<uint32_t, 5> queue;
|
||||
|
||||
DigitalOut myled(LED1);
|
||||
|
||||
void queue_isr() {
|
||||
queue.put((uint32_t*)2);
|
||||
myled = !myled;
|
||||
}
|
||||
|
||||
void queue_thread(void const *argument) {
|
||||
while (true) {
|
||||
queue.put((uint32_t*)1);
|
||||
Thread::wait(1000);
|
||||
}
|
||||
}
|
||||
|
||||
int main (void) {
|
||||
Thread thread(queue_thread);
|
||||
|
||||
Ticker ticker;
|
||||
ticker.attach(queue_isr, 1.0);
|
||||
|
||||
while (true) {
|
||||
osEvent evt = queue.get();
|
||||
if (evt.status != osEventMessage) {
|
||||
printf("queue->get() returned %02x status\n\r", evt.status);
|
||||
} else {
|
||||
printf("queue->get() returned %d\n\r", evt.value.v);
|
||||
}
|
||||
}
|
||||
}
|
43
tool/mbed/mbed-sdk/libraries/tests/rtos/cmsis/mail/main.cpp
Normal file
43
tool/mbed/mbed-sdk/libraries/tests/rtos/cmsis/mail/main.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include "mbed.h"
|
||||
#include "cmsis_os.h"
|
||||
|
||||
typedef struct {
|
||||
float voltage; /* AD result of measured voltage */
|
||||
float current; /* AD result of measured current */
|
||||
uint32_t counter; /* A counter value */
|
||||
} mail_t;
|
||||
|
||||
osMailQDef(mail_box, 16, mail_t);
|
||||
osMailQId mail_box;
|
||||
|
||||
void send_thread (void const *argument) {
|
||||
uint32_t i = 0;
|
||||
while (true) {
|
||||
i++; // fake data update
|
||||
mail_t *mail = (mail_t*)osMailAlloc(mail_box, osWaitForever);
|
||||
mail->voltage = (i * 0.1) * 33;
|
||||
mail->current = (i * 0.1) * 11;
|
||||
mail->counter = i;
|
||||
osMailPut(mail_box, mail);
|
||||
osDelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
osThreadDef(send_thread, osPriorityNormal, DEFAULT_STACK_SIZE);
|
||||
|
||||
int main (void) {
|
||||
mail_box = osMailCreate(osMailQ(mail_box), NULL);
|
||||
osThreadCreate(osThread(send_thread), NULL);
|
||||
|
||||
while (true) {
|
||||
osEvent evt = osMailGet(mail_box, osWaitForever);
|
||||
if (evt.status == osEventMail) {
|
||||
mail_t *mail = (mail_t*)evt.value.p;
|
||||
printf("\nVoltage: %.2f V\n\r" , mail->voltage);
|
||||
printf("Current: %.2f A\n\r" , mail->current);
|
||||
printf("Number of cycles: %u\n\r", mail->counter);
|
||||
|
||||
osMailFree(mail_box, mail);
|
||||
}
|
||||
}
|
||||
}
|
33
tool/mbed/mbed-sdk/libraries/tests/rtos/cmsis/mutex/main.cpp
Normal file
33
tool/mbed/mbed-sdk/libraries/tests/rtos/cmsis/mutex/main.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include "mbed.h"
|
||||
#include "cmsis_os.h"
|
||||
|
||||
osMutexId stdio_mutex;
|
||||
osMutexDef(stdio_mutex);
|
||||
|
||||
void notify(const char* name, int state) {
|
||||
osMutexWait(stdio_mutex, osWaitForever);
|
||||
printf("%s: %d\n\r", name, state);
|
||||
osMutexRelease(stdio_mutex);
|
||||
}
|
||||
|
||||
void test_thread(void const *args) {
|
||||
while (true) {
|
||||
notify((const char*)args, 0); osDelay(1000);
|
||||
notify((const char*)args, 1); osDelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
void t2(void const *argument) {test_thread("Th 2");}
|
||||
osThreadDef(t2, osPriorityNormal, DEFAULT_STACK_SIZE);
|
||||
|
||||
void t3(void const *argument) {test_thread("Th 3");}
|
||||
osThreadDef(t3, osPriorityNormal, DEFAULT_STACK_SIZE);
|
||||
|
||||
int main() {
|
||||
stdio_mutex = osMutexCreate(osMutex(stdio_mutex));
|
||||
|
||||
osThreadCreate(osThread(t2), NULL);
|
||||
osThreadCreate(osThread(t3), NULL);
|
||||
|
||||
test_thread((void *)"Th 1");
|
||||
}
|
48
tool/mbed/mbed-sdk/libraries/tests/rtos/cmsis/queue/main.cpp
Normal file
48
tool/mbed/mbed-sdk/libraries/tests/rtos/cmsis/queue/main.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include "mbed.h"
|
||||
#include "cmsis_os.h"
|
||||
|
||||
typedef struct {
|
||||
float voltage; /* AD result of measured voltage */
|
||||
float current; /* AD result of measured current */
|
||||
uint32_t counter; /* A counter value */
|
||||
} message_t;
|
||||
|
||||
osPoolDef(mpool, 16, message_t);
|
||||
osPoolId mpool;
|
||||
|
||||
osMessageQDef(queue, 16, message_t);
|
||||
osMessageQId queue;
|
||||
|
||||
void send_thread (void const *argument) {
|
||||
uint32_t i = 0;
|
||||
while (true) {
|
||||
i++; // fake data update
|
||||
message_t *message = (message_t*)osPoolAlloc(mpool);
|
||||
message->voltage = (i * 0.1) * 33;
|
||||
message->current = (i * 0.1) * 11;
|
||||
message->counter = i;
|
||||
osMessagePut(queue, (uint32_t)message, osWaitForever);
|
||||
osDelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
osThreadDef(send_thread, osPriorityNormal, DEFAULT_STACK_SIZE);
|
||||
|
||||
int main (void) {
|
||||
mpool = osPoolCreate(osPool(mpool));
|
||||
queue = osMessageCreate(osMessageQ(queue), NULL);
|
||||
|
||||
osThreadCreate(osThread(send_thread), NULL);
|
||||
|
||||
while (true) {
|
||||
osEvent evt = osMessageGet(queue, osWaitForever);
|
||||
if (evt.status == osEventMessage) {
|
||||
message_t *message = (message_t*)evt.value.p;
|
||||
printf("\nVoltage: %.2f V\n\r" , message->voltage);
|
||||
printf("Current: %.2f A\n\r" , message->current);
|
||||
printf("Number of cycles: %u\n\r", message->counter);
|
||||
|
||||
osPoolFree(mpool, message);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
#include "mbed.h"
|
||||
#include "cmsis_os.h"
|
||||
|
||||
osSemaphoreId two_slots;
|
||||
osSemaphoreDef(two_slots);
|
||||
|
||||
void test_thread(void const *name) {
|
||||
while (true) {
|
||||
osSemaphoreWait(two_slots, osWaitForever);
|
||||
printf("%s\n\r", (const char*)name);
|
||||
osDelay(1000);
|
||||
osSemaphoreRelease(two_slots);
|
||||
}
|
||||
}
|
||||
|
||||
void t2(void const *argument) {test_thread("Th 2");}
|
||||
osThreadDef(t2, osPriorityNormal, DEFAULT_STACK_SIZE);
|
||||
|
||||
void t3(void const *argument) {test_thread("Th 3");}
|
||||
osThreadDef(t3, osPriorityNormal, DEFAULT_STACK_SIZE);
|
||||
|
||||
int main (void) {
|
||||
two_slots = osSemaphoreCreate(osSemaphore(two_slots), 2);
|
||||
|
||||
osThreadCreate(osThread(t2), NULL);
|
||||
osThreadCreate(osThread(t3), NULL);
|
||||
|
||||
test_thread((void *)"Th 1");
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
#include "mbed.h"
|
||||
#include "cmsis_os.h"
|
||||
|
||||
DigitalOut led(LED1);
|
||||
|
||||
void led_thread(void const *argument) {
|
||||
while (true) {
|
||||
// Signal flags that are reported as event are automatically cleared.
|
||||
osSignalWait(0x1, osWaitForever);
|
||||
led = !led;
|
||||
}
|
||||
}
|
||||
|
||||
osThreadDef(led_thread, osPriorityNormal, DEFAULT_STACK_SIZE);
|
||||
|
||||
int main (void) {
|
||||
osThreadId tid = osThreadCreate(osThread(led_thread), NULL);
|
||||
|
||||
while (true) {
|
||||
osDelay(1000);
|
||||
osSignalSet(tid, 0x1);
|
||||
}
|
||||
}
|
29
tool/mbed/mbed-sdk/libraries/tests/rtos/cmsis/timer/main.cpp
Normal file
29
tool/mbed/mbed-sdk/libraries/tests/rtos/cmsis/timer/main.cpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include "mbed.h"
|
||||
#include "cmsis_os.h"
|
||||
|
||||
DigitalOut LEDs[4] = {
|
||||
DigitalOut(LED1), DigitalOut(LED2), DigitalOut(LED3), DigitalOut(LED4)
|
||||
};
|
||||
|
||||
void blink(void const *n) {
|
||||
LEDs[(int)n] = !LEDs[(int)n];
|
||||
}
|
||||
|
||||
osTimerDef(blink_0, blink);
|
||||
osTimerDef(blink_1, blink);
|
||||
osTimerDef(blink_2, blink);
|
||||
osTimerDef(blink_3, blink);
|
||||
|
||||
int main(void) {
|
||||
osTimerId timer_0 = osTimerCreate(osTimer(blink_0), osTimerPeriodic, (void *)0);
|
||||
osTimerId timer_1 = osTimerCreate(osTimer(blink_1), osTimerPeriodic, (void *)1);
|
||||
osTimerId timer_2 = osTimerCreate(osTimer(blink_2), osTimerPeriodic, (void *)2);
|
||||
osTimerId timer_3 = osTimerCreate(osTimer(blink_3), osTimerPeriodic, (void *)3);
|
||||
|
||||
osTimerStart(timer_0, 2000);
|
||||
osTimerStart(timer_1, 1000);
|
||||
osTimerStart(timer_2, 500);
|
||||
osTimerStart(timer_3, 250);
|
||||
|
||||
osDelay(osWaitForever);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue