Disclosure of Invention
Aiming at the technical problems in the related art, the invention provides a coordinated sending method of a CAN shared mailbox, which is applied to a CAN communication system, wherein the system comprises N CAN, the N CAN are communicated through a CAN bus, the N CAN is provided with a top mailbox shared signal of the CAN, a CAN internal mailbox comprises a mail sending and a mail receiving, and the N is a positive integer larger than 1; the method comprises the following steps:
S1, an ith CAN_i sends a sending request of a mail [ i ] [ j ], and the mail [ i ] [ j ] has mail information;
s2, all CAN are polled, a j-th CAN_j is obtained to give out an answer signal ACK [ j ], and the mail [ i ] [ j ] is locked;
S3, the CAN_i receives and sends mail n information to the CAN_j; mail n information of CAN_i is sent from a CAN_j sending port;
and S4, after the CAN_j is sent, the ACK [ j ] of the CAN_j is pulled down.
Specifically, the step S4 further includes: s5, finishing the ACK response, continuing to poll the transmission request by CAN_i, waiting for the next coordinated transmission request, and waiting for the requests of other CAN to transmit to CAN_i.
Specifically, all CAN_n are polled, and whether responses are responded or not is checked in sequence;
CAN_0-CAN_j-1, no response;
CAN_j gives a response signal, and the mail [ i ] [ j ] is locked and not sent and changed by CAN_i.
Specifically, the step S4 specifically includes: after CAN_j responds, CAN_i receives and sends mail n information to CAN_j;
mail n information of CAN_i is sent from a CAN_j sending port;
Mail n of can_i is unlocked;
Manually updating the filling state of the mail [ i ] [ j ] of the CAN_i; the filling state of the mail [ i ] [ j ] of the CAN_i is updated manually, and specifically, the filling state of the mail [ i ] [ j ] of the CAN_i is updated through a DSP or other hosts.
Specifically, the step S1 specifically includes: CAN_i coordinates CAN_j to send request command CAN_REQ_i;
the CAN_REQ_i request is configured by a DSP or other host.
Specifically, can_i polls can_req_i [ j ] [ n ] and the filling state of mail n is not null and waits for a response can_ack_j [ i ] sent by can_j, then mail n of can_i is locked, mail n is not written by DSP or other host, and content of mail n is not sent by can_i.
Specifically, after the response, the mail n is locked, if CAN_i designates to send the mail n to the bus interface, the sending state of CAN_i is in a waiting state, and after the response of CAN_j is completed, the locking CAN be released, and CAN_i starts to send the mail n to the CAN bus interface; if CAN is sent sequentially and the response state of CAN_ACK_j [ i ] is pulled up, skipping mail n and continuing to send n+1 content.
Specifically, if the can_j coordinates to send the mail n information sent by the can_i, the can_ack_j [ i ] responds to complete, and can_i updates the filling state of the mail n, if the filling state of the mail n is cleared, can_i cannot be sent secondarily, and if the filling state of the mail n is not cleared, can_i CAN be sent secondarily.
In a second aspect, another embodiment of the present invention provides a coordinated sending method of a CAN shared mailbox, which is applied to a CAN communication system, where the system includes N CANs, the N CANs communicate through a CAN bus, the N CANs have top-level mailbox shared signals of the CAN, and a CAN internal mailbox includes sending and receiving mails, and the N is a positive integer greater than 1; the method comprises the following steps:
S1, under an idle state, CAN_j receives a coordinated transmission command of CAN_i, and CAN_j transmits a response CAN_ACK_j [ i ] to CAN_i;
s2, after the response, locking the sending function of the CAN_j bus interface, wherein CAN_j receives the mail n information of CAN_i, the mail n is not written into the internal mail of CAN_j, only the sending function of the bus interface of CAN_j is occupied, and the mail n information of CAN_i is sent through the bus interface of CAN_j;
S3, after the response, detecting a CAN_j bus interface sending completion signal, wherein the CAN_j sending response CAN_ACK_j [ i ] is pulled down, and the CAN_j releases the locking of a mailbox of the user.
S4, the CAN_j continues to be in an idle state, and polling is conducted to check the coordination transmission request of other CAN.
Specifically, after the response, the sending function of the CAN_j bus interface is locked, the CAN_j sends the mailbox lock of the CAN_j and cannot be sent out through the CAN_j bus interface, waiting is needed, the coordinated sending priority is highest, and only after the coordinated sending of the CAN_j is finished, the CAN_j mailbox CAN be sent to the bus interface of the CAN_j.
The invention adds the external signal of CAN, based on the original internal system network communication, realizes the mail information transmission method between mailboxes in the same chip system, greatly improves the access efficiency between the mailboxes and reduces the resource occupation of CAN bus.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which are derived by a person skilled in the art based on the embodiments of the invention, fall within the scope of protection of the invention.
Example 1
Referring to fig. 1, a CAN mailbox sharing method of the present embodiment is used in a CAN communication system, where the CAN communication system includes N CAN communication interfaces can_0..can_n, each of which has one or more mailboxes, that is, each of which CAN read and write a corresponding mailbox, and in the prior art, access operations are generally performed to internal mailboxes of the CAN through an on-chip system bus network (in which the on-chip system bus network is used to configure registers and mailbox contents of the CAN), such as an AMBA bus, and mail messages of the mailboxes of the CAN are triggered to be transferred to a CAN bus interface (in which the CAN bus interface is used to send/receive mails by the CAN), so as to perform transfer of mail messages between the CANs. This results in the transmission of mail messages between a plurality of CAN's in the same chip system, which is limited by the transmission rate of CAN's of 1Mbit/s via differential voltage signal lines.
Referring to fig. 2-3, this embodiment discloses a CAN mailbox sharing method, where each CAN mailbox CAN accept mailbox sharing status and control, and then control the mailbox according to the mailbox sharing status and control information. The state and control information shared by the mailbox in this embodiment are expressed by the response and control information to the corresponding command, for example, the ACK response to the read-write command, the CAN response to the coordinated transmission command, and the control information thereof. Reference is made to the following detailed description for specific implementations.
The mail sharing state and control information are mutually transferred between the CAN, and the mail transferring and receiving operation between the CAN CAN be completed by applying other mail boxes to coordinate the sending request, reading the mail information request of the other mail boxes, obtaining the working state of the other mail boxes, sending and receiving the mail operation of the other mail boxes, and returning the mail sharing information such as the empty and full state information of the other mail boxes or the self mail boxes. The working state of the mailbox of the embodiment comprises: mailbox lock determined by fate, mailbox reply command ACK, etc.; the empty and full state information of the mailbox is confirmed through the mailbox filling state. In the process of sending and receiving commands and executing the commands, the CAN interface of the embodiment outputs state information inside each CAN according to the running state of each CAN, and each CAN receives internal state information (such as mailbox filling, mail information and the like) from each CAN, and only confirms the state information of the CAN to be received through the commands to perform corresponding state response.
In this embodiment, taking can_0 as an example to coordinate other CAN shared mailboxes in the same chip system, a specific CAN external communication architecture is shown in fig. 1. For each CAN add-on peripheral signal, the add-on peripheral signal includes: the method comprises the steps of reading and writing a control signal wr_n [ n:0] of a mailbox, a chip selection signal cs_n [ n:0] of a CAN, a mailbox response signal ack_n [ n:0], a mail [ n ] sending request, a response of the CAN [ n ] to the mail sending request and the filling state of the mailbox, and judging the types of other CAN requests: mailbox read-write request, request for sending coordinated mails, CAN response of mail generation request and filling state of mailboxes among each other. Through the basic information, information sharing of the shared mail and resource coordination are completed.
The CAN sharing mailbox of the invention has 2 operation modes in total: reading and writing operations of mails and coordinated sending operations of mails.
First kind: reading and writing operations of mails: the mail read-write request wr_0[1 is that the n-th mail of the mailbox of CAN_1 is read-written by CAN_0, wherein the read operation does not modify the mailbox filling state, the write operation updates the filling state of the mailbox, and the read-write request command is confirmed to be received by which CAN by judging that each CAN responds to the request of CAN_0.
Second kind: coordinated sending operation of mails: the sending request of the mail n [0] is a sending request of an nth mailbox initiated by CAN_0, wherein the CAN_0 confirms which CAN the sending request command is received by a polling mode, once the sending request CAN_0 is confirmed, the coordinated sending function is locked by the receiving command CAN, and only if the sending completion or manual release of the command CAN is accepted, the CAN_0 CAN start the coordinated sending function. The filling state of the CAN mailbox of the received command cannot be updated, and after the completion of the transmission, the filling state of the CAN_0 mailbox needs to be manually updated. The manual update in this embodiment refers to the read-write operation of the filling status register of the mailbox through the DSP or other host.
And after the shared mailbox is sent in a coordinated manner, the filling state of the mailbox is not changed, the locking state of the mailbox is released, and at the moment, a user sends again according to the need or not, if the user does not need to send again, the DSP or other hosts clear the filling state bit of the mailbox, so that secondary sending is prevented, and CAN bus resources are saved. I.e. the present embodiment controls the filling status bit of the mailbox by the user if it is to be sent again (manually updated) as required. The manual meaning is that the flexibility of the user is increased, and the possibility that the user needs secondary transmission is increased.
Referring to fig. 4-5, the embodiment discloses a coordinated sending method of a CAN shared mailbox, which is applied to a CAN communication system, wherein the system comprises N CANs, the N CANs communicate through a CAN bus, the N CANs have top-level mailbox shared signals of the CAN, a CAN internal mailbox comprises a mail sending and mail receiving, and the N is a positive integer greater than 1;
The method comprises the following steps:
S1, an ith CAN_i sends a sending request of a mail [ i ] [ j ], and the mail [ i ] [ j ] has mail information;
Step S1 is specifically that CAN_i coordinates CAN_j to send a request command CAN_REQ_i;
the CAN_REQ_i request is configured by a DSP or other host.
S2, all CAN are polled, a j-th CAN_j is obtained to give out an answer signal ACK [ j ], and the mail [ i ] [ j ] is locked;
In the embodiment, CAN_i polls all CAN_n and sequentially checks whether to answer;
CAN_0-CAN_j-1, no response;
CAN_j gives a response signal, and the mail [ i ] [ j ] is locked and not sent and changed by CAN_i.
S3, the CAN_i receives and sends mail n information to the CAN_j; mail n information of CAN_i is sent from a CAN_j sending port;
s4, after the CAN_j is sent, the ACK [ j ] of the CAN_j is pulled down;
after CAN_j responds, CAN_i receives and sends mail n information to CAN_j;
mail n information of CAN_i is sent from a CAN_j sending port;
Mail n of can_i is unlocked;
The filling status of the mail i j of AN i is manually updated.
After ACK [ j ] is pulled low, the present embodiment further includes step S5: the ACK acknowledgement is completed, can_i continues to poll for a transmission request, waits for the next coordinated transmission request, and waits for requests for other CAN's to transmit to can_i.
Specifically, CAN_i starts from CAN_REQ_i [0] [0] to poll whether the request is valid (pulled high), if the request waits for a certain time without a response, the coordination sending command is manually canceled, otherwise, CAN_i always waits for the request response;
Can_i polls can_req_i [ j ] [ n ] to be pulled high, and the filling state of mail n is not null and waits for a response can_ack_j [ i ] sent by can_j, then mail n of can_i is locked, mail n is not written by DSP or other host, and the content of mail n is not sent by can_i.
After the response, CAN_i sends mail n information to CAN_j.
After the response, the mail n is locked, if CAN_i designates to send the mail n to the bus interface, the sending state of CAN_i is in a waiting state, and after the response of CAN_j is completed, the locking CAN be released, and CAN_i starts to send the mail n to the CAN bus interface; if CAN is sent sequentially and CAN_ACK_j [ i ] responds to the state (pulled high), skipping mail n and continuing to send n+1 content.
CAN_j coordinates the sending of the mail n information sent by CAN_i, CAN_ACK_j [ i ] responds to completion (pulling low), CAN_i updates the filling state of mail n, if the filling state of mail n is cleared, CAN_i cannot be sent secondarily, and if the filling state of mail n is not cleared, CAN_i CAN be sent secondarily.
In this embodiment can_i first sends a mail sending request, polls all CANs, when there is a CAN giving a response signal, sends a mail through the CAN giving the response, adds a peripheral signal of the CAN in the invention, on the basis of the original internal system network communication, the mail information transmission method between the mailboxes in the same chip system is realized, the access efficiency between the mailboxes is greatly improved, and the resource occupation of the CAN bus is reduced.
Example two
Referring to fig. 6, the embodiment discloses a coordinated sending method of a CAN shared mailbox, which is applied to a CAN communication system, wherein the system comprises N CANs, the N CANs communicate through a CAN bus, the N CANs have top-level mailbox shared signals of the CAN, a CAN internal mailbox comprises a mail sending and mail receiving function, and the N is a positive integer greater than 1;
the method is applied to sending mails in CAN_j, and comprises the following steps of:
S1, under an idle state, CAN_j receives a coordinated transmission command of CAN_i, and CAN_j transmits a response CAN_ACK_j [ i ] to CAN_i;
And the CAN_j receives a coordinated transmission command of the CAN_i, and receives a read-write mail n command in the CAN_j idle state, specifically, the CAN_j does not transmit a coordinated transmission command CAN_REQ_j to other CAN, the CAN_j does not transmit mails to a CAN bus interface, or the CAN_j bus interface is receiving other mail information.
In the CAN_j idle state, the received coordination transmission request is detected in a polling way, and when the CAN_j detects the command of a coordination transmission command CAN_REQ_i [ j ] [ n ] of the CAN_j, a response signal CAN_ACK_j [ i ] is transmitted to the CAN_i.
S2, after the response, locking the sending function of the CAN_j bus interface, wherein CAN_j receives the mail n information of CAN_i, the mail n is not written into the internal mail of CAN_j, only the sending function of the bus interface of CAN_j is occupied, and the mail n information of CAN_i is sent through the bus interface of CAN_j;
After the response, the sending function of the CAN_j bus interface is locked, but the internal mailbox of the CAN_j CAN be accessed by the chip system bus. After the response, the CAN_j receives the mail n information of the CAN_i, the mail n is not written into the internal mail of the CAN_j, only the sending function of the bus interface of the CAN_j is occupied, and the mail n information of the CAN_i is sent through the bus interface of the CAN_j.
After the response, locking the sending function of the CAN_j bus interface, wherein the CAN_j sends the self mailbox lock, CAN not be sent out through the CAN_j bus interface and needs to wait, at the moment, the coordinated sending priority is highest, and only after the CAN_j coordinated sending is finished, the CAN_j self mailbox CAN be sent to the CAN_j bus interface;
after the response, the sending function of the CAN_j bus interface is locked, but the internal mailbox of the CAN_j CAN be accessed by the chip system bus.
After the response, the CAN_j receives the mail n information of the CAN_i, the mail n is not written into the internal mail of the CAN_j, only the sending function of the bus interface of the CAN_j is occupied, and the mail n information of the CAN_i is sent through the bus interface of the CAN_j.
S3, after the response, detecting a CAN_j bus interface sending completion signal, wherein the CAN_j sending response CAN_ACK_j [ i ] is pulled down, and the CAN_j releases the locking of a mailbox of the user.
S4, the CAN_j continues to be in an idle state, and polling is conducted to check the coordination transmission request of other CAN.
The CAN of the embodiment polls the signals on the CAN bus, when the CAN is idle and gives out response signals, the mail is sent out through the CAN giving out response, the invention adds the peripheral signals of the CAN, on the basis of the original internal system network communication, the mail information transmission method between the mailboxes in the same chip system is realized, the access efficiency between the mailboxes is greatly improved, and the resource occupation of the CAN bus is reduced.
The foregoing description of the preferred embodiments of the invention is not intended to be limiting, but rather is intended to cover all modifications, equivalents, alternatives, and improvements that fall within the spirit and scope of the invention.