rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions | Variables
openblt_usb.cpp File Reference

Functions

void Rs232Init ()
 
static blt_bool Rs232ReceiveByte (blt_int8u *data)
 
static void Rs232TransmitByte (blt_int8u data)
 
void Rs232TransmitPacket (blt_int8u *data, blt_int8u len)
 Transmits a packet formatted for the communication interface.
 
PUBLIC_API_WEAK void openBltUnexpectedByte (blt_int8u firstByte)
 
blt_bool Rs232ReceivePacket (blt_int8u *data, blt_int8u *len)
 Receives a communication interface packet if one is present.
 

Variables

blt_bool stayInBootloader
 

Function Documentation

◆ openBltUnexpectedByte()

PUBLIC_API_WEAK void openBltUnexpectedByte ( blt_int8u  firstByte)

Definition at line 49 of file openblt_usb.cpp.

49 {
50#if defined(OPEN_BLT_TEST_COMMAND)
51// 'z' is right at the end of 128 ascii range
52static_assert(BOOT_COM_RS232_RX_MAX_DATA < 'z');
53 if (firstByte == 'z') {
54 const char * bltTest = "openblt\n";
55 chnWriteTimeout(&SDU1, (const uint8_t*)bltTest, sizeof(bltTest), TIME_INFINITE);
56 }
57#endif // OPEN_BLT_TEST_COMMAND
58}
BaseChannel SDU1

Referenced by Rs232ReceivePacket().

Here is the caller graph for this function:

◆ Rs232Init()

void Rs232Init ( )

Definition at line 12 of file openblt_usb.cpp.

12 {
13#if (BOOT_BACKDOOR_ENTRY_TIMEOUT_MS == 0)
14 if (stayInBootloader || (NvmVerifyChecksum() == BLT_FALSE))
15#endif
16 {
17 // Set up USB serial
19 }
20}
void usb_serial_start(void)
Main function of PDL.
blt_bool NvmVerifyChecksum(void)
Verifies the checksum, which indicates that a valid user program is present and can be started.
Definition nvm.c:108
blt_bool stayInBootloader
Here is the call graph for this function:

◆ Rs232ReceiveByte()

static blt_bool Rs232ReceiveByte ( blt_int8u data)
static

Definition at line 131 of file openblt_usb.cpp.

132{
133 if (!is_usb_serial_ready()) {
134 return BLT_FALSE;
135 }
136
137 auto bytesRead = chnReadTimeout(&SDU1, data, 1, TIME_IMMEDIATE);
138
139 return bytesRead == 0 ? BLT_FALSE : BLT_TRUE;
140}
bool is_usb_serial_ready()

Referenced by Rs232ReceivePacket().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Rs232ReceivePacket()

blt_bool Rs232ReceivePacket ( blt_int8u data,
blt_int8u len 
)

Receives a communication interface packet if one is present.

Parameters
dataPointer to byte array where the data is to be stored.
lenPointer where the length of the packet is to be stored.
Returns
BLT_TRUE if a packet was received, BLT_FALSE otherwise.

Definition at line 67 of file openblt_usb.cpp.

68{
69 static blt_int8u xcpCtoReqPacket[BOOT_COM_RS232_RX_MAX_DATA+1]; /* one extra for length */
70 static blt_int8u xcpCtoRxLength;
71 static blt_bool xcpCtoRxInProgress = BLT_FALSE;
72 static blt_int32u xcpCtoRxStartTime = 0;
73
74 /* start of cto packet received? */
75 if (xcpCtoRxInProgress == BLT_FALSE)
76 {
77 /* store the message length when received */
78 if (Rs232ReceiveByte(&xcpCtoReqPacket[0]) == BLT_TRUE)
79 {
80 if ( (xcpCtoReqPacket[0] > 0) &&
81 (xcpCtoReqPacket[0] <= BOOT_COM_RS232_RX_MAX_DATA) )
82 {
83 /* store the start time */
84 xcpCtoRxStartTime = TimerGet();
85 /* reset packet data count */
86 xcpCtoRxLength = 0;
87 /* indicate that a cto packet is being received */
88 xcpCtoRxInProgress = BLT_TRUE;
89 } else {
90 openBltUnexpectedByte(xcpCtoReqPacket[0]);
91 }
92 }
93 }
94 else
95 {
96 /* store the next packet byte */
97 if (Rs232ReceiveByte(&xcpCtoReqPacket[xcpCtoRxLength+1]) == BLT_TRUE)
98 {
99 /* increment the packet data count */
100 xcpCtoRxLength++;
101
102 /* check to see if the entire packet was received */
103 if (xcpCtoRxLength == xcpCtoReqPacket[0])
104 {
105 /* copy the packet data */
106 CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength);
107 /* done with cto packet reception */
108 xcpCtoRxInProgress = BLT_FALSE;
109 /* set the packet length */
110 *len = xcpCtoRxLength;
111 /* packet reception complete */
112 return BLT_TRUE;
113 }
114 }
115 else
116 {
117 /* check packet reception timeout */
118 if (TimerGet() > (xcpCtoRxStartTime + RS232_CTO_RX_PACKET_TIMEOUT_MS))
119 {
120 /* cancel cto packet reception due to timeout. note that that automaticaly
121 * discards the already received packet bytes, allowing the host to retry.
122 */
123 xcpCtoRxInProgress = BLT_FALSE;
124 }
125 }
126 }
127 /* packet reception not yet complete */
128 return BLT_FALSE;
129} /*** end of Rs232ReceivePacket ***/
void CpuMemCopy(blt_addr dest, blt_addr src, blt_int16u len)
blt_int32u TimerGet()
PUBLIC_API_WEAK void openBltUnexpectedByte(blt_int8u firstByte)
static blt_bool Rs232ReceiveByte(blt_int8u *data)
unsigned char blt_int8u
Definition types.h:49
unsigned char blt_bool
Definition types.h:46
unsigned int blt_int32u
Definition types.h:53
Here is the call graph for this function:

◆ Rs232TransmitByte()

static void Rs232TransmitByte ( blt_int8u  data)
static

Definition at line 142 of file openblt_usb.cpp.

143{
144 chnWriteTimeout(&SDU1, &data, 1, TIME_INFINITE);
145}

Referenced by Rs232TransmitPacket().

Here is the caller graph for this function:

◆ Rs232TransmitPacket()

void Rs232TransmitPacket ( blt_int8u data,
blt_int8u  len 
)

Transmits a packet formatted for the communication interface.

Parameters
dataPointer to byte array with data that it to be transmitted.
lenNumber of bytes that are to be transmitted.
Returns
none.

Definition at line 34 of file openblt_usb.cpp.

35{
36
37 /* verify validity of the len-paramenter */
38 // ASSERT_RT(len <= BOOT_COM_RS232_TX_MAX_DATA);
39
40 /* first transmit the length of the packet */
42
43 chnWriteTimeout(&SDU1, data, len, TIME_INFINITE);
44
45 /* wait for transmission ends */
47} /*** end of Rs232TransmitPacket ***/
static void Rs232TransmitByte(blt_int8u data)
void usb_serial_flush()
Here is the call graph for this function:

Variable Documentation

◆ stayInBootloader

blt_bool stayInBootloader
extern

Definition at line 17 of file bootloader_main.cpp.

Referenced by main(), and Rs232Init().

Go to the source code of this file.