/**************************************************************************//** * @brief * Read from a file. * * @param[in] file * Descriptor for the file you want to read from. * * @param[in] ptr * Pointer to the chacaters that are beeing read. * * @param[in] len * Number of characters to be read. * * @return * Number of characters that have been read. *****************************************************************************/ int _read(int file, char *ptr, int len) { int c, rxCount = 0; (void) file; while (len--) { if ((c = RETARGET_ReadChar()) != -1) { *ptr++ = c; rxCount++; } else { break; } } if (rxCount <= 0) { return -1; /* Error exit */ } return rxCount; }
/* Notes :(1) The first line of code is used to prevent a compiler warning because 'p_arg' is not * used. The compiler should not generate any code for this statement. * * ********************************************************************************************************* */ void APP_TaskTwo(void *p_arg) { OS_ERR err = OS_ERR_NONE; /* As USART connectors are not available on the STK by default, * therefore printf() functions are turned off. * Uncomment the macro definition in includes.h if serial * is connected to your STK board (USART1 or LEUART0)! */ #ifdef USART_CONNECTED static char taskMsg; /* Received character to be passed to TaskThree */ signed int taskCharBuffer = -1; /* Character buffer for receiving */ #endif /* end of #ifndef USART_CONNECTED */ (void)p_arg; /* Note(1) */ while (1) { /* Task body, always written as an infinite loop */ /* As USART connectors are not available on the STK by default, * therefore printf() functions are turned off. * Uncomment the macro definition in includes.h if serial * is connected to your STK board (USART1 or LEUART0)! */ #ifdef USART_CONNECTED /* Load character received on serial (USART0) to character buffer */ taskCharBuffer = RETARGET_ReadChar(); /* If the character in the buffer is valid... */ if (taskCharBuffer != -1) { /* ...cast and copy it to message buffer variable... */ taskMsg = (char)taskCharBuffer; /* ...and post the message to the mailbox */ OSQPost((OS_Q *) pSerialQueObj, (void *) &taskMsg, (OS_MSG_SIZE ) 1U, (OS_OPT )(OS_OPT_POST_FIFO | OS_OPT_POST_ALL), (OS_ERR *)&err); if(OS_ERR_NONE != err) { /* Error has occured, handle can be done here */ } } #endif /* end of #ifndef USART_CONNECTED */ /* Delay task for 1 system tick (uC/OS-III suspends this task and executes * the next most important task) */ OSTimeDly(1U, OS_OPT_TIME_DLY, &err); } }
size_t __read(int handle, unsigned char * buffer, size_t size) { /* Remove the #if #endif pair to enable the implementation */ int nChars = 0; /* This template only reads from "standard in", for all other file * handles it returns failure. */ if (handle != _LLIO_STDIN) { return _LLIO_ERROR; } for (/* Empty */; size > 0; --size) { int c = RETARGET_ReadChar(); if (c < 0) break; *buffer++ = c; ++nChars; } return nChars; }
/**************************************************************************//** * @brief * Reads character from file * * @param[in] f * File * * @return * Character *****************************************************************************/ int fgetc(FILE *f) { return(RETARGET_ReadChar()); }
int __getchar(void) { return(RETARGET_ReadChar()); }