Handel-C Language Reference Manual
Total Page:16
File Type:pdf, Size:1020Kb
DK4 Handel-C Language Reference Manual For DK version 4 Handel-C Language Reference Manual Celoxica, the Celoxica logo and Handel-C are trademarks of Celoxica Limited. All other products or services mentioned herein may be trademarks of their respective owners. Neither the whole nor any part of the information contained in, or the product described in, this document may be adapted or reproduced in any material form except with the prior written permission of the copyright holder. The product described in this document is subject to continuous development and improvement. All particulars of the product and its use contained in this document are given by Celoxica Limited in good faith. However, all warranties implied or express, including but not limited to implied warranties of merchantability, or fitness for purpose, are excluded. This document is intended only to assist the reader in the use of the product. Celoxica Limited shall not be liable for any loss or damage arising from the use of any information in this document, or any incorrect use of the product. The information contained herein is subject to change without notice and is for general guidance only. Copyright © 2005 Celoxica Limited. All rights reserved. Authors: RG Document number: RM-1003-4.2 Customer Support at http://www.celoxica.com/support/ Celoxica in Europe Celoxica in Japan Celoxica in the Americas T: +44 (0) 1235 863 656 T: +81 (0) 45 331 0218 T: +1 800 570 7004 E: [email protected] E: [email protected] E: [email protected] www.celoxica.com Handel-C Language Reference Manual Contents 1 INTRODUCTION ............................................................................. 11 1.1 REFERENCES............................................................................ 11 2 GETTING STARTED WITH HANDEL-C ................................................... 12 2.1 BASIC CONCEPTS ...................................................................... 12 2.1.1 Handel-C programs ............................................................................... 12 2.1.2 Parallel programs.................................................................................. 12 2.1.3 Channel communication ......................................................................... 13 2.1.4 Scope and variable sharing..................................................................... 15 3 LANGUAGE BASICS ......................................................................... 16 3.1 PROGRAM STRUCTURE................................................................ 16 3.2 COMMENTS ............................................................................. 17 3.3 STATEMENT SUMMARY ............................................................... 17 3.4 OPERATOR SUMMARY................................................................. 19 3.5 TYPE SUMMARY ........................................................................ 21 3.6 COMPARISON OF HANDEL-C AND ANSI-C ..................................... 22 3.6.1 Handel-C v C: types and type operators ................................................... 23 3.6.2 Handel-C v C: floating-point variables ...................................................... 23 3.6.3 Handel-C v C: variable widths and casting ................................................ 24 3.6.4 Handel-C v C: side effects ...................................................................... 25 3.6.5 Handel-C v C: functions ......................................................................... 26 3.6.6 Handel-C v C: loop statements ............................................................... 27 3.6.7 Handel-C v C: unions............................................................................. 28 3.6.8 Handel-C v C: data input and output........................................................ 29 3.6.9 Handel-C v C: memory allocation ............................................................ 29 3.6.10 Handel-C v C: standard library .............................................................. 29 3.6.11 C and Handel-C types and objects ......................................................... 29 3.6.12 Expressions in C and Handel-C .............................................................. 30 3.6.13 Statements in C and Handel-C .............................................................. 32 3.7 HANDEL-C CONSTRUCTS NOT FOUND IN ANSI-C ............................. 32 4 DECLARATIONS ............................................................................. 36 4.1 INTRODUCTION TO TYPES ........................................................... 36 4.1.1 Handel-C values and widths.................................................................... 36 4.1.2 String constants ................................................................................... 37 4.1.3 Constants ............................................................................................ 37 4.2 LOGIC TYPES ........................................................................... 38 4.2.1 int ...................................................................................................... 38 4.2.2 Signed | unsigned syntax....................................................................... 39 4.2.3 Supported types for porting.................................................................... 39 4.2.4 Inferring widths .................................................................................... 40 www.celoxica.com Page 1 Handel-C Language Reference Manual 4.2.5 Arrays ................................................................................................. 41 4.2.6 Array indices ........................................................................................ 43 4.2.7 struct .................................................................................................. 43 4.2.8 enum .................................................................................................. 44 4.2.9 Bit fields .............................................................................................. 45 4.3 POINTERS............................................................................... 46 4.3.1 Pointers and addresses .......................................................................... 48 4.3.2 Pointers to functions.............................................................................. 48 4.3.3 Pointers to interfaces............................................................................. 49 4.3.4 Structure pointers ................................................................................. 49 4.3.5 address and indirection operators............................................................ 50 4.4 ARCHITECTURAL TYPES .............................................................. 51 4.5 CHANNELS .............................................................................. 51 4.5.1 FIFO code example ............................................................................... 53 4.5.2 Arrays of channels ................................................................................ 53 4.5.3 Restrictions on channel accesses ............................................................. 53 4.5.4 Timing and latency in FIFOs ................................................................... 55 4.6 INTERFACES: OVERVIEW ............................................................ 56 4.6.1 Interface declaration ............................................................................. 56 4.6.2 Interface definition................................................................................ 57 4.6.3 Example interface to external code .......................................................... 58 4.6.4 Interface specifications .......................................................................... 59 4.7 RAMS AND ROMS.................................................................... 61 4.7.1 Initialization ......................................................................................... 61 4.7.2 Inferring size from use........................................................................... 62 4.7.3 Accessing RAMs and ROMs ..................................................................... 62 4.7.4 Differences between RAMs and arrays...................................................... 62 4.7.5 RAM and ROM support on different devices ............................................... 63 4.7.6 Multidimensional memory arrays ............................................................. 63 4.8 MPRAM (MULTI-PORTED RAMS) .................................................. 64 4.8.1 Initialization of mprams ......................................................................... 66 4.8.2 Mapping of different width mpram ports ................................................... 66 4.8.3 mprams example .................................................................................. 68 4.9 WOM (WRITE-ONLY MEMORY) .................................................... 69 4.10 SEMA ................................................................................... 69 4.11 SIGNAL ................................................................................ 70 4.12 STORAGE CLASS SPECIFIERS...................................................... 71 4.12.1 auto .................................................................................................. 71 4.12.2 extern (external variables) ................................................................... 72 4.13 EXTERN LANGUAGE CONSTRUCT