EXAMPLE DISCO-F303VC
main.cpp@0:b04aae5b80fd, 2022-05-06 (annotated)
- Committer:
- davidahuertas
- Date:
- Fri May 06 05:58:29 2022 +0000
- Revision:
- 0:b04aae5b80fd
LAB 3 DISCO-F303VC
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| davidahuertas | 0:b04aae5b80fd | 1 | #include "mbed.h" |
| davidahuertas | 0:b04aae5b80fd | 2 | #include "rtos.h" |
| davidahuertas | 0:b04aae5b80fd | 3 | DigitalOut led1(LED6); |
| davidahuertas | 0:b04aae5b80fd | 4 | DigitalOut led2(LED1); |
| davidahuertas | 0:b04aae5b80fd | 5 | |
| davidahuertas | 0:b04aae5b80fd | 6 | Mutex mutex; |
| davidahuertas | 0:b04aae5b80fd | 7 | |
| davidahuertas | 0:b04aae5b80fd | 8 | uint32_t cont =0; |
| davidahuertas | 0:b04aae5b80fd | 9 | bool done[2] = {0,0}; |
| davidahuertas | 0:b04aae5b80fd | 10 | |
| davidahuertas | 0:b04aae5b80fd | 11 | Thread t1; |
| davidahuertas | 0:b04aae5b80fd | 12 | Thread t2; |
| davidahuertas | 0:b04aae5b80fd | 13 | |
| davidahuertas | 0:b04aae5b80fd | 14 | void thread1( const int *i){ |
| davidahuertas | 0:b04aae5b80fd | 15 | int conth; |
| davidahuertas | 0:b04aae5b80fd | 16 | int conth2 =0; |
| davidahuertas | 0:b04aae5b80fd | 17 | while(conth2<100){ |
| davidahuertas | 0:b04aae5b80fd | 18 | mutex.lock(); |
| davidahuertas | 0:b04aae5b80fd | 19 | conth = cont; |
| davidahuertas | 0:b04aae5b80fd | 20 | conth2++; |
| davidahuertas | 0:b04aae5b80fd | 21 | conth++; |
| davidahuertas | 0:b04aae5b80fd | 22 | Thread::wait(10); |
| davidahuertas | 0:b04aae5b80fd | 23 | cont = conth; |
| davidahuertas | 0:b04aae5b80fd | 24 | printf(" %d\n\r ",cont); |
| davidahuertas | 0:b04aae5b80fd | 25 | mutex.unlock(); |
| davidahuertas | 0:b04aae5b80fd | 26 | } |
| davidahuertas | 0:b04aae5b80fd | 27 | done[(int)i] =1; |
| davidahuertas | 0:b04aae5b80fd | 28 | } |
| davidahuertas | 0:b04aae5b80fd | 29 | |
| davidahuertas | 0:b04aae5b80fd | 30 | |
| davidahuertas | 0:b04aae5b80fd | 31 | int main(){ |
| davidahuertas | 0:b04aae5b80fd | 32 | t1.start(callback(thread1, (int*) 1)); |
| davidahuertas | 0:b04aae5b80fd | 33 | t2.start(callback(thread1, (int*) 2)); |
| davidahuertas | 0:b04aae5b80fd | 34 | while(1){ |
| davidahuertas | 0:b04aae5b80fd | 35 | Thread::wait(1); |
| davidahuertas | 0:b04aae5b80fd | 36 | if(done[0] && done[1]){ |
| davidahuertas | 0:b04aae5b80fd | 37 | if(cont == 200){ |
| davidahuertas | 0:b04aae5b80fd | 38 | led1=1; |
| davidahuertas | 0:b04aae5b80fd | 39 | } |
| davidahuertas | 0:b04aae5b80fd | 40 | else{ |
| davidahuertas | 0:b04aae5b80fd | 41 | led2 = 1; |
| davidahuertas | 0:b04aae5b80fd | 42 | } |
| davidahuertas | 0:b04aae5b80fd | 43 | } |
| davidahuertas | 0:b04aae5b80fd | 44 | } |
| davidahuertas | 0:b04aae5b80fd | 45 | } |
| davidahuertas | 0:b04aae5b80fd | 46 |