1 RMOS3 V3.50 Reference Manual Part II ___________________ About this manual... 2 ___________________ Function groups RMOS3 RMOS3 real-time operating system RMOS3 V3.50 Reference Manual Part II Programming Manual 07/2012 A5E03692298-01 3 ___________________ Data structures 4 ___________________ Error codes and messages Functions and configuration 5 ___________________ of the basic I/O system A ___________________ Abbreviations/glossary Legal information Warning notice system This manual contains notices you have to observe in order to ensure your personal safety, as well as to prevent damage to property. The notices referring to your personal safety are highlighted in the manual by a safety alert symbol, notices referring only to property damage have no safety alert symbol. These notices shown below are graded according to the degree of danger. DANGER indicates that death or severe personal injury will result if proper precautions are not taken. WARNING indicates that death or severe personal injury may result if proper precautions are not taken. CAUTION indicates that minor personal injury can result if proper precautions are not taken. NOTICE indicates that property damage can result if proper precautions are not taken. If more than one degree of danger is present, the warning notice representing the highest degree of danger will be used. A notice warning of injury to persons with a safety alert symbol may also include a warning relating to property damage. Qualified Personnel The product/system described in this documentation may be operated only by personnel qualified for the specific task in accordance with the relevant documentation, in particular its warning notices and safety instructions. Qualified personnel are those who, based on their training and experience, are capable of identifying risks and avoiding potential hazards when working with these products/systems. Proper use of Siemens products Note the following: WARNING Siemens products may only be used for the applications described in the catalog and in the relevant technical documentation. If products and components from other manufacturers are used, these must be recommended or approved by Siemens. Proper transport, storage, installation, assembly, commissioning, operation and maintenance are required to ensure that the products operate safely and without any problems. The permissible ambient conditions must be complied with. The information in the relevant documentation must be observed. Trademarks All names identified by (R) are registered trademarks of Siemens AG. The remaining trademarks in this publication may be trademarks whose use by third parties for their own purposes could violate the rights of the owner. Disclaimer of Liability We have reviewed the contents of this publication to ensure consistency with the hardware and software described. Since variance cannot be precluded entirely, we cannot guarantee full consistency. However, the information in this publication is reviewed regularly and any necessary corrections are included in subsequent editions. Siemens AG Industry Sector Postfach 48 48 90026 NURNBERG GERMANY A5E03692298-01 07/2012 Technical data subject to change Copyright (c) Siemens AG 2012. All rights reserved Table of contents 1 2 3 About this manual... .............................................................................................................................. 11 1.1 About this manual... .....................................................................................................................11 1.2 Notations ......................................................................................................................................12 Function groups .................................................................................................................................... 15 2.1 2.1.1 2.1.2 2.1.3 2.1.4 RMOS3 functions .........................................................................................................................15 Notes on programming in C .........................................................................................................16 Short description of the RMOS3 functions ...................................................................................17 Configuration functions ................................................................................................................23 Miscellaneous functions ...............................................................................................................25 2.2 2.2.1 2.2.2 2.2.3 CLI functions ................................................................................................................................26 Startup code for C programs........................................................................................................26 Problems when aborting a program .............................................................................................26 Short description of the CLI functions ..........................................................................................27 2.3 2.3.1 2.3.2 C library functions ........................................................................................................................28 Scope of the C library ..................................................................................................................28 Short description of the C library functions ..................................................................................28 2.4 2.4.1 2.4.2 2.4.3 2.4.4 Driver functions ............................................................................................................................37 Application model .........................................................................................................................37 Short description of the driver functions ......................................................................................38 System variables for parameter transfer ......................................................................................39 Differences between type I and type II drivers .............................................................................39 Data structures ..................................................................................................................................... 43 3.1 RmAbsTimeStruct ........................................................................................................................43 3.2 RmAsciiTimeStruct.......................................................................................................................44 3.3 RmDCDStruct ..............................................................................................................................45 3.4 RmEntryStruct ..............................................................................................................................46 3.5 RmIntrhandMailStruct ..................................................................................................................47 3.6 RmIOStatusStruct ........................................................................................................................48 3.7 RmIRBStruct ................................................................................................................................49 3.8 RmMailboxStruct ..........................................................................................................................50 3.9 RmMailIDStruct ............................................................................................................................51 3.10 RmMemPoolInfoStruct .................................................................................................................52 3.11 RmSpinLockStruct .......................................................................................................................53 3.12 RmSysB .......................................................................................................................................54 3.13 RmTaskInfoStruct ........................................................................................................................57 RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 3 Table of contents 4 5 3.14 RmTCDStruct .............................................................................................................................. 59 3.15 RmTimeStruct ............................................................................................................................. 62 3.16 RmTMBStruct .............................................................................................................................. 63 3.17 RmUCDHeadStruct ..................................................................................................................... 67 3.18 RmUCDStruct ............................................................................................................................. 68 3.19 loader_result ................................................................................................................................ 69 3.20 stdstruct ....................................................................................................................................... 71 Error codes and messages ................................................................................................................... 73 4.1 Nucleus ....................................................................................................................................... 73 4.2 Error codes of the RMOS3 API calls ........................................................................................... 76 4.3 SVC exception handler ............................................................................................................... 80 4.4 CLI ............................................................................................................................................... 81 4.5 CRUN .......................................................................................................................................... 84 4.6 HSFS ........................................................................................................................................... 86 4.7 Debugger..................................................................................................................................... 87 4.8 Resource reporter ....................................................................................................................... 90 4.9 Task loader stl_load, stl_free....................................................................................................... 91 4.10 LOADRM task loader .................................................................................................................. 93 Functions and configuration of the basic I/O system .............................................................................. 95 5.1 Overview ..................................................................................................................................... 95 5.2 5.2.1 5.2.1.1 5.2.1.2 5.2.1.3 5.2.1.4 5.2.1.5 5.2.1.6 5.2.1.7 5.2.2 5.2.2.1 5.2.2.2 5.2.2.3 5.2.3 5.2.3.1 5.2.3.2 5.2.3.3 5.2.3.4 5.2.3.5 5.2.3.6 5.2.3.7 5.2.3.8 BYT driver ................................................................................................................................... 96 Properties .................................................................................................................................... 96 Optional EGA functions ............................................................................................................... 97 Half/full duplex mode ................................................................................................................... 97 Control characters for BYT drivers and terminals ....................................................................... 99 History mode ............................................................................................................................. 101 Data flow of received characters ............................................................................................... 101 Special features for EGA units .................................................................................................. 104 Opcodes of the BYT driver (bits 0..3) ........................................................................................ 111 RmIO interface .......................................................................................................................... 113 Function parameter ................................................................................................................... 113 Parameter pState ...................................................................................................................... 115 Parameter pParam .................................................................................................................... 117 Opcodes of the BYT driver ........................................................................................................ 118 Reserve unit (BYT_RESERVE) ................................................................................................ 118 Release unit (BYT_RELEASE) ................................................................................................. 120 Read (BYT_READ) ................................................................................................................... 121 Write (BYT_WRITE) .................................................................................................................. 123 Unconditional writing (BYT_XWRT) .......................................................................................... 125 Read character in transparent mode (BYT_ONE_XREAD) ...................................................... 125 Write and read in transparent mode (BYT_WRT_XREAD) ....................................................... 125 Write and read (BYT_WRT_READ) .......................................................................................... 126 RMOS3 V3.50 Reference Manual Part II 4 Programming Manual, 07/2012, A5E03692298-01 Table of contents 5.2.3.9 5.2.3.10 5.2.3.11 5.2.3.12 5.2.3.13 5.2.3.14 5.2.3.15 5.2.3.16 5.2.4 5.2.4.1 5.2.4.2 5.2.4.3 5.2.4.4 5.2.4.5 5.2.4.6 5.2.4.7 5.2.4.8 Skip line (BYT_SKIP_LINE) .......................................................................................................127 Clear screen (BYT_FORM_FEED) ............................................................................................127 Read character to buffer in transparent mode (BYT_HSFS_XREAD) .......................................127 Write character (BYT_HSFS_WRT) ...........................................................................................128 Read interim buffer in transparent mode (BYT_POLL_XBUF) ..................................................128 Check input buffer for abort characters (BYT_CHECK_ABO) ...................................................129 Redefine and initialize the unit (BYT_CREATE_NEW) ..............................................................130 Multifunction (only for EGA units) ..............................................................................................131 Configuration ..............................................................................................................................141 Driver Control Data table (RmDCDStruct in RMTYPES.H) .......................................................142 Unit Control Data table (RmUCDStruct in RMTYPES.H) ..........................................................142 Driver-specific parameters in the UCD block .............................................................................143 Interrupt routines of the BYT driver ............................................................................................153 Configuring the control characters in Rinitbyt.c .........................................................................154 EGA-specific configuration ........................................................................................................155 Ribtega.c ....................................................................................................................................156 Stack requirements of the BYT driver ........................................................................................159 5.3 5.3.1 5.3.1.1 5.3.1.2 5.3.1.3 5.3.1.4 5.3.2 5.3.2.1 5.3.2.2 5.3.2.3 5.3.3 5.3.3.1 5.3.3.2 5.3.3.3 5.3.3.4 5.3.3.5 5.3.3.6 5.3.3.7 5.3.3.8 5.3.3.9 5.3.3.10 5.3.3.11 5.3.3.12 5.3.3.13 5.3.3.14 5.3.3.15 5.3.4 5.3.4.1 5.3.4.2 5.3.4.3 5.3.4.4 5.3.4.5 CRT drivers ................................................................................................................................160 Properties ...................................................................................................................................160 Sequence of functions ...............................................................................................................160 Timeout handling........................................................................................................................160 Control characters ......................................................................................................................161 Opcodes of the CRT driver (bits 0 to 3) .....................................................................................162 RmIO interface ...........................................................................................................................162 Function parameter ....................................................................................................................163 Parameter pState .......................................................................................................................164 Parameter pParam .....................................................................................................................165 Opcodes of the CRT driver ........................................................................................................165 Reserve unit (CRT_RESERVE) .................................................................................................165 Release unit (CRT_RELEASE) ..................................................................................................166 Read (CRT_READ) ....................................................................................................................166 Write (CRT_WRITE) ..................................................................................................................167 Write (CRT_WRITE) ..................................................................................................................167 Read character in transparent mode (CRT_ONE_XREAD) ......................................................168 Write and read in transparent mode (CRT_WRT_XREAD) .......................................................168 Write and read (CRT_WRT_READ) ...........................................................................................169 Line feed/skip line (CRT_SKIP_LINE) .......................................................................................169 Form feed/clear screen (CRT_FORM_FEED) ...........................................................................169 Read character in transparent mode (CRT_HSFS_XREAD) .....................................................170 Write character (CRT_HSFS_WRITE) .......................................................................................170 Redefine unit (CRT_CREATE_NEW) ........................................................................................170 Keyboard control characters for I/O devices ..............................................................................171 ASCII codes used by the CRT DRIVER ....................................................................................171 Configuration ..............................................................................................................................172 Driver control data table (DCD)..................................................................................................172 Unit Control Data table (UCD) ...................................................................................................172 Driver-specific parameters in the UCD block .............................................................................173 Interrupt routines of the CRT2 driver .........................................................................................177 Stack requirements of the CRT2 driver .....................................................................................177 5.4 5.4.1 RAM disk driver ..........................................................................................................................178 Properties ...................................................................................................................................178 RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 5 Table of contents 5.4.1.1 5.4.1.2 5.4.2 5.4.2.1 5.4.2.2 5.4.2.3 5.4.3 5.4.3.1 5.4.3.2 5.4.3.3 5.4.3.4 5.4.3.5 5.4.3.6 5.4.3.7 5.4.3.8 5.4.4 5.4.4.1 5.4.4.2 Sequence of the RmIO system call ........................................................................................... 179 Opcodes of the RAM DISK driver ............................................................................................. 179 RmIO interface .......................................................................................................................... 180 Function parameter ................................................................................................................... 180 Parameter pState ...................................................................................................................... 181 Parameter pParam .................................................................................................................... 182 Opcodes .................................................................................................................................... 183 Reserve RAM DISK (00H) ........................................................................................................ 183 Release RAM DISK (01H)......................................................................................................... 183 Read logical block (02H) ........................................................................................................... 184 Write logical block (03H) ........................................................................................................... 184 Dummy operation (04H) ............................................................................................................ 184 Read logical blocks (05H) ......................................................................................................... 185 Write logical blocks (06H) ......................................................................................................... 185 I/O control operation (0EH) ....................................................................................................... 186 Configuration ............................................................................................................................. 187 Driver control data (DCD) table ................................................................................................. 187 Unit Control Data table .............................................................................................................. 188 5.5 5.5.1 5.5.1.1 5.5.1.2 5.5.1.3 5.5.2 5.5.2.1 5.5.2.2 5.5.2.3 5.5.3 5.5.3.1 5.5.3.2 5.5.3.3 5.5.3.4 5.5.3.5 5.5.3.6 5.5.3.7 5.5.3.8 DMA driver ................................................................................................................................ 190 Properties .................................................................................................................................. 190 Functionality of the DMA driver ................................................................................................. 190 Note for use as subprogram...................................................................................................... 190 Special features of the DMA controller ..................................................................................... 190 RmIO interface .......................................................................................................................... 191 Function parameter ................................................................................................................... 191 Parameter pState ...................................................................................................................... 192 Parameter pParam .................................................................................................................... 193 Opcodes .................................................................................................................................... 193 Reserve unit (DMA_RESERVE) ............................................................................................... 193 Release unit (DMA_RELEASE) ................................................................................................ 194 Read from memory (DMA_READ) ............................................................................................ 194 Write to memory (DMA_WRITE) ............................................................................................... 194 Transmission abortion (DMA_ABORT) ..................................................................................... 195 Redefine unit (DMA_CREATE) ................................................................................................. 195 Subprogram calls of the DMA driver ......................................................................................... 196 Program call (X_DM2_DRIVER) ............................................................................................... 199 5.6 5.6.1 5.6.1.1 5.6.1.2 5.6.2 5.6.2.1 5.6.2.2 5.6.2.3 5.6.3 5.6.3.1 5.6.3.2 5.6.3.3 5.6.3.4 5.6.3.5 5.6.3.6 FD0 driver.................................................................................................................................. 200 Properties .................................................................................................................................. 200 Sequence of functions ............................................................................................................... 201 Opcodes of the FD0 driver ........................................................................................................ 201 RmIO interface .......................................................................................................................... 202 Function parameter ................................................................................................................... 202 Parameter pState ...................................................................................................................... 203 Parameter pParam .................................................................................................................... 205 Opcodes .................................................................................................................................... 206 Reserve unit (FD2_RESERVE) ................................................................................................. 206 Release unit (FD2_RELEASE) ................................................................................................. 206 Read logical block (FD2_READ_1) ........................................................................................... 207 Write logical block (FD2_WRITE_1) .......................................................................................... 207 Format floppy disk (FD2_FORMAT) ......................................................................................... 207 Read logical blocks (FD2_READ) ............................................................................................. 207 RMOS3 V3.50 Reference Manual Part II 6 Programming Manual, 07/2012, A5E03692298-01 Table of contents 5.6.3.7 5.6.3.8 5.6.3.9 5.6.3.10 5.6.3.11 5.6.3.12 5.6.4 5.6.4.1 5.6.4.2 5.6.4.3 5.6.4.4 Write logical blocks (FD2_WRITE) .............................................................................................208 Position to track (FD2_SEEK) ....................................................................................................208 Position to track 0 (FD2_RECA) ................................................................................................208 Get drive status (FD2_UNIT_RDY) ............................................................................................208 Remove drive parameters (delete) (FD2_DELETE) ..................................................................209 Define drive parameters (create) (FD2_CREATE) ....................................................................209 Configuration ..............................................................................................................................210 Driver control data (DCD) table..................................................................................................210 Unit Control Data (UCD) table ...................................................................................................210 Interrupt routines of the FD0 driver ............................................................................................216 Stack requirements of the FD0 driver ........................................................................................216 5.7 5.7.1 5.7.1.1 5.7.2 5.7.2.1 5.7.2.2 5.7.2.3 5.7.3 5.7.3.1 5.7.3.2 5.7.3.3 5.7.3.4 5.7.3.5 5.7.3.6 5.7.3.7 5.7.3.8 5.7.3.9 5.7.3.10 5.7.4 5.7.4.1 5.7.4.2 5.7.4.3 5.7.4.4 5.7.4.5 HD0 driver ..................................................................................................................................217 Properties ...................................................................................................................................217 Area of application and opcode .................................................................................................218 RmIO interface ...........................................................................................................................218 Function parameter ....................................................................................................................219 Parameter pState .......................................................................................................................220 Parameter pParam .....................................................................................................................222 Opcodes .....................................................................................................................................223 Reserve unit (00H) .....................................................................................................................223 Release unit (01H) .....................................................................................................................223 Read logical block (02H) ............................................................................................................223 Write logical block (03H) ............................................................................................................223 Format hard disk (04H) ..............................................................................................................224 Read logical blocks (05H) ..........................................................................................................224 Write logical blocks (06H) ..........................................................................................................224 Read drive parameters (0AH) ....................................................................................................225 Remove drive parameters (delete or dismount) (0BH) ..............................................................225 Define drive parameters (create or mount) (0CH) .....................................................................225 Configuration ..............................................................................................................................226 Driver control data (DCD) table..................................................................................................226 Unit Control Data (UCD) table ...................................................................................................226 Driver-specific parameters in the UCD block .............................................................................227 Interrupt routines of the HD0 driver............................................................................................233 Stack requirements of the HD0 driver ........................................................................................233 5.8 5.8.1 5.8.1.1 5.8.1.2 5.8.1.3 5.8.1.4 5.8.1.5 5.8.1.6 5.8.1.7 5.8.2 5.8.2.1 5.8.2.2 5.8.2.3 5.8.3 5.8.3.1 5.8.3.2 COM driver .................................................................................................................................234 Properties ...................................................................................................................................234 Sequence of functions ...............................................................................................................234 Timeout handling........................................................................................................................235 Transfer protocol ........................................................................................................................235 Signal sequences .......................................................................................................................236 Example of signal sequences ....................................................................................................238 Control characters ......................................................................................................................241 Opcodes of the COM driver .......................................................................................................241 RmIO interface ...........................................................................................................................242 Function parameter ....................................................................................................................242 Parameter pState .......................................................................................................................243 Parameter pParam .....................................................................................................................244 Opcodes .....................................................................................................................................245 Reserve unit (C64_RESERVE) ..................................................................................................245 Release unit (C64_RELEASE)...................................................................................................246 RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 7 Table of contents A 5.8.3.3 5.8.3.4 5.8.3.5 5.8.4 5.8.4.1 5.8.4.2 5.8.4.3 5.8.4.4 5.8.4.5 Read (C64_READ) .................................................................................................................... 246 Write (C64_WRITE) .................................................................................................................. 247 Redefine unit (C64_CREATE_NEW) ........................................................................................ 247 Configuration ............................................................................................................................. 248 Driver Control Data table (RmDCDStruct in RMTYPES.H) ...................................................... 248 Unit Control Data table (RmUCDStruct in RMTYPES.H) ......................................................... 249 Driver-specific parameters in the UCD block ............................................................................ 249 Interrupt routines of the COM driver ......................................................................................... 254 Stack requirements of the COM driver ...................................................................................... 255 5.9 5.9.1 5.9.1.1 5.9.2 5.9.2.1 5.9.2.2 5.9.2.3 5.9.3 5.9.3.1 5.9.3.2 5.9.3.3 5.9.3.4 5.9.3.5 5.9.3.6 5.9.3.7 5.9.3.8 5.9.4 5.9.4.1 5.9.4.2 SRAM driver .............................................................................................................................. 256 Areas of application ................................................................................................................... 256 Organization of tasks/functions ................................................................................................. 256 RmIO interface .......................................................................................................................... 257 Function parameter ................................................................................................................... 258 Parameter pState ...................................................................................................................... 259 Parameter pParam .................................................................................................................... 260 Opcodes .................................................................................................................................... 260 Reserve unit (RD40_RESERVE) .............................................................................................. 260 Release unit (RD40_FREE) ...................................................................................................... 260 Read logical block (RD40_READ_ONE) ................................................................................... 261 Write logical block (RD40_WRITE_ONE) ................................................................................. 261 Format (RD40_FORMAT) ......................................................................................................... 261 Read logical blocks (RD40_READ_MORE) .............................................................................. 262 Write logical blocks (RD40_WRITE_MORE) ............................................................................. 262 I/O control operation (RD40_IOCTRL) ...................................................................................... 262 Configuration ............................................................................................................................. 264 Driver control data (DCD) table ................................................................................................. 264 Unit Control Data (UCD) table................................................................................................... 265 Abbreviations/glossary .........................................................................................................................267 Index ...................................................................................................................................................275 RMOS3 V3.50 Reference Manual Part II 8 Programming Manual, 07/2012, A5E03692298-01 Table of contents Tables Table 1- 1 Commands ................................................................................................................................... 12 Table 1- 2 Abbreviations ............................................................................................................................... 12 Table 1- 3 General data types ....................................................................................................................... 13 Table 1- 4 Data types of the RMOS3 API ..................................................................................................... 13 Table 5- 1 Combination of read and write operations in DUPLEX mode ...................................................... 98 Table 5- 2 Function code of the internal input interface .............................................................................. 108 Table 5- 3 RmIO parameter Function of the BYT driver ............................................................................. 113 Table 5- 4 Configuration as I/O device (e.g. terminal) ................................................................................ 114 Table 5- 5 Configuration as output device (e.g. line printer) ....................................................................... 115 Table 5- 6 Configuration as input device (e.g. keyboard): .......................................................................... 115 Table 5- 7 RmIO parameter pState ............................................................................................................. 116 Table 5- 8 RmIO parameter pState (continuation) ...................................................................................... 117 Table 5- 9 ASCII characters ........................................................................................................................ 157 Table 5- 10 Defines for status displays ......................................................................................................... 260 Table 5- 11 Parameters in UCD_HEAD ........................................................................................................ 265 Table 5- 12 Parameters in UCD_RD40_TYPE.............................................................................................. 265 Table 5- 13 Parameters in UCD_RD40_COMMON ...................................................................................... 265 RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 9 Table of contents Figures Figure 2-1 System processes ........................................................................................................................ 37 Figure 5-1 Data flow of an incoming expected character in the BYT driver ................................................ 101 Figure 5-2 Data flow of an incoming unexpected character in the BYT driver ............................................ 102 Figure 5-3 Handling of control characters in the BYT driver for transparent read jobs ............................... 102 Figure 5-4 Handling of control characters in the BYT driver for standard read jobs ................................... 103 Figure 5-5 Handling of character output in the BYT driver .......................................................................... 103 Figure 5-6 Keyboard integration .................................................................................................................. 108 Figure 5-7 Example of unit 2 (debugger) output to the assigned window 2 on page 2 ............................... 109 Figure 5-8 Page 0, window arrangement .................................................................................................... 110 Figure 5-9 Page 0, window arrangement .................................................................................................... 110 Figure 5-10 Assigning scan codes to the individual keys .............................................................................. 156 Figure 5-11 Character table from 0 to 255 (0H to FFH), part 1 ..................................................................... 158 Figure 5-12 Character table from 0 to 255 (0H to FFH), part 2 ..................................................................... 159 Figure 5-13 Receiving data ........................................................................................................................... 238 Figure 5-14 Sending data .............................................................................................................................. 239 Figure 5-15 Master slave configuration with initiation conflict ....................................................................... 240 Figure 5-16 Structure of the RMOS3 driver functions ................................................................................... 257 RMOS3 V3.50 Reference Manual Part II 10 Programming Manual, 07/2012, A5E03692298-01 About this manual... 1.1 1 About this manual... Overview This reference manual provides you with support for programming the RMOS3 system. It contains an overview of the supported function calls, of RMOS3 data structures, of error codes and error messages, as well as of the programming of RMOS3 drivers. Chapter 1 "About this manual . . " offers you a guideline to the documentation and explains the notations used in the manual. Chapter 2 ""Function groups (Page 15)" shows the programmable functions in their logical context. If looking for a solution for a specific task, this chapter will help you to identify the function that is suitable for your application. The chapter also provides a description of the conditions for using the individual call groups. For a more detailed description of the individual functions, refer to the part III and IV of the reference manual. Chapter 3 ""Data structures (Page 43)" contains the most important structure definitions used for programming. Chapter 4 ""Error codes and error messages (Page 73)" lists all possible error codes for the RMOS3 components. Chapter 5 "Functions and configuration of the basic I/O system (Page 95)" provides a separate description of the function of each RMOS3 driver and explains the call syntax. RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 11 About this manual... 1.2 Notations 1.2 Notations We use the following notation to enhance legibility of the RMOS3 documentation: Commands Commands control program sequences in dialog or batch mode. The Courier font is used in the text to highlight the commands. A command consists of at least one element. Elements are constants or variables. They are comprised of letters, numbers and special characters (e.g. #*?). The Courier font is also used to present program listings. They are printed in compliance with the characters and do not follow the notation for commands. The programming language C, for example, distinguishes between uppercase and lowercase notation. Table 1- 1 Commands Representation Property Comment UPPERCASE Constant Elements in uppercase notation represent constants. Entries are made in accordance with the character notation with support of uppercase and lowercase letters. 1847 Constant Numbers are always constants. x Variable Elements in lowercase notation represent variables that can be replaced by current elements. ()\:;> Special characters Special characters and whitespaces serve as delimiters between elements and always need to be entered. The use of elements is described by meta characters. Meta characters are not entered. Representation Property Comment <> Delimiters Variables are enclosed in angled brackets [] Optional Elements in angled brackets are optional. Selection An element can be selected if several elements are arranged vertically in braces or horizontally between vertical lines. Repetition Ellipses indicate a possible repetition of the previous element. |a|b|c| ... Abbreviations A number of abbreviations and short names apply to the entire RMOS3 documentation: Table 1- 2 Abbreviations Abbreviation Meaning Text passage cfg configurable System calls uintmax maximum unsigned integer (FFFF FFFFH) System calls dp data pointer (sel:off) 48-bit pointer System calls RMOS3 V3.50 Reference Manual Part II 12 Programming Manual, 07/2012, A5E03692298-01 About this manual... 1.2 Notations Data types The following data types may be used for the C compilers approved for RMOS3: Table 1- 3 General data types Data type Data length char 8 bit short 16 bit int 32 bit long long 32 bit long 1 64 bit void _FAR * 2 48 bit void _NEAR * 32 bit 2 enum 32 bit float 32 bit double 64 bit 1 Only available for GNU programs. 2 Pointers in flat programs always have a length of 32 bit. No distinction is made between NEAR and FAR. Table 1- 4 Data types of the RMOS3 API Name Data type Data length uchar unsigned char 8 bit ushort unsigned short 16 bit uint unsigned int 32 bit ulong unsigned long 32 bit rmfarproc 1 Pointer to function type void _FAR f(void) 48 bit rmnearproc 1 Pointer to function type void _NEAR f(void) 32 bit rmproc 1 Pointer to function type void _NEAR f(void) 32 bit 1 Pointers in flat programs always have a length of 32 bit. No distinction is made between NEAR and FAR. RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 13 About this manual... 1.2 Notations RMOS3 V3.50 Reference Manual Part II 14 Programming Manual, 07/2012, A5E03692298-01 2 Function groups The chapter lists the expressions used to program RMOS3 in their logical context. If using the functions of a group in reloadable tasks or programs, you need to provide the corresponding library during linking: For GNU compilers: 2.1 RMOS3 kernel functions libhlig.a CLI functions libclig.a C library functions libcrig.a RMOS3 functions RMOS3 V3.11 or higher offers a new application programming interface (API). The API is a pure function interface, with the return value of the function generally providing information related to the sequence (error code etc.). The function may also return notes. This API is supplied as library for compilers with segmented memory model and for compilers with FLAT memory model. Certain calls (descriptor operations, configuration calls) are not implemented in the FLAT interface. Programs and tasks that output calls to RMOS3 in accordance with V3.0 or earlier can still be executed. RMAPI.H is included as header file with the prototypes for the API. This file, in turn, includes the RMTYPES.H (SVC specific type definitions) and RMDEF.H (general definitions such as error codes etc.) files. The RMCOMP.H header file contains macros for customizing the application to the different C compilers and memory models. These macros are used by other include files (RMAPI.H, CRUN). The header file SVC.H is only required for SVCs to be migrated from an interface for RMOS3 V3.0. RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 15 Function groups 2.1 RMOS3 functions 2.1.1 Notes on programming in C The RMOS3 system calls are demonstrated based on code examples written in C. The C interface is described by the RMAPI.H file in directory INC. This file contains all function prototypes of the RMOS3 API. The files RMDEF.H and RMTYPES.H are also included. RMDEF.H contains the define constants, while RMTYPES.H contains the structures for programming the system calls. It is advisable to use the defined constants from RMDEF.H to exclude parameter errors. The parameters are always transferred via stack, with the return value containing the SVC error code. RM_OK (= 0) is returned if no errors were found. A value greater than 0 is returned if errors are found. Certain SVCs also return negative values, e.g. RmSetFlag returns RM_FLAG_ALREADY_SET if the flag was already set. Example of a system call: main() { int Error; void *Pointer; ... Error = RmAlloc( RM_CONTINUE, RM_NOAUTOFREE, 0ul, &Pointer) ... } Allocates a memory space of 1000 bytes that is not released automatically, therefore it is not allocated to specific tasks. The program does not wait on allocation if there is not sufficient memory space available. Notes on using PUBLIC symbols All PUBLIC symbols used in RMOS3 start with an x or x_ coding. These symbols are also available for the software drivers. It is advisable to dispense with the usage of PUBLIC symbols beginning with x or x_ to avoid possible conflicts. Interrupt numbers The interrupt number for all interrupt handler SVCs can be set in two different ways: 1. Number between 0 and 255 The interrupt is handled as software interrupt. 2. IRQ The number is entered directly, e.g. IRQ1, IRQ2. The interrupt is handled as hardware interrupt. Values such as IRQ1 or IRQ2 are specified in an include file. The IRQ(x) macro can be used to transfer the IRQ number in a variable. (x) can be a value between 0 and the maximum available interrupt. The range of values 0..15 (0..23 for APIC) is valid on the PC. RMOS3 V3.50 Reference Manual Part II 16 Programming Manual, 07/2012, A5E03692298-01 Function groups 2.1 RMOS3 functions Notes on timer programming Timeout values used in your program are entered in the timer queue according to their expiration time (sorted by timer ticks). Multiple timeout requests for a timer tick are processed based on the Last In First Out principle. If a timer tick is triggered between two timeout requests of the same duration, the requests are distributed to different timer ticks. Example: Timeout request 1,2,3 within one timer tick, and timeout request 4,5,6 within the next timer tick. The order in the timer queue is 3,2,1,6,5,4. Proceed as follows to ensure that all timer calls are executed within the same timer tick. 1. Set the task to maximum system priority to prevent other tasks from interrupting it. 2. Pause with 0 for synchronization to the next timer tick. 3. Output the timeout requests. 4. Reset task priority to its original value. Verify that processing is completed within one timer tick. 2.1.2 Short description of the RMOS3 functions Overview The RMOS3 functions form the interface to the operating system and enable access to the operating system utilities. For a detailed description of these functions, refer to Reference Manual Part III. System startup RmCreateOS Adapt dynamic to static resource IDs RmInitOS Pass start addresses of the subprograms for hardware operation RmResetOS Start operating system configuration RmRunOS Initialize all driver units RmSetOS Run system configuration RmSetPutcharProc Publish the address of function putchar() RmSetSMRCount Set SMR limit RmSetSVC Initialize SVC table RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 17 Function groups 2.1 RMOS3 functions Memory RmAlloc Allocate HEAP memory area RmCreateMemPool Create dynamic memory pool RmDeleteMemPool Delete dynamic memory pool RmExclude Reserve memory pool area RmFree Release memory area for specific task RmFreeAll Release all memory areas for specific tasks RmGetSize Get memory area length RmMemPoolAlloc Allocate memory area from memory pool RmReAlloc Change memory area size RmGetMemPoolInfo Get information on memory pool RmChangeDescriptor Change descriptor RmChangeDescriptorAccess Change descriptor access rights RmCreateDescriptor Create descriptor RmDeleteDescriptor Delete descriptor RmGetLinAddress Get linear address from pointer RmGetPhysAddress Get physical address of a memory area RmMapMemory Address physical memory RmActivateTask Activate task RmBindTask Bind task to core RmCreateTask Registers static or reloadable task with the operating system RmCreateChildTask Registers static or reloadable task with the operating system RmCreateTaskEx Define dynamic task RmDeleteTask Delete dynamic task RmDisableScheduler Disable scheduler RmEnableScheduler Enable scheduler RmEndTask End task RmGetBindTaskInfo Get task binding information RmGetTaskID Get task ID RmGetTaskInfo Get task information RmGetTaskPriority Get task priority RmGetTaskState Get task state RmKillTask Set task to DORMANT or NON-EXISTENT state RmPauseTask Wait for expiration of time interval Descriptors Task control RMOS3 V3.50 Reference Manual Part II 18 Programming Manual, 07/2012, A5E03692298-01 Function groups 2.1 RMOS3 functions RmQueueStartTask Add task start request to queue. The task is started as soon as it is in DORMANT state. RmRestartTask End and then restart the task on expiration of the time interval. RmResumeTask RmSetTaskPriority Terminate interval that was initiated with RmSuspendTask or RmPauseTask Change task priority RmStartTask Task start request for tasks in DORMANT state. RmSuspendTask Set task to BLOCKED state RmCatalog Enter resource in resource catalog RmGetEntry Find catalog entry RmGetName Search catalog for entry RmList List catalog entries RmUncatalog Remove resource from catalog RmCreateMessageQueue Create message queue RmDeleteMessageQueue Clear message queue RmReadMessage Fetch message from message queue RmSendMessage Add message to message queue RmSetMessageQueueSize Set message queue length RmCreateMailbox Define dynamic mailbox RmDeleteMailbox Delete dynamic mailbox RmReceiveMail Receive mail from local mailbox RmSendMail Send mail to local mailbox RmSendMailCancel Cancel timer that was started with RmSendMailDelayed Resources Messages Mails RmSendMailDelayed RmSetMailboxSize Transfer mail to mailbox with time-delay Set mailbox limits RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 19 Function groups 2.1 RMOS3 functions Flags RmCreateFlagGrp Define dynamic flag group RmDeleteFlagGrp Delete dynamic flag group RmGetFlag Test event flag RmResetFlag Reset event flag RmResetLocalFlag Reset local event flag RmSetFlag Set event flag RmSetFlagDelayed Set event flag on expiration of an interval RmSetLocalFlag Set local event flag RmCreateBinSemaphore Define dynamic semaphore RmDeleteBinSemaphore Delete dynamic semaphore RmReleaseBinSemaphore Reset semaphore RmGetBinSemaphore Test and set semaphore RmInitSpinLock Initialize SpinLock RmGetSpinLock Request SpinLock RmGetSpinLockIRQ Request SpinLock and disable interrupts RmReleaseSpinLock Release SpinLock RmReleaseSpinLockIRQ Release SpinLock and enable interrupts Semaphores SpinLocks Time management RmSetSystemTime Set date and time RmGetSystemTime Transfer date and time from the system RmSetHWClockTime Set date and HW clock RmGetHWClockTime Transfer date and HW clock RmGetAbsTime Transfer date and absolute time from the system RmGetSystemPeriod Query system clock rate RMOS3 V3.50 Reference Manual Part II 20 Programming Manual, 07/2012, A5E03692298-01 Function groups 2.1 RMOS3 functions Fast cycle times RmInitFastTick Initialize fast cycle with time pattern shorter than one millisecond RmRemoveFastTick Remove fast cycle RmInitFastTask Start task in fast cycle RmRemoveFastTask Remove task from fast cycle RmInitHPET Initialize function for reading HPET timer 0 RmGetTimeHPET0 Read current counter of HPET timer 0 RmGetPeriodHPET0 Query period of HPET timer 0 RmCreateDriver Register static or reloadable driver at the operating system RmCreateUnit Register unit at the operating system RmIO Request I/O operation RmResumeDriver Define new device driver RmSuspendDriver Suspend device driver (set to BLOCKED state) RmDecode Decode RMOS3 error number RmGetSysB Read System Control Block RmGetIntHandler Read interrupt handler RmReserveInterrupt 1 Reserve interrupt RmRestoreIntHandler Restore DI interrupt handler in GNU RmSetIntDIHandler Set DI interrupt handler RmSetIntISHandler Set S or I interrupt handler RmSetIntTaskHandler Set task start by interrupt handler RmSetIntMailboxHandler Set mailbox interrupt handler RmSetDeviceHandler 1 Create driver interrupt handler RmSetIntDefHandler Install default interrupt handler HPET functions Drivers System Interrupt handlers 1 Effective only at system startup RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 21 Function groups 2.1 RMOS3 functions Interrupt handlers on the PCI bus RmPciSearchFunction Scan the PCI bus for PCI devices (vendor and device ID) RmPciSearchSubFunction Scan the PCI bus for PCI devices and their subsystem IDs (vendor and device ID) RmIntShSrv Initialize Shared Interrupt Server RmInitShIntClient Initialize Shared Interrupt Client RmSetShIntISHandler1 Install Shared Interrupt Handler in compatibility mode RmSetShIntISHandler2 Install Shared Interrupt Handler in fast mode RmClrShIntISHandler Delete Shared Interrupt Handler RmHookException Hook callback function that is called on exception RmSetProfilerPoint Set orientation points in the profiler for "Task Activity" measurement Miscellaneous RMOS3 V3.50 Reference Manual Part II 22 Programming Manual, 07/2012, A5E03692298-01 Function groups 2.1 RMOS3 functions 2.1.3 Configuration functions Overview In addition to general information, these functions offer the possibility of performing a task/driver-/block-specific configuration. For a description of these functions, refer to Reference Manual Part IV. RcEOIProcPC EOI routine for PC-compatible modules RcGetCMOSDateTime Read date and time from the CMOS clock (PC) RcGetCMOSSize Read length of RAM from CMOS RAM (PC) RcDummyGetClock Dummy function RcGetFloppyType Read type and ID of floppy drives from CMOS RAM RcGetHardDiskType Read HDD type from CMOS RAM RcRAMSize Configure RAM size RcInit3964 Register 3964 driver in RMOS3 RcInit3964r8250 Register 8250 block at the 3964 driver RcInit3964r8530 Register 8530 block at the 3964 driver RcInit3964rCOM1 Register COM1 interface at the 3964 driver RcInit3964rCOM2 Register COM2 interface at the 3964 driver RcInit8254 Initialize 8254 timer RcInit8259A Initialize 8259A interrupt controller RcInitByt Register BYT driver in RMOS3 RcInitByt8250 Register 8250 block at the BYT driver RcInitByt8251 Register 8251 block at the BYT driver RcInitByt8255 Register PC line printer at the BYT driver RcInitByt8530 Register 8530 block at the BYT driver RcInitBytCOM1 Register COM1 interface at the BYT driver RcInitBytCOM2 Register COM2 interface at the BYT driver RcInitBytEga Register EGA display adapter at the BYT driver RcInitBytLPT1 Register LPT1 at the BYT driver RcInitBytLPT2 Register LPT2 at the BYT driver RcInitCLIDispatcher Create dispatcher task for debugger and CLI RcInitCrt Register CRT driver in RMOS3 RcInitCrt8250 Register 8250 block at the CRT driver RcInitCrtCOM1 Register COM1 interface at the CRT driver RcInitCrtCOM2 Register COM2 interface at the CRT driver RcInitDEBDispatcher Create dispatcher task without CLI RcInitDebugger Create debugger RcInitEmul Initialize co-processor emulator RcInitErrorLogger Create error logger task RcInitFd0 Register PC floppy driver in RMOS3 RcInitHd0 Register PC HD driver in RMOS3 RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 23 Function groups 2.1 RMOS3 functions RcInitHsfs Allocate resources for HSFS RcInitNPX Initialize co-processor RcInitPasspoint8250 Initialize 8250 block RcInitPasspoint8251 Initialize 8251 block RcInitPasspoint8530 Initialize 8530 block RcInitPasspointEga Initialize EGA adapter RcInitPICPC Initialize interrupt controller on PC hardware RcInitRamdisk Register RAM disk driver in RMOS3 RcInitRamdisk32 Register RAM disk driver in RMOS3 RcInitRemoteTask Create remote task RcInitReporter Create reporter task RcInitReporterX Create ReporterX task RcInitTimerPC Initialize 8254 timer on PC hardware RcInitUserTask Create user task RcPutchar8250COM1 Output character to 8250 block (COM1) RcPutchar8250COM2 Output character to 8250 block (COM2) RcPutchar8251 Output character to 8251 block RcPutchar8530 Output character to 8530 block RcPutcharEga Output character to EGA adapter RcScanRAMSize Query RAM length (with memory test) RcSetCMOSDateTime Set date and time of the CMOS clock (PC) RcSetDummyDateTime Dummy function RcSetFloppyType Set type and ID of floppy drives in CMOS RAM (PC) RMOS3 V3.50 Reference Manual Part II 24 Programming Manual, 07/2012, A5E03692298-01 Function groups 2.1 RMOS3 functions 2.1.4 Miscellaneous functions Overview This chapter describes special functions. Corresponding information is available in Reference Manual Part IV. Task start parameters get2ndparm Read task start parameter EBX getparm Read task start parameter as pointer getdword Read task start parameter as long value stl_load Load task stl_free De-allocate task x_hd_init Integration of one or several HD partitions into the HSFS Task operations HDD functions System functions for BUSY task x_bu_init Initialize BUSY task x_bu_get Query average system idle time in percent RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 25 Function groups 2.2 CLI functions 2.2 CLI functions 2.2.1 Startup code for C programs Initialization At the jump to the loaded program, the CLI performs the following actions: Register task with xinitt as task using CRUN support. Redirect stdin, stdout or stderr , if necessary. Disassemble the command line and convert to argc/argv format. The startup code is executed on completion. _FAR is defined in the RMCOMP.H file. 2.2.2 Problems when aborting a program A program is aborted by entering + or executing the CANCEL command. The task immediately jumps to CRUN function exit, regardless of its current activity. Abortion is only delayed if the task has output a system call (SVC) and is not executed until this call was completed. System resources requested by means of CRUN calls are released automatically. This rule applies both to dynamically allocated memory space and to files opened with fopen or fduopen. System resources that were not requested by means of CRUN calls are not released. The same applies to files opened with HSFS calls, for example. If the task is currently in possession of a semaphore, this semaphore is not released. You may install an atexit handler (CRUN function) to release resources allocated directly by RMOS3 (e.g: semaphores, flags, mailboxes). You can also inhibit abortion for the duration of a specific time. The x_cli_inhibit_abort CLI function and the inhibitabort CRUN function are available for this purpose. RMOS3 V3.50 Reference Manual Part II 26 Programming Manual, 07/2012, A5E03692298-01 Function groups 2.2 CLI functions 2.2.3 Short description of the CLI functions RMOS3 programs can utilize the following CLI functions. For information about these functions, refer to Reference Manual Part IV. x_cli_cancel Cancel job started with x_cli_cmdexec Execute CLI command x_cli_extended_session or x_cli_extended_start. x_cli_cmdline Read command line and process any redirection character that was possibly read x_cli_errorlevel Read error level x_cli_extended_session Start foreground job x_cli_extended_start Start background job x_cli_get_device Determines whether a given name is a device name. If yes, the device and unit numbers will be returned. x_cli_inhibit_abort Inhibit command abortion across a specific period, or permit it again x_cli_inhibit_control_c Inhibit command abortion with +C x_cli_init_manager Initialize CLI program manager x_cli_job_command Returns a pointer to the command line that was used to start a job x_cli_job_command_tail Returns a pointer to the parameters which were used to start a job x_cli_prompt Returns the current prompt in expanded form. x_cli_restart_job_pl0 Restart application at privilege level 0 x_cli_session Start foreground job x_cli_start Start background job x_cli_test_abort Determines whether an attempt was made to abort a job with +C or cancel while this action was inhibited. x_cli_truename Convert file name to file name with absolute path RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 27 Function groups 2.3 C library functions 2.3 C library functions 2.3.1 Scope of the C library The C library encompasses functions and macros in accordance with the following classification criteria or function classes (these function classes are identical to the greater extent with those mentioned in standard technical references): I/O operations, e.g. HDD, terminal, printer, ... Character management String operations Memory operations Memory allocation Mathematical functions Time and date functions Control functions Error handling Miscellaneous functions 2.3.2 Short description of the C library functions I/O operations I/O operations form the most extensive function class of the C library . It includes functions used in C programs to execute I/O operations (also by means of RMOS3 drivers), as well as functions for verifying/formatting I/O data and for file management. The functions are declared in the IO.H and STDIO.H header files. Current Working Directory The name of a file or directory is specified for certain functions (access, fopen, freopen, open, remove, rename, unlink and chdir). This name always relates to the task-specific Current Working Directory (CWD), with each task having a separate CWD. The CWD of a task is not initialized initially and is set by means of function call chdir. RMOS3 V3.50 Reference Manual Part II 28 Programming Manual, 07/2012, A5E03692298-01 Function groups 2.3 C library functions Rules for file and directory names The colon `:' is used as delimiter between the drive name and the file or directory name. It may be entered as second or third character in the path string and is not allowed in any other positions. This also implies that you may only use drive names with a length of one or two letters. Example: R:TEST The `\' and `/' delimit the directory names, or the directory name and file name. Example: DIR1\DIR2\DATEI Path names that begin with a drive name, i.e. with colon `:' as second or third character (drive name on the left), are absolute path names. The path name is transferred directly to the HSFS, while the CWD is ignored. Example: CWD: B:DEMO.DIR\SOURCE Path name: A:TEXT\README.TXT The addressed README.TXT file is located in the TEXT directory on drive A. Path names that begin with one of the delimiters `\' or `/' are a special form of absolute path name. In this case, the drive name is copied from the CWD and the path name is appended. The absolute path name generated in this way is transferred to the HSFS and the CWD is no longer taken into account. Requirement: the CWD must already be initialized if you are using this type of path name. Example: CWD: B:DEMO.DIR\SOURCE Path name: \TEXT\README.TXT The addressed README.TXT file is located in the TEXT directory on drive B. A path with "\" or "/" is a further variant that is used to address the root directory of the drive specified in the CWD. A typical application is the chdir("\") or chdir("/") command. Path names that do not begin with a delimiter (`\' or `/') or drive name represent relative path names that relate to the CWD. Example: CWD: B:DEMO.DIR\SOURCE Path name: IO\IOTEST.C The addressed IOTEST.C is located in directory DEMO.DIR\SOURCE\IO on drive B. RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 29 Function groups 2.3 C library functions Path names beginning with ".." (e.g. "..\") are special variants of relative path names. Each string of ".." at the beginning of the path returns the level by one step to the data volume name, starting at the CWD. Example: CWD: B:DEMO.DIR\SOURCE Path name: ..\BIN\IOTEST.386 The addressed IOTEST.386 file is located in directory DEMO.DIR\BIN on drive B. Example: CWD: B:DEMO.DIR\SOURCE Path name: ..\..\DOC.DIR\IO.TXT The addressed IO.TXT file is located in directory DOC.DIR on drive B. The path specification with ".." is a variant. It is used to address the directory that is closer by one level to the drive name than the CWD. A typical application is the chdir("..") command. You always need to specify absolute path names if the task CWD is not yet initialized. CRUN calls supported in the FAT16/FAT32 file systems The file system is adapted to support the use of long file names with the following CRUN calls: fopen A file can be opened with both the long and the short name. rename Rename supported for files with long or short name. unlink A file can be deleted with both the long and the short name. remove A file can be deleted with both the long and the short name. mkdir A directory can be created with both the long and the short name. search A file can be searched for with both the long and the short name. For searches with long name, the short name is always written to the DIR_ENTRY structure. searchlong A file can be searched for with both the long and the short name. rmdir A directory can be deleted with both the long and the host name. RMOS3 V3.50 Reference Manual Part II 30 Programming Manual, 07/2012, A5E03692298-01 Function groups 2.3 C library functions Text mode - Binary mode Whether to open a stream/handle in text or binary mode is specified in the fopen, fduopen, freopen, fdureopen and open functions. If a stream or handle is opened in text mode, all `\n' (New Line) are converted into `\r\n' (Carriage Return - New Line) for write access, while all `\r\n' (Carriage Return - New Line) strings are converted into `\n' (New Line) for read operations. No conversion is performed for streams or handles that were opened in binary mode. NUL file You can open a NUL file that exists in the system, without the file actually being physically present anywhere. Once it is opened, you can use the NUL file to perform all operations that are also possible with standard files. The difference is that write calls (e.g. fwrite) and read calls (e.g. fread) in conjunction with the NUL file are terminated immediately without I/O operations having been performed. All write operations accessing the NUL file are terminated (return value, errno, errno2, etc.) so that no error is signaled. Read operations to the NUL file report an EOF (End of File). The NUL file is addressed if NUL is set for the file or path name (any uppercase/lowercase combination) (e.g. fopen("NUL", "w")). File access functions The following function calls are used to read/write data and to open, close, rename or delete files. access Verify access to file chdir Change current working directory changevib Change description block of data volume checkpoint Save data from (HSFS) intermediate file buffer chmod Change file attributes clearerr Reset stream error status close Close file createvib Create new description block of data volume dismount Log off device from HSFS file system duread Read character by means of RMOS3 driver duwrite Write character by means of RMOS3 driver fclose Close stream fduopen Open stream to RMOS3 driver fdureopen Redirect stream to driver feof Query stream status after EOF ferror Query stream status after I/O error fflush Flush stream buffer fgetc Read character from stream fgetpos Return current position in file fgets Read string from stream fileno Determine file descriptor fopen Open stream fprintf Formatted output to stream fputc Write character to stream RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 31 Function groups 2.3 C library functions fputs Write string to stream fread Read data from stream freopen Replace file assigned to a stream fscanf Formatted input from stream fseek Position data pointer in stream fsetpos Set current position in file ftell Determine data pointer in stream fwrite Write data to stream getc Read character from stream getchar Read character from the standard input getcwd Determine current working directory gets Read string from stream getvolumestatus Get status information of data volume getw Read word from stream lseek Position data pointer in file mkdir Create directory mount Mount device in HSFS open Open file for read/write access printf Formatted output to standard output putc Write character to stream putchar Write character to standard output puts Write string to stream putw Write word to stream read Read data from file remap Format data volume remove Remove file rename Rename file rewind Position data pointer in stream rmdir Delete directory scanf Formatted input from standard input search Search for files setbuf Set stream buffer setvbuf Set stream buffer sprintf Formatted output to string sscanf Formatted input from a string tmpfile Create temporary file tmpnam Create name for temporary file ungetc Write back character to stream unlink Formatted output to stream vfprintf Formatted output to stream vprintf Formatted output to stream vsprintf Formatted output to string write Write data to file RMOS3 V3.50 Reference Manual Part II 32 Programming Manual, 07/2012, A5E03692298-01 Function groups 2.3 C library functions Character management Character management contains functions that are used to convert and classify character types and that are declared in the CTYPE.H header file. _tolower Convert characters to lowercase _toupper Convert characters to uppercase isalnum Specify whether a character is alphanumerical isalpha Specify whether a character is alphabetical isascii Specify whether a character is an ASCII character iscntrl Specify whether a character is an ASCII control character isdigit Specify whether a character is a decimal number isgraph Specify whether a character is printable islower Specify whether a character is a lowercase letter isprint Specify whether a character is printable ispunct Specify whether a character is a punctuation mark isspace Specify whether a character is a whitespace isupper Specify whether a character is an uppercase letter isxdigit Specify whether a character is a hexadecimal number toascii Convert character to integer tolower Convert character to lowercase toupper Convert character to uppercase String operations String operations can be used to verify and edit strings or byte sequences and are declared in the STRING.H and STDLIB.H header files. atof Convert string to double number atoi Convert string to integer atol Convert string to long integer strcat Append string to second string strchr Search for character in a string strcmp Compare two strings strcpy Copy string to second string strcspn Compare two strings strlen Get string length strncat Append string segment to second string strncmp Compare two string segments strncpy Copy string segment strpbrk Compare characters in two strings strrchr Search for character in a string strspn Compare two strings strstr Compare two strings strtod Convert string to double number strtok Find character unequal to delimiter in string strtol Convert string to long integer strtoul Convert string to unsigned long integer RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 33 Function groups 2.3 C library functions Memory operations Memory operations can be used to copy characters and compare or write to memory areas. and are declared in the STRING.H and MEMORY.H header files. memccpy Copy character from source to target memchr Find character memcmp Compare content of two memory ranges memcpy Copy character from source to target memmove Copy character from source to target memset Pad memory area with characters Memory allocation These functions are declared in the MALLOC.H and STDLIB.H header files. calloc Request memory space an initialize with 0 free Release memory realloc Change length of memory space malloc Request memory space Mathematical functions Functions declared in header file STDLIB.H can only be applied to integers, whereas floating point functions are declared in header file MATH.H. abs Calculate absolute value of an integer acos Arc cosine asin Arc sine atan Arc tangent atan2 Arc tangent of two double numbers ceil Round double number cos Cosine cosh Cosine hyperbolicus div Integer division exp Exponential function fabs Calculate absolute value of double number floor Round down a double number fmod Determine division remainder from two double numbers frexp Split double number labs Determine absolute value of long integer ldexp Generate double number RMOS3 V3.50 Reference Manual Part II 34 Programming Manual, 07/2012, A5E03692298-01 Function groups 2.3 C library functions ldiv Long integer division log Natural logarithm log10 Decadic logarithm matherr Application-specific error handling modf Split double number into integer and fraction pow Power function rand Generate random integer sin Sine sinh Sine hyperbolicus sqrt Square root function srand Set init value for rand tan tanh Tangent Tangent hyperbolicus Time and date functions These functions can be used to adjust time and date information e.g., convert and adjust to the respective time zone. The functions are declared in header file TIME.H. asctime Convert date and time to string ctime Convert date and time to string _ctime32 Convert date and time to string (for time data beyond January 19, 2038) difftime Determine length of period gmtime Convert date and time to GMT _gmtime32 Convert date and time to GMT (for time data beyond January 19, 2038) localtime Convert date and time to local time _localtime32 Convert date and time to local time (for time data beyond January 19, 2038) mktime Convert local time strftime Output formatted date and time time Calculate system time since 01.01.1970, 00:00:00 GMT _time32 Calculate system time since 01.01.1970, 00:00:00 GMT (for time data beyond January 19, 2038) tzset Set time zones Control functions The control functions are required to end tasks and are declared in the STDLIB.H and TASK.H header files. abort End task assert Abort task conditionally atexit Specify the routines to call on task completion exit Clear task and exit with defined state x_cr_killtsk Delete task inhibitabort Inhibit task abortion by means of CTRL-C (IO.H) RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 35 Function groups 2.3 C library functions Error handling Along with errno , an additional errno2 macro is available (RMOS3 extension). For more information, refer to the description of the errno call. The corresponding declarations are available in header file ERRNO.H. errno, errno2 Error numbers of system calls and library functions perror Ouput CRUN error message strerror Get error text sys_nerr Number of entries in sys_errlist sys_errlist String array of error messages Miscellaneous functions Summary of functions that cannot be assigned unambiguously to a class. bsearch Find element in sorted table getenv Get environment variable longjmp Execute non-local jump putenv Change or add environment variable qsort Sorting function raise Trigger signal setjmp Set mark for non-local jump signal Install exception handling function (signal handler) sleep Stop task for a specific time x_cr_gettaskid Get ID of the calling task x_cr_gettaskparam Determine stdin, stdout, stderr and the task environment x_cr_initenv Initialize task environment x_cr_setexit Set task-specific exit handler xinitc Initialize CRUN xinitt Execute task-specific initialization of CRUN RMOS3 V3.50 Reference Manual Part II 36 Programming Manual, 07/2012, A5E03692298-01 Function groups 2.4 Driver functions 2.4 Driver functions 2.4.1 Application model All routines in S state are interpreted as system processes. All system processes are executed sequentially and terminated automatically. The operating system core provides system variables and subprograms to support the functions of system processes. These subprograms support memory allocation, task communication, and the management of RMOS3 data structures. These driver functions can only be called by drivers which were linked statically in the system during system generation. Figure 2-1 System processes Note All subprogram calls in RMOS3 are of the type NEAR, which means that the driver code must always be available in segment RM3_CODE32. The corresponding subprogram parameters are passed by means of static transfer variables. These transfer variables are reserved for system processes only and may not be manipulated by interrupt handlers in DI or I state. Transfer variables are also used to pass parameters to driver entry points for handling I/O requests. RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 37 Function groups 2.4 Driver functions 2.4.2 Short description of the driver functions Assembler _ELIPSE Transition from DI to I state X_SYSTATE Transition from I to S state X_SYSTATE_SW Transition from I to S state without EOI X_XEL Change from I state to scheduler X_XEL_SW Change from I state to scheduler without EOI XCATALOG Enter in the RMOS3 resource catalog XCHANGEDESC Change descriptor base and/or limits XCHANGEDESCACCESS Change descriptor access byte XCREATEDESC Create descriptor XDELDESC Delete the descriptor specified by means of selector XDELTMB Remove TMB from monitoring list XDEVDATA Calculate XDCB and XUCB according to XDEVNUM and XDEVUNIT XDQTMB Exclude TMB from the monitoring list without releasing it XDWORD Convert the offset address of an RMOS3 data variable to doubleword address XERRLOG Log error at the system console, if available (error logger task) XEXSYS Exit the S state (end system process) XGETSMR Request system memory block XHALOC Allocate pool memory space XHDALOC Release memory space XIODONE Complete processing of SVC RmIO for type I drivers Assembler and C XOVER, xjmp_xover Completion of I/O request for type II drivers in C XPHYSADR Determine physical address XPUTSMR Return system memory block XQPIRB Add active IRB to the queue of a parallel driver XQSETUNS Queue start of user task for unexpected interrupts XQSIRB Add active IRB to the queue of a serial driver XQSTRT Add task start request to queue XQTMB Add TMB from monitoring list XRECV Receive mail from local mailbox XREF Reset event flag XSEF Set event flag XSEND Send mail to local mailbox XSETUNS Start user task for unexpected interrupts XSYSTEM Transition from DI to System state XTEF Test event flag XTIMEOUT Set device timeout (only type II drivers) RMOS3 V3.50 Reference Manual Part II 38 Programming Manual, 07/2012, A5E03692298-01 Function groups 2.4 Driver functions 2.4.3 System variables for parameter transfer The following variables are used to pass parameters to the subprograms of the nucleus and to pass parameters returned by the operating system kernel. All variables may only be used in S state. 2.4.4 Name Description Length XCIRB Address of the current I/O request block (IRB) 6 bytes XDEVNUM Current driver ID 1 byte XDEVUNIT Current device ID 1 byte XUCB Current UCB address 6 bytes XDCB Current DCB address 6 bytes XERRMSG Error message address 6 bytes XOFFSET OFFSET address; general usage 4 bytes XPOINTER OFFSET/SEGMENT address; general usage 6 bytes XSTATUS Status data to return to the task 8 bytes XTUNIT Time interval for timers 1 byte XTNUM Number of time intervals for timers 1 byte XPOOLNUM Memory pool ID for XHALOC and XHDALOC 1 byte XBLKLEN Number of bytes for XHALOC and XHDALOC 4 bytes XSEQ Sequential number of current IRB 2 bytes XSEG Selector for segment handling 2 bytes XSEGLIM Segment limit 4 bytes XTASK Task ID 2 bytes XPRIS Options for priority source 1 byte XPRIV Priority to use 1 byte XP1 Parameter 1 4 bytes XP2 Parameter 2 4 bytes XGRP Global event flag ID 1 byte XFLAGS Mask for flag group 4 bytes XBOX Local mailbox ID 1 byte XGENB Byte for general usage 1 byte XGENW Word for general usage 2 bytes XGEND Dword for general usage 4 bytes Differences between type I and type II drivers RMOS3 supports two different interfaces for drivers. Depending on the type of interface required, this driver is named type I or type II driver. Compared to type I drivers, type II drivers are more supported by subprograms of the nucleus and are therefore easier to program. You need to explicitly program nucleus support for type I drivers. RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 39 Function groups 2.4 Driver functions Primary differences between type I and type II drivers include the following: Handling RmIO parameter Function Type I drivers only have one entry point for handling I/O requests and must handle and execute all functions on their own dependent on the Function parameter. Type II drivers are provided with an entry point table for handling the functions. Depending on the Function parameter, the nucleus uses this entry point table to jump to a procedure of the driver for handling I/O requests pending. The driver jump table starts with function 2, because function 0 (reserve device) and function 1 (release device) are already implemented in the operating system kernel. Possible layout of the entry point table for type II drivers for handling an RmIO SVC: BRANCH_TBL DD READ_BLK DD WRITE_BLK DD CLEAR_UNIT ;code 2: read a block ;code 3: write a block ;code 4: reset unit The nucleus jumps directly to the procedures identified by the addresses in the table if requests to the driver with corresponding functions are pending. The nucleus, for example, directly calls the WRITE_BLK procedure if a request with function code 3 is pending. Note The jump table in RMOS3 consists of offset addresses (32-bit). The code must be available in segment RM3_CODE32. Reserving and releasing devices The reserve and release functions are implemented directly in the operating system kernel for type II drivers. Only the task that has reserved the device may release it. When bit 7 of parameter Function is set and the I/O device is currently processing an I/O request, the priority of the I/O request is raised to 255 and the IRB block is written to the first position in the queue after any preemptive requests that may already be queued. A reservation of the device by another task is ignored. Handling timeouts Type I drivers must completely process timeout events. This gives the programmer more scope. Although the nucleus handles timeout events at type II drivers, the driver can actually handle the event by itself. Status bits The nucleus sets and resets bit 0 (status) of DCB_STS or UCB_STS (sequential/parallel) for type II drivers. RMOS3 V3.50 Reference Manual Part II 40 Programming Manual, 07/2012, A5E03692298-01 Function groups 2.4 Driver functions Completing a job The type I driver terminates an I/O request and must then scan the request queue to initiate the next execution. This also enables the sharing of devices with another driver (if it is necessary to implement this property). The type II driver completes an I/O request by calling a nucleus procedure. This procedure manages the I/O request queue of the corresponding driver. The driver is reset to the active state via the entry point table if a further request is pending in the queue. Subprograms Both driver interfaces are supported by subprograms. Certain subprograms support only one interface type. RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 41 Function groups 2.4 Driver functions RMOS3 V3.50 Reference Manual Part II 42 Programming Manual, 07/2012, A5E03692298-01 3 Data structures 3.1 Syntax RmAbsTimeStruct #include typedef struct _RmAbsTimeStruct { ulong lotime; ulong hitime; }RmAbsTimeStruct; Description Contains the system time and date (absolute system time) and is used by the RmGetAbsTime and RmSetAbsTime SVCs. Field Type Meaning lotime ulong Least significant segment of the absolute time hitime ulong Most significant segment of the absolute time See also RmGetAbsTime, RmSetAbsTime RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 43 Data structures 3.2 RmAsciiTimeStruct 3.2 Syntax RmAsciiTimeStruct #include typedef struct _RmAsciiTimeStruct { char day[2]; /* 01 ... 31 (ASCII) char delim0; /* '-' char month[3];/* JAN ... DEC (ASCII) char delim1; /* '-' char year[4]; /* 0 ... 9999 (ASCII) char blank; /* ' ' char hour[2]; /* 0 ... 23 (ASCII) char colon0; /* ':' char min[2]; /* 0 ... 59 (ASCII) char colon1; /* ':' char sec[2]; /* 0 ... 59 (ASCII) }RmAsciiTimeStruct; */ */ */ */ */ */ */ */ */ */ */ Description Contains the system time and date (local or global system time) in ASCII format; used by the RmGetSystemTime and RmSetSystemTime SVCs. The various elements have the value ranges specified in the comments. See also RmGetSystemTime, RmSetSystemTime RMOS3 V3.50 Reference Manual Part II 44 Programming Manual, 07/2012, A5E03692298-01 Data structures 3.3 RmDCDStruct 3.3 Syntax RmDCDStruct #include typedef struct _RmDCDStruct { struct _RmUCDStruct _NEAR * ucd; uchar units; uchar shr; rmproc init; rmproc svc; uchar flags; uchar fmax; #if RM3 uchar res[4]; #else uchar res[2]; #endif }RmDCDStruct; Description The RmDCDStruct structure defines a structure for driver control data Field Type Meaning ucd Pointer to UCD address units RmUCDStruct uchar Reserved shr uchar Device number of a shared device (0FFH=no sharing) init rmproc Address of the driver init routine svc rmproc flags uchar Address of the RmIO entry point Bit Meaning 0=1 Parallel driver 0=0 Sequential driver 1=1 Type II driver 1=0 Type I driver 2=0 Driver is initialized after system init 2=1 Driver is not initialized after system init and suspended (in BLOCKED state) fmax uchar Maximum function code of the driver res[24] uchar Reserved See also RmIO RmUCDHeadStruct (Page 67) RmUCDStruct (Page 68) RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 45 Data structures 3.4 RmEntryStruct 3.4 Syntax RmEntryStruct #include typedef struct _RmEntryStruct { uchar slen; char string[16]; uchar type; ulong ide; ushort id; }RmEntryStruct; Description The RmEntryStruct structure is used in SVCs RmList and RmGetEntry to read catalog entries. Field Type Meaning slen uchar Length of next string. string char[16] String containing a resource name. type uchar Sets the resource type. The following values are possible: Value Meaning RM_CATALOG_TASK Task RM_CATALOG_DEVICE Device driver (Device) RM_CATALOG_POOL Memory pool RM_CATALOG_SEMAPHORE Semaphore RM_CATALOG_EVENTFLAG Global event flag RM_CATALOG_CNTRL Monitored program access RM_CATALOG_LOCALMAILBOX Local mailbox RM_CATALOG_MISC Reserved RM_CATALOG_USER User-defined type RM_CATALOG_UNIT Device (Unit) RM_CATALOG_MESSAGE Messages RM_CATALOG_ALL ide ulong Returns the extended resource ID. The range of values depends on the type and configured maximum values. id ushort Specifies the resource ID. The range of values depends on the type and configured maximum values. Note Resource type RM_CATALOG_USER is not reserved for specific RMOS3 resources and can be used to suit requirements. For example, you could display the availability of specific library modules by entering the library name and type RM_CATALOG_USER in the catalog. See also RmCatalog, RmList, RmGetEntry RMOS3 V3.50 Reference Manual Part II 46 Programming Manual, 07/2012, A5E03692298-01 Data structures 3.5 RmIntrhandMailStruct 3.5 Syntax RmIntrhandMailStruct #include typedef struct _RmIntrhandMailStruct { uint int_no ; uint int_vec :8 ; uint int_kind :1 ; uint lost_int_overflow :1 ; #if RM3 uint dummy_2 :22 ; #else uint dummy_2 :6 ; #endif ushort lost_int; #if RM3 ushort dummy_3; #endif }RmIntrhandMailStruct Description SVC RmSetIntMailboxHandler can be used to define interrupt handlers for sending mails to a mailbox. The RmIntrhandMailStruct structure defines the format of this mail that is saved to the mailbox after the corresponding interrupt was triggered. The structure consists of altogether three 23-bit words Field Type Meaning int_no uint Specifies the interrupt number. int_vec 8-bit Specifies the associated interrupt vector. int_kind 1-bit Identifies the interrupt type: Value Meaning 0 Hardware interrupt 1 Software interrupt lost_int_ overflow 1-bit This bit is set (= 1) if interrupts were lost. dummy_2 22 bit Reserved lost_int 8-bit Specifies the number of lost interrupts. dummy_3 24-bit Reserved See also RmSetIntMailboxHandler RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 47 Data structures 3.6 RmIOStatusStruct 3.6 Syntax RmIOStatusStruct #include typedef struct _RmIOStatusStruct { char primary; char secondary; ushort count; #if RM3 ushort status3; ushort status4; #endif }RmIOStatusStruct; Description The RmIOStatusStruct structure defines a structure to which return values are saved on completion of I/O requests (RmIO) Field Type Meaning primary char First status byte secondary char Second status byte count ushort Number of bytes transmitted status3 ushort Third status word status4 ushort Fourth status word See also RmIO RMOS3 V3.50 Reference Manual Part II 48 Programming Manual, 07/2012, A5E03692298-01 Data structures 3.7 RmIRBStruct 3.7 Syntax RmIRBStruct #include typedef struct _RmIRBStruct { struct _RmIRBStruct ushort pri; struct _RmTCBStruct struct _RmUCBStruct struct _RmTMBStruct uchar rio; uchar funct; uchar device; uchar unit; uchar grp; uint flags; void * status; #if RMFLAT ushort status_seg; #endif void * bufr; #if RMFLAT ushort bufr_seg; #endif ushort seq; }RmIRBStruct; Description _NEAR * tcb; _NEAR * ucb; _NEAR * tmb; The RmIRBStruct structure defines a structure for I/O requests (RmIO). Field Type Meaning link Pointer to RmIRBStruct Forward link or 0 ushort Priority Pointer to RmTCBStruct TCB address of the requesting task Pointer to RmTMBStruct TMB address of current request funct pri tcb ucb Pointer to RmUCBStruct UCB address of the requested device uchar Start of SDB image uchar Function code device uchar Driver ID unit uchar Device ID grp uchar Flag group (always zero) flags uint Flag mask status void* Address of status buffer status_seg ushort Fill word for FLAT model bufr void* Address of the device-specific parameter list bufr_seg ushort Fill word for FLAT model seq ushort Reserved tmb rio See also _NEAR * link; RmIO RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 49 Data structures 3.8 RmMailboxStruct 3.8 Syntax RmMailboxStruct #include typedef struct _RmMailboxStruct { void *adr; #if RMFLAT ushort adr_res; #endif #if RM3 ushort pqd; #endif uint len; }RmMailboxStruct; Description RmMailboxStruct is used for indirect transmission of a message via the mailbox by transferring the memory address and message length in the mailbox instead of the actual message. Field Type Meaning adr void* Contains a pointer to the memory address of the message. adr_res ushort Fill word for FLAT model pad ushort If adr is a FAR pointer it comprises 48 bits. pad is padded to 64 bits. len uint Specifies the message length. See also RmSendMail, RmReceiveMail RMOS3 V3.50 Reference Manual Part II 50 Programming Manual, 07/2012, A5E03692298-01 Data structures 3.9 RmMailIDStruct 3.9 Syntax RmMailIDStruct #include typedef struct _RmMailIDStruct { ulong low; ulong high; }RmMailIDStruct; Description Field Type Meaning low ulong Least significant segment of the mail ID high ulong Most significant segment of the mail ID See also RmSendMailCancel, RmSendMailDelayed RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 51 Data structures 3.10 RmMemPoolInfoStruct 3.10 Syntax RmMemPoolInfoStruct #include typedef struct _RmMemPoolInfoStruct { ulong pool_size; ulong avail_mem_size; ulong max_block_size; ulong reserved[5] }RmMemPoolInfoStruct; Description Return value of function RmGetMemPoolInfo. The return value contains information about the specified memory pool. Field Type Meaning pool_size ulong Total length of the memory avail_mem_size ulong Total length of available memory max_block_size ulong Length of the largest memory block (always -1) See also RmGetMemPoolInfo RMOS3 V3.50 Reference Manual Part II 52 Programming Manual, 07/2012, A5E03692298-01 Data structures 3.11 RmSpinLockStruct 3.11 Syntax RmSpinLockStruct #include struct _RmSpinLockStruct { uchar Spin; uchar CoreID; uchar Reserved; uchar Count; uint Interruptflags; } GNU_PACKED; typedef struct _RmSpinLockStruct RmSpinLockStruct; Description Return value of function RmInitSpinLock. Contains information about the initialized SpinLock. Field Type Meaning Spin uchar 1, if SpinLock is occupied, 0 if free CoreID uchar Core on which the SpinLock was requested Reserved uchar For internal use Count uchar Number of times the SpinLock was requested on the same core Interruptflags uint Flags for the interrupt state See also RmInitSpinLock, RmGetSpinLock, RmGetSpinLockIRQ, RmReleaseSpinLock, RmReleaseSpinLockIRQ RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 53 Data structures 3.12 RmSysB 3.12 Syntax RmSysB #include typedef struct _RmSysB { uchar version[6]; ushort proctype; ushort systemtype; ushort res1; ulong reserved; char statname[16]; uchar bootfname[128]; uchar bootnode[6]; uchar bootdrive; uchar res2; ulong ram_size; uint smr_max; uint smr_used; uint smr_avail; uint out_of_smr_count; #if RM3 ushort fl_er_sel; ushort fl_rw_sel; #endif ushort rate_msec; ulong rate_usec; ulong pit_count; ushort timer_int; rmproc issue_eoi_entry; uchar pic_count; uchar pic_base[8]; uchar pic_mask[8]; #if RM3 uchar res3[3]; #else uchar fres3[1]; #endif int (_FAR _FIXED * set_pic_mask) (uint irq); #if RM3 #if RMFLAT ushort res4f; #endif ushort res4; #endif int (_FAR _FIXED * init_pit) (void); #if RM3 #if RMFLAT ushort res5f; #endif ushort res5; #endif int (_FAR _FIXED * set_rtc_entry) (RmTimeStruct*); #if RM3 #if RMFLAT ushort res6f; #endif ushort res6; #endif int (_FAR _FIXED * get_rtc_entry) (RmTimeStruct*); #if RM3 #if RMFLAT ushort res7f; #endif ushort res7; RMOS3 V3.50 Reference Manual Part II 54 Programming Manual, 07/2012, A5E03692298-01 Data structures 3.12 RmSysB #endif int (_FAR _FIXED * putchar_entry) (char); #if RMFLAT ushort res8f; #endif } RmSysB; Description The RmSysB structure defines the System Control Blocks (SYSB). SYSB is created in the data segment of the nucleus. SYSB must be moved to a secure area prior to the booting of a new system, to enable access to it by the loaded system and to prevent its destruction, for example, during initialization of the system's data area. Field Type Meaning version[6] uchar RMOS version number proctype ushort Processor type The proctype can be logically linked by AND with different bit patterns to decode the processor information: systemtype ushort Bit pattern Single information 0x0F00 CPU type 0x00F0 CPU model (Pentium) 0x000F CPU stepping (Pentium) 0x8000 FPU available RMOS type Value Meaning 2 RMOS2 3 RMOS3 4 RMOS for WINDOWS res1 ushort Reserved reserved ulong Reserved statname[16] char Station name bootnode[6] uchar LAN address of the boot server bootfname[128] uchar File specification of the load system RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 55 Data structures 3.12 RmSysB See also Field Type Meaning bootdrive uchar RMOS3 boot drive Value Meaning 0 Floppy drive 0 1 Hard disk 0 2 Memory card 3 LAN 4 EPROM 5 Boot volume in bootfname res2 ushort Reserved ram_size ulong Size of RAM area in bytes smr_max uint Maximum number of SMRs smr_used uint Number of SMRs used smr_avail uint Available number of SMRs out_of_smr_count uint Specification of the number of times it was not possible to request new SMR areas fl_rw_sel ushort FLAT selector for code fl_rw_sel ushort FLAT selector for data rate_msec ushort RMOS3 system clock rate in milliseconds rate_usec ulong RMOS3 system clock rate in microseconds pit_count ulong Number of timer ticks between two timer interrupts timer_int ushort Interrupt number for timer issue_eoi_entry rmproc Address of the EOI function pic_count uchar Number of PICs pic_base[8] uchar Lowest vector address of PIC 1..8 (1=Master) pic_mask[8] uchar PIC masks for PIC 1..8 res3[3] uchar Reserved res3[1] uchar Reserved set_pic_mask (pointer to function) Function for manipulating the PIC mask res4f ushort Reserved res4 ushort Reserved init_pit (pointer to function) Function for timer initialization res5f ushort Reserved res5 ushort Reserved set_rtc_entry (pointer to function) Function for writing the real-time clock res6f ushort Reserved res6 ushort Reserved get_rtc_entry (pointer to function) Function for reading the real-time clock res7f ushort Reserved res7 ushort Reserved put_char_entry (pointer to function) res8f ushort Function putchar for nucleus outputs Reserved RmGetSysB RMOS3 V3.50 Reference Manual Part II 56 Programming Manual, 07/2012, A5E03692298-01 Data structures 3.13 RmTaskInfoStruct 3.13 Syntax RmTaskInfoStruct #include typedef struct _RmTaskInfoStruct { uchar pri; uchar state; uint*sp_ss; #if RM3 #if RMFLAT ushort sp_ss_res; #endif longlong rdy_time; #else uint rdy_time[3]; #endif char cpu_id; char flg; struct _RmTCDStruct *tcd_ptr; #if RMFLAT ushort tcd_ptr_res; #endif } RmTaskInfoStruct; Description Structure RmTaskInfoStruct defines the task data that SVC RmGetTaskInfo returns Field Type Meaning pri uchar Current task priority state uchar The two least significant bits define the task state Name Meaning RM_DORMANT Task in DORMANT state. RM_READY Task in READY state. RM_BLOCKED Task in BLOCKED state. The reason is decoded in the 6 most significant bits of state, so that state assumes one of the following values: RM_STA_EF Waiting for event flag RM_STA_SEMA Waiting for semaphore RM_STA_LOAD Wait until target task is loaded. RM_STA_STRT Waiting for start of the target task RM_STA_ENDT Waiting for end of the target task RM_STA_MSG Waiting for receipt of message RM_STA_MSGRCVD Waiting for receipt of transmitted message RM_STA_POOL Waiting for allocation of memory pool space RM_STA_HLT Stopped by DEBUGGER RM_STA_BREAK Interrupted by DEBUGGER breakpoint RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 57 Data structures 3.13 RmTaskInfoStruct Field Type Meaning RM_STA_PAUSE RM_STA_CNTRL Waiting for expiration of time interval (RmPauseTask) Waiting for completion of an I/O operation RM_STA_WAIT Wait for expiration of time interval RM_STA_ERR0 Runtime error, type 0 (Division by 0 Interrupt) RM_STA_ERR1 Runtime error, type 1 (Single Step Interrupt) RM_STA_ERR2 Runtime error, type 3 (Breakpoint Interrupt) RM_STA_ERR3 Runtime error, type 4 (Overflow Interrupt) RM_STA_ERR4 Runtime error, type 5 (Array Bound Interrupt) RM_STA_ERR5 Runtime error, type 6 (Unused Opcode) RM_STA_ERR6 Runtime error, type 7 (Escape Opcode) RM_STA_ERR7 Runtime error, type 8 (Double Fault) RM_STA_ERR8 Runtime error, type 9 (NDP Segment Overrun) RM_STA_ERR9 Runtime error, type 13 (General Protection) RM_STA_ERR10 Runtime error, type 16 (Floating Point Error) RM_STA_ERR11 Runtime error, type 10 (Invalid TSS) RM_STA_ERR12 Runtime error, type 11 (Segment Not Present) RM_STA_ERR13 Runtime error, type 12 (Stack Fault) RM_STA_ERR14 Runtime error, type 14 (Page Fault) RM_STA_ERR15 Runtime error, type 17 (Alignment Check) RM_STA_LOOK Wait for catalog entry RM_STA_KEND End of task with SVC RmKillTask (e.g. on completion of the current I/O operation) RM_STA_KDEL Delete task with SVC RmKillTask (e.g. on completion of the current I/O operation) RUNNING Task in RUNNING state. sp_ss uint Pointer to current stack pointer address sp_ss_res ushort Fill word for FLAT model rdy_time ulong Time of last change of the task to READY state cpu_id char Reserved, must be 0 flg char Task flags (Bits 7...0) Pointer to TCD address ushort Fill word for FLAT model tcd_ptr tcd_ptr_res RmTCDStruct RMOS3 V3.50 Reference Manual Part II 58 Programming Manual, 07/2012, A5E03692298-01 Data structures 3.14 RmTCDStruct 3.14 Syntax RmTCDStruct #include typedef struct _RmTCDStruct { uint eax; uint ebx; ushort ds; ushort es; char *stck; #if RMFLAT ushort stck_res; #endif rmfarproc task; #if RMFLAT ushort task_res; #endif #if RM3 char *load; #if RMFLAT ushort load_res; #endif /* RMFLAT */ #else uint efg[2]; #endif /* RM3 */ ushort time; uchar ovpri; uchar bpri; uchar inpri; uchar pid; ushort flags; ushort rr_ticks; #if RM3 uint efg[2]; #endif #if RM3 uchar reserve[4]; #else uchar reserve[2]; #endif }RmTCDStruct; Description Structure RmTCDStruct defines the TCD (Task Control Data) of an RMOS3 task. TCD contains the constants that the operating system needs to manage a task. TCDs for static tasks are configured using the RcInitUserTask functions and published to the system. TCDs for dynamic tasks are published to the system by means of SVC RmCreateTaskEx . An application may also receive a pointer to the TCD of a task by calling SVC RmGetTaskInfo. Meaning of the fields of the structure: RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 59 Data structures 3.14 RmTCDStruct Field Type Meaning eax uint Value transferred on the stack at task start. ebx uint Value transferred in the EBX register at task start. ds ushort Returns the length of the data segment in bytes. es ushort The ES register of the task is initialized with this value. stck char * Bit RM_TFL_STK=0 in the flags field means that stck is a pointer to the stack of the task. If RM_TFL_STK is set, stck returns the stack length in bytes. stck_res ushort Fill word for FLAT model task rmfarproc Pointer to the task start address. load char * load_res ushort Address of the load descriptor string for reloadable task, otherwise (char *) 0. efg uint Local event flag group. time ushort Time unit for timeout of the runtime-dependent priority control (see RM_TFL_OVPRI in the flags field). The time interval is calculated based on ?? * time. The following values are possible: Fill word for FLAT model Symbolic name *) Time unit RM_TCD_MSEC_1 00 1 ms RM_TCD_MSEC_10 04 10 ms RM_TCD_MSEC_100 08 100 ms RM_TCD_SEC 12 1s RM_TCD_SEC_10 24 10 s RM_TCD_MIN 16 1 min RM_TCD_MIN_10 28 10 min HOUR 20 1h *) value (decimal) to enter for ?? ovpri uchar The task priority is incremented by this value if runtimedependent priority control is activated (see RM_TFL_OVPRI in the flags field) and the timeout has expired. Must be initialized with 0 if RM_TFL_OVPRI is not set bpri uchar Limit up to which the runtime-dependent priority control (see RM_TFL_OVPRI in the flags field) increments the task priority. Must be initialized with 0 if RM_TFL_OVPRI is not set inpri uchar Specifies the priority of task start. pid uchar Reserved, must be 0 RMOS3 V3.50 Reference Manual Part II 60 Programming Manual, 07/2012, A5E03692298-01 Data structures 3.14 RmTCDStruct Field Type Meaning flags ushort Specifies further task properties. These properties can be combined with the help of the bit-oriented OR operator |. flags can be a combination of the following values (all other values re reserved; the corresponding bits must be 0): Symbol. Name Meaning RM_TFL_NPX Must be set if the task uses the numerical co-processor. RM_TFL_ NOHLT The task cannot be stopped by other tasks. RM_TFL_ OVPRI Activates runtime-dependent priority control. If this bit is set and the task is still in READY or RUNNING state on expiration of the timeout interval specified in ?? * time, the priority is incremented by the count of ovpri , provided the bpri limit was not yet reached. The timeout is retriggered at the task start, on expiration of the timeout after an increase of the priority level, and by the call of SVC RmSetTaskPriority. RM_TFL_STK RM_TFL_DS Specifies that RMOS3 automatically allocates system HEAP memory space to the task stack. Specifies that RMOS3 automatically allocates system HEAP memory space to the data segment of the task. rr_ticks ushort Task-specific Round-Robin counter, if the ROUND_ROBIN is defined as RM_RR_TASK in the RMCONF.C file or RmSetOS was called with RM_RR_TASK as second parameter. reserve[4] uchar 4 reserved bytes. See also RmCreateTask, RmGetTaskInfo RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 61 Data structures 3.15 RmTimeStruct 3.15 Syntax RmTimeStruct #include typedef struct _RmTimeStruct { uchar day; uchar month; ushort year; uchar hours; uchar minutes; uchar seconds }RmTimeStruct; Description Contains the system time and date (global system time) and is used by the RmGetHWTime and RmSetHWTime SVCs. Field Type Meaning day uchar Tag month uchar Month year ushort Year hours uchar Hours minutes uchar Minutes seconds uchar Seconds See also RmGetHWTime, RmSetHWTime RMOS3 V3.50 Reference Manual Part II 62 Programming Manual, 07/2012, A5E03692298-01 Data structures 3.16 RmTMBStruct 3.16 Syntax RmTMBStruct #include typedef struct _RmTMBStruct { /* *** Common part *** */ struct _RmTMBStruct _NEAR * link; uint ltime; uint htime; uchar type; union { /* *** Type 1 *** */ struct { uchar res; struct _RmUCBStruct _NEAR * ucb; void * sadr #if RMFLAT void * sadr_seg #endif } type_1; /* *** Type 2 *** */ struct { uchar res; struct _RmTCBStruct _NEAR * tcb; } type_2; /* *** Type 3 *** */ struct { uchar efgrp; struct _RmTCBStruct _NEAR * tcb; uint efmask; } type_3; /* *** Type 4 *** */ struct { uchar res; struct _RmTCBStruct _NEAR * tcb; } type_4; /* *** Type 5 *** */ struct { uchar res; struct _RmTCBStruct _NEAR * tcb; uchar ovpri uchar bpri uchar ovtime } type_5; /* *** Type 6 *** */ struct { uchar res; struct _RmTCBStruct _NEAR * tcb; uint swb; uint sem; } type_6; RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 63 Data structures 3.16 RmTMBStruct /* *** Type 7 *** */ struct { uchar res; struct _RmIRBStruct _NEAR * irb; } type_7; /* *** Type 8 *** */ struct { uchar res; uint tjt; ushort svc; uint qh; uint wb; } type_8; /* *** Type 9 *** */ struct { uchar res[3]; uint alarm; ushort tib; } type_9; } utmb; }RmTMBStruct Description Structure RmTMBStruct defines a structure for timer monitoring blocks Field Type Meaning Pointer to Forward link or 0 uint Least significant DWORD of the absolute time htime uint Most significant DWORD of the absolute time type uchar TMB type: link ltime RmTMBStruct Value Meaning 1 Driver or tod timeout 2 Task pause timeout 3 Event flag 4 Task restart timer 5 Override priority timer 6 Reserved 7 Reserved 8 SVC timeout 9 Message delay TMB type 1 Field Type Meaning res uchar Reserved ucb Pointer to UCB address sadr void* Address of the timeout routine ushort Fill word for FLAT model sadr_seg RmUCBStruct RMOS3 V3.50 Reference Manual Part II 64 Programming Manual, 07/2012, A5E03692298-01 Data structures 3.16 RmTMBStruct TMB type 2 Field Type Meaning res uchar Reserved tcb Pointer to TCB address Field Type Meaning res uchar Reserved efgrp uchar Event flag group tcb Pointer to TCB address efmsk uint Flag mask Field Type Meaning res uchar Reserved tcb Pointer to TCB address Field Type Meaning res uchar Reserved tcb Pointer to TCB address ovpri RmTCBStruct TMB type 3 RmTCBStruct TMB type 4 RmTCBStruct TMB type 5 RmTCBStruct uchar Priority increment bpri uchar Priority limit ovtime uchar Priority time interval in ms Field Type Meaning res uchar Reserved tcb Pointer to TCB address swb uint Address of the semaphore wait block uint Semaphore address TMB type 6 sem RmTCBStruct RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 65 Data structures 3.16 RmTMBStruct TMB type 7 Field Type Meaning res uchar Reserved irb Pointer to IRB address Field Type Meaning res uchar Reserved tjt uint Timeout jump table svc ushort Bit-coded SVC qh uint Specific queue header wb uint Specific wait block Field Type Meaning res uchar Reserved alarm uint Alarm routine called on expiration tib uint Associated TIB RmIRBStruct TMB type 8 TMB type 9 See also RmTCDStruct (Page 59) RMOS3 V3.50 Reference Manual Part II 66 Programming Manual, 07/2012, A5E03692298-01 Data structures 3.17 RmUCDHeadStruct 3.17 Syntax RmUCDHeadStruct #include typedef struct _RmUCDHeadStruct { uchar pid; uchar intno; rmfarproc intadr; ushort uns; }RmUCDHeadStruct; Description Structure RmUCDHeadStruct defines the general structure of unit control data. Field Type Meaning pid uchar Reserved intno uchar Interrupt number intadr rmfarproc Interrupt vector address uns ushort Task ID for unexpected interrupt See also RmIO, RmUCDStruct (Page 68) RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 67 Data structures 3.18 RmUCDStruct 3.18 Syntax RmUCDStruct #include typedef struct _RmUCDStruct { uchar pid; uchar intno; rmfarproc intadr; ushort uns; #if RM3 uchar port[256-10]; #else uchar port[128-8]; #endif }RmUCDStruct; Description Structure RmUCDStruct defines the general and a specific structure of unit control data. Field Type Meaning pid uchar Reserved intno uchar Interrupt number intadr rmfarproc Interrupt vector address uns ushort Task ID for unexpected interrupt port [256-10] uchar Device-dependent parameter See also RmIO, RmDCDStruct (Page 45) , RmUCDHeadStruct (Page 67) RMOS3 V3.50 Reference Manual Part II 68 Programming Manual, 07/2012, A5E03692298-01 Data structures 3.19 loader_result 3.19 Syntax loader_result #include struct loader_result { ushort except_code; ushort shareable; char reserved_byte; ushort reserved_word2; uint code_seg_offset; ushort code_seg_base; uint stack_offset; ushort stack_seg_base; uint stack_size; ushort data_seg_base; char num_more_slots; ushort more_slots [1]; ushort reserved_word3; void _FAR *reserved_pointer1; }; typedef struct struct loader_result LOADER_RESULT; Description Structure loader_result defines the configuration of the loader result segment that the task loader generates while programs are loaded. The loader result segment contains the following information about a task loaded with stl_load function Field Type Meaning except_code ushort Return status of the load operation; contains the same value as the return status of function stl_load. Since the loader result segment is only created for successful load operations, only the 0 value and values in the range from 8100H to 810FH will be set for this segment. reserved_ word1 ushort Reserved. reserved_ byte byte Reserved. reserved_ word2 ushort Reserved. code_seg_ offset uint Instruction pointer (EIP register); init value of the loaded task. code_seg_ base ushort Code segment (CS register); init value of the loaded task. stack_ offset uint Stack pointer (SP register); init value of the loaded task. stack_seg_ base ushort Stack segment (SS register); init value of the loaded task. stack_size uint Stack size of the loaded task in bytes. RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 69 Data structures 3.19 loader_result Field Type Meaning data_seg_ base ushort Data segment (DS register); init value of the loaded task. This value equals 0 if the task does not need an initialization data segment, i.e. the module contains no static global nor local data. num_more_ slots char Number of segments assigned to the loaded task, including initialization data/stack/code segments. This value always equals 255, even if the task was assigned more than 255 segments. more_slots [1] ushort reserved_ word3 ushort Field that contains all segment selectors of the loaded task. The length of the field is stored in num_more_slots. Reserved. reserved_ pointer1 void* Reserved. See also stl_load RMOS3 V3.50 Reference Manual Part II 70 Programming Manual, 07/2012, A5E03692298-01 Data structures 3.20 stdstruct 3.20 Syntax stdstruct #include struct std_struct { int stdin_dev; int stdin_unit; int stdout_dev; int stdout_unit; int stderr_dev; int stderr_unit; char *stdin_fname; #if RMFLAT unsigned short stdin_fill; #endif char *stdout_fname; #if RMFLAT unsigned short stdout_fill; #endif char *stderr_fname; #if RMFLAT unsigned short stderr_fill; #endif char *tmp_path; #if RMFLAT unsigned short tmp_fill; #endif }; typedef struct std_struct STDSTRUCT; Description Structure STDSTRUCT defines the stdin, stdout I/O channels and error output channel stderr of a program. A channel can be defined based on the device/unit number combination, or on the file name Field Type Meaning stdxx_dev int A value >= 0 determines the number of an I/O driver (device number). Meaning of values < 0: Value Meaning -1 The file name specified in stdxx_fname is used. A new file is generated in the case of stdout and stderr. stdxx_unit is not used. -2 -3 The file name specified in stdxx_fname is used. In the case of stdout and stderr the output data is appended to the end of the file, provided the file already exists. stdxx_unit is not used. You should handle this value similar to stdxx_dev = -2, because the value only has the following meaning for the interactive CLI command START: The output file is inherited from the calling job and cannot be inherited by other jobs. stdxx_unit int If the value in stdxx_dev >= 0 , stdxx_unit determines the number of an I/O device (unit number). If the value in stdxx_dev < 0, stdxx_unit is insignificant. RMOS3 V3.50 Reference Manual Part II Programming Manual, 07/2012, A5E03692298-01 71 Data structures 3.20 stdstruct Field Type Meaning stdxx_fname char * Points to a file name string. The file of the specified name is used if the value in stdxx_dev < 0 as described above. stdxx_fill unsigned short reserved; fill word for FLAT model tmp_path char * Points to a file name string that defines a file for temporary data. tmp_fill unsigned short reserved; fill word for FLAT model Note The values -2 and -3 in stdxx_dev described above are only relevant to the RMOS3 CLI. Function x_cr_gettaskparams always returns values stdxx_dev >= -1. The file name specified in the temp_path field and the name set in function xinitt() for the temporary file are identical RMOS3 V3.50 Reference Manual Part II 72 Programming Manual, 07/2012, A5E03692298-01 Error codes and messages 4.1 4 Nucleus The nucleus outputs its error messages to the console that is defined in the configuration as SYSCON. Lack of system resources The following error messages may be output if the system is lacking resources: *** nuc: