Sunday, July 4, 2010

中国高速铁路

CRH:中国高速铁路,英文全称(CHINA RAILWAY HIGH-SPEED)目前已知有CRH1,CRH2,CRH3,CRH5。据称,由于中国人忌讳“4”谐音“死”故没有CRH4的型号。


CRH2和CRH5具备提速至300KM/H的条件。

CRH1庞巴迪-四方-鲍尔(BSP)生产,原型是庞巴迪为瑞典AB提供的Regina。200公里级别(营运速度200KM/h,最高速度250KM/h)。
编组型式:8辆编组,可两编组连挂运行动力配置:2(2M+1T)+(1M+1T)车种:一等车、二等车、酒吧坐车合造车定员(人):670

客室布置:一等车2+2、二等车2+3

最高运营速度(km/h):200
中间车辆长度(mm):26600

车辆宽度(mm):3328

车辆高度(mm):4040
牵引电动机:265kW
CRH1共有三个派生车型,它们分别是CRH1A、CRH1B和CRH1E。

CRH2
南车四方(联合日本川崎)生产。
是以日本新干线的E2-1000型电动车组为基础,是继台湾高铁的700T型电联车后,第二款出口国外的新干线列车。供中国使用的CRH2型虽使用与E2-1000相同的电动机,由于其编组方式是4节动车配4节拖车,动力比日本的6M2T编组E2系小,因此在营运速度方面会比日本本土的E2系有所下调,最高营运时速为200公里。
CRH2系列有4个派生车型,它们分别是CRH2A、CRH2B、CRH2C和CRH2E。
编组型式:8辆编组,可两编组连挂运行(重联运行)
CRH2型电动车组,全部为8节或16节编组,动力分配形式各不相同;2A为4M+4T,2B为8M+8T,2C为6M+2T,2E为8M+8T。


车种:一等座车、二等座车、二等座车餐车。

车辆宽度(mm):3380

车辆高度(mm):3700

CRH3
北车唐山机车厂(联合西门子)生产,原型ICE3。编组形式为,8M0T。轴功率550kW,全车共16根动轴,平均分布于8辆车上,每车两台转向架,每台转向架均有一根动轴。
动力配置:全部为8节或16节编组,动力分配形式各不相同;3A/3C为4M+4T,3D目前暂不清楚。

车种:一等座车、二等座车、二等座车餐车

定员:601人
车辆宽度(mm):3265

车辆高度(mm):3890

CRH5
 北车长春客车厂(联合阿尔斯通)生产,原型阿尔斯通为芬兰国铁提供的SM3型。200公里级别(营运速度200KM/h,最高速度250KM/h)。
在CRH5中,CRH5-001A为原装进口车,CRH5-004A为散件组装车,CRH5-010A/011A/012A为采用部分进口部件的国产车。

编组型式:全部为8辆编组,可两编组连挂运行动力配置:(3M+1T)+(2M+2T)车种:一等车、二等车、酒吧坐车合造车定员(人):602+2(残疾人)客室布置:一等车2+2、二等车2+3

最高运营速度(km/h):200(具备提速到300km/h的条件)最高试验速度(km/h):250
车辆宽度(mm):3200
车辆高度(mm):4270


中国高铁建设规划
四纵:
北京-上海:全长1318公里,纵贯京津沪和冀鲁皖苏四省,连接环渤海 和长江三角洲两大经济区 。
北京-武汉-广州-深圳:全长约2260公里,连接华北和华南地区。武 汉至广州段全长995公里,2005年6月开工 。
北京-沈阳-哈尔滨(大连):全长约1700公里,连接东北和关内地区 。秦皇岛至沈阳段400 公里已于2003年建成 。
杭州-宁波-福州-深圳:全长约1600公里,连接长江、珠江三角洲 和东南沿海地区。

四横:
徐州-郑州-兰州:全长约1400公里,连接西北和华东地 区。已开工建设郑州至西安段455公里 。
杭州-南昌-长沙:全长约880公里,连接华中和华东地 区 。
青岛-石家庄-太原:全长约770公里,连接华北和华东 地区。已开工建设建设石家庄至太原段205公里。
宁汉蓉(南京-武汉-重庆-成都):全长约1600公里, 连接西南和华东地区。已开工建设南京至合肥段、武汉至 合肥段、宜万段、成遂渝段

Saturday, July 3, 2010

地铁系统

地铁和轻轨
为了增强轨道的稳定性,减少养护和维修的工作量,增大回流断面和减少杂散电流,地铁和轻轨都选用轨距为1435毫米的国际标准双轨作为列车轨道,与国铁列车选用的轨道规格相同,并没有所谓的钢轨重量轻重之分。
划分两者区别的依据是所选用列车的规格。按照国际标准,城市轨道交通列车可分为A、B、C三种型号,分别对应3米、2.8米、2.6米的列车宽度。凡是选用A型或B型列车的轨道交通线路称为地铁,采用5~8节编组列车;选用C型列车的轨道交通线路称为轻轨(上海轨道交通8号线除外),采用2~4节编组列车,列车的车型和编组决定了车轴重量和站台长度。在我国的规范中是指,轴重相对较轻,单方向输送能力在1万~3万人次的轨道交通系统,称为轻轨;每小时客运量3万~8万人次的轨道交通系统,称为地铁。

通常一个轨道交通网络,由三个等级的线网有机组合而成:区域快线系统(R线)、城区干线系统(M线)和辅助联络系统(L线)。区域快线系统,类似于美国的通勤铁路和日本的JR通勤铁路,起终点通常在郊县,有的经过主城区,有的不经过主城区。城区干线系统,则是主要为主城区交通服务的,起终点通常在城市建成区的边缘或城市外围城镇组团中。辅助联络系统,顾名思义,就是在整个线网中起到辅助和沟通作用的线路,他们通常采用比M线稍低一些的制式,运能相对也较小。
R线追求的是高速,因此站间距大,对列车速度的要求高,通常采用电力机车,而M线追求的是便捷,因此站间距比较小,对列车运行速度的要求不高,通常采用城轨车辆。
容量(车型)
地铁通常采用A型车和B型车,这两种车的区别在于几何尺寸和载客量。A型车通常长22米,宽3米(当然也有南京地铁使用的3.2米宽体A车),B型车通常长19米,宽2.8米,因此同样节数的一列列车,使用A车的载客量要大于B车。例如,6节编组A车的额定载客量可以达到1830人,而B车就只有1440人。
编组
以无锡轨道交通1号线为例。客流预测远期高峰小时单向客流量为31300人次,也就是说高峰小时在同一方向上,最大通过的客流量有31300人次之多。地铁设计规范规定,新建地铁的服务水平不得低于每小时开行30对的指标,也就是说,每个小时在同一方向上至少要发30班列车。一列4B,5B,6B列车的载客量分别为950人、1195人、1440人。用31300分别除以这三个数字,得到32.94、26.19和21.73。可以看出,如果采用4B编组,则必须每小时开行33对才能达到客流需要,也就是说系统长期将处在高强度满负荷状态,这显然是极其不利于安全的,因此4节B车编组无法满足无锡1号线的需要。而如果采用6B编组,则每小时只需要开行22对,相比较起来,发车间隔要比采用5B编组来的大,这也有些不利于提高服务水平。所以,初步看来选取5B是合适的。进一步验算,采用5B编组,假设每小时开行30对,则一小时单向可以输送35850人次,将它除以31300,得到1.145,意味着运能储备达到14.5%。
轨道交通列车通常只采用偶数节编组,比如2节,4节,6节,8节,很少有采用奇数节的(请注意是很少有,而不是没有,例如高雄地铁初期采用3节A车编组)。
众所周知,地铁列车分为动车和拖车,一节带受电弓或者受流器的动车和一节带空气压缩机的动车为一个单元,再加上一头一尾两节拖车,这就是为什么绝大多数城市的快轨列车编组都是偶数节的道理。我国通常用A代表拖车,用B代表带受电弓或授流器的动车,用C代表只带空气压缩机的动车。因此上海地铁1号线的6编,就是4动2拖A-B-C-B-C-A,8编就是6动2拖A-B-C-B-C-B-C-A。偶数节的好处,简直不言而喻。例如调配组合方便,购车方便,动力均衡,不同线路的车辆互换性好,可以增加系统运营的稳定性和可靠性,降低成本等等。
奇数节就不同的,如果是5编,按照无锡这次上报的方案,就是3动2拖A-B-C-B-A。这将会带来几个比较显著的问题:首先,动车不成单元,先是给购车带来了不便,带受电弓的动车数是带空气压缩机的动车数的一倍,无形中又增加了以后调配的难度和维护的成本。其次,动力不均衡,牵引和辅助系统的配备有区别。采用偶数节编组,例如6节,只需要配置2个辅助系统,而采用5节可能就要配置更多的辅助系统,无论是造价还是运营成本都显然是后者大于前者。可能这也就是为什么鲜有城市采用奇数节编组的道理。
动力
电气化铁路常用的两种供电网络方式包括接触网供电和第三轨供电。第三轨供电的概念就是在列车行走的两条路轨以外,再加上带电的钢轨。这条带电钢轨通常设于两轨之间或其中一轨的外侧。电动列车的集电装置在带电路轨上接触并滑行,把电力传到列车上。这种集电装置在英语称为 shoe,中译为集电靴(取流靴)。第三轨安装在轨道梁上,电动车辆取流靴与第三轨接触面大且对其磨损极小。采用第三轨式接触网的优点是工程易于安装,检修方便、维护简单,寿命长。从技术角度来讲,由于集电靴在高速之下难以准确地抓紧带电轨,故采用第三轨供电的线路速度不能太高。理论上来讲,采用轨道供电系统的列车的时速上限是 160 公里。另外,第三轨有触电的风险,只能用于封闭线路,因此不适用于以地面线路为主的铁路运输系统中。另一方面,地面重型铁路系统为了高速客运和货运重载的需要,会使用更高的电压,如25千伏的供电系统,这也是第三轨系统所不能承受的。

在铁路和城市轨道交通系统中,架空接触网只有导线的一个电极,电力机车通过集电弓取电,再通过金属轮轨回流到电网中。在无轨电车等使用胶轮的系统中,架空接触网有两根互不接触的两根接触导线(简称触线),通过两个集电杆取电。架空接触网的悬挂类型大致为三种:简单悬挂,链式悬挂,刚性悬挂。刚性悬挂是以硬质的金属条(通常是铜条)代替软质的导线的新型悬挂方式。刚性悬挂使用集电弓,没有使用集电靴的第三轨容易脱落的缺点,可以达到更高的运行速度。

Monday, June 28, 2010

video demystified(summary on mpeg2/mpeg4/h264)

  • MPEG-2
MPEG-2 uses the YCbCr color space, supporting 4:2:0, 4:2:2 and 4:4:4 sampling. The 4:2:2 and 4:4:4 sampling options increase the chroma resolution over 4:2:0, resulting in better picture quality.

There are three types of coded pictures.
I (intra) pictures are fields or frames coded as a
stand-alone still image.
P (predicted) pictures are fields or frames coded relative to the nearest previous I or P picture, resulting in forward prediction pro-cessing. B (bidirectional) pictures are fields or frames that use the closest past and future I or P picture as a reference, resulting in bidirectional prediction

A group of pictures (GOP) is a series of one or more coded pictures intended to assist in random accessing and editing. The GOP value is configurable during the encoding process. The smaller the GOP value, the better the response to movement (since the I pictures are closer together), but the lower the compression. In the coded bitstream, a GOP must start with an I picture and may be followed by any number of I, P, or B pictures in any order. In display order, a GOP must start with an I or B picture and end with an I or P picture.

An open GOP, identified by the broken_link flag, indicates that the first B pictures (if any) immediately following the first I picture after the GOP header may not be decoded correctly (and thus not be displayed) since the reference picture used for prediction is not available due to editing.



Macroblocks
Three types of macroblocks are available in MPEG-2.
The 4:2:0 macroblock consists of four Y blocks, one Cb block, and one Cr block.
The 4:2:2 macroblock consists of four Y blocks, two Cb blocks, and two Cr blocks.
The 4:4:4 macroblock consists of four Y blocks, four Cb blocks, and four Cr blocks.

Macroblocks in P pictures are coded using the closest previous I or P picture as a reference, resulting in two possible codings:
 - intra coding no motion compensation
 - forward prediction closest previous I or P picture is the reference
Macroblocks in B pictures are coded using the closest previous and/or future I or P picture as a reference, resulting in four possible codings:
 - intra coding: no motion compensation
 - forward prediction: closest previous I or P picture is the reference
 - backward prediction: closest future I or P picture is the reference
 - bi-directional prediction: two pictures used as the reference:
 - the closest previous I or P picture and
 - the closest future I or P picture

Block size: 8x8 for MPEG2

Video Bitstream
a hierarchical structure with seven layers.
From top to bottom the layers are:
 - Video Sequence
 - Sequence Header
 - Group of Pictures (GOP)
 - Picture
 - Slice
 - Macroblock (MB)
 - Block

Sequence Header
A sequence header should occur about every one-half second.
 - Sequence_header_code
 - Horizontal_size_value
 - Vertical_size_value
 - Aspect_ratio_information
 - Frame_rate_code
 - Bit_rate_value
 - Vbv_buffer_size_value
 - Constrained_parameters_flag
 - Load_intra_quantizer_matrix
 - Intra_quantizer_matrix
 - Load_non_intra_quantizer_matrix
 - Non_intra_quantizer_matrix
 - Sequence Extension
 - Extension_start_code
 - User Data
   --- User_data_start_code
   --- User Data

Data for each group of pictures consists of a GOP header followed by picture data. A GOP header should occur about every two seconds.
Data for each picture consists of a picture header followed by slice data. If a sequence extension is present, each picture header is followed by a picture coding extension.
Data for each picture consists of a picture header followed by slice data.
Data for each slice layer consists of a slice header followed by macroblock data.
Data for each macroblock layer consists of a macroblock header followed by motion vector and block data
Data for each block layer consists of coefficient data.


The program stream, used by the DVD and SVCD standards, is designed for use in relatively error-free environments. It consists of one or more PES packets multiplexed together and coded with data that allows them to be decoded in synchronization. Program stream packets may be of variable and relatively great length.

Data for each pack consists of a pack header followed by an optional system header and one or more PES packets.
The program stream map (PSM) provides a description of the bitstreams in the program stream, and their relationship to one another. It is present as PES packet data if stream_ID = program stream map.

A transport stream combines one or more programs, with one or more independent time bases, into a single stream. Each program in a transport stream may have its own time base. The time bases of different programs within a transport stream may be different.
The transport stream consists of one or more 188-byte packets. The data for each packet is from PES packets, PSI (Program Specific Information) sections, stuffing bytes, or private data.
At the start of each packet is a Packet IDentifier (PID) that enables the decoder to determine what to do with the packet.
Data for each packet consists of a packet header followed by an optional adaptation field and/or one or more data packets.


  • MPEG-4
MPEG-4 visual is divided into two sections.
MPEG-4 Part 2 includes the original MPEG-4 video codecs discussed in this section. MPEG-4 Part 10 specifies the "advanced video codec" also known as H.264, and is discussed at the end of this chapter.
Like H.263 and MPEG-2, the MPEG-4 Part 2 video codecs are also macroblock, block and DCT-based.

Instead of the video "frames" or "pictures" used in earlier MPEG specifications, MPEG-4 uses natural and synthetic visual objects.
Instances of video objects at a given time are called visual object planes (VOPs).

MPEG-4 Part 2 supports many visual profiles and levels. Only natural visual profiles are currently of the most interest in the marketplace.

Visual layers: (from top to bottom)
VS -> VO -> VOL -> GOV -> VOP
A MPEG-4 visual scene consists of one or more video objects.
Each video object may have one or more layers to support temporal or spatial scalable coding.

Each video object can be encoded in scalable (multi-layer) or nonscalable form (single layer), depending on the application, represented by the video object layer (VOL).

Video object planes can be grouped together to form a group of video object planes.

  • H.264
Rather than a single major advancement, H.264 employs many new tools designed to improve performance. These include:
- Support for 8-, 10- and 12-bit 4:2:2 and 4:4:4 YCbCr
- Integer transform
- UVLC, CAVLC and CABAC entropy coding
- Multiple reference frames
- Intra prediction
- In-loop de-blocking filter
- SP and SI slices
- Many new error resilience tools

 H.264 supported three profiles.  Baseline profile is designed for progressive video.
- I and P slice types
- 1/4-pixel motion compensation
- UVLC and CAVLC entropy coding
- Arbitrary slice ordering
- Flexible macroblock ordering
- Redundant slices
- 4:2:0 YCbCr format
Main profile is designed for a wide range of broadcast applications. Additional tools over baseline profile include:
- Interlaced pictures
- B slice type
- CABAC entropy coding
- Weighted prediction
- 4:2:2 and 4:4:4 YCbCr, 10- and 12-bit formats
- Arbitrary slice ordering not supported
- Flexible macroblock ordering not supported
- Redundant slices not supported
Extended profile is designed for mobile and Internet streaming applications. Additional tools over baseline profile include:
- B, SP and SI slice types
- Slice data partitioning
- Weighted prediction

H.264 uses the YCbCr color space, supporting 4:2:0, 4:2:2 and 4:4:4 sampling.
With H.264, the partitioning of the 16x16 macroblocks as been extended. Such fine granularity leads to a potentially large number of motion vectors per macroblock (up to 32) and number of blocks that must be interpolated (up to 96).

H.264 adds an in-loop de-blocking filter. It removes artifacts resulting from adjacent macroblocks having different estimation types and/or different quantizer scales.

The slice has greater importance in H.264 since it is now the basic independent spatial element. This prevents an error in one slice from affecting other slices.

When motion estimation is not efficient, intra prediction can be used to eliminate spatial redundancies. This technique attempts to predict the current block based on adjacent blocks. The difference between the predicted block and the actual block is then coded. This tool is very useful in flat backgrounds where spatial redundancies often exist.

H.264 adds supports for multiple reference frames. This increases compression by improving the prediction process and increases error resilience by being able to use another reference frame in the event that one was lost.

H.264 uses a simple 4x4 integer transform. An additional 2x2 transform is applied to the four CbCr DC coefficients. Intra-16×16 macroblocks have an additional 4x4 transform performed for the sixteen Y DC coefficents.

For everything but the transform coefficients, H.264 uses a single Universal VLC (UVLC) table that uses an infinite-extend codeword set (Exponential Golomb).

For transform coefficients, which consume most of the bandwidth, H.264 uses Context Adaptive Variable Length Coding (CAVLC).  Based upon previously processed data, the best VLC table is selected.

Additional efficiency (5-10%) may be achieved by using Context Adaptive Binary Arithmetic Coding (CABAC). CABAC continually updates the statistics of incoming data and real-time adaptively adjusts the algorithm using a process called context modeling.


NAL
The NAL facilitates mapping H.264 data to a variety of transport layers including:
- RTP/IP for wired and wireless Internet services
- File formats such as MP4
- H.32X for conferencing
- MPEG-2 systems
The data is organized into NAL units, packets that contain an integer number of bytes.
The first byte of each NAL unit indicates the payload data type and the remaining bytes contain the payload data. The payload data may be interleaved with additional data to prevent a start code prefix from being accidentally generated.

Monday, June 21, 2010

mix of hash & array (perl)

  • array of hashes
@AoH = (
    {
       husband  => "barney",
       wife     => "betty",
       son      => "bamm bamm",
    },
…
)
push @AoH, { husband => "fred", wife => "wilma", daughter => "pebbles" };
$AoH[0]{husband} = "fred";
$AoH[1]{husband} =~ s/(\w)/\u$1/;

  • array of arrays
@AoA = (
         [ "fred", "barney" ],
         [ "george", "jane", "elroy" ],
         [ "homer", "marge", "bart" ],
);
$AoA[2][3]
$ref_to_AoA->[2][3]


  • hash of arrays
%HoA = (
  flintstones => [ "fred","barney" ],
…)
$HoA{teletubbies} = [ "tinky winky", "dipsy", "laa-laa", "po" ];
$HoA{flintstones}[0] = "Fred";


  • hash of hashes
%HoH = (
    flintstones => {
        husband   => "fred",
        pal       => "barney",
    },
...
)
$HoH{ mash } = {
    captain  => "pierce",
    major    => "burns",
    corporal => "radar",
};
$role=$HoH{$family}{$role};

Sunday, June 20, 2010

ovm phase summary

Components execute their behavior in strictly ordered, pre-defined phases.  Each phase is defined by its own method, which derived components can override to incorporate component-specific behavior. 

During simulation, the phases are executed one by one, where one phase must complete before the next phase begins.  The following briefly describe each phase:
1.1     new

Also known as the constructor, the component does basic initialization of any members not subject to configuration.
1.2     build

The component constructs its children.  It uses the get_config interface to obtain any configuration for itself, the set_config interface to set any configuration for its own children, and the factory interface for actually creating the children and other objects it might need.
1.3     connect

The component now makes connections (binds TLM ports and exports) from child-to-child or from child-to-self (i.e. to promote a child port or export up the hierarchy for external access.  Afterward, all connections are checked via resolve_bindings before entering the end_of_elaboration phase.
1.4     end_of_elaboration

At this point, the entire testbench environment has been built and connected.  No new components and connections may be created from this point forward.  Components can do final checks for proper connectivity, and it can initiate communication with other tools that require stable, quasi-static component structure..
1.5     start_of_simulation

The simulation is about to begin, and this phase can be used to perform any pre-run activity such as displaying banners, printing final testbench topology and configuration information.
1.6     run

  This is where verification takes place.  It is the only predefined, time-consuming phase.  A component’s primary function is implemented in the run task.  Other processes may be forked if desired.  When a component returns from its run task, it does not signify completion of its run phase.  Any processes that it may have forked continue to run.  The run phase terminates in one of four ways:
1.6.1     stop

  When a component’s enable_stop_interrupt bit is set and global_stop_request is called, the component’s stop task is called.  Components can implement stop to allow completion of in-progress transactions, queues, etc.  Upon return from stop() by all enabled components, a do_kill_all is issued.  If the ovm_test_done_objection is being used, this stopping procedure is deferred until all outstanding objections on ovm_test_done have been dropped.
1.6.2     objections dropped

  The ovm_test_done_objection will implicitly call global_stop_request when all objections to ending the phase are dropped.  The stop procedure described above is then allowed to proceed normally.
1.6.3     kill

  When called, all component’s run processes are killed immediately.  While kill can be called directly, it is recommended that components use the stopping mechanism, which affords a more ordered and safe shut-down.
1.6.4     timeout

If a timeout was set, then the phase ends if it expires before either of the above occur.  Without a stop, kill, or timeout, simulation can continue “forever”, or the simulator may end simulation prematurely if it determines that all processes are waiting.
1.7     extract

This phase can be used to extract simulation results from coverage collectors and scoreboards, collect status/error counts, statistics, and other information from components in bottom-up order.  Being a separate phase, extract ensures all relevant data from potentially independent sources (i.e. other components) are collected before being checked in the next phase. Following are some examples of what you can do in this phase.

■ Collect assertion-error count.

■ Extract coverage information.

■ Extract the internal signals and register values of the DUT.

■ Extract internal variable values from components.

■ Extract statistics or other information from components.
1.8     check

Having extracted vital simulation results in the previous phase, the check phase can be used to validate such data and determine the overall simulation outcome.  It too executes bottom-up.
1.9     report

Finally, the report phase is used to output results to files and/or the screen.

It is called in bottom-up order.

 

Thursday, June 10, 2010

virtual things

Virtual class
If a base class is not intended to be instantiated, it can be made abstract by specifying the class to be virtual.
An abstract class cannot be instantiated; it can only be derived.
Abstract classes can also have virtual methods.

Virtual method(function)
 Virtual methods are a basic polymorphic construct. A virtual method overrides a method in all the base classes, whereas a normal method only overrides a method in that class and its descendants.(only a virtual method can be overrided.) One way to view this is that there is only one implementation of a virtual method per class hierarchy, and it is always the one in the latest derived class. When subclasses override virtual methods, they must follow the prototype exactly.

example:
virtual class BasePacket;
virtual function integer send(bit[31:0] data);
endfunction
endclass
class EtherPacket extends BasePacket;
function integer send(bit[31:0] data);
// body of the function
...
endfunction
endclass


Virtual interface
Virtual interfaces provide a mechanism for separating abstract models and test programs from the actual signals that make up the design. A virtual interface allows the same subprogram to operate on different portions of a design and to dynamically control the set of signals associated with the subprogram. Instead of referring to the actual set of signals directly, users are able to manipulate a set of virtual signals. Changes to the underlying design do not require the code using virtual interfaces to be rewritten. By abstracting the connectivity and functionality of a set of blocks, virtual interfaces promote code reuse.
A virtual interface is a variable that represents an interface instance.

Virtual interface variables can be passed as arguments to tasks, functions, or methods. A single virtual interface variable can thus represent different interface instances at different times throughout the simulation. A virtual  interface  must  be  initialized  before  it  can  be  used;  it  has  the  value  null  before  it  is  initialized.

A virtual  interface  must  be  initialized  before  it  can  be  used;  it  has  the  value  null  before  it  is  initialized.

Once  a  virtual  interface  has  been  initialized,  all  the components  of  the  underlying  interface  instance  are directly  available  to  the  virtual  interface  via  the  dot  notation. 
Virtual interfaces can be declared as class properties, which can be initialized procedurally or by an argument to new().

example:
interface SBus; // A Simple bus interface
logic req, grant;
logic [7:0] addr, data;
endinterface

class SBusTransctor; // SBus transactor class
  virtual SBus bus; // virtual interface of type Sbus
  function new( virtual SBus s );
    bus = s;  // initialize the virtual interface
  endfunction
endclass

module devA( Sbus s ) ... endmodule   // devices that use SBus

module top;
  SBus s[1:4] (); // instantiate 4 interfaces
  devA a1( s[1] ); // instantiate 4 devices
  ...
  initial begin
    SbusTransactor t[1:4];          // create 4 bus-transactors and bind
    t[1] = new( s[1] );
    ...
  end
endmodule

In the preceding example, the transaction class SbusTransctor is a simple reusable component. It is written without any global or hierarchical references and is unaware of the particular device with which it will interact. Nevertheless, the class can interact with any number of devices (four in the example) that adhere to the interface’s protocol.

(设想一下,在SBusTransctor中如果没有virtual修饰 SBus s, s就成为一个实在的interface, 所有对s的操作都在局限在SBusTransctor中,"到此为止"。有了virtual修饰,在SBusTransctor梨花的时候,通过把virtual interface和外部实际interface连接,相应的操作就能传递到理想的real DUT上。 所以virtual interface 常用于 ovm driver 设计中。

semaphore, mailbox and event


semaphore

a semaphore is a bucket to store 1 or more keys. Any process using semaphore must procure a key before it can continue to execute.
To declare a semaphore:
semaphore smTx
Semaphore is a built-in class that provides the following methods:
Create a semaphore with a specified number of keys:
function new(int keyCount = 0 );
Obtain one or more keys from the bucket. If the specified number of keys is not available, the process blocks until the keys become available.
task get(int keyCount = 1);
Return one or more keys into the bucket. If the specified number of keys is available, the method returns a positive integer and execution continues.
task put(int keyCount = 1);
Try to obtain one or more keys without blocking. The semaphore try_get() method is used to procure a specified number of keys from a semaphore, but without blocking.
function int try_get(int keyCount = 1);

mailbox
A mailbox is a communication mechanism that allows messages to be exchanged between processes. Data can be sent to a mailbox by one process and retrieved by another.
Conceptually, mailboxes behave like real mailboxes.
  When a letter is delivered and put into the mailbox, one can retrieve the letter (and any data stored within). However, if the letter has not been delivered when one checks the mailbox, one must choose whether to wait for the letter or to retrieve the letter on a subsequent trip to the mailbox. Similarly, SystemVerilog's mailboxes provide processes to transfer and retrieve data in a controlled manner.
size: Mailboxes are created as having either a bounded or unbounded queue size.
      A bounded mailbox becomes full when it contains the bounded number of messages. A process that attempts to place a message into a full mailbox shall be suspended until enough room becomes available in the mailbox queue.
      Unbounded mailboxes never suspend a thread in a send operation.

An example of creating a mailbox is as follows:
mailbox mbxRcv;

Mailbox is a built-in class that provides the following methods:
Create a new mailbox
  function new(int bound = 0);
If the bound argument  is  0,  then  the  mailbox  is  unbounded

The number of messages in a mailbox can be obtained via the num() method.
  function int num();

The put() method places a message in a mailbox.
  task put( singular message);
The message  is any singular expression, including object handles.
If the mailbox was created with a bounded queue, the process shall be suspended until there is enough room in the queue.

The try_put() method attempts to place a message in a mailbox.
  function int try_put( singular message);
The try_put()  method stores a message in the mailbox in strict FIFO order. Meaningful only for bounded mailboxes. If the mailbox is full, the method returns 0.

The get() method retrieves a message from a mailbox.
task get( ref singular message );
  The get()  method retrieves one message from the mailbox, that is, removes one message from the mailbox queue. If the mailbox is empty, then the current process blocks until a message is placed in the mailbox.

try_get() method attempts to retrieves a message from a mailbox without blocking.
  function int try_get( ref singular message );

The peek() method copies a message from a mailbox without removing the message from the queue.
  task peek( ref singular message );
The peek()  method copies one message from the mailbox without removing the message from the mailbox queue.

The try_peek() method attempts to copy a message from a mailbox without blocking.
  function int try_peek( ref singular message );



Event
 Nonblocking event trigger are supported in systemverilog  using the ->> operator.
 The basic mechanism to wait for an event to be triggered is via the event control operator, @.
@ hierarchical_event_identifier;

SystemVerilog can distinguish the event trigger itself, which is instantaneous. The triggered property is invoked using a method-like syntax:
hierarchical_event_identifier.triggered.
The triggered event property is most useful when used in the context of a wait construct:
wait ( hierarchical_event_identifier.triggered )