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.
MO.cpp
00001 00002 #include "MO.h" 00003 00004 extern DigitalOut out; 00005 extern Serial pc; 00006 00007 Queue<char,16> queueEnvoi; 00008 Mail<TRAME,16> trame_box; 00009 00010 char calcCRC16(TRAME* trame) 00011 { 00012 char length = trame->length; 00013 int CRC16 = 0xFFFF; 00014 for(char i =0x00; i<length; i++) { 00015 CRC16 = CRC16 ^ trame->data[i]; 00016 for(int j = 0 ; j<8 ; j++) { 00017 if((CRC16 & 0x1)==0x01) { 00018 CRC16 = CRC16/2 ^ 0xA001; 00019 } else { 00020 CRC16 = CRC16/2; 00021 } 00022 } 00023 } 00024 return CRC16 & 0x00FF ; 00025 } 00026 00027 void createTrame(char* data, char data_length) 00028 { 00029 TRAME *frame = trame_box.alloc(); 00030 frame->typeNFlag = TYPENFLAG; 00031 frame->length = data_length; 00032 frame->data = data; 00033 frame->ctrl = calcCRC16(frame); 00034 trame_box.put(frame); 00035 } 00036 00037 void sendData() 00038 { 00039 osEvent evt; 00040 TRAME* trame; 00041 while(1) { 00042 evt = trame_box.get(); 00043 if(evt.status==osEventMail) { 00044 trame = (TRAME*)evt.value.p; 00045 queueEnvoi.put((char*)IDLE_SYNC); 00046 queueEnvoi.put((char*)START); 00047 queueEnvoi.put((char*)trame->typeNFlag); 00048 queueEnvoi.put((char*)trame->length); 00049 for(int i = 0; i<(int)(trame->length); i++) { 00050 queueEnvoi.put((char*)trame->data[i]); 00051 } 00052 queueEnvoi.put((char*)trame->ctrl); 00053 queueEnvoi.put((char*)STOP); 00054 trame_box.free(trame); 00055 } 00056 } 00057 } 00058 00059 void sendChar() 00060 { 00061 while(1) { 00062 osEvent evt = queueEnvoi.get(); 00063 if(evt.status == osEventMessage) { 00064 char c = (char)evt.value.p; 00065 for(int i =0 ; i<8 ; i++) { 00066 if(((c>>i)&0x01)==1) { 00067 out = 1; 00068 Thread::signal_wait(0x01); 00069 out = 0; 00070 Thread::signal_wait(0x01); 00071 } else { 00072 out = 0; 00073 Thread::signal_wait(0x01); 00074 out = 1; 00075 Thread::signal_wait(0x01); 00076 } 00077 } 00078 } 00079 } 00080 } 00081 00082 00083
Generated on Wed Jul 13 2022 06:55:34 by
1.7.2