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 46 of file openblt_usb.cpp.

46 {
47#if defined(OPEN_BLT_TEST_COMMAND)
48// 'z' is right at the end of 128 ascii range
49static_assert(BOOT_COM_RS232_RX_MAX_DATA < 'z');
50 if (firstByte == 'z') {
51 const char * bltTest = "openblt\n";
52 chnWriteTimeout(&SDU1, (const uint8_t*)bltTest, sizeof(bltTest), TIME_INFINITE);
53 }
54#endif // OPEN_BLT_TEST_COMMAND
55}
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 128 of file openblt_usb.cpp.

129{
130 if (!is_usb_serial_ready()) {
131 return BLT_FALSE;
132 }
133
134 auto bytesRead = chnReadTimeout(&SDU1, data, 1, TIME_IMMEDIATE);
135
136 return bytesRead == 0 ? BLT_FALSE : BLT_TRUE;
137}
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 64 of file openblt_usb.cpp.

65{
66 static blt_int8u xcpCtoReqPacket[BOOT_COM_RS232_RX_MAX_DATA+1]; /* one extra for length */
67 static blt_int8u xcpCtoRxLength;
68 static blt_bool xcpCtoRxInProgress = BLT_FALSE;
69 static blt_int32u xcpCtoRxStartTime = 0;
70
71 /* start of cto packet received? */
72 if (xcpCtoRxInProgress == BLT_FALSE)
73 {
74 /* store the message length when received */
75 if (Rs232ReceiveByte(&xcpCtoReqPacket[0]) == BLT_TRUE)
76 {
77 if ( (xcpCtoReqPacket[0] > 0) &&
78 (xcpCtoReqPacket[0] <= BOOT_COM_RS232_RX_MAX_DATA) )
79 {
80 /* store the start time */
81 xcpCtoRxStartTime = TimerGet();
82 /* reset packet data count */
83 xcpCtoRxLength = 0;
84 /* indicate that a cto packet is being received */
85 xcpCtoRxInProgress = BLT_TRUE;
86 } else {
87 openBltUnexpectedByte(xcpCtoReqPacket[0]);
88 }
89 }
90 }
91 else
92 {
93 /* store the next packet byte */
94 if (Rs232ReceiveByte(&xcpCtoReqPacket[xcpCtoRxLength+1]) == BLT_TRUE)
95 {
96 /* increment the packet data count */
97 xcpCtoRxLength++;
98
99 /* check to see if the entire packet was received */
100 if (xcpCtoRxLength == xcpCtoReqPacket[0])
101 {
102 /* copy the packet data */
103 CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength);
104 /* done with cto packet reception */
105 xcpCtoRxInProgress = BLT_FALSE;
106 /* set the packet length */
107 *len = xcpCtoRxLength;
108 /* packet reception complete */
109 return BLT_TRUE;
110 }
111 }
112 else
113 {
114 /* check packet reception timeout */
115 if (TimerGet() > (xcpCtoRxStartTime + RS232_CTO_RX_PACKET_TIMEOUT_MS))
116 {
117 /* cancel cto packet reception due to timeout. note that that automaticaly
118 * discards the already received packet bytes, allowing the host to retry.
119 */
120 xcpCtoRxInProgress = BLT_FALSE;
121 }
122 }
123 }
124 /* packet reception not yet complete */
125 return BLT_FALSE;
126} /*** 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 139 of file openblt_usb.cpp.

140{
141 chnWriteTimeout(&SDU1, &data, 1, TIME_INFINITE);
142}

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} /*** end of Rs232TransmitPacket ***/
static void Rs232TransmitByte(blt_int8u data)
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.