2009年10月3日 星期六

C++ 中 struct 與 class keywords 的差異

C++ 中允許使用者在宣告(declare)、定義(define)型別時,使用 struct, class 兩個不同的關鍵字(keyword)。由於兩種都可以,因此很容易讓人好奇兩者是否存在必要性的差異。

在宣告時,使用 struct 或 class 都可以告訴 compiler 這是一個新的自訂型別,但在定義(define)時則有差異,根據最新 C++ standard
的描述, class 和 struct 對於 class definition 的差別在於:
1. 對於 member 的 default access level 不同(std.11);
2. 對於 base class 的default access level 不同(std.11.2)。

其不同在於 struct 是寬鬆的,都以 public 為預設。

上面的敘述很簡單,會引發一些聯想、甚至遐想:

Q1: 所以也可以使用 struct 寫多重繼承?多形?實現建構/解構子概念? 或者實作interface?就算可以,那為何會有class的產生?它不正是為了延伸structure的概念,達到更方便的OOP設計嗎?class 跟 struct 是可以互相繼承的嗎?
A1: 是的,可以。

Q2: 如果 Q1 的程式存成 .c ,可以compile過嗎?
A2: 沒辦法,C 語言不支援

Q3: 剛提到的差異是 class definition 上的,至於其他地方有差異嗎?
A3: 有的,像是 template 的 parameter list 只允許 class, typename ,無法使用 struct,因為 template 的設計,一開始就沒有打算和 C 相容。

Q4: 扣除些微差異,class 和 struct 幾乎是一樣的東西,為什麼 C++ 會同時引入兩個 keywords 呢?
A3: C++ 原本叫做: C with Class 。它的重要理念之一是與 C 相容,不過確實也是有不相容的地方,C++ Standard 的附錄 C 就列舉了 C++ 與 C 不相容的部份。因此為了這相容性,不可能將 struct keyword 拿掉,引入 class 這個新的 keyword ,它所帶來的不只是 parser 要多 parse 一個字,更重要的是其背後的抽象性、封裝性以及滿足人們對於 OO 的期待心理。而且以 Google 上"C++ struct class?"的搜尋,會先冒出一堆兩者的差異、比較的網頁就知道,class 的確辦到了"混淆視聽"的效果 : )

Q5: 都聽你在講,有沒有權威一點的說法啊?
A5:  Stanley Lippman 的著作: Inside The C++ Object Model,裡頭有一個章節叫做:Keywords, Schmeewords;開頭就是這樣說的:

One answer to the question of when, if ever, you should use a struct declaration rather than a class declaration then, is whenever it makes one feel better.

是的,重點在於 struct, class 定義出的 attributes, member functions 是否能符合你的需求期望。兩者的差異在於主觀的感覺: struct 用在 data aggregation,class 用在 Object oriented 或 object based 上。

Q6: 那為什麼不在 C++ 內限制 struct 只能宣告一般 aggregation type,不能有 access level 、member function 等能力呢?
A6: 其實原因很簡單:只是為了 C 到 C++ 遷移順利。 C++ 草創之初,除了效能是個大家關注的議題之外,什麼時候使用 struct 取代 class 也是常被問起的問題,與其涇渭分明的兩套標準,不如以一貫之,Bjarnet Stroustup 在 The Design and Evolution of C++ 這樣講著:

Maybe we could have lived with two set of rules, but a single concept provides a smoother integration of features and simpler implementation.尤其重要的是,嚴格區分兩者可能使得社群分裂(原文: community would fall into two distinct camps that would soon stop communicating.)

ㄜ,除了上面講的顏色對不對外,你覺得下面的 code 該編譯過還是不過呢?
// Forward Declaration
struct MyClass;
// Definition
class MyClass {
...
};
這應該是一致性問題,還是我們得一定要 compiler 嚴守 langauage 規範,幫我們挑出來呢? (以上很哲學又考古! )

Q7: 那我可以說 struct 原本要被幹掉嗎?
A7: 不算是要被幹掉,因為一開始就打算與 C 相容,所以不會幹掉,考量是:
1. 要不要引入新的 keywrod -- class
2. 引入 class 後,是否要讓 struct 與 class 不相容,使用兩套 rules。
而後的決定是:引入 class ,class 和 struct 使用同一套 rules (只差別在 default accessibility),而事實也證明 class 帶來令人滿意的效果,不管是心理的、實務上的。心理的上的話,套句 Lippman 的話:你會講 base class 還是 base struct ,雖然只是小小的哲學問題,卻還是得到滿足。

Q8: 我搞混了,那到底什麼時候該用 struct 、什麼時候該用 class?
A8: 我想 C++ 期望使用者自決。但我想可以分成兩個層面來看。先說心理層面:這是個 makes one feel better 的問題。
xxx MyClass {
public:
    void func();
private:
    int val_;
};
xxx 是 class or struct 都好,因為實際描述 MyClass 行為的是 class body 中的程式碼,而不是 struct 或 class。
另一個層面則比較實務:我想要 struct 或 class 定義出來的型別,其所產生的 object 與 C 是真正相容的,那就得考慮到 C++ 的 object model 和相關運算,簡單來說:要在 C++ 產生跟 C 相容的 object ,你的 C++ 型別必須是個 POD (Plain Old Data),standard 對於 POD 有其定義(std.9),或是上 Google 搜尋都可以看到,偷偷引用 wiki 的描述:
A POD type is a C++ type that has an equivalent in C, and that uses the same rules as C uses for
1. initialization
2. copying
3. layout
4. addressing
對我自己來說,什麼時候會使用 struct:
1. 想產生與 C 相容的 object 時,我會使用 struct 這個關鍵字,因為它帶有我對 C 的遐想,然後嚴格遵守 standard 對 POD 的規範。
2. 某些型別描述的對象很簡單(不太有(甚至沒有)繼承架構、抽象介面、生命週期短等),使用 setter, getter 又很麻煩時,那我會選使用 struct ,像是:
struct ParserResult {
bool Match;
int lineNo;
};
每個人都可以有自己一套結論!

Q8: 我試過了你這篇文章上弔詭(Paradox)的code:
struct MyClass;
class MyClass {};
/*
*warning C4099: 'MyClass' : type name first seen using 'struct' now  seen using 'class'
*
*是的,可以通過編譯,但會出現如此警告。
*因此將class、struct調換過來如下:
*/
class MyClass {};
struct MyClass;
/*
*錯誤訊息如下:
*warning C4099: 'MyClass' : type name first seen using 'class' now  seen using 'struct'
*/
A8: 揪甘心,這就是答案。記住:你的血統(class, struct)不代表什麼,重要的是你的所作所為(class body)

2009年9月18日 星期五

Porting AAC Decoder - 皓鈞

2009.09.18 - Progress update

‧改完第20個動態宣告,這一部分到目前先告一個段落。

[繼續閱讀]

2009年9月17日 星期四

Cyber Simulation - 宗胤

--- [09.09.16] ------------------------------------------------

目前完成的部份是可以將一個簡單的加減法電路掛到CDK板子的FPGA上,並且可透過ICE Server讓Host (PC)存取這個加減法電路,也可讓CDK上的Linux透過Driver使一隻User Space的程式可以存取這個電路。

CDK上的FPGA是透過AHB或APB與其他的硬體作溝通,因此要在FPGA上實作電路必須要實做與AHB或APB溝通的interface,這個interface我是直接使用CDK所給的範例裡的,我只修改最底層的電路。

另外,照CDK的規格書所述,基本上我們可以在fpga上實作兩個Slave掛在AHB下,而Bus上的Memory Map是已經給定好的:

  1. Slave1是Map在0x1CB20000,大小為2MB
  2. Slave2是Map在0x1CD20000,大小為2MB

CDK Memory Map

因此我透過範例的interface將電路實作在Slave1裡,讓其他硬體可透過0x1CB20000這個位址與其作溝通。

RVDB

上面是利用ICE Server讓Host在CDK上跑一隻簡單的程式,其中紅框中的slavebase即是儲存0x1CB20000,然後就透過存取slavebase直接與FPGA的電路溝通。藍框中是執行的結果。

CDK

而上圖則是先在CDK上boot Linux後,利用我寫的簡單driver (calculate.ko)來讓armtest這隻程式可以輸入2個數值給電路來做相加和相減。基本上armteset是透過ioctl這個function來與硬體做溝通,程式碼如下,將Device打開就利用driver事先定義好的command發命令至driver,driver再根據command控制加減法電路。

armtest c

再來應該是要做關於driver codegen的部份,但要寫codegen的話勢必要有一定程度至瞭解Linux driver,所以我想我應該要找個driver trace。

2009年9月15日 星期二

有關Group Meeting

2009, 9/15

DNA : 新的時間表 嘎喔

時間: 星期四下午2:00

地點: 未定 (暫定4282)

報告順序:

日期

報告成員

9/24

阿凡、小聽

10/1

皓鈞(補)、宗胤(補)

10/8

仕偉、品皓、大鈞

10/15

胤霖、宗胤、小明

10/22

嚕嚕、塞公、偉翔

10/29

小龍、雙魚、皓鈞

11/5

阿凡、小聽

11/12

仕偉、品皓、大鈞

11/19

胤霖、宗胤、小明

11/26

嚕嚕、塞公、偉翔

12/3

小龍、雙魚、皓鈞

12/10

阿凡、小聽

12/24

仕偉、品皓、大鈞

12/31

胤霖、宗胤、小明

1/7

嚕嚕、塞公、偉翔

1/14

小龍、雙魚、皓鈞

1/21

阿凡、小聽

1/28

仕偉、品皓、大鈞

2/4

胤霖、宗胤、小明

2/11

嚕嚕、塞公、偉翔

------------------------------------------------------------------

2009, 9/15

新的Group Meeting時間為每星期四下午兩點.

請DNA重新排報告的同學的時間表

------------------------------------------------------------------

2009,9/9

開學後的Group meeting請重新調查時間. 我的上課時間是:

(三)6~8. RM4261. 研究所的Multicore的課.

(四)2~4. RM4263. 大學部的System Level Programming

請大家上來說一下自己的上課時段, 請DNA排出時間並借教室.

至於Meeting的內容還是以報Paper為主, 每次三位同學比較好, 否則兩個月才會輪一次, 有點久.

Meeting的另一個目的本來是報告進度, 不過我覺得大家也許感到還沒做到一個地步就報告會不知道報什麼. 所以就改成你做到可以初步展示時再上來就好. 但是我又不希望隔太久, 所以強制一下, 一個月來展示一次. 但是我請大家自動自發, 每個禮拜在你的工作串上發表進度. 發表內容希望言之有物, 讓人知道你在做什麼. 也就是要交代前因與結果.

並且, "把串提到上面來, 並註明更新日期"

明年想畢業的同學, 固定兩星期上來展示一下你的成果. 所謂展示, 不是口頭報告, 要有Demo才行.

另外, 等穩定後, 約在十月中, 如我所說我會再找時間, 由我或博士班的學長幫碩一同學上一些課. 並且定一下個別meeting的時間與方式.



-----------------------------------------------------------------

4285被張大偉老師借去,奇怪的是他們每週二都註明是training course,晚點去系辦反應完看看能不能換,我們人數較多要借較大的教室。



時間: 早上10點

地點: 未定

報告順序:

日期

報告成員

8/11

品皓、仕偉

8/18

胤霖、大鈞

8/25

小明、宗胤

9/1

塞公、嚕嚕

9/8

偉祥、皓鈞

9/15

小龍、雙魚

9/22

阿凡、小聽

9/29

10/6

品皓、仕偉

10/13

胤霖、大鈞

10/20

小明、宗胤

10/27

塞公、嚕嚕

11/3

偉祥、皓鈞

11/10

小龍、雙魚

11/17

阿凡、小聽

11/24

進度報告: 每兩週一次

其他注意事項:

  1. 論文不知道要報什麼的請找你的Mentor或找老師。
  2. 下週三(8/12)早上10點大掃除!

演講:探索嵌入式 ARM 平台與 SoC -- Part I + Part II

演講:探索嵌入式 ARM 平台與 SoC -- Part I + Part I

推薦一下這個演講,講師是鼎港有名聲,下港尚出名ㄟ黃敬群(Jserv)
有在做ESL/ARM相關的人或有興趣的人可以去聽一下
看真實的系統長什麼樣,以軟體的角度是怎樣看待ARM/SoC System
業界又是如何來設計及使用ARM/SoC System
我相信Jserv可以提供許多寶貴的意見
詳細的時間地點,請參照連結內容

閒閒沒事做的,也可以去看一下本系有史以來最強的學長本尊
在現場你一定可以感受到他的無邊法力 XD

2009年9月13日 星期日

Vertical Bit Map Coding

[2009-09-20]

Bad news. I have found one bug in my Matlab code. The bitrate counter have been implemented in a wrong way so that the bitrate have been overcounted. The bitstream of 32kbps is actually the bitstream of 64kbps. Therefore, the coding efficiency shall be further underestimated.

=====================================================

A. Introduction
For recording my research in audio bit plane coding technique, here I demonstrate a series of decoded results produced by a fine-grain-scalable lossy-to-lossless audio coder. The key idea is quite simple but effective. From my doctoral study, I learned the significant map (the most significant bits of all coefficient to be encoded) plays a critical role in both coding efficiency and audio quality. If I can use as less bits as possible to encode the significant map, then the decoded quality will be as good as possible even in a very low bitrate. Unlike the scalable audio coder, Harmonic Quad Tree coding (HQT), in my doctoral thesis, this coder explores the relationship between the most significant bits of two adjacent frequency coefficients, not harmonic relationships among frequency coefficients. In addition, the bit plane coding technique, Set Partitioning In Hierarchical Trees (SPIHT), is absent in the new coder. I would like to named this coder as Vertical Bit Map coding (VBM) at this moment.

B. Experiment
The chosen test audio piece is from "castant" which is a famous test material for audio compression. Due to its rich and fast claps, the audio artifact so called "pre-echo" can be easily perceived after lossy compressed.

The following two examples show an interesting function I called it variable bitrate playback. To make you quickly understand this function, I decoded the bitstreams according a series of specified varying bitrates frame by frame and drawn their spectrum. The figures have the original spectrum in the top, the decoded spectrum in the middle, and the specified varying decoding bitrate of each frame in the bottom.

The first experiment is set the varying bitrate from 16kbps to 64kbps in a step size of 2kbits.


The second experiment is set the varying bitrate from 32kbps to 64kbps in a step unit of 1kbits.
The audio qualities are very defective because these two experiments are extraordinary only for demonstration. In an usual scenario, the varying decoding bitrate is expected to change in a smooth way. For keeping acceptable audio quality, the decoding bitrate would not be allowed to adjust so frequently and amplify so large range in a short time.

There are also some comparsions with other scalable audio coders. They can be downloaded from Result Comparsion, all 44.1KHz, 16-bit, mono.

The file list describes briefly here,
cast_ori.wav – castant original wave file
cast_rec_(16_64_2kbps).wav – the first experiment
cast_rec_(32_64_1kbps).wav – the second experiment
cast_rec_(16kbps).wav – 16kbps fixed rate VBM version
cast_rec_(32kbps).wav – 32kbps fixed rate VBM version
cast_rec_(64kbps).wav – 64kbps fixed rate VBM version
cast32_bsac.wav – 32kbps fixed rate MPEG4 BSAC version
cast32_sac.wav – 32kbps fixed rate Scala SAC version
cast32_hqt.wav – 32kbps fixed rate HQT version
cast32_eac.wav – 32kbps fixed rate Mircosoft EAC version

C. Summary
As a conclusion and a reminder for myself, this VBM coder is an experiment of my speculation in the importance of significat map in audio coding. This VBM audio coder can be categorized as:
1. Fine-scalability: scalable grain is downto 1 bit,
2. Lossy-to-lossless: the embedded bitstream contains all possible playback bitrates, even the archive,
3. Low complexity: there are very few prediction calculations and history storages in analyzing and reconstucting the significant map. Therefore it can be claimed that complexity is equivalent and low in both encoding and decoding,

and has the following features:
1. Encode once, decode many time: the basic goal VBM tries to achieve,
2. Variable bitrate playback: by indicating the decoding bitrate of every frame, decoder can achieve variable bitrate playback in frame scale,
3. Real-time encoding and decoding.

It is noted that the VBM coder has NO
1. Psychoaoustic model: there is no perceptual controlling in the current implement,
2. Window switch: there is no attack detection to control long/short window switch. Yes, there is one single frame size.

2009年9月4日 星期五

DAFx @ Italy

I’ve just finished my poster presentation at the vanue. There were so many interesting guys coming with many interesting thoughts. I prepared my business cards and the papers which were proposed by 義崧 and 維城 for the audiences who need.

Because our paper includes the fields such as pitch detection, partials tracking, score alignment, and also synthesis, there are many people coming to ask me some questions. The most popular question is the octave note (or overtone) of the multiple pitch detecion. The tracking algorithm is also the well-liked topic.

I also got the name card from Keita (the supervisor of Center for Advanced Sound Technologies in YAMAHA Corp.) and Juhan Nam (Ph.D candidate in CCRAM). There are also some guys coming from IRCAM and even know 維城.

Finally, Perry Cook is a really interesting guy who may give you a whistle whenever your demostration is impressive !

2009年9月3日 星期四

GTKWave and VCD - 哲榮

2009/9/3
已經把OpenESL的GEF部分加好GtkWave了
選擇port是否要trace 只要點選connection
然後在屬性欄位更改Trace的選項(From_port_trace ,To_port_trace)
Trace的選項是一個下拉式選單,有兩個選項: Traced , Not Traced
如下圖:
























多加了一個按鈕來啟動GtkWave:









按下按鈕後:





















2009/8/30
GtkWave目前已經整進command line的部份
剩下GEF這邊目前打算在connection裡面多加個兩個屬性
TraceSrc
TraceDes
可是還有遇到connection無法連接的問題 還要再問一下學長

2009/6/1一
更新指令
tr [MODULE's NAME].[PORT_NAME] :追蹤指定的port
detr [MODULE's NAME].[PORT_NAME] : 刪除已追蹤的port

list顯示trace變更成顯示link的兩個port之追蹤狀態

















儲存trace資訊的xml改為只儲存要追蹤的port









追蹤變數的進度目前還沒弄好
ModelSim跟esl之間的連結 目前有電機系學長的資料
大致上已經知道SystemC跟verilog怎麼互通 但是還沒有實際測過



2009/5/1五
OpenESL加入gtkwave大致上已經弄好了

我多加了三個指令
trln [link_num] : 追蹤指定的link
detr [link_num] : 把已設為追蹤的link 改成不要追蹤
vcd : 把產生的vcd檔案用gtkwave打開

儲存link是否要追蹤的xml跟儲存project的xml分開 其格式如下










在輸入指令list會多顯示link是否要追蹤


















vcd指令開啟vcdfile




















2009/3/24二
1.
關於上周的[法三]
只要把它看作是普通的傳pointer進去建構子就可以了,不需要繼承 fp()
[法三]在main裡面產生vcd file 將此file pointer傳到module中 :
int sc_main(int argc, char* argv[])
{
sc_trace_file *fp;
fp=sc_create_vcd_trace_file("wave");

// Instantiate DUT, pass on filepointer during dff instantiation
dff DUT("dff",fp);

sc_close_vcd_trace_file(fp);
}

SC_MODULE(dff) {
sc_in clk;
sc_out dout;

dff(sc_module_name _n, sc_trace_file* fp) : sc_module(_n){

sc_trace(fp,clk,"clk");
sc_trace(fp,dout,"dout");
}
};

2.
我後來發現說sc_trace();也可以用來trace一般的變數 比如說:int bool sc_int...
而且sc_trace() 必須在模擬之前就預先給定要追蹤的變數 也就是在sc_start()之前就要先設定好
所以我目前想使用以下方法來追蹤 interface裡的傳遞資料的變數

對於每一個在interface裡面想要追蹤的變數
我都新增一個共用變數 然後在每個interface的function裡面把想追蹤的變數assign給對應的共用變數
這樣我就可以只追蹤共用變數的變動狀況 也就可以在sc_start()之前先設定好要追蹤的變數

例如:
global.h :
extern sc_int<8> t_data; //每個module 包括main都可以看到的變數

global.cpp :
sc_int<8> t_data;

main.cpp :
int sc_main(int argc, char* argv[])
{
sc_trace_file *fp;
fp=sc_create_vcd_trace_file("wave");

sc_trace(fp,t_data,"t_data");
...............

sc_start();
sc_close_vcd_trace_file(fp);
}

bus.cpp :
........
//bus的interface function
void test_bus::write(unsigned addr, sc_int<8> *data,unsigned int priority)
{
t_data = data->to_int();
..............
}
........

小弟愚昧,目前只想到這樣作,之後再看看有沒有更聰明的方法XD



2009/3/17 二
有找到關於systemc dump vcd的資料了

以下是範例

[法一]在sc_main()裡面直接抓sc_signal :
int sc_main(int argc, char* argv[])
{
// signal declaration
sc_clock clk("clk", 1, SC_SEC, 0.5);
sc_signal ss;
sc_signal mm;
sc_signal hh;

// module declaration

// signal connection

//file trace
sc_trace_file *tf;
tf = sc_create_vcd_trace_file("trace");
sc_trace(tf,ss,"second");
sc_trace(tf,mm,"minute");
sc_trace(tf,hh,"hour");

// run simulation
sc_start(3700, SC_SEC);
sc_close_vcd_trace_file(tf);

return 0;
}


[法二]在各module中 :
SC_MODULE(dff) {
sc_in
clk;
sc_out
dout;

// Declare Local VCD filepointer
sc_trace_file *fp;

// Constructor
SC_CTOR(dff) {

fp=sc_create_vcd_trace_file("wave");

sc_trace(fp,clk,"dff.clk");
sc_trace(fp,dout,"dff.dout");
}

~dff() {
sc_close_vcd_trace_file(fp);
}
};

[法三]在main裡面產生vcd file 將此file pointer傳到module中 :
(可是這個我測了似乎不行,還要在看一下哪邊用錯)
int sc_main(int argc, char* argv[])
{
sc_trace_file *fp;
fp=sc_create_vcd_trace_file("wave");

// Instantiate DUT, pass on filepointer during dff instantiation
dff DUT("dff",fp);

sc_close_vcd_trace_file(fp);
}

SC_MODULE(dff) {
sc_in clk;
sc_out dout;

sc_trace_file *fp;

dff(sc_module_name _n, sc_trace_file* _fp) : sc_module(_n), fp(_fp) {

sc_trace(fp,clk,"clk");
sc_trace(fp,dout,"dout");
}
};

粉紅色的部分就是dump vcd file的方法
可是以上只能trace sc_in<> , sc_out<> , sc_signal<>的資料
如果是使用interface的 sc_port<> 我還要找看看有沒有可用的函式



2009/3/14 六
之前一直沒有PO進度,是因為IEEE的資料要付費 我抓不下來
後來才知道用學校當代理伺服器就可以抓了!!

1. GTKWave :

GTKWave 是一個用來檢測說模擬的output 有沒有錯誤的 digital waveform viewer
它可以讀取VCD的檔案 我先做windows的版本

他的網頁在此
http://gtkwave.sourceforge.net/

win32版程式取得
http://www.dspia.com/gtkwave.html

把執行檔和dll檔抓下來後 放在同一個資料夾就可以了

執行方式:
命令提示字元 移到目的資料夾 輸入 gtkwave yourfile.vcd
即可顯示yourfile.vcd的波形圖

2. Value Change Dump (VCD)

contains information about value changes on selected variables in the
design stored by value change dump system tasks

它是verilog跑完模擬之後,用來記錄每個variables數值變化的一種格式



VCD有兩種type
a) Four state: to represent variable changes in 0, 1, x, and z with no strength information.
b) Extended: to represent variable changes in all states and strength information.

如果要用VCD來記錄Open ESL的訊號值 應該是要用Extended

關於VCD詳細的資料要到IEEE官網下載PDF,目前我還在看

VCD的詳細資料載點:
http://ieeexplore.ieee.org/xpl/standardstoc.jsp?isnumber=20656&isYear=2001

2009年8月31日 星期一

禮拜二打羽球

禮拜二打羽球, 下午四點, 中愛羽球館
沒球拍, 小新跟巴菲特會借你

HDL Simulator with ESL Platform - 哲榮

----------------------------
2009 . 8 . 30
----------------------------
之前試著把這整個放入到SystemC library提供的simplebus範例裡面
master用nonblocking的方式傳data給負責跟ModelSim溝通的module
可以正常跑

現在要把它放入宗胤學長寫得TLM2.0.1 SimpleMultiCoreBus
然後作個跑DCT的範例
目前還在看TLM2.0.1的傳輸


----------------------------
2009 . 8 . 18
----------------------------
因為先前的架構在client端必須等待pipe傳輸完畢後才繼續動作 擔心會影響模擬的速度
所以就想說在client端多一條thread來跑pipe,然後把SystemC module想丟的資料暫存到linking list
之後thread在逐一從linking list上讀取並用pipe傳送

Server端也一樣用一條thread跑pipe,把收到資料先暫存到linking list上,然後module需要資料時再自行讀取

但是老師提到說,由於SystemC 的kernel沒有multithread,所以這樣可能還是會影響模擬速度

我目前還感覺不太出來速度上有沒有比較快,可是改成這樣之後有個優點是
ModelSim的module收到的每一筆data,間隔的時間比較短,都可以控制在下一個clock就能收到下一筆資料,因為data都暫存在linking list上,所以只要pipe收的速度夠快,每筆data進入verilog module的時間就可以控制為每個clock都收到一筆data

原先的架構 - verilog module收到的每筆資料時間間隔比較大 :
















目前的架構 - verliog module能在每一個clock收到一筆:


















----------------------------
2009 . 8 . 14
----------------------------
上次那個波形圖只有收到0和11的值,其實是因為我直接按Zoom full
然後中間那些值都疊在一起看起來像沒有值.........抱歉是我呆了........

原圖一直Zoom in後就可以看到那些值了:















後來才發現說只會掉一兩個值,然後原因是我pipe部份的bug,當client偵測到server正在忙碌或尚未有server在等待client時,整個client pipe要關掉重連,不然會有錯誤

SystemC module裡面要確定上一筆資料送出後才送下一筆,不然還是會有data沒收到的情形
這邊我寫成在Server收到資料後就先把pipe鎖起來,等到module送出data後,再將pipe解開

目前已經可以正常傳資料並顯示波形圖

----------------------------
2009 . 8 . 11
----------------------------
為了要測試OpenESL和ModelSim之間的連接 , 做了以下的測試
在ModelSim裡面跑一個SystemC module與Verilog module的System(簡稱MS_system)
MS_system沿用7.17號的架構,並在main_sysc.cpp裡面加入 win32的 thread來執行pipe,
以便於跟另外一個SystemC module組成的系統(簡稱SysC_system)溝通

大致上整個的架構圖如下:











我原先是希望SysC_system裡的fsm module一直丟int的data給SysC_to_MS module
然後SysC_to_MS module透過pipe將data送給MS_system , 並由MS_system的main_sysc.cpp接收

PIPE分成Server端和Client端 , 這邊我把SysC_system裡的SysC_to_MS module視為Client端
MS_system裡的main_sysc.cpp視為Server端

Server端寫在thread中 , 一直block住等待Client端的連接 , 一旦有Client連接上 , 並立即接收資料
然後將接收的資料丟給load.v

Client端原本我是寫成當有資料要傳遞時 , 就產生一個thread來傳資料 , 傳完後此thread就關閉
然後因為怕說會有因為等待Server接收的時間 , 造成傳送的順序打亂的情形 , 我加入了Semaphore在 Client端控制 , 但是順序一樣還是亂的 , 後來發現說Semaphore只能確保一次只有一個thread進行傳送 , 不能確保thread的傳送順序
所以後來就把thread和Semaphore拿掉,變成Client端的整個系統要等待PIPE傳輸完資料後才繼續執行

PIPE目前我寫成一次只傳一筆的資料 , 目前只是測試 , 之後如果有影響執行速度的話會在改成
累積多筆data再一起傳送

[目前遇到的問題是]
MS_system裡負責跑PIPE Server的thread能夠正常的接收到Client傳送的資料
我是寫成當Server接收到一筆資料就立刻丟給跟load.v相連的port
然後load.v在clk的posedge時接收 , 進行處理後在丟給接下去的module
但是波形圖跑出來卻實際上在MS_system裡面傳送的只有部份的data

也就是說 Server接收到每一筆資料 , 並丟給verilog module 但是verilog module卻沒有接收到完整的資料

如下圖:

跑PIPE的thread確實接收到每一筆資料 1~11

















波形圖跑出來卻只有收到兩個 0和11
















我猜測 應該是Server傳送給load.v的速度太快 導致它來不存取
我有試著用Sleep去卡Client端的傳送速度 發現說有比較改善 load.v有收到較多的資料

所以可能會看看加入一個port來判斷說load.v確實接收到Server的資料後才允許Server繼續丟下一筆來自client的資料


----------------------------
2009 . 7 . 17
----------------------------
補充一下測試的方式
連接的架構如下:









cclk使用SystemC產生的clock
main_sysc.cpp用finite state machine不斷的把值從aadder送出去
然後load.v單純接收 再丟給decrease.v
decrease.v接收到資料後 把值減1 將結果存在 dec

跑出來的波形圖如下:





















找到 modelsim 6.3 g
modelsim裡面使用的gcc compiler版本 : modelsim-gcc-3.3.1-mingw32.zip
(安裝方法:直接解壓縮把資料夾丟入modelsim的安裝路徑即可)

單純測試在modelsim中連接verilog module和SystemC module
可以成功跑出模擬