Verstehe gcc Code für AVR nicht

OP #4853691
Lesenswert?
• ▲
▼
Hi,

ich habe mir eine Software Uart Lib für AVRs im Inet runtergeladen. 
Verstehe aber nicht wie ich dies Sendefunktion genau aufrufen muss.

Was machst dieses FILE* stream? Und was muss ich als Argument dafür 
übergeben?

Hoffe ihr könnt mir weiterhelfen.

int
putChar(
  char  c,
  FILE* stream
)
{

  if ( c == '\n' ) putChar( '\r', stream );

                                    // Don't send while busy receiving 
or
                                    // transmitting.
  while (
    ( state != IDLE )
#ifndef TX_ONLY
    &&
    ( state != DATA_PENDING )
#endif
  );

#ifndef TX_ONLY
  DISABLE_EXTERNAL0_INTERRUPT( );   // Disable reception.
#endif // ifndef TX_ONLY
  state = TRANSMIT;
  SwUartTXData = c;                 // Put byte into TX buffer.
  SwUartTXBitCount = 0;

  TCCR_P &= ~CLOCK_SELECT_MASK;     // Reset prescaler counter.
  TCNT0 = 0;                        // Clear counter register.
  TCCR_P |= CLOCK_SELECT;           // CTC mode. Start prescaler clock.

  OCR = TICKS2WAITONE - 1;          // Set compare value to one bit 
period

  CLEAR_TIMER_INTERRUPT( );         // Clear interrupt bits

  CLEAR_TX_PIN( );                  // Clear TX line...start of preamble

  ENABLE_TIMER_INTERRUPT( );        // Enable interrupt

  return 0;

} // end putChar

#endif // ifndef RX_ONLY
(Firma: OBUP) #4853706
Lesenswert?
• ▲
▼
Hi

hier etwas zum Nachlesen: 
https://www.mikrocontroller.net/articles/Kategorie:UART_und_RS232

Das sind Grundlagen bzgl. AVR & U(S)ART.

s.a. https://www.mikrocontroller.net/articles/AVR-GCC-Tutorial/Der_UART

Dein Code wäre besser lesbar:
1
int
2
putChar(
3
  char  c,
4
  FILE* stream
5
)
6
{
7

8
  if ( c == '\n' ) putChar( '\r', stream );
9

10
                                    // Don't send while busy receiving 
11
or
12
                                    // transmitting.
13
  while (
14
    ( state != IDLE )
15
#ifndef TX_ONLY
16
    &&
17
    ( state != DATA_PENDING )
18
#endif
19
  );
20

21
#ifndef TX_ONLY
22
  DISABLE_EXTERNAL0_INTERRUPT( );   // Disable reception.
23
#endif // ifndef TX_ONLY
24
  state = TRANSMIT;
25
  SwUartTXData = c;                 // Put byte into TX buffer.
26
  SwUartTXBitCount = 0;
27

28
  TCCR_P &= ~CLOCK_SELECT_MASK;     // Reset prescaler counter.
29
  TCNT0 = 0;                        // Clear counter register.
30
  TCCR_P |= CLOCK_SELECT;           // CTC mode. Start prescaler clock.
31

32
  OCR = TICKS2WAITONE - 1;          // Set compare value to one bit 
33
period
34

35
  CLEAR_TIMER_INTERRUPT( );         // Clear interrupt bits
36

37
  CLEAR_TX_PIN( );                  // Clear TX line...start of preamble
38

39
  ENABLE_TIMER_INTERRUPT( );        // Enable interrupt
40

41
  return 0;
42

43
} // end putChar
44

45
#endif // ifndef RX_ONLY

FILE* stream << FileDescriptor als Output-Stream
s: http://www.cprogramming.com/tutorial/cfileio.html

mfg

Olaf

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren