91精品综合久久久久久五月天_国产精品一区电影_中文字幕欧美日韩一区二区_亚洲一区二区三区精品动漫

μC / OS-II multi-task information flow and the CAN bus driver

Abstract: This paper μC / OS-II multi-mission critical technology and interrupt the flow of information dealing with the general approach and the basic concepts of PC system interrupt; to CAN bus, detailed analysis in x86 real mode on μC / OS-II of the CAN The implementation of the bus driver.

μC / OS-II is an American Jean Labrosse prepared a free, open source embedded real-time kernel. Embedded computer applications for the development of the technical staff is a highly practical, real-time embedded operating system ERTOS (Embedded Real Time Operation System).

To develop a comprehensive ERTOS, we will have multi-task scheduling and I / O device operation stability, in terms of coordination to make a lot of work, this is my process in the development ERTOS deeply appreciate the focus. I hope this can develop ERTOS technical staff in the multi-task information flow and I / O-driven aspects of an inspiration.

More than one mission critical technical information flow

Multi-task information flow in the discussion before the discussion about multi-tasking working condition. In μC / OS, each task is an infinite loop, each task in the following five states: dormant, ready state, running state, suspend state and suspended state shown in Figure 1.

μC / OS-II multi-task information flow and the CAN bus driver

Multi-task scheduling and the driver of the preparation process will inevitably involve the public code and the shared storage area of the protection of Wen Ti. Even the original C function, in terms of reuse in the absence of verification of the theory and practice cases, need to be protected. This need to rationalize the algorithm to the common code segment, Gongxiangcunchu areas to protect, Bimian operating system running reuse problem arising in the process of Er Dao Zhi run results unpredictable.

System in the development process, we should consider to reduce the complexity of the system, but also take into account the stability and efficiency requirements. This requires us to various algorithms rational choice: the situation in stability can be guaranteed, the choice is relatively simple, CPU-less time of the algorithm; in Wending Xing can not be assured, consider comprehensive selection algorithm. The only way to make the operating system configuration in a certain environment to achieve maximum efficiency.

Then were used to void CanSendMessageProcess (void * data), void CanSendMessage (void * data), void CanReceiveMessageProcess (void * data), and void CanReceiveMessage (void * data) to describe the four tasks using message queues, mailboxes and semaphores communication mechanism for information flow in the transfer process.

(1) message queue communication mechanism

Message queue is initialized when a designated space array, the array is achieved when using the concept of circular buffers. The array will not be eliminated during operation, thus avoiding duplication of time to establish an array of memory leak problem. When a task sends a message to the message queue when the corresponding pointer plus 1 (OSQIn 1), the queue is full (OSQEntries = OSQSize), OSQIn then point to the same unit with OSQOut. If the point of the unit in OSQIn insert a new pointer pointing to a message, it constitutes a FIFO (First-In-First-Out) queue. Conversely, if the next unit in the OSQOut point to insert a new pointer to a cell, constitutes LIFO queue (Last-In-First-Out). In this instance, we define the FIFO queue. Message pointer always points to the unit from OSQOut out. OSQStart and OSQEnd define the message head and tail pointer array in order to OSQIn and OSQOut reach the edge of the queue, to the border inspection and pointer adjustment needed to achieve its circulation.

Message queue data structure is as follows:

typedef struct os_q (
struct os_q * OSQPtr; / * Queue control block in the free link to all of the queue control block * /
void * OSQStart; / * message queue pointer pointing to starting address of the array pointer * /
void * OSQEnd; / * point to the end of the message queue address of the next cell pointer * /
void * OSQIn; / * point to the message queue position to insert the next message pointer * /
void * OSQOut; / * point to the next message queue in the pointer position out message * /
INT16U OSQSize; / * message queue in the total number of elements * /
INT16U OSQEntries; / * message queue in the total number of messages * /
) OS_Q;

Figure 2 shows the flow of information message queue description.

① CanSendMessageProcess task after the completion of the calculation of information will be sent the information to send a message queue.

② CanSendMessage message queue a mandate to obtain inside information.

③ through the CAN bus I / O port sends data to the bus up. No information if the message queue, then the task by the running into the waiting state until the message queue from the information received so far.


④ CanReceiveMessage task responsible for reading the bus above information.

⑤ CanReceiveMessage task will be to read the information into the message queue 2.

⑥ CanReceiveMessageProcess task is removed from the message queue information 2 start work, if the message queue is empty, then the task into the wait state.

Message Queue apply one to one, one to many, many to many and many to one relationship. In other words, the message queue can be used as a shared public areas, to Shi Shi mutually exclusive, need to synchronize between tasks; to cooperation, inter-process requires the exchange of information, this also implements synchronization and communication.

μC / OS-II multi-task information flow and the CAN bus driver

(2) E-mail communication mechanism

E-mail concepts and pipelines (pipelines) are similar to the definition of a task or interrupt service routine task of sending a pointer to another type of variable, which contains a pointer to a specific "message" of the data structure. The source side of the task can only be written to the mailbox in the destination task can only be read from the mailbox. E-mail transport stream data, that is a continuous string of bytes or a stream. Therefore, to access a mailbox like to access a sequential file. E-mail can be used to notify the occurrence of an event (sending a message), can also be used to share certain resources, such mail will be treated as a binary semaphore.

Figure 3 shows the flow of information for the email instructions.

① CanSendMessageProcess task will calculate the best data sent to CanSendMessage task, and then wait for the response signal into the ready state. CanSendMessage the same time send a response in the receiver handshake signals to CanSendMessageProcess, confirmation has been received.

② CanSendMessage task CanSend MessageProcess mission sent to the information sent to the CAN bus, to send into the ready state after waiting for the next transmission work.

③ CanReceiveMessage task to receive the flow of information from the bus, will receive the information sent to the Can ReceiveMessageProcess task, enter the ready state to wait for response signal.

 

④ CanReceiveMessageProcess task received send a response message handshake.

(3) semaphore communication mechanism

Semaphore (semaphore) is a contract mechanism: two or more tasks by a simple signal of cooperation, a task can be forced to stop at a location until it receives a specific signal. In general the multi-tasking kernel semaphore for:

◇ mark the occurrence of an event;

◇ control the right to use shared resources (to meet the mutually exclusive conditions);

◇ make the behavior of the two tasks simultaneously.

Semaphore implementation of three main steps:

◇ A semaphore can be initialized non-negative;

◇ wait (wait) operation of the signal amount minus 1. If the value becomes negative, then the implementation of the task is blocked waiting.

◇ have the right to use the task singal CPU operation to increase a semaphore. If the value is not positive, the task was blocked waiting for operations to be unblocked.

To meet the information transfer process of the principle of real-time high, in part, in the message queue to introduce the concept of semaphores. Is CanSendMessageProcess task, the number of bytes of information at once sent to the message queue, so that by the operation plus 1 semaphore wait state into the suspended state. In CanSendMessage task was to enter ready state after the semaphore, wait for the right to use the CPU into the running state. Into the running state after the task and the signal amount minus one removed from the message queue message via I / O port to send to the CAN bus. CanReceiveMessage tasks and CanReceive MessageProcess mandate and contrary to the above operation. This example illustrates the semaphore signs for the occurrence of an event. (See Figure 2.)

μC / OS-II multi-task information flow and the CAN bus driver

2 μC / OS-II interrupt handling

μC / OS-II, the interrupt service routine generally written in assembly language. The following is indicative interrupt service routine code.

User interrupt service routine:

Save all the CPU registers;

Call OSIntEnter or OSIntNesting direct plus 1;

Implementation of the user code to interrupt;

Call OSIntExit;

Restore all CPU registers;

Implementation of the interrupt return instruction;

Here μC / OS-II provides two ISR and the kernel interface function: OSIntEnter and OSIntExit. OSIntEnter notify μC / OS-II kernel, interrupt service routine is running. In fact, this function do is to add a global variable OSIntNesting 1. And so have accumulated in the x86 CPU instructions, you can use the command instead of OSIntEnter:

INC BYTE PTR OSIntNesting

The interrupt nesting counter to ensure that all interrupt processing is complete and then for task scheduling. Another interface function is to inform the kernel OSIntExit, interrupt service has ended. According to the situation accordingly, returning to the breakpoint (which may be a task or interrupt service routine is nested), or by the kernel for task scheduling.

The user's ISR must be prepared to install a position to interrupt occurs, CPU number according to the corresponding interrupt service program is running and accurate. Many real-time operating systems are available to install, uninstall interrupt service routine of the API interface function, and even some mature RTOS interrupt controller's management has a corresponding API function. But the μC / OS-II kernel does not provide a similar interface function, the corresponding CPU requires the user to realize his transplantation. The interface function with the specific hardware environment, the next PC system interrupt handling this under the detailed description.

3 PC system interrupt under

X86 family of processors can support up to 256 interrupt, and methods used to scale associated with each interrupt and the corresponding position of ISR. In real mode, the interrupt vector table (IVT) stored in memory, the low end of 1K. Each entry to the scale, 4 bytes, save one ISR segment address and offset information. PC systems use two cascaded programmable interrupt controller 82C59A. A 82C59A can connect eight hardware interrupts, numbered IRQ0 ~ IRQ7. PC can manage a total of 15 external interrupt sources, PC's interrupt controller shown in Figure 4. (For more on the 82C59A uses can be found in the information.)

In μC / OS under, CAN bus I / O port interrupt vector to set pseudo-code:


void CanInitHW (UI segment, BYTE Irq0, BYTE Irq1) (
Save the old interrupt vector
Save the mask register value
So 82C59A mask register (0x21) the position 1, close the interrupt input
Close CPU interrupt
Set new interrupt vector
Interruption in service to respond to service against another (assuming the current service interruption is IRQ5)
Open CPU interrupt
Clear 82C59A mask register (0X21, 0XA1) you open the interrupt input
)

Buffer 4 semaphore queue with the support of the CAN bus driver

Introduced in front of μC / OS-II kernel key technology multi-task scheduling, interrupt and interrupt the normal PC system under way. You Yi 82C59A interrupt 5 (IRQ5), 0x0D interrupt vector, for example, introduced the interrupt service routine of re-distribution and response SJA1000 controller to send and receive interrupt service routine.

Here, under the ring signal volume with the buffer queue and the relationship between the interrupt handler, and this is part of the core device driver.

ERTOS drivers and other operating systems are different. Such as Windows, Unix, Solaris, Linux and other operating system, weakening the concept of the device, the user process can use the device file system to complete. However, in μC / OS-II to develop CAN bus driver is not so strict, as long as the equipment to meet the CPU time in a row do not occur when using the time overlap on it.

Character serial devices or other peripheral devices are there speed and CPU speed does not match the problem, so it is necessary to establish the appropriate buffer. CAN port to send data, as long as the data is written to the buffer, and then removed one by one by the SJA1000 controller made out of. CAN receive data from the mouth, they often receive such number of bytes after the CPU needs to process, so these data can be received in advance stored in the buffer before. Buffer can be set to receive the number of bytes after the interruption of CPU, so as to avoid frequent interruptions and reduce the CPU system in real time.

μC / OS-II multi-task information flow and the CAN bus driver

In the process of reading and writing the buffer zone, often encounter want to send data, send the buffer is full; want to read, the receiver buffer is empty. For the end user program can work with queries that can not read and write operation to give up, and then frequently to try this operation until the success of the efficiency of this process is clearly lower. If the introduction of reading and writing, respectively, two signals at both ends of the buffer to synchronize the operation, the problem will be solved. However, the user task write buffer is full, the signal quantity of sleep, so that CPU to run other tasks until the ISR data from the buffer time to go sleep and wake up to this task; Similarly, the user tasks like reading, but when the buffer is empty can also be the signal quantity of sleep, when the external device has data to the re-awakening. Because μC / OS-II provides a semaphore wait timeout mechanism, CAN I of course have the ability to read and write timeouts.

With the amount of buffer and signals to send and receive part of the CAN port network, see Articles Supplementary Edition (http://www.dpj.com.cn).

Interface functions are summarized below.

void CanInitHW (UI segment, BYTE irq0, BYTE IRQ1)
/ * Set the SJA1000 controller port interrupt vector * /
int canReleaseHW () / * clear the SJA1000 controller port interrupt vector * /
int canSendMsg (CANBYTE port, MSG_STRUCT msg)
/ * SJA1000 controller to the custom port to send data * /
int canReceiveMsg (CANBYTE port, MSG_STRUCT msg_ptr)
/ * SJA1000 controller port to receive from the custom data
int canConfig (CANBYTE port, CAN_STRUCT can)
/ * Initialize and configure the SJA1000 controller * /
int canNormalRun (CANBYTE port)
/ * Set SJA1000 normal (Normal) operation mode * /
int canReset (CANBYTE port)
/ * SJA1000 controller port reset, the buffer Set 0xff * /
CANBYTE can0r (CANBYTE addr)
/ * Read custom SJA1000 controller port 0 register values * /
CANBYTE can1r (CANBYTE addr)
/ * Read the SJA1000 controller port 1 of the custom register value * /

Receive and transmit data buffer data structure definition:

typedef struct (
INT16U RingBufRxCtr; / * number of characters to receive buffer * /
OS_EVENT RingBufRxSem; / * Receive semaphore * /
INT8U RingBufRxInPtr; / * Receive buffer to write the next character position * /
INT8U RingBufRxOutPtr; / * Receive buffer to be read the next character position * /
INT8U RingBufRx [CAN_RX_BUF_SIZE]; / * receiver ring buffer * /
INT16U RingBufTxCtr;
/ * Send the number of characters in buffer * /
OS_EVENT * RingBufTxSem; / * send a semaphore * /
INT8U * RingBufTxInPtr;
/ * Send the buffer to write the next character position * /
INT8U * RingBufTxOutPtr;
/ * Send the buffer to be read the next character position * /
INT8U RingBufTx [CAN_TX_BUF_SIZE]; / * send the ring buffer * /
) CAN_RING_BUF;

Concluding Remarks

This article is in the field of application of embedded computer technology background made, after the end of the project development, system uptime more than 27 days. Hoped that this paper put forward on the development of embedded operating systems and technical personnel can help, but also hope that the same developers to explore areas of common development.

Declined comment

91精品综合久久久久久五月天_国产精品一区电影_中文字幕欧美日韩一区二区_亚洲一区二区三区精品动漫
免费特级黄色片| 久久精品视频中文字幕| 亚洲一区二区三区四区中文| 久久伊人精品视频| 国产精品丝袜一区二区三区| www欧美日韩| 三级精品视频久久久久| 久久久久免费视频| 国产成人涩涩涩视频在线观看| 色噜噜狠狠狠综合曰曰曰| 日韩中文字幕在线视频| 国产厕所精品在线观看| 久久综合久久综合这里只有精品| 97人人干人人| 97精品国产97久久久久久粉红 | 久久国产精品网| 国产h视频在线播放| 精品国产网站地址| 国产精品极品美女在线观看免费 | 久久成人精品视频| 欧美激情亚洲激情| 亚洲aa中文字幕| 欧美一级视频免费在线观看| 日韩女优中文字幕| 国内精品**久久毛片app| 国产另类第一区| 91福利视频网| 久久国产一区二区三区| 久久97久久97精品免视看| 亚洲国产精品视频一区| 日韩视频在线免费播放| 国内精品国产三级国产99| 99在线免费视频观看| 久草热视频在线观看| 国产成人拍精品视频午夜网站| 久久综合九色九九| 亚洲人成无码www久久久| 日本www在线播放| 国产一级片黄色| 久久爱av电影| 久久久久久com| 欧美一区亚洲一区| 高清一区二区三区日本久| 色婷婷综合久久久久| 欧美精品激情在线| 欧美一级成年大片在线观看| 国产美女高潮久久白浆| 久久精品国产精品国产精品污| 国产精品狼人色视频一区| 伊人婷婷久久| 欧美乱大交xxxxx潮喷l头像| 国产精品永久免费| 久久久999国产精品| 午夜欧美一区二区三区免费观看| 国产又大又硬又粗| 久久久久久久中文| 亚洲午夜精品久久久久久人妖| 欧美在线影院在线视频| 91精品91久久久久久| 精品国产一区二区三区日日嗨 | 欧美一级免费在线观看| 国产视频99| 国产成人久久精品| 亚洲影视中文字幕| 国内一区二区在线视频观看| 久久一区二区精品| 最新国产精品久久| 欧美精品与人动性物交免费看| 99电影网电视剧在线观看| 欧美成人四级hd版| 欧美在线播放一区二区| 久久免费成人精品视频| 一级一片免费播放| 国产日产亚洲精品| 国产精品私拍pans大尺度在线 | 国产中文字幕日韩| 日韩在线免费视频| 亚洲国产精品久久久久爰色欲 | 欧美日韩一区二区视频在线 | 久久五月天综合| 欧美亚洲一二三区| 国产成人91久久精品| 亚洲最大福利网| 国产日韩欧美视频| 国产精品久久精品| 精品人妻大屁股白浆无码| 九一免费在线观看| 日本一区不卡| 国产高清精品一区| 丁香六月激情网| 91精品国产91久久久久麻豆 主演| 欧美精品久久久久久久| 国产精品一香蕉国产线看观看| 九色成人免费视频| 分分操这里只有精品| 中文字幕精品一区日韩| 国产伦精品一区二区三区高清版 | 国产成人精品午夜| 欧美影视一区二区| 国产精品欧美风情| 国产在线拍偷自揄拍精品 | 日本不卡一区二区三区四区| 国产精品69久久久久| 久久久久久国产精品久久| 成人精品一区二区三区电影黑人| 亚洲午夜精品久久久久久人妖| 99在线观看| 日韩中文字幕组| 日韩中文字幕不卡视频| 欧美亚洲一二三区| 国产精品高清在线| 国产欧美欧洲| 亚洲精品女av网站| 国产二级片在线观看| 青青草国产精品视频| 久久久久99精品久久久久| 国产资源在线视频| 中文字幕剧情在线观看一区| 91av在线国产| 欧洲成人一区二区| 欧美成人精品三级在线观看| yellow视频在线观看一区二区| 性一交一乱一伧国产女士spa| 久久国产精品99久久久久久丝袜| 欧美最猛黑人xxxx黑人猛叫黄| 国产精品视频免费观看www| 国产欧美日韩免费| 日本在线观看不卡| 国产精品老女人视频| 99精品一级欧美片免费播放| 日本韩国在线不卡| 另类专区欧美制服同性| 成人精品视频一区二区| 日本人妻伦在线中文字幕| 国产精品极品美女在线观看免费| 91麻豆蜜桃| 欧美在线观看日本一区| 麻豆成人在线看| 久久久人人爽| 国产在线资源一区| 日日夜夜精品网站| 国产精品久久国产精品| 久久综合婷婷综合| 国产亚洲精品网站| 欧美在线视频一区二区三区| 一级一片免费播放| 国产精品日韩在线| 91久久综合亚洲鲁鲁五月天| 国语自产精品视频在线看一大j8| 亚洲成人av动漫| 久久天天躁狠狠躁夜夜躁2014| 国产成人综合久久| 国产欧美久久久久| 欧美xxxx黑人又粗又长密月| 午夜精品一区二区在线观看| 精品久久久久久中文字幕动漫| 国产不卡视频在线| 国产精选久久久久久| 欧美久久久久久一卡四| 午夜精品99久久免费| 欧美激情亚洲视频| 国产精品久久久久9999小说| 国产大尺度在线观看| 99se婷婷在线视频观看| 国产欧美精品久久久| 好吊色欧美一区二区三区| 天天综合中文字幕| 久久久久国色av免费观看性色| 国产精品美女主播| 俺也去精品视频在线观看| 国产精品96久久久久久又黄又硬| 国产乱淫av片杨贵妃| 国内自拍中文字幕| 欧美亚洲激情视频| 日本一区二区三区四区视频| 亚洲一区二区久久久久久久| 一区二区精品在线观看| 国产精品国产精品| 久久精品成人一区二区三区| 久久久国内精品| 91精品国产91久久久久久吃药| 国产精品一区二区三区免费观看| 欧美精品免费在线| 国产精品九九久久久久久久| 国产精品久久久亚洲| 国产精品女人网站| 国产精品三区四区| 国产欧美一区二区三区另类精品 | 国产高清一区视频| 国产精品12| 成人精品视频一区二区| 成人精品视频99在线观看免费| 国产欧美日韩中文| 成人免费在线网| 99三级在线| 91成人免费观看网站| 国产h视频在线播放| 日韩中文字幕国产精品| 日韩在线高清视频| 国产精品无码一本二本三本色|