Keil Logo

C166: SERIAL EXAMPLE IN GETTING STARTED BOOK FAILS


Information in this article applies to:

  • C166 Version 4.03

QUESTION

I'm trying to use the serial example in the Getting Started and Creating Applications with µVision and the 166/ST10 manual.

The following code:

char putchar (char c)  {                          /*  substitute func for putchar */
  while ((( unsigned char)(tx_in + 1))==tx_out);  /*  buffer full? */
  _atomic_ (0);
  tx_buf [tx_in++] = c;                           /*  put char in buffer */
  _endatomic_ ();
  if (_testbit_ (tx_restart))  {                  /*  if transmits must be restarted */
    S0TIR = 1;                                    /*  enable transmit request */
  }
  return (c);
}

generates the following warnings and errors.

*** WARNING 140 IN LINE 35 OF .\SERIAL.C: '_testbit_' undefined; assuming 'extern int _testbit_()'
*** ERROR 185 IN LINE 32 OF .\serial.c: atomic #5: out of range

How can I fix this?

ANSWER

Warning 140 indicates that the specified function is undefined. In this case, the _testbit_ function. This was a misprint which should have been _testset_.

Error 185 indicates that the code in the atomic section is more than 4 instructions.

Change the program code for this example function to read as follows:

#pragma disable
static void putchar2 (char c)  {
  tx_buf [tx_in++] = c;                           /*  put the character in the buffer */
  if (_testclear_ (tx_restart))  {                /*  if transmits must be restarted.. */
    S0TIR = 1;                                    /*  enable transmit request */
  }
}

char putchar (char c)  {
  while ((( unsigned char)(tx_in + 1))==tx_out);  /*  buffer full? */
  putchar2 (c);
  return (c);
}

This solves the warning and error that you received.

MORE INFORMATION

SEE ALSO

Last Reviewed: Tuesday, October 24, 2006


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.