LMS 2012
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
c_output.c
Go to the documentation of this file.
1 /*
2  * LEGO® MINDSTORMS EV3
3  *
4  * Copyright (C) 2010-2013 The LEGO Group
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 
70 /*
71  * SYNCRONIZATION:
72  *
73  * Speed -100 to +100 is move forward or move backwards
74  * Turn ratio is how tight you turn and to what direction you turn
75  * - 0 value is moving straight forward
76  * - Negative values turns to the left
77  * - Positive values turns to the right
78  * - Value -100 stops the left motor
79  * - Value +100 stops the right motor
80  * - Values less than -100 makes the left motor run the opposite
81  * direction of the right motor (Spin)
82  * - Values greater than +100 makes the right motor run the opposite
83  * direction of the left motor (Spin)
84  *
85  * Example: opOUTPUT_TIME_SYNC(0, 10, 100, 50, 10000,1)
86  *
87  * 0 = Layer
88  * 10 = Motor bit field - Motor B and D
89  * 100 = Motor speed - Motor B will run at speed 100 (because ratio is positive)
90  * 10 = Turn ratio - Motor D will run at speed 50
91  * 10000 = time in mS - Motors will run for 10 sec.
92  * 1 = Brake bit - When 10 sec. has elapsed then brake both motors
93  *
94  *
95  * Example: opOUTPUT_TIME_SYNC(0, 10, 100, 150, 10000,1)
96  *
97  * 0 = Layer
98  * 10 = Motor bit field - Motor B and D
99  * 100 = Motor speed - Motor B will run at speed 100 (because ratio is positive)
100  * 10 = Turn ratio - Motor D will run at speed -50
101  * 10000 = time in mS - Motors will run for 10 sec.
102  * 1 = Brake bit - When 10 sec. has elapsed then brake both motors
103  *
104  *
105  * Example: opOUTPUT_TIME_SYNC(0, 10, 100, -50, 10000,1)
106  *
107  * 0 = Layer
108  * 10 = Motor bit field - Motor B and D
109  * 100 = Motor speed - Motor B will run at speed 50 (because ratio is positive)
110  * 10 = Turn ratio - Motor D will run at speed 100
111  * 10000 = time in mS - Motors will run for 10 sec.
112  * 1 = Brake bit - When 10 sec. has elapsed then brake both motors
113  *
114  *
115  * Example: opOUTPUT_TIME_SYNC(0, 10, 200, -150, 10000,1)
116  *
117  * 0 = Layer
118  * 10 = Motor bit field - Motor B and D
119  * 100 = Motor speed - Motor B will run at speed -50 (because ratio is positive)
120  * 10 = Turn ratio - Motor D will run at speed 100
121  * 10000 = time in mS - Motors will run for 10 sec.
122  * 1 = Brake bit - When 10 sec. has elapsed then brake both motors
123  *
124  *\
125 
126 \endverbatim
127  *
128  */
129 
130 
131 #include "lms2012.h"
132 #include "c_output.h"
133 #ifndef DISABLE_DAISYCHAIN_COM_CALL
134  #include "c_daisy.h"
135 #endif
136 
137 #if (HARDWARE != SIMULATION)
138 
139  #include <stdio.h>
140  #include <fcntl.h>
141  #include <stdlib.h>
142  #include <unistd.h>
143  #include <string.h>
144  #include <signal.h>
145  #include <sys/mman.h>
146 
148  #ifndef DISABLE_DAISYCHAIN_COM_CALL
149  static DATA8 DaisyBuf[64];
150  #endif
151 
152 
153 #else
154 
156 
158  {
159  gOutputInstance= _Instance;
160  }
161 
163  {
164  return gOutputInstance;
165  }
166 
167 #endif
168 
169 #ifdef Linux_X86
170 #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
171 #endif
172 
173 uint DELAY_COUNTER = 0;
175 
176 void OutputReset(void)
177 {
178  UBYTE Tmp;
179  DATA8 StopArr[3];
180 
181  for(Tmp = 0; Tmp < OUTPUTS; Tmp++)
182  {
183  OutputInstance.Owner[Tmp] = 0;
184  }
185 
186  StopArr[0] = (DATA8)opOUTPUT_STOP;
187  StopArr[1] = 0x0F;
188  StopArr[2] = 0x00;
189  if (OutputInstance.PwmFile >= 0)
190  {
191  write(OutputInstance.PwmFile,StopArr,3);
192  }
193 }
194 
195 
196 RESULT cOutputInit(void)
197 {
198  RESULT Result = FAIL;
199  MOTORDATA *pTmp;
200 
201  // To ensure that pMotor is never uninitialised
202  OutputInstance.pMotor = OutputInstance.MotorData;
203 
204  // Open the handle for writing commands
205  OutputInstance.PwmFile = open(PWM_DEVICE_NAME,O_RDWR);
206 
207  if (OutputInstance.PwmFile >= 0)
208  {
209 
210  // Open the handle for reading motor values - shared memory
211  OutputInstance.MotorFile = open(MOTOR_DEVICE_NAME,O_RDWR | O_SYNC);
212  if (OutputInstance.MotorFile >= 0)
213  {
214  pTmp = (MOTORDATA*)mmap(0, sizeof(OutputInstance.MotorData), PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, OutputInstance.MotorFile, 0);
215 
216  if (pTmp == MAP_FAILED)
217  {
219  close(OutputInstance.MotorFile);
220  close(OutputInstance.PwmFile);
221  }
222  else
223  {
224  OutputInstance.pMotor = (MOTORDATA*)pTmp;
225  Result = cOutputOpen();
226  }
227  }
228  }
229 
230  return (Result);
231 }
232 
233 
234 RESULT cOutputOpen(void)
235 {
236  RESULT Result = FAIL;
237 
238  UBYTE PrgStart = opPROGRAM_START;
239 
240  OutputReset();
241 
242  if (OutputInstance.PwmFile >= 0)
243  {
244  write(OutputInstance.PwmFile,&PrgStart,1);
245  }
246 
247  Result = OK;
248 
249  return (Result);
250 }
251 
252 
253 RESULT cOutputClose(void)
254 {
255  return (OK);
256 }
257 
258 
259 RESULT cOutputExit(void)
260 {
261  RESULT Result = FAIL;
262 
263  OutputReset();
264 
265  if (OutputInstance.MotorFile >= 0)
266  {
267  munmap(OutputInstance.pMotor,sizeof(OutputInstance.MotorData));
268  close(OutputInstance.MotorFile);
269  }
270 
271  if (OutputInstance.PwmFile >= 0)
272  {
273  close(OutputInstance.PwmFile);
274  }
275 
276  Result = OK;
277 
278  return (Result);
279 }
280 
281 
282 void cOutputSetTypes(char *pTypes)
283 {
284  DATA8 TypeArr[5];
285 
286  TypeArr[0] = opOUTPUT_SET_TYPE;
287  memcpy(&TypeArr[1], pTypes, 4);
288 
289  if (OutputInstance.PwmFile >= 0)
290  {
291  write(OutputInstance.PwmFile,TypeArr,sizeof(TypeArr));
292  }
293 
294 }
295 
296 
310 {
311  DATA8 Len;
312 
313  Len = 0;
314  if ((Val < 32) && (Val > -32))
315  {
316  pStr[Len] = (DATA8)(Val & 0x0000003F);
317  Len++;
318  }
319  else
320  {
321  if ((Val < DATA8_MAX) && (Val > DATA8_MIN))
322  {
323  pStr[Len] = 0x81;
324  Len++;
325  pStr[Len] = (DATA8)Val;
326  Len++;
327  }
328  else
329  {
330  if ((Val < DATA16_MAX) && (Val > DATA16_MIN))
331  {
332  pStr[Len] = 0x82;
333  Len++;
334  ((UBYTE*)pStr)[Len] = (UBYTE)(Val & 0x00FF);
335  Len++;
336  ((UBYTE*)pStr)[Len] = (UBYTE)((Val >> 8) & 0x00FF);
337  Len++;
338  }
339  else
340  {
341  pStr[Len] = 0x83;
342  Len++;
343  ((UBYTE*)pStr)[Len] = (UBYTE)(Val & 0x000000FF);
344  Len++;
345  ((UBYTE*)pStr)[Len] = (UBYTE)((Val >> 8) & 0x000000FF);
346  Len++;
347  ((UBYTE*)pStr)[Len] = (UBYTE)((Val >> 16) & 0x000000FF);
348  Len++;
349  ((UBYTE*)pStr)[Len] = (UBYTE)((Val >> 24) & 0x000000FF);
350  Len++;
351  }
352  }
353  }
354  return(Len);
355 }
356 /*
357 
358 UBYTE cMotorGetBusyFlags(void)
359 {
360  int test, test2;
361  char BusyReturn[10]; // Busy mask
362 
363  if (OutputInstance.PwmFile >= 0)
364  {
365  read(OutputInstance.PwmFile,BusyReturn,4);
366  sscanf(BusyReturn,"%u %u",&test,&test2);
367  }
368  else
369  {
370  test = 0;
371  }
372  printf("cMotorGetBusyFlags test = %d\n\r", test);
373  return(test);
374 }*/
375 
377 {
378  BusyOnes = Pattern;
379  DELAY_COUNTER = 0;
380 }
381 
383 {
384  int test, test2;
385  char BusyReturn[10]; // Busy mask
386 
387  if (OutputInstance.PwmFile >= 0)
388  {
389  read(OutputInstance.PwmFile,BusyReturn,4);
390  sscanf(BusyReturn,"%u %u",&test,&test2);
391  }
392  else
393  {
394  test = 0;
395  }
396  if(DELAY_COUNTER < 25)
397  {
398  test = BusyOnes;
399  DELAY_COUNTER++;
400  }
401 
402  return(test);
403 }
404 
405 
407 {
408  if (OutputInstance.MotorFile >= 0)
409  {
410  write(OutputInstance.MotorFile, &Flags, sizeof(Flags));
411  }
412 }
413 
414 
415 
416 //******* BYTE CODE SNIPPETS **************************************************
417 
418 
430 void cOutputPrgStop(void)
431 {
432  DSPSTAT DspStat = NOBREAK;
433  DATA8 PrgStop;
434 
435  PrgStop = (DATA8)opPROGRAM_STOP;
436  if (OutputInstance.PwmFile >= 0)
437  {
438  write(OutputInstance.PwmFile,&PrgStop,1);
439  }
440  SetDispatchStatus(DspStat);
441 }
442 
443 
458 void cOutputSetType(void)
459 {
460  DATA8 Layer;
461  DATA8 No;
462  DATA8 Type;
463  UBYTE Len;
464  DSPSTAT DspStat = NOBREAK;
465  IP TmpIp;
466 
467  TmpIp = GetObjectIp();
468  Len = 0;
469  Layer = *(DATA8*)PrimParPointer();
470  No = *(DATA8*)PrimParPointer();
471  Type = *(DATA8*)PrimParPointer();
472 
473  if (Layer == 0)
474  {
475  if ((No >= 0) && (No < OUTPUTS))
476  {
477  if (OutputInstance.OutputType[No] != Type)
478  {
479  OutputInstance.OutputType[No] = Type;
480 
481  if ((Type == TYPE_NONE) || (Type == TYPE_ERROR))
482  {
483 #ifdef DEBUG
484  printf(" Output %c Disable\r\n",'A' + No);
485 #endif
486  }
487  else
488  {
489 #ifdef DEBUG
490  printf(" Output %c Enable\r\n",'A' + No);
491 #endif
492  }
493  }
494  }
495  }
496  else
497  {
498  #ifndef DISABLE_DAISYCHAIN_COM_CALL
499  if (cDaisyReady() != BUSY)
500  {
501  DaisyBuf[Len++] = 0;
502  DaisyBuf[Len++] = 0;
503  DaisyBuf[Len++] = opOUTPUT_RESET;
504  Len += cOutputPackParam((DATA32)0, &(DaisyBuf[Len]));
505  Len += cOutputPackParam((DATA32)No, &(DaisyBuf[Len]));
506  Len += cOutputPackParam((DATA32)Type, &(DaisyBuf[Len]));
507  if(OK != cDaisyDownStreamCmd(DaisyBuf, Len, Layer))
508  {
509  SetObjectIp(TmpIp - 1);
510  DspStat = BUSYBREAK;
511  }
512  //cDaisyDownStreamCmd(DaisyBuf, Len, Layer);
513  }
514  else
515  {
516  SetObjectIp(TmpIp - 1);
517  DspStat = BUSYBREAK;
518  }
519  #endif
520  }
521  SetDispatchStatus(DspStat);
522 }
523 
524 
538 void cOutputReset(void)
539 {
540  DATA8 Layer;
541  UBYTE Nos;
542  UBYTE Len;
543  DSPSTAT DspStat = NOBREAK;
544  IP TmpIp;
545 
546  DATA8 ResetArr[2];
547 
548  TmpIp = GetObjectIp();
549  Len = 0;
550  Layer = *(DATA8*)PrimParPointer();
551  Nos = *(DATA8*)PrimParPointer();
552 
553  if (Layer == 0)
554  {
555 
556  ResetArr[0] = opOUTPUT_RESET;
557  ResetArr[1] = Nos;
558 
559  if (OutputInstance.PwmFile >= 0)
560  {
561  write(OutputInstance.PwmFile,ResetArr,sizeof(ResetArr));
562  }
563  }
564  else
565  {
566  #ifndef DISABLE_DAISYCHAIN_COM_CALL
567  if (cDaisyReady() != BUSY)
568  {
569  DaisyBuf[Len++] = 0;
570  DaisyBuf[Len++] = 0;
571  DaisyBuf[Len++] = opOUTPUT_RESET;
572  Len += cOutputPackParam((DATA32)0, &(DaisyBuf[Len]));
573  Len += cOutputPackParam((DATA32)Nos, &(DaisyBuf[Len]));
574  if(OK != cDaisyDownStreamCmd(DaisyBuf, Len, Layer))
575  {
576  SetObjectIp(TmpIp - 1);
577  DspStat = BUSYBREAK;
578  }
579  //cDaisyDownStreamCmd(DaisyBuf, Len, Layer);
580  }
581  else
582  {
583  SetObjectIp(TmpIp - 1);
584  DspStat = BUSYBREAK;
585  }
586  #endif
587  }
588  SetDispatchStatus(DspStat);
589 }
590 
591 
606 void cOutputStop(void)
607 {
608  DATA8 Layer;
609  UBYTE Nos;
610  UBYTE Brake;
611  UBYTE Len;
612  DSPSTAT DspStat = NOBREAK;
613  IP TmpIp;
614 
615  DATA8 StopArr[3];
616 
617  TmpIp = GetObjectIp();
618  Len = 0;
619  Layer = *(DATA8*)PrimParPointer();
620  Nos = *(DATA8*)PrimParPointer();
621  Brake = *(DATA8*)PrimParPointer();
622 
623  if (Layer == 0)
624  {
625  StopArr[0] = (DATA8)opOUTPUT_STOP;
626  StopArr[1] = Nos;
627  StopArr[2] = Brake;
628 
629  if (OutputInstance.PwmFile >= 0)
630  {
631  write(OutputInstance.PwmFile,StopArr,sizeof(StopArr));
632  }
633  }
634  else
635  {
636  #ifndef DISABLE_DAISYCHAIN_COM_CALL
637  if (cDaisyReady() != BUSY)
638  {
639  DaisyBuf[Len++] = 0;
640  DaisyBuf[Len++] = 0;
641  DaisyBuf[Len++] = opOUTPUT_STOP;
642  Len += cOutputPackParam((DATA32)0, &(DaisyBuf[Len]));
643  Len += cOutputPackParam((DATA32)Nos, &(DaisyBuf[Len]));
644  Len += cOutputPackParam((DATA32)Brake, &(DaisyBuf[Len]));
645  if(OK != cDaisyDownStreamCmd(DaisyBuf, Len, Layer))
646  {
647  SetObjectIp(TmpIp - 1);
648  DspStat = BUSYBREAK;
649  }
650  //cDaisyDownStreamCmd(DaisyBuf, Len, Layer);
651  }
652  else
653  {
654  SetObjectIp(TmpIp - 1);
655  DspStat = BUSYBREAK;
656  }
657  #endif
658  }
659  SetDispatchStatus(DspStat);
660 }
661 
662 
679 void cOutputSpeed(void)
680 {
681  DATA8 Layer;
682  UBYTE Nos;
683  DATA8 Speed;
684  UBYTE Len;
685  DSPSTAT DspStat = NOBREAK;
686  IP TmpIp;
687 
688  DATA8 SetSpeed[3];
689 
690  TmpIp = GetObjectIp();
691  Len = 0;
692  Layer = *(DATA8*)PrimParPointer();
693  Nos = *(DATA8*)PrimParPointer();
694  Speed = *(DATA8*)PrimParPointer();
695 
696  if (Layer == 0)
697  {
698 
699 
700  SetSpeed[0] = (DATA8)opOUTPUT_SPEED;
701  SetSpeed[1] = Nos;
702  SetSpeed[2] = Speed;
703 
704  if (OutputInstance.PwmFile >= 0)
705  {
706  write(OutputInstance.PwmFile,SetSpeed,sizeof(SetSpeed));
707  }
708  }
709  else
710  {
711  #ifndef DISABLE_DAISYCHAIN_COM_CALL
712  if (cDaisyReady() != BUSY)
713  {
714  DaisyBuf[Len++] = 0;
715  DaisyBuf[Len++] = 0;
716  DaisyBuf[Len++] = opOUTPUT_SPEED;
717  Len += cOutputPackParam((DATA32)0, &(DaisyBuf[Len]));
718  Len += cOutputPackParam((DATA32)Nos, &(DaisyBuf[Len]));
719  Len += cOutputPackParam((DATA32)Speed, &(DaisyBuf[Len]));
720  if(OK != cDaisyDownStreamCmd(DaisyBuf, Len, Layer))
721  {
722  SetObjectIp(TmpIp - 1);
723  DspStat = BUSYBREAK;
724  }
725  }
726  else
727  {
728  SetObjectIp(TmpIp - 1);
729  DspStat = BUSYBREAK;
730  }
731  #endif
732  }
733  SetDispatchStatus(DspStat);
734 }
735 
736 
751 void cOutputPower(void)
752 {
753  DATA8 Layer;
754  UBYTE Nos;
755  DATA8 Power;
756  DATA8 SetPower[3];
757  DATA8 Len;
758  DSPSTAT DspStat = NOBREAK;
759  IP TmpIp;
760 
761  TmpIp = GetObjectIp();
762  Len = 0;
763  Layer = *(DATA8*)PrimParPointer();
764  Nos = *(DATA8*)PrimParPointer();
765  Power = *(DATA8*)PrimParPointer();
766 
767  if (Layer == 0)
768  {
769  SetPower[0] = (DATA8)opOUTPUT_POWER;
770  SetPower[1] = Nos;
771  SetPower[2] = Power;
772  if (OutputInstance.PwmFile >= 0)
773  {
774  write(OutputInstance.PwmFile,SetPower,sizeof(SetPower));
775  }
776  }
777  else
778  {
779  #ifndef DISABLE_DAISYCHAIN_COM_CALL
780  if (cDaisyReady() != BUSY)
781  {
782  DaisyBuf[Len++] = 0;
783  DaisyBuf[Len++] = 0;
784  DaisyBuf[Len++] = opOUTPUT_POWER;
785  Len += cOutputPackParam((DATA32)0, &(DaisyBuf[Len]));
786  Len += cOutputPackParam((DATA32)Nos, &(DaisyBuf[Len]));
787  Len += cOutputPackParam((DATA32)Power, &(DaisyBuf[Len]));
788 
789  if(OK != cDaisyDownStreamCmd(DaisyBuf, Len, Layer))
790  {
791  SetObjectIp(TmpIp - 1);
792  DspStat = BUSYBREAK;
793  }
794  else
795  {
796  // printf("cOutPut @ opOUTPUT_POWER after cDaisyDownStreamCmd - OK and WriteState = %d\n\r", cDaisyGetLastWriteState());
797  }
798  //cDaisyDownStreamCmd(DaisyBuf, Len, Layer);
799  }
800  else
801  {
802  SetObjectIp(TmpIp - 1);
803  DspStat = BUSYBREAK;
804  }
805  #endif
806  }
807  SetDispatchStatus(DspStat);
808 }
809 
810 
824 void cOutputStart(void)
825 {
826  DATA8 Tmp;
827  DATA8 Layer;
828  UBYTE Nos;
829  DATA8 Len;
830  DSPSTAT DspStat = NOBREAK;
831  IP TmpIp;
832 
833  DATA8 StartMotor[2];
834 
835  TmpIp = GetObjectIp();
836  Len = 0;
837  Layer = *(DATA8*)PrimParPointer();
838  Nos = *(DATA8*)PrimParPointer();
839 
840  if (Layer == 0)
841  {
842  StartMotor[0] = (DATA8)opOUTPUT_START;
843  StartMotor[1] = Nos;
844  if (OutputInstance.PwmFile >= 0)
845  {
846  write(OutputInstance.PwmFile,StartMotor,sizeof(StartMotor));
847 
848  for (Tmp = 0; Tmp < OUTPUTS; Tmp++)
849  {
850  if (Nos & (0x01 << Tmp))
851  {
852  OutputInstance.Owner[Tmp] = CallingObjectId();
853  }
854  }
855  }
856  }
857  else
858  {
859  #ifndef DISABLE_DAISYCHAIN_COM_CALL
860  if (cDaisyReady() != BUSY)
861  {
862  DaisyBuf[Len++] = 0;
863  DaisyBuf[Len++] = 0;
864  DaisyBuf[Len++] = opOUTPUT_START;
865  Len += cOutputPackParam((DATA32)0, &(DaisyBuf[Len]));
866  Len += cOutputPackParam((DATA32)Nos, &(DaisyBuf[Len]));
867  if(OK != cDaisyDownStreamCmd(DaisyBuf, Len, Layer))
868  {
869  SetObjectIp(TmpIp - 1);
870  DspStat = BUSYBREAK;
871  }
872  else
873  {
874  //printf("cOutPut @ opOUTPUT_START after cDaisyDownStreamCmd - OK and WriteState = %d\n\r", cDaisyGetLastWriteState());
875  }
876  //cDaisyDownStreamCmd(DaisyBuf, Len, Layer);
877 
878  }
879  else
880  {
881  SetObjectIp(TmpIp - 1);
882  DspStat = BUSYBREAK;
883  }
884  #endif
885  }
886  SetDispatchStatus(DspStat);
887 }
888 
889 
909 void cOutputPolarity(void)
910 {
911  DATA8 Layer;
912  DATA8 Polarity[3];
913  UBYTE Len;
914  DSPSTAT DspStat = NOBREAK;
915  IP TmpIp;
916 
917  TmpIp = GetObjectIp();
918  Len = 0;
919  Layer = *(DATA8*)PrimParPointer();
920  Polarity[0] = (DATA8)opOUTPUT_POLARITY;
921  Polarity[1] = *(DATA8*)PrimParPointer();
922  Polarity[2] = *(DATA8*)PrimParPointer();
923 
924  if (Layer == 0)
925  {
926  if (OutputInstance.PwmFile >= 0)
927  {
928  write(OutputInstance.PwmFile,Polarity,sizeof(Polarity));
929  }
930  }
931  else
932  {
933  #ifndef DISABLE_DAISYCHAIN_COM_CALL
934  if (cDaisyReady() != BUSY)
935  {
936  DaisyBuf[Len++] = 0;
937  DaisyBuf[Len++] = 0;
938  DaisyBuf[Len++] = opOUTPUT_POLARITY;
939  Len += cOutputPackParam((DATA32)0, &(DaisyBuf[Len]));
940  Len += cOutputPackParam((DATA32)Polarity[1], &(DaisyBuf[Len]));
941  Len += cOutputPackParam((DATA32)Polarity[2], &(DaisyBuf[Len]));
942  if(OK != cDaisyDownStreamCmd(DaisyBuf, Len, Layer))
943  {
944  SetObjectIp(TmpIp - 1);
945  DspStat = BUSYBREAK;
946  }
947  //cDaisyDownStreamCmd(DaisyBuf, Len, Layer);
948  }
949  else
950  {
951  SetObjectIp(TmpIp - 1);
952  DspStat = BUSYBREAK;
953  }
954  #endif
955  }
956  SetDispatchStatus(DspStat);
957 }
958 
959 
979 {
980  DATA8 Layer;
981  DATA8 Tmp;
982  STEPPOWER StepPower;
983  UBYTE Len;
984  DSPSTAT DspStat = NOBREAK;
985  IP TmpIp;
986 
987  TmpIp = GetObjectIp();
988  Len = 0;
989  Layer = *(DATA8*)PrimParPointer();
990  StepPower.Cmd = opOUTPUT_STEP_POWER;
991  StepPower.Nos = *(DATA8*)PrimParPointer();
992  StepPower.Power = *(DATA8*)PrimParPointer();
993  StepPower.Step1 = *(DATA32*)PrimParPointer();
994  StepPower.Step2 = *(DATA32*)PrimParPointer();
995  StepPower.Step3 = *(DATA32*)PrimParPointer();
996  StepPower.Brake = *(DATA8*)PrimParPointer();
997 
998  if (0 == Layer)
999  {
1000  if (OutputInstance.PwmFile >= 0)
1001  {
1002  write(OutputInstance.PwmFile,(DATA8*)&(StepPower.Cmd),sizeof(StepPower));
1003 
1004  for (Tmp = 0; Tmp < OUTPUTS; Tmp++)
1005  {
1006  // Set calling id for all involved inputs
1007  if (StepPower.Nos & (0x01 << Tmp))
1008  {
1009  OutputInstance.Owner[Tmp] = CallingObjectId();
1010  }
1011  }
1012  }
1013  }
1014  else
1015  {
1016  #ifndef DISABLE_DAISYCHAIN_COM_CALL
1017  if (cDaisyReady() != BUSY)
1018  {
1019  DaisyBuf[Len++] = 0;
1020  DaisyBuf[Len++] = 0;
1021  DaisyBuf[Len++] = opOUTPUT_STEP_POWER;
1022  Len += cOutputPackParam((DATA32)0, &(DaisyBuf[Len]));
1023  Len += cOutputPackParam((DATA32)StepPower.Nos, &(DaisyBuf[Len]));
1024  Len += cOutputPackParam((DATA32)StepPower.Power, &(DaisyBuf[Len]));
1025  Len += cOutputPackParam((DATA32)StepPower.Step1, &(DaisyBuf[Len]));
1026  Len += cOutputPackParam((DATA32)StepPower.Step2, &(DaisyBuf[Len]));
1027  Len += cOutputPackParam((DATA32)StepPower.Step3, &(DaisyBuf[Len]));
1028  Len += cOutputPackParam((DATA32)StepPower.Brake, &(DaisyBuf[Len]));
1029 
1030  //if(OK != cDaisyDownStreamCmd(DaisyBuf, Len, Layer))
1031  if(OK != cDaisyMotorDownStream(DaisyBuf, Len, Layer, StepPower.Nos))
1032  {
1033  SetObjectIp(TmpIp - 1);
1034  DspStat = BUSYBREAK;
1035  }
1036 
1037  //cDaisyMotorDownStream(DaisyBuf, Len, Layer, StepPower.Nos);
1038 
1039  }
1040  else
1041  {
1042  SetObjectIp(TmpIp - 1);
1043  DspStat = BUSYBREAK;
1044  }
1045  #endif
1046  }
1047  SetDispatchStatus(DspStat);
1048 }
1049 
1050 
1070 {
1071  DATA8 Layer;
1072  DATA8 Tmp;
1073  TIMEPOWER TimePower;
1074  UBYTE Len;
1075  DSPSTAT DspStat = NOBREAK;
1076  IP TmpIp;
1077 
1078  TmpIp = GetObjectIp();
1079  Len = 0;
1080  Layer = *(DATA8*) PrimParPointer();
1081  TimePower.Cmd = opOUTPUT_TIME_POWER;
1082  TimePower.Nos = *(DATA8*) PrimParPointer();
1083  TimePower.Power = *(DATA8*) PrimParPointer();
1084  TimePower.Time1 = *(DATA32*)PrimParPointer();
1085  TimePower.Time2 = *(DATA32*)PrimParPointer();
1086  TimePower.Time3 = *(DATA32*)PrimParPointer();
1087  TimePower.Brake = *(DATA8*) PrimParPointer();
1088 
1089  if (0 == Layer)
1090  {
1091  if (OutputInstance.PwmFile >= 0)
1092  {
1093  write(OutputInstance.PwmFile,(DATA8*)&(TimePower.Cmd),sizeof(TimePower));
1094 
1095  for (Tmp = 0; Tmp < OUTPUTS; Tmp++)
1096  {
1097  // Set calling id for all involved inputs
1098  if (TimePower.Nos & (0x01 << Tmp))
1099  {
1100  OutputInstance.Owner[Tmp] = CallingObjectId();
1101  }
1102  }
1103  }
1104  }
1105  else
1106  {
1107  #ifndef DISABLE_DAISYCHAIN_COM_CALL
1108  if (cDaisyReady() != BUSY)
1109  {
1110  DaisyBuf[Len++] = 0;
1111  DaisyBuf[Len++] = 0;
1112  DaisyBuf[Len++] = opOUTPUT_TIME_POWER;
1113  Len += cOutputPackParam((DATA32)0, &(DaisyBuf[Len]));
1114  Len += cOutputPackParam((DATA32)TimePower.Nos, &(DaisyBuf[Len]));
1115  Len += cOutputPackParam((DATA32)TimePower.Power, &(DaisyBuf[Len]));
1116  Len += cOutputPackParam((DATA32)TimePower.Time1, &(DaisyBuf[Len]));
1117  Len += cOutputPackParam((DATA32)TimePower.Time2, &(DaisyBuf[Len]));
1118  Len += cOutputPackParam((DATA32)TimePower.Time3, &(DaisyBuf[Len]));
1119  Len += cOutputPackParam((DATA32)TimePower.Brake, &(DaisyBuf[Len]));
1120  if(OK != cDaisyMotorDownStream(DaisyBuf, Len, Layer, TimePower.Nos))
1121  {
1122  SetObjectIp(TmpIp - 1);
1123  DspStat = BUSYBREAK;
1124  }
1125  //cDaisyMotorDownStream(DaisyBuf, Len, Layer, TimePower.Nos);
1126  }
1127  else
1128  {
1129  SetObjectIp(TmpIp - 1);
1130  DspStat = BUSYBREAK;
1131  }
1132  #endif
1133  }
1134  SetDispatchStatus(DspStat);
1135 }
1136 
1156 {
1157  DATA8 Layer;
1158  DATA8 Tmp;
1159  STEPSPEED StepSpeed;
1160  UBYTE Len;
1161  DSPSTAT DspStat = NOBREAK;
1162  IP TmpIp;
1163 
1164  //DEBUG
1165 // int i;
1166 
1167  TmpIp = GetObjectIp();
1168  Len = 0;
1169  Layer = *(DATA8*)PrimParPointer();
1170  StepSpeed.Cmd = opOUTPUT_STEP_SPEED;
1171  StepSpeed.Nos = *(DATA8*)PrimParPointer();
1172  StepSpeed.Speed = *(DATA8*)PrimParPointer();
1173  StepSpeed.Step1 = *(DATA32*)PrimParPointer();
1174  StepSpeed.Step2 = *(DATA32*)PrimParPointer();
1175  StepSpeed.Step3 = *(DATA32*)PrimParPointer();
1176  StepSpeed.Brake = *(DATA8*)PrimParPointer();
1177 /*
1178  printf("StepSpeed.Cmd = %d\n\r", StepSpeed.Cmd);
1179  printf("StepSpeed.Nos = %d\n\r", StepSpeed.Nos);
1180  printf("StepSpeed.Speed = %d\n\r", StepSpeed.Speed);
1181  printf("StepSpeed.Step1 = %d\n\r", StepSpeed.Step1);
1182  printf("StepSpeed.Step2 = %d\n\r", StepSpeed.Step2);
1183  printf("StepSpeed.Step3 = %d\n\r", StepSpeed.Step3);
1184  printf("StepSpeed.Brake = %d\n\r", StepSpeed.Brake);
1185 
1186 */
1187  if (0 == Layer)
1188  {
1189  if (OutputInstance.PwmFile >= 0)
1190  {
1191  write(OutputInstance.PwmFile,(DATA8*)&(StepSpeed.Cmd),sizeof(StepSpeed));
1192 
1193  for (Tmp = 0; Tmp < OUTPUTS; Tmp++)
1194  {// Set calling id for all involved inputs
1195 
1196  if (StepSpeed.Nos & (0x01 << Tmp))
1197  {
1198  OutputInstance.Owner[Tmp] = CallingObjectId();
1199  }
1200  }
1201  }
1202  }
1203  else
1204  {
1205  #ifndef DISABLE_DAISYCHAIN_COM_CALL
1206  if (cDaisyReady() != BUSY)
1207  {
1208  DaisyBuf[Len++] = 0;
1209  DaisyBuf[Len++] = 0;
1210  DaisyBuf[Len++] = opOUTPUT_STEP_SPEED;
1211  Len += cOutputPackParam((DATA32)0, &(DaisyBuf[Len]));
1212  Len += cOutputPackParam((DATA32)StepSpeed.Nos, &(DaisyBuf[Len]));
1213  Len += cOutputPackParam((DATA32)StepSpeed.Speed, &(DaisyBuf[Len]));
1214  Len += cOutputPackParam((DATA32)StepSpeed.Step1, &(DaisyBuf[Len]));
1215  Len += cOutputPackParam((DATA32)StepSpeed.Step2, &(DaisyBuf[Len]));
1216  Len += cOutputPackParam((DATA32)StepSpeed.Step3, &(DaisyBuf[Len]));
1217  Len += cOutputPackParam((DATA32)StepSpeed.Brake, &(DaisyBuf[Len]));
1218 
1219  /* printf("Len = %d\n\r", Len);
1220  for(i = 0; i < Len; i++)
1221  printf("DaisyBuf[%d]= %x\n\r", i, DaisyBuf[i]);
1222  printf("\n\r");
1223 */
1224 
1225  if(OK != cDaisyMotorDownStream(DaisyBuf, Len, Layer, StepSpeed.Nos))
1226  {
1227  printf("NOT ok txed cOutputStepSpeed\n\r");
1228  SetObjectIp(TmpIp - 1);
1229  DspStat = BUSYBREAK;
1230  }
1231  else
1232  {
1233  /* for(i = 0; i < Len; i++)
1234  printf("DaisyBuf[%d]= %d, ", i, DaisyBuf[i]);
1235  printf("\n\r");
1236 */
1237  }
1238  //cDaisyMotorDownStream(DaisyBuf, Len, Layer, StepSpeed.Nos);
1239  }
1240  else
1241  {
1242  SetObjectIp(TmpIp - 1);
1243  DspStat = BUSYBREAK;
1244  }
1245  #endif
1246  }
1247  SetDispatchStatus(DspStat);
1248 }
1249 
1250 
1270 {
1271  DATA8 Layer;
1272  DATA8 Tmp;
1273  TIMESPEED TimeSpeed;
1274  UBYTE Len;
1275  DSPSTAT DspStat = NOBREAK;
1276  IP TmpIp;
1277 
1278  TmpIp = GetObjectIp();
1279  Len = 0;
1280  Layer = *(DATA8*)PrimParPointer();
1281  TimeSpeed.Cmd = (DATA8)opOUTPUT_TIME_SPEED;
1282  TimeSpeed.Nos = *(DATA8*)PrimParPointer();
1283  TimeSpeed.Speed = *(DATA8*)PrimParPointer();
1284  TimeSpeed.Time1 = *(DATA32*)PrimParPointer();
1285  TimeSpeed.Time2 = *(DATA32*)PrimParPointer();
1286  TimeSpeed.Time3 = *(DATA32*)PrimParPointer();
1287  TimeSpeed.Brake = *(DATA8*)PrimParPointer();
1288 
1289  if (0 == Layer)
1290  {
1291  if (OutputInstance.PwmFile >= 0)
1292  {
1293  write(OutputInstance.PwmFile,(DATA8*)&(TimeSpeed.Cmd),sizeof(TimeSpeed));
1294 
1295  for (Tmp = 0; Tmp < OUTPUTS; Tmp++)
1296  {
1297  // Set calling id for all involved inputs
1298  if (TimeSpeed.Nos & (0x01 << Tmp))
1299  {
1300  OutputInstance.Owner[Tmp] = CallingObjectId();
1301  }
1302  }
1303  }
1304  }
1305  else
1306  {
1307  #ifndef DISABLE_DAISYCHAIN_COM_CALL
1308  if (cDaisyReady() != BUSY)
1309  {
1310  DaisyBuf[Len++] = 0;
1311  DaisyBuf[Len++] = 0;
1312  DaisyBuf[Len++] = opOUTPUT_TIME_SPEED;
1313  Len += cOutputPackParam((DATA32)0, &(DaisyBuf[Len]));
1314  Len += cOutputPackParam((DATA32)TimeSpeed.Nos, &(DaisyBuf[Len]));
1315  Len += cOutputPackParam((DATA32)TimeSpeed.Speed, &(DaisyBuf[Len]));
1316  Len += cOutputPackParam((DATA32)TimeSpeed.Time1, &(DaisyBuf[Len]));
1317  Len += cOutputPackParam((DATA32)TimeSpeed.Time2, &(DaisyBuf[Len]));
1318  Len += cOutputPackParam((DATA32)TimeSpeed.Time3, &(DaisyBuf[Len]));
1319  Len += cOutputPackParam((DATA32)TimeSpeed.Brake, &(DaisyBuf[Len]));
1320  if(OK != cDaisyMotorDownStream(DaisyBuf, Len, Layer, TimeSpeed.Nos))
1321  {
1322  SetObjectIp(TmpIp - 1);
1323  DspStat = BUSYBREAK;
1324  }
1325  //cDaisyMotorDownStream(DaisyBuf, Len, Layer, TimeSpeed.Nos);
1326  }
1327  else
1328  {
1329  SetObjectIp(TmpIp - 1);
1330  DspStat = BUSYBREAK;
1331  }
1332  #endif
1333  }
1334  SetDispatchStatus(DspStat);
1335 }
1336 
1337 
1356 {
1357  DATA8 Layer;
1358  DATA8 Tmp;
1359  STEPSYNC StepSync;
1360  UBYTE Len;
1361  DSPSTAT DspStat = NOBREAK;
1362  IP TmpIp;
1363 
1364  TmpIp = GetObjectIp();
1365  Len = 0;
1366  Layer = *(DATA8*)PrimParPointer();
1367  StepSync.Cmd = opOUTPUT_STEP_SYNC;
1368  StepSync.Nos = *(DATA8*)PrimParPointer();
1369  StepSync.Speed = *(DATA8*)PrimParPointer();
1370  StepSync.Turn = *(DATA16*)PrimParPointer();
1371  StepSync.Step = *(DATA32*)PrimParPointer();
1372  StepSync.Brake = *(DATA8*)PrimParPointer();
1373 
1374  if (0 == Layer)
1375  {
1376  if (OutputInstance.PwmFile >= 0)
1377  {
1378  write(OutputInstance.PwmFile,(DATA8*)&(StepSync.Cmd),sizeof(StepSync));
1379 
1380  for (Tmp = 0; Tmp < OUTPUTS; Tmp++)
1381  {
1382  // Set calling id for all involved outputs
1383  if (StepSync.Nos & (0x01 << Tmp))
1384  {
1385  OutputInstance.Owner[Tmp] = CallingObjectId();
1386  }
1387  }
1388  }
1389  }
1390  else
1391  {
1392  #ifndef DISABLE_DAISYCHAIN_COM_CALL
1393  if (cDaisyReady() != BUSY)
1394  {
1395  DaisyBuf[Len++] = 0;
1396  DaisyBuf[Len++] = 0;
1397  DaisyBuf[Len++] = opOUTPUT_STEP_SYNC;
1398  Len += cOutputPackParam((DATA32)0, &(DaisyBuf[Len]));
1399  Len += cOutputPackParam((DATA32)StepSync.Nos, &(DaisyBuf[Len]));
1400  Len += cOutputPackParam((DATA32)StepSync.Speed, &(DaisyBuf[Len]));
1401  Len += cOutputPackParam((DATA32)StepSync.Turn, &(DaisyBuf[Len]));
1402  Len += cOutputPackParam((DATA32)StepSync.Step, &(DaisyBuf[Len]));
1403  Len += cOutputPackParam((DATA32)StepSync.Brake, &(DaisyBuf[Len]));
1404  if(OK != cDaisyMotorDownStream(DaisyBuf, Len, Layer, StepSync.Nos))
1405  {
1406  SetObjectIp(TmpIp - 1);
1407  DspStat = BUSYBREAK;
1408  }
1409  //cDaisyMotorDownStream(DaisyBuf, Len, Layer, StepSync.Nos);
1410  }
1411  else
1412  {
1413  SetObjectIp(TmpIp - 1);
1414  DspStat = BUSYBREAK;
1415  }
1416  #endif
1417  }
1418  SetDispatchStatus(DspStat);
1419 }
1420 
1421 
1441 {
1442  DATA8 Layer;
1443  DATA8 Tmp;
1444  TIMESYNC TimeSync;
1445  UBYTE Len;
1446  DSPSTAT DspStat = NOBREAK;
1447  IP TmpIp;
1448 
1449  TmpIp = GetObjectIp();
1450  Len = 0;
1451  Layer = *(DATA8*)PrimParPointer();
1452  TimeSync.Cmd = opOUTPUT_TIME_SYNC;
1453  TimeSync.Nos = *(DATA8*)PrimParPointer();
1454  TimeSync.Speed = *(DATA8*)PrimParPointer();
1455  TimeSync.Turn = *(DATA16*)PrimParPointer();
1456  TimeSync.Time = *(DATA32*)PrimParPointer();
1457  TimeSync.Brake = *(DATA8*)PrimParPointer();
1458 
1459  if (0 == Layer)
1460  {
1461  if (OutputInstance.PwmFile >= 0)
1462  {
1463  write(OutputInstance.PwmFile,(DATA8*)&(TimeSync.Cmd),sizeof(TimeSync));
1464 
1465  for (Tmp = 0; Tmp < OUTPUTS; Tmp++)
1466  {
1467  // Set calling id for all involved outputs
1468  if (TimeSync.Nos & (0x01 << Tmp))
1469  {
1470  OutputInstance.Owner[Tmp] = CallingObjectId();
1471  }
1472  }
1473  }
1474  }
1475  else
1476  {
1477  #ifndef DISABLE_DAISYCHAIN_COM_CALL
1478  if (cDaisyReady() != BUSY)
1479  {
1480  DaisyBuf[Len++] = 0;
1481  DaisyBuf[Len++] = 0;
1482  DaisyBuf[Len++] = opOUTPUT_TIME_SYNC;
1483  Len += cOutputPackParam((DATA32)0, &(DaisyBuf[Len]));
1484  Len += cOutputPackParam((DATA32)TimeSync.Nos, &(DaisyBuf[Len]));
1485  Len += cOutputPackParam((DATA32)TimeSync.Speed, &(DaisyBuf[Len]));
1486  Len += cOutputPackParam((DATA32)TimeSync.Turn, &(DaisyBuf[Len]));
1487  Len += cOutputPackParam((DATA32)TimeSync.Time, &(DaisyBuf[Len]));
1488  Len += cOutputPackParam((DATA32)TimeSync.Brake, &(DaisyBuf[Len]));
1489  if(OK != cDaisyMotorDownStream(DaisyBuf, Len, Layer, TimeSync.Nos))
1490  {
1491  SetObjectIp(TmpIp - 1);
1492  DspStat = BUSYBREAK;
1493  }
1494  //cDaisyMotorDownStream(DaisyBuf, Len, Layer, TimeSync.Nos);
1495  }
1496  else
1497  {
1498  SetObjectIp(TmpIp - 1);
1499  DspStat = BUSYBREAK;
1500  }
1501  #endif
1502  }
1503  SetDispatchStatus(DspStat);
1504 }
1505 
1506 
1520 void cOutputRead(void)
1521 {
1522 
1523  DATA8 Layer;
1524  DATA8 No;
1525  DATA8 Speed = 0;
1526  DATA32 Tacho = 0;
1527 
1528  Layer = *(DATA8*)PrimParPointer();
1529  No = *(DATA8*)PrimParPointer();
1530 
1531  if (0 == Layer)
1532  {
1533  if (No < OUTPUTS)
1534  {
1535  Speed = OutputInstance.pMotor[No].Speed;
1536  Tacho = OutputInstance.pMotor[No].TachoCounts;
1537  }
1538  }
1539  *(DATA8*)PrimParPointer() = Speed;
1540  *(DATA32*)PrimParPointer() = Tacho;
1541 }
1542 
1543 
1544 
1561 void cOutputReady(void)
1562 {
1563 
1564  OBJID Owner;
1565  DATA8 Layer, Tmp, Nos;
1566  IP TmpIp;
1567  DSPSTAT DspStat = NOBREAK;
1568  UBYTE Bits;
1569 
1570  int test;
1571  int test2;
1572 
1573  char BusyReturn[10]; // Busy mask
1574 
1575  TmpIp = GetObjectIp();
1576 
1577  Layer = *(DATA8*)PrimParPointer();
1578  Nos = *(DATA8*)PrimParPointer();
1579  Owner = CallingObjectId();
1580 
1581  if (0 == Layer)
1582  {
1583  if (OutputInstance.PwmFile >= 0)
1584  {
1585  read(OutputInstance.PwmFile,BusyReturn,4);
1586 
1587  sscanf(BusyReturn,"%u %u",&test,&test2);
1588 
1589  for (Tmp = 0;(Tmp < OUTPUTS) && (DspStat == NOBREAK);Tmp++)
1590  {
1591  // Check resources for NOTREADY
1592  if (Nos & (1 << Tmp))
1593  {
1594  // Only relevant ones
1595  if (test & (1 << Tmp))
1596  {
1597  // If BUSY check for OVERRULED
1598  if (OutputInstance.Owner[Tmp] == Owner)
1599  {
1600  DspStat = BUSYBREAK;
1601  }
1602  }
1603  }
1604  }
1605  }
1606  }
1607  else
1608  {
1609  Bits = cDaisyCheckBusyBit(Layer, Nos);
1610  Bits = 0;
1611 
1612  for (Tmp = 0;(Tmp < OUTPUTS) && (DspStat == NOBREAK);Tmp++)
1613  {
1614  // Check resources for NOTREADY
1615  if (Nos & (1 << Tmp))
1616  {
1617  // Only relevant ones
1618  if (Bits & (1 << Tmp))
1619  {
1620  // If BUSY check for OVERRULED
1621  if (OutputInstance.Owner[Tmp] == Owner)
1622  {
1623  DspStat = BUSYBREAK;
1624  }
1625  }
1626  }
1627  }
1628  }
1629 
1630  if (DspStat == BUSYBREAK)
1631  {
1632  // Rewind IP
1633  SetObjectIp(TmpIp - 1);
1634  }
1635  SetDispatchStatus(DspStat);
1636 }
1637 
1638 
1654 void cOutputTest(void)
1655 {
1656 
1657  DATA8 Layer, Nos, Busy = 0;
1658 
1659  int test;
1660  int test2;
1661 
1662  char BusyReturn[20]; // Busy mask
1663 
1664  Layer = *(DATA8*)PrimParPointer();
1665  Nos = *(DATA8*)PrimParPointer();
1666 
1667  if (0 == Layer)
1668  {
1669  if (OutputInstance.PwmFile >= 0)
1670  {
1671  read(OutputInstance.PwmFile,BusyReturn,10);
1672  sscanf(BusyReturn,"%u %u",&test,&test2);
1673 
1674  if (Nos & (DATA8)test2)
1675  {
1676  Busy = 1;
1677  }
1678  }
1679  }
1680  else
1681  {
1682  if (cDaisyCheckBusyBit(Layer, Nos))
1683  {
1684  Busy = 1;
1685  }
1686  }
1687  *(DATA8*)PrimParPointer() = Busy;
1688 }
1689 
1690 
1706 {
1707  DATA8 Layer;
1708  DATA8 ClrCnt[2];
1709  UBYTE Len;
1710  DSPSTAT DspStat = NOBREAK;
1711  IP TmpIp;
1712  UBYTE Tmp;
1713 
1714  TmpIp = GetObjectIp();
1715  Len = 0;
1716  Layer = *(DATA8*)PrimParPointer();
1717  ClrCnt[0] = opOUTPUT_CLR_COUNT;
1718  ClrCnt[1] = *(DATA8*)PrimParPointer();
1719 
1720  if (0 == Layer)
1721  {
1722  if (OutputInstance.PwmFile >= 0)
1723  {
1724  write(OutputInstance.PwmFile, ClrCnt, sizeof(ClrCnt));
1725  }
1726 
1727  // Also the user layer entry to get immediate clear
1728  for(Tmp = 0; Tmp < OUTPUTS; Tmp++)
1729  {
1730  if (ClrCnt[1] & (1 << Tmp))
1731  {
1732  OutputInstance.pMotor[Tmp].TachoSensor = 0;
1733  }
1734  }
1735  }
1736  else
1737  {
1738  #ifndef DISABLE_DAISYCHAIN_COM_CALL
1739  if (cDaisyReady() != BUSY)
1740  {
1741  DaisyBuf[Len++] = 0;
1742  DaisyBuf[Len++] = 0;
1743  DaisyBuf[Len++] = opOUTPUT_CLR_COUNT;
1744  Len += cOutputPackParam((DATA32)0, &(DaisyBuf[Len]));
1745  Len += cOutputPackParam((DATA32)ClrCnt[1], &(DaisyBuf[Len]));
1746  if(OK != cDaisyDownStreamCmd(DaisyBuf, Len, Layer))
1747  {
1748  SetObjectIp(TmpIp - 1);
1749  DspStat = BUSYBREAK;
1750  }
1751  //cDaisyDownStreamCmd(DaisyBuf, Len, Layer);
1752  }
1753  else
1754  {
1755  SetObjectIp(TmpIp - 1);
1756  DspStat = BUSYBREAK;
1757  }
1758  #endif
1759  }
1760  SetDispatchStatus(DspStat);
1761 }
1762 
1763 
1780 {
1781  DATA8 Layer;
1782  DATA8 No;
1783  DATA32 Tacho;
1784 
1785  Layer = *(DATA8*)PrimParPointer();
1786  No = *(DATA8*)PrimParPointer();
1787 
1788  if (0 == Layer)
1789  {
1790  if (No < OUTPUTS)
1791  {
1792  Tacho = OutputInstance.pMotor[No].TachoSensor;
1793  }
1794  }
1795  *(DATA32*)PrimParPointer() = Tacho;
1796 }
1797 
1798 
1799 //*****************************************************************************
RESULT cOutputInit(void)
Definition: c_output.c:196
RESULT cDaisyDownStreamCmd(DATA8 *pData, DATA8 Length, DATA8 Layer)
Definition: c_daisy.c:665
void SetDispatchStatus(DSPSTAT DspStat)
Set object (dispatch) status.
Definition: lms2012.c:256
UBYTE cDaisyCheckBusyBit(UBYTE Layer, UBYTE PortBits)
Definition: c_daisy.c:360
void cOutputSetType(void)
opOUTPUT_SET_TYPE byte code
Definition: c_output.c:458
SLONG TachoSensor
Definition: lms2012.h:1348
RESULT cOutputOpen(void)
Definition: c_output.c:234
#define DATA8_MIN
Definition: bytecodes.h:1497
void cOutputTimeSync(void)
opOUTPUT_STEP_SYNC byte code
Definition: c_output.c:1440
DATA32 Time2
Definition: lms2012.h:1368
void ResetDelayCounter(UBYTE Pattern)
Definition: c_output.c:376
uint DELAY_COUNTER
Definition: c_output.c:173
SWORD DATA16
VM Type for 2 byte signed value.
Definition: lmstypes.h:62
void LogErrorNumber(ERR Err)
Definition: lms2012.c:445
DATA8 Power
Definition: lms2012.h:1366
SLONG DATA32
VM Type for 4 byte signed value.
Definition: lmstypes.h:63
OBJID Owner[OUTPUTS]
Definition: c_output.h:66
void cMotorSetBusyFlags(UBYTE Flags)
Definition: c_output.c:406
RESULT cOutputExit(void)
Definition: c_output.c:259
UWORD OBJID
Object id type.
Definition: lmstypes.h:73
OUTPUT_GLOBALS * gOutputInstance
Definition: c_output.c:155
UBYTE cOutputPackParam(DATA32 Val, DATA8 *pStr)
Definition: c_output.c:309
void SetObjectIp(IP Ip)
Set current instruction pointer.
Definition: lms2012.c:309
#define DATA16_MAX
Definition: bytecodes.h:1500
Port empty or not available.
Definition: lms2012.h:585
DATA8 Brake
Definition: lms2012.h:1412
DATA16 Turn
Definition: lms2012.h:1410
void cOutputReset(void)
opOUTPUT_RESET byte code
Definition: c_output.c:538
void * PrimParPointer(void)
Get next encoded parameter from byte code stream.
Definition: lms2012.c:694
DATA32 Time
Definition: lms2012.h:1411
void cOutputStepSpeed(void)
opOUTPUT_STEP_SPEED byte code
Definition: c_output.c:1155
IP GetObjectIp(void)
Get current instruction pointer.
Definition: lms2012.c:298
DATA32 Time1
Definition: lms2012.h:1389
UBYTE BusyOnes
Definition: c_output.c:174
DATA8 Speed
Definition: lms2012.h:1399
DATA8 Nos
Definition: lms2012.h:1354
OBJID CallingObjectId(void)
Get calling object id.
Definition: lms2012.c:196
DATA32 Time3
Definition: lms2012.h:1369
DATA8 Power
Definition: lms2012.h:1355
DATA8 Speed
Definition: lms2012.h:1377
DATA8 Speed
Definition: lms2012.h:1409
IMGDATA * IP
Instruction pointer type.
Definition: lmstypes.h:74
DATA8 Cmd
Definition: lms2012.h:1353
void cOutputClrCount(void)
opOUTPUT_CLR_COUNT byte code
Definition: c_output.c:1705
DATA8 Brake
Definition: lms2012.h:1370
void cOutputStepPower(void)
opOUTPUT_STEP_POWER byte code
Definition: c_output.c:978
DATA16 Turn
Definition: lms2012.h:1400
DATA8 Nos
Definition: lms2012.h:1365
DATA8 Brake
Definition: lms2012.h:1402
void cOutputStepSync(void)
opOUTPUT_STEP_SYNC byte code
Definition: c_output.c:1355
void cOutputRead(void)
opOUTPUT_READ byte code
Definition: c_output.c:1520
SLONG TachoCounts
Definition: lms2012.h:1346
RESULT cOutputClose(void)
Definition: c_output.c:253
DATA32 Step2
Definition: lms2012.h:1357
void cOutputPower(void)
opOUTPUT_POWER byte code
Definition: c_output.c:751
Port not empty and type is invalid.
Definition: lms2012.h:586
SBYTE Speed
Definition: lms2012.h:1347
DATA32 Step3
Definition: lms2012.h:1358
void cOutputPolarity(void)
opOUTPUT_POLARITY byte code
Definition: c_output.c:909
RESULT cDaisyMotorDownStream(DATA8 *pData, DATA8 Length, DATA8 Layer, DATA8 PortField)
Definition: c_daisy.c:399
DATA8 Brake
Definition: lms2012.h:1392
DATA8 OutputType[OUTPUTS]
Definition: c_output.h:65
void OutputReset(void)
Definition: c_output.c:176
DATA8 Cmd
Definition: lms2012.h:1397
DATA8 Nos
Definition: lms2012.h:1376
MOTORDATA * pMotor
Definition: c_output.h:72
unsigned char UBYTE
Basic Type used to symbolise 8 bit unsigned values.
Definition: lmstypes.h:29
DATA8 Brake
Definition: lms2012.h:1381
DATA8 Cmd
Definition: lms2012.h:1407
void SetPower(UBYTE Port, SLONG Power)
Definition: d_pwm.c:806
DATA32 Time1
Definition: lms2012.h:1367
void cOutputStop(void)
opOUTPUT_STOP byte code
Definition: c_output.c:606
void cOutputStart(void)
opOUTPUT_START byte code
Definition: c_output.c:824
void cOutputPrgStop(void)
opOUTPUT_PRG_STOP byte code
Definition: c_output.c:430
#define OUTPUTS
Number of output ports in the system.
Definition: lms2012.h:191
DATA8 Cmd
Definition: lms2012.h:1386
DATA8 Nos
Definition: lms2012.h:1398
DATA32 Step1
Definition: lms2012.h:1356
DATA32 Time2
Definition: lms2012.h:1390
DATA8 Cmd
Definition: lms2012.h:1364
void cOutputSetTypes(char *pTypes)
Definition: c_output.c:282
DATA32 Step2
Definition: lms2012.h:1379
DATA32 Step1
Definition: lms2012.h:1378
void cOutputTest(void)
opOUTPUT_TEST byte code
Definition: c_output.c:1654
DATA8 Speed
Definition: lms2012.h:1388
DATA8 Brake
Definition: lms2012.h:1359
void cOutputTimePower(void)
opOUTPUT_TIME_POWER byte code
Definition: c_output.c:1069
RESULT cDaisyReady(void)
Definition: c_daisy.c:531
SBYTE DATA8
VM Type for 1 byte signed value.
Definition: lmstypes.h:61
#define OutputInstance
Definition: c_output.h:78
void cOutputSpeed(void)
opOUTPUT_SPEED byte code
Definition: c_output.c:679
UBYTE cMotorGetBusyFlags(void)
Definition: c_output.c:382
void cOutputTimeSpeed(void)
opOUTPUT_TIME_SPEED byte code
Definition: c_output.c:1269
#define DATA16_MIN
Definition: bytecodes.h:1499
DATA8 Nos
Definition: lms2012.h:1387
void cOutputGetCount(void)
opOUTPUT_GET_COUNT byte code
Definition: c_output.c:1779
DSPSTAT
Definition: lms2012.h:665
DATA8 Cmd
Definition: lms2012.h:1375
DATA8 Nos
Definition: lms2012.h:1408
void cOutputReady(void)
opOUTPUT_READY byte code
Definition: c_output.c:1561
Break because of waiting for completion.
Definition: lms2012.h:671
DATA32 Step
Definition: lms2012.h:1401
Dispatcher running (looping)
Definition: lms2012.h:667
void setOutputInstance(OUTPUT_GLOBALS *_Instance)
Definition: c_output.c:157
OUTPUT_GLOBALS * getOutputInstance()
Definition: c_output.c:162
#define DATA8_MAX
Definition: bytecodes.h:1498
DATA32 Time3
Definition: lms2012.h:1391
MOTORDATA MotorData[OUTPUTS]
Definition: c_output.h:71
DATA32 Step3
Definition: lms2012.h:1380