Home

C Programmer`s Toolkit for Series 90 PCMs User`s Manual, GFK

image

Contents

1. ABORT REGISTER DATA STATE Write Regs timed out COMREQ received Write regs completed COMREQ Ack received COMREQ wy ACK COMPLETE STATE REGS_ DATA_COMPLETE_ STATE WAIT_ FOR_EVENT_ OIT Command received WRITE_ REGISTER_DATA_ STATE Display write timed out COMREQ Ack timed out ABORT_ COMREO_ACK_ STATE Displaywrite A completed DISPLAY DATA COMPLETE STATE DISPLAY DATA STATE Figure 6 1 State Transition Diagram Of AST Based Example Each state which is triggered by an event has one or more actions that the program takes when it is in that state When all the actions of a particular state are completed another state transition takes place through the unlabeled arrow leading away from that state 6 10 C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A The program s main function begins with START STATE where the actions initialize variables and open I O channels The for loopin main never terminates it is WAIT FOR EVENT STATE The actions for all the other states are in the eight AST functions Each AST function contains code to perform all the actions for the program state in its identifier A comment in each AST function names the event which triggers it include lt vtos h gt include lt memory h gt include lt cpu_data h gt define COMMAND SIZE d
2. GFK 0771A Chapter 5 PCM Libraries and Header Files 5 7 5 6 The PCM supports I O through named devices and all devices use a common access model Presently these devices are available Device Name Description COMI COM2 The PCM serial ports REM1 REM2 The PCM backplane remote devices CPU lt object name gt lt qualifiers gt The PCM backplane device RAM The PCM RAM disk file system ROM The PCM 301 EEROM device file system PC The MS DOS file system on an attached personal computer NULL A dummy device which doesnot support actual I O For more information on specific PCM devices see Open_dev in the PCM C Function Library Reference Manual GFK 0772 A channel must be opened on a device by calling Open dev before any I O operations may take place Data is input from a device by calling Read dev and output to a device by calling Write dev When I O operations on a channel are completed it may be closed by calling Close dev The data pointer for an I O channel may be set to a specified position by using Seek dev The Devctl dev function may be used to format the PCM 301 EEROM device delete named files return the names in a file directory determine the unused file space remaining in the EEROM device set or clear AST notification of received serial breaks and set or clear the serial All Sent event flag Ioctl dev can be called to determine whether a specified channel i
3. Communication Between Tasks VTOS tasks can signal each other by using event flags Event flags simply notify the receiving task that an event has occurred They carry no information about the event A task can send signals plus information to another task by using asynchronous traps Finally tasks can exchange data through shared memory modules shared files or a block of memory reserved by the PCM Y Set upper memory limit command Access to these shared memory resources can be controlled with VTOS semaphores C Programmer s Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Event Flags Chapter 6 in this manual explains how application tasks can request VTOS to notify them with event flags when timer and I O events occur Tasks can also signal each other directly by setting local and global event flags SWAPC is a simple example in which two tasks signal each other using global event flags Both tasks run the same code the C source is shown here SWAP C include vtos h include lt stdio h gt define USER_TASKS 0x07FF word Task flags EF 15 EF 14 EF 13 EF 12 EF 11 EF 10 EF 09 EF_08 EF 07 EF 06 EF 05 EF 04 EF 03 EF 02 EF O1 EF 00 void maint word active_tasks word other_flag word my_task Get_task_id word my_flag Task_flags my_task printf task d my flag x n my task my flag for Do something useful here Reset_
4. RR eee ke ke ke e ke hehehe e ke KR ehe KKK ke e e e e KK ke e e ke KKK e e e e e e He He e he e e ke e e de ke e He He He He he e e He He He He ke ke Initialize the command and data blocks for COMMREQs sent to TASK2 The status location is type 8 offset 28 M0029 ce KKK KKK KKK e e e ke kk ke kk e he he hehe hehe e e e e ke ke ke kk e He hehe hehe he e e e e ke ke ke ke ke e e e hc ke ke ke ke ke ke ke ke e ke e e ee Program PLC 70 C PCMC EXAMPLES DEMO_3T PLC_70 Block _MAIN Listing 9 1 Continued C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A GFK 0771A 12 10 92 15 22 GE FANUC SERIES 90 70 DOCUMENTATION v3 04 PCM C Demo Application For Series 90 70 PLC RUNG 16 I ALW ON BLKMV I INT I CONST IN1 Q R00020 00001 I I CONST IN2 00000 I I I CONST IN3 400008 I I CONST IN4 00028 I I CONST IN5 00000 I I I I I I I CONST IN6 00000 I CONST IN7 01234 lt lt RUNG 17 gt gt ATV_CR2 COMMENT RR eee ke ke ke e ke ehe he KK ke e ke e ke kk e e ke e Sk KK e e ke KKK ke e KER KKK e e e ke ke He He e e de e e He KERR KKK e eek Latch a request to send a COMMREQ to TASK2 when M0021 is toggled on zi See the comment at RUNG
5. Please enter copyright text file name copr txt PCM EXAMPLES COPR TXT Enter Please enter file name to be loaded into the PROM image PCM EXAMPLES RUN HELLO BAT lt Enter gt Please enter the name for the module RUNHELLO BAT PCMEXEC BAT lt Enter gt Do you wish this module to appear in the directory listing Y lt Enter gt Do you wish this module to be copied to RAM before use N lt Enter gt Please enter file name to be loaded into the PROM image HELLO EXE Enter Please enter the name for the module HELLO EXE lt Enter gt Do you wish this module to appear in the directory listing Y Enter stack size 800 Please enter file name to be loaded into the PROM image lt Enter gt next available paragraph is c43f 0 After printing its invocation message BLD PROM asks for the name of an initialization file However initialization files are not supported by Microsoft LINK the response is just a semicolon followed by Enter Chapter 11 Utilities 11 11 11 12 BLD PROM needs to know the starting address for the ROM because one starting address C000 0 hexadecimal is used for the PCM711 PCM301 and PCM311 and a different starting address is used for the PCM300 A000 0 hexadecimal Since the target PCM model is the PCM711 the default is correct this time the response is just the Enter key Next BLD_PROM prompts for a text file containing a copyright string An example copyright string
6. device result Accesses the completion status and return value of deviceI O operations env blk Specifies the execution environment for executablememory modules Jong ptr Accesses the segment and offset parts ofa far pointer asan alternative to the Microsoft C FP SEG and FP OFF macros mod hdr Describes each PCM memory module special dev 8 type Defines the type and offset for PLC data references in the form used by Special dev when called with special code 8 Chapter 5 PCM Libraries and Header Files 5 11 5 12 These data types are defined in CPU DATA H Table 5 15 VTOS Types in CPU DATA H Type Name Purpose cmrq union Astructure type componentof comreq msg It defines the COMMREQ union type and consists of both the short emrq and long cmrq structure types comreq msg Defines COMMREO messages it consists of msg hdr and cmrq union members cpu long status Defines the CPU long status structurereturned by reading the CPU LST AT CPU Long Status device cpu rt clk Astructure type component of cp sweep info It defines the CPU scheduler clock structure type cpu_short_status Defines the CPU short status structure type returned by reading the CPU SST AT CPU Short Status device It is approximately equivalent to the PLC_STATUS_INFO_STRUC type defined in STATUS H cpu_stat_flags Astructure type component of cpu_short_status It defines the P
7. Chapter 6 PCM Real Time Programming 6 3 When VTOS calls an AST function a pointer to an ast blk structure is passed as the only parameter For an I O operation the ast_blk contains the completion status of the operation When a timer AST function is called the structure contains a value which identifies the timer which expired The application may suspend itself to wait for one or more AST NOTIFY events to occur bycalling Wait ast When one of the events occurs the corresponding AST function executes as soon as the task has the highest priority of all the tasks which are ready When the AST function returns the task s call to Wait ast will return Strategies For Predictable Real Time Performance There is no single best way to design real time PCM applications Every application has a unique set of requirements WAIT mode event processing fits some requirements very well and has the advantage of simplicity Of the asynchronous techniques EVENT NOTIFY processing requires the smallest VTOS processing overhead It is well suited to applications where events must be processed in a fixed order AST NOTIFY processing requires the most VTOS overhead but is well suited to applications where events must be processed in order of their occurrence Using WAIT Mode Event Processing 6 4 For example suppose that the requirements of a PLC application specify that a certain safety related condition must be monitored continuously and that an
8. Table 11 1 STKMOD Error Messages Message Description Invalidoption One of the command line options was invalid Nostack size value specified The s option was used but was not followed by a value The space between the option and the value may have been omitted can t open file The specified EXE file could not be opened premature end of data reading file The specified EXE file is corrupted invalid EXE file The specified EXE file does not begin with the MS DOS executable file marker error writing file The modified EXE file header could not be written to disk The file may have read only access C Programmer s Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A PCMDUMP Program PCMDUMDEXE is a utility program for formatting the binary output of the PCM task dump PD command To use PCMDUMPEXE 1 Stop the application in the task state you want to examine by pressing the restart reset button for less than 5 seconds a soft reset If your application has serious problems the PCM may reset itself 2 If your PCM is configured to start the application whenever a soft reset occurs a hard reset pressing the restart reset button for ten seconds will be necessary to access the PCM command interpreter The hard reset has no effect on the saved dump information 3 Start TERMF with the PC serial port connected to the PCM port 1 Use the command to put the PCM
9. _fstrrchr _harderr _fstrrev _hardresume A 13 fstrset A 12 _hardretn _fstrspn A 12 _heapadd A 10 _fstrstr _heapchk _fstrtok A 12 heapmin A 10 _fstrupr _heapset _fullpath _heapwalk _getactivepage _imagesize getarcinfo A 4 _imagesize_w Index 2 GFK 0771 Index imagesize wxy _pg_getchardef _lineto _pg_getpalette _lineto_w _pg _getstyleset A 6 _Irotl A 8 _pg_hlabelchart _lrotr _pg_initchart _makepath _pg_resetpalette _matherr A 9 _pg_resetstyleset _memavl _pg_setchardef _memmax A 10 _pg_setpalette _memsize _pg_setstyleset _moveto A 4 _pg_vlabelchart _moveto_w A 4 pie A 4 _ncalloc A 10 _pie_w _nexpand JA 10 pie wxy _nfree A 10 pipe A 11 _nheapchk A 10 polygon A 4 _nheapmin A 10 polygon_w _nheapset polygon way _nheapwalk A 10 Popen _putimage A 5 _nmalloc A 10 _putimage_w A 5 _nmsize A 10 _rectangle A 5 _nrealloc A 10 _rectangle_w nstrdup A 12 rectangle wxy A 5 _outgtext A 4 _registerfonts A 5 _outmem A 4 _remapallpalette _outtext A 4 _remappalette A 5 close A 11 _rotl A 8 _pg_analyzechart _rotr pg analyzechartms A 8 _scrolltextwindow A 5 _pg_analyzepie _searchenv _pg_analyzescatter _selectpalette _pg_analyzescatterms _setactivepage A 5 pe chart _setbkcolor _pg_chartms _setcliprgn A 5 _pg_chartpie _setcolor _pg_chartscatter _setfillmask A 5 pg chartscatter
10. If you answer N to the prompt you must do one of two things before the toolkit will work correctly 1 Copy the new version of AUTOEXEC BAT to the root directory of your computer s boot drive or 2 Change your existing AUTOEXEC BAT file manually as described in the following sections GFK 0771A Chapter 2 Installation 2 3 Adding PCMC to Your MS DOS Path If you choose to modify your AUTOEXEC BAT manually you must add NPCMC to the PATH definition in your AUTOEXEC BAT file For example if your PATH is currently defined as PATH C C DOS C BIN C C600 BINB C C600 BIN or PATH C C DOS C BIN C C700 BINB C C700 BIN You must change it to PATH C C DOS C BIN C PCMC C C600 BINB C C600 BIN or PATHZC NV C NDOS C NBIN C NPCMC C NC700NBINB C NC700NBIN respectively If the PCM C toolkit was not installed on drive C substitute the correct drive letter in the PATH command Adding PCMC LIB to Your LIB Environment Variable If you choose to modify your AUTOEXEC BAT manually youmustalsoadd PCMC LIB to the definition of your LIB environment variable before the Microsoft C library subdirectory This variable tells the Microsoft linker where to find PCM startup code and libraries For example if your LIB variable is currently defined by SET LIB C C600 LIB or SET LIB C C700 LIB Then you must change it to SET LIB C PCMC LIB C C600 LIB or SET LIB C PCMC LIB C C700 LIB respectively If the PCM C toolk
11. When using Megabasic make sure all your programs have been saved to your computer the PC device before attempting to use the command interpreter All PCM commands begin with a single letter which identifies the command The complete command is an ASCII string terminated by a CR character Command arguments are separated from the command character and each other by one or more spaces NOTE In PCM firmware versions prior to 3 0 command letters used in PCM batch files see appendix B were required to be upper case When using PCM commands in batch files which may be used with an earlier firmware version you should use upper case characters exclusively to avoid errors C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Notation Conventions Arguments are shown as symbolic names within angle brackets For example file name represents a string of ASCII characters containing the name of a file pcm filename represents a string of ASCII characters containing the name of a PCM file led use code represents two ASCII characters containing a one byte hexadecimal value etc Optional arguments are shown in square brackets They may be omitted all other arguments are required The notation option indicates that zero or more instances of option may be used A vertical bar separates two or more valid selections where one value must be specified For example 112 i
12. Wait gef DATA READY GEF mod data p mod data far modv 1 1 printf ntask T2 module data address 04x 04x n word amp mod data p 1 word amp mod data p printf module data 04x 04x 04x task num d string s n word far mod data p word far mod data p 1 word far mod data p 2 mod data p gt task_ num mod data p 5s Set gef EXIT GEF Here is the output which TERMF displays when the two tasks are run from the PCM batch file MODULE BAT The shared module is created here gt module M MODULE1 6 R T2 EXE IOE MMODULE1 B R T1 EXE IOF task T1 module found module address 0296 0000 module data address 0296 0020 module data 000f 03a8 OfdO task T2 module data address 0296 0020 module data task num 15 string Hello from T1 running as task 15 Chapter 7 Multitasking Creating Memory Modules From Applications Memory modules may also be created by PCM applications as shown in this code fragment word task id Get task id word handle Open dev RAM MODULE2 WRITE MODE WAIT task id Seek dev handle SIZE WAIT task id Close dev handle WAIT task id where SIZE is the desired memory module size in bytes However this method is not equivalent to the PCM M command 1 The Open dev callcreates only a module header that is a structure of type mod hdr as defined in VTOS H The Seek dev call creates ano
13. Why Use Multitasking ssseeseeeeeee e lask Priorities c sete ears Bein vene tte els MIOS Tasks riot e ee red ted D e E Hos Task Startup ehe eee ee LERRA ma Rege Task Scheduling x eere eee RR ec Prionity Based Tasks eege Ke e UE RE ner be etd Time lice Tasks Ritiri cto de ot E oe es Models Supported By the PCM Small and Medium Model Differences Between VTOS and MS DOS Advantages and Restrictions Making the Most of Small and Medium Models STKMOD Program e ei eked bee keen ee PCMDUMP Program oiran ed Task Register and Stack Data 6 6 60 Using Microsoft Map Files 0 60666 BLD_PROM Program Customizing the PROM Copyright String 7 1 7 1 7 1 7 2 7 2 7 3 7 3 7 4 7 6 7 6 7 7 7 8 7 12 7 14 7 17 7 21 7 21 7 21 8 1 8 1 8 2 8 4 8 4 9 1 9 1 9 1 9 2 9 2 9 2 9 3 9 7 10 1 10 1 10 2 11 1 11 1 11 3 11 8 11 10 11 11 11 13 GFK 0255 Contents Chapter 13 GE Fanuc Support Services and Consultation 11 1 AppendixA Microsoft Runtime Library Support A 1 AppendixB PCM Commands eu eg REN EEN EE neta SEAN wen B 1 Accessing the Command Interpreter B 1 Interactive Mode sssesseeeeeee tne e ERA B 2 Notation Conventions serso aakh ts cee cece e B 3 Commands ia cese ber pr EO E eb eae eee a B 3 Execute a Batch File B 4 B Configute LEDS il du
14. modalias if mod p modtype amp LAST MOD data size mod p gt modalias break word far amp mod p 1 mod p modalias printf ntotal data size 1d bytes n data size Note that the device name RAM is required in the string passed to Open dev but may not be included in the string passed to Get mod GFK 0771A Chapter 7 Multitasking 7 13 Running MODTEST produces this output r modtest exe module name MYMODULE module 0 module 1c09 module MYMODUL 001 module 1024 module 1c4c module name MYMODUL 002 module size 1024 module alias 0038 total data size 1992 bytes gt MYMODULE contains three distinct memory modules but only MYMODUL 001 and MYMODUL 002 contain data As before the data address within these modules is mod pt 1 Note When the Open dev Seek dev method is used to create a memory module just one Seek dev call should be made The position passed to Seek dev should be as large as the maximum data size the module will ever need AsynchronousTraps 7 14 Chapter 6 also describes the use of ASTs for handling asynchronous events ASTs can be used for communication between tasks as well Here is an example program in which two tasks exchange signals and data with ASTs There are three files AST H AST1 C and AST2 C In order to send an AST to the other task each one must have two items of information the target task number and the address of an AST fun
15. A 10 freopen A 7 frexp A 8 frexpl A 9 fscanf fseek A 7 fsetpos A 7 fstat A 3 ftell A 6 ftime fwrite A 7 G G Get hardware ID TERMF command gcvt Get best buff Get board id Get buff get config info get config info nowait get cpu type rev get cpu type rev nowait Get date Get dp buff bel Get mem lim get memtype sizes get memtype sizes nowait Get mod 57 9 710 E Index 7 Index Index 8 Get_next_block get one rackfaults get one rackfaults nowait Get pcm rev Kl get prgm info get prgm info nowait get rack slot faults get rack slot faults nowait Get task id 5 1 52 Get time gete 7 20 A 7 getch A 7 getchar getche A 7 getewd A 3 getenv A 11 getpid A 11 gets A 7 getw A 7 Global event flags 7 7 gmtime A 14 H H Get PCM firmware revision number TERMF command halloc HARDEXEC BAT C 1 HELLO C hfree A 10 Holding the reset restart pushbutton down for 10 seconds Holding the reset restart pushbutton down for less than 5 seconds hypot hypotl A 9 I Initialize device TERMF command Ba I O AST_NOTIFY Asynchronous 6 2 EVENT NOTIFY 6 3 Notification of completion WAIT mode 6 4 In circuit emulators 7 21 INCLUDE environment variable Init task b 1 inp 7 inpw A 7 Install_dev Install_isr Installation Microsoft C 2 2 PCM C toolkit int86 int86x int
16. August 1996 GFK 0771A First AST Block for Task 1f this field is non zero it contains the segment part of the far address of the first item on the linked list of AST blocks which are ready for this task to process AST blocks always begin at offset zero in the specified segment If there are no AST blocks for this task this field is zero Last AST Block for Task If this field is non zero it contains the segment part of the far address of the last item on the linked list of AST blocks which are ready for this task to process AST blocks always begin at offset zero in the specified segment If there are no AST blocks for this task this field is zero Suspend Count This field contains the Suspend task count for this task If the task has not been suspended this field is zero Task s Initial Data Segment This field contains the data segment DS register value assigned to the task when it was started Task s Initial Stack Segment This field contains the stack segment SS register value assigned to the task when it was started Safe Point Address When a PCM device driver is executing this field contains the stack pointer SP register value on entry It is used to locate the stack frame where return values will be placed Semaphore Count for Setting Safe Point This field controls access to the Safe point address field when one PCM device driver calls another Semaphore Count for UO Operations Unused reserved Segment
17. PCMEXEC BAT Copyright GEFAN UC 1992 PCM C V 1 00 92FW26B1 The first 48 decimal bytes contain the copyright string Note that there are no carriage return CR ASCII code 13 decimal or line feed LF ASCII code 10 decimal characters They are optional The next 48 decimal characters starting at address C000 0030 contain the module header and file contents of PCMEXEC BAT The final 96 bytes starting at C000 0060 contain the module header executable file header and a part of the startup module data from HELLO EXE The PCM toolkit release which produced HELLO EXE is identified by its GE Fanuc version number 1 00 C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Chapter 12 GFK 0771A GE Fanuc Support Services and Consultation With the purchase of the C Programmer s Toolkit IC641SWP710 GE Fanuc provides 26 hours of consultation during the first 12 months This service is available in the form of telephone 800 828 5747 and in person consultation sessions in Charlottesville Consultation time is accrued in increments of 1 4 hour with the minimum time being 1 4 hour Appendix GFK 0771A A Microsoft Runtime Library Support The tables in this appendix list all the functions provided in Microsoft C 6 0 and Microsoft C C 7 0 runtime libraries For each function a table entry specifies its availability for PCM C applications Generally availability falls into one of thes
18. SYSMEMNWH NOWAIT versions of SYSMEM H services TIME H PLC API services for reading and setting PLC time of dayclock TIMENWH NOWAIT versions of time H services UTILS H PLC API services for finding PLC CPU module type memory sizes etc UTILSNWH NOWAIT versions of UTILS H services VME H New in this version VTOS H Data types and function prototypes for VTOS services Appendix D PCM C Directories and Files D 3 D Directory File Purpose PCMC LIB APIL LIB APIM LIB APIS LIB PLCAPIlibraries CHKSTKL OBJ CHKSTKM OBJ CHKSTKS OBJ CRTOLG OBJ CRTOMD OBJ CRTOSM OBJ IFCALLMD OBJ IFCALLRG OBJ IFCALLSM OBJ Object files linked to PCM EXE files PCML LIB PCMM LIB PCMS LIB VTOSlibraries D 4 C Programmer s Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Index Sym bo Is _dos_close dos creat Execute a batch file TERMF com dos creatnew d _dos_findfirst A 13 Per _dos_findnext pres _dos_freemem _atold A 3 _dos_getdate pure dos getdiskfree Ne dos getdrive bexpand A 10 dos getfileattr A 13 pus dos getftime A 13 E i _dos_gettime A 13 bfreeseg A 10 dos_getvect _bheapadd A 10 7 di _bheapchk A 10 R indes bheapmin A 10 i MA Dees bheapseg A 10 dos setblock _bheapset A 10 dos setdate A 13 bheapwalk A 10 dos setdrive bios disk dos setfileattr bios equiplist A 13 dos setftim
19. Utility programs BLD_PROM SEN PCMDUMPEXE Zi Correlating PCM and MAP file ad dresses Interpreting cul put STKMOD EXE 3 3 ZE Error messages Options utime A14 V V Verify a file TERMF command va_arg A 14 va_end va_start vfprint A 7 GFK 0771 GFK 0771 VME function blocks VMEbus Series 90 70 4 1 Address modifier Ve AN Using in PCM programs 4 14 4 22 vprint A 7 vsprint A 7 VTOS 6 1 6 2 VTOS H 3 VTOS PCM a system 4 1 6 1 File system 4 2 Global data 5 13 W W Wait TERMF command B 17 wait A 11 Wait_ast SA 6 16 wait et 52 3 63 E ES Index Wait_gef 5 3 4 Wait task 5 1 5 2 Wait time 5 5 Warning Microsoft C compiler Where am i write A 7 Write_dev ka 7 5 p e write localdata write localdata nowait write prgmdata write prgmdata nowait 5 15 write sysmem write sysmem nowait X X eXterminate file TERMF command B 18 Y Y Set upper memory limit TERMF com mand Index 15
20. VME Write Function The VMEWRT function can be used to write data from a Series 90 70 CPU to the VME dual port RAM of the PCM Locate the function block at a place in the program where the output data is ready to send The format of the VMEWRT function block is data to be written IN address enable function OK logic modifier module address Parameter Description Enable Power flow input that when TRUE enables the execution of the function Type Function type either BYTE or WORD to select the corresponding type of VME bus access to be performed WORD accesses transfer 16 bits of data on each VMEbus cycle while BYTE accesses transfer just 8 data bits per buscycle LEN Aninternal parameter that depending on the function type specifies the number of bytes or words to be transferred IN Specifies the first PLC user reference location where the data to be written to the PCM is stored This parameter may be a constant in which case the constant value is written to all VME addresses covered by the function s length AddressModifier A hexadecimal word value that specifies both the rack where the target PCM is installed and the VMEbus access mode to be performed Module Address A double word specifying the hexadecimal address where the first word or byte is read from the VME bus It may be a constant or the reference address of the first least significant word o
21. memory nowait Event flag Global Local Gi 6 8 7 7 7 EVENT NOTIFY b 2 6 3 6 6 Events Asynchronous 6 1 1 0 PCM task notification Timer WAIT mode Examples execl execle execlp A 11 execlpe Execution threads 2 execv execve execvp execvpe exit A 11 exp A 8 expand A 10 expl A 9 F F Show Free memory TERMF command fabs A 8 fabsl A 9 fclose A 6 fcloseall A 6 fcvt A 3 fdopen A 7 feof A 6 ferror fflush A 6 fgetc A 6 fgetchar A G fgetpos A 6 fgets A 6 fieeetomsbin A 8 File transfer PC to PCM filelength A 3 fileno A d Files Batch AST2 C 7 14 CC BAT B 2 CLINK BAT B HARDEXEC BAT Lat eee SEM BAT 19 SLICE BAT 7 4 SWAPBAT 7 8 C source 3 1 C 5 GFK 0771 GFK 0771 T1 C 7 10 T2 C 7 10 TASK_ASTC 9 3 TASK1 C TASK2 C 9 3 p 4 Example ASTH MODULE H 7 10 7 11 SEM H 7 17 Header API PLC APITYPES H CHKSUM H CHKSUMNWH MIXTYPES H 5 21 MXREAD H MXREADNWH Microsoft replacement EXTH MEMORYH 5 21 STDARG H 5 21 STDIO H 5 21 STDLIB H STRING H VTOS CPU DATA H 5 12 CTOS H 5 20 PCMCSARGH BS D VTOS H 5 11 floor floor A 9 flushall A 6 fmod A 8 Index fmodl A 9 fmsbintoieee A 8 fopen 9 3 A 6 FP OFE FP SEG fprintf B 3 A6 fputc A 6 fputchar fputs 7 20 A 8 fread A 6 free
22. the balance of the parameter list is unspecified as indicated by the ellipsis The VTOS library code for these functions assumes that all data pointers are far in all memory models When using any of these functions in the small or medium model to print strings the s format specifier the character pointer parameters must be coerced to type char far There are two ways it can be done A pointer identifier which was declared as type char far may be used Alternatively a string literal may be type cast explicitly to include vtos h char far For example include lt stdio h gt char far s Hello printf s s n s char far world See Small and Medium Model Differences Between VTOS and MS DOS in chapter 8 Memory Models Failure to coerce printf data pointers to far in small or medium model will result in unexpected operation possibly including PCM lockup Header Files The PCM C toolkit provides these header files Table 5 32 VTOS Header Files PCM Header File Description CTOS H PCMCSARG H PCMLIB H These PCM header files are not used by release 1 00 or later of the PCM C toolkit They are furnished to provide backward compatibility with previous unreleased versions of the toolkit In this release these filessimply include the files STDARG H and VTOS H respectively VTOS H Provides type definitions and function prototypes for all VTOS operating system
23. timedate Returns the current time and date from the PLC time of day clock read timedate nowait inasingle operation set date Sets the date in the PLC time of dayclock set date nowait set time Sets the time in the PLC time of dayclock set time nowait set timedate Sets the time and date in both the PLC and PCM time of day clocks set timedate nowait inasingle operation PLC API Types These data types are defined in APITYPES H Table 5 29 PLC API Types Type Name Purpose BOOLEAN Unsignedchar type which takes the values TRUE and FALSE only BYTE Unsigned char type which takes the values 0 through 255 decimal CONFIG INFO STRUC Astructuretypereturned by get config info and get config info nowait CPU TYPE STRUC Astructuretypereturned by get cpu type revand get cpu type rev nowait DATE LONG STRUC Astructuretypereturned by read date and read date nowait and passed to set date and set date nowait DATE STRUC Astructure type component of IO FAULT TBL STRUC and PLC FAULT TBL STRUC FAULT HDR STRUC Astructure type component of IO FAULT TBLSTRUC and PLC FAULT TBL STRUC IO FAULTSTRUC Astructure type component of IO FAULT TBL STRUC GFK 0771A Chapter 5 PCM Libraries and Header Files 5 17 Type Name Purpose IO FAULT TBL STRUC Astructuretypereturned by read io fault tbl and read io fault tbl nowait MEM SIZES STRUC Astructure type returned by get memtype siz
24. 2 Notification 6 2 Notify_task O O Get LED configuration TERMF com mand B 12 OIT_DRVR C onexit open A 7 A 7 Open dev l3 I s 5 7 6 3 BAB N outpw A 7 P P Request status data TERMF command Ibis PATH iC adding Bl variable PCMC re PCMEXEC BAT ka spo t pere Personal computer PC GFK 0771 GFK 0771 PLC P 1 Ports serial PC L Task contention 7 6 Post ast 63 pow powl A 9 Pre empted time slice tasks pn a FF E Use in small me medium memory models Process_env e Programming g COMMREO function blocks 4 putc A 7 putch A 7 putchar putenv A 11 puts A 7 putw Q Q Set protection level TERMF com mand B 14 qsort Quick C 2 2 R R Run TERMF command B 14 raise A 11 rand A 8 read A 7 read date read date nowait b read io fault tbl read io fault tbl nowait Index read localdata read localdata nowait read mixed memory read mixed memory nowait read plc fault tbl read plc fault tbl nowait read prgmdata read prgmdata nowait read sysmem read sysmen nowait read time read time nowait read timedate read timedate nowait 5 17 Real time Performance realloc A 10 remove A 3 rename Reserve_dp_buff 5 6 5 7 Reset PCM Hard defined Soft er Reset ef f Reset_gef 5 2 Resume task 6 1 Return buff Return dp buff b 6 5
25. 7 rewind A 7 rmdir rmtmp A 7 ROM read only EE BLD PROM utility 10 2 Creating applications for 10 2 Memory models Te D sri PCM applications in 10 1 Running PCM programs ES S S Save TERMF command Biel scanf A 6 Index 11 Index Index 12 Scheduling task 7 2 Seek dev 5 7 5 8 7 12 segread A 13 SEM BAT 7 19 SEM H 7 17 SEM1 C 7 18 SEM2 C 7 19 Semaphore Deadlock Semaphores 47 Services PLC API set date set date nowait Set dbd ctl Set ef Set gef Set led Set std device 5 1 set_time set_time_nowait set_timedate set_timedate_nowait Set_vme_ctl setbuf A 7 setimp A 11 setlocale setmode A 3 setvbuf A 7 setwritemode A 5 Shared memory modules 7 8 signal A 11 sin A 8 sinh A 8 sinhl A 9 sinl A 9 SLICE BAT SLICE C 7 3 sopen A 7 spawn A 11 spawnle A 11 spawnlp A 11 spawnlpe spawnv spawnve A 11 spawnvp A 11 spawnvpe A 11 Special dev 57 kd Specifying the stack size DA sprintf 7 19 4 7 sqrt A 8 sqrtl A 9 srand A 8 sscan A 7 Stack PCM PAE Specifying size 8 3 STKMOD EXE utility 3 stackavail Standard C libraries A 1 Function categories Buffer manipulation A 2 Character classification and conver sion Console and port I O Data conversion Directory control File handling A 3 Internationalization A 8 a d graphi
26. EXAMPLES COPRTXT contains a sample copyright string which performs all three of these functions Copr 1992 GE Fanuc Automation N A Inc PCM711 The six initial characters Copr are required to enable automatic checksum verification of the PROM when the PCM is reset We recommend that every PROM image begin with these exact characters including the dot and space characters The characters PCM711 enable the optional check that the PROM image was intended for the PCM711 hardware The location of these characters is unimportant This table shows the three valid hardware check strings Table 11 4 Valid Hardware Check Strings Hardware Check String PCM Module Type s PCM711 PCM711 with any or no memory expansionboard PCM300 PCM300 module only PCM301 PCM301 and PCM311 module Note that the PCM301 and PCM311 do not require separate PROMs The copyright information in the string can use any ASCII printing and non printing characters except NUL ASCII code zero and may have any length BLD PROM EXE reads the entire file appends an ASCII NUL character to it and pads the resulting string to the next larger integer multiple of 16 decimal bytes GFK 0771A Chapter 11 Utilities 11 13 11 14 Here is a hexadecimal dump of the first 192 bytes in the PROM image file produced by the BLD_PROM session described in the preceding paragraphs Copr 1992 GE Fa nuc Automation N A Inc PCM711
27. Function Name Purpose Iset ef Sets one or more local event flags from an interrupt or communication timerserviceroutine Iset gef Sets one or more global event flags from an interrupt or communication timerserviceroutine Reset ef Resets one or more local event flags Reset gef Resets one or more global event flags Set ef Sets one or more local event flags Set gef Sets one or more global event flags Test ef Tests oneor more local event flags Test gef Tests one or more global event flags Wait ef Waits for one or more local event flags to be set Wait gef Waits for one or more global event flags to be set Each PCM task has 16 local event flags which it can use to determine when external events occur There are also 16 global event flags shared by all PCM tasks A task can test its own local event flags to determine whether one or more of them is set using Test ef A task can also clear one or more of its own local event flags using Reset ef Any task can test or clear one or more global event flags by using Test gef or Reset gef respectively Any task may set the global event flags as well as local event flags for any task Global event flags should be set from communication timer timeout functions see Start com timer inthe PCM C Function Library Reference Manual GFK 0772 or device drivers by calling Iset gef Allother functions can set global event flags by calling Set gef Similarly local event flags should be set from c
28. Purpose read_prgmdata Reads up to 2048 bytes of Series 90 70 P data read_prgmdata_nowait read_localdata Reads up to 2048 bytes of Series 90 70 L data read_localdata_nowait 5 14 C Programmer s Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A GFK 0771A Writing PLC Data References The WAIT mode functions are declared in SYSMEM H and the NOWAIT versions are declared in SYSMEMNWH Table 5 22 Writing PLC Data References Function Name Purpose write sysmem Writes up to 2048 bytes of a single PLC reference type write sysmem nowait These WAIT mode functions are declared in PRGMEM H and the NOWAIT versions are declared in PRGMEMNWH Table 5 23 Writing Series 90 70 PLC Data References Function Name Purpose write prgmdata Writes up to 2048 bytes of Series 90 70 P data write prgmdata nowait write localdata Writes up to 2048 bytes of Series 90 70 L data write localdata nowait Controlling PLC Operation The WAIT mode functions are declared in CNTRL H and the NOWAIT versions are declared in CNTRLNWH Table 5 24 Controlling PLC Operation Function Name Purpose start plc Sets the PLC state to RUN mode Series 90 30 outputs are always start plc nowait enabled but the Series 90 70 output scan state depends on the positionof the CPU RUN STOP switch start plc noio Sets the PLC state to RUN mode with outputs disabled start plc no
29. STATE ast CMD READ HNDL Start of WAIT FOR EVENT STATE for Wait ast GFK 0771A Chapter 6 PCM Real Time Programming 6 13 To make this somewhat lengthy example as brief and clear as possible a few details have been omitted The function process command is assumed to move the new register data to the New regs array but the details of process command are not shown The implementation of display dead plc alarm isomitted PLC register data is assumed to be formatted for OIT display by calling ormat display data Finally code to check error conditions has been omitted from all the AST functions except COMREQ ACK COMPLETE STATE ast butthe details of recover from error are also omitted Note that the structure of this example is very simple Each of the event triggered states has only one successor state WAIT FOR EVENT STATE At any given time the possible successor states of WAIT FOR EVENT STATE are determined by the events which may occur based on the program s recent history There is no program logic at all to select successor states Differences between ASTs and MS DOS ISRs 6 14 MS DOS interrupt service routines ISRs are different from VTOS asynchronous traps in many ways Making MS DOS service requests from ISRs often causes errors when the interrupted code is MS DOS itself In addition the time which can be spent executing ISR code is usually limited Neither of these considerations applies to V
30. Series 90 70 PCMs Note that the application must periodically test a status flag to determine when each PLC API service completes Event flag and AST notification are not supported for PLC API services PLC API Services By Category This section summarizes PLC API services by grouping them in categories of related services For full details on all PLC API services refer to the PCM C Function Library Reference Manual GFK 0772 Before any of the PLC API services can be used an API session must be opened with the PLC The interface must be initialized by calling api_initialize acommunication link must be specified by calling configure comm link and a channel to the PLC CPU must be opened by calling establish comm session See api initialize in the PCM C Function Library Reference Manual GFK 0772 for details When the session has been completed terminate comm session is called to close the session and free its data Table 5 17 Open and Close a PLC API Session Function Name Purpose api initialize Initializes PLC API data for a new session configure comm link Specifies the communication link to the PLC establish comm session Specifies a channel for the CPU device and returns a session ID terminate comm session EndsaPLC API session GFK 0771A Chapter 5 PCM Libraries and Header Files 5 13 PLC Hardware Type Configuration and Status Information The WAIT mode functions are declared in UTILS H a
31. TERMF serial communication settings See Using TERMSET to Configure TERMF or PCOP in chapter 2 section 3 of the Series 90 Programmable Coprocessor Module and Support Software User s Manual GFK 0255D or later Chapter 3 Creating and Running PCM C Programs 3 5 3 6 When you have connected your PC s serial port to the PCM configured TERME and run it from the MS DOS prompt reset your PCM by pressing the Restart Reset button and holding it for more than five 5 seconds a hard reset If you press the Enter key on your PC you should see the gt prompt from the PCM command interpreter Pressing the Enter key repeatedly should add another gt prompt on the same line each time you press it The command interpreter defaults to its non interactive mode which is used by PCOP However loading and running C applications is much easier in interactive mode Type two exclamation points and press the Enter key to switch to interactive mode You should see this message INTERACTIVE MODE ENTERED type for a list of commands Once again the gt character is the PCM prompt If you press the Enter key at this point you should see another prompt separated from the first one by a blank line If you have trouble communicating with your PCM or getting into interactive mode refer to appendix B PCM Commands Appendix B also includes a complete reference for PCM commands When TERMF is communicating with the PCM com
32. and lists some types of applications which have been successfully implemented in C on the PCM Chapter 2 Installation Chapter 2 lists the items you will need to develop PCM applications in C explains how to install the PCM C toolkit and describes how Microsoft C version 6 00 must be installed Chapter 3 Creating and Running PCM C Programs Chapter 3 describes the creation and installation of a simple C program for the PCM Chapter 4 Using PCM Resources Chapter 4 describes how to use the hardware resources of the PCM the facilities of its VTOS operating system and services provided by the PLC CPU from C applications Chapter 5 PCM Libraries and Header Files Chapter 5 lists all the services provides by the PCM C libraries and the C header files which describe them to the C compiler Chapter 6 PCM Real Time Programming Chapter 6 describes some important issues in real time communication and control applications and how to address them in PCM applications Chapter 7 Multitasking Chapter 7 describes how to use multiple PCM tasks to design a real time application and how to run two or more independent applications in the same PCM Chapter 8 Memory Models Chapter 8 describes the memory models which the PCM supports Chapter 9 Example Programs Chapter 9 describes the sample programs provided with the PCM C toolkit Chapter 10 Applications In ROM Chapter 10 describes how to install PCM applications in PCM Read Only Memo
33. at level 2 and higher the PCM will be unable to read or write PLC memory until the PCM sends a valid pass word Passwords are case sensitive and valid passwords may have upper case letters numbers and underbar _ characters only If an empty string is specified for PLC access password a password consisting of eight NUL characters will be sent to the PLC CPU There is no default disable clock sync N disables backplane messages the PCM normally sends once per second to synchronize its internal time of day with the PLC CPU Any character other than N or n enables clock synchronization Available in PCM firmware version 4 03 or later Some applications may be sensitive to the impact that clock synchronization mes sages have on PLC sweep time or backplane message rates If these issues are more important than time of day accuracy use this option Default synchro nizationenabled Examples I COMI 9600 S I COM2 38400 0 8 1 S 485 2 10 1024 GFK 0771A Appendix B PCM Commands B 9 The first example sets the port 1 data rate to 9 600 baud and selects software flow control Selections for parity data bits and stop bits are the omitted items between the four consecutive commas they are unchanged The second example sets port 2 for RS 485 two wire half duplex operation at 38 400 baud odd parity 8 data bits and one stop bit using software flow control a ten millisecond time delay and a 1024 character type
34. calloc A 10 Cancel_com_timer cancel_mixed_memory cancel_mixed_memory_nowait Cancel_timer CC BAT ceil A 8 ceill A 9 cgets A 7 chdir chg_priv_level chg_priv_level_nowait chk_genius_bus chk_genius_bus_nowait chk_genius_device chk_genius_device_nowait chmod A 3 chsize A 3 clearerr CLINK BAT clock A 14 close A 7 Close_dev 5 7 clr_io_fault_tbl clr io fault tbl nowait clr plc fault tbl cr plc fault tbl nowait COMMREQ r3 64 65 bd 7 Command block Data block 4 6 Programming Index Receiving in PCM programs Responding to Timing Compiling 3 2 Configuration PCM in PLC rack slot configure comm link COS cosh cosh A 9 cosl A 9 cprintf cputs creat A 7 Creating memory modules from applica tions 7 12 Critical sections 5 10 cscanf ctime cwait D D file Directory TERMF command B Data Global VTOS Deadlocks HS Dealloc com timer DEBUG macro 9 3 Debugging 3 7 21 In circuit emulators Multiple tasks Define led Devctl dev 5 7 5 8 dieeetomsbin A 8 difftime A 14 Disable_asts 5 3 6 14 div dmsbintoieee A 8 dosexterr A 13 dup A 7 dup2 A 7 Index 5 Index Index 6 E ecvt Editor text 2 1 Elapse 5 4 Enable asts Environment variables INCLUDE p 5 LIB p 4 PATH p 4 eof A7 establish comm session establish mixed memory establish mixed
35. data if Cmrq msg header msg type amp 0x40 there is no data buffer cmrq data size 12 memcpy Plc regs Cmrq msg data short c data size else there is a data buffer cmrq data size Cmrq msg data long c data size Read dev Cmrq hndl Plc regs cmrq data size WAIT Task id Send a COMREQ acknowledgement to the PLC CPU Write_dev Cmrq_ack_hndl amp status 1 AST_NOTIFY Task_id COMREQ ACK COMPLETE STATE ast CMRQ ACK HNDL Cmrq ack timeout Start timer RELATIVE TIMEOUT AST NOTIFY MODE MS COUNT MODE 0 ACK TIMEOUT ABORT COMREQ ACK STATE ast CMRQ TIMEOUT HNDL Display the data display size format display data Display data Plc regs cmrq data size sizeof word Write dev Oit hndl Display data display size AST NOTIFY Task id DISPLAY ACK COMPLETE STATE ast DISPLAY ACK HNDL Display ack timeout Start timer RELATIVE TIMEOUT AST NOTIFY MODE MS COUNT MODE 0 DISPLAY TIMEOUT ABORT DISPLAY DATA STATE ast DISPLAY TIMEOUT HNDL 6 12 C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A void far REGS DATA COMPLETE STATE ast ast blk far ast ptr The Write dev for new PLC register data completed Cancel timer Regs ack timeout void far ABORT REGISTER DATA STATE ast ast blk far ast ptr The Write dev for new PLC register data timed out Abort dev New regs hndl ABORT ALL 0 d
36. disabled immediately before transmitting and remains off until delay value expires after the last character is sent When lt physical_interface gt 422 or 485 the RS 485 line drivers for RTS and transmitted data outputs on the specified port are turned on immediately before transmitting and remain on until lt delay_value gt expires after the last character is sent At all other times these drivers are in theirhigh impedancestate tri stated delay value the time in milliseconds between the end of the last outgoing character and the time RTS is turned off if applicable RS 485 line drivers are tri stated Gf applicable the receiver is enabled in half duplex mode if applicable and WAIT mode output statements complete execution Default 0 Available in PCM firmware version 3 00 or later typeahead size the typeahead buffer size in characters for the port The port can ac cept up to one less than this number of characters without overflow before an application reads the port When overflow occurs any additional characters will be lost Any size in the range 64 32750 bytes may be specified but the maximum may be limited by available system memory Default 320 Available in PCM firmware version 3 00 or later PLC access password disable clock sync where PLC access password the PLC access password for privilege level 2 or higher If passwords are enabled in the PLC CPU and the PLC has passwords
37. entered with no argument the operating system uses all the RAM on the PCM and the Ger mem lim utility will indicate that no limit has been set When a limitis set it does not actually take effect until the PCM is reset GFK 0771A Appendix B PCM Commands B 19 Appendix C Overview Batch Files The PCM supports batch files similar to those used with MS DOS You can specify a batch file to be executed interactively In addition you can create batch files which are executed automatically when power is applied or a soft reset occurs or when a hard reset occurs These files must be named PCMEXEC BAT and HARDEXEC BAT respectively PCM batch files may consist of any number of commands Each command must end with the ASCII CR carriage return character CR may be followed optionally with the LF line feed or newline character All the commands described in appendix B PCM Commands may be used in batch files Unlike MS DOS there are no commands such as IE ECHO or GOTO which work only in batch files Caution In PCM firmware versions prior to 3 0 command letters used in PCM batch files were required to be upper case If you are creating a batch file which may be used with an earlier PCM version you should use upper case characters exclusively to avoid errors Creating Batch Files GFK 0771A You can create batch files with any text editor which produces standard ASCII text files Suppose you want to create a simple batch fil
38. extract the status address from the message and write a status value to it include directives and data declarations from the previous example are not repeated here special dev 8 type status addr word status hndl word commreq status 1 open a channel for writing to the PLC status location the data type and offset are not important status hndl Open dev CPU R1 WRITE MODE WAIT task no read a COMMREQ message as in example above not repeated here test the COMMREQ message type if msg header msg type amp 0x40 COMMREQ data is in the message get the status type and offset status addr type msg data short c status type status addr offset msg data short c status offset else separate COMMREQ data buffer get the status type and offset status addr type msg data long c status type status addr offset msg data long c status offset change the PLC data location of the status_handle channel Special_dev status_handle 8 amp status_addr 0 WAIT task_no write a status value to the new location Write dev status handle amp commreq status 2 WAIT task no The VTOS Special dev function permits changing the PLC reference data type and offset for a channel opened on the CPU device This capability allows a channel to be opened to a dummy reference address The channel is then switched to the actual status address for each COMMREO C Prog
39. fault tables Dolo QoS ser t m Check Series 90 70 PLCs for faulted racks modules Genius busses and Genius devices GFK 0771A Chapter 4 Using PCM Resources 4 3 7 CleartheI O and PLC fault tables 8 Read collections of mixed PLC data references 9 Change the PLC access privilege level 10 Read and write PLC data references 11 Read and write Series 90 70 Program P and Local L data 12 Read and set the PLC time of day clock and 13 Start and stop PLC program execution For more information on PLC API services see chapter 5 PCM Libraries and Header Files Communications Request COMMREQ Messages From PLC Programs PLC programs can send messages to PCM programs with COMMREO function blocks Each COMMREO message can include up to 128 words 256 bytes of PLC data COMMREO data must be a contiguous block from a single word oriented PLC reference type R IA or AQ in both Series 90 70 and Series 90 30 COMMREQs plus P or L in Series 90 70 COMMREQs only Discrete PLC data types may not be transferred directly as COMMREO data However they can be copied to a word oriented type and then transferred by a COMMREQ COMMREO function blocks may be programmed for either WAIT mode or NOWAIT mode In WAIT mode the PLC CPU sends aCOMMREQ message and waits for a reply from the target PCM before ladder program execution continues In NOWAIT mode ladder execution continues immediately after the COMMREQ message is sent N
40. field contains the VME block number used for VMEbus access by the task The value is useful only in a Series 90 70 PCM See Set vme ctl inthe PCM C Function Library Reference Manual GFK 0772 for more information on accessing VMEbus memory VME address modifier code This field contains the VME address modifier AM code This value is also useful only in a Series 90 70 PCM Note that the task control block data for tasks which were not active when the reset occurred such as task 000D hexadecimal contains only the Task ID and Current state fields Task Register and Stack Data 11 8 A portion of the stack for the PCM real time clock RTC task and the two application tasks are shown below REGISTERS and STACK of task 00 AX 0007 BX 0032 CxX 0700 DxX 0104 SP 02FC BP 02FC SI 0018 DI 0000 DS 0000 ES 0000 SS 02FD CS E55E IP 5F0A NV UP EI PL ZR NA PE NC 5A3F E55E 0002 030C 02FD 0002 0314 O2FD 0B38 FD8E OB40 FD8E 0B20 FD8E 0000 041A 0B4E FD8E BBBB REGISTERS assuming a pushbutton reset and STACK of task OE AX 000E BX 0000 Cx 03DC DX 073E SP 03D4 BP 03E2 SI 0BB4 DI 468B DS 073E ES 0000 SS 06FD CS 0620 IP 01AE NV UP EI NG NZ AC PE CY 0109 0001 03F4 O6FD 0001 O3F8 O6FD 03E4 5A3F E55E 0001 03F4 O6FD 0001 O3F8 O6FD 0038 O6F7 0020 O6F7 0000 061D BBBB 076C 0618 076C O6FC 002E FFOE 1111 B5E1 DFS5E 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 REGISTERS and STACK of task OF AX 000F BX 0000 CX 03DC DX 06C8 SP 0
41. file are missing or if errors are encountered while initializing the new configuration the PCM is placed in its factory default configuration The configuration file argument must be either FDEF factory or UCDF user UDCF configuration data is stored only by PCOP Any other file name results in one of these error messages Module not found lt file_name gt Illegal module type lt file_name gt V Verify a File W Wait Format V lt file_name gt The V command causes the PCM to verify the checksum of the specified file on the PCM RAM disk The file must previously have been protected by using the PCM Q Set protection level command If the checksum calculated for the file matches the checksum stored in it the PCM returns just the prompt If the checksums do not match the PCM prints this error message Invalid file lt file_name gt followed by the gt prompt The Q command is used provide checksum protection for files Format W time The WAIT command causes PCM command interpreter to wait for the specified time in seconds before initiating or responding to any activity on the serial ports or REM remote device After the specified time the PCM prints the prompt This command is provided to allow tasks running in background mode to access the PC fileserver Since the PCM command interpreter and file server usually share the same serial port the command interpreter has to be kept from
42. interpreter will be connected to serial port 1 whenever the PCM is reset by holding the restart button for more than five seconds a hard reset Pressing the Enter key displays a prompt from the interpreter when it is active Pressing Enter repeatedly adds another prompt on the same line each time you press it Depending on the Logicmaster 90 configuration for the PCM the MegaBasic interpreter may start at power up or a reset MegaBasic prints a startup banner message by default to port 1 whenever it starts When you see the startup message anda Ready prompt you can type bye and press the Enter key to exit from MegaBasic to the command interpreter If you see the startup message but no Ready prompt MegaBasic is running a program You can usually stop the program by pressing Ctrl C hold the Ctrl key down while typing C If you cannot access the command interpreter after trying the procedures described above use the Logicmaster 90 configuration software to check the PCM configuration If a configuration has been stored to the PLC load it to Logicmaster software and then check the PCM configuration mode to be sure it is either BASIC BAS CCM PCM CFG or PROG PRI If the PCM mode is not one of these change it and store the new configuration to the PLC If there is no PLC configuration create one with the PCM configured to PCM CFG mode and then store it to the PLC As a last resort try powering off the PLC disconnecting the
43. itself must initialize any data which it modifies Code is not PROMable C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Making the Most of Small and Medium Models In small model the 64K byte code size restriction can often be circumvented by partitioning an application into two or more tasks See chapter 7 Multitasking for details In small and medium models the 64 Kbyte limitation on static data can almost always be avoided by allocating free PCM memory for large data structures and arrays These structures and arrays are then accessed through far pointer variables Microsoft C 6 0 actually generates more code bytes to access a structure member or array element in a large model far datasegmentthan througha far pointer in medium model GFK 0771A Chapter 8 Memory Models 8 5 Chapter Example Programs 9 This chapter describes an example PCM application that demonstrates how to use PCM and VTOS capabilities in actual applications The example consists of three PCM C programs and a PLC ladder logic program The PCM programs execute as separate PCM tasks They exchange data with the PLC program and an operator interface terminal OIT connected to the PCM Serial port 1 of the PCM is reserved for the programming computer you can query the PCM command interpreter while the application runs All the files required to compile and link the three PCM tasks and to load them to a PCM and execute them we
44. on the first scan Rung 9 initializes the command and data blocks for COMMREQs sent to the DATA task The BLKMV function blocks are activated on every sweep new data values are used immediately in COMMREQs Rungs 11 and 12 latch aCOMMREQ request in M0003 when M0001 is turned on The on transition coil M0002 assures that M0001 must be turned off and then on again before another COMMREO will be requested Rung 14 sends COMMREQs to the DATA task First a COMMREO request must be latched in M0003 the COMMREO fault latch M0006 must be off and the delay timer in rung 7 must have expired closing 7610001 If all these conditions are met the COMMREO status value in R00019 is checked If the status value is non zero the status location is cleared to zero and the COMMREO is sent Power flow through the COMMREO function block resets the request latch If a COMMREO fault occurs the fault latch 70M0006 prevents more COMMREQs until the program is stopped and restarted In the Series 90 30 version of the program three ladder rungs perform the work of rung 14 in this Version Ladder rungs 16 through 21 send COMMREQs to PCM TASK2 Except for data references they are identical to rungs 9 through 14 GFK 0771A Chapter 9 Example Programs 9 7 12 10 92 15 22 GE FANUC SERIES 90 70 DOCUMENTATION v3 04 PCM C Demo Application For Series 90 70 PLC START OF LD PROGRAM PLC 70 1 VARIABLE DECLARATIONS PROGRAM BLOCK DECLARATIONS
45. predictable time are often referred to as real time programming This chapter discusses real time programming under the PCM s VTOS operating system AsynchronousEvents Applicationtasks are typically structured as non terminating loops Events which occur at random times in relation to execution of the loop are often referred to as asynchronous events VTOS provides mechanisms for handing three kinds of asynchronous events 1 Incoming communication from the PCM serial ports or PLC backplane 2 Completion of slow file I O operations on the PC REM1 or REM2 devices and 3 Timer timeout events There are two separate mechanisms for handling asynchronous events asynchronous traps ASTs and event flags Both are built on the 80186 80188 microprocessor hardware interrupt mechanism They provide alternate abstract views of asynchronous events at a higher and safer level of abstraction than hardware interrupts Either of these mechanisms may be specified for each VTOS I O and timer service request VTOS Asynchronous I O Scenario When a PCM application task makes a VTOS device I O service call one of the function parameters specifies the method which VTOS will use to notify the task when the request completes If the task specified WAIT mode the service call does not return until the requested operation has completed The calling task is blocked while the operation is in progress This mode is referred to as synchronous I O because task e
46. read this data from the PCM VMEbus dual port RAM by using for example a memcpy function call C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A VME Read Modify Write Function The VMERMW function can be used to update a data element in the dual port RAM of the Series 90 70 PCM Once the sequence of operations begins the PCM will not be able to access the data until the entire sequence has completed The format of the VMERMW function block is operation data mask enable function OK logic address modifier module address Parameter Description Enable Power flow input that when TRUE enables the execution of the function Type Function type either BYTE or WORD to select the corresponding type of VME bus access to be performed WORD accesses transfer 16 bits of data on each VMEbus cycle while BYTE accesses transfer just 8 data bits per buscycle Operation A constant which specifies whether an AND or OR function is to be used to combine the data and the mask 0 specifies AND 1 specifies OR Data Mask A word value containing a mask to be ANDed or ORed with the data read from the bus If Type is BYTE only the least significant 8 bits of the mask areused AddressModifier A hexadecimal word value that specifies both the rack where the target PCM is installed and the VMEbus access mode to be performed Module Address A double word specify
47. repeated forever The number of times the counting loop repeats before printing the task number can be specified as a command line parameter SLICE C include lt vtos h gt include lt stdio h gt include lt stdlib h gt void main int argc char far far argv word i max_count word task Get task id if argc lt 2 max count atoi argv 1 0 max count 1024 for printf 5d task for i 0 i lt max count i GFK 0771A Chapter 7 Multitasking 7 3 After compiling and linking SLICE C in small model assign a 1024 byte stack size to SLICE EXE with the STKMOD utility Then load SLICE EXE to a PCM and run it as four time slice tasks using the PCM batch file SLICE BAT Part of the TERMF screen display produced by this exercise is shown below The command line parameter 512 specifies max count for each of the tasks it was selected for a Series 90 30 PCM The default count 1024 is about right for a Series 90 70 PCM Qslice SLICE EXE I9 E2 T25 512 SLICE EXE I8 E2 T25 512 SLICE EXE I7 E2 T25 512 SLICE EXE I6 E2 T25 512 The first line of output is the command to execute the batch file SLICE BAT The PCM command interpreter echos the commands in SLICE BAT as they are executed Task 9 is started first but before it can begin printing its task number task 8 is started Time slice scheduling requires at least two tasks so the time slice task rotation does not begin
48. restriction exclusive of the device and path prefix A PC disk drive may be included in pc filename if a disk drive is specified the PC device must also be explicitlyspecified Other files systems may use different pc filename formats The last example here assumes the UNIX file system L MYFILE DAT L PC A MYFILE DAT L PC C MYDIRMMYFILE EXE L usr abc this is a funny name MYFILE DAT If pc filename has the extension EXE and the file begins with a valid MS DOS relocatable EXE file header the PCM will attempt to convert the file to an absolute executable image in RAM The protection mode for EXE files is Protected regardless of any options used with the load command See the Q Set Protection Level command for a special restriction regarding EXE files using the Intel large memory model C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A M Create a Memory Module Format M module name size The create memory module command creates a PCM data module using the specified module name and size arguments The module size isinterpreted as a hexadecimal number of bytes The command has no effect if the module already exists If the module does not exist it will be created and initialized to all zeros No checksum protection will be applied to the module it may be freely read and written The location of the module may change after a reset but its contents will remain the
49. same O Get LED Configuration Format O This command is used to return the LED configuration for the PCM Two words of binary data are returned The first word holds the configuration of LED 1 and the second holds the LED 2 configuration However TERMF does not display the binary values correctly Note The O command is provided mainly for PCOP and does not return meaningful data when invoked from interactive mode GFK 0771A Appendix B PCM Commands B 13 P Request Status Data Format P status type The status type a second letter specifies the type of status data requested No intervening spaces are permitted The information returned is explained in this table Status Type Description PC Show how the status of the PCM configuration If thelast configuration completed without errors the PCM returns the prompt If there were errors the PCM returns an errorstring PD Dump the operating status of PCM at the most recent PCM reset When a soft reset occurs the reset restart pushbutton is held down for less than five seconds or a PCM resets itself because of certain fatal software errors it saves the contents of its task control blocks plus the top 64 words of the stack for the task which was executing at the time and the top 32 words of all other tasks The PD command causes the PCM to write this information to a binary filecalled PCMDUMP OUT onthePC default directory This data can be formatted as
50. services CPU_DATA H Defines PLC CPU data types which are used by VTOS services 5 20 C Programmer s Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A GFK 0771A Table 5 33 PLC API Header Files PLC API Header File Description APITYPES H CHKSUM H CHKSUMNWH CLRFITH CLRFITNWH CNTRL H CNTRLNWH FAULIS H FAULISNWH MEMTYPES H MIXTYPES H MXREAD H MXREADNWH PRGMEM H PRGMEMNWH SESSION H STATUS H SYSMEM H SYSMEMNWH TIME H TIMENWH UTILS H UTILSNWH These files provide type definitions and function prototypes for PLC APIservices as described earlier in this chapter Each file provides a small group of related services Table 5 34 Microsoft Replacement Header Files Microsoft Replacement Description Header Files EXTH These header files must be included instead of the Microsoft MALLOC H header files of the same name In addition the appropriate PCM MEMORY H library PCMS LIB PCMM LIB or PCML LIB mustappear STDARG H before any Microsoft libraries in the Microsoft linkercommand STDIO H lineor the LIB environmentvariable STDLIB H STRING H Chapter 5 PCM Libraries and Header Files 5 21 Chapter PCM Real Time Programming 6 PCM applications typically process unpredictable events such as operator intervention and incoming messages from the serial ports or PLC backplane The techniques for detecting events like these and responding within a
51. sinhl sqrtl tanl tanhl These functions are not supported in any memory model _clear87 _control87 _status87 These functions are not supported in any memory model Note The Bessel functions are j0 j1 jn y0 yl yn _j01 _j11 _jnl _y01 _y11 and ynl Appendix A Microsoft Runtime Library Support A 9 A 10 Table A 12 Memory Allocation Functions Function Memory Model stackavail This function is supported in all memory models The PCM library function must be linked rather than the Microsoft library function calloc free malloc These functions are supported in all memory models In small and medium models they are redefined by macros Note that in small and medium models far pointers must be used to access allocated buffers alloca _bcalloc _bexpand _bfree _bfreeseg _bheapadd _bheapchk _bheapmin _bheapseg _bheapset _bheapwalk _bmalloc _bmsize _brealloc _expand _fcalloc _fexpand _ffree _fheapchk _fheapmin _fheapset _fheapwalk _fmalloc _fmsize _frealloc _freect halloc _heapadd _heapchk _heapmin _heapset _heapwalk hfree _memavl _memmax _memsize _ncalloc _nexpand _nfree _nheapchk _nheapmin _nheapset _nheapwalk _nmalloc _nmsize _nrealloc realloc These functions are not supported in any memory model C Programmer s Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A GFK 0771A Table A 13 Process and En
52. source file without the file extension or dot character You can specify either s m or for Small Medium and Large respectively as the memory model S M and IL have the same meaning Compiling in Small model produces smaller faster code You should specify s or S whenever possible For more information on memory models see chapter 8 Memory Models To compile our example firstcopy PCMC EXAMPLES HELLOC to a working directory Then type cc s hello at the MS DOS prompt and press the Enter key You should see this on your screen Microsoft R C Optimizing Compiler Version 6 00A Copyright c Microsoft Corp 1984 1990 All rights reserved hello c gt If you see Bad command or file name gt your PCM C toolkit has not been installed correctly Please review the steps in chapter 2 Installation Compiling C code for the PCM requires the use of several Microsoft C Compiler command line switches CC BAT remembers all of them for you One of these switches produces a log file for example HELLO OUT When the compiler issues error or warning messages they are placed in the log file After compilation completes the log file is displayed on your screen If you see error messages you can open the log file in your text editor while correcting the C source file C Programmer s Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Linking Objects After compiling to
53. started by calling Start com timer The time interval is specified as milliseconds and is limited to 65 535 seconds or less When the timer expires a timeout function which was specified asa Start com timer parameter is called Arunning communication timer can be stopped by calling Cancel com timer Unused communication timers are freed by calling Dealloc com timer GFK 0771A Chapter 5 PCM Libraries and Header Files 5 5 Memor y Management Functions 5 6 Table 5 8 Memory Management Functions Function Name Purpose Get best buff Allocatesmemory from the smallest free memory block which is at least as large as the requested size Get buff Allocatesmemory from the first free memory block which is at least as large as the requested size Get dp buff Allocates memory from free VMEbus dual ported RAM in a Series 90 70 PCM Get mem lim Returns the starting address of a memory block reserved for application programs Max avail buff Returns the size in bytes of the largest free memory block Max avail mem Returns the total number of bytes in free memory Reserve dp buff Reserves a specified block of VMEbus dual ported RAM in a Series 90 70 PCM Return buff Returns the specified memory buffer to the free memory pool Return dp buff Returns the specified block of VMEbus dual ported RAM to the free memory pool in a Series 90 70 PCM Two functions are provided for allocating blocks of free mem
54. the PCM RAM disk The commands you put in your PCMEXEC BAT will control the PCM whenever it powers up or a soft reset occurs Similarly commands in yourHARDEXEC BAT control the PCM when a hard reset occurs Use your computer and any text editor which produces ASCII text files to create these files Then use the L Load command described in appendix A Microsoft Runtime Library Support to load them to the PCM RAM disk If it exists PCMEXEC BAT is always run on power up and a soft reset regardless of whether or not PCOP has stored User Configuration Data UCDF to the PCM AlthoughPCMEXEC BAT can be thought of as a configuration tool its function is different from the UCDE A UCDF can define the entire operating environment of the PCM while PCMEXEC BAT is limited to defining the environment for application tasks In addition UCDF data is processed much earlier on the reset or power up process than PCMEXEC BAT Caution Be very careful when attempting to use both a PCMEXEC BAT file and UCDF configuration data There are subtle interactions between them which can prevent the PCM from operating as expected The most common use of the PCMEXEC BAT file is to run application programs Batch file commands can also be used to configure the user LEDs on the PCM and set the serial port communication parameters as described in appendix B PCM Commands GFK 0771A Appendix C Batch Files C 3 Appendix PCM C Directories and Files During installati
55. the accuracy completeness sufficiency or usefulness of the information contained herein No warranties of merchantability or fitness for purpose shall apply Thefollowing are trademarks of GE Fanuc Automation North America Inc Alarm Master GEnet PowerMotion Series One CIMPLICITY Genius ProLoop SeriesSix CIMPLICITYPowerTRAC Genius PowerTRAC PROMACRO Series Three CIMPLICITY 90 ADS Helpmate Series Five VuMaster CIMSTAR Logicmaster Series90 Workmaster Field Control Modelmaster Copyright 1993 1996 GE Fanuc Automation North America Inc All Rights Reserved Preface This manual contains essential information about the design and construction of C language application programs for the GE Fanuc Series 90 Programmable Coprocessor Module PCM It is written for experienced C programmers who are also familiar with the operation of Series 90 PLCs Readers new to the C programming language or to Series 90 PLCs should familiarize themselves thoroughly with these topics before attempting to use the material in this manual The list of publications at the end of this section contains helpful references General information on PCM hardware its installation and operation and connecting a personal computer PC to a PCM can be found in the Series 90 Programmable Coprocessor Module and Support Software User s Manual GFK 0255 revision D or later Content of this Manual GFK 0771A Chapter 1 Introduction Chapter 1 describes the PCM C toolkit
56. the object OBJ files C programs must be linked with Microsoft and PCM library functions to produce an executable EXE file Linking for the PCM also requires several command line switches To make it simple another MS DOS batch file CLINK BAT is provided for linking a single object file Its use is similar to CC BAT clink memory model file name where the same memory model and file name used with CC BAT must be used again Typing clink s hello produces Microsoft R Segmented Executable Linker Version 5 10 Copyright C Microsoft Corp 1984 1990 All rights reserved If there are linkage errors the linker will display error messages between its invocation message and the MS DOS prompt CLINK BAT accepts up to five object files If your application requires six or more source files see Using Makefiles later in this chapter Specifying the Stack Size Unlike standard MS DOS the PCM executes applications in ROM Read Only Memory as well as RAM Random Access Memory which can be read and written One consequence of this feature is that the PCM cannot use the MS DOS method for specifying program stack size Instead each PCM EXE file has a data value in its header which contains the stack size MS DOS uses this data for a different purpose and the Microsoft linker always initializes the PCM stack size to 65 520 bytes This is a very large stack for most applications and wastes PCM memory A PCM C uti
57. to develop your PCM applications If you care about your productivity you will want an 80386 or 80486 based computer MS DOS 4 0 or 5 0 and a fast hard disk You can install the toolkit software from a DOS window under Microsoft Windows amp 3 x but not under Windows 95 or Windows NT If your computer runs Windows 95 restart your computer in MS DOS mode If your computer runs Windowsx NT you must install DOS and then configure your computer to boot either Widows NT or DOS A serial cable to connect the PCM and PC These GE Fanuc products are also required to develop PCM C applications PCM Support Software TERME revision 1 00 or later is required for terminal emulation and file transfer between the PC and PCM Logicmaster 90 Configuration Software is required to set the PCM configuration mode for C applications These items which are not furnished by GE Fanuc are required for PCM C development Microsoft C Version 6 0 Microsoft C C Version 7 0 or a 16 bit version of Microsoft Visual C C Professional Edition A text editor such as the Microsoft Editor EDIT COM furnished with Microsoft MS DOS Version 5 00 Microsoft MS DOS and Windows are registerd trademarks of Microsoft Corporation Microsoft C Installation Requirements Microsoft C must be installed before the PCM C toolkit There are two requirements for installing Microsoft C 1 You must select the Alternate Math package during installation When you r
58. values Using EVENT NOTIFY Mode Event Processing For the purpose of illustrating EVENT NOTIFY processing assume that a simple operator interface is required This interface has two functions sending the first 100 PLC register R values to the operator interface terminal OIT once per second and receiving operator commands from the terminal Operator commands must be acted upon immediately when they arrive The program OTT DRVR C shows how these requirements might be met OIT DRVR C include vtos h define CMD RECEIVED EF 00 define REGS RECEIVED EF 01 define READ REGS EF 02 define DEAD PLC EF 03 define TASK FLAGS CMD RECEIVED REGS RECEIVED READ REGS DEAD PLC define COMMAND SIZE 84 define REG SIZE 100 define REG READ TIME 1000 one second define DEAD PLC TIME 5000 five seconds byte Command COMMAND SIZE word Regs REG SIZE These function prototypes specify functions which are beyond the scope of this example void process command byte far cmd ptr void display registers word handle word far data ptr void display bad regs alarm word handle void display dead plc alarm word handle void main void device result command result regs result word oit hndl regs hndl task id word read timer dead plc timer local flags word read pending 0 C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Reset ef TASK
59. was sent successfully Note that Series 90 30 COMMREO function blocks have no OK output OK and FT can have these states Enable Error OK Output FT Output Active No TRUE FALSE Active Yes FALSE TRUE Notactive No execution FALSE FALSE In NOWAIT mode a COMMREQ function block with a valid SYSID always passes power flow to the OK output whenever it executes The FT output becomes active in NOWAIT mode if L There is no PCM or other intelligent module in the rack and slot specified by the SYSID input 2 The data length specified in the command block is zero or greater than128 words The COMMREQ Command and Data Blocks The command block provides additional information about the COMMREQ message needed by the COMMREQ function block The address of the command block is provided to the IN input to the COMMREQ function This address may be in any word oriented PLC reference R AI or AQ in both the Series 90 70 and Series 90 30 COMMREO P or L in the Series 90 70 COMMREO only The length of the command block is always 6 words The COMMREO data must immediately follow the command block in the same reference table C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Data Block Length Wait Nowait Flag Status Pointer Memor y Type GFK 0771A The command block has the following structure Data Block Length Start address 0 word 1 Wait NOWaitFlag Start address
60. 00 hexadecimal by the STKMOD utility The offset value of the last stack word is 03FE hexadecimal Chapter 11 Utilities 11 9 The SP register value tells us that the stack word display for task OE begins at offset 03D4 hexadecimal in the stack segment The leftmost value in the first row of the stack display is the word at that stack location Since each row of the display contains 8 words 16 decimal or 10 hexadecimal bytes it follows that the offset of the word at the start of the second row is 03E4 hexadecimal Similarly the third row starts at offset 03F4 hexadecimal Counting along the third row by twos we find that the value at offset O3FE is 061D hexadecimal The next value BBBB hexadecimal is the start of a different PCM memory block BBBB is actually the value which VTOS uses to mark the start of free memory blocks The last 23 words of the stack display are beyond the end of the stack segment for task OE This version of PCMDUMP has no knowledge of task stack sizes Using Microsoft Map Files 11 10 For small model tasks all executable code is contained in a single code segment In map files produced by the Microsoft linker for example HELLO MAP the code segment value is shown as zero 0000 hexadecimal In the Publics by Value section of the map file the offset value within the code segment for each function is also shown To identify the function which each task was executing most recently before the reset occurred compar
61. 00H EE0000H to to to to to to to to EO7FFFH E27FFFH E47FFFH E67FFFH E87FFFH EA7FFFH EC7FFFH EE7FFFH D00000H D20000H D40000H D60000H D80000H DA0000H DC0000H DE0000H to to to to to to to to D07FFFH D27FFFH D47FFFH D67FFFH D87FFFH DA7FFFH DC7FFFH DE7FFFH 3 C00000H C20000H C40000H C60000H C80000H CA0000H CC0000H CE0000H to to to to to to to to CO7FFFH C27FFFH C47FFFH C67FFFH C87FFFH CA7FFFH CC7FFFH CE7FFFH B00000H B20000H B40000H B60000H B80000H BA0000H BC0000H BE0000H to to to to to to to to BO7FFFH B27FFFH B47FFFH B67FFFH B87FFFH BA7FFFH BC7FFFH BE7FFFH A00000H A20000H A40000H A60000H A80000H AA0000H AC0000H AE0000H to to to to to to to to A07FFFH A27FFFH A47FFFH A67FFFH A87FFFH AA7FFFH AC7FFFH AE7FFFH 900000H 920000H 940000H 960000H 980000H 9A0000H 9C0000H 9E0000H to to to to to to to to 907FFFH 927FFFH 947FFFH 967FFFH 987FFFH 9A7FFFH 9C7FFFH 9E7FFFH 800000H 820000H 840000H 860000H 880000H 8A0000H 8C0000H 8E0000H to to to to to to to to 807FFFH 827FFFH 847FFFH 867FFFH 887FFFH 8A7FFFH 8C7FFFH 8E7FFFH In PCM address space VMEbus memory is located in the range 0xA000 0x0000 to 0xA000 0x7FFE regardless of the rack slot location where the PCM is installed The Series 90 70 VMEbus data path is 16 bits wide AllSeries 90 70 modules support 16 bit data access
62. 1 word 2 Status Pointer Memory Type Start address 2 word 3 Status Pointer Offset Start address 3 word 4 Idle Timeout Value Start address 4 word 5 MaximumCommunicationTime Start address 5 word 6 Start address 6 word 7 Data Block through Start address 533 word 134 Information required for the command block can be placed in the designated memory area using the MOV or BLKMOV function block When entering information for the command block refer to these definitions This word contains the number of data words starting at address 6 word 7 to the end of the data block inclusive The data block length ranges from 1 to 128 words This word selects whether or not the program should wait for the COMMREO to be acknowledged by the PCM before the PLC sweep continues This word should always be set to zero to select NOWAIT mode The two status pointer words specify a PLC memory location where the target PCM is expected to write a status word Status Pointer Memory Type must contain a numeric word value that specifies the PLC memory reference type for the status word location The table below shows the code for each reference type Status Pointer Memory Type For This Memory Type Use This Value Discrete input table 16 Discrete output table 18 Registermemory 8 Analoginputtable 10 Analog output table 12 The most significant byte of the word value at address 2 should contain zero Chapter 4 Using PCM
63. 10 for details ccce KKK hehehe e e e e kk ke kk e e he he he he he e e e e ke ke ke e kk He He e hehehe e e e e e kk ke ke e e e hc ke ke ke ke ke ke ke ke ke ke e e ek lt lt RUNG 18 gt gt M00021 M00022 SND_CR2 COMMENT I Program PLC_70 C PCMC EXAMPLES DEMO_3T PLC_70 Block _MAIN Listing 9 1 Continued Chapter 9 Example Programs 9 11 9 12 12 10 92 15 22 GE FANUC SERIES 90 70 DOCUMENTATION v3 04 Page PCM C Demo Application For Series 90 70 PLC ccce echec hehehe e e e e e ke kk ke e He hehe he he he e e e e ke kk e He e He He e hehe he he e e e e ke kk ke kk e c ke ke ke ke k ke ke k k ke ke e kk k If a COMMREQ has been requested and there are no faults from previous COMMREQs and at least 5 seconds have elapsed since the first scan then check the COMMREQ status location before sending a new COMMREQ to TASK2 See the comment at RUNG 13 for details Rok e e e e e e e e e e e e e e Ae e e e e e e e e Ae e e e e e e He e Ae e e e e e e He e Ae e e e e e e He e Ae e e e e e e Ae e Ae e e e e III IAI lt lt RUNG 21 gt gt M00023 M00026 T00001 I 1 NE INT I I M00023 R00029 I1 Q 4COMM 4 RM I I REQ I I I M00026 CONST I2 CONST IN Q R00029 R00020 IN FT SM 4000004 400000 LEN 100001 I I CONST SYSID 0002 I I I CONST TASK 00000018 END OF PROGRAM LOGIC Program PLC_70 C PCMC EXAMPLES D
64. 3D2 BP 03E2 SI FF6E DI 9EC4 DS 06C8 ES 0000 SS 0687 CS 0620 IP 030E NV UP EI PL ZR NA PE NC O1AD 0109 0001 O3F4 0687 0001 O3F8 0687 03E4 5A3F E55E 0001 03F4 0687 0001 03F8 0687 0038 0613 C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A The register and stack data is displayed in two parts the contents of PCM microprocessor registers and the first few words of data on the task s stack No register or stack data is displayed the for tasks which were not active when the reset occurred such as task 000D hexadecimal The contents of thirteen microprocessor registers AX BX etc are displayed as hexadecimal values The processor status word or flags register is displayed as eight individualflags Table 11 3 Flags Register Flag Name Symbol and Meaning Symbol and Meaning When Not Set When Set Overflow flag NV Nooverflow OV Overflow occurred Directionflag UP Up DN Down Interruptflag DI Disable interrupts EI Enable interrupts Sign flag PL Plus NG Negative Zeroflag NZ Notzero ZR Zero AL Carry Borowflag NA NoAL register carry or AC ALcarry or borrow borrow occurred Parityflag PO Parityodd PE Parityeven Carry Borow flag NC Nocarry or borrow CY Carry or borrow occurred For more information on status flags and the processor status word refer to Intel Corporation documentation on the 80186 and 80188 microprocessors The regi
65. 485 only on COM2 With hardware flow control RTS is turned on when the port is ready to transmit Then transmission begins when CTS becomes active RTS remains on until lt delay_value gt expires after the last character is sent With software or no flow control RTS is not turned on and transmission begins immediately lt duplex_mode gt 2 4 or p the type of physical connection 2 half duplex 2 wire for RS 422 485 4 full duplex 4 wire for RS 422 485 p point to point Available in PCM firmware version 3 00 or later In point to point mode e The receiver for the specified port is always enabled When physical interface 422 or 485 all RS 485 line drivers for the specified port are enabled when the command is executed and remain on continuously Default selection B 8 C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A InitializationString COMI duplex mode Continued COM2 Continued In full duplex mode Thereceiver for the specified portis always enabled When lt physical_interface gt 422 or 485 the RS 485 line drivers for RTS and transmitted data outputs on the specified port are turned on immediately before transmitting and remain on until lt delay_value gt expires after the last character is sent At all other times these drivers are in theirhigh impedancestate tri stated In half duplex mode The receiver for the specified portis
66. CPU device for receiving COMMREQ messages from the PLC CPU and for responding to them With all the preliminaries completed main enters a non terminating for loop At the top of the loop a WAIT mode Read dev call causes DATA to stop executing until a COMMREO arrives an error occurs or the Read dev call is aborted by some other task If the data returned by Read dev is smaller than the size of a COMMREQ message the continue statement jumps to the top of the loop skipping the code where the data is processed The COMMREQ message specifies a PLC memory location where the PLC CPU expects to receive a COMMREQ status value The PLC memory type and offset of the status address are extracted from the COMMREQ and assigned to the corresponding members ofthe st addr structure A Special dev callusing special code 8 sets the PLC CPU address of the stat hndl channel to the new memory type and offset Finally a WAIT mode Write dev call sends the value 1 to the status address Note that the code expects all the COMMREO data to be in the message Supporting COMMREQs with external data buffers will require a change to the msg buf union member where main looks for the COMMREO status location plus additional code to process a COMMREO data buffer Next command data is extracted from the COMMREQ message and assigned to the command recnum and cpuloc variables The cpuloc value is used to construct a VTOS device name string for CPU register R memory in tmp
67. EMO_3T PLC_70 Listing 9 1 Concluded C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Chapter 10 Restrictions GFK 0771A Applicationsin ROM Two PCM models the Series 90 70 PCM 711 and Series 90 30 PCM 300 use a pair of read only memory ROM devices One ROM contains the VTOS operating system and other system firmware the PCM will not operate without it However the second ROM contains firmware for the MegaBasic programming environment and the CCM communication protocol This second ROM may be replaced by one containing a custom application ROM resident applications provide several advantages 1 The code and initial data values are completely non volatile Code stored in PCM battery backed RAM depends on a battery for retention while the PLC is powered off However ROM resident applications require a battery only when data they modify at run time must be preserved while power is off In addition ROM resident code can never be corrupted by program errors although RAM resident code can 2 Storing the application in ROM frees all of RAM for program data Some applications may fit in a smaller less expensive memory option Table 10 1 below shows the memory models which support code in ROM and the code data and stack size limits for each Table 10 1 Memory Models Which Support Code in ROM Memory Model Max ROM Code Max Static Data Max Stack Data Small 64 K
68. FANUC GE Fanuc Automation Programmable Control Products C Programmer s Toolkit for Series 90 PCMs User s Manual GFK0771A August 1996 GFL 002 Warnings Cautions and Notes as Used in this Publication Warning notices are used in this publication to emphasize that hazardous voltages currents temperatures or other conditions that could cause personal injury exist in this equipment or may be associated with its use Insituations where inattention could cause either personal injury or damage to equipment a Warning notice is used Caution notices are used where equipment might be damaged if care is not taken Note Notes merely call attention to information that is especially significant to understanding and operating the equipment This document is based on information available at the time of its publication While efforts have been made to be accurate the information contained herein does not purport to cover all details or variations in hardware or software nor to provide for every possible contingency in connection with installation operation or maintenance Features may be described herein which are not present in all hardware and software systems GE Fanuc Automation assumes no obligation of notice to holders of this document with respect to changes subsequently made GE Fanuc Automation makes no representation or warranty expressed implied or statutory with respect to and assumes no responsibility for
69. FLAGS Set ef READ REGS task id Get task id oit hndl Open dev COM1 13 WRITE MODE WAIT task id regs hndl Open dev CPU R1 READ MODE NATIVE MODE AUTO REWIND MODE WAIT task id Read dev oit hndl Command COMMAND SIZE EVENT NOTIFY task id CMD RECEIVED device result far amp command result read timer Start timer RELATIVE TIMEOUT REPEAT MODE MS COUNT MODE 0 REG READ TIME READ REGS for local flags Test ef Reset ef local flags if local flags amp CMD RECEIVED if command result ioresult SUCCESS process command Command Read dev oit hndl Command COMMAND SIZE EVENT NOTIFY task id CMD RECEIVED device result far amp command result local flags amp REGS RECEIVED Cancel timer dead plc timer read pending 0 if regs result ioreturn REG SIZE display bad regs alarm oit hndl else display registers oit hndl Regs local flags amp READ REGS amp amp read pending Read dev regs hndl Regs REG SIZE EVENT NOTIFY task id REGS RECEIVED device result far amp regs result read pending 1 dead plc timer Start timer RELATIVE TIMEOUT MS COUNT MODE 0 DEAD PLC TIME DEAD PLC local flags amp DEAD PLC Abort dev regs hndl ABORT ALL 0 read pending 0 display dead plc alarm oit hndl Wait ef TASK FLAGS GFK 0771A Chapter 6 PCM Real Time Programming 6 7 OTT DRVR C recognizes four even
70. INTERRUPTS START OF PROGRAM LOGIC lt lt RUNG 5 gt gt INI_FSC COMMENT BRK E KKK hehehe e e e e ke KKK kk e he he he hehe he e e e e kk ke e kk He He e He e He e e e e kk ke ke ke e e e c kc ke ke ke ke ke ke ke ke ke ke e ee On the first scan initialize the PCM COMMREQ status locations to non zero values to permit sending the first COMMREOs Clear the COMMREQ fault latches Reset the COMMREQ delay timer and start the 5 second delay for the first COMMREQ cce de de de hehehe he e e e e ke ke ke ke ke e He He e he hehe he e e e e ke kk ke ke ke He He hehe he he e e e e ek ke ke ke e c c ke ke ke ke ke ke ke ke e ke k e k k k lt lt RUNG 6 gt gt FST SCN M00006 MOVE_ I INT I I CONST IN Q RO0019 CONST IN Q R00029 00001 LEN 00001 LEN I 100001 100001 I I lt lt RUNG 7 gt gt I TO0001 TOO001 ONDTR 10 10s FST SCN R I I CONST PV CV 00050 R00015 lt lt RUNG 8 gt gt Program PLC_70 C PCMC EXAMPLES DEMO_3T PLC_70 Block _MAIN Listing 9 1 C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A GFK 0771A 12 10 92 15 22 GE FANUC SERIES 90 70 DOCUMENTATION v3 04 Page PCM C Demo Application For Series 90 70 PLC F F e ke ee e e e ke ke ee KK ke Sk ke ehe e KK ke e e e ke KKK e e ke KKK ke e e e e e He e e e e e ke e e de RK He He e e ke e e e H
71. LC CPU which contains PLC register values When a COMMREQ arrives the values are sent out serial port 1 to an operator interface terminal OIT The program acknowledges the COMMREO by writing to the PLC data location specified by the COMMREO status pointer The OIT may send a command which contains new register values When a command arrives the new values are written to the PLC CPU The Write dev operations which acknowledge the COMMREQ send register data to the OIT and write new register data to the PLC CPU all use AST notification Each one also uses a timer with AST notification to abort the write operation when it does not complete In addition Read dev calls using AST notification receive the COMMREQ and OIT command There are a total of eight I O operations and timers Each I O completion or timeout is an event for the program to process Figure 6 1 is a state transition diagram which shows how the example program processes these events The arrows in Figure 6 1 represent events and the circles represent states The arrows pointing away from the center circle are labeled with the name of an event When one of the named events occurs the state of the program transitions from the state at start of the corresponding arrow to the state at the tip of the arrow The state at the tip is said to be the successor of the state at the root of the arrow GFK 0771A Chapter 6 PCM Real Time Programming 6 9 SEND DISPLAY DATA STATE
72. LC CPU status flags bit field structure and is approximately equivalent to the PLC_STATUS_WORD_STRUC type defined in STATUS H cp sweep info Astructure type component of cpu long status It defines the PLC sweep execution data structure cpu tod Defines the time and date structure type used to read or write the CPU TOD CPU Time of Day clock device It contains the current day of the week and is equivalent to the TIMESTAMP LONG STRUC type definedin APITYPES H cpu_tod_sclk Astructure type component of cpu_sweep_infa It defines the short no day of the week time of day clock structure type used to timestamp PLC program changesin cpu_long_status and is equivalent to the TIMESTAMP_STRUC type definedin APITYPES H long_cmrq Astructure type component of cmrq_union It defines COMMREO messages with msg_type values 0x82 and 0x83 hexadecimal These COMMREQs have a separate data buffer msg addr Defines the bit field structure type which specifies the source and destinationofallPLCbackplanemessagesasPLC rack slot taskaddresses It is used as a member of the msg hdr type msg hdr Defines the common header structure used by all PLC backplane messages including COMMREOs short cmrq Astructure type component of emrq union It defines COMMREQ messages with msg type values 0xD2 and 0xD3 hexadecimal These COMMREQs contain all their data within the message smemreq msg Defines the structuret
73. LC Data References e 5 14 Table 5 21 Reading Series 90 70 PLC Data References eese 5 14 Table 5 22 Writing PLC Data References 5 15 Table 5 23 Writing Series 90 70 PLC Data References sees 5 15 Table 5 24 Controlling PLC Operation nace caseiros ea e 5 15 Table 5 25 Reading Mixed PLC Data References nn nrar r rrun rrur rrur 5 16 Table 5 26 Reading and Clearing PLC and I O Faults LL 5 16 Table 5 27 Reading Series 90 70 Genius and System Faults 0 6 cece eee eee 5 16 Table 5 28 Reading and Setting the PLC Time of Day Clock LL 5 17 Table 529 PEC API Types EE 5 17 Table 5 30 Data IVpe3 EE 5 18 Table 5 31 PLC API Global Data cesse e ep ce RPG d REG PI 5 18 Table 5 32 VTOS Header Files eere ieee e EEN Ee bd 5 20 Table 5 33 PLC API Header Files ori ceret e i Rep ea 5 21 Table 5 34 Microsoft Replacement Header Files 5 21 Table 10 1 Memory Models Which Support Code in ROM 10 1 Table 10 2 ROM Device Part Numbers and Locations 060 ccc eee 10 2 GFK 0771A CProgrammer s Toolkit for Series 90 DC Ms User s Manual August 1996 xiii Contents Table 11 1 STKMOD Error Messages 11 2 Table 11 2 Current State Values iieri i sri yaara E een 11 6 Table 11 3 Flags Register 11 9 Table 11 4 Valid Hardware Check Strings 11 13 Table A 1 Buffer Manipulation Functions LL A 2 Table A 2 Character Classification and Conversion Functions A 2
74. M 301 You will need to change the I O configuration in the Logicmaster 90 30 folder PCMC EXMPLES DEMO_3T PLC_30 if you use a different Series 90 30 PCM model The Series 90 70 PCM can run the demo without a Logicmaster 90 70 I O configuration and none is provided in the Logicmaster 90 70 folder PCM Rack and Slot Location The PLC ladder programs assume that the PCM is installed in PLC rack 0 slot 2 If your PCM is in a different location you will need to change the SYSID input to the COMMREO function blocks in the program If you use a Series 90 30 PLC you will also need to change the PCM slot location in the I O configuration for your PLC Building The PCM Executable Files Follow these steps to build the PCM files 1 Make the hard drive where the PCM C toolkit is installed the current drive Make NPCMCNEXMPLESNDEMO 3Tthecurrent directory 2 Type nmake mk demo3 or nmk mk demo3 as appropriate See Using Makefiles in chapter 3 of this manual followed by the Enter key at the MS DOS prompt The Microsoft NMK or NMAKE utility will compile all the sources link the three executable files and set the stack sizes 3 Run TERMF on your computer 4 At the PCM command prompt type 1 load bat and press the Enter key 5 Then type load at the PCM command prompt and press the Enter key The PCM commands in LOAD BAT will load the application files to the PCM 6 Exitfrom TERMF by holding the Ctrl key down while pressing t
75. Microsoft C header file DOS H is included because it contains declarations of the functions disable and enable and definitions for the macros FP SEG and FP OFE These macros provide a simple method for assigning fixed addresses to far pointers This example uses a 4K byte memory block The macro definitions VME LIMIT and VME OFFSET place it in the last 4K bytes of VMEbus memory The segment and offset values for the block are assigned to a far pointer vme ptr The memory block is reserved by passing its start address and size to Reserve dp buff Ifthecall returns SUCCESS vme avail is set to one otherwise vme avail isset to zero If the block was reserved successfully the code tests the lock word in VMEbus memory If the PLC CPU has control of the memory block the code waits five milliseconds and tests the lock again A VMEWRT WORD transfer of 4K data bytes takes about five milliseconds for a Series 90 70 Model 771 CPU Note the disable and enable function calls They disable hardware interrupts while the code acquires control of the lock byte Without these calls the task which executes this code could be pre empted after it tested the lock word but before it could be changed Interrupts must be enabled when Wait time iscalled After the memory block is acquired the data in it is copied to the array local buf and the lock byte is unlocked Finally the memory block is freed by calling Return dp buff Chapter 4 Using PCM Resourc
76. O function block which sends the COMMREQ message must use 6 as the value of its TASK ID parameter In the loop a Read dev request is made in WAIT mode Normally this function call does not return until a message is received which contains COMREQ SIZE bytes However the Read dev request could be aborted by another task If so fewer than COMREO MSG SIZE characters would be returned Consequently the program checks the number of bytes read by Read dev Ifthe data size is correct the function send serial alarm is called to send the alarm and respond to comreq is called to write a non zero value to the COMMREQ status pointer location in the PLC CPU The implementation of these functions is beyond the scope of this example For more information on COMMREQs refer to Communications Request COMMREQ Messages from PLC Programs in chapter 4 Using PCM Resources ALARM EXE should be run as a priority based VTOS task with priority that is ID value 5 the highest priority which should be used by any application task This command line ina PCMEXEC BAT file could be used R ALARM EXE I5 Chapter 6 PCM Real Time Programming 6 5 H Once ALARM EXE enters the loop it executes only when the condition it monitors has actually occurred If this is a rare event ALARM EXE will require very little PCM processor time on average One or more additional application tasks can run in this same PCM as long as they execute at lower priority higher ID
77. OWAIT mode should always be used because WAIT mode COMMREQs can significantly degrade PLC sweep time In addition WAIT mode COMMREOsS can cause the PLC watchdog timer to expire halting PLC program execution C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Programming COMMREQ Function Blocks COMMREQ function blocks have four inputs Series 90 30 COMMREQs have one output while Series 90 70 COMMREQs have two enable ok Series 90 70 only IN This parameter specifies the PLC memory location where the COMMREQ command block begins for example R00001 The COMMREO command and data blocks must occupy contiguous areas within one of the word oriented PLC data types listed above The command block is described in the next section SYSID This parameter species the rack and slot address of the target PCM Logicmaster 90 software displays SYSID as a hexadecimal value Its most significant byte must contain the rack number of the target PCM and the least significant byte must contain the slot address For example the value 0102 hexadecimal specifies rack 1 slot 2 Note that Series 90 30 PCMs must be installed in rack zero If SYSID does not specify a rack slot address where a PCM or other Series 90 module capable of receiving COMMREQs is installed no COMMREQ will be sent when the function block is enabled and the function block FT output will become active TASK This parameter species
78. PCM battery shorting the PCM battery terminals for at least ten seconds powering on the PLC and then reconnecting the battery If there is no MegaBasic startup banner or command prompt and you are sure the PCM configuration mode is correct refer to chapter 6 Troubleshooting Guide in the Series 90 Programmable Coprocessor Module and Support Software User s Manual GFK 0255D or later GFK 0771A B 1 Interactive Mode B 2 When the PCM connects you to the command interpreter after power up or a reset you should see a this prompt When you return to the command interpreter from MegaBasic you may not see a prompt on your screen immediately but pressing the Enter key should display a prompt At this point the interpreter is in its default mode which is used to communicate with the PCM development software package PCOP Default mode does not respond to you with text messages nor does it echo the keys you type back to your screen You must switch to interactive mode by typing two exclamation points and pressing the Enter key This message will appear INTERACTIVE MODE ENTERED type for a list of commands To display the list of PCM commands type a question mark and press the Enter key If you are using PCOD you need to type three exclamation points and then press the Enter key in order to return to PCOP mode PCOP cannot communicate with the command interpreter while it is in interactive mode
79. Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A The function prototypes for these services in VTOS H contain ellipses for the optional NOWAIT mode parameters When using EVENT NOTIFY mode with any of these functions in the small and medium memory models the result ptr parameter type must be coerced to device result far There are two ways it can be done An identifier which was declared as type device result far may be used Altematively the address of a structure may be passed by using an explicit type cast to device result far For example include vtos h device result far p Get buff size of device result device result result word task id Get task id Open dev COM1 WRITE MODE EVENT NOTIFY task id EF O01 Open dev COM2 WRITE MODE EVENT NOTIFY task id EF 02 device result far amp result See Small and Medium Model Differences Between VTOS and MS DOS in chapter 8 Memory Models for more information Failure to coercethe result ptr parameterto far insmallor medium model will result in unexpected operation possibly including PCM lockup Device Driver Support Functions Table 5 11 Device Driver Support Functions Function Name Purpose Get next block Returns device argument blocks to a VTOS device driver Install dev Installs a VTOS device driver Install isr Installs a VTOS interrupt serviceroutine Notify task Notifies a VTOS task whe
80. Resources 4 7 Status Pointer The word at address 3 contains the zero based offset for the status word location Offset within the selected memory type For example R00001 is at offset zero in the register table R00300 is at offset 299 Idle Timeout The idle timeout value is the maximum time the PLC CPU waits for the target PCM to Value acknowledge receipt of the COMMREO This value is ignored in NOWAIT mode Maximum The value at address 5 specifies the maximum time the PLC CPU waits for the target Communica PCM to complete the COMMREO This time is also ignored in NOWAIT mode tion Time Data Block The COMMREQ data block contains all the data which the PLC CPU will send to the target PCM with the COMMREO message The data size in words is specified by the Data Block Length value described above Receiving COMMREQ Messages In a PCM Program PCM C applications receive COMMREO messages by calling Open dev to open an I O channel on the CPU device for reading and then calling Read dev to copy each COMMREQ message to a program variable The following program fragment opens a channel using a service point it calculates by adding ten to its VTOS task number Note that the VTOS device I O operations in this example use WAIT mode I O to receive NOWAIT COMMREQs There is no connection between PLC CPU COMMREO WAIT NOWMAIT modes and the notification mode used by VTOSI O 4 6 C Programmer e Toolkit for Series 90 PCMs User s Manual A
81. ST to itself ora different task by calling Post_ast Semaphore Functions GFK 0771A Table 5 4 Semaphore Functions Function Name Purpose Block_sem Checks whether a semaphore is open wait if not Link_sem Links the calling task to a named semaphore create one if it is not found If the semaphore already exists and is controlled by another task the call ing task waits Unblock sem Releases a semaphore and activates the first waiting task Unlink sem Unlinks the calling task from a semaphore Two or more tasks can share memory modules but not I O channels by using named semaphores A task may create a new named semaphore or use an existing one by calling Link sem The task calls Block sem before using the resource and then calls Unblock sem when itis finished If the resource is available that is the semaphore is open execution proceeds immediately However if another task is already using the resource the semaphore is closed execution is suspended until the resource is available again Chapter 5 PCM Libraries and Header Files 5 3 Note that Link sem leaves the semaphore closed Unblock sem must be called after the Link sem call Typically the controlled resource is accessed between calls to Link sem and Unblock sem An unused semaphore can be freed by calling Unlink sem but this is rarely necessary One possible application might be for a semaphore used only during initialization when PCM mem
82. STRUC containing MAX SESSIONS elements When each PLC API servicerequest completes it updatesthe plc status info elementcorresponding tothe session id valuepassed to it when it was called Note that update plc status and update plc status nowait haveno other effect than updating an element of this array C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Using Standard C Libraries Most standard C library functions may be used with PCM C applications However there are some restrictions described below Other Microsoft C runtime library functions such as MS DOS services and graphics are not supported by PCM hardware and or VTOS Appendix A Microsoft Runtime Library Support provides a complete reference on the suitability of each Microsoft C 6 0 runtime library function for PCM applications Restrictions Many standard C library functions are supported without restriction in all the Intel memory models supported by the PCM However the actual Microsoft library code is not always used In some cases a C preprocessor macro defined in a PCM header file substitutes a different Microsoft library function call In other cases code provided with the PCM C toolkit replaces code in the Microsoft library These substitutions occur as a result of the order in which libraries are specified to the Microsoft linker Other functions may be used without restrictions in large model applications but restrictio
83. SUM H services CLRFITH PLC API services forclearingI O and PLC fault tables CLRFITNWH NOWAIT versions of CLRFLTH services CNTRL H PLC APIservicesfor controlling PLC operation CNTRLNWH NOWAIT versions of CNTRL H services CPU DATA H Data types used by VTOS CPU device CTOS H EXTH Replacement for MS DOS include file with the same name FAULTS H PLC APIservicesforreadingI Oand PLC fault tables FAULTSNWH NOWAIT versions of FAULTS H services MALLOC H Replacement for MS DOS include file with the same name MEMORY H Replacement for MS DOS include file with the same name MEMTYPES H Data types used by SYSMEM H services MIXTYPES H Data types used by MXREAD H services MXREAD H PLC API services for reading collections of mixed PLC Data MXREADNWH NOWAIT versions of MXREAD H services PCMCSARG H No longer used retained for compatibility PCMLIB H No longer used retained for compatibility PRGMEM H PLC API services for reading and writing Series 90 70 L and P data PRGMEMNWH NOWAIT versions of PRGMEM H services SESSION H Function prototypes for starting a PLC APIsession STATUS H Data Types used for reporting PLC operation status STDARG H Replacement for MS DOS include file with the same name STDIO H Replacement for MS DOS include file with the same name STDLIB H Replacement for MS DOS include file with the same name STRING H Replacement for MS DOS include file with the same name SYSMEM H PLC API services for reading and writing PLC data
84. Slot in this section OK Power flow output that is TRUE when the function is enabled and completessuccessfully Q Set to TRUE if the semaphore was acquired Set to FALSE if thesemaphore was not available i e was owned by another task GFK 0771A Chapter 4 Using PCM Resources 4 21 When the VMETS function receives power flow a boolean TRUE is exchanged with the data at the address specified by ADR using the address mode specified by AM The VMETS function activates the Q output if the semaphore was available and acquired by the function When the operation is successfully completed the VMETS function passes power to the right through the OK output For more information on Series 90 70 PLC programming refer to the Logicmaster 90 70 Programming Software User s Manual GFK 0263 and the Series 90 70 Programmable Controller Reference Manual GFK 0265 For more information about Series 90 70 VME bus applications refer to the Series 90 70 Programmable Controller User s Guide to the Integration of Third Party VME Modules GFK 0448 C Program Access to PCM Dual Port RAM VMEbus dual port RAM occupies the address range 0xA000 0x0000 through 0xA000 0x7FFF in the current hardware revision of the Series 90 70 PCM VTOS and the PLC APIlibrary use a part of this memory the portion they use is at the low end of the address range When VME function blocks are used for data PCM transfers both the PLC and PCM programs must know the location
85. TEST2 C include lt vtos h gt include lt string h gt include lt stdio h gt char str PCM char s 4 void main void char far p strcpy p C printf s char far str p char far toolkit The printf call in this example has three optional parameters all pointer to char The second one p was declared far and does not need a type cast However the array str and the string literal toolkit are passed by defaultas near addresses They do need type casts For information on using optional parameters in VTOS device services see Devicel O Functions in chapter 5 PCM Libraries and Header Files Chapter 8 Memory Models 8 3 Advantages and Restrictions Each memory model supported by VTOS has its own set of advantages and restrictions They are summarized below Small Model e Smallest fastest code of any memory model supported by VTOS e Code size is limited to 64K bytes maximum Constant and static data are limited to 64K bytes total all of which must be in DGROUP Automatic stack data is limited to 64K bytes total Two or more tasks can execute a single copy of code each task has its own data and stack e Static data may be initialized in declarations VTOS initializes it every time the task runs e PROMable Medium Model Code is almost as small and fast as small model Code size is limited only by PCM RAM or PROM size Constant and static data are
86. TOS asynchronous traps The AST thread of a VTOS task may use almost any VTOS service although it is not safe to call Disable asts from the AST thread in VTOS versions earlier than 3 00 After initialization a VTOS task may spend virtually all its time executing the AST thread The example program above demonstrates how all the real work of an application can be done in AST functions One common programming technique is specifically not recommended for VTOS MS DOS ISRs are often used to set flags or condition codes which then control execution of the main program Under VTOS using ASTs to set condition codes or flags is very inefficient VTOS event flags are the preferred method C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A s Other Considerations When Using Asynchronous Traps The far Keyword In small model the far keyword is required with AST function identifiers It is good practice toinclude far inall models Processing in Both Main and AST Threads Although it is a bad programming practice to use ASTs just to set flags or condition codes for the main thread flags are often necessary to divide a task s processing between both threads This program fragment illustrates a problem which can occur when the AST sets a flag used in the main thread include lt vtos h gt include lt dos h gt word Input_size void far serial input ast ast blk far ast ptr Do something usef
87. Table A 3 Data Conversion Functions iisssssseeeeeeeee ee eee eee A 3 Table A 4 Directory Control Functions A 3 Table A 5 File Handling Functions 2 2 ccc III ee A 3 Table A 6 Low Level Graphics and Character Font Functions A 4 Table A 7 Presentation Graphics Functions A 6 Table A 8 Stream I O Functions A 6 Table A 9 Console and PortI OFunctions A 7 Table A 10 Internationalization Functions A 8 Jable A 11 Math Functions 4 2 cete et dere EE ete done ahora Toe ar tette e A 8 Table A 12 Memory Allocation Functions sssssssssseeels e A 10 Table A 13 Process and Environment Control Functions LL A 11 Table A 14 Search and Sort Functions A 11 Table A 15 String Manipulation Functions A 12 Table A 16 System Calls Sotoren ea ae eee ae ea pallone A 13 Table A 17 Time Functions 2 EEN ia e ei A 14 Table A 18 Variable Length Argument List Functions c cece eee eee eee A 14 Table B 1 PCM Commands beet eere Eee e eee B 3 Table B 2 PCM Command si ee ENN EEN nete ES S DR URN e ean TE B 4 Table D 1 PCM C Directories and Files 0 D 1 xiv CProgrammer s Toolkit for Series 90 DC Ms User s Manual August 1996 GFK 0255 Chapter Introduction The C Programmer s Toolkit for Series 90 PCM the PCM C toolkit contains header files libraries utility programs and documentation required to design and construct C language applications for the Series 90 Pro
88. Task state bx Time slice 7 3 7 4 TASK_ASTC 9 3 p 4 TASKI1 C p 3 TASK2 C 9 3 p 4 tell A 7 tempnam A 7 TERME ES Ez 21 PA Commands Execute a batch file Index 13 Index Index 14 F Show Free memory B 7 G Get hardware ID B 7 H Get PCM firmware revision num ber I Initialize device J Format EEROM device B 10 K Kill a task 7 12 B 10 K Kill task 7T L Load B 5 B 11 M SCH a memory module 7 8 B 12 O Get LED configuration B 12 P Request status data 7 21 B 13 Q Set PE pe level R Run Bib F 5 ST S Save U Recon ouie the PCM B 17 V Verify a file B 17 W Wait X eXterminate file Y Set upper memory limit B 18 Installation Interactive mode 3 6 terminate comm session Terminate task ba TERMSET Test ef 6 3 Test_gef Test_task 5 2 Thread execution AST 5 3 6 15 Main Main thread 6 15 Thread main time A 14 Time slice scheduling Time slice tasks Es Timers VTOS General purpose 6 2 Timers VTOS tmpfile A 7 tmpnam toascii tolower toupper Transfer file Transfer file PC to PCM Transitions Types API PLC 5 17 VTOS 5 11 tzset A 14 U U Reconfigure the PCM TERMF com mand ultoa umask A 3 S A 7 Unblock sem 5 3 5 4 ungetc A 7 ungetch unlink A 3 Unlink sem 5 3 update_plc_status update_plc_status_nowait
89. VTOS Start timer service also permits the calling task to specify local event flag or AST notification Up to 32 timers may be in use simultaneously by all tasks The most common uses of VTOS timers are l Triggering processes which the task must perform on a periodic basis and 2 Timing out I O operations which do not complete so that they can be aborted cleanly This sequence of events occurs when a timer expires L APCM hardware timer asserts a timer interrupt whenever a timer is scheduled to expire 2 The timer interrupt service routine resumes execution of the VTOS real time clock RIC task pre empting whatever task was executing 3 The RIC task determines which timer or timers have expired It sets a local event flag or posts an AST as specified when the timer was started to the task which owns each of the expired timers Depending on whether event flag or AST notification was used the section Local Event Flag Notification or AST Notification and Execution Threads respectively describes what happens next 6 2 C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A s Local Event Flag Notification If an application task uses the EVENT NOTIFY option for a device operation or timer VTOS sets a specified local event flag when the I O completion or timeout event occurs The task can have two or more device operations and or timers in progress at the same time However different event fla
90. XE in EEPROM first rename the PC file MYPROG RAM You could use any file extension other than EXE Then use these PCM commands to save the EXE file to EEPROM More information on the L Load and S Save commands may be found in later sections of this appendix L MYPROG RAM S RAM MYPROG RAM ROM MYPROG EXE The following commands may be placed in a PCMEXEC BAT batch file to load and run the program whenever the PCM is reset or powered on Note that an old copy of the program in RAM if there is one is replaced automatically by the L Load command L ROM MYPROG EXE R MYPROG EXE K Kill a Task GFK 0771A Format K task id This command stops the specified task and frees the resources it was using The task is unlinked from all associated modules all link counts are decremented Timers used by the task are cancelled pending ASTS are discarded pending I O is aborted open files are closed and memory used by the task is returned to the operating system The task ID argument must be in the range of 4 0F hexadecimal If itis not the PCM responds with the error message Cant terminate task Appendix B PCM Commands B 11 L Load Format L options pc filename pcm filename This command directs the PCM to load the file specified by pc filename to pcm filename inthe PCM RAM disk The file names are not case sensitive If the optional pem filename isomitted the PC filename will be used but withou
91. able Controller User s Guide to the Integration of Third Party VME Modules GFK 0448 C Programmer s Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A General VME Information for the PCM When a PCM is the target module for VME functions it should be configured with the Logicmaster 90 configuration software in the same way it would be for non VME functions The PCM should not be configured as a foreign VME module Addresses on the Series 90 70 VMEbus consist of two parts an address modifier AM code and a 24 bit address The AM code consists of 6 bits and is used to select the target Series 90 70 rack and the type of VME access that is the number of address bits used The AM code for a PCM is 39 hexadecimal It specifies the Standard Nonprivileged access type VME bus addresses for PCM modules used as VME function block targets depend on the rack and slot location of the PCM The PCM must be addressed in the range allocated to the rack and slot where itis located Address allocations for PCMs are provided in the following table Table 4 1 GE Fanuc PCM Module Address Allocation SlotNumber Rack da T qp ee Li BALI SE 000000H 020000H 040000H 060000H 080000H 0A0000H 0C0000H 0E0000H to to to to to to to to 07FFFH 027FFFH 047FFFH 067FFFH 087FFFH 0A7FFFH 0C7FFFH 0E7FFFH 100000Hthrough 7FFFFFH user defined for rack 0 only E00000H E20000H E40000H E60000H E80000H EA0000H EC00
92. address of a memory module specified by name mod hdr far p Get mod MODULE1 byte far data ptr byte far p 1 Note that the module name must by specified as upper case characters Get mod returns the address of the mod hdr structure at the start of the module The actual data in the module begins immediately after the module header The data address may be obtained by C pointer arithmetic as shown in the second line of the code fragment above The second mechanism for obtaining a memory module address is the VTOS modc modv mechanism The M option of the PCM R Run command may be used to specify one or more memory modules for a VIOS task These modules are passed as function parameters of main The main function of a VTOS program may be declared like this void main int argc char far far argv int mode mod hdr far far modv where argc and argv are the conventional C parameters for passing command line arguments to the program The parameters modo and modv are unique to VTOS They provide the count of memory modules specified on the command line and an array of their addresses respectively At least one module is passed to every VTOS task the address of the arg_blk structure used to start the task is always in modv 0 When the value of mode is2 or more additional modv elements contain the addresses of memory modules Unlike modv 0 optional modv elements contain the addresses of mod hdr structures The example p
93. afe point address Semaphore count for setting safe point Semaphore count for I O operations Segment of STDIN Device Access Block Segment of STDOUT Device Access Block Segment of STDERR Device Access Block Task environment block address Link field for tasks waiting at semaphore Semaphore address if waiting at semaphore Flag for enabling ASTs VME window selector code VME address modifier code Task ID S Current state 3 Task was never allocated Task ID gt Current state i Task is executing Old state Current stack pointer P 03BA Local event flags which have been set Local event flags where task is waiting Global event flags where task is waiting Other tasks which task is waiting for First AST block for task Last AST block for task Suspend count Task s initial data segment Task s initial stack segment Safe point address Semaphore count for setting safe point Semaphore count for I O operations Segment of STDIN Device Access Block Segment of STDOUT Device Access Block Segment of STDERR Device Access Block Task environment block address i Link field for tasks waiting at semaphore Semaphore address if waiting at semaphore Flag for enabling ASTs A VME window selector code VME address modifier code C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Task ID Current state Old state Current stack pointer Local event flags which have been set Local event flags where task is
94. age and exits immediately If TASK1 was compiled with DEBUG defined main opens the debug device and writes a debug message announcing its task name task number and the shared module data address Next main links to the SEM NAME semaphore When it has acquired the semaphore main initializes its own AST function address and task number variables in the shared module clears the port allocation flag and releases the semaphore Chapter 9 Example Programs 9 3 9 4 After waiting for one second to give the PCM and PLC CPU time to begin communication main opens two I O channels on the CPU device one for reading PLC register data starting at R00050 and the other for writing register data starting at R00060 If VTOS is unable to open either of these channels main exits immediately Finally main posts an AST to itself to start the periodic reading of PLC register values Then it enters a non terminating loop to wait for ASTs In the loop timer ASTs and ASTs posted by TASK 2 are processed in the order in which the events occur TASK2 TASK2is similar to TASK1 Itssourceis PCMC EXAMPLES DEMO_3T ASK2 C TASK2 receives COMMREO messages from the PLC CPU When a COMMREQ arrives it is processed by the function commreq ast which sends one data word from the COMMREO to TASKI by posting an AST The AST includes the COMMREO data It is posted using the AST address and task ID information that TASK1 previously stored in the shared memory m
95. ahead buffer I CPU 45 PASSWD I CPU 5 MYPASWD N I CPU 5 Y The third example sets the PCM privilege to the access level protected by the password PASSWD The fourth example sets the PCM privilege to the access level protected by MYPASWD and also disables PCM clock synchronization The last example re enables PCM clock synchronization but has no effect on PLC access level C Programmer s Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A J Format EEROM Device Format J ROM The Format command causes an electrically erasable ROM EEROM device installed in a PCM 301 to be erased and formatted as the file device ROM Once the EEROM has been formatted files can be loaded to it and MegaBasic programs stored to it just as they are in RAM Note that files may be copied to the ROM device only from the PCM RAM disk Only the PCM 301 GE Fanuc catalog number IC693PCM301 supports an optional EEROM device Attempting to format an invalid device produces this message Unknown device name C language executable EXE files may not be executed from EEPROM They may however be stored as relocatable files in EEPROM and then loaded to RAM for execution Since EEPROM files must be copied from RAM the PCM must be tricked into loading EXE files to RAM inrelocatable form The trick requires renaming the executable file in the PC so that it no longer has the EXE extension For example to save MYPROG E
96. alarm message must be sent to a supervisory computer within a given time after the condition occurs Assume further that a transition contact in the PLC CPU has been assigned to represent the specified condition When the contact closes the PLC ladder program sends a COMMREO message to the PCM A PCM application task is required to detect the COMMREQ and send the alarm message from PCM serial port 2 C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A GFK 0771A s Here is a short example program showing how this requirement could be met using WAIT mode event processing ALARM C include vtos h include cpu data bs void send serial alarm word handle void respond to comreq word handle byte comreq buf COMREQ MSG SIZE void main void word serial_hndl comreq_hndl task_id task_id Get_task_id serial hndl Open dev COM2 WRITE MODE WAIT task id comreq hndl Open_dev CPU 6 WRITE MODE WAIT task id for if Read dev comreq hndl comreq buf COMREQ MSG SIZE WAIT task id COMREQ MSG SIZE send serial alarm serial hndl respond to comreq comreq hndl The program in this example ALARM C opens two I O channels and then enters a non ter minating loop One of the channels receives the COMMREO from the PLC CPU the other sends the alarm message to the supervisor Note that the COMMREO channel is opened on device CPU 6 The PLC COMMRE
97. and interpreter will ask TERME to look in the current PC directory If the file is found there it will be loaded and then run Debugging a PCM Task GFK 0771A PCM firmware version 3 00 does not include a runtime debugger The best debug method currently available is to use printf statements to trace program execution and display program data Applications which use both PCM serial ports for communication can log execution trace data to a PCM file or named memory module Series 90 70 PCM applications can log trace data to a reserved memory block in VME dual port memory A second PCM can be used to read the data in VME master mode When an application task locks up the PCM task state dump facility can be used to diagnose the cause For more information on this topic see Dumping PCM task state information in chapter 7 Multitasking Some developers of PCM C applications use hardware debuggers See Debugging Multiple Tasks in chapter 7 Multitasking for more information on hardware debuggers Chapter 3 Creating and Running PCM C Programs 3 7 Using Makefiles 3 6 Building PCM EXE files from two or more C sources and building multitasking applications with two or more EXE files is handled most efficiently by using either the NMAKE or NMK utility provided with Microsoft C NMK is provided with Microsoft C 6 0 but not with Microsoft C C 7 0 Some restrictions apply to NMK See the Microsoft documentation for information on usin
98. askable hardware interrupts respectively in 80x86 family microprocessors The callto disable prevents the serial port 1 hardware interrupt from being serviced until interrupts are enabled again If the Wait ast callis made VTOS enables interrupts for itself as soon as the calling task is blocked When the call is not made enable will do the job Note that when Wait ast iscalled interrupts are still disabled for the calling task after it returns The enable callis required whether or not Wait ast iscalled 6 16 C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Chapter Multitasking Multitasking is a technique for creating the illusion that two or more programs or tasks are running in the same processor at the same time Actually the processor executes just one task at a time while the others wait their turn VTOS provides facilities for multitasking two or more application tasks in PCMs This chapter describes multitasking the reasons for using it and special considerations which arise when multiple application tasks are running Why Use Multitasking Multitasking offers a number of benefits 1 The requirements for an application may contain subsets which are functionally unrelated to each other Multitasking can provide a clean separation between unrelated requirements The first example program of chapter 6 illustrates such a task 2 Multitasking can permit small model code exceedin
99. at Q file name This command executes the PCM batch file ile name No intervening space is permitted between the command and the file name These examples show how the command is used The file extension is optional in the last example MYFILE BAT is executed If no device is specified as in the first and last examples RAM is assumed GMY BAT PC A MYDIR MY BAT QMYFILE These errors can be returned File not found file name Illegal module type file name See appendix C Batch Files for more information on PCM batch files B 4 C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A B Configure LEDs GFK 0771A Format B led number led use code lt task_number gt This command configures either of the bottom two PCM LEDs USER1 and USER2 The LED number can be either of the ASCII characters 1 or 2 The LED use code is a two digit ASCII hexadecimal code that specifies a configuration byte for the LED Binary values for the LED use code are as follows Bit 7654 3 210 Value Serial port 1 transmit Serial port 1 receive Serial port 2 transmit Serial port 2 receive Backplane transmit Backplane receive Must be zero Combine the bits for the desired LED action into a single byte value in hexadecimal format For example to blink LED USER1 when characters are transmitted or received on serial port 2 use binary code 00001100 This is equivalent to OC hexadec
100. ata are far by default The far data accesses and pointers require extra code and time to load microprocessor segment registers Consequently large model has the largest code size and slowest execution of any memory model supported by PCMs Small and Medium Model Differences Between VTOS and MS DOS 8 2 Unlike MS DOS VTOS assigns different data and stack segments to small and medium model tasks One benefit is that tasks using these models can have up to 64K bytes of static data plus 64K bytes of automatic stack data However there is a cost to PCM C programmers 1 Pointers to data must be declared far if they will ever contain the address of an automatic stack based variable or any other address outside the task s data segment when passed as a function parameter The safest practice is to declare all pointers to data as far pointers For example TEST1 C include lt vtos h gt include lt string h gt include lt stdio h gt void main void char text PCM C char far p MUST be far for p text p M p DH printf d n strlen p In this example the pointer p is assigned the address of an automatic array text in the for loop initializer The address in p is modified and then passed to the standard C library function strlen Note that Microsoft C 6 0 produces a warning message when it uses the address of a stack based variable in line 8 of this example where t
101. backplane device CPU It can communicate with any character mode device Accessing PLC Data From PCM Programs Data from the PLC CPU is almost always an important part of PCM applications There are four ways PCM programs can access PLC data 1 The VTOS Open dev Read dev Write dev and Close dev services 2 PLCAPIservices 3 COMMREQ messages from PLC programs and 4 Series 90 70 VME function blocks PCM applications can use any or all of these methods except that VME function blocks are available only in Series 90 70 PCMs The following sections provide an overview of each of these methods VTOS CPU Device Services The built in VTOS device driver for the PC device supports I O operations between PCM applications and PLC data PCM applications can open I O channels to all PLC global data references Each channel must be opened by calling the Open dev function and specifying a device name of the form CPU lt r ef letter where lt r ef letter isa single letter that specifies a PLC memory reference type PLC API Services Series 90 PLCs provide a rich set of services which are accessible from PCMs The PLC service request Application Program Interface API library provides convenient function calls to Open a PLC API session with the PLC CPU Determine PLC operational status Determine the PLC CPU hardware type and data sizes Obtain the PLC user program and configuration data checksums Read the I O and PIC
102. bytes 64 Kbytes 64 Kbytes Medium 128 Kbytes 64 Kbytes 64 Kbytes Large NotSupported NotSupported NotSupported Code size is limited only by available ROM In addition the MegaBasic programming environment and CCM communication protocol are not available in a PCM with a custom application in ROM Building ROM Applications These steps are required to develop ROM based PCM applications 1 Oneor more application tasks must be designed coded tested and debugged During this phase the application code is loaded to PCM RAM and executed there See chapter 3 Creating and Running PCM C Programs for a description of this process 2 When development is complete the BLD PROM utility is used to package all the application tasks plus a PCMEXEC BAT file to run them when the host PCM powers up or is reset BLD PROM produces a ROM image file which contains all the data to be programmed in the ROM Chapter 11 Utilities describes the BLD PROM utility and the process of creating a ROM image 3 The ROM image file is used to program an erasable programmable read only memory EPROM part The table below shows EPROM device part numbers and locations for the PCM 711 and PCM 300 models Table 10 2 ROM Device Part Numbers and Locations PCM Model EPROM Part Number EPROM Location PCM711 27C1024 155 U59 PCM 300 27C010 205 U35 Higher speed parts may be substituted 4 The standard PCM EPROM in the location spe
103. cessor This task continues to execute until it voluntarily gives up control or a higher priority task becomes ready to run A task gives up control unconditionally when it performs WAIT mode I O or calls one of the VTOS functions Wait ast Wait ef Wait gef Wait time or Wait task Inaddition an executing task gives up control when it calls Suspend task and passes its own task number or when it calls Link sem or Block sem and the semaphore is busy By default the PCM R Run command executes VTOS tasks using priority based scheduling Time Slice Tasks Time slice task scheduling is a bit more complex Basically two or more tasks must be explicitly started as time slice tasks by using the E2 or T option or both of the PCM R Run command Each time slice task will execute for the number of milliseconds specified with the T option or for the default 10 millisecond time slice if the E2 option is used alone At the end of its time slice the task is suspended and control is passed to the next time slice task in the sequence When all the time slice tasks have executed once the first one is resumed again and executes for its allotted time slice Time slice tasks execute in ascending order of their task numbers regardless of the order in which they were started The program SLICE C shown below can be used to experiment with time slice tasks It simply prints its task number and then wastes time in a counting loop This process is
104. ch COMMREO messages arrive VTOS has a queue for messages which arrive from the PLC CPU When a COMMREQ message arrives it is stored in this queue until the PCM application makes a Read dev function call to get it When COMMREQs arrive more rapidly than Read dev calls are made the queue eventually overflows When overflow occurs no more COMMREO messages can be received until a message slot in the queue is freed by a Read dev call Until then new messages are lost The PCM posts a fault to the PLC fault table whenever a message is lost Queue overflow can be avoided by designing the PLC program so that no more than two COMMREO messages are outstanding to each PCM in the PLC at any time The PLCprogramsinfolders PCMC EXAMPLES DEMO_3T PLC_3 nd PCMC EXMPLES DEMO_3T PLC_70 also contain logic which waits for the target PCM to acknowledge each COMMREO before the next one is sent GFK 0771A Chapter 4 Using PCM Resources 4 11 Using Series 90 70 VME Function Blocks Series 90 70 PLC ladder programs can also communicate with the PCM using the VME Read VMERD and VME Write VMEWRT functions These functions are not available for Series 90 30 PLCs VMERD VMEWRT and other associated functions treat the PCM as a standard VMEbus module Data is moved to and from the PCM s VMEbus dual port RAM VME functions usually execute faster than the equivalent COMMREO for the same data transfer These functions can also be useful in situations when the PLC Sy
105. cified above is removed and replaced by the EPROM containing your ROM based application Note EPROM programming hardware is not available from GE Fanuc Automation However a number of suitable models are offered by several manufacturers 10 2 C Programmer s Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Chapter 11 Utitlies This chapter describes the utility programs provided with the PCM C toolkit STKMOD Program GFK 0771A STKMOD EXE is a utility program used to assign a stack size to PCM executable EXE files Its command line format is gt stkmod options Enter where options includes one or more of h h s stack size in bytes s stack size in bytes exe file name The stack size in bytes isadecimal number specifying the new stack size value and exe file name is the name of the PCM EXE file to be modified with or without the EXE file extension and dot character Options may appear in any order and the case of alphabetic characters in the options is ignored Invoking STKMOD EXE with no options or with any ofthe h or h options causes STKMOD to print its help text stkmod GE Fanuc Automation PCM EXE File Stack Size Utility Version 1 00 Copyright c 1992 GE Fanuc Automation North America Inc All rights reserved usage stkmod h stkmod exefile s stack bytes gt where stack bytes is a decimal number in 1024 65520
106. code void process command byte far cmd ptr void display dead plc alarm word handle word format display data char far formatted data word far binary data word num registers void far COMREQ ACK COMPLETE STATE ast ast blk far ast ptr The Write dev to acknowledge the COMREQ completed if ast ptr handle CMRQ ACK HNDL amp amp ast ptr argl SUCCESS Cancel timer Cmrq ack timeout else recover from error CMRO ACK HNDL ast ptr arg2 Chapter 6 PCM Real Time Programming 6 11 void far ABORT COMREQ ACK STATE ast ast blk far ast ptr The Write dev to acknowledge the COMREQ timed out Abort dev Cmrq ack hndl ABORT ALL 0 display dead plc alarm Oit hndl void far DISPLAY ACK COMPLETE STATE ast ast blk far ast ptr The Write_dev to display PLC register data on the OIT completed Cancel_timer Display ack timeout void far ABORT DISPLAY DATA STATE ast ast blk far ast ptr The Write_dev to display PLC register data on the OIT timed out Abort dev Oit hndl ABORT ALL 0 void far SEND DISPLAY DATA STATE ast ast blk far ast ptr A COMREQ was received word display size cmrq data size send count status STAT VALUE Do an AST NOTIFY read for the next COMREQ Read dev Cmrq hndl amp Cmrq msg CMRQ MSG SIZE AST NOTIFY Task id SEND DISPLAY DATA STATE ast CMRQ READ HNDL Get the COMREQ
107. cs and character font A 4 Math Memory allocation Presentation graphics Process and environment control Search and sort StreamI O A 6 String manipulation A 12 System calls A 13 Time A 14 Variable length argument list A 14 Start_com_ timer start plc start plc noio start plc noio nowait GFK 0771 GFK 0771 start plc nowait Start timer 5 5 6 2 7 15 Startup stat A 3 State Machine 1 1 Transition 6 9 6 9 6 10 State machines 1 2 STKMOD EXE B 3 7 4 stop plc stop plc nowait strcat A 12 strchr stremp A 12 strcoll A 8 strcpy strcspn A 12 strdup A 12 strerror strftime A 8 stricmp A 12 strlen B3 strlwr strncat A 12 strnemp A 12 strncpy strnicmp A 12 strnset A 12 strpbrk A 12 strrchr strrev strset A 12 strspn A 12 strstr strtod strtok strtol A 3 strtoul A 3 strupr Index strxfrm A 8 Support for Microsoft A 1 Suspend task 5 1 6 2 ba swab A 2 SWAPBAT SWAPC system A 11 T T C 40 T2 C 710 tan tanh tanhl A 9 tanl Task a functions Task PCM 7 1 ey ae serial ports Debugging B 7 Inter task communication Using ASTs Using event flags Using semaphores RER memory modules 7 8 9 5 Interaction of priority and time slice tasks 7 4 Rules 7 Notification Number Pre emption Priorities Priority Running 3 7 Scheduling Startup 7 2 State dump
108. ction These items are passed in a shared memory module MODULE2 The mod data structure in AST H specifies the data in the module AST H define READY 1 GEF EF 00 define READY 2 GEF EF 01 define MOD NAME MODULE2 typedef struct word taskl num word task2 num void far tmr ast func void far post ast func mod data AST1 C contains an AST function ast func which simply prints the task name and the values of the ast b1lk members which its parameter points to The main C Programmer s Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A GFK 0771A function also prints the task name In addition main resets the global event flags READY 1 GEFand READY 2 GEE and then waits for AST2 to set READY 2 GEE After READY 2 GEF is set signalling that AST2 has completed its part of the shared module initialization AST1 initializes its data in the module starts a timer prints the timer handle and then waits for an AST After the AST is processed AST1 exits from main The Start timer call from AST1 specifies that AST2 should be notified with an AST when the timer expires The task2 num and tmr ast func members from the shared module data are used to specify the task and AST function respectively AST1 uses its own task number as the handle value which will be passed to the AST function AST1 C include vtos h include lt stdio h gt include ast bn mod_data far p mod_hdr
109. d processors embed control characters in the text or set the high order bit of text characters If you use one of these programs the Microsoft compiler will complain about invalid characters A text editor called EDITCOM is provided with Microsoft MS DOS Version 5 00 It works reasonably well The source file for the demonstration is PCMC EXAMPLES HELLCC which was copied to your hard disk during the PCM C toolkit installation Open it with your text editor it should look like this HELLO C PCM C demonstration program include lt vtos h gt include lt stdio h gt void main word task rev task Get task id rev Get pcm rev printf Hello world n printf I m running as task 02x hex under VTOS version x 02x n task rev 8 rev amp Oxff If you prefer you can type it into your editor The program prints its greeting and some information about where it is running It calls three library functions Get task id and Get pcm rev from the PCM libraries and the standard library function printf GFK 0771A 3 1 Compiling Sources 3 2 An MS DOS batch file CC BAT is provided for compiling single source files Using it is the most convenient way to compile one or two sources The command line for using it is simply cc memory model file name gt where memory model specifies the memory model you want to use and file name gt is the name of your
110. d then enters a non ter minating loop to wait for COMMREQs If a COMMREO and its data are read successfully commreq data size contains the number of data words and commreq data ptr contains the address of an array of words containing the data If an error occurred comnreq data size contains zero GFK 0771A Chapter 4 Using PCM Resources 4 9 Note that there are two formats for COMMREQ messages depending on whether the data size is 6 or fewer words the short format or more than 6 words the long format Accordingly PCMC INCLUDE CPU_IATA H contains a C union type definition comreq msg for COMMREQs Both formats begin with a 16 byte header structure The header contains a msg type member which can be tested to determine the format of each COMMREO message COMMREO messages with the 0x40 bit set contain 6 or fewer data words If the bit is not set the COMMREO has a separate data buffer and a second Read dev callis used to get the data Note also that the COMMREO message does not specify the data size when there are six or fewer data words If the data size can vary and must be known the data should specify its own size with a value in the first data word Responding to COMMREQs 4 10 The next program fragment illustrates the preferred method for returning a COMMREQ acknowledgement to the PLC CPU The status pointer type and offset values specified in the COMMREO command block are included in the COMMREO message This example shows how to
111. data is needed in the PLC ladder program The format of the VMERD function block is enable function OK logic address modifier module address ADR Q destination for VME data Parameter Description Enable Power flow input that when TRUE enables the execution of the function Type Function type either BYTE or WORD to select the corresponding type of VME bus access to be performed WORD accesses transfer 16 bits of data on each VMEbus cycle while BYTE accesses transfer just 8 data bits per buscycle LEN Aninternal parameter that depending on the function type specifies the number of bytes or words to be transferred AddressModifier A hexadecimal word value that specifies both the rack where the target PCM is installed and the VMEbus access mode to be performed Module Address A double word specifying the hexadecimal address where the first word or byte is read from the VME bus It may be a constant or the reference address of the first least significant word of two words containing the module address The address is based on the rack and slot where the PCM is located Refer to Address Allocation by Rack and Slot in this section OK Power flow output that is TRUE when the function is enabled and completessuccessfully Specifies the first PLC user reference location into which the data read from the PCM is to be stored GFK 0771A Chapter 4 Usin
112. date the file directory with the correct file size One result is that data may be lost when an application hangs Under MS DOS for example recovering from a hung application often requires a warm boot Ctrl Alt Delete reset If the application opened a new output file but did not close it before hanging the file size will be zero 0 after the warm boot VTOS files are not buffered Because read and write operations are performed directly on RAM or ROM buffering would actually make them slower Each write operation at the end of a file adds the new data and updates the file size If the application should hang all the data it wrote will be in the file 4 2 C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A The PCM Command Interpreter The user interface to the PCM is a command interpreter which is conceptually similar to the MS DOS command line interpreter or the Unix shell The PCM command interpreter allows the user to download application programs and run them and provides many other commands which are listed in appendix B PCM Commands The interpreter also supports batch files which are described in appendix C Batch Files A special startup batch file named PCMEXEC BAT can be used to run applications automatically on power up or reset By default the command interpreter uses PCM serial port 1 COM1 as its input and output device However it can be redirected to serial port 2 COM2 or the PLC
113. de to start and end a critical section in which PCM reset or power fail processing will not occur Critical sections are typically used for linked list maintenance within PCM RAM modules or disk files Because power fail processing needs to be completed quickly these macros save a little time by generating inline assembly language instructions rather than using function calls Note The total processing time between BEGIN CRIT SECT and END CRIT SECT must be limited to 1 millisecond or less Do not make any VTOS function calls inside a critical section All accesses to data should be made through far pointers Table 5 13 VTOS Macros Type Name Purpose BEGIN CRIT SECT Beginsa critical section which will not be interrupted by power fail or reset button events END CRIT SECT Endsacriticalsection allowing power fail and reset processing to occur C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A VTOS Types GFK 0771A These data types are defined in VTOS H Table 5 14 VTOS Types in VTOS H Type Name Purpose arg blk Passesinformation between the PCM device manager and device drivers ast blk Accesses arguments passed to an asynchronous trap AST handler function code hdr Specifiesadditionalinformation for executablememory modules dcb blk Controls data flow between the VTOS device manager and device drivers Each device has a unique device control block
114. dos A 13 intdosx A 13 Ern of priority and time slice tasks 7 4 Interrupt service routine ISR 6 2 614 Ioctl dev B 7 isalnum A2 isalpha A 2 isascii A 2 isatty A 3 iscntrl A 2 isdigit A 2 Iset_ef 5 Iset gef isgraph A 2 islower isprint A 2 ispunct A 2 isspace A 2 isupper GFK 0771 isxdigit A J J J Format EEROM device TERMF com mand K Kill a task TERMF command kbhit A 7 L L Load TERMF command labs Idexp A 8 Idexpl A 9 div Ifind A 11 LIB environment variable 2 4 Libraries API PLC Function categories Controlling PLC operation 5 15 Open and close a PLC API session PLC hardware type configuration and status PLC program and configuration checksums 5 14 Reading mixed PLC data refer ences Reading PLC data references 5 14 Reading Series 90 70 PLC data ref erences 5 14 Reading clearing PLC and I O faults 5 16 Reading setting PLC time of day clock 5 17 Writing PLC data references 5 15 Writing Series 90 70 PLC data refer ences 5 15 Services Standard C libraries Installing Restrictions Using in PCM programs Index VTOS Function categories 5 1 Asynchronous trap 5 3 Communication timer Device driver support Devicel O 5 7 Event flag 5 2 Memory management 5 6 Memory module Miscellaneous Semaphore Task management Time of day clock Timer Limitations PCM hardware 1 2 Lin
115. e bios keybrd dos settime bios memsize dos setvect bios printer dos write bios serialcom ellipse A 4 bios timeofday A 13 _ellipse_w _bmalloc A 10 _ellipse_wxy _bmsize _enable 4 23 6 16 _brealloc A 10 _endthread A 11 _c_exit _exit _cexit A 11 _fcalloc _chain_intr _fexpand A 10 _chdrive A 3 _ffree A 10 _clear87 A 9 _fheapchk A 10 clearscreen _fheapmin _control87 _fheapset _disable 4 23 6 16 A 13 _fheapwalk A 10 displaycursor floodfill A 4 dos allocmem floodfill w GFK 0771 dereen Index _fmalloc A 10 _getbkcolor _fmemccpy _getcolor _fmemchr _getcurrentposition _fmemcmp _getcurrentposition_w _fmemcpy _getdewd _fmemicmp A 2 _getdrive _fmemmove A 2 _getfillmask A 4 _fmemset _getfontinfo _fmsize A 10 _getgtextextent _fpreset _getgtextvector A 4 _frealloc A 10 _getimage A 4 _freect A 10 getimage w _fsopen _getimage_wxy _fstreat getlinestyle A 4 _fstrchr _getphyscoord A 4 fstremp A 12 Spas _fstrcpy A 12 getpixel_w _fstrespn A 12 gettextcolor c fstr dup A 1 _gettextcursor _gettextposition A 4 _fstricmp A 12 gettextwindow A 4 _fstrlen _getvideoconfig _fstrlwr getviewcoord A 4 _fstrncat _getviewcoord_w fstrmcmp A 12 _getviewcoord_wxy _fstrncpy A 12 _getvisualpage A 4 _fstrnicmp A 12 _getwindowcoord A 4 _fstrnset A 12 _getwritemode _fstrpbrk A 12 _grstatus
116. e categories 1 The function is supported without restriction in all the Intel memory models supported by the PCM Note that Microsoft code will not always be used for these functions In some cases a C preprocessor macro defined in a PCM header file will substitute a different function call In other cases code provided with the PCM C toolkit will replace code in the Microsoft library These substitutions occur as a result of the order in which libraries are specified to the Microsoft linker The function may be used without restrictions in large model applications but restrictions apply in small and medium models In many cases functions which take pointers as parameters are restricted in small and medium models to DS based addresses addresses of global or static variables for these parameters This isa result of VI OS having separate data and stack segments even in the small and medium models In other cases functions may be used only in large model The function is not supported in any memory model because of a major difference between the VTOS and MS DOS operating systems or between PCM and PC hardware Caution There is no enforcement of these restrictions The user is responsible for avoiding the use of unsupported functions and for the correct use of conditionally supported functions Errors will occur when unsupported functions are used or conditionally supported functions are used incorrectly The consequences range fr
117. e A 17 Time Functions Function Memory Model asctime clock ctime difftime ftime gmtime localtime mktime _strdate strftime _strtime time tzset utime These functions are not supported in any memory model Table A 18 Variable Length Argument List Functions Function Memory Model va_arg va_end va_start the header file stdarg h These functions are supported in all memory models They are defined in C Programmer s Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Appendix PCM Commands b The PCM includes a command interpreter which is similar in principle to the MS DOS command line interpreter or the UNIX shell PCM commands provide complete control for loading and storing applications and for executing them Accessing the Command Interpreter The PCM command interpreter is connected by default to PCM serial port 1 whenever the PCM is not configured by Logicmaster 90 software in CCM ONLY mode and is not executing an application program The following discussion assumes that you are trying to access the command interpreter through serial port 1 using the TERMF terminal emulation program TERME is described fully in chapter 2 section 3 of Series 90 Programmable Coprocessor Module and Support Software User s Manual GFK 0255D or later When a PCM is configured in PCM CFG mode using Logicmaster 90 software and there are no files stored in it the command
118. e State Name 0 Task was never allocated This task ID has never been assigned to a task since the most recent PCM reset Note that task number zero should never be in this state Task was terminated This task ID was assigned to a task after the most recent PCM reset but the task has terminated 1 Task is executing If this task has the lowest ID value of all the tasks which have the current state value one and is not suspended it was executing when the reset occurred The code which was executing was mainline code thatis called directly or indirectly from the task s main function rather than an AST function Taskis ready If this task is not suspended and another task has a smaller Task ID value and also has the current state value one 1 this task was ready to execute when the reset occurred but its priority was not high enough to gain control of the PCM processor Taskis suspended If the Suspend count value for this task is non zero the task was suspended when the reset occurred 2 Executing an asynch trap This task was executing an AST function when the reset occurred Waiting for an asynch trap This task had called Wait ast and was still waiting 4 Waiting forI Ocompletion This task was waiting fora WAIT modeI Ooperationto complete when the reset occurred 5 Waiting for local event flag This task was waiting for a local event flag to be set by another task when the reset occurred 6 Waiting for global event flag The tas
119. e e dua B 5 C Clear the PCM ie o ute Rh exte B 6 D file Directory i lira de duce v e ds B 6 F Show Free Memory Li B 7 G Get Hardware ID B 7 H Get PCM Firmware Revision Number B 7 I Initialize Device LL B 8 J Format EEROM Device LL B 11 EAEE EE EE B 11 ExXL90ad doti El ih allatta dalai B 12 M Create a Memory Module cece eee eee B 13 O Get LED Configuration LLLL eh B 13 P Request Status Data eee eee B 14 Q Set Protection Level sseeeeeeeeeee ee B 15 R R n tee hid he ee et etd De e ee herd beet REDE ed DR B 15 SASAVO wiiereiib amp effe Rer pierde ld eel db Sew eo d eid B 17 U Reconfigure the PCM LL B 18 MiVetity EE B 18 NA EE BEE B 18 X eXterminate file B 19 Y Set Upper Memory Limit B 19 Appendix C Batch Files ii C 1 Overview ove et ete tw e b e e eta ie a p ig C 1 Creating Batch Files eege Re Be nal REFUSES EE ET C 1 Running Batch Files ria C2 PEMEXEC BAT Files orrore site MADRE e PURIS C2 HARDEXEC BATFiles C 3 User Installed PCMEXEC BAT and HARDEXEC BAT Files C 3 AppendixD PCM C Directories and Files D 1 GFK 0771A CProgrammer s Toolkit for Series 90 DC Ms User s Manual August 1996 xi Contents Figure 6 1 State Transition Diagram Of AST Based Example 6 10 TAS OT uum re te EE Ae a tae eMe ed M Po tette A V acte eed A Pateat 9 8 Listing 9 1 Continued Ae e ER RI ee E
120. e eee ate 9 9 listing 9 1 Continued teen pes eer had whan deg 9 10 Listing 9 1 Combined DEE E 9 11 Listing 9 1 Concluded 5 x eege ee che iis wands PE Se pub es WN Ne 9 12 xii C Programmer s Toolkit for Series 90 PCMs User s Manual August1996 GFK 0255 Contents Table 4 1 GE Fanuc PCM Module Address Allocation 4 13 Table 5 1 Task Management Functions 5 1 Table 5 2 Event Flag Functions radona aea usep aa b aE eee ee 5 2 Table 5 3 Asynchronous Trap Functions 5 3 Table 5 4 Semaphore Functions y nhie auie ea d paa E ER EE rE a E E R E E E a 5 3 Table 5 5 Time of Day Clock Functions 5 4 Table 5 6 Timer Functions ee ee x erre ua EN esta e a e RE dere 5 5 Table 5 7 Communication Timer Functions 5 5 Table 5 8 Memory Management Functions 5 6 Table 5 9 Memory Module Functions 5 7 Table 5 10 Device I O PBunchonsg eR Re res 5 7 Table 5 11 Device Driver Support Functions 5 9 Table 5 12 Miscellaneous Functions LL 5 10 Table 5 18 RENE EE 5 10 Table 5 14 VTOS Types VIOS H rd ker ke epa ANEN RI prn e 5 11 Table 5 15 VFOS Typesatn C FU DATAH siriaca PC AO Ea doe Cor dde de eas den 5 12 Table 5 16 VTOS Global Data 22 ENTENTE EN e rn ere he a pe EN EE 5 13 Table 5 17 Open and Close a PLC API Session 5 13 Table 5 18 PLC Hardware Type Configuration and Status Information 5 14 Table 5 19 PLC Program and Configuration Checksum Data LL 5 14 Table 5 20 Reading P
121. e from text of chapter 7 MODULE H C header file from text of chapter 7 MODVC C source file from text of chapter 7 OIT DRVR C C source from text of chapter 6 RUNHELLOBAT PCM batch file for running HELLO EXE SEM BAT PCM batch file from text of chapter 7 SEM H C header file from text of chapter 7 SEMI C C source file from text of chapter 7 SEM2 C C source file from text of chapter 7 SLICE BAT PCM batch file from text of chapter 7 SLICE C C source file from text of chapter 7 SWAPBAT PCM batch file from text of chapter 7 SWAPC C source file from text of chapter 7 T1 C C source file from text of chapter 7 T2 C C source file from text of chapter 7 TEST1 C C source from text of chapter 8 TEST2 C C source from text of chapter 8 PCMC EXMPLES AAREADME NDEMO 3T DATA C DEMO 3TBAT LOAD BAT MEMMODUL H Mk DEMO3 MK_DEMO3 600 MK_DEMO3 700 MK_DEMO3 MVC PLC 30 PRT PLC 70 PRT TASK1 C TASK2 C TASK_ASTC PCMC EXMPLES CPUCFG CFG DEMO_3T PLC_30 IOCFG CFG LMFOLDER 30 _MAIN DEC _MAIN EXP _MAIN LH1 _MAIN PRG _MAIN SYM D 2 C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Directory File Purpose PCMC EXMPLES LMFOLDER 70 DEMO_3T PLC_70 MAIN DAT _MAIN DEC _MAIN EXP _MAIN LH1 _MAIN PRG _MAIN SYM PCMC INCIDE APITYPES H Data types used by PLC servicerequest API CHKSUM H PLC API services for checking program and config integrity CHKSUMNWH NOWAIT versions of CHK
122. e ke ke Initialize the command and data blocks for COMMREQs sent to the DATA zi task The status location is type 8 offset 18 R0019 ce ke e e ce he e e ce ee he ce ce he ee ce che e e ce ce e he ce ce che e e ce ee e ce ce che e ce ce hee e ce ce e he ce ce che e ce ce ce e ce ce ce ke e ce ce ce e e c ck kv ke x x lt lt RUNG 9 gt gt INT I I CONST IN1 0 R00001 CONST IN1 0 R00008 00003 I 00003 I I I I I CONST IN2 CONST IN2 l 00000 00100 I I I I CONST IN3 l CONST IN3 l 00008 00000 I I I I CONST IN4 l CONST IN4 00018 00000 I I I I CONST IN5 00000 I I I I CONST IN6 I 00000 I I I I CONST IN7 l CONST IN5 00000 I CONST IN6 00000 CONST IN7 00001 00000 lt lt RUNG 10 gt gt ATV_CRD COMMENT kc KKK KKK hehe e e e e ke ke ke e kk e e hh he he he e e e e ke kk e He e He He e hehe he e e e e e e He ke e e e He e ke ke ke ke ke ke ke ke ke ke e e ee This discrete logic detects an activation contact for sending COMMREQ to the DATA task and remembers it until the next COMMREQ is sent Toggling MO001 sets M0003 which remains set until the COMMREQ is sent The on transition coil M0002 assures that M0003 is set only on the sweep when M0001 is toggled on PE E e e e e e He e e e e He e e He e II ICI ICICI ICICI ICICI He e e He e He ICICI II IK KICK l
123. e that starts MegaBasic First create a PC file called TEST BAT which contains the single line R BASIC EXE After saving the file invoke TERMF on your PC and then enter the PCM command interpreter interactive mode as described in appendix A of this document Load the batch file to the PCM by typing L TEST BAT followed by the Enter key Do not attempt to load batch files to the PCM using the MegaBasic LOAD command The MegaBasic LOAD command converts files to MegaBasic program format which is not understood by the PCM command interpreter Using the MegaBasic LOAD command for batch files will prevent them from executing as expected An alternative method of creating batch files directly in the PCM is to use MegaBasic The following sequence of commands may be entered at the Ready prompt to create our example TEST BAT in the PCM RAM disk and then exit from MegaBasic ram test bat R BASIC EXE Running Batch Files To run the batch file created by either method of the previous section type TEST and press the Enter key You should see the command in TEST BAT followed by the MegaBasic startup banner indicating that the command interpreter executed the command to run MegaBasic If youtype BYE again you should once again be communicating with the command interpreter in interactive mode Verify this by pressing the Enter key note that the gt prompt appears on a new line PCMEXEC BAT Files C 2 When the PCM power
124. e the IP register value from the task s stack dump to the offsets in Publics by Value The function which was executing or interrupted will have the largest offset value which is smaller than IP If the PCM application uses more than one PCM task the Task ID value for each EXE file is determined by the R Run commands in PCMEXEC BAT which are used to start them See the R Run command in appendix B of this manual for details The situation is more complex for medium and large model tasks because there is more than one code segment The code segment CS register value from a PCM stack dump must be used to identify the code segment which was executing when the reset occurred The PCM directory command D provides an entry point address for all executable PCM modules This address is the PCM memory location of the public symbol astart in the MAP file The segment value of the entry point address is used to calculate the code segment value in the MAP from the corresponding CS register value in a PCM stack dump For any code segment Map code segment value CS entry point segment value __astart segment value from MAP file For example the stack dump of task E hexadecimal in the previous section shows that it was executing in code segment OA4F hexadecimal when the reset occurred If the PCM directory command shows 0837 00A0 as the entry point address for this task and the MAP file gives 0000 00A0 for the location of __astart then the MAP
125. econd task must be prevented from displaying a message until the first task has received all its input data This function demonstrates the preferred technique for controlling access to VTOS services A named semaphore controls access to a locking flag and the flag controls access to the port C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A An application task should never call a VTOS service function while the task has control of a named semaphore Deadlocks between tasks may result Semaphore deadlocks occur in this way Suppose task A controls semaphore X and task B controls semaphore Y at the same time Now suppose that task A is executing and needs to acquire semaphore Y before it can release semaphore X When task A calls Block sem to acquire semaphore Y VTOS will prevent task A from executing again until task B releases it Suppose further that task B needs to acquire semaphore X before it can release semaphore Y When task B calls Block sem it will also be prevented from executing The process is deadlocked because each task is prevented from releasing the semaphore that the other task needs Deadlocks involving more than two semaphores and more than two tasks are also possible Caution VTOS uses semaphores internally to control access to PCM resources Consequently calling a VTOS service function or standard C library I O function such as printf from an application task that has control of ase
126. ed task slice2 SLICE EXE E2 T25 512 SLICE EXE E2 T25 512 SLICE EXE E2 T25 512 SLICE EXE 512 SLICE EXE E2 T25 512 WD v Ze We Uu v OO OV OO Oh Oh Ou Oh OO OF UI OO Oh Oo OD oO UI oO UI O e gt UI OO OO Oo UI O DD oO O t 00Y U1 Om Oh Oo 0 201 o O UI Oh OD OO D 0 HW Oh OY UI OF OY UI OD Oh OV OO OF o UI ON O Ul OY OY UI OY OF UI OD OV DO OO 0 OO O A 01000100000 Oh OO Oh OV OF Oh Oh Ou OY OY OY LD OY Ov Ov OO DNUADHDUAH UO 9 5 6 6 5 6 9 5 We know from the previous example that tasks 9 8 and 7 start executing in a time slice rotation But before any of them can print they are pre empted when task 6 is started as a priority based task Task 5 is also started as a time slice task Since there are four time slice tasks with equal times task 5 is allocated one fourth of the PCM processor time During the other time slices task 6 executes most of the time because its priority is higher than any of the other time slice tasks However tasks 7 8 and 9 occasionally manage to print Why The answer involves the PCM implementation of printf At the lowest level printf makes a WAIT mode call to Write dev when it sends characters to a PCM serial port By default Write_dev returns when the serial port begins sending the last character of the output data Since the printf format string specifies a field width of five characters for the task numbers each task waits about four character tim
127. efine REG_SIZE define OIT_FORMAT WIDTH display width of R data in chars define ACK_TIMEOUT five seconds define DISPLAY TIMEOUT five seconds define REGS_TIMEOUT five seconds define CMRQ MSG SIZE define MAX CMRQ DATA define CMD READ HNDL define REGS ACK HNDL define REGS TIMEOUT HNDL define DISPLAY ACK HNDL define DISPLAY TIMEOUT HNDL define CMRQ TIMEOUT HNDL define CMRQ ACK HNDL define CMRQ READ HNDL define STAT VALUE define DONT CARE comrmeq msg Cmrq msg storage for PLC COMREQs word New regs REG SIZE storage for new R values from OIT char Display data OIT FORMAT WIDTH REG SIZE formatted R data storage byte Command COMMAND SIZE storage for OIT commands word Plc regs MAX CMRQ DATA sizeof word R values from COMREQs word Task id ID value of this program s VTOS task word Cmrq hndl Open dev handle for reading PLC COMREQs word New regs hndl Open dev handle for writing new R data to PLC word Cmrq ack hndl Open dev handle for writing COMREQ status word Oit hndl Open dev handle for OIT commands and display data word Cmrq ack timeout timer handle for COMREQ ack write word Display ack timeout timer handle for OIT data write word Regs ack timeout timer handle for new R data write to PLC CMROSTAT C These function prototypes specify functions which are beyond the scope of this example void recover from error word op handle word error
128. ello from task says Hello from task says Hello from task says Hello from task says Hello from task VTOS function calls must not be made directly or indirectly from code which is executed aftera Link sem or Block sem calland beforean Unblock sem call Violating this rule can cause a PCM application to lock up All standard C library functions which perform data input or output operations such as getc fputs and printf use VTOS UO services These functions must not be called within semaphore protected code C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Debugging Multiple Tasks Applications with multiple tasks can be debugged with the same techniques which are used for single tasks However there are some additional considerations The sequence of events is often harder to understand when events are handled by different tasks Keeping a trace history with information from all the application tasks can help a great deal The trace can be kept in a shared memory module with access controlled by a semaphore as shown in the preceding section Dumping PCM Task State Information Several kinds of problems which occur commonly during the development phase of multiple task PCM applications can be diagnosed by looking at task state information You can take a snapshot of the states of all the active tasks in a PCM and then analyze the state data Whenever a PCM soft reset occurs holding the r
129. ents Chapter 5 Usine PCM Resources sacri casita dead wae de 4 1 PCM Hardware Resources 4 1 The VTOS Operating System 0 6 66 cee ee 4 1 The VTOS File System 4 2 The PCM Command Interpreter 4 3 Accessing PLC Data From PCM Programs 4 3 VTOS CPU Device Services 0 cece eee 4 3 PLO API Services scisseceie e ete eto nu eg E EEN 4 3 Communications Request COMMREQ Messages From PLC Programs 4 4 Programming COMMREQ Function Blocks 4 5 The COMMREQ Command and Data Blocks 4 6 Receiving COMMREO Messages In a PCM Program 4 8 Responding to COMMREOs sssssss 4 10 Regulating the Timing of COMMREQ Messages 4 11 Using Series 90 70 VME Function Blocks c cece eee 4 12 VME Function Blocks for Communicating with the PCM 4 12 Some Rules for VME Bus Operations in Series 90 70 PLCs 4 12 General VME Information for the PCM 4 13 PCM Dual Port RAM Available for Applications 4 14 VME Read Function LL 4 15 VME Write Function LL 4 17 VMiRead Modify Write Function 0000 c cece 4 19 VME Test and Set Function LL 4 21 C Program Access to PCM Dual Port RAM 4 22 viii C Programmer s Toolkit for Series 90 PCMs User s Manual August1996 GFK 0255 Contents Chapter 6 PCM Libraries and Header Files 5 1 PEM Libraries erd iere dE Aer E ee afore ai
130. er AST occurred handle 000e argl 0078 arg2 5a3f arg3 e55e arg4 0002 Note that the ast blk members argl through arg4 printed by timer ast function contain strange values For timer AST functions only the handle member can be specified Semaphores In some situations memory modules must be accessed repeatedly by two or more tasks When these accesses occur asynchronously semaphores provide a convenient mechanism for preventing access conflicts This example shows how access to a shared module may be controlled by a semaphore This example also uses three source files File SEM H defines a new mod data structure type for the memory module as well as string constants for the module and semaphore names In addition there are constant values for the module size and access flag member of the structure SEM H define SEM NAME MOD SEM define MOD NAME MODULE3 define MOD SIZE 512 typedef struct word access_flag char s MOD SIZE sizeof word mod_data access_flag values define FREE define BUSY define DIRTY GFK 0771A Chapter 7 Multitasking 7 17 7 18 Task SEMI gets a wait time value from its command line parameter Then it assigns the module data address to p which is declared asa far pointer to mod data Finally it links to the semaphore and enters a non terminating loop At the top of the loop SEMI has acquired control of the semaphore It tests the access flag member of mod da
131. eries 90 70 PCMs can also operate as VMEbus masters to read and write VMEbus memory in other PLC modules The VTOS Operating System VTOS is a small real time multitasking operating system which runs on the PCM family of products It provides system services to C applications VTOS is optimized for process control communications and operator interface applications on the Intel 80186 and 80188 processors VTOS provides these key features A pre emptive scheduler supports both priority based and time slice scheduling of application tasks e The majority of system services are implemented in assembly language to minimize execution times Event flags semaphores shared memory and asynchronous traps are provided for inter task communication A real time clock provides up to 256 programmable timers with one millisecond resolution and a seven week range GFK 0771A 4 1 A device manager provides access to the serial ports files stored in RAM ROM or the disk drives of an attached PC and backplane access to Series 90 70 and 90 30 PLC CPUs as well as other PCMs in the same PLC A consistent interface is provided for all devices which is similar to asynchronous I O under UNIX m Each task has predefined standard input output and error channels which can be redirected to any device m Tasks can open channels to any PCM device m I O can proceed asynchronously to task execution The VTOS memory manager and PCM batter
132. es whenever it calls printf During this time another task is permitted to execute Whenever task 5 waits for serial I O completion task 6 executes But during the time slices for tasks 7 8 and 9 task 6 usually executes When task 6 waits for printf the lower priority task which owns the current time slice can execute Eventually they all get enough execution time to complete one pass through the counting loop and print In this example the execution time actually given to three of the time slice tasks depends entirely on the number of characters printed by a fourth task This illustrates how unpredictable the result can be when both time slice and priority based tasks are used by a PCM application Great care is required when designing the task processes and assigning them to VTOS task numbers These principles should be kept in mind 1 Priority based tasks should used for time critical processing such as handling asynchronous events They should perform their functions and relinquish the PCM processor as quickly as possible 2 Time slice tasks should be assigned a group of contiguous task numbers All the time slice task numbers should be higher than any priority based task number That is all the time slice tasks should have lower priority than any priority based task GFK 0771A Chapter 7 Multitasking 7 5 Task Contention for PCM Serial Ports The preceding example also shows that the PCM serial ports will happily accept output da
133. es 4 23 Chapter PCM Libraries and Header Files 5 This chapter describes how the libraries and header files provided with the PCM C toolkit are used to access PCM resources from C programs PCM Libraries Two sets of libraries are furnished with the PCM C toolkit Services provided by the PCM s VTOS operating system are accessed through the library files PCMS LIB PCMM LIB and PCML LIB for the small medium and large memory models respectively PLC CPU services are provided by the PLC application program interface PLC API library files APIS LIB APIM LIB and APIL LIB for the small medium and large memory models respectively The following sections describe VTOS and PLC API services VTOS Interface VTOS services are provided as system service function calls and global data Some of the services use predefined VTOS data types The function calls global variables and data types are all defined in the C header file VTOS H Data types used by the PLC CPU which are returned to PCM applications or sent to the CPU by VTOS device services are defined in CPU DATA H VTOS Services By Category This section summarizes VTOS services by grouping them in categories of related services For full details on all VTOS services refer to the PCM C Function Library Reference Manual GFK 0772 Table 5 1 Task Management Functions Function Name Purpose Get task id Returns the task ID value of the calling task Init task Execu
134. es the Microsoft C command line option D to define the DEBUG C preprocessor macro An NMK or NMAKE macro also named DEBUG specifies that either DDEBUG or no characters at all are inserted into compiler command lines when the DEBUG macro is evaluated TASK1 The C source code for the first of the PCM tasks that comprise the demo application is in thefile PCMC EXAMPLES DEMO_3T ASK1 C This task shares a memory module with TASK2 C the module contains data flags and asynchronous trap AST addresses When PCMEXEC BAT starts the application it clears the memory module and passes it to each task In operation TASK1 periodically reads a register YR value from the CPU If the new value is different from the previous value an AST is posted to TASK2 using the AST address and task ID values that TASK2 previously stored in the shared memory module The new register value is passed to TASK2 s AST function as a member of an ast_blk Structure A VTOS timer controls the time between register read operations When the timer expires the function tmr ast is called to read the CPU data make the comparison and when appropriate post the AST to TASK2 TASKI also receives ASTs from TASK2 The function other task ast imported from TASK_ASTC processes these ASTs it is described below The main function of TASKI finds the data address of the shared memory module If the module name was not specified on TASK1 s command line it prints an error mess
135. esand get memtype sizes nowait PLC FAULT STRUC Astructure type component of PLC FAULT TBL STRUC PLC FAULT TBL STRUC Astructuretypereturned by read plc fault tbland read plc fault tbl nowait PROGRAM INFO STRUC Astructuretypereturned by get prgm info and get prgm info nowait RACK FAULT STRUC Astructuretypereturned by get one rackfaults and get one rackfaults nowait RACK SLOT STRUC Astructure type component of RACK FAULT STRUC TIMESTAMP LONG STRUC A structure type returned by read timedate and read timedate nowait and passed to set timedate and set timedate nowait TIMESTAMP STRUC Astructure type component of IO FAULT TBL STRUC and PLC FAULT TBL STRUC TIME STRUC A structure type returned by read time and read time nowait and passedto set time and set time nowait WORD Unsigned short int type which takes the values 0 through 65 535decimal These data types are defined in MIXTYPES H Table 5 30 Data Types Type Name Purpose MEM FORMAT STRUC Astructure type component of MIXED MEMORY READ STRUC MIXED MEMORY READ STRUC Structure type passed to establish mixed memory and establish mixed memory nowait PLC API Global Data These global variables are defined as extern data in STATUS H 5 18 Table 5 31 PLC API Global Data Variable Name Purpose plc status info Thisis an array oftype PLC STATUS INFO
136. eset restart pushbutton down for less than five seconds the states of all the VTOS tasks and a portion of each task s stack are saved When you execute the PCM PD Dump the PCM task status command from TERME the data saved during the most recent soft reset is sent to a file named PCMDUMPOUT in the current PC disk drive and directory PCMDUMPOUT is a binary file The PCMDUMPEXE utility furnished with the PCM C toolkit formats the binary task data into readable form When a PCM is configured to start an application on soft resets a hard reset holding the button down for ten seconds may be required to access the PCM command interpreter Hard resets have no effect on the task state and stack data from the most recent soft reset However cycling PLC power off and on will corrupt any state data which was previously saved The task state data makes it easy to diagnose common problems which are otherwise very difficult For example it is obvious when a task is waiting for an AST with ASTs disabled If you run an application several times and same task is always executing at the same code location CS IP register values the task may be stuck in a loop For complete information on dumping PCM task state information and using the PCMDUMP utility see chapter 11 Utilities Using In Circuit Emulators GFK 0771A Complex interactions between application tasks and asynchronous events often lead to software errors which are difficult to diagnose I
137. example stkmod myapp s 2048 Invoking STKMOD EXE with just the exe file name option displays the current stack size value without changing it 11 1 11 2 gt stkmod hello GE Fanuc Automation PCM EXE File Stack Size Utility Version 1 00 Copyright C 1992 GE Fanuc Automation North America Inc All rights reserved HELLO EXE hex dec old stack size in paragraphs 0800 128 old stack size in bytes 0800 2048 When the s or s option is used the stack size specification in the file specified by exe file name gt is modified If stack size in bytes is nota decimal number or is less than 1024 the stack size will be set to 1024 bytes If lt stack size in bytes gt is greater than 65 520 bytes the stack size will be set to 65 520 bytes If the specified stack size is at least 1024 less than 65 520 and an integer multiple of 16 bytes the specified value will be used Otherwise the specified value will be adjusted to the next larger multiple of 16 bytes When STKMOD modifies the specified value it displays this message stack size adjusted to xxxxx bytes For example entering either of these command lines stkmod hello s abcd stkmod hello s 1023 results in a new stack size of 1024 bytes Entering these command lines stkmod hello s 100000 stkmod hello s 1025 stkmod hello s 1040 results in new stack sizes of 65520 bytes 1040 bytes and 1040 bytes respectively STKMOD produces these error messages
138. f two words containing the module address The address is based on the rack and slot where the PCM is located Refer to Address Allocation by Rack and Slot in this section OK Power flow output that is TRUE when the function is enabled and completessuccessfully GFK 0771A Chapter 4 Using PCM Resources 4 17 When the VMEWRT function receives power flow through its enable input LEN data units words or bytes from the PLC locations beginning at the input parameter IN are written to the PCM at the specified address ADR When the operation is successfully completed the VMEWRT function passes power to the right through the OK output For information on PCM module addressing using address and address modifier codes refer to General VME Information for the PCM presented earlier in this section Example VMEWRT Function In the following example the hexadecimal value FFFF is written to each of 20 words on the PCM during every sweep when enabling input M00001 is TRUE The starting lowest PCM address is specified by the contents of R00019 low word and R00020 high word Unless an error occurs while writing the data internal coil 70M00055 is set to TRUE M00055 WRT WORD CONST IN FFFF LEN 1000201 CONST AM 0039 I I R00019 ADR I The PCM must be located in the rack and slot corresponding to the address contained in R00019 and R00020 The PCM C application would
139. far mod_ptr void far ast_func ast_blk far p printf task AST1 an AST was posted Wn printf handle 04x n p gt handle printf argl 04xWn p argl printf arg2 04xWn p arg2 printf arg3 04xWn p arg3 printf arg4 04xWn p arg4 void main word tmr_hndl word task Get task id printf task AST1 id d n task Reset gef READY 1 GEF READY 2 GEF Wait gef READY 2 GEF The other task has initialized its data in the module mod ptr Get mod MOD NAME P mod data far mod ptr 1 p taskl num task p post ast func ast func Start a timer which will notify the other task by posting an AST tmr_hndl Start_timer AST NOTIFY MODE TASK SPECIFIED RELATIVE TIMEOUT p gt task2_num MS COUNT MODE 0 1000 p tmr ast func task printf task AST1 timer handle 04x n tmr hndl Set gef READY 1 GEF Wait ast Chapter 7 Multitasking 7 15 7 16 AST2 also contains an AST function timer ast function It is the function which was specified by AST1 when it started the timer This AST function prints the members of its ast blk The main function of AST2 assumes that it can begin initializing MODULE2 when it begins execution It copies task and AST function address values to its members of the shared module signals AST1 by setting READY 2 GEE and then waits for READY 1 GEE When the Wait gef callreturns signaling
140. fault stack size is 320 800 decimal bytes Dxxxx Allocatexxxxhexadecimal bytes of data space to the task This option is ignored for EXE files using the Intel large memory model Its primary use is to limit the memory allocated to MegaBasic reserving the balance for the PCM RAM disk Applications using this option must provide their own mechanism to determine the location and size of the allocated memory Ex Specify the executable task type The defaultis E1 priority based E2 timeslice isalso valid When E2 isspecified butno T option is included the default time slice value is 10 milliseconds When a priority based task runs it executes until itis blocked suspends itself or is pre empted when a higher priority task becomes ready to run When a time slicetaskruns it continues until its allocated time expires itis blocked itsuspendsitself or it is pre empted when a priority based task with higher priority becomes ready torun x Use a specified task ID value in the range 4 OF hexadecimal by default the largest lowest priority unused value For priority based tasks smaller task ID values have higher priority When there are two or more time slice tasks they run in round robin fashion in the order of their ID values The time slice task with the lowest ID value runs first followed by others in the order of increasing ID value We recom mend that all priority based tasks have higher priority than an
141. file PCMC EXAMPLES COPR TXT was copied to your PC hard disk when this software was installed its full path specification plus the Enter key is the response The section Customizing the PROM Copyright String below explains how to provide a unique copyright for your application The first application file for the PROM is a PCM batch file which will run the application whenever the PCM is reset or powered on This file was also copied to your PC hard disk when this software was installed Its full path specification PCMC EXAMPLES RUNHELLO BAT plus the Enter key is the response BLD_PROM asks what file name should be used for RUNHELLO BAT in the PROM Rather than the default name it PCMEXEC BAT this is the batch file name which is run automatically on reset or power up Use the Enter key to terminate the name BLD_PROM also asks whether the file should be visible in the PROM directory listing You can make it a hidden file by responding with just the N key Type the Enter key to select the default which makes it visible Since this is a data file the next prompt asks whether the file should be copied to RAM before use This file will never need to be changed so type the Enter key to select the default You can also use ROM data modules to provide initialization values for read write modules in RAM In this case the module would be copied to RAM before use Next BLD PROM asks for another file to be put into the PROM Respond with ou
142. from the VMEbus When more than one byte of data will be transferred the WORD data type should be specified for VME functions WORD transfers move one word per VME bus cycle but BYTE transfers require two bus cycles to move a word GFK 0771A Chapter 4 Using PCM Resources 4 13 PCM Dual Port RAM Available for Applications The PCM system software uses a large part of the first 4000 hexadecimal bytes of the PCM VMEbus dual port RAM In addition some PLC API library services require VMEbusRAM Addresses within the first 4000 hexadecimal bytes of PCM VMEbus memory should never be used as target addresses for VME functions Use only addresses at or above offset 4000 hexadecimal Future PCM enhancements are likely to use VMEbus memory above the first 4000 hexadecimal bytes Applications should use the highest possible address for VME communication PCM C applications which use one or more blocks of VMEbus memory should reserve them by calling the VTOS function Reserve dp buff This call should be made before any calls to api initialize Thereturn value from the Reserve dp buff call should be tested to assure that the requested block of VME dual port memory is available for the application C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A VME Read Function The VMERD function can be used to read data from the dual port RAM of a Series 90 70 PCM to the PLC CPU This function should be executed before the
143. g 64K bytes by partitioning the application into separate tasks Ideally the tasks would have no interactions but this is not always possible Techniques for communication and data sharing between tasks are described later in this chapter 3 In some cases one copy of program code can be executed as two or more tasks performing the same process with different data For example a PCM configured for CCM communication on both serial ports executes a single executable file as two tasks Each task controls just one of the two ports and has its own stack and data segments Task Priorities GFK 0771A Every VTOS task has a unique priority which is related to its task number returned by the VIOS Ger task id service Tasks with larger task numbers have lower priority Task 0 has the highest priority it is always assigned to the VTOS Real Time Clock RTC task which manages timers and schedules all other tasks Task 15 decimal 0F hexadecimal is the lowest possible priority for application tasks VTOS Tasks Task Startup In addition to the RTC task VTOS almost always starts three other system tasks CPULINK PCLINK and OPCOM although a UCDF configuration from PCOP can suppress them These tasks are the PLC backplane communication driver task the PC file transfer task and the PCM command interpreter task respectively In PCM release 3 00 and later VTOS also starts the remote communication task REM whenever a hard reset occurs or when a
144. g NMAKE and NMK When using one of these utilities to build PCM applications the command line options which NMAKE or NMK uses to invoke the Microsoft compiler and linker must be specified correctly The file MAKEFILE 1 which was copied to your PCMC EXAMPLES directory during installation of the PCM C toolkit builds HELLO EXE You can use it by deleting all the HELLO files except HELLO C from your working directory and then typing NMAKE PCMC EXAMPLES MAKEFILE 1 or NMK PCMC EXAMPLES MAKEFILE 1 at the MS DOS prompt NMAKE or NMK should respond with Microsoft R Program Maintenance Utility Version 1 11 Copyright c Microsoft Corp 1988 90 All rights reserved cl Ze AS Aw G1 Gs FPa Z1 Zp Fchello hello c gt hello out Microsoft R C Optimizing Compiler Version 6 00A Copyright c Microsoft Corp 1984 1990 All rights reserved type hello out hello c link NOD NOE M crt0sm hello obj chkstks ifcallsm hello exe hel lo map apis pcms slibca Microsoft R Segmented Executable Linker Version 5 10 Copyright C Microsoft Corp 1984 1990 All rights reserved When the MS DOS prompt appears all the steps for building HELLO EXE have been completed C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A GFK 0771A MAKEFILE 1 may be used as a pattern for makefiles which build other applications Just change the OBJLIST macro and target EXE file name appropriately For example to b
145. g PCM Resources 4 15 When the VMERD function receives power flow through its ENABLE input the function accesses the PCM at the specified address ADR and copies LEN data units words or bytes from the PCM to PLC locations beginning at the output parameter Q When the operation is successfully completed the VMERD function passes power to the right through the OK output For information on PCM module addressing using addresses and address modifier codes refer to General VME Information for the PCM presented earlier in this section Example VMERD Function In this example 128 words 256 bytes of data are read from a PCM in rack 4 slot 7 into registers R00001 through R00128 whenever enabling input 76100001 is TRUE Unless an error occurs while reading the data output 7900001 is set to TRUE 100001 Q00001 CONST AM 0039 LEN 100128 CONST ADR Q R00001 OBA4000 I In Series 90 70 PCMs VME dual port memory occupies 32K bytes In PCM address space VME memory begins at address 0xA0000 0x0000 regardless of the rack and slot where the PCM is installed In this example the VME bus address 0BA7000 hexadecimal corresponds to the PCM internal address 0xA000 0x7000 There are several ways for PCM C programs to move data to this address in VMEbus dual port RAM One of the simplest is to use the standard C library memcpy function C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A
146. gef my_flag active_tasks Test_task amp USER_TASKS other_flag active_tasks amp my_flag printf task d other flag x n my task other flag if other flag Set gef other flag Wait gef my flag The array Task flags isinitialized with one event flag constant for each task ID value supported by VTOS The order in which the flags are assigned to array elements assures that the my_flag bit for task 15 for example is the same bit that Test task returns for task 15 This ordering permits each task to calculate the correct event flag for the other task by masking its own bitinthe Test task return value If the other task has not been started or has terminated the task which is running will obtain zero for the other task s event flag and will not call Wait gef Although this method of determining the other task s event flag is not the simplest one possible it has the advantage of preventing a task from waiting for an event flag which will never be set GFK 0771A Chapter 7 Multitasking 7 7 Two tasks are started by a PCM batch file SWAPBAT The contents of the batch file and a portion of the output from the two tasks is shown below Note that the my flag value which each task prints is equal tothe other flag value printed by the other task Both tasks are run in background mode to permit killing them from TERME There is no contention for input characters from the programming port because SWAP does not use serial in
147. ges a boolean TRUE 1 for the value currently at the semaphore location If that value already was TRUE then the VMETS function does not acquire the semaphore If the existing value was FALSE the semaphore is set and the VMETS function block has acquired control of the semaphore as well as the memory area it controls The semaphore is cleared and control relinquished by using the VMEWRT function to write FALSE 0 to the semaphore location The format of the VMETS function block is enable VME function OK logic TS address BYTE modifier AM Q semaphore acquired module address ADR Parameter Description Enable Power flow input that when TRUE enables the execution of the function Type Function type either BYTE or WORD to select the corresponding type of VME bus access to be performed WORD accesses transfer 16 bits of data on each VMEbus cycle while BYTE accesses transfer just 8 data bits per buscycle AddressModifier A hexadecimal word value that specifies both the rack where the target PCM is installed and the VMEbus access mode to be performed Module Address A double word specifying the hexadecimal address of the first word or byte to be accessed It may be a constant or the reference address of the first least significant word of two words containing the module address The address is based on the rack and slot where the PCM is located Refer to Address Allocation by Rack and
148. grammable Coprocessor Module PCM These applications are developed on a standard personal computer PC and then installed in battery backed RAM or EPROM in a PCM Why Develop PCM Applications In C The PCM has supported the MegaBasic programming language since its introduction MegaBasic is an interpreted language Although it is relatively fast in comparison to other interpreted languages MegaBasic is considerably slower than compiled C code OEMs can install C applications in EPROM making more efficient use of PCM RAM space C applications can use multiple PCM tasks to efficiently handle external events Appropriate Applications GFK 0771A APLC CPU is optimized for control processing However many PLC applications include some computation intensive information processing which is not well suited to the PLC CPU environment These applications can often be optimized by moving the computation out of the CPU The Series 90 PCM family provides a platform for hosting this kind of processing within PLCs PCMs offer these features to support PLC applications 1 APCM provides an independent processing platform which is not directly bound by PLC sweep time constraints 2 Each PCM provides two serial communication ports for the PLC application 3 PCMs can read PLC process data they can also change it 4 The PCM operating system VTOS is optimized for real time processing based on the finite state machine abstraction 5 PCMs pro
149. gs must be specified for each one to permit the task to identify events as they occur Once the application has started all the I O operations and timers it needs it can wait for one of the pending I O completion or timeout events to occur by calling Wait ef A set of event flags is specified as a parameter in the call and the function will not return until one of the specified event flags is set If one has been set before the call Wait ef returns immediately Otherwise execution of the calling task is suspended When any local event flag is set VTOS determines whether the task which owns it is waiting for that flag If so the task is made ready and the VTOS scheduler compares its priority to the task which was executing when the event or events occurred The waiting task resumes execution and returns from the Wait ef call when it has the highest priority of all the tasks which are ready to execute When Wait ef returns the task can determine which event or events have occurred by calling Test ef and checking to see which event flags have been set Whenever notification is not required for a device operation you can use EVENT NOTIFY and specify no event flags at all Simply use zero 0 as the local ef mask parameter for the function call AST Notification and Execution Threads GFK 0771A Anapplication task may also specify AST NOTIFY as the method of notification for an event One of the parameters in an AST NOTIFY service reques
150. he Break key 7 Start the Logicmaster 90 software on your PC Select the PLC folder that is appropriate for your PLC If you are using a Series 90 30 PLC load configuration and logic to the PLC otherwise load just logic Note that the rung numbers the Logicmaster software displays for the comment rungs of the PLC program may vary from the rung numbers shown in Listing 9 1 depending on your version of Logicmaster 90 software 9 2 C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A H 8 Put the PLC CPU into RUN mode and reset the PCM by pressing the Restart Reset pushbutton for less than five seconds Use Logicmaster 90 software to trigger PCM COMMREQs by toggling M0001 and M0021 Change the value of R0050 to trigger activity on the OIT For details on the operation of the demo see the following sections and comments in the PLC program and C source files The PCM Tasks GFK 0771A Three PCM tasks are included in the demo TASK1 TASK2 and DATA Detailed descriptions for them can be found in the following sections Each task contains debugging code that is compiled only when the DEBUG macro symbol is defined This debug code sends text messages to the VTOS device named by the DEBUG_DEV macro definition DEBUG DEN is opened and written as a file using the fopen and fprintf library functions respectively The source files define DEBUG DEV to be coml The makefile for this application MK DEMOS us
151. he PCM RAM disk to be saved to a PC file If the optional pc filename is omitted the PCM filename will be used and the file will be saved in the current directory of the current drive If the file does not already exist on the PC it is created otherwise the existing PC file is overwritten The pc filename mayincludea PC disk drive and or file path as described above for the L Load command The pem filename may contain at most an eight character file name a dot character and a three character file extension 8 3 or eight dot three format The pc filename formatis determined by the PC file system The MS DOS file system has the same 8 3 filename format restriction exclusive of the device and path prefix The Save command is also used to copy files from the RAM disk to the ROM device in the PCM 301 GE Fanuc catalog number IC693PCM301 This is the only mechanism for transferring files to the ROM device EXE files which have been loaded to PCM RAM no longer contain relocation information They cannot be saved to PC files For information on saving EXE files to the ROM device see the J command Possible errors are Module not found file name Cant save module file name GFK 0771A Appendix B PCM Commands B 17 U Reconfigure the PCM Format U configuration file This command reconfigures the PCM according to the specified configuration file If any ofthe modules specified in the configuration
152. he string constant is copied to text In this case the warning does not indicate a problem warning C4058 address of automatic local variable taken DS SS C Programmer s Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A GFK 0771A Try running this program yourself to verify that it works It prints the expected result 3 Then change the declaration of p to just char and try it again This time the same warning is also produced at line 11 The program prints 5 which is clearly an error The second warning message does indicate a problem You can examine the TEST1 COD file to find out why 2 All function parameters which are addresses have been declared far in the function prototypes in VTOS H the PLC API header files and the PCM C toolkit header files for standard C library functions However a few functions accept a variable number of parameters and or parameters of varying type The function prototypes for these functions contain an ellipsis where parameters may vary All addresses passed as variable parameters in the small or medium memory models must be either identifiers which have been declared as far pointers or explicitly type cast to far There are two commonly used families of library functions with variable parameter lists the VTOS device services Open_dev etc andthe printf family of standard C library functions This example shows how to print strings using printf in small model
153. imal so the command is B 1 OC The task number if specified is an ASCII hexadecimal digit that specifies which task will control the indicated LED The task number must be the number of a valid task 0 0F hexadecimal When an LED is assigned to a task the LED use code must be specified as 40 hex To configure LED 1 to be controlled by task 7 use B 1407 Task 7 will then be able to change the behavior of LED 1 A second B command may be used specify a default communication event or events which will flash the LED before task 7 programs it Appendix B PCM Commands B 5 C Clear the PCM Format C This command deletes all RAM disk files on the PCM including UCDF configuration data The C command returns an error Module in use file name if any files are in use When this occurs the PCM must be put in factory mode by holding the restart reset button for more than five seconds or issuing a hard reset COMMREQ message from the PLC ladder program before it can be cleared D file Directory B 6 Format D lt option gt This command prints the names of the files stored in the PCM RAM disk or other file devices It returns no errors A single letter option separated by a space from the D command may be used The table below shows the data returned by this command and its options Option Description D The D command used alone shows the names of non hidden files in the PCM RAM disk DH This command o
154. in interactive command mode At the PCM prompt gt use the PD command to get a binary PCMDUMDPOUT file in the current directory of your PC 4 Exitfrom TERME From the MS DOS prompt run the PCMDUMP utility PCMDUMP or gt PCMDUMP gt DUMP ASC or gt PCMDUMP gt LPT1 By default PCMDUMPEXE sends its output to the PC display Redirecting the output to a file such as DUMPASC as shown in the second example allows you to analyze the dump information using a text editor You can also redirect output to a printer as in the third example There are two kinds of task state information in the output from PCMDUMPEXE task control block data and task register and stack data Here is an example showing the task control blocks for the VTOS real time clock task Task ID 0000 and two user tasks Task ID 000E and 000F hexadecimal GFK 0771A Chapter 11 Utilities 11 3 11 4 GE Fanuc Automation PCM Task State Dump Utility Version 1 02 Copyright c 1992 GE Fanuc Automation North America Inc All rights reserved TASK CONTROL BLOCKS Task ID 2 Current state Waiting for local event flag Old state S Current stack pointer gt 02E2 Local event flags which have been set Local event flags where task is waiting Global event flags where task is waiting Other tasks which task is waiting for First AST block for task Last AST block for task Suspend count Task s initial data segment Task s initial stack segment S
155. include module h mod hdr far mod p defined in VTOS H mod data far mod data p defined in MODULE H void main word task Get task id char str 40 sprintf str Hello from T1 running as task d n task mod p Get mod APP MODULE if mod p NULL printf task T1 module found module address 04x 04xWn word amp mod p 1 word amp mod p mod data p mod data far mod p 1 printf module data address 04x 04x n word amp mod data p 1 word amp mod data p mod data p task num task mod data p s str printf module data 04x 04x 04x n word far mod data p word far mod data p 1 word far mod data p 2 Reset gef EXIT GEF Set gef DATA READY GEF Wait gef EXIT GEF C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A GFK 0771A T2 C also includes MODULE H but it finds the address of MODULE from modv 1 T2 waits for T1 to set DATA READY GEE indicating that the shared module data has been initialized T2 then accesses and prints the data T2 C include lt vtos h gt include lt stdio h gt include module h mod data far mod data p defined in MODULE H void main int argc char far far argv int mode mod hdr far far modv if mode lt 2 printf ntask T2 memory module not found n return Reset gef DATA READY GEF
156. ined by calling Test ef and the flags of interest are cleared by calling Reset ef Then the word containing the event flags is tested by a separate if statement for each event The tests occur in the order of importance for the events When one of the events has occurred the appropriate action is taken 1 Ifa command was received from the OIT its length is checked If the command length is correct the command is processed A read operation is requested for the next command 2 Ifregister data was received the timeout is cancelled and the data is checked for the correct length If the length is correct the data is sent to the OIT for display 3 Ifthe time has arrived to request new register data and no read request is still pending a read request is sent and the timeout is started 4 Ifthe register read timeout has expired the read request is aborted and the OIT is notified The purposes of the functions process command display registers display bad regs alarm and display dead plc alarm should be evident from their names the details are not considered here C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A s Using AST NOTIFY Mode Event Processing Finally here is an example where AST NOTIFY event processing is most appropriate In this case we assume that events are required to be processed in the order they occur The PCM application periodically receives a COMMREO message from the P
157. info _getgtextextent _getgtextvector _getimage _getimage_w _getimage_wxy _getlinestyle _getphyscoord _getpixel _getpixel_w _gettextcolor _gettextcursor _gettextposition _gettextwindow _getvideoconfig _getvisualpage _getviewcoord _getviewcoord_w _getviewcoord_wxy _getwindowcoord _getwritemode _grstatus _imagesize _imagesize_w _imagesize_wxy _lineto _lineto_w _moveto _moveto_w _outgtext outmem outtext _pie _pie_w _pie_wxy _polygon _polygon_w _polygon_wxy These functions are not supported in any memory model C Programmer s Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A GFK 0771A Function Memory Model putimage putimage w rectangle rectangle w rectangle wxy _registerfonts _remapallpalette _remappalette _scrolltextwindow _selectpalette _setactivepage _setbkcolor _setcliprgn _setcolor _setfillmask _setfont _setgtextvector _setlinestyle _setpbel _setpixel_w _settextcolor _settextcursor _settextposition _settextrows _settextwindow _setvideomode _setvideomoderows _setvieworg _setviewport _setvisualpage _setwindow _setwritemode _unregisterfonts _wrapon These functions are not supported in any memory model Appendix A Microsoft Runtime Library Support A 5 A 6 Table A 7 Presentation Graphics Functions Function Memory Model _pg_analyzechart _pg_analyzechartms _pg_analyzepie _pg_analyzescatter _pg_analyze
158. ing the hexadecimal address of the word or byte to be accessed It may be a constant or the reference address of the first least significant word of two words containing the module address The address is based on the rack and slot where the PCM is located Refer to Address Allocation by Rack and Slot in this section OK Power flow output that is TRUE when the function is enabled and completessuccessfully GFK 0771A Chapter 4 Using PCM Resources 4 19 When the VMERMW function receives power flow through its enable input the function reads a word or byte of data from the module at the specified address ADR and address modifier AM This byte or word of data is combined AND OR with the data mask MSK Selection of AND or OR is made using the input OP If byte data is specified only the lower 8 bits of MSK are used The result is then written back to the same VME address from which it was read When the operation is successfully completed the VMERMW function passes power to the right through the OK output For information on PCM module addressing using address and address modifier codes refer to General VME Information for the PCM presented earlier in this section C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A VME Test and Set Function The VMETS function can be used to handle semaphores located in the VMEbus dual port RAM of a Series 90 70 PCM The VMETS function exchan
159. io nowait Series 90 70 PLC CPU request only stop plc Sets the PLC state to STOP mode stop plc nowait Chapter 5 PCM Libraries and Header Files 5 15 Reading Mixed PLC Data References The WAIT mode functions are declared in MXREAD H and the NOWAIT versions are declared in MXREADNWH Table 5 25 Reading Mixed PLC Data References Function Name Purpose establish mbed memory establish mbed memory nowait Establishesa mixed memory shopping list for subsequent read mixed memory or read mixed memory nowait calls read mbed memory read mbied memory nowait Gets the mixed memory data previously specified by an establish mixed memoryor establish mixed memory nowait call cancel mbed memory cancel mbed memory nowait Cancels the mixed memory shopping list previously specified by an establish mixed memory or establish mixed memory nowait call Reading and Clearing PLC and I O Faults The WAIT mode functions are declared in CLRFLT H and the NOWAIT versions are declared in CLRFLTNW H Table 5 26 Reading and Clearing PLC and I O Faults Function Name Purpose read_plc_fault_tbl read_plc_fault_tbl_nowait Reads the entire PLC fault table read_io_fault_tbl read_io_fault_tbl_nowait Reads the entire I O fault table clr_plc_fault_tbl clr_plc_fault_tbl_nowait Clears the entire PLC fault table clr_io_fault_tbl clr_io_fault_tbl_nowait Clear
160. ion command data string This command causes the PCM to run the executable file specified by file name The command line may include zero or more options and zero or more data strings Options and data strings may be intermixed The following options are available GFK 0771A Appendix B PCM Commands B 15 B 16 Option Description gt outchnl Redirectstandard output to the channel specified by outchnl Choices are COM1 COM2 RAM pcm filename ROM pcm filename and PC pc filename where pcm filename and pc filename are the names of PCM RAM disk and PC files respectively A device must be explicitly specified for files the colon is required The ROM device is available only in the PCM 301 GE Fanuc catalog number IC693PCM301 A pc filename may contain a PC deviceand orfilepathspecification R MYFILE EXE gt PC C MYDIR MYFILE OUT lt inchnl Take standard input from the channel specifiedby inchnl Choices are identical to the ones for the outchnl option errchnl Redirectstandard error output to the channel specified by errchn1 Choices are identical to the ones for the outchnl option Sxxxx Use a stack size of xxxx hexadecimal bytes If the specified value is greater than the size from the executable file header specified by the STKMOD utility it will override the file header value When the S option is not used and the file header value is zero the de
161. ions are not supported in any memory model Table A 9 Console and Port I O Functions Function Memory Model inp inpw outp outpw These functions are supported in all memory models cgets cprintf cputs cscanf getch getche kbhit putch ungetch These functions are not supported in any memory model Appendix A Microsoft Runtime Library Support A 7 A 6 Table A 10 Internationalization Functions Function Memory Model localeconv setlocale strcoll strftime strxfrm These functions are not supported in any memory model Table A 11 Math Functions Function Memory Model acos asin atan atan2 ceil cos cosh div exp fabs floor fmod Idexp ldiv log log10 _lrotl _lrotr max min pow rand _rotl _rotr sin sinh sqrt srand tan tanh These functions are supported in all memory models dieeetomsbin dmsbintoieee fieeetomsbin fmsbintoieee modf In small and medium memory models use only with DS based variables Unrestricted inlarge model cabs frexp hypot These functions are supported in large model only C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A GFK 0771A Function Memory Model acosl asinl atanl atan2l bessel cabsl ceill cos coshl expl fabsl floor fmodl _fpreset frexpl hypotl Idexpl logl log101 matherr matherrl modfl powl sinl
162. isplay dead plc alarm Oit hndl void far WRITE REGISTER DATA STATE ast ast blk far ast ptr A command was received from the OIT Do an AST NOTIFY read for the next command Regs_ack_timeout Start_timer RELATIVE_TIMEOUT AST_NOTIFY_MODE MS COUNT MODE 0 REGS TIMEOUT ABORT REGISTER DATA STATE ast REGS TIMEOUT HNDL Process the command and send the new R data to the PLC CPU process_command Command Write dev New regs hndl New regs REG SIZE AST NOTIFY Task id REGS DATA COMPLETE STATE ast REGS ACK HNDL void main void Get the task ID of this task from VTOS Task id Get task id Open PLC CPU channels for acknowledging COMREQs and sending new register values Cmrq ack hndl Open dev CPU R200 WRITE MODE NATIVE MODE AUTO REWIND MODE WAIT Task id New regs hndl Open dev CPU R1 WRITE MODE NATIVE MODE AUTO REWIND MODE WAIT Task id Open a COMREQ channel for reads Cmrq hndl Open_dev CPU 5 READ MODE WAIT Task id Open a read write channel to the Operator Interface Terminal Oit hndl Open dev COM1 13 READ MODE WRITE MODE WAIT Task id Do an AST NOTIFY read for the first COMREQ and command Read dev Cmrq hndl amp Cmrq msg CMRQ MSG SIZE AST NOTIFY Task id SEND DISPLAY DATA STATE ast CMRQ READ HNDL Read dev Oit hndl Command COMMAND SIZE AST NOTIFY Task id WRITE REGISTER DATA
163. it was not installed on drive C substitute the correct drive letter in the SET LIB command The subdirectory PCMC LIB must occur before C600 LIB or C700 LIB in the LIB environment variable If it does not your PCM applications will not execute as expected and a PCM lockup may occur 2 4 C Programmer s Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Adding PCMC INCLUDE to Your INCLUDE Environment Variable Finally if you choose to modify your AUTOEXEC BAT manually you must add PCMC INCUDE to the definition of your INCLUDE environment variable It must occur before the Microsoft C INCLUDE subdirectory For example if your INCLUDE variable is currently defined by SET INCLUDE C C600 INCLUDE or SET INCLUDE C C700 INCLUDE Then you must change it to SET INCLUDE C PCMC INCLUDE C C600 INCLUDE or SET INCLUDE C PCMC INCLUDE C NC700N INCLUDE respectively If the PCM C toolkit was not installed on drive C substitute the correct drive letter in the SET INCLUDE command The subdirectory PCMC INCLUDE must occur before C600 INCLUDE or C700 INCLUDE in the INCLUDE environment variable If it does not your PCM applications will not execute as expected and a PCM lockup may occur GFK 0771A Chapter 2 Installation 2 5 Switching Between PCM and MS DOS Application Development These changes to the INCLUDE and LIB environment variables are necessary to guarantee that Microsoft C will find the cor
164. ither PCM CFG or PROG PRT mode The configuration can be performed using either the Series 90 30 Hand Held Programmer or the Logicmaster 90 30 configuration software package Caution When a Series 90 30 PCM has not been configured by either the Hand Held Programmer or Logicmaster 90 30 software its default configuration mode is CCM communication on both serial ports You will not be able to load or run PCM programs until the PCM has been configured for PCM CFG or PROG PRT mode Programs can be loaded to a Series 90 70 PCM without configuring it using Logicmaster 90 70 configuration software An RS 232C serial port on your computer PC must be connected to serial port 1 of the PCM by an appropriate serial cable RS 232C cables for common PC serial ports are described in appendix A of the Series 90 Programmable Coprocessor Module and Support Software User s Manual GFK 0255D or later The serial communication settings for TERMF must be identical to the ones used by the PCM When the PCM is configured for Logicmaster 90 PCM CFG mode the settings are 19 200 baud no parity eight 8 data bits one 1 stop bit and hardware handshaking In PROG PRT mode the settings are selected by the user Note PCM file transfer requires 8 data bits and hardware handshaking File transfers will fail if 7 data bits or software handshaking is selected The TERMSET program included with both the TERMF and PCOP software products may be used to specify
165. ive task the PCM returns the task number and the names of the task s code and environment modules B 14 C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Q Set Protection Level Format Q file name protection level This command is used to change the protection level of a module or modules on the PCM RAM disk Level Description 0 Unprotectthe file the file is not checksum protected and may be freely written The checksum is not verified on powerup or reset 1 Protect the file a checksum is calculated for it and it may no longer be written to On powerup or reset the checksum of the module is verified and if itis not correct the module is discarded Note that when a C executable EXE file is loaded the the PCM RAM disk its protection mode is set by default to Protected EXE files using the Intel large memory model and produced by the Microsoft linker have their code and date segments intermixed There is no information in a large model EXE file itself about the locations and sizes of its data segments The PCM assumes that all the code and data segments should be protected Consequently any changes to the data in these segments static data in C parlance will cause a checksum verification failure at the next reset of the PCM The Q command must be used to unprotect large model EXE files loaded to the PCM RAM disk R Run Format R file name opt
166. k sem 6 3 KA 7 3 7 20 Linker Linking Loading PCM files B 5 Local event flag 6 8 Local event flags 7 1 localeconv localtime locking A 3 Lockup 5 20 Lockup PCM 5 19 7 20 A 1 log log10 log101 Logicmaster 90 software 9 1 Configuration software 2 1 Logicmaster 90 30 configuration Programming software Pal log A 9 longjmp A 11 lsearch lseek a 7 Itoa A 3 M Create a memory module TERMF command Makefiles B 8 malloc Index 9 Index Index 10 i with PCM matherr max A 8 Max avail buff Max avail mem memccpy memchr mememp A 2 memcpy 4 16 k 18 memicmp A 2 memmove Memory PCM Models 8 1 s 8 4 Advantag E Large Mediunr i Differences between VTOS and MS DOS Restrictions 8 4 ROM applications in 10 1 Small Differences between VTOS and MS DOS 8 2 Modules Creation from C programs VTOS M command rg modc modv mechanism Sharing 7 8 memset A 2 Microsoft C compiler 8 2 Warning 8 2 C icu d ch Installation Versions ER by PCM 2 1 p 1 LINK NMAKE NMK Saba Quick C min A 8 mkdir mktemp mktime A 14 mode modf modfl A 9 MODTESTC MODULE BAT 7 10 MODULE H modv MODVC 7 9 MS DOS 2 1 C BS ree switching from PCM 2 6 Running PCM applications under Versions supported 2 Multitasking Benefits N BH NMK Microsoft utilities 3 8 P 9
167. k was waiting for a global event flag to be set by another task when the reset occurred 7 Waiting for a timer This task had called Wait time and was still waiting Waiting for another task This task had called Wait task and was still waiting Waiting at a semaphore This task blocked on a semaphore by calling Link sem or Block sem and was still waiting 11 6 Old State When a task is waiting for some event this field contains the task s state before it began waiting Current Stack Pointer This field contains the far address of the top of the task s stack Local Event Flags Which Have Been Set This field contains the current state of the task s local event flags Local Event Flags Where Task is Waiting This field contains a local event flag mask in which all the local event flags where the task is waiting if any are set If this task is not waiting for local event flags this field is zero Global Event Flags Where Task is Waiting This field contains a global event flag mask in which all the global event flags where the task is waiting if any are set If this task is not waiting for global event flags this field is zero Other Tasks Which Task is Waiting for This field contains a task mask in which the bit of the task for which this task is waiting if any is set If this task is not waiting for another task this field is zero C Programmer s Toolkit for Series 90 PCMs User s Manual
168. libraries and the C header files which support the PCM features described in chapter 4 It is a good starting point for answers to How do I questions Chapter 6 is a discussion of PCM support for real time event driven applications like communication interactive terminal drivers and process control Anyone who develops real time PCM applications should read and understand this material Chapter 7 describes PCM multitasking its uses and special considerations for debugging applications with multiple tasks Developers of real time applications will need to read it carefully but all PCM C developers should understand the ideas in this chapter Chapter 8 is a discussion of memory models supported by the PCM There are code size performance and ease of use tradeoffs between memory models all PCM C programmers should understand these issues Chapter 9 contains several example programs along with discussion of their design and applicability Most C developers should find a starting point for their project here Chapter 10 explains how to install PCM applications in EPROM OEMs will find this chapter useful Chapter 11 is a reference for the utility programs provided with the PCM C toolkit The basic operation of these utilities is covered in other chapters Chapter 12 details the support services provided by GE Fanuc to purchasers of this development software Appendix A is a complete list of Microsoft C Version 6 0 library functi
169. limited to 64K bytes total all of which must be in DGROUP Automatic stack data is limited to 64K bytes total Two or more tasks can execute a single copy of code each task has its own data and stack Static data may be initialized in declarations VTOS initializes it every time the task runs PROMable up to about 128K bytes of code and initialized data Large Model Large model applications may not contain initialized data that changes during execution The Microsoft linker places initialized data into an area that is protected by a checksum when the executable file is loaded to the PCM Executing the SE causes the data to change At the next module reset the checksum test of the application will fail causing the PCM to delete it from memory For large model only data that is declared const should be assigned initial values All othert data must be initialized by assignment statements Code is larger and slower than any other memory model supported by VTOS Code size is limited only by PCM RAM or PROM size Constant data is limited to 64K bytes total but uninitialized static data is limited only by PCM RAM size Automatic stack data is limited to 64K bytes total Constants and other initialized data are initialized only once when the task is loaded When initialized data is modified by the application VTOS is unable to reset it to its initial values after the application runs the first time Consequently the application
170. lity program STKMOD EXE is used to specify the correct stack size Note The Microsoft compiler and linker command line switches for specifying the stack size of MS DOS executable files have no effect when used for PCM C applications The STKMOD utility must be used instead GFK 0771A Chapter 3 Creating and Running PCM C Programs 3 3 3 4 The STKMOD command line is stkmod lt exe name gt s lt decimal stack size in bytes gt or stkmod lt exe name gt s lt decimal stack size in bytes gt where exe name gt is the EXE file name with or without the file extension and dot character and lt decimal stack size in bytes gt specifies the stack size To specify a 2 Kbyte stack for HELLO EXE type stkmod hello s 2048 at the MS DOS prompt STKMOD responds with GE Fanuc Automation PCM EXE File Stack Size Utility Version 1 00 Copyright c 1992 GE Fanuc Automation North America Inc All rights reserved HELLO EXE hex dec new stack size in paragraphs 0080 128 new stack size in bytes 0800 2048 which shows that the stack size is now 800 hexadecimal or 2048 decimal bytes A stack size of 2048 bytes is ample for most PCM applications although some will require more The minimum PCM stack size is 1024 bytes and the maximum size is 65 520 Valid stack sizes are integer multiples of 16 bytes If you specify a stack size which does not meet these requirements STKMOD EXE will adjust it for you The STKMOD
171. mableControllerInstallationManual GFK 0356 This manual describes the hardware used in a Series 90 30 PLC system and explains system setup and operation Logicmaster 90 Series 90 30 and 90 20 Programming Software User s Manual GFK 0466 This manual describes operation of Logicmaster 90 30 software for configuring programming monitoring and controlling a Series 90 30 PLC Series 90 30 90 20 ProgrammableControllersReference Manual GFK 0467 This manual describes program structure and instructions for the Series 90 30 PLC PCM C Function Library Reference Manual GFK 0772 This manual provides a complete reference to all the library functions provided in the PCM runtime libraries for the PCM C toolkit The C Primer Hancock Les and Morris Krieger New York McGraw Hill Book Co Inc 1982 C A Reference Manual Harbison Samuel P and Greg L Steele Englewood Cliffs New Jersey Prentice Hall Inc Third Edition 1988 The C Programming Language Kernighan Brian W and Dennis M Ritchie Englewood Cliffs New Jersey Prentice Hall Inc Third Edition 1988 CProgrammer s Toolkit for Series 90 DC Ms User s Manual August 1996 GFK 0771A Preface Programming in C Kochan Stephen Hasbrouck Heights New Jersey Hayden Book Co Inc 1983 Learning to Program in C Plum Thomas Cardiff New Jersey Plum Hall Inc 1983 We Welcome Your Comments and Suggestions At GE Fanuc Automation we strive to produce
172. mand interpreter in interactive mode and HELLO EXE is in your PC s current directory you are ready to load it to the PCM Use the PCM L Load command type L HELLO EXE at the PCM prompt You should see the middle LED on the PCM flash while the file is being loaded When the file transfer has completed another blank line and gt prompt will be displayed Verify that the file was loaded by using the PCM D Directory command HELLO EXE should be one of the files listed gt dHELLO EXE 0616 00A0 The hexadecimal numbers which follow the the file name are its entry point address Entry points are shown only for executable files and only if your PCM has firmware version 3 00 or later Entry point addresses are useful for debugging C programs with hardware debuggers and for interpreting the output of the PCMDUMP utility See chapter 11 Utilities for information on the PCMDUMP utility C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Running a PCM Task The PCM R Run command is used to execute an EXE file as a PCM task At the PCM prompt type R HELLO EXE The file extension EXE is required by the PCM command interpreter When the program is executed TERMF will display its output Hello world I m running as task Of hex under VTOS version 3 00 The Run command can also be used to load PCM programs from your PC If the specified EXE file has not been stored to the PCM the comm
173. maphore can easily cause a semaphore deadlock The other task ast function blocks onthe tmp buf sem semaphore When the semaphore is available other task ast tests port alloc flag inthe shared memory module If the flag contains a non zero value indicating that the serial port is inuse other task ast unblocks the semaphore and waits 50 milliseconds Then other task ast blocks on the semaphore and tests the flag again This process is repeated until the flag indicates the port is available When the port becomes available other task ast allocates it for the current task and then unblocks the semaphore At this point other task ast isready to send a message to the OIT and wait for input as described above When the OIT transaction is complete other task ast blocks on the semaphore until the flag is available Once the semaphore is acquired the port is released by setting the flag to zero and the semaphore is unblocked GFK 0771A Chapter 9 Example Programs 9 5 DATA The DATA task has only one function main When VTOS starts main it waits for four seconds to give the other PCM tasks time to complete their initialization If DEBUG is defined main opens the debug file and announces its task name and number Then it opens the database file and checks its size If the database file is smaller than the size specified by the product of RECORD SIZE and MAX RECORDS main extends it to the correct size Next main opens separate channels on the
174. ms A d _setfont A 5 _pg_defaultchart _setgtextvector A 5 GFK 0771 did Index _setlinestyle A 5 _setpixel A 5 _setpixel_w _settextcolor _settextcursor A 5 _settextposition A 5 _settextrows A 5 _settextwindow _setvideomode A 5 _setvideomoderows A 5 _setvieworg A 5 _setviewport A 5 _setvisualpage A 5 _setwindow A 5 _splitpath A 3 _status87 A 9 _strdate A 14 _strerror A 12 _strtime _strtold A 3 _tolower _toupper A 2 _unregisterfonts A 5 _wrapon A abort A 11 Abort dev 5 7 abs A 3 access acos acosl A 9 Address modifier Alloc com timer alloca Altemate math package b Index 4 API PLC Interface 5 13 Services 4 3 api initialize 5 13 argc argv asctime asin A 8 asinl A 9 assert A 11 AST function 6 15 AST thread 6 3 ASTH AST NOTIFY b 2 6 3 AST1 C 7 14 AST2 C 7 14 Asynchronous trap AST 6 15 x Differences from MS DOS interrupts 6 14 Execution thread 6 3 Functions Task state while waiting for AST Asynchronous trap AST e 2 atan atan2 atan21 A 9 atanl atexit A 11 atof atoi A 3 atol A 3 B B Ns LEDs TERMF command B 5 bdos bessel A 9 Block_sem 5 3 ka 7 20 bsearch Buffer manipulation GFK 0771 GFK 0771 C C Clear the PCM TERMF command B 6 C source files 5 1 CES ae serial communication D 1 cabs A 8 cabsl A 9
175. n Pret 5 1 VTOS ke 5 1 VTOS Services By Category 5 1 Event Flag Functions 5 2 Asynchronous Trap Functions 5 3 Semaphore Functions 5 3 Time of Day Clock Functions 5 4 Timer Functions nti echt ya dans sha a oce bob Red dak EN ek ead ewe 5 5 Communication Timer Functions LL 5 5 Memory Management Functions 5 6 Memory Module Functions esee 5 7 DeviceI O Functions 5 7 Device Driver Support Functions 6 06 e ee 5 9 Miscellaneous Functions 5 10 VTOS EEN 5 10 NT OS Iypes ie Steet e t e er abest Med s 5 11 VTOS Global Data ceste Eee e e E uad 5 13 The PLC API Tnterface i i seem mace e e ries 5 13 PLC API Services By Categorie 5 13 PECZAPLITyp s dac ayaa ad cet att V e dort vete e A gates 5 17 PEC AP Global Data 5 2 entrer teeccebreeseMbELDeepsecreeee mue 5 18 Using Standard C Libraries 6 666 5 19 lestricHOflS ss eb ada ie E e E woman Pe wees 5 19 Using printf In Small and Medium Models 5 20 Header Files 4 2 eter ig Se ead pedestal i deiere Ned See 5 20 Chapter 7 PCM Real Time Programming 0 cee cee eee eee eee 6 1 Asynchronous Events 6 1 VTOS Asynchronous I O Scenario 6 1 VTOS Asynchronous Timer Scenario 6 2 Local Event Flag Notification 6 6 66 6 3 AST Notification and Execution Threads 6 3 Strategies For Predictable Real Time Performance 6 4 Using WAIT Mode Even
176. n ASCII string containing two hexadecimal digits which specify the ID One of the following codes is returned Code Description 00 Series90 70 PCM with no daughter board 1D Series 90 70 PCM with a 512K daughter board 640K bytes total 1E Series 90 70 PCM with a 256K daughter board 384K bytes total 1F Series 90 70 PCM with a 128K daughter board 256K bytes total 1C Series 90 70 PCM with a 64K daughter board 192K bytes total FF Series 90 30 PCM model IC693PCM300 160K bytes FE Series 90 30 PCM model IC693PCM301 192K bytes FC Series 90 30 PCM model IC693PCM311 640K bytes 80 Graphics Display Coprocessor Module with a video daughter board 81 Series90 70 AlphanumericDisplay Coprocessor Module 82 Series90 30 AlphanumericDisplay Coprocessor Module H Get PCM Firmware Revision Number GFK 0771A Format H This command returns the firmware release number of the PCM The ASCII string returned by the PCM contains a single digit for the major revision number a period and two digits for the minor revision number For example Software revision number is 3 00 Appendix B PCM Commands B 7 Initialize Device Format device name device initialization string This command sends the specified initialization string to the specified device Currently the two serial devices COM1 and COM2 and the CPU device support this command A space character is required be
177. n a device operation completes These functions can all be used for installing and operating custom device drivers A future edition of this manual will discuss VTOS device drivers Install isr may also be used to install software interrupt vectors so that two or more tasks can share a single copy of library function code GFK 0771A Chapter 5 PCM Libraries and Header Files 5 9 Miscellaneous Functions VTOS Macros 5 10 Table 5 12 Miscellaneous Functions Function Name Purpose Define led Defines the function of one of the programmable light emitting diodes LEDs Get board id Returns the PCM hardware type Get pom rev Returns the revision number of VTOS Set dbd ctl Sets theSeries 90 70 PCM daughterboard control register Set led Sets the state of one of the LEDs Set vme ctl Sets the VMEbus access parameters in a Series 90 70 PCM Where am i Returns the PLC rack slot location of the PCM Define led and Set led are used to control the two programmable light emitting diodes LEDs Get board id may be used to determine the PCM hardware type and memory size Where am i is used to determine its Series 90 PLC rack slot address and Get pcm rev returns the PCM firmware version Set vme ctl is used to access memory on the Series 90 70 VMEbus in bus master mode and Set dbd ctl is used to control custom Series 90 70 PCM daughter boards such as video controllers Two VTOS macros are provi
178. n circuit emulators offer a unique capability which can often be invaluable an execution trace history collected by the hardware Solving software problems often requires knowing how the code reached a particular point and in circuit emulators provide this information without special trace code Their cost is frequently justified by improvements in productivity and time to market Using an in circuit emulator requires a correlation between code and data addresses in the map of the EXE file and the corresponding addresses in PCM memory The technique described in the previous section is also applicable to in circuit emulators Chapter 7 Multitasking 7 21 Chapter 8 Memory Models The segmented architecture of the Intel 80x86 family of microprocessors gives rise to several different memory or compilation models These models are nothing more than alternate views of the segmented architecture Each model offers a different tradeoff between code speed and size on one hand and restrictions on code and data sizes on the other This chapter discusses the memory models supported by the PCM and their implications for developing PCM C applications Models Supported By the PCM GFK 0771A VTOS supports the small medium and large memory models Each is discussed below Small Model In the small model the code data and stack segment registers of the microprocessor are loaded by VTOS when the application starts By default function call
179. n small and medium models they are redefined by macros The model independent versionsbelow arerecommended _fstrcat _fstrchr _fstremp _fstrcpy _fstrcspn _fstricmp _fstrlen _fstrlwr _fstrncat _fstrncmp _fstrncpy _fstrnicmp _fstrnset _fstrpbrk _fstrrchr _fstrrev _fstrset _fstrspn _fstrstr _fstrtok _fstrupr These functions are supported in all memory models _nstrdup strerror _strerror These functions are not supported in any memory model C Programmer s Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A GFK 0771A Table A 16 System Calls Function Memory Model disable enable FP OFF FP SEG These functions are supported in all memory models bios disk _bios_equiplist _bios_keybrd _bios_memsize _bios_printer _bios_serialcom _bios_timeofday bdos _chain_intr _dos_allocmem _dos_close _dos_creat _dos_creatnew dos findfirst dos findnext dos freemem dos getdate dos getdiskfree dos getdrive dos getfileattr dos getftime dos gettime _dos_getvect _dos_keep _dos_open _dos_read _dos_setblock _dos_setdate dos setdrive dos setfileattr dos setftime dos settime dos setvect dos write dosexterr _harderr _hardresume _hardretn int86 int86x intdos intdosx segread These functions are not supported in any memory model Appendix A Microsoft Runtime Library Support A 13 A 14 Tabl
180. nd the NOWAIT versions are declared in UTILSNWH Table 5 18 PLC Hardware Type Configuration and Status Information Function Name Purpose get cpu type rev Returns the PLC CPU hardware type and firmwarerevision get cpu type rev nowait get memtype sizes Returns the sizes of user configurablePLC memory types get memtype sizes nowait che priv level Changes the PLC access privilege level of the calling task che priv level nowait update plc status Updates PLC status data in the global structure update plc status nowait plc status info PLC Program and Configuration Checksum Data The WAIT mode functions are declared in CHKSUM H and the NOWAIT versions are declared in CHKSUMNWH Table 5 19 PLC Program and Configuration Checksum Data Function Name Purpose get prgm info Returns the PLC program checksums get prgm info nowait get config info Returns the PLC configuration data checksums get config info nowait Reading PLC Data References The WAIT mode functions are declared in SYSMEM H and the NOWAIT versions are declared in SYSMEMNWH Table 5 20 Reading PLC Data References Function Name Purpose read sysmem Reads up to 2048 bytes of a single PLC reference type read sysmem nowait These WAIT mode functions are declared in PRGMEM H and the NOWAIT versions are declared in PRGMEMNWH Table 5 21 Reading Series 90 70 PLC Data References Function Name
181. ndicates you may choose either 1 or 2 Commands PCM commands are summarized in the following table Table B 1 PCM Commands Command Description L Loada file from the PC S Save a file to the PC D Show a Directory of files in memory X eXterminate delete a file R Run an executablefile K Killarunning task C Clear the PCM Execute a batch file F Show availablememory G Get PCM memory ID H Get the PCM revision number B Configure a user LED U Reconfigure the PCM M Create a memory module PT Show PCM task information PC Show PCM config errors PM Show reset type and mode PL Show the location of the PCM PD Dump the state of the PCM just before the last reset to a PC file Il Enter INTERACTIVE mode tI Exit INTERACTIVE mode The following commands are also available The I Initialize a device command is often used to set the communication parameters of PCM serial ports The others are seldom used except by PCOP GFK 0771A Appendix B PCM Commands B 3 Table B 2 PCM Commands Command Description Initializea device Format the ROM device PCM 301 only Get LED configuration Set protection level Verify a file Wait for a background task Set upper memory limit KE lt 0070 The remainder of this appendix provides detailed descriptions of the commands listed in the preceding tables The commands are presented in alphabetical order Execute a Batch File Form
182. nous events like communication and operator interaction behind the scenes Effective PCM applications tend to use multiple tasks and multiple execution threads within tasks By contrast MS DOS encourages a single threaded polling loop style of program design However PCM applications designed in this way are substantially slower than they could be C programmers whose experience is limited to MS DOS applications should read and thoroughly understand the material in chapters 6 and 7 of this manual before undertaking PCM programs Getting Started The remaining chapters in this manual contain information on various aspects of C program development for PCM applications Depending on your background you may already be familiar with the material in some chapters Here is a list of the chapters with recommendations on who should read each one Chapter 2 covers the installation of the PCM C toolkit on your PC You should start here if the software has not been installed Chapter 3 is a step by step introduction to the process of compiling linking loading and running PCM C applications If you are not familiar with these procedures you should go through each step on your PC while you read chapter 3 Chapter 4 is an overview of PCM features available to C programmers All PCM C developers need to understand these features C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Chapter 5 is an overview of PCM C
183. ns apply in small and medium models VTOS uses separate data and stack segments even in the small and medium models Consequently many functions which take pointers as parameters are restricted in small and medium models to DS based addresses addresses of global or static variables for these parameters A few functions may be used only in large model Caution There is no enforcement of these restrictions The user is responsible for avoiding the use of unsupported functions and for the correct use of conditionally supported functions Errors will occur when unsupported functions are used or conditionally supported functions are used incorrectly The consequences range from immediate PCM lockup to intermittent or minor errors with no apparent connection to the unsupported or conditionally supported function Every C source file which calls one or more standard C library functions must include all the header files where the prototypes for those functions are defined This is absolutely essential in the small and medium memory models Failure to include header files where prototypes for standard C library functions are defined will often result in PCM lockup or unexpected operation GFK 0771A Chapter 5 PCM Libraries and Header Files 5 19 Using printf In Small and Medium Models The function prototypes for printf anditsrelatives fprintf sprintf and vprintf see STDIO H specify that the control string parameter isa far pointer However
184. o Wait time Suspends execution of the calling task for the specified time Up to 32 general purpose timers may be used by PCM applications Timers are started bycalling Start timer and are programmed to expire after either a specified number of days hours minutes seconds and milliseconds or a specified long integer number of milliseconds in the future Timers may be programed to restart automatically when they expire or for one shot operation When the timer expires a specified task usually the task which started the timer is notified either by a local event flag or an asynchronous trap A timer which is running can be stopped by calling Cancel timer A task may suspend its own execution for a specified time interval by calling Wait time When the time expires the Wait time call returns Communication Timer Functions Table 5 7 Communication Timer Functions Function Name Purpose Alloc com timer Allocates a communication timer to the calling task Cancel com timer Stops a communication timer Dealloc com timer De allocatesacommunicationtimer Start com timer Startsapreviouslyallocated communication timer Four communication timers are available in the PCM They require far less execution overhead than general purpose timers and are recommended when short time intervals are required A task must call Alloc com timer to reserve a communication timer before it can be used Communication timers are
185. ock of dual ported memory on the VMEbus can be allocated by calling Get dp buff Applications can also reserve a specified region of VMEbus memory by calling Reserve dp buff Applications which use VME dual ported memory should call one of these services to avoid memory conflicts with PLC API services and built in backplane communication services Unused VME dual ported memory is freed by calling Return dp buff Memor y Module Functions Table 5 9 Memory Module Functions Function Name Purpose Get mod Returns the address of a named memory module A task may obtain the address of a named memory module by calling Get mod It returns the far address of the mod hdr structure at the start of the memory module Device UO Functions Table 5 10 Device UO Functions Function Name Purpose Abort dev Aborts one or moreI O operations ona previously opened I O channel Close dev Closesapreviously openedI O channel Devctl dev Performs a specified control operation on a named device Ioctl dev Performs a specified control operation on a previously opened I O channel Open dev Opens a channel on a named I O device Read dev Returns input data froma previously opened I O channel Seek_dev Positions the data pointer of a previously opened I O channel toa specified location Special_dev Performs a special operation ona previously opened I O channel Write_dev Sends output toa previously opened I O channel
186. odule TASK2 also imports other task ast from TASK_ASTC to process ASTs it receives from TASKI The main function of TASK2 performs initialization in much the same way as TASKI Before entering its loop main calls Read dev in AST NOTIFY mode so that commreq ast will be called when the first COMMREO arrives TASK ASTC This source file contains the function other task ast itis linked into both TASK1 and TASK2 The function name derives from its use each copy of the function processes ASB from the other task When TASK1 or TASK2 posts an ast to the other task VTOS calls other task ast in the target task The ast ptr parameter points to an ast blk structure that contains a data value sent from the other task The function displays the data value on the OIT prompts the user to enter a new value and then waits for user input Only decimal digits the destructive backspace and the Return Enter character are accepted as input all other characters are rejected Each backspace character erases the digit character that is immediately to the left of the cursor if there is one Return terminates the collecting of input characters The digit characters are converted to a 16 bit word value and sent to a register table R location in the PLC CPU Both TASK1 and TASK 2 use PCM serial port 2 to communicate with the OIT When one of the tasks is waiting for data from the user the other task may receive an AST and try to display its own message The s
187. of STDIN Device Access Block This field contains the segment part of the far address of a device access block used as the STDIN channel by this task The offset part of the address is zero Segment of STDOUT Device Access Block This field contains the segment part of the far address of a device access block used as the STDOUT channel by this task The offset part of the address is zero Segment of STDERR Device Access Block This field contains the segment part of the far address of a device access block used as the STDERR channel by this task The offset part of the address is zero Task environment block address This field contains the segment part of the address of the environment block for this task The offset part of the address is zero Link field for tasks waiting at semaphore This field may contain the segment part of the FAR address of another task control block When two or more tasks wait at the same named semaphore their task control blocks are placed on a linked list in the order of their priorities Semaphore address if waiting at semaphore If the task is waiting at a named semaphore this field contains the segment part of the semaphore address otherwise this field contains zero Named semaphores always begin at offset zero in the specified segment Flag for enabling ASTs This field is one when ASTs are enabled for the task other wise ASTs are disabled Chapter 11 Utilities 11 7 VME window selector code This
188. of a block of VMEbus memory The application designer usually chooses a location for this memory block before the programs are written However it is possible for other PCM code to try to use the same memory block It is important for all PCM code which uses VMEbus memory to allocate or reserve it through the VTOS Gert dp buff or Reserve dp buff respectively If these functions are used VTOS will prevent VMEbus memory conflicts This example shows how to place a memory block for VME data transfers at the top end of VMEbus dual port RAM reserve it and then free it when it is no longer needed The example assumes that the PLC CPU will use a VMEWRT function block to transfer data to the PCM and that the first data word is used as a lock to control access to the data C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A GFK 0771A include vtos h include dos h define VME SIZE 4 1024 define VME LIMIT 32 1024 define VME OFFSET VME LIMIT VME SIZE word vme available void far vme ptr char local buff VME SIZE FP SEG vme ptr FP OFF vme ptr 0OxA000 VME OFFSET vme available Reserve dp buff vme ptr VME SIZE SUCCESS if vme available disable while vme ptr 1 _enable Wait_time MS_COUNT_MODE 0 5 _disable vme ptr 1 enable memcpy local buff vme ptr VME SIZE vme ptr 0 Return dp buff vme ptr The
189. om immediate PCM lockup to intermittent or minor errors with no apparent connection to the unsupported or conditionally supported function Every C source file must include the header file where the function prototype is defined for each standard library function which it calls This is absolutely essential in the small and medium memory models Caution Failure to include header files where prototypes for standard library functions are defined often results in PCM lockup or unexpected operation Table A 1 Buffer Manipulation Functions Function Memory Model memccpy These functions are supported in all memory models In small and memchr medium models they are redefined by macros The model independent memcmp versionsbelow arerecommended memcpy memicmp memmove memset _fmemecpy These model independent functions are supported in all memory models _fmemchr and are recommended _fmememp _fmemcpy _fmemicmp _fmemmove _fmemset swab This function is supported in large model only Table A 2 Character Classification and Conversion Functions Function Memory Model isalnum These functions are supported in all memory models isalpha isascii iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit toascii tolower _tolower toupper _toupper A 2 C Programmer s Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A GFK 0771A Table A 3 Data Con
190. ommunication timer timeout functions or device drivers by calling Iset ef while other functions can set them by calling Set ef C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 A task can wait for one or more global or local event flags to be set by external events by calling Wait gef or Wait ef respectively Event flags should be reset before a task waits for them otherwise Wait gef or Wait ef willreturn immediately if one of the specified flags happens to be set AsynchronousTrap Functions Table 5 3 Asynchronous Trap Functions Function Name Purpose Disable asts Prevents the calling task from processing ASTs Enable_asts Permits the calling task to process ASTs Post_ast Sends an asynchronous trap to a specified task Wait_ast Suspends execution of the calling task until an AST is received Asynchronous traps ASTs may be set for timer and device I O events See Timer Functions and Device I O Functions below A task may suspend execution and wait for one or more traps to spring by calling Wait_ast When the event occurs an AST handler function which was previously specified for that event is executed After the AST function returns the Wait_ast function call which suspended the task also returns and the task resumes normal execution Tasks may prevent ASTs from being processed by calling Disable asts and may resume AST processing by calling Enable_asts A task may send an A
191. on of the Series 90 PCM C toolkit these directories and files are created on your computer s hard disk Table D 1 PCM C Directories and Files Directory File Purpose NPCMC AAREADME How to install this software this list of files AUTOEXECBAT AUTOEXECBAK If INSTALLreplaces AUTOEXEC BAT BLD_PROM EXE Utility program for creating EPROM images BLD_PROM MSG Message file for BLD_PROM EXE CC 600 CC BAT MS DOS batch file for compiling one C source CC MVC CLINKK 600 CLINK BAT MS DOS batch file for creating a PCM EXE from one object CLINK MVC DOSC BAT Sets LIB and INCLUDE environment variables for MS DOS compile and link PCMC BAT Sets LIB and INCLUDE environment variables for PCM compile and link PCMDUMPEXE Utility program for diagnosing PCM task states PCMDUMPMSG Message file for PCMDUMPEXE STKMOD EXE Utility program for setting PCM task stack size STKMOD MSG Message file for STKMOD MSG V6_BLD BA V7_BLD BAR VC1_BLD BAT GFK 0771A D 1 D Directory File Purpose PCMC EXMPLES ALARM C C source from text of chapter 6 APP MOD H ASTH C header file from text of chapter 7 AST1 C C source file from text of chapter 7 AST2 C C source file from text of chapter 7 COPR TXT Example PROM copyright text file HELLOC Demonstration program 1 MAKEFILE 1 NMAKE recipe for building HELLO EXE MAKEFILE 600 MAKEFILE 700 MAKEFILRMVC MODTESTC C source file from text of chapter 7 MODULE BAT PCM batch fil
192. ons and includes the level of support for each function in the PCM Everyone will use this material on an as needed basis Appendix B is a complete reference to the commands supported by the PCM command processor for configuration and operation of the PCM This material is also useful on an as needed basis Appendix C describes PCM batch files which use the commands in appendix B to control the operation of the PCM when it is powered on or reset This material is not unique to C applications All PCM developers should be familiar with it Appendix D is a list of the directories and files created when this software is installed A short description of each file is also provided GFK 0771A Chapter 1 Introduction 1 3 Chapter 2 Installation This chapter describes the installation process for the PCM C toolkit What You Will Need These hardware items are required to develop C applications for PCMs GFK 0771A A GE Fanuc Series 90 PLC containing at least one PCM An IBM PC PC XT PC AT or PS 2 GE Fanuc Workmaster Workmaster II or CIMSTAR I industrial computer or other IBM compatible MS DOS PGDOS based personal computer PC with a hard disk and at least one RS 232C serial port running MS DOS 3 3 or later Your computer must have enough unused hard disk capacity to install Microsoft amp C up to 25 megabytes depending on your version and what you choose to install and the PCM C toolkit software about 600K bytes and
193. or Series 90 PCMs User s Manual August 1996 GFK 0771A Task SEM2 also gets a delay value from its command line assigns the module data address to a pointer and links to the same semaphore When it acquires the semaphore it enters its own for loop In the loop SEM2 tests the access flag inthe module data to determine whether there is new that is DIRTY data If so the module is marked BUSY Next SEM2 releases the semaphore before calling printf The call must not be made within semaphore protected code because printf makes a VTOS request to write the data to SEM2 s STDIO device However the BUSY value of the access flag prevents other tasks from writing new data to the module After printf returns SEM2 re acquires the semaphore and changes the access flag value to FREE Then it releases the semaphore and waits before trying to acquire it again SEM2 C include vtos h include lt stdio h gt include lt string h gt include sem h void main int argc char far far argv mod_hdr far mod_ptr mod_data far p word sem_hndl wait_time word task Get task id if argc lt 2 wait time atoi argv 1 0 wait_time 2 printf task SEM2 id d wait time d n task wait time mod ptr Get mod MOD NAME P mod data far mod ptr 1 sem hndl Link sem SEM NAME for if p gt access_flag DIRTY p gt access_flag BUSY Unblock sem sem hndl printf ta
194. ory in PCM RAM When there are gaps in free memory Get best buff searches the list of free blocks to find the smallest one which fits the requested size Get buff allocates a buffer from the first free block which is large enough Get buff isfaster but Get best buff is recommended for applications which use many temporary buffers because it minimizes free memory fragmentation Note that the built in I O device drivers use temporary buffers heavily Note The standard C library function malloc isredefined in PCMC INCIUDE MALLOC HndPCMC INCLUDE STDLIB Has Get_buff You may wish to modify these header files so that malloc is redefined to be Get best buff A buffer which was allocated by either Get buff or Get best buff may be deallocated by calling Return buff Ifthe returned buffer is adjacent to one or two free memory blocks they are consolidated This is the PCM s only runtime garbage collection facility The total free memory size in bytes is returned by Max avail mem and the largest free block size is returned by Max avail buff Applicationscan call Get mem limit to determine whether PCM memory has been partitioned to exclude some memory from VTOS by the command interpreter Y Set Upper Memory Limit command A pointer to the start of the excluded partition is returned if there is one otherwise a NULL pointer is returned C Programmer s Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A In Series 90 70 PCMs a bl
195. ory is tight Time of Day Clock Functions 5 4 Table 5 5 Time of Day Clock Functions Function Name Purpose Elapse Returns a count of milliseconds since the last time its count was reset Get date Returns the current date Get time Returns the current time of day Get date and Get time return the current date and time respectively from the PCM time of day clock The PCM clock is synchronized with the PLC time of day clock once per second The PLC time of day clock can be read directly by using read date read time or read timedate described below Elapse returns a count of milliseconds since the last time it was reset by passing zero as its parameter The Elapse count is unaffected by PCM time of day clock synchronization Caution Do notuse Get time to calculate the time interval between two events The value returned by Get time isaffected by synchronization of the PCM time of day clock with the PLC CPU If the PCM clock is re synchronized with the PLC CPU between two calls to Get time the calculated time interval will be incorrect Always use Elapse to determine time intervals PCM clock synchronization has no effecton Elapse C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Timer Functions Table 5 6 Timer Functions Function Name Purpose Cancel timer Stops a timer and undefines it Start timer Defines a timer and starts it counting from zer
196. ption shows all files hidden and non hidden in the PCM RAM disk Hidden files may include files loaded to the PCM using the Hidden attribute as wellas file data blocks appended to files created by PCM applications DP This command option shows files in the PCM system EPROM These files provide VTOS functionality DR This command option shows files in the PCM option EPROM These files provide functionality such as MegaBasic CCM etc When the D command is invoked from INTERACTIVE mode an entry point address is shown for executable EXE files gt D HELLO EXE 0616 00A0 The entry point is displayed as a segmented FAR address In the example above HELLO EXE is a C program which was created on a PC and then loaded to the PCM RAM disk using the L Load command The entry point is useful for debugging medium and large model PCM applications C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A F Show Free Memory Format F In interactive mode this command displays the amount of free PCM memory as two decimal numbers Total available memory is xxxxxx bytes Largest available block is yyyyyy bytes The first is the total of all available memory The second is the size of the largest free memory block Both sizes are expressed in bytes No errors are returned G Get Hardware ID Format G This command returns the ID number of the PCM hardware configuration The value is a
197. put gt swap R SWAP EXE B R SWAP EXE B gt task 14 my flag 2 task 14 other flag 1 task 15 my flag 1 task 15 other flag task 14 other flag task 15 other flag task 14 other flag task 15 other flag ww wm NENEN The example above uses global event flags for the rather trivial purpose of switching execution from one task to another However it should be obvious how this technique can be adapted for sending any kind of signal between tasks Local event flags can also be used for signalling between tasks Shared Memory Modules 7 8 VTOS shared memory modules provide a mechanism for sharing data between two or more tasks From the point of view of a VTOS task memory modules are blocks of PCM memory which are accessed through pointers Memory modules may be created using the PCM M Create a Memory Module command The module name and its size in bytes must be specified when the module is created For example this command M MODULE1 6 creates a memory module named MODULE 1 which contains 6 bytes By default memory modules have no checksum protection However the PCM Q Set Protection Level command may be used add checksum protection to memory modules making them read only modules C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A There are two mechanisms for determining the address of a memory module from a PCM application The VTOS Get mod service returns the far
198. quality technical documentation After you have used this manual please take a few moments to complete and return the Reader s Comment Card located on the next page Henry Konat Senior Technical Writer GFK 0771A Preface v Chapter 2 Chapter 3 Chapter 4 GFK 0771A Introduction Installation Creating and Running PCM C Programs Why Develop PCM Applications nc AppropriateApplications Limitations tee fe date e ent ALES RR d ens Expertise Required vi ii a REIS Getting Started cose debe eines Mae hele Bows What You Will Need sssssssss eee eens Microsoft C Installation Requirements 0 000s cece Installing the PCM Cook Adding PCMC to Your MS DOS Path 0 00000008 Adding PCMC LIBto Your LIB Environment Variable Adding PCMC INCLUDE to Your INCLUDE Environment Variable Switching Between PCM and MS DOS Application Development Creating C Source Files ics trito dee EE ih Compiling Sources e venae ee ke e EEN be dele dE e s Linking ODbjecte irrita en teas e ene a a Specifying the Stack Size 6 eee eee Loading Executable Files L LL Running a PCM Task Debugging a PCM Task 6 eee Using Makefile code eec xe unte us C Programmer s Toolkit for Series 90 PCMs User s Manual August1996 Contents 1 1 1 1 1 1 1 2 1 2 1 2 x 2 1 2 1 2 2 2 3 2 4 2 5 2 6 3 1 3 2 3 3 3 3 3 5 3 7 3 7 3 8 vii Cont
199. r example executable file from chapter 3 HELLO EXE It is assumed to be in the current PC directory Since PCMEXEC BAT will try to run HELLO EXE it should be given the default name HELLO EXE in the PROM This time a semicolon as well as Enter is required Make HELLO EXE visible by answering Enter to the next prompt EXE files should always be made visible The PCM directory command D R will provide the entry point address in the PROM for debugging purposes but only if the file is visible BLD_PROM informs us that the stack size for HELLO EXE is 800 hexadecimal 2048 decimal bytes HELLO EXE is the last file to be loaded into ROM so the next prompt for a module name is answered with a semicolon and Enter BLD PROM tells us that the empty space in ROM begins at address C43F 0 hexadecimal and then exits It has created a binary PROM image file named ROM 001 which contains exactly 128K bytes 131072 decimal C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Customizing the PROM Copyright String Each PCM PROM begins with a copyright message string The copyright message actually has three purposes 1 Itis a notice of intellectual property rights in the PROM firmware 2 It provides a trigger for enabling checksum verification of the PROM contents when the PCM is powered on 3 Italso triggers verification at power up that the firmware has been installed in the correct hardware Thefile PCMC
200. rammer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Regulating the Timing of COMMREQ Messages There are tvo COMMREO timing issues the time when the first COMMREO for a PCM task arrives relative to task initialization and the speed with which repeated COMMREQs arrive The target PCM will reject a COMMREO that is addressed to a valid service point if a COMMREQ is sent before the PCM program has opened the service point PLC ladder programs must provide some mechanism for preventing COMMREQs from being sent before the target PCM application is ready to receive them In particular a PLC power cycle or brownout causes all the PCMs in the PLC to re initialize themselves The first COMMREO to any PCM must be delayed until the PCM has finished initialization VTOS has started the application tasks and the application has opened the target service point s The simplest method for preventing a PLC program from sending COMMREQs before the target PCM is ready to receive them is to start a timer on the first scan of the PLC program When a fixed time delay expires program logic enables the COMMREQ function blocks The recommended delay is five seconds ThePLCprogramfolders PCMC EXAMPLES DEMO_3T PLC_3 nd PCMC EAMPLES DEMO_3T PLC_70 installed with the PCM C toolkit contain PLC programs with timers to prevent COMMREOS during the first five seconds of program execution The other COMMREO timing issue concerns the speed at whi
201. re copied to the PCMC EXAMPLES DEMO_ 3directory on your PC when you installed the PCM C toolkit In addition the PLC ladder program that cooperates with the PCM tasks is provided in separate Logicmaster 90 program folders for Series 90 30 and Series 90 70 PLCs These folders are PCMC EXMPLES DEMO_3T PLC_a d PCMC EXAMPLES DEMO_3T PLC_70 respectively PLC Hardware Requirements The demo will run in a Series 90 70 PCM with any or no memory expansion board A Series 90 30 PCM 301 or PCM 311 is required in order to configure serial port 2 for RS 232C operation with the OIT Our OIT was a VT100 from Digital Equipment Corp If you have an RS 422 RS 485 terminal you can use a PCM 300 Logicmaster 90 Compatibility The Logicmaster program folders were created using version 2 04 of Logicmaster 90 30 and version 3 04 of Logicmaster 90 70 If you have one of these versions or a later one you can select the appropriate folder directly from the Logicmaster Programmer and Configurator packages If you have an earlier Logicmaster version such as a Release 2 version of Logicmaster 90 70 you will not be able to select the PLC program folder You can print the text file version of the program for your PLC PLC_30 PRT or PLC 70 PRT in the NPCMCNEXMPLESNDEMP 3 Hirectory and then enter the program manually into the Logicmaster 90 Programmer GFK 0771A 9 1 H Logicmaster 90 30 Configuration The Logicmaster 90 30 I O configuration specifies a PC
202. rect include files and libraries for PCM C applications When you develop C applications for MS DOS you will need to change these environment variables before compiling or linking Two batch files in the PCMC subdirectory PCMC BAT and DOSC BAT are provided for redefining the INCLUDE and LIB environment variables to the correct values for PCM and MS DOS C development respectively These batch files are created automatically during the installation process They reflect the hard drives and directories where the PCM C toolkit and Microsoft C are actually installed Note If a C application program intended for MS DOS is inadvertently compiled and linked using the INCLUDE and LIB definitions for the PCM the error message run time error Linked for execution on a PCM not DOS willbe displayed when MS DOS runs the application If you load an MS DOS program to your PCM and attempt to run it the program will terminate immediately no error message is printed 2 6 C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Chapter Creating and Running PCM C Programs 3 This chapter describes the process of developing C applications for the PCM It will show you how to create a simple demonstration program and run it in your PCM Creating C Source Files C language source files are created using a text editor Any editor which produces text files using only the seven bit ASCII character set may be used Some wor
203. rogram MODVC prints the addresses of all the memory modules passed to it MODV C include vtos h include lt stdio h gt void main int argc char far far argv int modc mod_hdr far far modv int i for i 0 i lt modc i printf modv d 04x 04x n i word far amp modv i 1 word far amp modv i GFK 0771A Chapter 7 Multitasking 7 9 7 10 Here is another example which shows how two VTOS tasks may share a memory module The example comprises four files MODULE BAT MODULE H T1 C and T2 C MODULE H defines two global event flags the name of a shared memory module and the structure type of the data in the shared module All but the module name will be used by both application tasks MODULE H define DATA READY GEF EF O00 define EXIT GEF EF 01 define APP MODULE MODULE1 typedef struct word task_num char far s mod_data T1 C includes MODULE H It uses the module name defined as APP MODULE to get the module address from Get mod If the module exists T1 writes values to the task num and s members ofits data structure Then it resets global event flag EXIT GEE sets DATA READY GEE and waits for EXIT GEF to be set This event flag signals that the data in the str array in T1 s stack segment is no longer needed T1 can exit returning its stack and data segments to VTOS free memory T1 C include lt vtos h gt include lt stdio h gt
204. ry ROM Chapter 11 Utilities Chapter 11 describes the utility programs provided with the PCM C toolkit iii Preface Chapter 12 GE Fanuc Support Services Chapter 12 describes the consultation services provided by GE Fanuc to each purchaser of the PCM C toolkit Appendix A Microsoft Runtime Library Support Appendix A lists all the functions provided in the Microsoft C 6 00 runtime libraries and indicates which ones are applicable to the PCM Appendix B PCM Commands Appendix B is a complete reference to the PCM command interpreter Appendix C Batch Files Appendix C describes how to control PCM operation with batch files Appendix D PCM C Directories and Files Appendix D lists all the directories and files created on your hard disk during installation of the PCM C toolkit Related Publications For more information refer to these publications Series90 70 ProgrammableControllerInstallationManual GFK 0262 This manual describes the hardware used in a Series 90 70 PLC system and explains system setup and operation Logicmaster 90 70 Programming Software User s Manual GFK 0263 This manual describes operation of Logicmaster 90 70 software for configuring programming monitoring and controlling a Series 90 70 PLC and or remote I O drop Series90 70 ProgrammableController Reference Manual GFK 0265 This manual describes program structure and instructions for the Series 90 70 PLC Series 90 30 Program
205. s a character or file oriented channel whether the channel has input data available and if so how much whether the channel is ready for output data and whether an ASCII ETX Ctrl C character has been received to purge the channel s input or output buffer to control serial port Send Break RIS and DTR status and check Break Detect status Special dev is used to determine the size of a file accessed through a specified channel or set its maximum size to specify passwords for PLC CPU data access to set serial port communication parameters to set the Series 90 PLC rack slot destination address for backplane messages to set files to read only access mode to set the memory type and starting offset for PLC CPU data access and to set high priority mode for backplane messages Device I O operations may be performed in WAIT EVENT NOTIFY or AST NOTIFY mode In WAIT mode the function call does not return until the specified operation completes In EVENT NOTIFY and AST NOTIFY modes the function call returns immediately and the task is notified of completion of the I O operation by a local event flag or AST respectively EVENT NOTIFY and AST NOTIFY modes are most useful for operations which VTOS cannot complete immediately such as Read dev Write dev Seek dev andcertain Devctl dev and Special dev operations on the COM1 COM2 CPU PC REM1 and REM2 devices Pending Device I O operations may be cancelled by calling Abort dev C
206. s are intra segment near calls static data references are within the single data segment near data and pointers to data are near pointers The segment registers are never changed by the task s code unless the programmer intentionally overrides the default behavior Consequently compiling in small model produces code which is somewhat smaller and faster than with the other models The tradeoff for this efficiency is a size limitation for both code and data Each task is limited to 64K bytes of code and 64K bytes of static data Medium Model In medium model function calls are inter segment far calls by default This removes the 64K byte code size limitation at a cost of two extra code bytes per function call There is also a speed penalty In Series 90 70 PCMs the total call and return time for each function call is a bit more than one microsecond longer than for small model In Series 90 30 PCMs the penalty is almost two microseconds Data pointers and references are near by default in medium model Large Model Large model overcomes the 64K byte static data size limitation of the small and medium models The total size of constants and initialized variables is 64K bytes but each C source file may also have its own uninitialized data segment These may be as large as 64K bytes each Large model adds still more code for function calls and returns and far accesses are required for data in the uninitialized data segments Pointers to d
207. s the entireI O fault table These WAIT mode functions are declared in FAULTS H and the NOWAIT versions are declared in FAULTSNWH Table 5 27 Reading Series 90 70 Genius and System Faults Function Name Purpose chk_genius_bus chk_genius_bus_nowait Determines whether the specified Genius bus on the module in the specified rack and slot has a faulted device Series 90 70 PLC CPU request only chk_genius_device chk_genius_device_nowait Determines whether the specified Genius device at the specified bus rack and slot address is faulted Series 90 70 PLC CPU request only get_one_rackfaults get_one_rackfaults_nowait Returns all the system fault bits for the specified PLC rack Series 90 70 PLC CPU request only get_rack_slot_faults get_rack_slot_faults_nowait Determines which slot or slots if any in a specified rack have faulted modules Series 90 70 PLC CPU request only C Programmer s Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Reading and Setting the PLC Time of Day Clock The WAIT mode functions are declared in TIME H and the NOWAIT versions are declared in TMENWH Table 5 28 Reading and Setting the PLC Time of Day Clock Function Name Purpose read date Returns the current date from the PLC time of dayclock read date nowait read time Returns the current time from the PLC time of dayclock read time nowait read
208. s up or a soft reset occurs the operating system looks for a file named PCMEXEC BAT in the RAM disk In PCM 301 modules the ROM device is also searched for PCMEXEC BAT If it is not found and the PCM has been configured by Logicmaster 90 in BASIC or BAS CCM mode a new one is created This file contains a single R Run command which instructs the command interpreter to allocate a specified block of PCM RAM to MegaBasic to send a message to MegaBasic to execute a program named BASIC PGM and then to run the MegaBasic interpreter If BASIC PGM is found it is then executed When the command interpreter starts it executes the commands in PCMEXEC BAT just as the MS DOS command interpreter uses the AUTOEXEC BAT file when MS DOS is booted However PCMEXEC BAT is not executed following a hard reset C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A HARDEXEC BA Files When a hard reset occurs the operating system looks for a file named HARDEXEC BAT in the RAM disk If this file is not found and the PCM has been configured for BASIC or BAS CCM mode anew HARDEXEC BAT created It contains an R Run command which allocates a block of memory to MegaBasic and then starts the MegaBasic interpreter In this case no MegaBasic program name is specified MegaBasic starts in command mode User Installed PCMEXEC BAT and HARDEXEC BAT Files You can create your own version of PCMEXEC BATand orHARDEXEC BAT and load them to
209. scatterms _pg_chart _pg_chartms _pg_chartpie _pg_chartscatter _pg_chartscatterms _pg_defaultchart _pg_getchardef _pg_getpalette _pg_getstyleset _pg_hlabelchart _pg_initchart _pg_resetpalette _pg_resetstyleset _pg_setchardef _pg_setpalette _pg_setstyleset _pg_vlabelchart These functions are not supported in any memory model Table A 8 Stream I O Functions Function Memory Model fclose fcloseall fgetc fgetpos fgets fopen fprintf fputc fputs fread These functions are supported in all memory models PCM Library functions mustbe linked rather than Microsoft library functions clearerr feof ferror fgetchar fileno fputchar ftell getchar putchar These functions are supported in all memory models They are redefined bymacros scanf fflush flushall These functions are not supported in any memory model C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A GFK 0771A Function Memory Model freopen fseek fsetpos fwrite getc gets getw printf putc puts putw rewind sprintf ungetc vsprintf These functions are supported in all memory models PCM library functions must be linked rather than Microsoft library functions fscanf sscanf vfprintf vprintf fdopen _fsopen rmtmp setbuf setvbuf tempnam tmpfile tmpnam close creat dup dup2 eof lseek open read sopen tell umask write These funct
210. se floating point math cannot be compiled with Quick C C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Installing the PCM C Toolkit To install the Series 90 PCM C toolkit insert the GE Fanuc distribution diskette into a diskette drive of your personal computer If you have more than one diskette drive you can use any one of them Then at the DOS prompt type A INSTALL or B INSTALL depending on which diskette drive you are using The installation program will prompt you for all required information including the hard disk drive where you want to install the toolkit A complete list of the directories and files which were created on your hard disk during the installation process can be found in appendix D of this manual During the installation process a new version of AUTOEXEC BAT is created on the hard drive and directory where the PCM C toolkit is installed The INSTALL program asks you whether to replace the copy of AUTOEXEC BAT in the root directory of your computer s boot drive in this case C Copy PCMC AUTOEXEC BAT to C AUTOEXEC BAT If you answer Y to this prompt the version of AUTOEXEC BAT which INSTALL found in the root directory of your boot drive will be copied to the PCMC directory of the drive you specified for the toolkit installation The name of the file will be changed to AUTOEXEC BAK Then the modified AUTOEXEC BAT will be moved to the root directory of your boot drive
211. sk d says 7 s n task p gt s Block sem sem hndl p access flag FREE Unblock sem sem hndl Wait time MS COUNT MODE 0 wait time Block sem sem hndl The batch file SEM BAT starts one task using SEM2 EXE and two tasks using SEM1 EXE Before starting the two tasks SEM BAT deletes the existing copy of the shared module if there is one and creates a new copy which VTOS initializes to contain zero character values GFK 0771A Chapter 7 Multitasking 7 19 A portion of the output from a Series 90 30 PCM is shown below Note that using an access flag in the memory module assures that SEM2 will always print each distinct data string exactly once In addition each of the two SEMI tasks uses every count value starting at 0 exactly once The frequency with which the two SEMI tasks are able to access the shared memory module is controlled by the delay time values specified in their command lines sem MODULE3 MODULE3 200 SEM2 EXE 1 B SEMI EXE 3 B SEMI EXE 10 SEM1 id 13 wait time SEM1 id 14 wait time id 15 wait time says Hello from task says Hello from task says Hello from task says Hello from task says Hello from task says Hello from task says Hello from task says Hello from task says Hello from task says Hello from task says Hello from task says Hello from task says Hello from task says Hello from task says Hello from task says Hello from task says H
212. soft reset occurs and there is no PCMEXEC BAT file or UCDF in the PCM The PCM PT command displays this information when all five VTOS system tasks are active RTC COD CPULINK COD PCLINK COD OPCOM COD REM COD Each line shows a task number the executable file name and the name of an environment block which told VTOS how to run the task Multiple PCM application tasks are started using the PCM R Run command in much the same way as for single tasks However there is one additional complication The PCM command interpreter stops accepting input when the first application task starts unless background mode is specified by using the B option For example R MYAPP1 EXE B R MYAPP2 EXE B R MYAPP3 EXE Allbut the last application task must be started in background mode The final one may also be started in background mode if you need to use PCM commands while the application is running See Task Contention for PCM Serial Ports below for some issues you must consider when all the application tasks run in background mode and when two or more tasks share a serial port Task Scheduling 7 2 VTOS provides two algorithms for scheduling task execution priority based and time slice C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Priority Based Tasks VTOS priority based scheduling is conceptually very simple The highest priority task which is ready to run is given control of the PCM pro
213. stem Communications Window must be severely shortened or eliminated However VME functions lack many of the advantages of COMMREOS including Guaranteed data coherency e Automatic protection against simultaneous access to the same data location by the PCM and PLC CPU Fault reporting of some user programming errors such as an invalid task or the wrongrack slot Norequirement for user knowledge or manipulation of dual port addresses Most applications should use COMMREO function blocks to transfer data between the ladder program and the PCM VME functions should be used only when timing constraints or other factors dictate their use VME Function Blocks for Communicating with the PCM A group of PLC functions blocks is available in Logicmaster 90 software to allow a Series 90 70 PLC CPU to communicate with VMEbus modules including the PCM These functions include e VME Read VMERD e VME Write VMEWRT e VMRead Modify Write VMERMW VME Test and Set VMETS Each of these function blocks is discussed in detail later in this section Some Rules for VME Bus Operations in Series 90 70 PLCs VMEbus block move transfers are not supported by Series 90 70 PLCs Do not install a PCM or any other GE Fanuc Series 90 70 module in a standard VMEbus rack Series 90 70 modules must be installed only in Series 90 70 PLC racks For more information about VME in the Series 90 70 PCM refer to the Series 90 70 Programm
214. ster and stack data display for the task which was interrupted when the reset occurred task OE hexadecimal in this case is different in two respects First the header for the stack data contains the disclaimer assuming a pushbutton reset Register values are saved in slightly different order depending on whether the reset was caused by the reset restart pushbutton by a COMMREO message or by a severe software error which caused the PCM to reset itself Unfortunately DCMDUMP does not know which kind of reset actually occurred It can only assume that the button was pushed When some other event caused the reset the register values will not be correct Only the executing task is affected by this difficulty Register values for the other tasks are always saved in the same order by VTOS The second difference is the number of stack words which are displayed The executing task stack display contains 45 words while only 19 are displayed for the other tasks Note that the stack pointer SP register value is different from the one displayed in the task control block TCB for the task The Current stack pointer field of the TCB points to the start of the saved registers In the register display the SP register value is adjusted to point to the start of the stack word display Note also that the stack word display may include values which are actually beyond the end of the task s stack The stack for task OE hexadecimal was set to 1024 bytes 04
215. str The recnum value is checked DATA exits if itis invalid DATA responds to just two command values 1 Read CPU data and store it as records containing RECORD WORDS words in a database file in the PCM RAM disk and 2 Copy data records from the database file to the CPU When command specifies copying data from the CPU to the database file value 1 DATA opens a CPU channel reads the data and writes it to the database record specified by recnum Ifan error occurs while attempting to read the CPU data the command is ignored When the COMMREQ specifies copying data from the file to the CPU value 2 the specified database record is read and the data is written the the CPU If the COMMREO contained an unknown command DATA exits C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A E PLC Ladder Program The Logicmaster 90 70 version of the ladder program from folder PCMC EAMPLES DEMO_3T PLC_70 is shown here as Listing 9 1 The Logicmaster 90 30 version which is not shown requires a few more rungs because Series 90 30 COMMREO function blocks do not pass power flow In Listing 9 1 rung 6 initializes the PCM COMMREQ status locations and clears the internal contacts which latch COMMREO faults Note that the status locations must contain non zero values before the first COMMREOS can be sent Rung 7 is a timer which delays the first COMMREQs until five seconds after the first scan It is reset
216. t lt RUNG 11 gt gt M00001 M00002 Program PLC 70 C PCMC EXAMPLES DEMO_3T PLC_70 Listing 9 1 Continued Chapter 9 Example Programs 9 10 12 10 92 15 22 GE FANUC SERIES 90 70 DOCUMENTATION v3 04 PCM C Demo Application For Series 90 70 PLC lt lt RUNG 13 gt gt I SND_CRD COMMENT I RE RE e e e hee e e e RR KK KKK KK KKK he e e e e ke ke ke kk e ke e He hehehe e e e e e ke kk ke ke e He e He He He He e He e He He e ke e ke ke ke ke ke ke ke k k k If a COMMREQ has been requested and previous COMMREQs have not caused a fault and at least 5 seconds have elapsed since the first scan then check the status location for the COMMREQ If this is the first i T COMMREQ or the PCM has acknowledged the previous one then clear the status location send a new COMMREQ to the DATA task and reset the I I I I I request latch If a COMMREQ fault occurs set the fault latch l kk KK e He e ee e e e kk e He e He He e He e He e e e e e e kk e He e He He e He e He e e e e e kk ke ke e e e ke ke ke ke ke ke ke ke e k k k k k k k I I I lt lt RUNG 14 gt gt NE INT I I M00003 R00019 I1 Q COMM_ RM I I REQ I I I M00006 CONST I2 CONST IN 0 R00019 R00001 IN SM 4000004 400000 LEN 100001 I I CONST SYSID 0002 I I I CONST TASK 00000019 lt lt RUNG 15 gt gt INI_CR2 COMMENT
217. t Processing 060 cece eee 6 4 Using EVENT NOTIFY Mode Event Processing 6 6 Using AST NOTIFY Mode Event Processing 6 9 Differences between ASTs and MS DOSISRs sess 6 14 Other Considerations When Using Asynchronous Traps 6 15 GFK 0771A CProgrammer s Toolkit for Series 90 DC Ms User s Manual August 1996 ix Contents Chapter 8 Chapter 9 Chapter 10 Chapter 11 Chapter 12 Multitasking Memory Models Example Programs Applications in ROM REStHCHONS sonate uere EPA EN Gre Ee e Building ROM Applications Utilities Interaction of Priority and Time Slice Tasks Task Contention for PCM Serial Porte Communication Between Tasks 0 0 0 2 666 cece cece eee Event Flagsi L nti irreali ilari Shared Memory Modules Creating Memory Modules From Applications Asynchronous Traps ne eaa a e eee Semaphores yie iaee n RE ed e ox te d da a ei Debugging Multiple Tasks 0 66 60 Dumping PCM Task State Information 0 eee eee Using In Circuit Emulators PLC Hardware Requirements Logicmaster 90 Compatibility 0 0 0 6 eens Logicmaster 90 30 Configuration LL PCM Rack and Slot Location Building The PCM Executable Files eee eee The PEM Tasks out en t eae ves S en PLC Ladder Program ee x C Programmer s Toolkit for Series 90 PCMs User s Manual August1996
218. t any device or file path prefix If the file already exists in the PCM it will be overwritten Two optional qualifiers may be specified with the load command display mode and protection mode The display mode determines whether or not the file will be included in a module directory listing The two modes are normal N and hidden H Normal mode is the default The protection mode is used to determine whether the PCM file will be volatile V semi volatile S or protected P For certain file types for example EXE files described below the protection level is fixed at P by default and a protection option in the load command is ignored Data files are volatile by default but this may be overridden by the load command If options are used in the load command they follow the command directly with no intervening spaces For example LH is used to load a hidden module and LHP is used to load a protected hidden module Possible errors are File not found file name Illegal module type file name Insufficient memory The pem filename may contain at most an eight character file name a dot character and a three character file extension 8 3 or eight dot three format The pc filename format is determined by the PC file system The PC file name may optionally begin with a path and or device name If there is no device name the default device PC is assumed The DOS file system also has the 8 3 filename format
219. t call is the address of a function which is referred to as the AST function for the event When the event occurs VTOS posts an AST to the task VTOS tasks may be thought of as having two independent execution threads the mainline or normal thread and the AST thread The mainline thread is simply the task s main function plus the functions called directly or indirectly from it The AST thread consists of the task s AST functions plus any functions which they call directly or indirectly If the task s mainline thread is executing when an AST is posted to the task that thread is interrupted VTOS calls the AST function associated with the AST When the AST function returns the mainline thread resumes execution at the point where it was interrupted If the task is not executing when the AST is posted because it was pre empted by a higher priority task for example execution of the AST function is delayed until the task becomes the highest priority task which is ready to run If more than one AST has been posted while the task was pre empted the corresponding AST functions are executed in the order in which they were posted When the last AST function returns the task s mainline code resumes execution at the point where it was pre empted Note If the task is waiting for completion of WAIT mode I O or for local or global event flags when the AST is posted execution does not resume until the I O operation completes or the event flags are set
220. ta Ifthe module data area is FREE SEMI calls sprintf to construct a string and copy it to the memory module and then sets the access flag to DIRTY indicating that the data contains a new value Note that both of these operations are protected by the semaphore Since sprintf makes no VIOS service requests it may be called safely from semaphore protected code SEMI releases the semaphore and then waits for for the time which was specified on the command line if any or the default value After the delay SEMI attempts to acquire the semaphore again before repeating the loop If some other task happens to control the semaphore SEMI will not execute until all the tasks ahead of it at the semaphore have had their turn SEM1 C include vtos h include lt stdio h gt include sem h void main int argc char far far argv l mod hdr far mod ptr mod data far p word sem hndl wait time word count 0 word task Get task id if arge 2 wait time atoi argv 1 0 wait time 10 printf task SEM1 id d wait time d n task wait time mod ptr Get mod MOD NAME P mod data far mod ptr 1 sem hndl Link sem SEM NAME for if p access flag FREE sprintf p s Hello from task d count d task countt p access flag DIRTY Unblock sem sem hndl Wait time MS COUNT MODE 0 wait time Block sem sem hndl C Programmer e Toolkit f
221. ta from any number of tasks in any order Requests from two or more tasks to read serial input data can also be pending at the same time and the results can be unpredictable For example try typing R BASIC EXE B at the PCM command interpreter prompt Running MegaBasic in background B mode allows the PCM command interpreter to compete with MegaBasic for serial input The two tasks become very confused Caution When two or more tasks need to share a serial port they must provide their own mechanism for assuring that one task at a time owns the port Otherwise they will corrupt each other s data Note that the PCM file server for the PC device also uses serial port 1 If an application task needs to use the file server all other tasks including the PCM command interpreter must be prevented from using port 1 In addition an application task must not attempt to use the serial port while a PC file transfer is in progress The PCM command interpreter is normally disconnected from the programmer port serial port 1 by default by running one of the application tasks in foreground that is without the B option of the R Run command When all the application tasks are run with the B option the command interpreter task must be suspended while an application task is receiving serial input or performing a PC file transfer The application task must execute this code Suspend_task 3 Use the serial port Resume_task 3
222. tes a VTOS device driver as a task Process env Starts a PCM task using a saved environment block Resume task Allows a task to execute Set std device Sets a standard I O channel for a task Suspend task Prevents a task from executing Terminate task Kills a task permanently and frees its resources Test task Returns the set of active tasks Wait task Waits for a specified task to terminate GFK 0771A 5 1 PCM applications including these using multiple tasks should be started from PCMEXEC BAT files Itis possible but not recommended to start one application task from PCMEXEC BAT and then start the others from the first by calling Init task or Process env A task s ID value is required by many VTOS services and may be obtained by calling Ger task id Task execution can be temporarily stopped by Suspend task andthenstarted again by Resume task Test task isused to determine which task numbers are active and Wait task permits a task to wait until a lower priority task terminates for example by exitingits main function Set std device reassigns the I O channels assigned to the predefined STDIN STDOUT and STDERR devices for a task and Terminate task permits a task to terminate its own execution or that of another task Note that Terminate task is called automatically when a task returns from its main function Event Flag Functions 5 2 Table 5 2 Event Flag Functions
223. text with the PCMDUMP EXE utility or the MegaBasic program PCMDUMP PGM The information is useful when the PCM unexpectedly locks up or resets itself Hard resets holding the button down for ten seconds have no effect on the saved task control block and stack data from the most recent soft reset but cycling PLC power off and on will corrupt it PL Show the PCM rack slotlocation The PCM returns two ASCII digits The first digitspecifies therack number and the second digit specifies the slot number The ASCII digits may be followed by a string that contains the CPU ID If the PLC CPU does not have an ID a string consisting of just the ASCIINL characteris returned If the PCM cannot establish communication with the CPU the message NO CPU is sent PM Show the type and mode of the most recent PCM reset The PCM returns two ASCII digits The first digit specifies the type of the most recent PCM reset 0 Powerup reset 1 Soft reset 2 Hard reset including a COMMREO hard reset 3 ACFAILreset 4 Reset caused by receipt of new soft switch data 5 Internal software error reset 6 COMMREO soft reset The second digit specifies the type of configuration data used during the most recent reset 0 User configuration UCDF data 1 Factory default configuration data 2 Logicmaster 90 configuration 3 A combination of Logicmaster 90 and factory default data PT Show the status of PCM tasks For each act
224. that AST1 has completed its initialization AST2 posts an AST to ASTI and then waits for its timer AST to occur AST2 exits after the timer AST is processed AST2 C include lt vtos h gt include lt stdio h gt include ast bn mod_data far p mod_hdr far mod_ptr void far timer_ast_function ast_blk far p printf task AST2 a timer AST occurred Mn printf handle 04x n p gt handle printf argl 04x n p argl printf arg2 04xWn p arg2 printf arg3 04xWn p arg3 printf arg4 04xWn p arg4 void main word task Get task id printf task AST2 id d n task mod ptr Get mod MOD NAME P mod data far mod ptr 1 p task2 num task p tmr ast func timer ast function Set gef READY 2 GEF Wait gef READY 1 GEF Post ast p taskl num p post ast func task 1 2 Wait ast C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Since AST1 resets the global event flags which control the initialization of MODULE2 it must be run first and at higher priority than AST2 The PCM batch file AST BAT allocates MODULE2 and then runs the two tasks in the correct order gt ast M MODULE2 0C R AST1 EXE IOE B R AST2 EXE IOF task AST1 id 14 task AST2 id 15 task AST1 timer handle 3903 task AST1 an AST was posted handle 000 argl 0001 arg2 0002 arg3 0003 arg4 0004 task AST2 a tim
225. the task or service point in the target PCM where the COMMREQ will be delivered This value is not equivalent to the VTOS task number of the destination task Instead it is the numeric value specified in the device name string passed to a call by the VTOS Open dev function word commreq handle commreq handle Open dev cpu lt number gt where commreq handle isa VTOS handle for the device I O channel where COMMREQs will be received and number is the service point value for that channel Service point values must be in the range 4 through 120 decimal Note that values outside this range are either invalid or reserved for use by VTOS A PCM task may open more than one service point for COMMREQ messages GFK 0771A Chapter 4 Using PCM Resources 4 5 OKand FT Logicmaster 90 software displays this parameter in hexadecimal format while Open dev expects service point values in device name strings to be specified in decimal format Thesame value mustbe used for both otherwise the COMMREO message will not be delivered to the target task and an Invalid Task fault will be posted to the PLC fault table The safest technique is to enter the COMMREO TASK value in decimal format on the Logicmaster 90 input line Before pressing the Enter key to accept the value verify visually that is the same one used in the Open dev device name The OK and FT fault outputs can provide power flow to optional logic to verify that the COMMREO
226. ther memory module which is linked to the first The size of the new module is the smallest integer multiple of 1024 bytes which is larger than SIZE 2 Ifa Seek dev callis made which specifies a position beyond the end of the last data module a new memory module will be created and linked to the end of the module chain 3 This method unlike the PCM M command does not fill the new module with zeros Additional code would be needed to do so The only reliable way to find the data address of a module created with this method is shown in the example program MODTESTC It creates a new file named MYMODULE in the RAM device Then two Seek dev calls are made to extend the module length Finally the linked list of modules which make up the file is traversed 7 12 C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A MODTEST C include lt vtos h gt include lt stdio h gt define SIZE1 128 define SIZE2 1992 mod_hdr far mod_p void main long unsigned data_size 0 word task Get task id word handle Open dev RAM MYMODULE WRITE MODE WAIT task Seek dev handle SIZE1 WAIT task Seek dev handle SIZE2 WAIT task Close dev handle WAIT task mod p mod hdr far Get mod MYMODULE for data size mod p modsize printf module name s n char far mod p name printf module size ld n mod p modsize printf module alias 04xWn mod p
227. ts 1 A command has been received from the OIT 2 Register data has been received from the PLC CPU 3 Itis now time to request PLC register data 4 Thelast request to read PLC registers has timed out and no data has arrived Each of these events is assigned a unique local event flagin define macros The non terminating for loop waits for one or more of them to occur If two or more of the events occur they are processed in a fixed order determined by the order of if conditions in the loop Before entering the loop the task opens separate I O channels for reading commands from the OIT displaying values and alarm messages to the OIT and reading PLC register values The first read request for an OIT command is also made before entering the loop However the first read request for PLC register data is made in the loop triggered by setting the READ RECS event flag before the loop is entered The timer which triggers register requests on a constant time intervalis started in REPEAT MODE so that processing time will not increase the interval between requests The automatic variable read pending prevents making a register read request before the previous one has completed Another timer is started to time out the read request in case there is a malfunction In the loop the task waits for one or more of the local event flags of interest to be set When the Wait ef callreturns the current values of all the task s local flags are obta
228. tween the device name and initialization string The parameters in device initialization string must occur in the order listed in the table below with no intervening spaces Any number of parameters may be omitted at the right end of the string Parameters to the left of the last one may be omitted but all the surrounding commas must be included Omitted parameters retain their previous settings InitializationString baud rate parity data bits stop bits flow contr ol physical interface duple x mode delay value typeahead size where baud rate 300 600 1200 2400 4800 9600 19200 or 38400 the number of bits per second Note that 38 400 baud is supported only by the Series 90 70 PCM and only for RS 422 or RS 485 port configurations parity O E N the type of parity checking Odd Even or None data bits 70r8 the number of data bits per character Use 8 unless text with 7 bit characters will be the only data transferred stop bits 1 or 2 the number of stop bits per character The normalselection for 300 baud and higher is 1 flow control H S or N the flow control method Hardware CTS RTS Soft ware X ON X OFF or None physical interface 232 422 or 485 the physical connection protocol for the port RS 323 RS 422 or RS 485 RS 422 is equivalent to RS 485 All Series 90 30 PCMs support RS 232 only on COMI IC693PCM300 supports RS 422
229. ugust 1996 GFK 0771A include vtos h include cpu data bs include lt stdlib h gt comreq msg msg char dev name cpu 00 word task no word commreq handle word read size word commreq data buffer 128 word commreq data size 0 word commreq data ptr NULL task no Get task id insert task number 10 into device name string itoa task no 10 dev name 5 10 open an I O channel to read COMMREQ messages commreq handle Open dev dev name READ MODE WAIT task no loop forever for clear the COMMREQ data size and pointer values commreq data size 0 commreq data ptr NULL read a COMMREQ read size Read dev commreq handle msg COMMREQ MSG SIZE WAIT task no if a complete COMMREQ was read extract the data read size COMMREQ MSG SIZE test the COMMREQ message type byte if msg header msg type amp 0x40 COMMREQ data is in the message set the data size and pointer commreq data size 6 commreq data ptr msg data short c data else there is a separate COMMREQ data buffer read it read size Read dev commreq handle commreq data buffer msg data long c data size WAIT task no if read size msg data long c data size all the data was read set the data size and pointer commreq data size read size 2 commreq data ptr commreq data buffer The example opens a channel to read COMMREO messages an
230. uild a PCM application called myapp exe from the sources myapp1 c myapp2 c and myapp3 c use OBJLIST myappl obj myapp2 obj myapp3 obj myapp exe OBJLIST Note Asthe total number of characters in the OBJLIST macro definition increases the LINK command line issued by NMAKE or NMK will eventually exceed the MS DOS command length limit When this happens linker errors willoccur The remedy is to use a linker response file for long command input See the Microsoft LINK documentation For more information on makefiles NMAKE and NMK see the Microsoft C documentation Chapter 3 Creating and Running PCM C Programs 3 9 Chapter Using PCM Resources 4 The GE Fanuc Series 90 Programmable Coprocessor Module PCM family provides a platform within Series 90 PLCs for C applications developed by OEMs and system integrators This chapter is an overview of the resources provided by PCMs and PLC CPUs PCM Hardware Resources Each PCM is equipped with 128 to 640K bytes of RAM 256K bytes of EPROM 128K bytes of which is dedicated to system firmware two high performance serial ports a PLC backplane communication channel to the PLC CPU three programmable timers and three programmable light emitting diode LED indicators two of which may be programmed by applications In addition to communication between the PCM and PLC CPU the PLC backplane communication channel supports communication between two or more PCMs in the same PLC S
231. ul Input size ast_ptr gt arg2 void main void char input_data MAX_INPUT word task Get task id word serial pl Open dev COM1 13 READ MODE WAIT task for Input_size 0 Read dev serial pl input data MAX INPUT AST NOTIFY task serial input ast if Input size 0 Wait ast Do something with the input data This program waits for input on PCM serial port 1 which was opened with the option to terminate read requests when ASCII code 13 CR arrives If input characters with a terminating CR character are already in the COMI type ahead buffer serial input ast willbe called before input size istestedinthe if condition However it is possible for the CR character to arrive just in time for VTOS to call serial input ast after the test but before the call to Wait ast When this happens the program will hang until some other AST occurs if ever GFK 0771A Chapter 6 PCM Real Time Programming 6 15 The problem can be avoided by preventing VTOS from posting ASTS between the test and Wait ast call as shown here Only the for loop has changed for Input size O0 Read dev serial pl input data MAX INPUT AST NOTIFY task serial input ast disable if Input size 0 Wait ast _enable Do something with the input data Both disable and enable are Microsoft library functions defined in DOS H They disable and enable m
232. un the Microsoft C SETUP program you will encounter this line Math options Emulator Y N 8087 N N Alt Math N Y You must answer Y to Alt Math You may also wish to install the Emulator and or 8087 math package but they are not useful for PCM applications 2 The Microsoft C SETUP program attempts to modify the AUTOEXEC BAT file in the root directory of your boot drive normally C SETUP tries to modify the SET commands if any which definine the environment variables LIB and INCLUDE If there are no SET commands defining them SETUP will attempt to add them The PCM C toolkit relies on these environment variables for finding Microsoft library files such as SLIBCE LIB etc and include files such as CTYPE H etc If SETUP does not add the definitions for these environment variables to your AUTOEXEC BAT file you will need to do it manually See Adding NW PCMC LIBto Your LIB Environment Variable and Adding PCMC INCLUDE to Your INCLUDE Environment Variable later in this chapter Caution PCM C applications which use floating point math must be compiled with the Microsoft C Alternate Floating Point math FPa command line switch and the alternate math library must be installed If you have already installed Microsoft C without the alternate math library you must run the Microsoft C SETUP program again to install it Microsoft Quick C does not support the alternate math package PCM C applications which u
233. until task 8 starts At that time task 8 pre empts task 9 because it has higher priority But the task rotation has begun before task 7 is started and tasks 7 and 6 are simply added to the rotation Task 8 is allowed to execute until the end of its time slice Task 9 follows task 8 then the first complete task rotation begins with task 6 The printed output shows six complete rotations plus the start of the seventh Because all the tasks were run in background mode the PCM command interpreter can accept more commands while the tasks are running You can use a PCM K Kill command to stop each of the tasks Interaction of Priority and Time Slice Tasks 7 4 When both priority and time slice tasks execute some complex interactions can occur These rules apply 1 Time slice tasks are pre empted when a priority based task with higher priority becomes ready to execute 2 When a time slice task is pre empted its time slice continues to tick away 3 When a pre empted time slice task s time expires the task is paused The next task in the time slice rotation is resumed but it will execute only if its priority is higher than the priority based task which pre empted the previous task in the time slice rotation C Programmer s Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Another experiment with SLICE EXE illustrates these rules This time the time slice tasks are 9 8 7 and 5 Task 6 is started as a priority bas
234. using the port while the background task is using the file server This is not a problem with tasks run in foreground mode because the command interpreter is suspended until the foreground task completes C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A X eXterminate file Format X file name This command deletes a file named file name in the PCM RAM disk Possible errors are Module in use file name Module not found file name The specified file is deleted immediately There is no confirmation prompt nor is there any method for recovering a deleted file Y Set Upper Memory Limit Format Y lt limit gt PCM memory may be divided between the operating system and one or more applications Setting a limit on the memory used by the operating system causes it to ignore all memory above the limit It will never load programs or allocate memory buffers there Application programs can determine the limit with VTOS and access memory above the limit through the use of pointers or absolute addresses The optional limit argument is the amount of memory in 16 byte paragraphs to be retained by the operating system It is specified as a hexadecimal value and must be at least 800 32K bytes to leave space for operating system data If the specified value is too small or exceeds the total amount of memory on the PCM this error message is returned Insufficient memory If the command is
235. utility can also be used to check the stack size of PCM EXE files without changing it Simply invoke STKMOD without a stack size value If you type stkmod hello STKMOD responds with GE Fanuc Automation PCM EXE File Stack Size Utility Version 1 00 Copyright c 1992 GE Fanuc Automation North America Inc All rights reserved HELLO EXE hex dec old stack size in paragraphs 0080 128 old stack size in bytes 0800 2048 C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A Loading Executable Files GFK 0771A Executable files must be loaded to the PCM using TERME the PCM terminal emulation file transfer program TERMF is available separately from GE Fanuc Automation as catalog number IC641SWP063 For information on TERMF installation and configuration see chapter 2 section 3 TERMF installation and Configuration in the Series 90 Programmable Coprocessor Module and Support Software User s Manual GFK 0255D or later If you already have a copy of PCOP the PCM development software package catalog number IC641SWP061 you do not need to purchase TERMF separately TERMF isa part of the PCOP package it can be invoked from within PCOP with the Shift F3 function key Alternatively TERMF can be started without PCOP by typing PCOP TERMRt the MS DOS prompt If the PCOP directory is in your PATH you can simply type TERME Before a program can be loaded to a Series 90 30 PCM it must be configured for e
236. value of the code segment which was executing when the reset occurred is OA4F 0837 0000 0218 Within the segment individual functions can be identified by the stack dump IP register value in the same way as for small model tasks C Programmer e Toolkit for Series 90 PCMs User s Manual August 1996 GFK 0771A BLD PROM Program GFK 0771A BLD PROM EXE is the utility program used to build the binary image files for programming erasable programmable read only memory EPROM devices The actual programming of EPROM devices requires an EPROM programmer EPROM programmers are not available from GE Fanuc Automation For more information on PCM applications in ROM see chapter 10 of this manual To invoke BLD_PROM simply type BLD_PROM at the MS DOS prompt BLD_PROM will ask you for the inputs it needs Most prompt messages from BLD_PROM contain a default value which is displayed in square brackets Most defaults can be selected simply by pressing the lt Enter gt key However if BLD_PROM is expecting a string as input for example a file name you must select the default by entering a semicolon UC character followed by the lt Enter gt key In this example BLD_PROM session user input is shown in this typeface gt BLD_PROM Bld_prom utility Copyright 1989 GE Fanuc Automation North America Inc Please enter initialization file name lt Enter gt Please enter PROM address 1 c0000 2 a0000 1 Enter
237. version Functions Function Memory Model abs labs These functions are supported in all memory models atoi atol ltoa ultoa These functions are supported in all memory models PCM library functions must be linked rather than Microsoft library functions atof ecvt fcvt gcvt strtod strtol strtoul These functions are supported in large model without restriction In the smalland medium memory models they may be used only for DS based variables _atold _strtold These functions are not supported in any memory model Table A 4 Directory Control Functions Function Memory Model chdir _chdrive getcwd _getdewd _getdrive mkdir rmdir _searchenv These functions are not supported in any memory model Table A 5 File Handling Functions Function Memory Model access chmod chsize filelength fstat _fullpath isatty locking _makepath mktemp remove rename setmode _splitpath stat umask unlink These functions are not supported in any memory model Appendix A Microsoft Runtime Library Support A 3 A 4 Table A 6 Low Level Graphics and Character Font Functions Function Memory Model arc _arc_w _arc_wxy _clearscreen _displaycursor _ellipse _ellipse_w _ellipse_wxy _floodfill _floodfill_w _getactivepage _getarcinfo _getbkcolor _getcolor _getcurrentposition _getcurrentposition_w _getfillmask _getfont
238. vide a wide range of optional memory Applications can store up to 618 Kbytes of process data 6 PCM applications can store data as files in the PCM RAM disk file system or ina personal computer PC attached to a PCM serial port 1 1 Limitations A number of C applications are already at work in PCMs or nearing completion The application areas include Serial communication nodes for assorted protocols Drivers for operator interface terminals Boiler controls Electric power control and monitoring Automatic assembly machine control Tank truck loading station controls Controls for integrated circuit fabrication equipment The Series 90 70 PCM is approximately equivalent in computing throughput to an 8 Mhz 80286 based personal computer The three Series 90 30 PCM models are all about half as fast as the Series 90 70 PCM There is no hardware support for floating point math coprocessor chips C applications in RAM have a bit more than 600 Kbytes available for code and data Nearly 128 Kbytes of EPROM space is available for code and constant data in both series Expertise Required Successful C programming for the PCM requires a thorough understanding of advanced topicslike mixed memory model programming event driven finite state machines re entrancy and concurrency among others Familiarity with Series 90 PLCs is also required The PCM includes a multitasking operating system VTOS which is designed to handle asynchro
239. vironment Control Functions Function Memory Model exit exit These functions are supported in all memory models abort assert atexit _beginthread _cexit _c_exit cwait _endthread execl execle execlp execlpe execv execve execvp execvpe getenv getpid longjmp onexit _pclose perror _pipe _popen putenv raise setjmp signal spawnl spawnle spawnlp spawnlpe spawnv spawnve spawnvp spawnvpe system wait These functions are not supported in any memory model Table A 14 Search and Sort Functions Function Memory Model bsearch lfind lsearch qsort In small and medium memory models use only with DS based variables Unrestricted inlarge model Appendix A Microsoft Runtime Library Support A 11 A 12 Table A 15 String Manipulation Functions Function Memory Model strdup _fstrdup These functions are supported in all memory models PCM library functions must be linked rather than Microsoft library functions Note that insmall and medium models far pointers must be used as parameters and return values strcpy strlen These functions are supported in all memory models In small and medium models they are redefined by macros strcat strchr strcmp strcspn stricmp strlwr strncat strncmp strncpy strnicmp strnset strpbrk strrchr strrev strset strspn strstr strtok strupr These functions are supported in all memory models I
240. waiting Global event flags where task is waiting Other tasks which task is waiting for First AST block for task Last AST block for task Suspend Count Task s initial data segment Task s initial stack segment Safe point address Semaphore count for setting safe point Semaphore count for I O operations Segment of STDIN Device Access Block Segment of STDOUT Device Access Block Segment of STDERR Device Access Block Task environment block address Link field for tasks waiting at semaphore Semaphore address if waiting at semaphore Flag for enabling ASTs VME window selector code VME address modifier code 000F 0003 0001 0687 03B8 0000 0000 0000 0000 0000 0000 0000 06C8 0687 0000 0000 0000 045E 0611 0611 0613 0000 0000 0000 0001 00 29 Waiting for an asynch trap The task control block fields are described in the following sections Task ID This field contains a task number in the range 0000 through 000F hexadecimal 0 through 15 decimal inclusive If the task number has not been used since the last PCM reset the binary POMDUMPOUT file actually contains zero in this field However PCMDUMDEXE prints an ID value for every task regardless of the value in the binary dump Chapter 11 Utilities 11 5 Current State This field contains one of the values from the following table Table 11 2 Current State Values Current State PCMDUMP Description Valu
241. xecution is synchronized with completion of the I O request WAIT mode provides programming simplicity at a cost 1 A task may have only one I O operation in progress at a time 2 Ifa malfunction occurs and the I O operation never completes the calling task will resume execution only if and when the operation is aborted by a different task or an asynchronous timeout GFK 0771A 6 1 Altematively the application task may specify EVENT NOTIFY or AST NOTIFY mode For either of these modes the service call returns immediately The calling task may make additional I O requests or perform other operations while the I O request is in progress When the request completes this chain of events is set in motion 1 A hardware interrupt is asserted by the PCM serial controller or backplane I O hardware 2 The microprocessor hardware interrupt mechanism transfers control to a VTOS interrupt service routine ISR The details of I O processing depend on which physical device is involved and how it was opened by the application 3 When processing is complete VTOS notifies the application either by setting a local event flag or posting an AST as specified in the request What happens next depends on whether event flag or AST notification was used The narrative continues in one of the following sections Local Event Flag Notification or AST Notification and Execution Threads as appropriate VTOS Asynchronous Timer Scenario The
242. y backed RAM allow user programs and data to be retained in memory through power outages A fast runtime memory manager allocates memory blocks in as little as 50 microseconds A command interpreter loads and runs user tasks and controls their execution environment A batch file facility starts applications automatically when the PCM powers up or is reset VTOS supports user programs in EPROM These services are built into the PCM firmware A smalllibrary of interface functions provides access from application code The VTOS File System Files in the PCM are stored in either RAM EPROM or EEPROM in the PCM 301 only Consequently there are some important differences between VTOS files and files in a disk operating system 1 Disk file systems are based on magnetic storage media which have an inherent block structure based on disk tracks and sectors VTOS files however are structured at the lowest level as sequential files of bytes or stream files PCM C developers may choose to impose their own block structure on the data in VTOS files VTOS provides services for random access to files Data read and write operations on magnetic media are inherently slow Disk file systems use buffering to minimize the impact on applications When an application writes data to a file the data is actually put into a file buffer in memory Closing the file is often the only way to force the file system to move all the data to the disk and up
243. y time slice task Txx Allocate an execution time slice of xx hexadecimal milliseconds Any value from 05 to FA 250 decimal inclusive may be specified Mname Link the task to memory module name The names of one or more memory modules are available to C applications through the PCM modc modv mechanism B Run the task in background mode If the task and the PCM command interpreter share a serial port for stdin stdout or stderr the command interpreter remains in control of the port K Keep the task s environment block in memory after task termination Default selection C Programmer s Toolkit for Series 90 PCMs User s Manual August 1996 Any strings in the command line which do not begin with the special characters or are assumed to be command data strings They are passed to the executable program for processing C language applications can use the standard argc argv mechanism to access them If the file specified by the R command is not present in the PCM RAM Disk the PCM attempts to load it from the default device PC using the specified file name If it cannot find the file in either device an error message is returned Errors that can be returned are Module not found file name File not found file name Insufficient memory S Save Format S pcm filename pc filename The Save command causes a file named pcm filename int
244. ypeused forread writesystem memory service requestmessages svcreq msg Defines a generic service request message structure type C Programmer s Toolkit for Series 90 PCMs User s Manual August 1996 VTOS Global Data These global variables are defined as extern data in VIOS H Table 5 16 VTOS Global Data Variable Name Purpose VTOS error VTOS services which return a completion status also copy their completion error code here The PLC API Interface AllSeries 90 PLC CPUs provide a broad range of services to other Series 90 modules and software processes for example Logicmaster 90 software through a message based service request interface The PCM C toolkit provides an application program interface the PLC API which hides all the details inside a function call access model Previously applications were required to send PLC service request messages referred to as generic messages in the PCM User s Manual GFK 0255D and later to use these same services Two function calls are provided for each PLC service a WAIT mode and a NOWAIT mode function The WAIT mode functions suspend the calling task while the service request is in progress and then return when the request has been completed NOWAIT requests return immediately and a status flag is set when each request completes NOWAIT requests permit a significant reduction of the total time required for multiple requests to be serviced in

Download Pdf Manuals

image

Related Search

Related Contents

Proslat 60001 Instructions / Assembly  Gebrauchsanleitung Instruction manual Mode d`emploi Manuale di  Creative MuVo V200 User's Manual  Betriebsanleitung  Digital indicator model DI35-M GB  GGIG Graphical Interface Generator User Guide    ALL RIGHTS RESERVED  E20080001 Unifluorc  Homework 12: User Manual Include this sheet as a cover page for  

Copyright © All rights reserved.
Failed to retrieve file