LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-02-2004, 01:05 PM   #1
eskimo22
LQ Newbie
 
Registered: Feb 2004
Posts: 11

Rep: Reputation: 0
gcc link question


i wrote a library for Amtel8515 and Amtel162 dealing
with serial communication. it has similar functions
like putchar and getchar, each depending on one interrupt
service routine.
for example putchar depends on SIG_UART_DATA. if i put
SIG_UART_DATA into a different object file than putchar
, there is no way for the linker to know that it must link
SIG_UART_DATA, if some other module uses putchar.
so my solution was to put them together into one file.

now there's a serious problem : how can the module that
initializes the serial communication know that it needs
to enable the ISR, if and only if SIG_UART_DATA was linked
into the project ?
 
Old 03-02-2004, 02:42 PM   #2
chewysplace
Member
 
Registered: Sep 2003
Distribution: Slackware 10 w/ Kernel 2.6.8
Posts: 176

Rep: Reputation: 30
#if SIG_UART_DATA
#define .....
#endif

is that what your looking for? maybe show some code.
 
Old 03-03-2004, 03:09 AM   #3
eskimo22
LQ Newbie
 
Registered: Feb 2004
Posts: 11

Original Poster
Rep: Reputation: 0
file SIG_UART_RECV :

SIGNAL(SIG_UART_RECV)
/* signal handler for receive complete interrupt */
{

*uart_rxd_in_ptr0 = inp(UDR); // read byte from receive register
uart_rxd_buf_cnt0++;
if (++uart_rxd_in_ptr0 >= uart_rxd_buffer0 + UART_BUF0_SIZE_IN) // Pointer wrapping
uart_rxd_in_ptr0 = uart_rxd_buffer0;
}


file uart_getchar (depends on SIG_UART_RECV):

s16 uart_getchar(void)
{
u08 c;

if (uart_rxd_buf_cnt0>0) {
cli();
uart_rxd_buf_cnt0--;
c = *uart_rxd_out_ptr0; /* get character from buffer */
if (++uart_rxd_out_ptr0 >= uart_rxd_buffer0 + UART_BUF0_SIZE_IN) /* pointer wrapping */
uart_rxd_out_ptr0 = uart_rxd_buffer0;
sei();
return c;
}
else
return -1; /* buffer is empty */
}


file uart_init:

void uart_init(void)
{
uart_txd_in_ptr0 = uart_txd_out_ptr0 = uart_txd_buffer0;
uart_rxd_in_ptr0 = uart_rxd_out_ptr0 = uart_rxd_buffer0;
uart_txd_buf_cnt0 = 0;
uart_rxd_buf_cnt0 = 0;


// enable RxD/TxD, receive complete int
outp((1<<RXCIE)|(1<<RXEN)|(1<<TXEN),UCSRB); // <-- INTERRUPT enabled
// set baud rate
outp(25, UBRRL);
//outp((u08)UART_BAUD_SELECT, UBRRL);
}



this line :

outp((1<<RXCIE)|(1<<RXEN)|(1<<TXEN),UCSRB); // <-- INTERRUPT enabled receive, transfer enabled

enables the receive interrupt. if i don't have SIG_UART_RECV linked
the mashine will crash. so if i never use uart_getchar this line should
read:

outp((1<<TXEN),UCSRB); // <-- INTERRUPT disabled, receive disabled

with conditional compiling this won't be hard to do. but i don't want
the library recompile for each project, that is not the purpose of a library.
most of my projects do not use uart_getchar, but some do.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"gcc linker" does not link C++ programs ( gxx_personality undefined ?) bahramH Programming 9 12-25-2009 01:38 PM
problem when trying to static link with gcc glvgfz Programming 11 09-18-2005 07:58 PM
Link Image Question... cmfarley19 General 0 05-13-2005 01:35 PM
How to link a library to gcc? Andrea_81 Programming 6 05-05-2005 04:22 AM
Link errors from gcc CraigN Programming 2 02-27-2003 07:43 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration