5.2.1 - Updated I2C files

Dependents:   mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510

Committer:
group-onsemi
Date:
Wed Jan 25 20:34:15 2017 +0000
Revision:
0:098463de4c5d
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
group-onsemi 0:098463de4c5d 1 #include "mbed.h"
group-onsemi 0:098463de4c5d 2 #include "test_env.h"
group-onsemi 0:098463de4c5d 3 #include "rtos.h"
group-onsemi 0:098463de4c5d 4
group-onsemi 0:098463de4c5d 5 #if defined(MBED_RTOS_SINGLE_THREAD)
group-onsemi 0:098463de4c5d 6 #error [NOT_SUPPORTED] test not supported
group-onsemi 0:098463de4c5d 7 #endif
group-onsemi 0:098463de4c5d 8
group-onsemi 0:098463de4c5d 9 #define NUM_THREADS 5
group-onsemi 0:098463de4c5d 10 #if defined(__CORTEX_A9)
group-onsemi 0:098463de4c5d 11 #define THREAD_STACK_SIZE DEFAULT_STACK_SIZE
group-onsemi 0:098463de4c5d 12 #else
group-onsemi 0:098463de4c5d 13 #define THREAD_STACK_SIZE 256
group-onsemi 0:098463de4c5d 14 #endif
group-onsemi 0:098463de4c5d 15
group-onsemi 0:098463de4c5d 16 DigitalOut led1(LED1);
group-onsemi 0:098463de4c5d 17 volatile bool should_exit = false;
group-onsemi 0:098463de4c5d 18 volatile bool allocation_failure = false;
group-onsemi 0:098463de4c5d 19
group-onsemi 0:098463de4c5d 20 void task_using_malloc(void)
group-onsemi 0:098463de4c5d 21 {
group-onsemi 0:098463de4c5d 22 void* data;
group-onsemi 0:098463de4c5d 23 while (1) {
group-onsemi 0:098463de4c5d 24 // Repeatedly allocate and free memory
group-onsemi 0:098463de4c5d 25 data = malloc(100);
group-onsemi 0:098463de4c5d 26 if (data != NULL) {
group-onsemi 0:098463de4c5d 27 memset(data, 0, 100);
group-onsemi 0:098463de4c5d 28 } else {
group-onsemi 0:098463de4c5d 29 allocation_failure = true;
group-onsemi 0:098463de4c5d 30 }
group-onsemi 0:098463de4c5d 31 free(data);
group-onsemi 0:098463de4c5d 32
group-onsemi 0:098463de4c5d 33 if (should_exit) {
group-onsemi 0:098463de4c5d 34 return;
group-onsemi 0:098463de4c5d 35 }
group-onsemi 0:098463de4c5d 36 }
group-onsemi 0:098463de4c5d 37 }
group-onsemi 0:098463de4c5d 38
group-onsemi 0:098463de4c5d 39 int main()
group-onsemi 0:098463de4c5d 40 {
group-onsemi 0:098463de4c5d 41 Thread *thread_list[NUM_THREADS];
group-onsemi 0:098463de4c5d 42 int test_time = 15;
group-onsemi 0:098463de4c5d 43 GREENTEA_SETUP(20, "default_auto");
group-onsemi 0:098463de4c5d 44
group-onsemi 0:098463de4c5d 45 // Allocate threads for the test
group-onsemi 0:098463de4c5d 46 for (int i = 0; i < NUM_THREADS; i++) {
group-onsemi 0:098463de4c5d 47 thread_list[i] = new Thread(osPriorityNormal, THREAD_STACK_SIZE);
group-onsemi 0:098463de4c5d 48 if (NULL == thread_list[i]) {
group-onsemi 0:098463de4c5d 49 allocation_failure = true;
group-onsemi 0:098463de4c5d 50 }
group-onsemi 0:098463de4c5d 51 thread_list[i]->start(task_using_malloc);
group-onsemi 0:098463de4c5d 52 }
group-onsemi 0:098463de4c5d 53
group-onsemi 0:098463de4c5d 54 // Give the test time to run
group-onsemi 0:098463de4c5d 55 while (test_time) {
group-onsemi 0:098463de4c5d 56 led1 = !led1;
group-onsemi 0:098463de4c5d 57 Thread::wait(1000);
group-onsemi 0:098463de4c5d 58 test_time--;
group-onsemi 0:098463de4c5d 59 }
group-onsemi 0:098463de4c5d 60
group-onsemi 0:098463de4c5d 61 // Join and delete all threads
group-onsemi 0:098463de4c5d 62 should_exit = 1;
group-onsemi 0:098463de4c5d 63 for (int i = 0; i < NUM_THREADS; i++) {
group-onsemi 0:098463de4c5d 64 if (NULL == thread_list[i]) {
group-onsemi 0:098463de4c5d 65 continue;
group-onsemi 0:098463de4c5d 66 }
group-onsemi 0:098463de4c5d 67 thread_list[i]->join();
group-onsemi 0:098463de4c5d 68 delete thread_list[i];
group-onsemi 0:098463de4c5d 69 }
group-onsemi 0:098463de4c5d 70
group-onsemi 0:098463de4c5d 71 GREENTEA_TESTSUITE_RESULT(!allocation_failure);
group-onsemi 0:098463de4c5d 72 }