This is Webservice SDK for mbed. LPCXpresso1769/LPC1768/FRDM-K64F/LPC4088

Dependents:   MbedFileServer_1768MiniDK2 RedWireBridge IssueDebug_gcc MiMicRemoteMCU-for-Mbed ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers NyLPC_cRomPtrStream.c Source File

NyLPC_cRomPtrStream.c

00001 /*********************************************************************************
00002  * PROJECT: MiMic
00003  * --------------------------------------------------------------------------------
00004  *
00005  * This file is part of MiMic
00006  * Copyright (C)2011 Ryo Iizuka
00007  *
00008  * MiMic is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU Lesser General Public License as published
00010  * by the Free Software Foundation, either version 3 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public License
00019  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020  *
00021  * For further information please contact.
00022  *  http://nyatla.jp/
00023  *  <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
00024  *
00025  *********************************************************************************/
00026 #include "NyLPC_cPtrStream_protected.h"
00027 
00028 /**
00029  * ROMをラップするブロッキングストリーム型です。
00030  * このクラスは、NyLPC_TcBlockingStreamにキャストすることができます。
00031  特性
00032  このクラスは、read onlyです。write動作は永久に失敗します。
00033  また、タイムアウト値は意味を持たず、最終データを読みだした後はカウント0でタイムアウトと同じ挙動を示します。
00034  */
00035 typedef struct NyLPC_TcRomPtrStream NyLPC_TcRomPtrStream_t;
00036 
00037 /**********************************************************************
00038  *
00039  * NyLPC_TcRomBlockingStream class
00040  *
00041  **********************************************************************/
00042 
00043 struct NyLPC_TcRomPtrStream
00044 {
00045     NyLPC_TcPtrStream_t _super;
00046     NyLPC_TChar* _rom;          //ROMアドレス
00047     NyLPC_TInt32 _rom_size;     //ROMサイズ
00048     NyLPC_TInt32 _ed;           //読出し済みサイズ
00049     NyLPC_TInt16 _packet_size;  //一度当たりの読出しサイズ制限
00050 };
00051 
00052 NyLPC_TBool NyLPC_TcRomPtrStream_initialize(NyLPC_TcRomPtrStream_t* i_inst,void* i_rom_addr,NyLPC_TInt32 i_length,NyLPC_TInt16 i_packetsize);
00053 
00054 #define NyLPC_TcRomPtrStream_finalize(i_inst)
00055 
00056 static NyLPC_TInt32 m_pread(NyLPC_TcPtrStream_t* i_inst,const void** o_buf_ptr,NyLPC_TUInt32 i_wait_msec);
00057 static void m_close(NyLPC_TcPtrStream_t* i_inst);
00058 static void m_preadSeek_func(NyLPC_TcPtrStream_t* i_inst,NyLPC_TUInt16 i_seek);
00059 
00060 //関数テーブル
00061 static struct NyLPC_TcPtrStream_TInterface NyLPC_TcRomPtrStream_Interface=
00062 {
00063     m_pread,
00064     NyLPC_cPtrStream_write_func,
00065     m_preadSeek_func,
00066     m_close
00067 };
00068 
00069 
00070 
00071 NyLPC_TBool NyLPC_TcRomPtrStream_initialize(NyLPC_TcRomPtrStream_t* i_inst,void* i_rom_addr,NyLPC_TInt32 i_length,NyLPC_TInt16 i_packetsize)
00072 {
00073     NyLPC_ArgAssert(i_inst!=NULL);
00074     NyLPC_ArgAssert(i_rom_addr!=NULL);
00075     NyLPC_ArgAssert(i_length>0);
00076     NyLPC_ArgAssert(i_packetsize>0);
00077     i_inst->_super._interface=&NyLPC_TcRomPtrStream_Interface;
00078     i_inst->_rom=(NyLPC_TChar*)i_rom_addr;
00079     i_inst->_rom_size=i_length;
00080     i_inst->_packet_size=i_packetsize;
00081     return NyLPC_TBool_TRUE;
00082 }
00083 
00084 static void m_preadSeek_func(NyLPC_TcPtrStream_t* i_inst,NyLPC_TUInt16 i_seek)
00085 {
00086     (void)i_inst;
00087     NyLPC_TcRomPtrStream_t* inst=(NyLPC_TcRomPtrStream_t*)i_inst;
00088     inst->_rom+=i_seek;
00089 }
00090 
00091 
00092 /*private*/
00093 static NyLPC_TBool m_pread(NyLPC_TcPtrStream_t* i_inst,const void** o_buf_ptr,NyLPC_TUInt32 i_wait_msec)
00094 {
00095     NyLPC_TInt32 size,psize;
00096     NyLPC_TcRomPtrStream_t* inst=(NyLPC_TcRomPtrStream_t*)i_inst;
00097     //引数
00098     NyLPC_ArgAssert(i_inst!=NULL);
00099     NyLPC_ArgAssert(o_buf_ptr!=NULL);
00100     //クローズしてない?
00101     NyLPC_Assert(inst->_rom!=NULL);
00102 
00103     size=inst->_rom_size-inst->_ed;     //残り長さ計算
00104     psize=(size>inst->_packet_size)?inst->_packet_size:size;    //パケットサイズ計算
00105     *o_buf_ptr=(inst->_rom+inst->_ed);  //現在位置を返す
00106     inst->_ed+=psize;//読出し位置更新
00107     return psize;
00108 }
00109 
00110 
00111 static void m_close(NyLPC_TcPtrStream_t* i_inst)
00112 {
00113     NyLPC_TcRomPtrStream_t* inst=(NyLPC_TcRomPtrStream_t*)i_inst;
00114     inst->_rom=NULL;
00115 }
00116 
00117 
00118