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.
Dependencies: SDFileSystem mbed-rtos mbed cmsis_rtos_demo_thread
Fork of cmsis_rtos_demo_thread by
main.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 #include "cmsis_os.h" 00004 #include "SDFileSystem.h" 00005 00006 DigitalOut led1(D7); 00007 DigitalOut led2(D9); 00008 Serial uart1(D8, D2); /* UART1: Modbus */ 00009 Serial uart2(D1, D0); /* UART2: pc(USBTX, USBRX) */ 00010 /* (i.e.) pc(D1, D0) */ 00011 I2C i2c(I2C_SDA, I2C_SCL); /* I2C1: */ 00012 00013 SDFileSystem sd(D11, D12, D13, D10, "sd"); /* SPI1: MOSI, MISO, SCK, CS */ 00014 FILE *fp; 00015 00016 AnalogIn ain_0(A0); 00017 AnalogIn ain_1(A1); 00018 AnalogIn ain_2(A2); 00019 AnalogIn ain_3(A3); 00020 00021 InterruptIn user_sw_1(USER_BUTTON); 00022 00023 /* N.B. - add to the FRU... */ 00024 //const char key[] = "your_api_key"; // Replace with your API key 00025 //const char feed[] = "your_feed_id"; // Replace with your Feed ID 00026 //const char stream[] = "your_stream_name"; // Replace with your stream name 00027 //char name[] = "your_device_location_name"; // Name of current location of datasource 00028 //double latitude = 30.3748076; 00029 //double longitude = -97.7386896; // You can also read those values from a GPS 00030 //double elevation = 400.00; 00031 00032 void led2_thread(void const *args){ 00033 while (true) { 00034 led1 = led2; 00035 led2 = !led2; 00036 osDelay(1000); 00037 } 00038 } 00039 00040 void uart1_thread(const void *args){ 00041 uart1.baud(9600); 00042 while(true){ 00043 uart1.putc(uart1.getc()); 00044 } 00045 } 00046 void uart2_thread(const void *args){ 00047 uart2.baud(9600); 00048 while(true){ 00049 uart2.putc(uart2.getc()); 00050 } 00051 } 00052 00053 osThreadDef(uart1_thread, osPriorityNormal, DEFAULT_STACK_SIZE); 00054 osThreadDef(uart2_thread, osPriorityNormal, DEFAULT_STACK_SIZE); 00055 osThreadDef(led2_thread, osPriorityNormal, DEFAULT_STACK_SIZE); 00056 00057 int main() { 00058 00059 /* Set RTC time to 16 December 2013 10:05:23 UTC */ 00060 set_time(1387188323); 00061 /* Time as seconds since January 1, 1970 */ 00062 time_t seconds = time(NULL); /* */ 00063 00064 osThreadCreate(osThread(led2_thread), NULL); 00065 osThreadCreate(osThread(uart1_thread), NULL); 00066 wait(1); 00067 00068 uart2.printf("\r\n"); 00069 wait(1); 00070 uart2.printf("Initializing...\r\n"); 00071 00072 fp = fopen("/sd/hello.txt", "r"); 00073 if (fp != NULL) { 00074 fclose(fp); 00075 remove("/sd/hello.txt"); 00076 uart2.printf("Remove an existing file with the same name\r\n"); 00077 } 00078 00079 fp = fopen("/sd/hello.txt", "w"); 00080 if (fp == NULL) { 00081 uart2.printf("Unable to write the file\r\n"); 00082 } else { 00083 fprintf(fp, "mbed SDCard application!"); 00084 fclose(fp); 00085 uart2.printf("File successfully written!\r\n"); 00086 } 00087 00088 osThreadCreate(osThread(uart2_thread), NULL); 00089 00090 Thread::wait(osWaitForever); /* this is better than an infinite loop... */ 00091 /* spin and spin */ 00092 // while(true); 00093 }
Generated on Tue Jul 12 2022 22:46:28 by
1.7.2
