瀏覽代碼

cmAudDsp.h/c, cmAudioSys.h/c, cmDspSys.h/c, cmDspNet.h : Added support for serial port.

master
kevin.larke 4 年之前
父節點
當前提交
e686cc2c9c
共有 7 個檔案被更改,包括 108 行新增7 行删除
  1. 58
    2
      cmAudDsp.c
  2. 2
    0
      cmAudDsp.h
  3. 30
    0
      cmAudioSys.c
  4. 2
    0
      cmAudioSys.h
  5. 1
    0
      dsp/cmDspNet.h
  6. 13
    4
      dsp/cmDspSys.c
  7. 2
    1
      dsp/cmDspSys.h

+ 58
- 2
cmAudDsp.c 查看文件

@@ -19,6 +19,7 @@
19 19
 #include "cmApBuf.h"
20 20
 #include "cmMidi.h"
21 21
 #include "cmMidiPort.h"
22
+#include "cmSerialPort.h"
22 23
 #include "dsp/cmDspValue.h"
23 24
 #include "cmMsgProtocol.h"
24 25
 #include "cmThread.h"
@@ -91,6 +92,12 @@ typedef struct
91 92
   unsigned           msgsPerClientPoll;
92 93
   const cmChar_t*    dfltProgramLabel;
93 94
 
95
+  char*              serialDeviceStr;
96
+  unsigned           serialBaud;
97
+  unsigned           serialCfgFlags;
98
+  unsigned           serialPollPeriodMs;
99
+  cmSeH_t            serialPortH;
100
+
94 101
   cmAdAggDev_t*      aggDevArray;
95 102
   unsigned           aggDevCnt;
96 103
 
@@ -169,6 +176,7 @@ cmAdRC_t _cmAdParseSysJsonTree( cmAd_t* p )
169 176
   cmJsonNode_t*   nrtDevArrNodePtr = NULL;
170 177
   cmJsonNode_t*   afpDevArrNodePtr = NULL;
171 178
   cmJsonNode_t*   audDspNodePtr    = NULL;
179
+  cmJsonNode_t*   serialNodePtr    = NULL;
172 180
   const cmChar_t* errLabelPtr      = NULL;
173 181
   unsigned        i;
174 182
   cmJsRC_t      jsRC = kOkJsRC;
@@ -190,12 +198,28 @@ cmAdRC_t _cmAdParseSysJsonTree( cmAd_t* p )
190 198
         "aggDevArray",        kArrayTId  | kOptArgJsFl, &aggDevArrNodePtr,
191 199
         "nrtDevArray",        kArrayTId  | kOptArgJsFl, &nrtDevArrNodePtr,
192 200
         "afpDevArray",        kArrayTId  | kOptArgJsFl, &afpDevArrNodePtr,
201
+        "serial",             kObjectTId | kOptArgJsFl, &serialNodePtr,
193 202
         NULL )) != kOkJsRC )
194 203
   {
195 204
     rc = _cmAdParseMemberErr(p, jsRC, errLabelPtr, "aud_dsp" );
196 205
     goto errLabel;
197 206
   }
198 207
 
208
+  // parse the serial port cfg
209
+  if( serialNodePtr != NULL )
210
+  {
211
+    if(( jsRC      = cmJsonMemberValues( serialNodePtr, &errLabelPtr, 
212
+          "device",           kStringTId, &p->serialDeviceStr,
213
+          "baud",             kIntTId,    &p->serialBaud,
214
+          "flags",            kIntTId,    &p->serialCfgFlags,
215
+          "pollPeriodMs",     kIntTId,    &p->serialPollPeriodMs,
216
+          NULL )) != kOkJsRC )
217
+    {
218
+      rc = _cmAdParseMemberErr(p, jsRC, errLabelPtr, "serial" );
219
+      goto errLabel;
220
+    }
221
+  }
222
+
199 223
   // parse the aggregate device specifications into p->aggDevArray[].
200 224
   if( aggDevArrNodePtr != NULL && (p->aggDevCnt = cmJsonChildCount(aggDevArrNodePtr)) > 0)
201 225
   {
@@ -382,6 +406,22 @@ cmAdRC_t _cmAdSetup( cmAd_t* p )
382 406
   return rc;
383 407
 }
384 408
 
409
+cmAdRC_t _cmAdCreateSerialPort( cmAd_t* p )
410
+{
411
+  cmAdRC_t rc = kOkAdRC;
412
+  
413
+  if( p->serialDeviceStr != NULL )
414
+  {
415
+    p->serialPortH = cmSeCreate( &p->ctx, &p->serialPortH, p->serialDeviceStr, p->serialBaud, p->serialCfgFlags, NULL, NULL, p->serialPollPeriodMs );
416
+    
417
+    if( !cmSeIsOpen(p->serialPortH) )
418
+    {
419
+      rc = cmErrMsg(&p->err,kSerialDevCreateFailAdRC,"The serial device '%s' creation failed.",cmStringNullGuard(p->serialDeviceStr));
420
+    }
421
+  }
422
+  return rc;
423
+}
424
+
385 425
 cmAdRC_t _cmAdCreateAggDevices( cmAd_t* p )
386 426
 {
387 427
   cmAdRC_t rc = kOkAdRC;
@@ -570,6 +610,15 @@ cmAdRC_t _cmAudDspFree( cmAd_t* p )
570 610
     goto errLabel;
571 611
   }
572 612
 
613
+  if( cmSeIsOpen(p->serialPortH) )
614
+  {    
615
+    if( cmSeDestroy(&p->serialPortH) != kOkSeRC )
616
+    {
617
+      rc = cmErrMsg(&p->err,kSerialPortFailAdRC,"Serial port finalize failed.");
618
+      goto errLabel;      
619
+    }
620
+  }
621
+  
573 622
   if( cmMpIsInitialized() )
574 623
     if( cmMpFinalize() != kOkMpRC )
575 624
     {
@@ -695,6 +744,13 @@ cmAdRC_t cmAudDspAlloc( cmCtx_t* ctx, cmAdH_t* hp, cmMsgSendFuncPtr_t cbFunc, vo
695 744
     goto errLabel;
696 745
   }
697 746
 
747
+  // create the serial port
748
+  if( _cmAdCreateSerialPort(p) != kOkAdRC )
749
+  {
750
+    rc = cmErrMsg(&p->err,kSerialPortFailAdRC,"The MIDI system initialization failed.");
751
+    goto errLabel;
752
+  }
753
+  
698 754
   // initialize the MIDI system
699 755
   if( cmMpInitialize(ctx,NULL,NULL,p->midiPortBufByteCnt,"app") != kOkMpRC )
700 756
   {
@@ -713,7 +769,7 @@ cmAdRC_t cmAudDspAlloc( cmCtx_t* ctx, cmAdH_t* hp, cmMsgSendFuncPtr_t cbFunc, vo
713 769
     goto errLabel;
714 770
 
715 771
   // initialize the DSP system
716
-  if( cmDspSysInitialize(ctx,&p->dsH,p->netH) )
772
+  if( cmDspSysInitialize(ctx,&p->dsH,p->netH,p->serialPortH) )
717 773
   {
718 774
     rc = cmErrMsg(&p->err,kDspSysFailAdRC,"The DSP system initialization failed.");
719 775
     goto errLabel;
@@ -1143,7 +1199,7 @@ cmAdRC_t _cmAudDspLoadAudioSys( cmAd_t* p, unsigned asCfgIdx )
1143 1199
       {
1144 1200
         // ... and allocate additional DSP systems when more than one sub-sys is 
1145 1201
         // defined in the audio system configuration
1146
-        if( cmDspSysInitialize(&p->ctx,&dsH,p->netH) != kOkDspRC )
1202
+        if( cmDspSysInitialize(&p->ctx,&dsH,p->netH,p->serialPortH) != kOkDspRC )
1147 1203
         {
1148 1204
           rc = cmErrMsg(&p->err,kDspSysFailAdRC,"Unable to initialize an additional DSP system.");
1149 1205
           goto errLabel;

+ 2
- 0
cmAudDsp.h 查看文件

@@ -13,6 +13,7 @@ extern "C" {
13 13
     kAudioPortFailAdRC,
14 14
     kAudioSysFailAdRC,
15 15
     kMidiSysFailAdRC,
16
+    kSerialPortFailAdRC,
16 17
     kDspSysFailAdRC,
17 18
     kFileSysFailAdRC,
18 19
     kJsonFailAdRC,
@@ -21,6 +22,7 @@ extern "C" {
21 22
     kNoPgmLoadedAdRC,
22 23
     kInvalidSubSysIdxAdRC,
23 24
     kUnknownMsgTypeAdRC,
25
+    kSerialDevCreateFailAdRC,
24 26
     kAggDevSysFailAdRC,
25 27
     kAggDevCreateFailAdRC,
26 28
     kNrtDevSysFailAdRC,

+ 30
- 0
cmAudioSys.c 查看文件

@@ -15,6 +15,7 @@
15 15
 #include "cmThread.h"
16 16
 #include "cmUdpPort.h"
17 17
 #include "cmUdpNet.h"
18
+#include "cmSerialPort.h"
18 19
 #include "cmAudioSysMsg.h"
19 20
 #include "cmAudioSys.h"
20 21
 #include "cmMidi.h"
@@ -37,6 +38,7 @@ typedef struct
37 38
   cmTsMp1cH_t        htdQueueH; // host-to-dsp thread safe msg queue
38 39
   cmThreadMutexH_t   engMutexH; // thread mutex and condition variable
39 40
   cmUdpNetH_t        netH;
41
+  cmSeH_t            serialPortH; 
40 42
   bool               enableFl;  // application controlled pause flag
41 43
   bool               runFl;     // false during finalization otherwise true
42 44
   bool               statusFl;  // true if regular status notifications should be sent
@@ -507,6 +509,13 @@ void _cmAudioSysMidiCallback( const cmMidiPacket_t* pktArray, unsigned pktCnt )
507 509
 
508 510
 }
509 511
 
512
+void _cmAudioSysSerialPortCallback( void* cbArg, const void* byteA, unsigned byteN )
513
+{
514
+  //_cmAsCfg_t* p (_cmAsCfg_t*)cbArg;
515
+  
516
+  // TODO: handle serial receive
517
+}
518
+
510 519
 cmAsRC_t cmAudioSysAllocate( cmAudioSysH_t* hp, cmRpt_t* rpt, const cmAudioSysCfg_t* cfg )
511 520
 {
512 521
   cmAsRC_t rc;
@@ -832,6 +841,7 @@ cmAsRC_t cmAudioSysInitialize( cmAudioSysH_t h, const cmAudioSysCfg_t* cfg )
832 841
     cp->iMeterArray      = cmMemAllocZ( double, cp->status.iMeterCnt );
833 842
     cp->oMeterArray      = cmMemAllocZ( double, cp->status.oMeterCnt );
834 843
     cp->netH             = cfg->netH;
844
+    cp->serialPortH      = cfg->serialPortH;
835 845
 
836 846
     // create the audio System thread
837 847
     if((rc = cmThreadCreate( &cp->threadH, _cmAsThreadCallback, cp, ss->args.rpt )) != kOkThRC )
@@ -874,6 +884,16 @@ cmAsRC_t cmAudioSysInitialize( cmAudioSysH_t h, const cmAudioSysCfg_t* cfg )
874 884
         goto errLabel;
875 885
       }
876 886
 
887
+    // install the serial port 
888
+    if( cmSeIsOpen(cp->serialPortH) )
889
+    {
890
+      if( cmSeSetCallback(cp->serialPortH, _cmAudioSysSerialPortCallback, cp ) != kOkSeRC )
891
+      {
892
+        rc = _cmAsError(p,kSerialPortFailAsRC,"Serial port callback installation failed.");
893
+        goto errLabel;        
894
+      }
895
+    }
896
+
877 897
     // setup the sub-system status notification 
878 898
     cp->statusUpdateSmpCnt = floor(cmApBufMeterMs() * cp->ss.args.srate / 1000.0 );
879 899
     cp->statusUpdateSmpIdx = 0;
@@ -886,6 +906,16 @@ cmAsRC_t cmAudioSysInitialize( cmAudioSysH_t h, const cmAudioSysCfg_t* cfg )
886 906
       rc = _cmAsError(p,kThreadErrAsRC,"Thread start failed.");
887 907
       goto errLabel;
888 908
     }
909
+
910
+    if( cmSeIsOpen(cp->serialPortH) )
911
+    {
912
+      if( cmSeStart( cp->serialPortH ) != kOkSeRC )
913
+      {
914
+        rc = _cmAsError(p,kSerialPortFailAsRC,"Serial port start failed.");
915
+        goto errLabel;        
916
+      }
917
+      
918
+    }
889 919
   }
890 920
 
891 921
 

+ 2
- 0
cmAudioSys.h 查看文件

@@ -73,6 +73,7 @@ extern "C" {
73 73
     kBufTooSmallAsRC,
74 74
     kNoMsgWaitingAsRC,
75 75
     kMidiSysFailAsRC,
76
+    kSerialPortFailAsRC,
76 77
     kMsgSerializeFailAsRC,
77 78
     kStateBufFailAsRC,
78 79
     kInvalidArgAsRC,
@@ -197,6 +198,7 @@ extern "C" {
197 198
     cmTsQueueCb_t         clientCbFunc; // Called by  cmAudioSysReceiveMsg() to deliver internally generated msg's to the host. 
198 199
                                         //  Set to NULL if msg's will be directly returned by buffers passed to cmAudioSysReceiveMsg().
199 200
     cmUdpNetH_t           netH;
201
+    cmSeH_t               serialPortH;
200 202
   } cmAudioSysCfg_t;
201 203
 
202 204
   extern cmAudioSysH_t cmAudioSysNullHandle;

+ 1
- 0
dsp/cmDspNet.h 查看文件

@@ -72,6 +72,7 @@ extern "C" {
72 72
     cmDspPresetMgr_t    pm;
73 73
     unsigned            nextInstId;
74 74
     unsigned            pgmIdx;
75
+    cmSeH_t             serialPortH;
75 76
 
76 77
 
77 78
     cmUdpNetH_t           netH;          //

+ 13
- 4
dsp/cmDspSys.c 查看文件

@@ -19,6 +19,7 @@
19 19
 #include "cmThread.h"
20 20
 #include "cmUdpPort.h"
21 21
 #include "cmUdpNet.h"
22
+#include "cmSerialPort.h"
22 23
 #include "cmAudioSys.h"
23 24
 #include "cmProcObj.h"
24 25
 #include "cmDspCtx.h"
@@ -165,7 +166,7 @@ cmDspRC_t _cmDspSysFinalize( cmDsp_t* p )
165 166
   return rc;
166 167
 }
167 168
 
168
-cmDspRC_t cmDspSysInitialize( cmCtx_t* ctx, cmDspSysH_t* hp, cmUdpNetH_t netH )
169
+cmDspRC_t cmDspSysInitialize( cmCtx_t* ctx, cmDspSysH_t* hp, cmUdpNetH_t netH, cmSeH_t serialPortH )
169 170
 {
170 171
   unsigned        i;
171 172
   cmDspRC_t       rc     = kOkDspRC;
@@ -178,9 +179,10 @@ cmDspRC_t cmDspSysInitialize( cmCtx_t* ctx, cmDspSysH_t* hp, cmUdpNetH_t netH )
178 179
 
179 180
   cmErrSetup(&p->err,&ctx->rpt,"DSP System");
180 181
   //p->ctx.ctx   = asCtx;
181
-  p->cmCtx     = *ctx;
182
-  p->netH      = netH;
183
-  p->pgmIdx    = cmInvalidIdx;
182
+  p->cmCtx       = *ctx;
183
+  p->netH        = netH;
184
+  p->serialPortH = serialPortH;
185
+  p->pgmIdx      = cmInvalidIdx;
184 186
 
185 187
   // create the DSP class  linked heap
186 188
   if(cmLHeapIsValid( p->lhH = cmLHeapCreate(1024,ctx)) == false)
@@ -1560,6 +1562,13 @@ cmSymTblH_t  cmDspSysSymbolTable( cmDspSysH_t h )
1560 1562
   return p->ctx.stH;  
1561 1563
 }
1562 1564
 
1565
+cmSeH_t      cmDspSysSerialPort( cmDspSysH_t h )
1566
+{
1567
+  cmDsp_t* p = _cmDspHandleToPtr(h);
1568
+  return p->serialPortH;
1569
+}
1570
+
1571
+
1563 1572
 unsigned     cmDspSysRegisterStaticSymbol( cmDspSysH_t h, const cmChar_t* symLabel )
1564 1573
 { return cmSymTblRegisterStaticSymbol( cmDspSysSymbolTable(h), symLabel ); }
1565 1574
 

+ 2
- 1
dsp/cmDspSys.h 查看文件

@@ -23,7 +23,7 @@ extern "C" {
23 23
   //  Control Functions
24 24
   //
25 25
 
26
-  cmDspRC_t cmDspSysInitialize( cmCtx_t* ctx, cmDspSysH_t* hp, cmUdpNetH_t netH );
26
+  cmDspRC_t cmDspSysInitialize( cmCtx_t* ctx, cmDspSysH_t* hp, cmUdpNetH_t netH, cmSeH_t serialPortH );
27 27
   cmDspRC_t cmDspSysFinalize(  cmDspSysH_t* hp );
28 28
   
29 29
   bool      cmDspSysIsValid(   cmDspSysH_t h );
@@ -156,6 +156,7 @@ extern "C" {
156 156
   double          cmDspSysSampleRate( cmDspSysH_t h );
157 157
   cmJsonH_t       cmDspSysPgmRsrcHandle( cmDspSysH_t h );
158 158
   cmSymTblH_t     cmDspSysSymbolTable( cmDspSysH_t h );
159
+  cmSeH_t         cmDspSysSerialPort( cmDspSysH_t h );
159 160
 
160 161
   unsigned        cmDspSysRegisterStaticSymbol( cmDspSysH_t h, const cmChar_t* symLabel );
161 162
   unsigned        cmDspSysRegisterSymbol( cmDspSysH_t h, const cmChar_t* symLabel );

Loading…
取消
儲存