473,409 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

Can anyone explain me the meaning of the following code block

Can anyone please help me in understanding the following code:
UD1RX is referred to in the application code (foreg: RX = UD1RX) and i have found the following defines for the same, but
couldnt quite understand why they mean.

I understand it is being casted as a pointer to a pointer. But it is confusing. I appreciate if any one could explain it.

Expand|Select|Wrap|Line Numbers
  1. #define    UD1RX            CAST_UC(0xfffffa16UL)
  2.  
  3. #ifdef __LANGUAGE_ASM__
  4.    #define CAST_UC(x) x
  5. #else
  6.    typedef volatile unsigned char*   pU08necDevFile;
  7.  
  8.    #define CAST_UC(x) ( *(pU08necDevFile)(x) ) 
  9.  
Nov 14 '12 #1
7 1867
weaknessforcats
9,208 Expert Mod 8TB
I can't see what CAST_UC does but if the flag __LANGUAGE_ASM__ is defined, then CAST_UC will do something with the value in parentheses. If __LANGUAGE_ASM__ is not defined, then your x will be type cast to a volatile unsigned char* and then de-referenced to a volatile char and then pass to CAST_UC.

You would think you could just cast the x to a volatile char and omit the typedef but that typedef may be used elsewhere in the programif __LANGUAGE_ASM__ if is not defined.
Nov 14 '12 #2
donbock
2,426 Expert 2GB
Your example
Expand|Select|Wrap|Line Numbers
  1. ...
  2. RX = UD1RX;
expands to the following if __LANGUAGE_ASM__ is defined:
Expand|Select|Wrap|Line Numbers
  1. ...
  2. RX = 0xfffffa16UL;
otherwise it expands to this (the typedef is not part of the expansion, I wrote it below to provide context):
Expand|Select|Wrap|Line Numbers
  1. typedef volatile unsigned char*   pU08necDevFile;
  2. ...
  3. RX = ( *(pU08necDevFile)(0xfffffa16UL) );
.
I suspect RX is itself a macro whose expansion depends on __LANGUAGE_ASM__.
Nov 14 '12 #3
hi weaknessforcats and donbock,

Thanks for your responses.
I have understood to some extent. But i still couldnot understand the following: (I am quoting a few lines out of weaknessforcats's response)
"If __LANGUAGE_ASM__ is not defined, then your x will be type cast to a volatile unsigned char* and then de-referenced to a volatile char and then pass to CAST_UC. "

i.e in my example if x=0xfffffa16UL, at first it is being typecast to volatile unsigned char* and then derefenced, in the sense that the value at this adress (oxfffffa16UL) is stored in RX. Have i understood it correctly?
Nov 14 '12 #4
donbock
2,426 Expert 2GB
@srikanthpadava: Refer to line 3 of the third code block in my earlier reply post for the case when __LANGUAGE_ASM__ is undefined.
Expand|Select|Wrap|Line Numbers
  1. RX = ( *(pU08necDevFile)(0xfffffa16UL) );
First, 0xfffffa16UL is cast to a pU08necDevFile (volatile unsigned char*). Then, the asterisk deferences the pointer. That is, the value of the unsigned char at location 0xfffffa16UL is stored in RX.

Is RX a macro?
Nov 14 '12 #5
hi donbock,

thanks for the explanation.

No RX is not a macro.
RX is defined as static T_UINT8 RXTemp without any ifdef
and takes directly the value of UD1RX which is i believe is a register
Nov 14 '12 #6
Banfa
9,065 Expert Mod 8TB
My guess would be that UD1RX is a register and that it may be stands for something like

UART Device [b]1[b] Receive

RX is a common abbreviation of receive(r) as TX is for transmit(er).

If __LANGUAGE_ASM__ is not defined my guess is that this is reading the receive buffer of a UART device. For some reason if __LANGUAGE_ASM__ is defined it does not; a reason for this is that the software can build built on difference platforms, may be a target platform and a simulator or test platform. On the simulator platform there is no UART device so the coder wanted to ensure the program didn't read a random in invalid memory address and since he needs to return something he just returns the value of the address.

Why they have used __LANGUAGE_ASM__ as the symbol to control this I do not know, I would use something that was more meaningful but it is possible that they just looked for a symbol that is defined by the compiler of the simulator build and is not defined by the compiler of the target build. Personally I would say that wasn't very good practice.


BTW if you don't know a UART or USART device controls communication using a serial line such as an RS232 port. Modern USARTs normally support multiple different serial protocols RS232, I2C, SPI etc
Nov 15 '12 #7
thanks for the response banfa.

Yes UD1RX is the register of the device (UART) controlling the serial communication you were mentioning.
Nov 16 '12 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
4
by: Chris | last post by:
Hello Could anyone explain why the following: #footer ul { float : left; margin : 2px 0px 7px 28px; padding : 0px; width : 360px;
13
by: C++fan | last post by:
The following code is for list operation. But I can not understand. Could anyone explain the code for me? /* * List definitions. */ #define LIST_HEAD(name, type) struct name { type...
5
by: xperiencednoob | last post by:
I want a left-column menu bar and a right-column data area. The menu items (6 or so) are fixed-height and the space below them needs to expand. I've run into a strange situation only with IE6....
1
by: Andrew | last post by:
Hello, friends, I am implementing web app security using asp.net 1.1, and I found the following source code from Yahoo! Mail login page: <form method="post"...
3
by: Edward K. Ream | last post by:
Here is a little regular expression puzzle. I wish a regex that matches an rst code block, that is, '::' followed by a group of lines all indented by at least as much as the first non-blank...
16
by: KIRAN | last post by:
Hi all, #include<stdio.h> int main(void) { int a = 1;
1
Eclipse
by: Eclipse | last post by:
G'day all Can anyone explain the difference in the results to me as I don't understand why specifying the directory name in two different ways could give a different answer. In CODE 1 below i...
0
by: Tom | last post by:
The included code block demonstrates programmatically clicking a non-derived ToolStripButton in the OnShown() method. When I derive a button from ToolStripButton and override the _private_...
3
by: leon.san.email | last post by:
This a modified part of a larger script I made. I couldn't get it working so I made a smaller part of it - hoping to get it working. Well it still doesn't work :( The following code creates the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.