You are on page 1of 26

Kobekara Company 2008

PART 1: WRITING A RESOURCE


MANAGER
1. Overview QNX

 QNX đọc là Q-N-X hoặc Q-NIX.


 QNX là hệ điều hành đa người dùng, đa nhiệm, thời gian thực, dành cho máy tính cá nhân
được phát triển bởi QNX Software Systems.
 QNX chạy nhanh, tựa UNIX, tuân theo tiêu chuẩn POSIX, được sử dụng chủ yếu trong các
hệ thống nhúng, và có thể được coi là hệ điều hành vi nhân tốt nhất hiện nay.
 QNX Neutrino là hệ điều hành đầu tiên phân phát các tiêu chuẩn hệ thống mở, có thể phát
triển rộng và có độ tin cậy cao.

Ten Steps to Your First QNX Program


1. Requirements
2. Installing the QNX Momentics development suite
3. Installing the QNX Neutrino RTOS
4. Networking with QNX Neutrino
5. Creating a program project
6. Communicating with QNX Neutrino
7. Compiling and linking
8. Preparing to launch the program
9. Starting and debugging
10. Making the program your own

2. Writing a resource manager

Một resource Manager là một user-level mức người dùng cung cấp những chương trình có thể truy
xuất những thông điệp đến những chương trình khác hay giao tiếp với phần cứng. Nó là một quy
trình ghi nhận đường dẫn ví dụ /dev/ser1 sử dụng các tập lệnh cơ bản open(), read(), write().
Ví dụ:
fd = open("/dev/ser1", O_RDWR);
for (packet = 0; packet < npackets; packet++)
write(fd, packets[packet], PACKET_SIZE);
close(fd);

2.1 Commands basic

open(), open64()
Mỡ một file
Cấu trúc:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

Embedded Group 1
Kobekara Company 2008

int open( const char * path,


int oflag,
... );
int open64( const char * path,
int oflag,
... );

read()
Đọc bytes từ một file
Cấu trúc:
#include <unistd.h>

ssize_t read( int fildes,


void* buf,
size_t nbyte );

ví dụ
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

int main( void )


{
int fd;
int size_read;
char buffer[80];
/* Open a file for input */
fd = open( "myfile.dat", O_RDONLY );
/* Read the text */
size_read = read( fd, buffer,
sizeof( buffer ) );
/* Test for error */
if( size_read == -1 ) {
perror( "Error reading myfile.dat" );
return EXIT_FAILURE;
}
/* Close the file */
close( fd );
return EXIT_SUCCESS;
write()
Viết bytes đến một file.
Cấu trúc:
#include <unistd.h>
ssize_t write( int fildes,
const void* buf,
size_t nbyte );

Ví dụ
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>

Embedded Group 2
Kobekara Company 2008

char buffer[] = { "A text record to be written" };


int main( void )
{
int fd;
int size_written;
/* open a file for output */
/* replace existing file if it exists */
fd = creat( "myfile.dat", S_IRUSR | S_IWUSR );
/* write the text */
size_written = write( fd, buffer,
sizeof( buffer ) );
/* test for error */
if( size_written != sizeof( buffer ) ) {
perror( "Error writing myfile.dat" );
return EXIT_FAILURE;
}
/* close the file */
close( fd );
return EXIT_SUCCESS;
}

ioctl()
Điều khiển một thiết bị
Cấu trúc:
#include <sys/ioctl.h>
int ioctl( int fd,
int request,
... );

2.2 Components of a resource manager

Embedded Group 3
Kobekara Company 2008

Các thành phần của một Resource


Manager

iofunc layer (top)

resmgr layer

dispatch layer

thread pool layer (bottom)

2.2.1 iofunc layer

Chứa tập hợp hàm của file hệ thống. IOFUNC cung cấp POSIX-personality.

2.2.2 resmgr layer

Nhận lệnh, sau đó chọn lệnh thích hợp để sử lí.

2.2.3 dispatch layer

Sử lý các _IO_* messages, select, pulses, và các messages khác

Embedded Group 4
Kobekara Company 2008

2.2.4 thread pool layer

Cho phép tạo Resource manager đơn luồng hây đa luồng. Nghĩa là một luồng đang sử lí lệnh
write(), luồng khác sử lí lệnh read() đồng thời với nhau.

Ví dụ:
Single-threaded device resource manager
Here's an outline of the steps we followed:

 Initialize the dispatch interface


 Initialize the resource manager attributes
 Initialize functions used to handle messages
 Initialize the attribute structure used by the device
 Put a name into the namespace
 Start the resource manager message loop
#include <errno.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/iofunc.h>
#include <sys/dispatch.h>

static resmgr_connect_funcs_t connect_funcs;


static resmgr_io_funcs_t io_funcs;
static iofunc_attr_t attr;

main(int argc, char **argv)


{
/* declare variables we'll be using */
resmgr_attr_t resmgr_attr;
dispatch_t *dpp;
dispatch_context_t *ctp;
int id;

/* initialize dispatch interface */


if((dpp = dispatch_create()) == NULL) {
fprintf(stderr,

Embedded Group 5
Kobekara Company 2008

"%s: Unable to allocate dispatch handle.\n",


argv[0]);
return EXIT_FAILURE;
}

/* initialize resource manager attributes */


memset(&resmgr_attr, 0, sizeof resmgr_attr);
resmgr_attr.nparts_max = 1;
resmgr_attr.msg_max_size = 2048;

/* initialize functions for handling messages */


iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &connect_funcs,
_RESMGR_IO_NFUNCS, &io_funcs);

/* initialize attribute structure used by the device */


iofunc_attr_init(&attr, S_IFNAM | 0666, 0, 0);

/* attach our device name */


id = resmgr_attach(
dpp, /* dispatch handle */
&resmgr_attr, /* resource manager attrs */
"/dev/sample", /* device name */
_FTYPE_ANY, /* open type */
0, /* flags */
&connect_funcs, /* connect routines */
&io_funcs, /* I/O routines */
&attr); /* handle */
if(id == -1) {
fprintf(stderr, "%s: Unable to attach name.\n", argv[0]);
return EXIT_FAILURE;
}

/* allocate a context structure */


ctp = dispatch_context_alloc(dpp);

/* start the resource manager message loop */


while(1) {
if((ctp = dispatch_block(ctp)) == NULL) {
fprintf(stderr, "block error\n");
return EXIT_FAILURE;
}
dispatch_handler(ctp);
}
}

Embedded Group 6
Kobekara Company 2008

PART 2: PCI ARCHITECTURE


1. OVERVIEW PCI

PCI trong khoa học máy tính (là viết tắt Tiếng Anh: Peripheral Component Interconnect) là một

chuẩn để truyền dữ liệu giữa các thiết bị ngoại vi đến một bo mạch chủ (thông qua chip cầu nam).

Embedded Group 7
Kobekara Company 2008

Khi giao tiếp với các thiết bị ngoại vi đòi hỏi phải có cơ chế truyền và nhận dữ liệu giữa các thiết bị
đó. Kiến trúc PCI được thiết kế như là một sự thay thế chuẩn ISA nhằm truyền tải dữ liệu giữa máy
tính và các thiết bị ngoại vi tốt hơn. PCI được trang bị 32 bit dữ liệu và 64 bit mỡ rộng, xây dựng
trên Platform độc lập. Khi cài đặt Driver cho PCI, nó sẽ dò giao diện bo mạch và cấu hình tự động
khi khởi động máy, từ đó người dùng có thể truy xuất thông tin cấu hình thiết bị.

2. PCI Architecture

2.1 Advantage of PCI

 Speed: Có thể truyền tốc độ 133MBytes với 32bit hoặc 266 MBytes/s với 64 bit.
 Configurability: hệ thống bus độc lập với processor cho phép định cấu hình tự động dễ dàng
cho người sử dụng.
 Multiple Master: bất kỳ thiết bị nào cũng có thể là chủ bus hỗ trợ cơ chế DMA
 Reliability: có tính Hot plug và Hot swap: khả năng thay đổi module mà không làm ảnh
hưởng tới hoạt động của hệ điều hành.

Embedded Group 8
Kobekara Company 2008

2.2 Characteristics basic

 Là cầu nối giữa bộ vi xử lý và bus mở rộng.


 Khả năng giao tiếp tối đa 256 thiết bị.
 Là bus 32 bit với tốc độ 133MBytes/s.
 Có khả năng mở rộng 64 bit với tốc độ 266MBytes/s.
 Làm việc với hệ thống đa xử lý.
 Hỗ trợ nguồn 5V và 3.3V.
 Tần số làm việc trong khoảng 0 đến 33MHz.
 Tín hiệu địa chỉ và dữ liệu được dồn kênh.
 Định cấu hình qua phần mềm và thanh ghi.
 Đặc tính độc lập với bộ vi xử lý.

2.3 PCI slots

2.4 Pins Signal

Embedded Group 9
Kobekara Company 2008

2.5 Processing Bus

 Khi có nhiều thiết bị cùng yêu cầu làm chủ bus, việc xử lý bus dựa vào bộ Arbiter
 REQ: tín hiệu yêu cầu làm chủ bus
 GNT: tín hiệu cấp bus

Embedded Group 10
Kobekara Company 2008

Exam:PCI 9050

Exam: PCI of Xilinx Device Co.,

Embedded Group 11
Kobekara Company 2008

2.6 PCI Configuration Header

2.7 PCI Commands

Embedded Group 12
Kobekara Company 2008

Địa chỉ PCI

3 Register PCI with Device and QNX OS

Các lệnh cơ bản giao tiếp với PCI trong hệ điều hành QNX và các thiết bị ngoại vi:

3.1 pci_attach()

Kết nối với PCI server.


#include <hw/pci.h>
int pci_attach( unsigned flags );
Lưu ý: phải gọi pci_attach() trước khi gọi bất cứ hàm PCI nào khác.

3.2 pci_attach_device()

Gán một Driver đến một PCI.


#include <hw/pci.h>
void* pci_attach_device(
void* handle,
uint32_t flags,

Embedded Group 13
Kobekara Company 2008

uint16_t idx,
struct pci_dev_info* info );
handle: xác nhận thiết bị. Gọi lần đầu chức năng này, thiết lập Handle là NULL. Chức năng này trả
lại một Handle để có thể sử dụng vào lần kế tiếp.
Idx: là Index của thiết bị, số 0 cho thiết bị đầu tiên, số 1 cho thiết bị kế .v.v.
Info: trỏ đến cấu trúc pci_dev_info structure để chỉ rõ mã code, vendor/device ID, hay số bus và số
device/function muốn scan.

3.2 pci [-n] [-v]

-n: Số bus PCI lớn nhất để scan.


-v: Hiển thị tất các thiết bị PCI (chạy trên Neutrino).
Lệnh này theo mặc định hiển thị các thiết bị: disk, network, and graphics. Dùng -v (verbose) để hiển
thị tất cả PCI.
Ví dụ: một vài mẫu ngõ ra từ PCI
Class = Mass Storage (IDE)
Vendor ID = 8086, Intel Corporation
Device ID = 7010h, 82371SB PIIX3 IDE Interface (Triton II)
PCI index = 0
IO Address = ffa0h enabled
PCI Int Pin = NC
Interrupt line = 0

3.4 pci_detach()

Ngắt kết nối với PCI server.


#include <hw/pci.h>
int pci_detach( unsigned handle );

3.5 pci_detach_device()

Tách một Driver từ một PCI.


#include <hw/pci.h>
int pci_detach_device( void* handle );
handle: giá trị của handle được trả về bởi lệnh pci_attach_device().
Hàm pci_detach_device() tách một Driver từ một PCI, bất cứ tài nguyên nào được cấp phát với lệnh
pci_attach_device() đều được tự do, trừ khi thiết bị được gán với lệnh pci_persist.

3.6 pci_find_class()

Tìm thiết bị có mã code đặc biệt.


#include <hw/pci.h>
int pci_find_class( unsigned long class_code,
unsigned index,
unsigned* bus,
unsigned* dev_func );
class_code: tức là mã code của device hay funtion cần tìm.
Index: tức là chỉ số của device gay funtion cần tìm. Số 0 cho chỉ số đầu tiên, số 1 cho chữ số thứ 2...
bus: phạm vi của bus là [0...255].

Embedded Group 14
Kobekara Company 2008

dev_func: số device hay funtion thứ cấp của lớp đã cho. Số device là 7 đến 3 bit, còn số funtion là 2
đến 0.
Hàm pci_find_class() xác định vị trí của PCI hay funtion thứ n có mã code xác định.

3.7 pci_find_device()

Nghĩa là tìm thiết bị PCI với một ID and vendor ID đã cho.


#include <hw/pci.h>
int pci_find_device( unsigned device,
unsigned vendor,
unsigned index,
unsigned* bus,
unsigned* dev_func );
device Device ID đã cho. Một danh sách những device IDs được hỗ trợ, xem <hw/pci_devices.h>.
vendor Vendor ID đã cho. Một danh sách những vendor IDs được hỗ trợ, xem: <hw/pci_devices.h>.
index index (n) của device hay của function.
Bus Trỏ tới một vị trí nơi mà funtion có thể lưu trữ số bus của device hay funtion.
dev_func Trỏ tới một vị trí nơi mà funtion có thể lưu trữ device ID hay funtion ID của device hay
funtion thứ cấp.
pci_find_device() trả đến vị trí của PCI thứ cấp có device và vendor ID. Bạn có thể tìm tất cả các
PCI có chung device và vendor ID bằng cách gọi liên tiếp đến chức năng này, bắt đầu từ số 0 và
tăng đến lúc PCI_DEVICE_NOT_FOUND thì quay lại.

3.8 pci_present()

Xác định liệu có mặt của PCI BIOS hay không.


#include <hw/pci.h>
int pci_present( unsigned* lastbus,
unsigned* version,
unsigned* hardware );
lastbus: số bus của PCI cuối cùng trong hệ thống.
Version: xem số version.

3.9 Notes

pci_attach() kết nối với server PCI


pci_attach_device(): attach một Driver đến một thiết bị PCI.
pci_detach(): ngắt kết nối từ PCI server.
pci_detach_device(): tách một Driver từ một thiết bị PCI.
pci_find_class(): tìm thiết bị có code xác định.
pci_find_device(): tìm thiết bị với device ID và vendor ID cho trước.
pci_irq_routing_options(): khôi phục thông tin PCI IQR.
pci_map_irq(): vẽ một điểm ngắt đến một IRQ.
pci_present(): xác định tình trạng có mặt của PCI BIOS
pci_read_config(): đọc cấu hình của thiết bị PCI.
pci_read_config8(): đọc một byte cấu hình của thiết bị.
pci_read_config16(): đọc giá trị 16 bit cấu hình của thiết bị.
pci_read_config32(): đọc giá trị 32 bít cấu hình củamột thiết bị.
pci_rescan_bus(): quét lại bus PCI để bổ sung hay gỡ bỏ thiết bị.

Embedded Group 15
Kobekara Company 2008

pci_write_config(): viết cấu hình của thiết bị.


pci_write_config8(): viết các bytes để cấu hình thiết bị.
pci_write_config16(): viết giá trị 16 bit để cấu hình thiết bị.
pci_write_config32(): viết giá trị 32 bit để cấu hình thiết bị.

disp_pci_init() disp_pci_init(): gán Driver đến thiết bị PCI.


disp_pci_shutdown(): tách Driver ra khỏi thiết bị.
disp_pci_read_config(): đọc thanh ghi cấu hình PCI.
disp_pci_write_config(): viết thanh ghi cấu hình PCI.
disp_pci_dev_find(): tương tự như lệnh pci_find_device().
disp_pci_dev_read_config():
disp_pci_dev_write_config()
disp_pci_info()

Exam:
int main (int argc, char **argv)

{
int pathID;
int unit_num;
int ret;
char name[20];

printf ("%s: starting...\n", progname);


if( argc <= 1 )
{
printf ("Command Line Error");
return (DEV_ERR);
}

unit_num = atoi(argv[1]);
// if ( isdigit ( (int)argv[1] ) ) unit_num = atoi(argv[1]);
// else unit_num = 0;
// if (unit_num < 0 || unit_num > 9) unit_num = 0;

dpp = dispatch_create ();


if (dpp == NULL)
{
fprintf (stderr, "%s: couldn't dispatch_create: %s\n", progname, strerror (errno));
exit (EXIT_FAILURE);
}

memset( &po2dev, 0, sizeof(po2dev));


memset( &po2PciConfInfo, 0, sizeof(po2PciConfInfo) );
memset( &rbuffer, 0, sizeof(rbuffer) );

ret = pciConfigGet( ETS_VENDER_ID, ETSPO2_DEVICE_ID, ETSPO2_SUBSYSTEM_ID, unit_num,


&po2PciConfInfo );

Embedded Group 16
Kobekara Company 2008

if( ret != PCI_OK ) return DEV_ERR;

etsPO2GetDevInfo(&po2dev, po2PciConfInfo);

strcpy(name, "/dev/ets_po2_");
strcat(name,argv[1]);

memset (&rattr, 0, sizeof (rattr));


iofunc_func_init (_RESMGR_CONNECT_NFUNCS, &connect_funcs,_RESMGR_IO_NFUNCS, &io_funcs);
connect_funcs.open = etsPO2DrvOpen;
io_funcs.read = etsPO2DrvRead;
io_funcs.write = etsPO2DrvWrite;
io_funcs.devctl = etsPO2DrvIoctl;

iofunc_attr_init (&ioattr, S_IFCHR | 0666, NULL, NULL);

pathID = resmgr_attach (dpp, &rattr, name,_FTYPE_ANY, 0, &connect_funcs, &io_funcs, &ioattr);

if (pathID == -1)
{
fprintf (stderr, "%s: couldn't attach pathname: %s\n",progname, strerror (errno));
exit (EXIT_FAILURE);
}

ctp = dispatch_context_alloc ( dpp );

while (1)
{
if ((ctp = dispatch_block (ctp)) == NULL)
{
fprintf (stderr, "%s: dispatch_block failed: %s\n", progname, strerror (errno));
exit (EXIT_FAILURE);
}
dispatch_handler (ctp);
}
}

Code:
#include <sys/neutrino.h>
#include <hw/pci.h>
#include <hw/pci_devices.h>
#include <stdio.h>
#include <sys/mman.h>
#include <errno.h>

struct pci_dev_info inf;

#define HOTICE_CARD_DEVICE_ID 0x8478


#define HOTICE_CARD_VENDOR_ID 0x14f1
#define FUNC0_BAR_START ((void*)0x00900000)
int phndl;
void* hndl;
uint32_t addr;

Embedded Group 17
Kobekara Company 2008

void*mem_hndl;
uint32_t addr_hndl;
void pci_debug(struct pci_dev_info *inf);
void pci_give_command(uint16_t pci_command, struct pci_dev_info *inf);
int hdlc_detect_card(void);
void remove_card(struct pci_dev_info *inf);

//int main(int argc, char *argv)


int main(int argc, char *argv)
{
hdlc_detect_card();
remove_card(&inf);

}
void pci_debug(struct pci_dev_info *inf)
{
uint32_t i;
fprintf(stdout,"\n device id=%x",inf->DeviceId);
fprintf(stdout,"\n Vendo id=%x",inf->VendorId);
fprintf(stdout,"\n BusNumber=%x",inf->BusNumber);
fprintf(stdout,"\n device function=%x",inf->DevFunc);
fprintf(stdout,"\n device class=%x",inf->Class);
fprintf(stdout,"\n device irq=%x",inf->Irq);
fprintf(stdout,"\n pcibase address =%x",(*(inf->CpuBaseAddress)));
//addr_hndl=(uint32_t*)(*(inf->CpuBaseAddress));
fprintf(stdout,"\n base address size=%x",(*(inf->BaseAddressSize)));
pci_read_config32(inf->BusNumber,inf->DevFunc,0x10,1,&i);
fprintf(stdout,"\n base address 0=%x",i);
pci_read_config32(inf->BusNumber,inf->DevFunc,0x14,1,&i);
fprintf(stdout,"\n base address 1=%x",i);
pci_read_config32(inf->BusNumber,inf->DevFunc,0x18,1,&i);
fprintf(stdout,"\n base address 2=%x",i);
pci_read_config32(inf->BusNumber,inf->DevFunc,0x1c,1,&i);
fprintf(stdout,"\n base address 3=%x",i);
pci_read_config32(inf->BusNumber,inf->DevFunc,0x20,1,&i);
fprintf(stdout,"\n base address 4=%x",i);
pci_read_config32(inf->BusNumber,inf->DevFunc,0x24,1,&i);
fprintf(stdout,"\n base address 5=%x",i);

void pci_give_command(uint16_t pci_command, struct pci_dev_info *inf)


{
uint16_t test_read;
//fprintf(stdout,"\n pci command register ip=%x",pci_command);
pci_write_config16(inf->BusNumber,inf->DevFunc,0x04,1,&pci_command);
pci_read_config16(inf->BusNumber,inf->DevFunc,0x06,1,&test_read);

Embedded Group 18
Kobekara Company 2008

fprintf(stdout,"\n pci command register ip=%x",pci_command);


fprintf(stdout,"\n pci command register op =%x",test_read);

}
int hdlc_detect_card(void)
{
volatile uint32_t *x;
volatile int status;
volatile int pidx=0;
int flg;
unsigned device=HOTICE_CARD_DEVICE_ID;
unsigned vendor=HOTICE_CARD_VENDOR_ID;
unsigned index=1;
unsigned bus;
unsigned dev;
unsigned func;
unsigned dev_func;

memset( &inf, 0, sizeof( inf ) );


inf.VendorId= HOTICE_CARD_VENDOR_ID;
inf.DeviceId= HOTICE_CARD_DEVICE_ID;
ThreadCtl( _NTO_TCTL_IO, 0 );
phndl=pci_attach(0);
if (-1==phndl)
fprintf(stderr,"\n unable to attach pci");
else
{
status=pci_find_device( device,vendor,index,&bus,&dev_func );
if (status!=PCI_SUCCESS)
{
fprintf(stderr,"\n device not found");
}
else
{
dev=(dev_func&0xf8)>>3;
func=dev_func&0x07;
fprintf(stdout,"\n BusNumber=%x",bus);
fprintf(stdout,"\n device function=%x",func);
fprintf(stdout,"\n device dev_function=%x",dev_func);
fprintf(stdout,"\n device number=%x",dev);
}

hndl=pci_attach_device(NULL,(PCI_SHARE|PCI_SEARCH_VENDEV|PCI_INIT_ALL),pidx,&i
nf);
// hndl = pci_attach_device( NULL, (PCI_SEARCH_VENDEV|PCI_INIT_ALL), pidx, &inf );
if(NULL==hndl)
{
fprintf(stderr,"\n Erro code %x, implies %s",errno,sys_errlist[errno]);

Embedded Group 19
Kobekara Company 2008

return errno;
}
//pci_debug(&inf);
status =pci_read_config32(inf.BusNumber,inf.DevFunc,0x10,1,&addr);
if (PCI_SUCCESS!=status)
{
fprintf(stderr,"\n error reading config space 0 BAR2");
}
else
{
fprintf(stdout,"\n reading config space 0 BAR2, addr is =%x",addr);
addr_hndl=PCI_MEM_ADDR(addr);
fprintf(stdout,"\n config space 0 BAR2 addr is =%x",addr_hndl);
// flg=(/*MAP_PRIVATE|*/MAP_ANON|MAP_PHYS);
flg=0;
#if 0

mem_hndl=mmap(/*FUNC0_BAR_START*/NULL,(*(inf.BaseAddressSize)),(PROT_READ|PR
OT_WRITE/*|PROT_NOCACHE*/),flg,NOFD,(uint64_t)addr_hndl);
#endif
#if 1

mem_hndl=mmap_device_memory(/*FUNC0_BAR_START*/NULL,(*(inf.BaseAddressSize)),(P
ROT_READ|PROT_WRITE/*|PROT_NOCACHE*/),flg,(uint64_t)addr_hndl);
#endif
// |MAP_BELOW16M
if (MAP_FAILED==mem_hndl)
{
fprintf(stderr, "mmap failed : %s\n",strerror(errno));
remove_card(&inf);
return;
}
fprintf(stdout,"\n config space 0 BAR2 map addr is =%x",mem_hndl);
pci_give_command(0x384, &inf);
x=(uint32_t*)(mem_hndl+0x0600);
*x=0x00000010;
fprintf(stdout,"\n 1.base read addr =%x",x);
fprintf(stdout,"\n 1.value at base read addr =%x",*x);
x=(uint32_t*)(mem_hndl+0x0008);
// x=(uint32_t*)addr_hndl;
*x=0x00000100;
fprintf(stdout,"\n 2. base read addr =%x",x);
fprintf(stdout,"\n 2.value at base read addr =%x",*x);
x=(uint32_t*)(mem_hndl+0x0600);
// *x=0x00000010;
fprintf(stdout,"\n 3.base read addr =%x",x);
fprintf(stdout,"\n 3.value at base read addr =%x",*x);
x=(uint32_t*)(mem_hndl+0x0008);

Embedded Group 20
Kobekara Company 2008

// x=(uint32_t*)addr_hndl;
*x=0x00000000;
fprintf(stdout,"\n 4.base read addr =%x",x);
fprintf(stdout,"\n 4.value at base read addr =%x",*x);
/*Interrupt Status Descriptor*/
x=(uint32_t*)(mem_hndl+0x000C);
while (*x==0x00)
{
fprintf(stdout,"\n 5.base read addr =%x",x);
fprintf(stdout,"\n 5.value at base read addr =%x",*x);
}
}
}
}

void remove_card(struct pci_dev_info *inf)


{
int status;
if (MAP_FAILED!=mem_hndl)
{
// status = munmap(mem_hndl,(*(inf->BaseAddressSize)));
status = munmap_device_memory(mem_hndl,(*(inf->BaseAddressSize)));
if (-1==status)
{
fprintf(stderr, "munmap failed : %s\n",strerror(errno));
}
}
status=pci_detach_device(hndl);
if (PCI_SUCCESS!=status)
{
fprintf(stderr, "detach device failed status =%x : %s\n",status,strerror(errno));
}
status=pci_detach(phndl);
if (PCI_SUCCESS!=status)
{
fprintf(stderr, "detach device failed status =%x : %s\n",status,strerror(errno));
}

Embedded Group 21
Kobekara Company 2008

PART 3: IEEE 1394 STACK

1. Overview IEEE 1394 Standard

Chuẩn IEEE 1394 được biết như là Fire-Wire™ và i.LINK™, là chuẩn truyền tải kỹ dữ liệu số nối
tiếp. Tổ chức IEEE xây dựng chuẩn này từ năm 1994 với mục đích thiết lập một tiêu chuẩn truyền
tải dữ liệu với băng thông rộng và tốc độ cao khi kết nối với các thiết bị ngoại vi. Tốc độ truyền tải
từ 100 Mbip/s lên đến 3200 Mbip/s, hỗ trợ chế độ hot-plug. Hình vẽ là bảng so sánh giữa chuẩn
IEEE 1394 và chuẩn USB.

2. IEEE 1394 Driver Stack

Driver của một thiết bị kết nối với bus IEEE 1394 đặt ở phần đầu của IEEE 1394 driver stack.
Driver này giao tiếp với thiết bị bằng cách gởi IRPs đến bus driver IEEE. Nó cung cấp một một
giao diện phần cứng độc lập với bus IEEE 1394.

Embedded Group 22
Kobekara Company 2008

IEEE 1394 Device Stack


Hình vẽ bên dưới là tổng quát về hỗ trợ giao diện lập trình ứng dụng (API). Việc sử dụng giao diện
này sẽ giúp người lập trình dễ dàng phát triển các ứng dụng nhúng trên IEEE 1394.

Serial Bus Protocol 2


Là chuẩn truyền tải dữ liệu bất đồng bộ nối tiếp. Ứng dụng chính là thực thi giao thức SCSI-2 trên
IEEE 1394 . Kết nối các thiết bị ngoại vi với máy tính như máy scan, máy in, các thiết bị lưu trữ.

Embedded Group 23
Kobekara Company 2008

Embedded Group 24
Kobekara Company 2008

PART 4: C PROGRAMMING

1. Overview C Programming

1.1 Foundation of C

1.2 In/out command Standard

1.3 Architecture control and repeater cycle

1.4 Functions and Architecture Programming

1.5 Array and Pointer

1.6 Type Architecture

1.7 Transfer Data for Function

1.8 Connection List

(Tài liệu tham khảo trên Internet)

Table of Contents
PART 1: WRITING A RESOURCE MANAGER .............................................................................. 1
1. Overview QNX ............................................................................................................................ 1
2. Writing a resource manager ......................................................................................................... 1
2.1 Commands basic ................................................................................................................... 1
2.2 Components of a resource manager ...................................................................................... 3
2.2.1 iofunc layer .................................................................................................................... 3
2.2.2 resmgr layer ................................................................................................................... 4
2.2.3 dispatch layer ................................................................................................................. 4
2.2.4 thread pool layer ............................................................................................................ 4
PART 2: PCI ARCHITECTURE ......................................................................................................... 7
1. OVERVIEW PCI ......................................................................................................................... 7
2. PCI Architecture .......................................................................................................................... 8
2.1 Advantage of PCI .................................................................................................................. 8
2.2 Characteristics basic .............................................................................................................. 8

Embedded Group 25
Kobekara Company 2008

2.3 PCI slots ................................................................................................................................ 8


2.4 Pins Signal ............................................................................................................................. 9
2.5 Processing Bus .................................................................................................................... 10
2.6 PCI Configuration Header ................................................................................................... 11
2.7 PCI Commands ................................................................................................................... 12
3 Register PCI with Device and QNX OS ..................................................................................... 12
3.1 pci_attach() .......................................................................................................................... 12
3.2 pci_attach_device() ............................................................................................................. 12
3.2 pci [-n] [-v] .......................................................................................................................... 13
3.4 pci_detach() ......................................................................................................................... 13
3.5 pci_detach_device() ............................................................................................................ 13
3.6 pci_find_class() ................................................................................................................... 13
3.7 pci_find_device() ............................................................................................................... 14
3.8 pci_present() ........................................................................................................................ 14
3.9 Notes.................................................................................................................................... 14
PART 3: IEEE 1394 STACK............................................................................................................. 21
1. Overview IEEE 1394 Standard .................................................................................................. 21
2. IEEE 1394 Driver Stack ............................................................................................................. 21
PART 4: C PROGRAMMING .......................................................................................................... 23
1. Overview C Programming ......................................................................................................... 23
1.1 Foundation of C ................................................................................................................... 23
1.2 In/out command Standard ................................................................................................... 23
1.3 Architecture control and repeater cycle............................................................................... 23
1.4 Functions and Architecture Programming .......................................................................... 23
1.5 Array and Pointer ............................................................................................................... 23
1.6 Type Architecture ............................................................................................................... 23
1.7 Transfer Data for Function .................................................................................................. 23
1.8 Connection List .................................................................................................................. 23

Embedded Group 26

You might also like