JP2005148904A - Ring buffer controller and ring buffer control method - Google Patents

Ring buffer controller and ring buffer control method Download PDF

Info

Publication number
JP2005148904A
JP2005148904A JP2003382333A JP2003382333A JP2005148904A JP 2005148904 A JP2005148904 A JP 2005148904A JP 2003382333 A JP2003382333 A JP 2003382333A JP 2003382333 A JP2003382333 A JP 2003382333A JP 2005148904 A JP2005148904 A JP 2005148904A
Authority
JP
Japan
Prior art keywords
ring buffer
pointer
address
address bit
control device
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
JP2003382333A
Other languages
Japanese (ja)
Inventor
Hitoshi Hashimoto
均 橋本
Akihiko Yamazaki
明彦 山崎
Yoshito Goto
由人 後藤
Maki Hayashi
真樹 林
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Panasonic Holdings Corp
Original Assignee
Matsushita Electric Industrial Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Matsushita Electric Industrial Co Ltd filed Critical Matsushita Electric Industrial Co Ltd
Priority to JP2003382333A priority Critical patent/JP2005148904A/en
Publication of JP2005148904A publication Critical patent/JP2005148904A/en
Pending legal-status Critical Current

Links

Images

Abstract

<P>PROBLEM TO BE SOLVED: To easily and accurately detect the full/empty of a ring buffer, without increasing the control sequence. <P>SOLUTION: A write pointer generating part 105 increments the value of a write pointer(WP) and updates the WP. A readout pointer generating part 107 increments the value of a readout pointer(RP) and updates the RP. The writing pointer generating part 105 and the readout pointer generating part 107 manage the pointers with the number of bits obtained, by adding 1 bit to the number of address bits to be decided by the size of a ring buffer 104, and inverts the added bits when the address bits are counted up from the final address of the ring buffer 104, and returned to the leading address. A comparison arithmetic part 110 compares the WP with the RP and detects the full/empty of the ring buffer 104. <P>COPYRIGHT: (C)2005,JPO&NCIPI

Description

本発明は、ポインタ値からリングバッファの残量を算出するシステム上でリングバッファの状態を制御するリングバッファ制御装置およびリングバッファ制御方法に関する。   The present invention relates to a ring buffer control device and a ring buffer control method for controlling a state of a ring buffer on a system for calculating a remaining amount of the ring buffer from a pointer value.

従来、メモリ制御方式において、書込みポインタ(WP)と読出しポインタ(RP)の2つのアドレスポインタを用いてメモリバッファを管理するリングバッファ方式と呼ばれるメモリ制御方式が知られている。   Conventionally, in the memory control system, a memory control system called a ring buffer system that manages a memory buffer using two address pointers of a write pointer (WP) and a read pointer (RP) is known.

WPはメモリへのデータ書込みアクセス後にインクリメントし、RPはメモリからのデータ読出しアクセス後にインクリメントする。WPとRPの両ポインタの可変範囲はバッファメモリ領域に対応する。バッファ領域の先頭アドレスを初期値として、インクリメント後にバッファ領域の最終アドレスを超える場合には初期値に戻される。   WP increments after data write access to the memory, and RP increments after data read access from the memory. The variable range of both the WP and RP pointers corresponds to the buffer memory area. The initial address of the buffer area is set as an initial value. If the final address of the buffer area is exceeded after increment, the initial value is returned.

リングバッファ方式では、これらのポインタ値を用いてバッファの全領域を使用している状態(フル)とバッファの全領域が未使用の状態(エンプティ)とを判断する。書込み後にWP=RPとなる場合にはフルと判断し、読出し後にWP=RPとなる場合にはエンプティと判断する。
特開平5−289847号公報
In the ring buffer method, using these pointer values, it is determined whether the entire area of the buffer is being used (full) and whether the entire area of the buffer is unused (empty). If WP = RP after writing, it is determined to be full, and if WP = RP after reading, it is determined to be empty.
JP-A-5-289847

しかしながら、従来の方式では、書込みによってバッファがフル(WP=RP)になった後に、読出しイベントが発生したが何らかの原因で読出しを行うことができなかった場合には、読出しイベント後にRPがインクリメントされないためにWP=RPのままである。この場合、書込み制御部は、読出しイベント後のWP=RPと見なして、実際にはフルのままにも関わらず、これをエンプティと判断してしまう。   However, in the conventional method, when a read event occurs after the buffer becomes full (WP = RP) by writing but reading cannot be performed for some reason, RP is not incremented after the read event. Therefore, WP = RP remains. In this case, the write control unit regards WP = RP after the read event, and determines that this is empty even though it is actually full.

逆の場合も同様で、読出しによってバッファがエンプティ(WP=RP)になった後に、書込みイベントが発生したが何らかの原因で書込みを行うことができなかった場合には、書込みイベント後にWPがインクリメントされないためにWP=RPのままである。この場合、読出し制御部は、書込みイベント後のWP=RPと見なして、実際にはエンプティのままにも関わらず、これをフルと判断してしまう。   The same applies to the reverse case. If the write event occurs after the buffer becomes empty (WP = RP) by reading, but writing cannot be performed for some reason, WP is not incremented after the write event. Therefore, WP = RP remains. In this case, the read control unit regards WP = RP after the write event, and determines that this is full although it is actually empty.

このような事態の対策としてWP値とRP値の差分を計算し、例えばWP−RP=1の場合、即ち残量が1の場合にバッファフルと判断する方法がある。しかし、この方法では、RP値からWP値を減算する機能が必要になることに加え、バッファ領域を完全には使用できないという課題がある。   As a countermeasure against such a situation, there is a method of calculating the difference between the WP value and the RP value and determining that the buffer is full when, for example, WP-RP = 1, that is, when the remaining amount is 1. However, this method requires a function of subtracting the WP value from the RP value, and has a problem that the buffer area cannot be used completely.

また、他の方法として、新たにレジスタにフラグを追加して、書込み完了後にWP=RPとなった場合には書込み制御部がフラグを「書込み終了」に書き換え、読出し完了後にWP=RPとなった場合には読出し制御部が同じフラグを「読出し終了」に書き換える方法がある。これにより、書込みあるいは読出しが完了してWP=RPとなったのか、書込みあるいは読出しが行われずWP=RPのままであったのか、区別することが可能になる。しかし、この方法では、追加したフラグレジスタへの読出しと書込みアクセス等の制御シーケンスが増加するという課題がある。   As another method, when a flag is newly added to the register and WP = RP is obtained after writing is completed, the write control unit rewrites the flag to “end of writing”, and WP = RP is obtained after reading is completed. In such a case, there is a method in which the read control unit rewrites the same flag to “read complete”. This makes it possible to distinguish whether writing or reading is completed and WP = RP, or writing or reading is not performed and WP = RP is maintained. However, this method has a problem that the control sequence such as reading and writing access to the added flag register increases.

本発明は係る点に鑑みてなされたものであり、容易に、かつ正確に、リングバッファのフルとエンプティを判断することのできるリングバッファ制御装置およびリングバッファ制御方法を提供することを目的とする。   SUMMARY An advantage of some aspects of the invention is that it provides a ring buffer control device and a ring buffer control method capable of easily and accurately determining the fullness and emptyness of a ring buffer. .

本発明のリングバッファ制御装置は、リングバッファを用いたデータの転送を制御するリングバッファ制御装置であって、次回に転送データを格納するリングバッファアドレスを示す書込みポインタを生成する書込みポインタ生成手段と、次回に読み出す転送データのリングバッファアドレスを示す読出しポインタを生成する読出しポインタ生成手段と、を備え、前記書込みポインタ生成手段および前記読出しポインタ生成手段は、それぞれリングバッファで使用する第1アドレスビットに前記リングバッファで使用しない第2アドレスビットを付加したポインタを生成し、前記ポインタの前記第1アドレスビットが前記リングバッファの最終アドレスにあるときに前記ポインタを更新する場合に前記ポインタの前記第1アドレスビットを前記リングバッファの先頭アドレスに戻すと同時に前記第2アドレスビットを反転する構成を採る。   A ring buffer control device according to the present invention is a ring buffer control device for controlling transfer of data using a ring buffer, and a write pointer generating means for generating a write pointer indicating a ring buffer address for storing transfer data next time; Read pointer generation means for generating a read pointer indicating the ring buffer address of the transfer data to be read next time, and the write pointer generation means and the read pointer generation means each have a first address bit used in the ring buffer. Generating a pointer to which a second address bit not used in the ring buffer is added, and updating the pointer when the first address bit of the pointer is at the final address of the ring buffer; Before address bit At the same time back to the start address of the ring buffer employs a configuration for inverting the second address bits.

本発明のリングバッファ制御装置は、前記書込みポインタと前記読出しポインタとの排他的論理和(EXOR)演算を行い、演算結果が、前記第1アドレスビットがゼロであり前記第2アドレスビットが1である場合はリングバッファの残量がゼロであることを検出し、前記第1アドレスビットと前記第2アドレスビットがともにゼロである場合にはリングバッファの使用量がゼロであることを検出する比較演算手段を備える構成を採る。   The ring buffer control device of the present invention performs an exclusive OR (EXOR) operation of the write pointer and the read pointer, and the operation result is that the first address bit is zero and the second address bit is 1. In some cases, it is detected that the remaining amount of the ring buffer is zero, and in the case where both the first address bit and the second address bit are zero, a comparison for detecting that the usage amount of the ring buffer is zero. A configuration including arithmetic means is adopted.

本発明のリングバッファ制御装置は、リングバッファを用いてデータの転送元である送信手段からデータの転送先である受信手段へデータを転送するリングバッファ制御装置であって、前記比較演算手段は、演算結果が、前記第1アドレスビットがゼロであり前記第2アドレスビットが1である場合に前記送信手段へリングバッファのオーバーフローを警告する第1割り込み信号を出力し、前記第1アドレスビットと前記第2アドレスビットがともにゼロである場合に前記受信手段へデータの転送完了を示す第2割込み信号を出力する構成を採る。   The ring buffer control device of the present invention is a ring buffer control device that transfers data from a transmission means that is a data transfer source to a reception means that is a data transfer destination using a ring buffer, wherein the comparison operation means includes: When the operation result is that the first address bit is zero and the second address bit is 1, a first interrupt signal is output to the transmitting means to warn of an overflow of a ring buffer, and the first address bit and the A configuration is adopted in which when the second address bits are both zero, a second interrupt signal indicating completion of data transfer is output to the receiving means.

これらの構成により、リングバッファを余すことなく効率的に使用することができ、かつ、制御シーケンスを増大させることなく容易にリングバッファのフルおよびエンプティを検出することができる。   With these configurations, it is possible to efficiently use the ring buffer without leaving it, and it is possible to easily detect the fullness and emptyness of the ring buffer without increasing the control sequence.

本発明のプロセッサ間通信装置は、デュアルポートメモリを使用して第1プロセッサと第2プロセッサの間でデータ転送を行う通信装置であって、前記第1プロセッサから前記第2プロセッサへのデータ転送に用いる請求項3記載の第1リングバッファ制御装置と、前記第2プロセッサから前記第1プロセッサへのデータ転送に用いる請求項3記載の第2リングバッファ制御装置と、を備え、前記第1リングバッファ制御装置の第1割り込み信号と前記第2リングバッファ制御装置の第2割り込み信号を前記第1プロセッサへ入力し、前記第2リングバッファ制御装置の第1割り込み信号と前記第1リングバッファ制御装置の第2割り込み信号を前記第2プロセッサへ入力する構成を採る。   An inter-processor communication device according to the present invention is a communication device that transfers data between a first processor and a second processor using a dual port memory, and is used for data transfer from the first processor to the second processor. A first ring buffer control device according to claim 3, and a second ring buffer control device according to claim 3 used for data transfer from the second processor to the first processor, wherein the first ring buffer is used. The first interrupt signal of the control device and the second interrupt signal of the second ring buffer control device are input to the first processor, and the first interrupt signal of the second ring buffer control device and the first ring buffer control device The second interrupt signal is input to the second processor.

この構成により、第1プロセッサと第2プロセッサは、リングバッファの書込みポインタと読出しポインタの比較管理することなく、割込み信号によってリングバッファのフルまたはエンプティを、容易、かつ正確に検知することができる。また、このような装置を小規模なハードウェア構成で実現することができる。   With this configuration, the first processor and the second processor can easily and accurately detect the fullness or emptyness of the ring buffer by the interrupt signal without managing the comparison of the write pointer and the read pointer of the ring buffer. Moreover, such an apparatus can be realized with a small-scale hardware configuration.

本発明のリングバッファ制御方法は、リングバッファで使用する第1アドレスビットに、前記リングバッファで使用しない第2アドレスビットを付加したポインタを生成し、前記ポインタの前記第1アドレスビットが前記リングバッファの最終アドレスにあるときに前記ポインタを更新する場合に、前記ポインタの前記第1アドレスビットを前記リングバッファの先頭アドレスに戻すと同時に前記第2アドレスビットを反転する方法を採る。   In the ring buffer control method of the present invention, a pointer is generated by adding a second address bit not used in the ring buffer to a first address bit used in the ring buffer, and the first address bit of the pointer is the ring buffer. When the pointer is updated at the last address, the first address bit of the pointer is returned to the head address of the ring buffer and the second address bit is inverted at the same time.

この方法により、リングバッファを余すことなく効率的に使用することができ、かつ、制御シーケンスを増大させることなく容易にリングバッファのフルおよびエンプティを検出することができる。   According to this method, the ring buffer can be used efficiently without being left over, and the full and empty of the ring buffer can be easily detected without increasing the control sequence.

本発明によれば、リングバッファを余すことなく効率的に使用することができ、かつ、制御シーケンスを増大させることなく容易にリングバッファのフルおよびエンプティを検出することができる。   According to the present invention, it is possible to efficiently use a ring buffer without leaving it, and to easily detect the fullness and emptyness of the ring buffer without increasing the control sequence.

本発明の骨子は、リングバッファの書込みポインタと読み出しポインタを、バッファサイズから決まるアドレスビット数に1ビットを付加したビット数にし、ポインタがリングバッファの最終アドレスにあるときにインクリメントする場合はポインタをリングバッファの先頭アドレスに移すと同時に付加ビットを反転することで、リングバッファのフルまたはエンプティの誤検出を防ぐことである。   The essence of the present invention is that the write pointer and read pointer of the ring buffer are set to the number of bits obtained by adding 1 bit to the number of address bits determined from the buffer size, and when the pointer is incremented when the pointer is at the final address of the ring buffer, the pointer is changed. It is to prevent erroneous detection of the full or empty of the ring buffer by inverting the additional bit at the same time as moving to the head address of the ring buffer.

以下、本発明の実施の形態について、図面を参照して詳細に説明する。   Hereinafter, embodiments of the present invention will be described in detail with reference to the drawings.

(実施の形態1)
図1は、本発明の第1の形態におけるリングバッファ制御装置の構成を示すブロック図である。
(Embodiment 1)
FIG. 1 is a block diagram showing a configuration of a ring buffer control device according to the first embodiment of the present invention.

リングバッファ制御装置100は、書込み制御部101と、読出し制御部102と、データバス103、リングバッファ104と、書込みポインタ生成部105と、書込みポインタ保持部106と、読出しポインタ生成部107と、読出しポインタ保持部108と、切替え部109と、比較演算部110とから主に構成される。   The ring buffer control device 100 includes a write control unit 101, a read control unit 102, a data bus 103, a ring buffer 104, a write pointer generation unit 105, a write pointer holding unit 106, a read pointer generation unit 107, and a read A pointer holding unit 108, a switching unit 109, and a comparison calculation unit 110 are mainly configured.

書込み制御部101は、書込みイベントが発生するとデータバス103を介してリングバッファ104へデータを書き込む。また、書込み制御部101は、書込みイベントが終了すると書込みポインタ生成部105へ書込みイベント終了を通知する。   The write control unit 101 writes data to the ring buffer 104 via the data bus 103 when a write event occurs. In addition, when the write event ends, the write control unit 101 notifies the write pointer generation unit 105 of the end of the write event.

読出し制御部102は、読出しイベントが発生するとデータバス103を介してリングバッファ104からデータを読み出す。読出し制御部102は、読出しイベントが終了すると読出しポインタ生成部107へ読出しイベント終了を通知する。   The read control unit 102 reads data from the ring buffer 104 via the data bus 103 when a read event occurs. When the read event ends, the read control unit 102 notifies the read pointer generation unit 107 of the end of the read event.

リングバッファ104は、切替え部109から出力されたアドレスに対して、データバス103のデータを書込み、あるいは読出しを行う。   The ring buffer 104 writes or reads data on the data bus 103 to the address output from the switching unit 109.

書込みポインタ生成部105は、書込み制御部101から書込みイベント終了の通知を受けると書込みポインタ(WP)の値をインクリメントしてWPを更新し、書込みポインタ保持部106と切替え部109へ出力する。なお、書込みポインタ生成部105の動作の詳細は後述する。   When receiving a write event end notification from the write control unit 101, the write pointer generation unit 105 increments the value of the write pointer (WP) to update the WP, and outputs the WP to the write pointer holding unit 106 and the switching unit 109. Details of the operation of the write pointer generator 105 will be described later.

書込みポインタ保持部106は、書込みポインタ生成部105から出力された書込みアドレスを保持するとともに、比較演算部110へ出力する。   The write pointer holding unit 106 holds the write address output from the write pointer generation unit 105 and outputs it to the comparison operation unit 110.

読出しポインタ生成部107は、読出し制御部102から読出しイベント終了の通知を受けると読出しポインタ(RP)の値をインクリメントしてRPを更新し、読出しポインタ保持部108と切替え部109へ出力する。なお、読出しポインタ生成部107の動作の詳細は後述する。   When the read pointer generation unit 107 receives a read event end notification from the read control unit 102, the read pointer generation unit 107 updates the RP by incrementing the value of the read pointer (RP), and outputs it to the read pointer holding unit 108 and the switching unit 109. Details of the operation of the read pointer generation unit 107 will be described later.

読出しポインタ保持部108は、読出しポインタ生成部107から出力された読出しアドレスを保持するとともに、比較演算部110へ出力する。   The read pointer holding unit 108 holds the read address output from the read pointer generation unit 107 and outputs it to the comparison operation unit 110.

切替え部109は、書込みポインタ生成部105から出力されたWPの値(書込みアドレス)と、読出しポインタ生成部107から出力されたRPの値(読出しアドレス)とを切替えてリングバッファのアドレスバスへ出力する。   The switching unit 109 switches between the WP value (write address) output from the write pointer generation unit 105 and the RP value (read address) output from the read pointer generation unit 107 and outputs it to the address bus of the ring buffer. To do.

比較演算部110は、書込みアドレスと読み出しアドレスの比較演算を行い、結果を書込み制御部101と読出し制御部102へ出力する。なお、比較演算部110の動作の詳細は後述する。   The comparison operation unit 110 performs a comparison operation between the write address and the read address, and outputs the result to the write control unit 101 and the read control unit 102. Details of the operation of the comparison calculation unit 110 will be described later.

以下、本発明の主要部分である書込みポインタ生成部105、読出しポインタ生成部107及び比較演算部110の動作について、図2及び図3を用いて詳細に説明する。   Hereinafter, operations of the write pointer generation unit 105, the read pointer generation unit 107, and the comparison calculation unit 110, which are main parts of the present invention, will be described in detail with reference to FIGS.

図2はポインタとリングバッファのビット構成を表している。   FIG. 2 shows the bit structure of the pointer and ring buffer.

書込みポインタと読出しポインタは、リングバッファアドレスの上位に1ビット幅のビット(以下、「付加ビット」という)201を付加した構成とする。例えば、リングバッファのアドレスのビット幅が10ビットの場合、書込みポインタと読出しポインタのビット幅は11ビットである。   The write pointer and the read pointer have a configuration in which a bit (hereinafter referred to as “additional bit”) 201 having a 1-bit width is added to the upper part of the ring buffer address. For example, if the bit width of the address of the ring buffer is 10 bits, the bit width of the write pointer and the read pointer is 11 bits.

図3はポインタの遷移と対応するリングバッファのアドレスを表した図である。   FIG. 3 shows the ring buffer address corresponding to the pointer transition.

書込みポインタ生成部105と読出しポインタ生成部107の動作は同じである。WPとRPの両ポインタのうちの付加ビット201を除くリングバッファアドレス部分は、リングバッファの先頭アドレス301を初期値として順次インクリメントしていき、リングバッファの最終アドレス302までカウントアップしていく。ポインタが最終アドレス302に到達した場合、次のカウントでリングバッファの先頭アドレス301に戻される。この時に付加ビット201を反転する。   The operations of the write pointer generator 105 and the read pointer generator 107 are the same. The ring buffer address portion of the WP and RP pointers excluding the additional bit 201 is incremented sequentially with the initial address 301 of the ring buffer as an initial value, and counts up to the final address 302 of the ring buffer. When the pointer reaches the final address 302, it is returned to the head address 301 of the ring buffer at the next count. At this time, the additional bit 201 is inverted.

具体例をあげて説明する。例えば、リングバッファのアドレスを、図3に示すように、先頭アドレス301を000hで最終アドレス302を2FFhとする10ビット構成とする。ポインタは、図2で示したように上位に付加ビット201を付加した11ビット構成とする。付加ビット201の初期値は0であるとする。   A specific example will be described. For example, as shown in FIG. 3, the ring buffer address has a 10-bit configuration in which the start address 301 is 000h and the final address 302 is 2FFh. As shown in FIG. 2, the pointer has an 11-bit configuration in which an additional bit 201 is added to the higher order. It is assumed that the initial value of the additional bit 201 is 0.

ポインタの値がリングバッファの最終アドレス302、すなわち2FFhである場合には、次のカウントで、ポインタの下位10ビットはリングバッファの先頭アドレス351である000hとして、付加ビット201は反転して1とする。すなわちポインタの値は400hとする。更にカウントが進むと、やがて、ポインタの下位10ビットがリングバッファの最終アドレス352の2FFhとなり、付加ビット201(値は1)と合わせて6FFhになる。この場合には、次のカウントで、ポインタの下位10ビットはリングバッファの先頭アドレスである000hとして、付加ビット201は反転して0とする。すなわちポインタの値は000hとする。   When the value of the pointer is the final address 302 of the ring buffer, that is, 2FFh, in the next count, the lower 10 bits of the pointer are set to 000h which is the head address 351 of the ring buffer, and the additional bit 201 is inverted to 1. To do. That is, the pointer value is 400h. As the count proceeds further, the lower 10 bits of the pointer eventually becomes 2FFh of the final address 352 of the ring buffer, and becomes 6FFh together with the additional bit 201 (value is 1). In this case, in the next count, the lower 10 bits of the pointer are set to 000h which is the head address of the ring buffer, and the additional bit 201 is inverted to 0. That is, the pointer value is 000h.

これにより、ポインタの値は、000hから2FFhまで加算されていき、次に400hとなり、その後6FFhまで加算され、また000hに戻される。このとき、リングバッファのアドレスはポインタの下位10ビットであるので、対応するリングバッファアドレスは、いずれも000hから2FFhまでである。   As a result, the pointer value is added from 000h to 2FFh, then becomes 400h, then added to 6FFh, and returned to 000h. At this time, since the ring buffer address is the lower 10 bits of the pointer, the corresponding ring buffer addresses are all from 000h to 2FFh.

このようにポインタを管理することでリングバッファのフルとエンプティを容易に区別できる。   By managing the pointers in this way, it is possible to easily distinguish between full and empty ring buffers.

リングバッファがフルになるのは、読出しアドレス(RPの値)と書込みアドレス(WPの値)の下位10ビットが等しく、上位1ビットの付加ビットのみが異なる場合である。すなわち、例えば、RP=1AAhである時に、WP=5AAhとなった場合や、RP=5AAhである時に、WP=1AAhとなった場合である。ここで、ポインタ値1AAhおよび5AAhに対応するリングバッファのアドレスはいずれも1AAhである。   The ring buffer becomes full when the lower 10 bits of the read address (RP value) and the write address (WP value) are equal and only the additional bit of the upper 1 bit is different. That is, for example, when RP = 1AAh, WP = 5AAh, or when RP = 5AAh, WP = 1AAh. Here, the ring buffer addresses corresponding to the pointer values 1AAh and 5AAh are both 1AAh.

一方、リングバッファがエンプティになるのは、読出しアドレスと書込みアドレスが等しい場合である。すなわち、例えば、WP=18Bhである時に、RP=18Bとなった場合や、WP=58Bhである時に、RP=58Bhとなった場合などである。ここで、ポインタ値18Bhおよび58Bhに対応するリングバッファのアドレスはいずれも18Bhである。   On the other hand, the ring buffer becomes empty when the read address and the write address are equal. That is, for example, when WP = 18Bh, RP = 18B, or when WP = 58Bh, RP = 58Bh. Here, the ring buffer addresses corresponding to the pointer values 18Bh and 58Bh are both 18Bh.

ここで、比較演算部110は、WPとRPとの各ビット同士で排他的論理和(EXOR)を演算する。演算結果が000hであればリングバッファはエンプティであり、結果が400hであればリングバッファはフルであり、それ以外であれば書込みおよび読出しがともに可能な状態であるということができる。   Here, the comparison operation unit 110 calculates an exclusive OR (EXOR) between the bits of WP and RP. If the calculation result is 000h, the ring buffer is empty. If the result is 400h, the ring buffer is full. Otherwise, it can be said that both writing and reading are possible.

このような処理により、書込みによってバッファがフル(WPとRPとが上位1ビットのみ異なる)になった後に、読出しイベントが発生したが何らかの原因で読出しを行えなかった場合にも、読出しイベント後にRPがインクリメントされないがWP=RPではない。したがって、この場合にエンプティ(WP=RP)と判断されることはない。   By such processing, even when a read event occurs after the buffer becomes full by writing (WP and RP differ only in the upper 1 bit), but the read operation cannot be performed for some reason, the RP is read after the read event. Is not incremented but WP = RP. Therefore, in this case, it is not determined that it is empty (WP = RP).

逆の場合も同様で、読出しによってバッファがエンプティ(WP=RP)になった後に、書込みイベントが発生したが何らかの原因で書込みを行えなかった場合にも、書込みイベント後にWPがインクリメントされずにWP=RPのままである。したがって、この場合にフル(WPとRPとが最上位1ビットのみ異なる)と判断されることはない。   The same applies to the reverse case, and if the write event occurs after the buffer becomes empty (WP = RP) by reading, but the write cannot be performed for some reason, the WP is not incremented after the write event. = RP remains. Therefore, in this case, it is not determined that the full state (WP and RP differ by only the most significant 1 bit).

なお、付加ビットの初期値を1とした場合には、リングバッファのフルとエンプティの条件が入れ替わる。すなわち、WP=RPのときにフルであり、WPとRPとが最上位1ビットのみ異なるときにエンプティである。   If the initial value of the additional bits is 1, the ring buffer full and empty conditions are switched. That is, it is full when WP = RP, and it is empty when WP and RP differ by only the most significant 1 bit.

また、比較演算部110をハードで構成する場合には、書込みポインタと読出しポインタをレジスタに入力して、2つのレジスタのEXOR演算によりリングバッファのフルないしエンプティを検知することができ、減算機能などを持たせる必要はなく、小規模な回路規模で構成することができる。   Further, when the comparison operation unit 110 is configured by hardware, a write pointer and a read pointer can be input to the registers, and the full or empty of the ring buffer can be detected by the EXOR operation of the two registers. It is not necessary to have a small circuit scale.

また、フルとエンプティの誤検出を防ぐためにリングバッファ領域の一部をマージンとして使用しない処理などは必要なく、リングバッファ領域の全てを効率的に使用することができる。   Further, in order to prevent erroneous detection of full and empty, it is not necessary to perform processing that does not use a part of the ring buffer area as a margin, and the entire ring buffer area can be used efficiently.

また、汎用プロセッサなどポインタのビット幅があらかじめ決められていて、リングバッファアドレスのビット幅がそれより小さい場合には、従来使用していなかった上位ビットを使用すれば、新たにフラグを追加してフラグレジスタへの書込みや読出しといったアクセスのための制御シーケンスが増大するといった課題が生じることはない。   In addition, if the bit width of the pointer is predetermined and the bit width of the ring buffer address is smaller than that, such as a general-purpose processor, if a higher bit that was not used conventionally is used, a flag is newly added. There is no problem that the control sequence for access such as writing to and reading from the flag register increases.

(実施の形態2)
図4は、デュアルポートRAMを用いたCPU間通信におけるリングバッファ制御装置の構成を示すブロック図である。なお、図4に示すリングバッファ制御装置400において、図1に示したリングバッファ制御装置100と共通する構成部分には図1と同一符号を付してその説明を省略する。
(Embodiment 2)
FIG. 4 is a block diagram showing a configuration of a ring buffer control device in inter-CPU communication using a dual port RAM. In the ring buffer control device 400 shown in FIG. 4, the same components as those in the ring buffer control device 100 shown in FIG.

図4に示すリングバッファ制御装置400は、比較演算部401の作用が図1の比較演算部110と異なる。また、図4に示すリングバッファ制御装置400の送信CPU402は、図1の書込み制御部101の機能と書込みポインタ生成部105の機能を含む。図4に示すリングバッファ制御装置400の受信CPU403は、図1の読出し制御部102の機能と読出しポインタ生成部107の機能を含む。図4のデュアルポートRAM(DPRAM)404は、その記憶領域の一部を、図1のリングバッファ104として用いる。   The ring buffer control device 400 shown in FIG. 4 is different from the comparison operation unit 110 in FIG. 1 in the operation of the comparison operation unit 401. Further, the transmission CPU 402 of the ring buffer control device 400 shown in FIG. 4 includes the function of the write control unit 101 and the function of the write pointer generation unit 105 of FIG. The reception CPU 403 of the ring buffer control device 400 shown in FIG. 4 includes the functions of the read control unit 102 and the read pointer generation unit 107 of FIG. The dual port RAM (DPRAM) 404 in FIG. 4 uses a part of the storage area as the ring buffer 104 in FIG.

送信CPU402は、書込みイベントが発生するとDPRAM404へデータを書き込む。送信CPU402は、書込みイベントが終了すると書込みポインタ(WP)の値をインクリメントしてWPを更新し、書込みポインタ保持部106と比較演算部401とへWPを出力する。   The transmission CPU 402 writes data to the DPRAM 404 when a write event occurs. When the write event ends, the transmission CPU 402 updates the WP by incrementing the value of the write pointer (WP), and outputs the WP to the write pointer holding unit 106 and the comparison operation unit 401.

受信CPU403は、読出しイベントが発生するとDPRAM404からデータを読み出す。受信CPU403は、読出しイベントが終了すると読出しポインタ(RP)の値をインクリメントしてRPを更新し、読出しポインタ保持部108と比較演算部401とへRPを出力する。   The reception CPU 403 reads data from the DPRAM 404 when a read event occurs. When the read event ends, the reception CPU 403 updates the RP by incrementing the value of the read pointer (RP), and outputs the RP to the read pointer holding unit 108 and the comparison calculation unit 401.

比較演算部401は、書込みポインタ保持部106に保持されたWPと読出しポインタ保持部108に保持されたRPとを比較して、比較結果によって送信CPU402または受信CPU403へ割込み信号を出力する。WP=RPである場合には、リングバッファはエンプティであり、比較演算部401は、受信CPU403へエンプティを示す割り込み信号を出力する。WPとRPとが付加ビット(1ビット)のみ異なる場合は、リングバッファはフルであり、比較演算部401は、送信CPU402へフルを示す割り込み信号を出力する。   The comparison operation unit 401 compares the WP held in the write pointer holding unit 106 with the RP held in the read pointer holding unit 108, and outputs an interrupt signal to the transmission CPU 402 or the reception CPU 403 depending on the comparison result. When WP = RP, the ring buffer is empty, and the comparison operation unit 401 outputs an interrupt signal indicating empty to the reception CPU 403. When WP and RP differ only by an additional bit (1 bit), the ring buffer is full, and the comparison operation unit 401 outputs an interrupt signal indicating full to the transmission CPU 402.

このような構成で、実施の形態1に示したように、リングバッファの管理に必要なアドレスビットに1ビットを付加したビット数でWPとRPを管理する。   With such a configuration, as shown in the first embodiment, WP and RP are managed by the number of bits obtained by adding 1 bit to the address bits necessary for managing the ring buffer.

これにより、送信CPUと受信CPUはDPRAM上に設けたリングバッファの書込みポインタと読出しポインタの比較管理することなく、割込み信号によってリングバッファのフルまたはエンプティを、容易、かつ正確に検知することができる。また、このような装置を小規模なハードウェア構成で実現することができる。   As a result, the sending CPU and the receiving CPU can easily and accurately detect the fullness or emptyness of the ring buffer by the interrupt signal, without comparing and managing the write pointer and the read pointer of the ring buffer provided on the DPRAM. . Moreover, such an apparatus can be realized with a small-scale hardware configuration.

本発明は、小さなバッファを用いて効率的なデータ転送を行う通信装置に用いるに好適である。   The present invention is suitable for use in a communication apparatus that performs efficient data transfer using a small buffer.

本発明の実施の形態1に係るリングバッファ制御装置の構成を示すブロック図1 is a block diagram showing a configuration of a ring buffer control device according to a first embodiment of the present invention. 上記実施の形態に係るポインタとリングバッファアドレスのビット構成を示す図The figure which shows the bit structure of the pointer and ring buffer address which concern on the said embodiment 上記実施の形態に係るポインタの遷移と対応するリングバッファのアドレスを示す図The figure which shows the address of the ring buffer corresponding to the transition of the pointer which concerns on the said embodiment 本発明の実施の形態2に係るリングバッファ制御装置の構成を示すブロック図The block diagram which shows the structure of the ring buffer control apparatus which concerns on Embodiment 2 of this invention.

符号の説明Explanation of symbols

101 書込み制御部
102 読出し制御部
103 データバス
104 リングバッファ
105 書込みポインタ生成部
106 書込みポインタ保持部
107 読出しポインタ生成部
108 読出しポインタ保持部
109 切替え部
110、401 比較演算部
402 送信CPU
403 受信CPU
404 DPRAM
DESCRIPTION OF SYMBOLS 101 Write control part 102 Read control part 103 Data bus 104 Ring buffer 105 Write pointer production | generation part 106 Write pointer holding part 107 Read pointer production | generation part 108 Read pointer holding part 109 Switching part 110, 401 Comparison calculating part 402 Transmission CPU
403 receiving CPU
404 DPRAM

Claims (5)

リングバッファを用いたデータの転送を制御するリングバッファ制御装置であって、
次回に転送データを格納するリングバッファアドレスを示す書込みポインタを生成する書込みポインタ生成手段と、
次回に読み出す転送データのリングバッファアドレスを示す読出しポインタを生成する読出しポインタ生成手段と、を備え、
前記書込みポインタ生成手段および前記読出しポインタ生成手段は、それぞれリングバッファで使用する第1アドレスビットに前記リングバッファで使用しない第2アドレスビットを付加したポインタを生成し、前記ポインタの前記第1アドレスビットが前記リングバッファの最終アドレスにあるときに前記ポインタを更新する場合に前記ポインタの前記第1アドレスビットを前記リングバッファの先頭アドレスに戻すと同時に前記第2アドレスビットを反転することを特徴とするリングバッファ制御装置。
A ring buffer control device for controlling transfer of data using a ring buffer,
Write pointer generation means for generating a write pointer indicating a ring buffer address for storing transfer data next time,
Read pointer generation means for generating a read pointer indicating a ring buffer address of transfer data to be read next time,
The write pointer generation unit and the read pointer generation unit generate a pointer in which a second address bit not used in the ring buffer is added to a first address bit used in the ring buffer, respectively, and the first address bit of the pointer When the pointer is updated when is at the last address of the ring buffer, the first address bit of the pointer is returned to the head address of the ring buffer, and at the same time, the second address bit is inverted. Ring buffer controller.
前記書込みポインタと前記読出しポインタとの排他的論理和(EXOR)演算を行い、演算結果が、前記第1アドレスビットがゼロであり前記第2アドレスビットが1である場合はリングバッファの残量がゼロであることを検出し、前記第1アドレスビットと前記第2アドレスビットがともにゼロである場合にはリングバッファの使用量がゼロであることを検出する比較演算手段を備えることを特徴とする請求項1記載のリングバッファ制御装置。   An exclusive OR (EXOR) operation of the write pointer and the read pointer is performed, and when the operation result is that the first address bit is zero and the second address bit is 1, the remaining amount of the ring buffer is Comparing operation means for detecting zero and detecting that the amount of use of the ring buffer is zero when both the first address bit and the second address bit are zero is provided. The ring buffer control device according to claim 1. リングバッファを用いてデータの転送元である送信手段からデータの転送先である受信手段へデータを転送するリングバッファ制御装置であって、
前記比較演算手段は、演算結果が、前記第1アドレスビットがゼロであり前記第2アドレスビットが1である場合に前記送信手段へリングバッファのオーバーフローを警告する第1割り込み信号を出力し、前記第1アドレスビットと前記第2アドレスビットがともにゼロである場合に前記受信手段へデータの転送完了を示す第2割込み信号を出力することを特徴とする請求項2に記載のリングバッファ制御装置。
A ring buffer control device for transferring data from a transmission means as a data transfer source to a reception means as a data transfer destination using a ring buffer,
The comparison operation means outputs a first interrupt signal that warns the transmission means of an overflow of a ring buffer when the operation result is that the first address bit is zero and the second address bit is 1. 3. The ring buffer control device according to claim 2, wherein when the first address bit and the second address bit are both zero, a second interrupt signal indicating completion of data transfer is output to the receiving means.
デュアルポートメモリを使用して第1プロセッサと第2プロセッサの間でデータ転送を行う通信装置であって、
前記第1プロセッサから前記第2プロセッサへのデータ転送に用いる請求項3記載の第1リングバッファ制御装置と、
前記第2プロセッサから前記第1プロセッサへのデータ転送に用いる請求項3記載の第2リングバッファ制御装置と、を備え、
前記第1リングバッファ制御装置の第1割り込み信号と前記第2リングバッファ制御装置の第2割り込み信号を前記第1プロセッサへ入力し、
前記第2リングバッファ制御装置の第1割り込み信号と前記第1リングバッファ制御装置の第2割り込み信号を前記第2プロセッサへ入力することを特徴とするプロセッサ間通信装置。
A communication device for transferring data between a first processor and a second processor using a dual port memory,
The first ring buffer control device according to claim 3, which is used for data transfer from the first processor to the second processor;
A second ring buffer control device according to claim 3, which is used for data transfer from the second processor to the first processor.
A first interrupt signal of the first ring buffer controller and a second interrupt signal of the second ring buffer controller are input to the first processor;
An inter-processor communication device, wherein a first interrupt signal of the second ring buffer control device and a second interrupt signal of the first ring buffer control device are input to the second processor.
リングバッファで使用する第1アドレスビットに、前記リングバッファで使用しない第2アドレスビットを付加したポインタを生成し、前記ポインタの前記第1アドレスビットが前記リングバッファの最終アドレスにあるときに前記ポインタを更新する場合に、前記ポインタの前記第1アドレスビットを前記リングバッファの先頭アドレスに戻すと同時に前記第2アドレスビットを反転することを特徴とするリングバッファ制御方法。   A pointer is generated by adding a second address bit not used in the ring buffer to a first address bit used in the ring buffer, and the pointer is located when the first address bit of the pointer is at the final address of the ring buffer. In the ring buffer control method, when the first address bit of the pointer is returned to the head address of the ring buffer, the second address bit is inverted at the same time.
JP2003382333A 2003-11-12 2003-11-12 Ring buffer controller and ring buffer control method Pending JP2005148904A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2003382333A JP2005148904A (en) 2003-11-12 2003-11-12 Ring buffer controller and ring buffer control method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2003382333A JP2005148904A (en) 2003-11-12 2003-11-12 Ring buffer controller and ring buffer control method

Publications (1)

Publication Number Publication Date
JP2005148904A true JP2005148904A (en) 2005-06-09

Family

ID=34691441

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2003382333A Pending JP2005148904A (en) 2003-11-12 2003-11-12 Ring buffer controller and ring buffer control method

Country Status (1)

Country Link
JP (1) JP2005148904A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2010061618A (en) * 2008-09-08 2010-03-18 Mega Chips Corp Memory system
US8510503B2 (en) 2009-01-07 2013-08-13 Renesas Electronics Corporation Ring buffer circuit and control circuit for ring buffer circuit
KR20160040878A (en) * 2014-10-06 2016-04-15 주식회사 엘지화학 Apparatus and Method of Updating Current Value of Secondary Battery Pack
US9544401B2 (en) 2013-02-18 2017-01-10 Ricoh Company, Ltd. Device and method for data communication using a transmission ring buffer

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2010061618A (en) * 2008-09-08 2010-03-18 Mega Chips Corp Memory system
US8510503B2 (en) 2009-01-07 2013-08-13 Renesas Electronics Corporation Ring buffer circuit and control circuit for ring buffer circuit
US9544401B2 (en) 2013-02-18 2017-01-10 Ricoh Company, Ltd. Device and method for data communication using a transmission ring buffer
KR20160040878A (en) * 2014-10-06 2016-04-15 주식회사 엘지화학 Apparatus and Method of Updating Current Value of Secondary Battery Pack
KR101696316B1 (en) * 2014-10-06 2017-01-13 주식회사 엘지화학 Apparatus and Method of Updating Current Value of Secondary Battery Pack

Similar Documents

Publication Publication Date Title
KR101050554B1 (en) Masking in Data Processing Systems Applicable to Development Interfaces
US7934025B2 (en) Content terminated DMA
US8291136B2 (en) Ring buffer
US20120117428A1 (en) Cache memory system
CN107636630B (en) Interrupt controller
US8190794B2 (en) Control function for memory based buffers
JP2006338538A (en) Stream processor
JPWO2010013340A1 (en) Data transfer device, data transmission device, data reception device, and data transfer method
CN113900974B (en) Storage device, data storage method and related equipment
JP2010211322A (en) Network processor, reception controller, and data reception processing method
US10505704B1 (en) Data uploading to asynchronous circuitry using circular buffer control
JP2005148904A (en) Ring buffer controller and ring buffer control method
JPWO2008068937A1 (en) Data transfer control device and computer system
KR20110089129A (en) Bit inversion for communication interface
JP5843804B2 (en) Arithmetic apparatus and error processing method
US8904076B2 (en) Coder with snoop mode
US20020032846A1 (en) Memory management apparatus and method
KR20060004829A (en) Direct memory access device, system and method for transmitting and receiving data through direct memory access device
KR20100063219A (en) Apparatus and method for writing of bitwise data in bus system
JPWO2004051492A1 (en) Storage device that compresses the same input value
JP5093986B2 (en) Interprocessor communication method and interprocessor communication apparatus
JP4478592B2 (en) Memory circuit
JPH0773114A (en) Memory control circuit for space digital computer
JP3800171B2 (en) Store instruction execution control method and store instruction execution control method
JPH05233440A (en) Data transfer system equipped with buffer function