Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 // Title: mbed-os-mutex 00002 // Author: Jacques-Olivier Klein - IUT de CACHAN 00003 // Date: 2018-02-10 rev. 2019-01-06 00004 00005 #include "mbed.h" 00006 #include "IHM.h" 00007 00008 IHM ihm; 00009 00010 DigitalOut L0 (PB_3) ; // led L0 00011 DigitalOut L1 (PA_7) ; // led L1 00012 DigitalOut L2 (PA_6) ; // led L2 00013 00014 void bargraph_up_counter(); 00015 void bargraph_down_counter(); 00016 00017 Mutex bargraph_mutex; 00018 00019 Thread Thread_bargraph_up_counter; 00020 Thread Thread_bargraph_down_counter; 00021 00022 00023 int main(void) 00024 { ihm.LCD_clear(); 00025 ihm.LCD_printf("Mutex-%s %s",__DATE__,__TIME__); 00026 printf("\n\rmbed-os-mutex-%s %s\n\r",__DATE__,__TIME__); 00027 printf(" OS_STACK_SIZE:%d\n\r", OS_STACK_SIZE); 00028 00029 Thread_bargraph_up_counter.start(bargraph_up_counter); 00030 Thread_bargraph_down_counter.start(bargraph_down_counter); 00031 00032 while(1){ 00033 wait(4.000); 00034 L0=!L0; 00035 printf(" [pid-%d]Main \n\r",osThreadGetId()); 00036 } 00037 } 00038 00039 void bargraph_up_counter(){ 00040 static int up_counter = 1; 00041 while(1){ 00042 bargraph_mutex.lock(); 00043 L1=1; 00044 for(up_counter = 1; up_counter != 0xFF; up_counter = (up_counter<<1)|1){ 00045 ihm.BAR_set(up_counter); 00046 wait(0.200); 00047 } 00048 bargraph_mutex.unlock(); 00049 L1=0; 00050 } 00051 } 00052 00053 void bargraph_down_counter(){ 00054 static int down_counter = 1; 00055 while(1){ 00056 bargraph_mutex.lock(); 00057 L2=1; 00058 for(down_counter = 0x80; down_counter != 0xFF; 00059 down_counter = (down_counter>>1)|0x80){ 00060 ihm.BAR_set(down_counter); 00061 wait(0.200); 00062 } 00063 bargraph_mutex.unlock(); 00064 L2=0; 00065 } 00066 }
Generated on Fri Aug 26 2022 12:54:14 by
1.7.2