mbed Phone Platform

Dependencies:   ulaw mbed ConfigFile

Files at this revision

API Documentation at this revision

Comitter:
okini3939
Date:
Fri Jan 07 18:20:41 2011 +0000
Parent:
3:1d5dc4107558
Child:
5:30e2847d241b
Commit message:

Changed in this revision

IpLine.cpp Show annotated file Show diff for this revision Revisions of this file
IpLine.h Show annotated file Show diff for this revision Revisions of this file
Line.cpp Show annotated file Show diff for this revision Revisions of this file
Line.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/IpLine.cpp	Thu Jan 06 17:04:13 2011 +0000
+++ b/IpLine.cpp	Fri Jan 07 18:20:41 2011 +0000
@@ -4,6 +4,10 @@
 
 #include "IpLine.h"
 
+#define NET_RETRY (FREQ)
+#define NET_TIMEOUT (FREQ * 3)
+#define PACKET_IDENT 0x6465626d // "mbed"
+
 IpLine::IpLine (AnalogOut p_dac, AnalogIn p_adc) : dac(p_dac), adc(p_adc), dial(DIAL_SIZE), dabuf(DATA_SIZE * 4), adbuf(DATA_SIZE * 2)
 , led1(LED1), led2(LED2), led3(LED3), led4(LED4) {
     EthernetErr r;
@@ -45,15 +49,15 @@
             // over sample
             if (dataskip) {
                 dataskip = 0;
-led1 = 1; led2 = 0; led3 = 0;
             } else {
                 if (! dabuf.get(c)) {
                     dac.write_u16(ulaw2pcm(c));
                 } else {
-//                    dac.write_u16(gaussian());
+                    dac.write_u16(gaussian());
                 }
                 dataskip = 1;
             }
+led1 = 1; led2 = 0; led3 = 0;
         } else {
             // normal
             dabuf.get(c);
@@ -114,7 +118,7 @@
     // get data
     len = udpsock->recvfrom((char *)&packet, sizeof(struct ipline_packet), &recv);
 
-    if (memcmp(packet.header.text, "mbed", 4) != 0) return;
+    if (packet.header.ident != PACKET_IDENT) return;
 
 led4 = 1;
     if (packet.header.status != StatusNone) {
@@ -183,7 +187,7 @@
 /// send packet (header only)
 void IpLine::send (struct ipline_header *header) {
 
-    memcpy(header->text, "mbed", 4);
+    header->ident = PACKET_IDENT;
     if (! header->num) {
         header->num = packet_num;
         packet_num ++;
@@ -201,7 +205,7 @@
 /// send packet
 void IpLine::send (struct ipline_packet *packet) {
 
-    memcpy(packet->header.text, "mbed", 4);
+    packet->header.ident = PACKET_IDENT;
     if (! packet->header.num) {
         packet->header.num = packet_num;
         packet_num ++;
@@ -281,3 +285,23 @@
     }
     remote.setPort(UDPPORT);
 }
+
+unsigned long IpLine::xor128 () {
+    static unsigned long x = 123456789;
+    static unsigned long y = 362436069, z = 521288629, w = 88675123;
+    unsigned long t; 
+    t = (x ^ (x << 11));
+    x = y; y = z; z = w;
+    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)) ); 
+}
+
+int IpLine::gaussian () {
+    int i, j;
+
+    j = 0;
+    for (i = 0; i < 12; i ++) {
+       j = j + (xor128() >> 16);
+    }
+    j = (j - 0x60000) & 0xffff;
+    return 0x3fff + (j >> 1);
+}
--- a/IpLine.h	Thu Jan 06 17:04:13 2011 +0000
+++ b/IpLine.h	Fri Jan 07 18:20:41 2011 +0000
@@ -5,11 +5,8 @@
 #include "RingBuffer.h"
 #include "ulaw.h"
 
-#define NET_RETRY (FREQ)
-#define NET_TIMEOUT (FREQ * 3)
-
 struct ipline_header {
-    char text[4];
+    unsigned long ident;
     unsigned short num;
     enum PhoneType target;
     enum Mode mode;
@@ -53,4 +50,6 @@
     void onLisnerEvent (UDPSocketEvent);
     void send (struct ipline_header *);
     void send (struct ipline_packet *);
+    unsigned long xor128 ();
+    int gaussian ();
 };
--- a/Line.cpp	Thu Jan 06 17:04:13 2011 +0000
+++ b/Line.cpp	Fri Jan 07 18:20:41 2011 +0000
@@ -83,6 +83,9 @@
     }
 }
 
+void Line::poll () {
+}
+
 /**
  * @brief change mode
  * @param newmode mode of line
@@ -213,7 +216,7 @@
 /// tone
 void Line::tone (enum Tone type) {
     if (! hook && ( type == DialTone ||
-      (type == RingBackTone && tonecount < TONE_RBT_ON) ||
+      (type == RingBackTone && tonecount < TONE_RBT_ON && (tonecount % RING_PULSE) < (RING_PULSE / 2)) ||
       (type == BusyTone && tonecount < TONE_BT_ON) ) ) {
         // on hook
         dac.write_u16(tonetable[tonecount % TONE_DT]);
--- a/Line.h	Thu Jan 06 17:04:13 2011 +0000
+++ b/Line.h	Fri Jan 07 18:20:41 2011 +0000
@@ -10,6 +10,7 @@
     Line (PinName p_line, PinName p_xline, PinName p_hook, AnalogOut p_dac);
 
     void intr ();
+    void poll ();
     int enter (enum Mode);
     int scan (enum Scan);
 
--- a/main.cpp	Thu Jan 06 17:04:13 2011 +0000
+++ b/main.cpp	Fri Jan 07 18:20:41 2011 +0000
@@ -267,10 +267,13 @@
     line2.enter(ModeReady);
     ipline.enter(ModeReady);
 
+    NVIC_SetPriority(TIMER3_IRQn, (1 << __NVIC_PRIO_BITS) - 1); // preemption=1, sub-priority=1
     ticker.attach_us(&int_sample, 1000000 / FREQ);
 
     for (;;) {
         ipline.poll();
+        line1.poll();
+        line2.poll();
 
         i = scanline(PhoneLine1, ScanMode);
         checkline(PhoneLine1);