OSDN Git Service

(none)
[hos/hos-v4a.git] / aplfw / driver / serial / at91 / at91uartdrv_read.c
1 /** 
2  *  Hyper Operating System  Application Framework
3  *
4  * @file  at91uartdrv_read.c
5  * @brief %jp{ATMEL AT91シリーズUART用デバイスドライバ}
6  *
7  * Copyright (C) 2006-2007 by Project HOS
8  * http://sourceforge.jp/projects/hos/
9  */
10
11
12 #include "at91uartdrv_local.h"
13
14
15 /** %jp{受信} */
16 FILE_SIZE At91UartDrv_Read(C_DRVOBJ *pDrvObj, C_FILEOBJ *pFileObj, void *pBuf, FILE_SIZE Size)
17 {
18         C_AT91UARTDRV   *self;
19         C_CHRFILE               *pChrFile;
20         unsigned char   *pubBuf;
21         FILE_SIZE               i;
22         int                             c;
23         
24         /* upper cast */
25         self     = (C_AT91UARTDRV *)pDrvObj;
26         pChrFile = (C_CHRFILE *)pFileObj;
27
28         pubBuf = (unsigned char *)pBuf;
29
30         /* クリティカルセクションに入る */
31         SysMtx_Lock(self->hMtxRecv);
32
33         for ( i = 0; i < Size; i++ )
34         {
35                 while ( (c = StreamBuf_RecvChar(&self->StmBufRecv)) < 0 )
36                 {
37                         if ( pChrFile->cReadMode == FILE_RMODE_BLOCKING )
38                         {
39                                 /* ブロッキングなら受信イベントを待つ */
40                                 SysEvt_Wait(self->hEvtRecv);
41                                 SysEvt_Clear(self->hEvtRecv);
42                         }
43                         else
44                         {
45                                 /* ノンブロッキングなら終了 */
46                                 goto loop_end;
47                         }
48                 }
49                 *pubBuf++ = (unsigned char)c;
50         }
51 loop_end:
52         
53         /* クリティカルセクションを出る */
54         SysMtx_Unlock(self->hMtxRecv);
55
56         return i;
57 }
58
59
60 /* end of file */