mirror of
https://github.com/infiniteCable2/panda.git
synced 2026-02-18 17:23:52 +08:00
Revert "fix openpilot board flashing" This reverts commit8ff93ad5da. Revert "Fixed output_enabled led not turning off when mode changed to no output." This reverts commit27a8af1107. Revert "Fixed loopback test for new GMLAN 'can4' behavior." This reverts commit59592f599a. Revert "GMLAN is now always mapped through CAN4 (index 3)" This reverts commit329c091024. Revert "Removed compile time config for CAN loopback, implemented as usb message." This reverts commite1a4c32985. Revert "Change all output safety mode identifier to prevent user mistakes." This reverts commit6b363e2e92. Revert "untabify" This reverts commit191f67b083. Revert "Refactor of safety to support more modular additions of safety policies." This reverts commite5b524eddc. Revert "Split up some more header files into compilation units." This reverts commite2a78912f5. Revert "Enabled emulated control writes over USB." This reverts commit133cfe9703. Revert "Moved CAN and USART code out of main.c and into more appropriate files." This reverts commitdaad2dc062. Revert "Large Panda CAN cleanup. Restrict GMLAN to valid baud rates." This reverts commita0616a2bc2. Revert "Panda library now correctly sends USB direction bit." This reverts commit1712c901d4. Revert "Board makefile now automatically calculates header file dependencies." This reverts commit4a8d4e597b. Revert "Loopback test works over wifi. (Disable trying to send over wifi)" This reverts commitdae636968a. Revert "Fix legacy board build" This reverts commit62bf4e5756. Revert "Style cop" This reverts commitc439f43726. Revert "Untabify" This reverts commit41e5eec621. Revert "Fixed disabling gmlan." This reverts commit5e1e45a4af. Revert "Removed dead code, standardized canid in more commands, better erroring behavior." This reverts commitb59aeb6d87. Revert "loopback test works with new CAN bus ids." This reverts commit75970861cf. Revert "Large reorganization of code and early integration of can bitrate setting." This reverts commita1ed7b62ee.
71 lines
1.7 KiB
C
71 lines
1.7 KiB
C
#define __DIV(_PCLK_, _BAUD_) (((_PCLK_)*25)/(4*(_BAUD_)))
|
|
#define __DIVMANT(_PCLK_, _BAUD_) (__DIV((_PCLK_), (_BAUD_))/100)
|
|
#define __DIVFRAQ(_PCLK_, _BAUD_) (((__DIV((_PCLK_), (_BAUD_)) - (__DIVMANT((_PCLK_), (_BAUD_)) * 100)) * 16 + 50) / 100)
|
|
#define __USART_BRR(_PCLK_, _BAUD_) ((__DIVMANT((_PCLK_), (_BAUD_)) << 4)|(__DIVFRAQ((_PCLK_), (_BAUD_)) & 0x0F))
|
|
|
|
void uart_set_baud(USART_TypeDef *u, int baud) {
|
|
if (u == USART1) {
|
|
// USART1 is on APB2
|
|
u->BRR = __USART_BRR(48000000, baud);
|
|
} else {
|
|
u->BRR = __USART_BRR(24000000, baud);
|
|
}
|
|
}
|
|
|
|
void uart_init(USART_TypeDef *u, int baud) {
|
|
// enable uart and tx+rx mode
|
|
u->CR1 = USART_CR1_UE;
|
|
uart_set_baud(u, baud);
|
|
|
|
u->CR1 |= USART_CR1_TE | USART_CR1_RE;
|
|
//u->CR2 = USART_CR2_STOP_0 | USART_CR2_STOP_1;
|
|
//u->CR2 = USART_CR2_STOP_0;
|
|
// ** UART is ready to work **
|
|
|
|
// enable interrupts
|
|
u->CR1 |= USART_CR1_RXNEIE;
|
|
}
|
|
|
|
void putch(const char a) {
|
|
if (has_external_debug_serial) {
|
|
putc(&debug_ring, a);
|
|
} else {
|
|
injectc(&debug_ring, a);
|
|
}
|
|
}
|
|
|
|
int puts(const char *a) {
|
|
for (;*a;a++) {
|
|
if (*a == '\n') putch('\r');
|
|
putch(*a);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void puth(unsigned int i) {
|
|
int pos;
|
|
char c[] = "0123456789abcdef";
|
|
for (pos = 28; pos != -4; pos -= 4) {
|
|
putch(c[(i >> pos) & 0xF]);
|
|
}
|
|
}
|
|
|
|
void puth2(unsigned int i) {
|
|
int pos;
|
|
char c[] = "0123456789abcdef";
|
|
for (pos = 4; pos != -4; pos -= 4) {
|
|
putch(c[(i >> pos) & 0xF]);
|
|
}
|
|
}
|
|
|
|
void hexdump(void *a, int l) {
|
|
int i;
|
|
for (i=0;i<l;i++) {
|
|
if (i != 0 && (i&0xf) == 0) puts("\n");
|
|
puth2(((unsigned char*)a)[i]);
|
|
puts(" ");
|
|
}
|
|
puts("\n");
|
|
}
|
|
|