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精品综合久久久久久五月天_国产精品一区电影_中文字幕欧美日韩一区二区_亚洲一区二区三区精品动漫
精品国产中文字幕| 欧美日韩一区二区三区免费| 久久久久久久久久久免费| 91精品综合视频| 久久人人看视频| 日韩在线视频中文字幕| 日日狠狠久久偷偷四色综合免费| 国产国语刺激对白av不卡| 久久手机在线视频| 色偷偷噜噜噜亚洲男人| 国产精品日韩欧美| 欧美激情一级精品国产| 亚洲**2019国产| 青青青国产精品一区二区| 黄色一级二级三级| 国产精品一区而去| 91极品视频在线| 日韩一级黄色av| 另类色图亚洲色图| 亚洲一区二区中文字幕| 日韩av片免费在线观看| 欧美性在线视频| 国产日韩在线亚洲字幕中文| 99久热re在线精品视频| 久久国产精品高清| 欧美成人在线网站| 视频一区国产精品| 国产在线xxxx| 国产成人91久久精品| 久久久精品影院| 亚洲熟女乱色一区二区三区 | 狠狠久久综合婷婷不卡| 国产伦精品一区二区三区四区视频_ | 国产女教师bbwbbwbbw| 91九色国产在线| 国产精品视频500部| 自拍视频一区二区三区| 欧美与黑人午夜性猛交久久久 | 日韩一级片一区二区| 欧美视频小说| 91蜜桃网站免费观看| 久久久国产视频| 亚洲一区二区三区香蕉| 黄色一级片播放| 88国产精品欧美一区二区三区| 国产精品天天狠天天看| 亚洲日本理论电影| 国产专区欧美专区| 久久久久久久久久久av| 亚洲一区二区三区四区视频| 欧美尤物一区| 久久免费看毛片| 久久久久久91香蕉国产| 欧美亚洲国产视频小说| 116极品美女午夜一级| 精品丰满人妻无套内射| 欧美福利一区二区三区| 久久人人爽人人爽人人av| 欧美精品xxx| 激情深爱综合网| www亚洲欧美| 日本在线精品视频| y111111国产精品久久婷婷| 国产精品久久av| 欧美一区二区影院| 国产高清免费在线| 亚洲人久久久| 国产精品午夜一区二区欲梦| 国产精品久久久影院| 日本久久久精品视频| 91精品国产电影| 在线播放豆国产99亚洲| 国内自拍欧美激情| 久久精品免费播放| 欧美亚州在线观看| 日韩一级裸体免费视频| 色播五月综合| 国产精品96久久久久久| 亚洲中文字幕无码专区| 国产美女精品视频| 国产精品黄色影片导航在线观看| 欧美在线视频二区| 日韩三级成人av网| 欧美在线www| 国产精品日韩欧美一区二区| 欧美亚洲国产日韩2020| 俺去了亚洲欧美日韩| 日韩精品一区二区三区四区五区| 国产v亚洲v天堂无码| 日韩久久一级片| xxx一区二区| 欧美精品自拍视频| 国产精品色视频| 国产一区免费观看| 欧美精品久久久久久久免费观看| 国产特级淫片高清视频| 久久国产精品亚洲| 国产三级中文字幕| 一区二区欧美日韩| 国产精品6699| 欧美在线播放cccc| 国产精品电影观看| www精品久久| 日韩aⅴ视频一区二区三区| 久久国产精品亚洲va麻豆 | 亚州欧美日韩中文视频| 久久久com| 欧美极品一区| 欧美激情精品久久久久久久变态 | 欧美一区少妇| 欧美精品午夜视频| 91久久在线视频| 青青视频免费在线| 欧美精品日韩www.p站| 成人毛片网站| 日韩欧美在线观看强乱免费| 国产精品麻豆va在线播放| 国产一区红桃视频| 无码人妻精品一区二区蜜桃百度| 久久亚洲a v| 精品欧美国产一区二区三区不卡| 欧美人与性动交a欧美精品| 国产精品av在线播放| 欧美中文字幕在线播放| 欧美成人精品在线播放| 7777精品久久久久久| 欧美精品一区二区三区在线四季| 精品国产一区二区三区日日嗨| 97人人模人人爽视频一区二区 | 国产极品在线视频| 欧美亚洲一区在线| 久久艹在线视频| 国产成人综合一区二区三区| 国内少妇毛片视频| 日韩中文字幕在线视频观看| 国产精品久久久久9999小说| 不卡影院一区二区| 欧美精品久久久久久久免费 | 日韩中文字幕一区| 萌白酱国产一区二区| 久久精品国产sm调教网站演员 | 欧美精品一区二区视频| 中文字幕无码精品亚洲35| 久久久久久久久电影| 国产精品一区二区三区在线播放| 欧美亚洲第一区| 午夜精品短视频| 精品免费二区三区三区高中清不卡| 久久精品五月婷婷| av不卡在线免费观看| 国产专区在线视频| 欧美亚洲在线视频| 午夜精品久久久久久久久久久久久 | 日韩中文字幕免费| 91久久久一线二线三线品牌| 韩国精品一区二区三区六区色诱| 色狠狠久久av五月综合| 在线免费一区| 国产精品精品久久久| 视频在线一区二区| 国产成人在线视频| 97国产在线播放| 国产精品综合网站| 国内精品中文字幕| 青青草成人网| 日韩高清国产精品| 日韩中文字幕在线视频观看| 亚洲在线免费视频| 欧美精品久久一区二区| 久久在线精品视频| 国产精品美女xx| 久久精品人人做人人爽| 色999日韩欧美国产| 久久免费视频在线观看| 99在线视频首页| 99久久久精品视频| www日韩在线观看| www久久99| 99视频精品免费| 91久久国产精品91久久性色| 成人久久18免费网站图片| 国产乱码精品一区二区三区中文| 国产综合色一区二区三区| 欧美亚洲日本网站| 欧美精品七区| 国产原创精品| 国产欧美在线看| 国产欧美日韩中文字幕| 国产一区二区在线视频播放| 国产一区二区色| 国产精品一区二区不卡视频| 国产精品一区二区三区免费观看| 国产精品中文久久久久久久| 国产精品自产拍高潮在线观看| 成人av中文| 91福利视频导航| 九九九九九九精品| 国产精品网红直播| 美女国内精品自产拍在线播放| 欧美激情亚洲国产|