home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / dsp / 3069 < prev    next >
Encoding:
Text File  |  1993-01-23  |  2.2 KB  |  59 lines

  1. Xref: sparky comp.dsp:3069 comp.lang.c:20104
  2. Newsgroups: comp.dsp,comp.lang.c
  3. Path: sparky!uunet!sarge!scotty
  4. From: scotty@verdix.com (Scott R. Chilcote)
  5. Subject: Is this a Legal Way to Access a Specific Address?
  6. Message-ID: <1993Jan23.042626.991@verdix.com>
  7. Summary: Assigning Pointer = Constant
  8. Keywords: DSP, C, ANSI, Fixed RAM
  9. Sender: news@verdix.com
  10. Nntp-Posting-Host: sarge.hq.verdix.com
  11. Organization: Lack Thereof
  12. Date: Sat, 23 Jan 1993 04:26:26 GMT
  13. Lines: 44
  14.  
  15. Hi Folks!
  16.  
  17. We're programming a device that has a RAM cache at address 809800H.
  18.  
  19. Is it legal to address this memory in C as follows?
  20.  
  21. #define ON_CHIP 0x809800
  22.  
  23. int main(void)
  24. {
  25.  
  26.    float *oc_ptr = (float *) ON_CHIP;
  27.  
  28.  
  29. Our device-specific ANSI C compiler lets us do this in order to address the
  30. on-chip memory, without a warning.  The emulator shows that it works.  I've
  31. looked in several textbooks, however, and I've never seen mention of setting
  32. a pointer equal to a constant in order to define a specific address.  Even the
  33. new K & R book doesn't mention if this is legal.
  34.  
  35. Does anyone know if this is acceptable coding, and what kinds of problems could
  36. crop up from using this method?
  37.  
  38. The other way we can achieve the same result is using the linker for this 
  39. device to declare a section of memory at a specific address, and associate
  40. a label with the section.  We can then use that label with an external pointer
  41. declaration in the C program ( extern void *on_chip; ) to reference the 
  42. specific address we need.  This method requires more CPU cycles than the one
  43. above to resolve pointers, but at least the address space we're using is 
  44. declared in the linker's memory map.
  45.  
  46. Note that this device has no operating system to speak of, so we're free to 
  47. access all address space with impunity.
  48.  
  49. Thanks for any help!
  50.  
  51.  
  52. -------------------------------------------------------------
  53. Disclaimer: I do not represent Verdix Corporation, and my
  54. postings do not represent their opinions.  
  55. -------------------------------------------------------------
  56.                                             Scott R. Chilcote
  57.                                             scotty@verdix.com  - or -
  58.                                             scotty%verdix.com@uunet.uu.net
  59.