multithreading example

Dependencies:   FastAnalogIn

Committer:
candre97
Date:
Mon Nov 25 02:56:01 2019 +0000
Revision:
109:1d95a4596fb5
Parent:
103:2da5fc276330
Child:
110:037667235b6d
added circ_buff.hpp; some structure to the main.cpp

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 82:abf1b1785bd7 1 /* mbed Microcontroller Library
mbed_official 82:abf1b1785bd7 2 * Copyright (c) 2018 ARM Limited
mbed_official 82:abf1b1785bd7 3 * SPDX-License-Identifier: Apache-2.0
mbed_official 82:abf1b1785bd7 4 */
mbed_official 82:abf1b1785bd7 5
Jonathan Austin 0:2757d7abb7d9 6 #include "mbed.h"
mbed_official 100:ec006d6f3cb6 7 #include "platform/mbed_thread.h"
mbed_official 82:abf1b1785bd7 8 #include "stats_report.h"
candre97 102:14fd65f261a2 9 #include <AnalogIn.h>
candre97 102:14fd65f261a2 10 #include <AnalogOut.h>
candre97 109:1d95a4596fb5 11 #include "circ_buff.hpp"
Jonathan Austin 0:2757d7abb7d9 12
candre97 102:14fd65f261a2 13 AnalogOut v_src(GPIO0);
candre97 102:14fd65f261a2 14 AnalogIn therm(GPIO2);
Jonathan Austin 0:2757d7abb7d9 15
mbed_official 88:bea4f2daa48c 16 #define SLEEP_TIME 500 // (msec)
mbed_official 88:bea4f2daa48c 17 #define PRINT_AFTER_N_LOOPS 20
mbed_official 88:bea4f2daa48c 18
candre97 102:14fd65f261a2 19 #include "mbed.h"
candre97 102:14fd65f261a2 20
candre97 109:1d95a4596fb5 21 //DigitalOut led1(LED1);
candre97 109:1d95a4596fb5 22 //DigitalOut led2(LED2);
candre97 109:1d95a4596fb5 23 Thread thread_adc;
candre97 109:1d95a4596fb5 24
candre97 109:1d95a4596fb5 25 Thread thread_mfcc;
candre97 102:14fd65f261a2 26
candre97 109:1d95a4596fb5 27 void adc_thread() {
Jonathan Austin 0:2757d7abb7d9 28 while (true) {
candre97 109:1d95a4596fb5 29 printf("Top of ADC sampling thread");
candre97 109:1d95a4596fb5 30
candre97 109:1d95a4596fb5 31 wait(0.6);
Jonathan Austin 0:2757d7abb7d9 32 }
Jonathan Austin 0:2757d7abb7d9 33 }
candre97 103:2da5fc276330 34
candre97 109:1d95a4596fb5 35 /*
candre97 109:1d95a4596fb5 36 this thread is in charge of converting
candre97 109:1d95a4596fb5 37 */
candre97 109:1d95a4596fb5 38 void mfcc_thread() {
candre97 102:14fd65f261a2 39 while (true) {
candre97 109:1d95a4596fb5 40 printf("Top of MFCC thread");
candre97 109:1d95a4596fb5 41
candre97 109:1d95a4596fb5 42 wait(2);
candre97 102:14fd65f261a2 43 }
candre97 102:14fd65f261a2 44 }
candre97 102:14fd65f261a2 45
candre97 102:14fd65f261a2 46 int main() {
candre97 109:1d95a4596fb5 47 thread_adc.start(adc_thread);
candre97 109:1d95a4596fb5 48 thread_mfcc.start(mfcc_thread);
candre97 102:14fd65f261a2 49 }