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.
Diff: main.cpp
- Revision:
- 1:5c0ca9bdf810
- Parent:
- 0:703249a56b9d
- Child:
- 2:a4a73ba6f492
--- a/main.cpp Mon Oct 23 13:13:33 2017 +0000
+++ b/main.cpp Mon Oct 23 15:54:33 2017 +0000
@@ -6,104 +6,22 @@
DigitalOut led1(LED1);
-DigitalOut led2(LED2);
-DigitalOut led3(LED3);
DigitalOut out(PIN_OUT);
InterruptIn in(PIN_IN);
Serial pc(USBTX,USBRX);
-
-Thread sendCharThread;
-Thread receiveBitThread;
-
-Ticker ticker;
-Mutex mux;
-Timer timer;
-
-
-Mail<char,16> mailBoxReception;
-Mail<char,16> mailBoxEnvoi;
-Queue <void,16> queueBitReception;
-
-
-//MODULATION
-void sendChar()
-{
- while(1) {
- osEvent evt = mailBoxEnvoi.get();
- if(evt.status == osEventMail) {
-
- char* c = (char*)evt.value.p;
- for(int i =0 ; i<8 ; i++) {
- if(((*c>>7-i)&0x01)==1) {
- out = 1;
- Thread::signal_wait(0x01);
- out = 0;
- Thread::signal_wait(0x01);
- } else {
- out = 0;
- Thread::signal_wait(0x01);
- out = 1;
- Thread::signal_wait(0x01);
- }
- }
- }
- }
-}
+char test[5]={0x01,0x01,0x01,0x01,0x01};
-//DEMODULATION
-void receiveChar()
-{
- char res;
- while(1) {
- res=0x00;
- for(int i =0; i<8; i++) {
- osEvent evt = queueBitReception.get();
- if(evt.status == osEventMessage) {
- res = res | (((char)evt.value.p)<<i);
- }
- }
- mailBoxReception.put((char*)res);
- }
-
-}
+Thread sendCharThread;
+Thread sendDataThread;
-//DEMODULATION
-void receiveBit()
-{
- int oldTime;
- bool bitType=false;
- Thread::signal_wait(0x02);
- oldTime = timer.read_ms();
- while(1) {
-
-
- Thread::signal_wait(0x01);
- if(timer.read_ms()-oldTime<T) {
- Thread::signal_wait(0x01);
- oldTime=timer.read_ms();
- } else {
- oldTime=timer.read_ms();
- bitType=!bitType;
- }
-
-
-
-
-
- if(bitType) {
- queueBitReception.put((void*)0x01);
- } else {
- queueBitReception.put((void*)0x00);
- }
-
-
-
- }
-}
+Thread receiveBitThread;
+Thread receiveCharThread;
+
+Ticker ticker;
void interruptRise()
@@ -119,21 +37,24 @@
void wake()
{
sendCharThread.signal_set(0x01);
- led3=!led3;
+ led1=!led1;
}
int main()
{
- timer.start();
- ticker.attach(&wake,T/2.0);
+ led1=1;
in.rise(&interruptRise);
in.fall(&interruptFall);
- led3=1;
wait(1);
+ sendCharThread.start(&sendChar);
+ receiveBitThread.start(&receiveBit);
+ receiveCharThread.start(&receiveChar);
+ sendDataThread.start(&sendData);
+ ticker.attach(&wake,T/2.0);
while(1) {
- if(pc.readable()) {
- sendCharThread.start(&sendChar);
+ createTrame(test,5);
+ wait(1);
}
- }
+
}