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精品综合久久久久久五月天_国产精品一区电影_中文字幕欧美日韩一区二区_亚洲一区二区三区精品动漫
精品国产一二| 精品无码av无码免费专区| 精品一区二区视频| 欧美一区二区三区电影在线观看| 久久久久日韩精品久久久男男| 日本精品一区二区三区视频| 国产精品久久久久999| 福利视频久久| 国产精品稀缺呦系列在线| 日韩在线第三页| 亚洲最新免费视频| 一级做a爰片久久| 亚洲一区 在线播放| 国产成人精品在线观看| 国产片侵犯亲女视频播放| 亚洲va久久久噜噜噜久久天堂| 国产成人精彩在线视频九色| 欧美亚洲精品一区二区| 欧美xxxx做受欧美| 国产精品免费网站| 久久国产精品偷| 亚洲日本精品一区| 色噜噜一区二区| 久久精品国产一区二区三区| 国产精品一区久久| 99精品视频播放| 国产成人在线免费看| 国产欧美一区二区在线播放| 日韩国产精品毛片| 欧美日韩国产综合在线| 亚洲伊人第一页| 欧美激情第1页| 亚洲高清乱码| 欧美日韩一级在线| 国产一区二中文字幕在线看| 日本国产高清不卡| 黄色一级片网址| 成人免费视频久久| 68精品久久久久久欧美| 成人h在线播放| 国产精品91久久久久久| 99国产精品久久久久老师| 黄色99视频| 99中文字幕在线观看| 欧美一级特黄aaaaaa在线看片| 久久av.com| 亚洲一区二区三区香蕉| 欧美日本亚洲视频| 日韩在线观看成人| 欧美日韩爱爱视频| 亚洲欧洲中文| 欧美二区在线看| 99视频日韩| 久久久国产一区二区三区| 91美女福利视频高清| 国产一区二区三区四区五区在线| 日本精品一区在线观看| 亚洲v国产v在线观看| 一本色道婷婷久久欧美| 操91在线视频| 任我爽在线视频精品一| 人妻少妇精品无码专区二区| 日本精品视频在线观看| 一本色道久久99精品综合| 欧美精品福利在线| 日韩av影视| 高清视频一区| 日韩在线播放视频| 精品中文字幕在线观看| 国产精品精品视频一区二区三区| 九色91国产| 久久国产精品影片| 热99在线视频| 国产精品中文久久久久久久| 国产男女激情视频| 深夜福利91大全| 亚洲av首页在线| 国产尤物99| 国产成人av网| 亚洲色成人www永久在线观看| 中文字幕色呦呦| 欧美区高清在线| 久久99欧美| 亚洲欧美精品在线观看| 亚洲乱码一区二区三区 | 黄色片一级视频| 国产精品av网站| 久久97久久97精品免视看| 久久的精品视频| 日韩欧美视频第二区| 日韩精品在线观看av| 少妇av一区二区三区无码| 午夜精品免费视频| 国产在线精品一区二区三区 | 国产美女无遮挡网站| 国产中文字幕免费观看| 国产日韩欧美视频| 日韩视频一区在线| 热门国产精品亚洲第一区在线| 青青a在线精品免费观看| 日韩电影天堂视频一区二区| 亚洲影院色在线观看免费| 亚洲免费精品视频| 国产在线观看福利| 国产精品久久久av久久久| 久久久久国产精品免费| 亚洲一区二区免费| 国产精品自拍片| 欧美日韩xxx| 超碰国产精品久久国产精品99| 久久久这里只有精品视频| 国产成人精品免高潮在线观看| 久久精品国产综合精品| 欧美另类69精品久久久久9999 | 国产日韩精品电影| 99精品视频在线看| 伊人久久大香线蕉综合75 | 久久99国产综合精品女同| 亚洲一区久久久| 成人国产一区二区| 一区二区精品在线观看| 青青青青在线视频| 久久精品美女视频网站| 欧美激情综合亚洲一二区| 性欧美在线看片a免费观看| 欧美在线激情网| 国产精品丝袜久久久久久高清 | 欧美一级片在线播放| 欧美 日韩 国产精品| 国产精品自拍偷拍| 亚洲国产精品女人| 久久久久久久久久国产精品| 亚洲在线观看一区| 国产经品一区二区| 欧美视频免费看欧美视频| 91黄在线观看| 日韩人妻无码精品久久久不卡| 国产这里只有精品| 在线观看日本一区| 97精品久久久| 日韩免费毛片| 欧美激情日韩图片| 久久涩涩网站| 黄色网zhan| 亚洲国产精品久久久久久女王| 国产综合av一区二区三区| 国产福利精品视频| 欧美极品一区二区| 国产99在线|中文| 国产高清视频一区三区| 久久久久久999| 国产极品粉嫩福利姬萌白酱| 欧美激情综合色综合啪啪五月| 欧美深夜福利视频| 精品乱色一区二区中文字幕| 免费99视频| 亚洲一二三区精品| 国产成人免费观看| 91免费看国产| 五月天在线免费视频| 成人精品久久一区二区三区| 国产精品福利网站| 久久伊人资源站| 国产亚洲综合视频| 日韩欧美猛交xxxxx无码| 国产第一区电影| 国产专区欧美专区| 日韩视频在线视频| 久久99精品久久久久久噜噜| 国产在线视频欧美| 日产精品久久久一区二区| 国产精品91免费在线| 亚洲v国产v在线观看| y111111国产精品久久婷婷| 免费av一区二区| 久久国产乱子伦免费精品| 天堂а√在线中文在线| 91好吊色国产欧美日韩在线| 亚州国产精品久久久| 粉嫩av免费一区二区三区| 亚洲午夜精品久久| 国产精品久久久久久av福利| 韩日精品中文字幕| 色999日韩自偷自拍美女| 久久久av水蜜桃| 国产伦视频一区二区三区| 欧美激情一级欧美精品| 成人h视频在线观看| 懂色中文一区二区三区在线视频| 91精品国产91久久久久久最新| 亚洲va男人天堂| 久久99国产精品久久久久久久久| 成人精品视频一区二区| 婷婷久久青草热一区二区| 久久精品综合一区| 成人免费aaa| 国产伦精品一区| 国产一级黄色录像片| 亚洲最大激情中文字幕| 国产精品777|