5.2.1 - Updated I2C files

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

Committer:
jacobjohnson
Date:
Mon Feb 27 17:45:05 2017 +0000
Revision:
1:f30bdcd2b33b
Parent:
0:098463de4c5d
changed the inputscale from 1 to 7 in analogin_api.c.  This will need to be changed later, and accessed from the main level, but for now this allows the  adc to read a value from 0 to 3.7V, instead of just up to 1V.;

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 "greentea-client/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 typedef struct {
group-onsemi 0:098463de4c5d 10 float voltage; /* AD result of measured voltage */
group-onsemi 0:098463de4c5d 11 float current; /* AD result of measured current */
group-onsemi 0:098463de4c5d 12 uint32_t counter; /* A counter value */
group-onsemi 0:098463de4c5d 13 } message_t;
group-onsemi 0:098463de4c5d 14
group-onsemi 0:098463de4c5d 15 #define CREATE_VOLTAGE(COUNTER) (COUNTER * 0.1) * 33
group-onsemi 0:098463de4c5d 16 #define CREATE_CURRENT(COUNTER) (COUNTER * 0.1) * 11
group-onsemi 0:098463de4c5d 17 #define QUEUE_SIZE 16
group-onsemi 0:098463de4c5d 18 #define QUEUE_PUT_DELAY 100
group-onsemi 0:098463de4c5d 19
group-onsemi 0:098463de4c5d 20 /*
group-onsemi 0:098463de4c5d 21 * The stack size is defined in cmsis_os.h mainly dependent on the underlying toolchain and
group-onsemi 0:098463de4c5d 22 * the C standard library. For GCC, ARM_STD and IAR it is defined with a size of 2048 bytes
group-onsemi 0:098463de4c5d 23 * and for ARM_MICRO 512. Because of reduce RAM size some targets need a reduced stacksize.
group-onsemi 0:098463de4c5d 24 */
group-onsemi 0:098463de4c5d 25 #if (defined(TARGET_EFM32HG_STK3400)) && !defined(TOOLCHAIN_ARM_MICRO)
group-onsemi 0:098463de4c5d 26 #define STACK_SIZE 512
group-onsemi 0:098463de4c5d 27 #elif (defined(TARGET_EFM32LG_STK3600) || defined(TARGET_EFM32WG_STK3800) || defined(TARGET_EFM32PG_STK3401)) && !defined(TOOLCHAIN_ARM_MICRO)
group-onsemi 0:098463de4c5d 28 #define STACK_SIZE 768
group-onsemi 0:098463de4c5d 29 #elif (defined(TARGET_EFM32GG_STK3700)) && !defined(TOOLCHAIN_ARM_MICRO)
group-onsemi 0:098463de4c5d 30 #define STACK_SIZE 1536
group-onsemi 0:098463de4c5d 31 #elif defined(TARGET_MCU_NRF51822) || defined(TARGET_MCU_NRF52832)
group-onsemi 0:098463de4c5d 32 #define STACK_SIZE 768
group-onsemi 0:098463de4c5d 33 #elif defined(TARGET_XDOT_L151CC)
group-onsemi 0:098463de4c5d 34 #define STACK_SIZE 1024
group-onsemi 0:098463de4c5d 35 #else
group-onsemi 0:098463de4c5d 36 #define STACK_SIZE DEFAULT_STACK_SIZE
group-onsemi 0:098463de4c5d 37 #endif
group-onsemi 0:098463de4c5d 38
group-onsemi 0:098463de4c5d 39 MemoryPool<message_t, QUEUE_SIZE> mpool;
group-onsemi 0:098463de4c5d 40 Queue<message_t, QUEUE_SIZE> queue;
group-onsemi 0:098463de4c5d 41
group-onsemi 0:098463de4c5d 42 /* Send Thread */
group-onsemi 0:098463de4c5d 43 void send_thread () {
group-onsemi 0:098463de4c5d 44 static uint32_t i = 10;
group-onsemi 0:098463de4c5d 45 while (true) {
group-onsemi 0:098463de4c5d 46 i++; // Fake data update
group-onsemi 0:098463de4c5d 47 message_t *message = mpool.alloc();
group-onsemi 0:098463de4c5d 48 message->voltage = CREATE_VOLTAGE(i);
group-onsemi 0:098463de4c5d 49 message->current = CREATE_CURRENT(i);
group-onsemi 0:098463de4c5d 50 message->counter = i;
group-onsemi 0:098463de4c5d 51 queue.put(message);
group-onsemi 0:098463de4c5d 52 Thread::wait(QUEUE_PUT_DELAY);
group-onsemi 0:098463de4c5d 53 }
group-onsemi 0:098463de4c5d 54 }
group-onsemi 0:098463de4c5d 55
group-onsemi 0:098463de4c5d 56 int main (void) {
group-onsemi 0:098463de4c5d 57 GREENTEA_SETUP(20, "default_auto");
group-onsemi 0:098463de4c5d 58
group-onsemi 0:098463de4c5d 59 Thread thread(osPriorityNormal, STACK_SIZE);
group-onsemi 0:098463de4c5d 60 thread.start(send_thread);
group-onsemi 0:098463de4c5d 61 bool result = true;
group-onsemi 0:098463de4c5d 62 int result_counter = 0;
group-onsemi 0:098463de4c5d 63
group-onsemi 0:098463de4c5d 64 while (true) {
group-onsemi 0:098463de4c5d 65 osEvent evt = queue.get();
group-onsemi 0:098463de4c5d 66 if (evt.status == osEventMessage) {
group-onsemi 0:098463de4c5d 67 message_t *message = (message_t*)evt.value.p;
group-onsemi 0:098463de4c5d 68 const float expected_voltage = CREATE_VOLTAGE(message->counter);
group-onsemi 0:098463de4c5d 69 const float expected_current = CREATE_CURRENT(message->counter);
group-onsemi 0:098463de4c5d 70 // Check using macros if received values correspond to values sent via queue
group-onsemi 0:098463de4c5d 71 bool expected_values = (expected_voltage == message->voltage) &&
group-onsemi 0:098463de4c5d 72 (expected_current == message->current);
group-onsemi 0:098463de4c5d 73 result = result && expected_values;
group-onsemi 0:098463de4c5d 74 const char *result_msg = expected_values ? "OK" : "FAIL";
group-onsemi 0:098463de4c5d 75 printf("%3d %.2fV %.2fA ... [%s]\r\n", message->counter,
group-onsemi 0:098463de4c5d 76 message->voltage,
group-onsemi 0:098463de4c5d 77 message->current,
group-onsemi 0:098463de4c5d 78 result_msg);
group-onsemi 0:098463de4c5d 79 mpool.free(message);
group-onsemi 0:098463de4c5d 80 if (result == false || ++result_counter == QUEUE_SIZE) {
group-onsemi 0:098463de4c5d 81 break;
group-onsemi 0:098463de4c5d 82 }
group-onsemi 0:098463de4c5d 83 }
group-onsemi 0:098463de4c5d 84 }
group-onsemi 0:098463de4c5d 85 GREENTEA_TESTSUITE_RESULT(result);
group-onsemi 0:098463de4c5d 86 return 0;
group-onsemi 0:098463de4c5d 87 }