mirror of https://github.com/commaai/panda.git
parent
ed831773ea
commit
a2d0b87d4e
|
@ -1,26 +1,8 @@
|
|||
// Flasher and pedal use raw mailbox access
|
||||
#define GET_MAILBOX_BYTE(msg, b) (((int)(b) > 3) ? (((msg)->RDHR >> (8U * ((unsigned int)(b) % 4U))) & 0xFFU) : (((msg)->RDLR >> (8U * (unsigned int)(b))) & 0xFFU))
|
||||
#define GET_MAILBOX_BYTES_04(msg) ((msg)->RDLR)
|
||||
#define GET_MAILBOX_BYTES_48(msg) ((msg)->RDHR)
|
||||
|
||||
// SAE 2284-3 : minimum 16 tq, SJW 3, sample point at 81.3%
|
||||
#define CAN_QUANTA 16U
|
||||
#define CAN_SEQ1 12U
|
||||
#define CAN_SEQ2 3U
|
||||
#define CAN_SJW 3U
|
||||
|
||||
#define CAN_PCLK 48000U
|
||||
// 333 = 33.3 kbps
|
||||
// 5000 = 500 kbps
|
||||
#define can_speed_to_prescaler(x) (CAN_PCLK / CAN_QUANTA * 10U / (x))
|
||||
|
||||
#define CAN_NAME_FROM_CANIF(CAN_DEV) (((CAN_DEV)==CAN1) ? "CAN1" : (((CAN_DEV) == CAN2) ? "CAN2" : "CAN3"))
|
||||
|
||||
void print(const char *a);
|
||||
#include "llbxcan_declarations.h"
|
||||
|
||||
// kbps multiplied by 10
|
||||
const uint32_t speeds[] = {100U, 200U, 500U, 1000U, 1250U, 2500U, 5000U, 10000U};
|
||||
const uint32_t data_speeds[] = {0U}; // No separate data speed, dummy
|
||||
const uint32_t speeds[SPEEDS_ARRAY_SIZE] = {100U, 200U, 500U, 1000U, 1250U, 2500U, 5000U, 10000U};
|
||||
const uint32_t data_speeds[DATA_SPEEDS_ARRAY_SIZE] = {0U}; // No separate data speed, dummy
|
||||
|
||||
bool llcan_set_speed(CAN_TypeDef *CANx, uint32_t speed, bool loopback, bool silent) {
|
||||
bool ret = true;
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
#pragma once
|
||||
|
||||
// Flasher and pedal use raw mailbox access
|
||||
#define GET_MAILBOX_BYTE(msg, b) (((int)(b) > 3) ? (((msg)->RDHR >> (8U * ((unsigned int)(b) % 4U))) & 0xFFU) : (((msg)->RDLR >> (8U * (unsigned int)(b))) & 0xFFU))
|
||||
#define GET_MAILBOX_BYTES_04(msg) ((msg)->RDLR)
|
||||
#define GET_MAILBOX_BYTES_48(msg) ((msg)->RDHR)
|
||||
|
||||
// SAE 2284-3 : minimum 16 tq, SJW 3, sample point at 81.3%
|
||||
#define CAN_QUANTA 16U
|
||||
#define CAN_SEQ1 12U
|
||||
#define CAN_SEQ2 3U
|
||||
#define CAN_SJW 3U
|
||||
|
||||
#define CAN_PCLK 48000U
|
||||
// 333 = 33.3 kbps
|
||||
// 5000 = 500 kbps
|
||||
#define can_speed_to_prescaler(x) (CAN_PCLK / CAN_QUANTA * 10U / (x))
|
||||
|
||||
#define CAN_NAME_FROM_CANIF(CAN_DEV) (((CAN_DEV)==CAN1) ? "CAN1" : (((CAN_DEV) == CAN2) ? "CAN2" : "CAN3"))
|
||||
|
||||
void print(const char *a);
|
||||
|
||||
// kbps multiplied by 10
|
||||
#define SPEEDS_ARRAY_SIZE 8
|
||||
extern const uint32_t speeds[SPEEDS_ARRAY_SIZE];
|
||||
#define DATA_SPEEDS_ARRAY_SIZE 1
|
||||
extern const uint32_t data_speeds[DATA_SPEEDS_ARRAY_SIZE]; // No separate data speed, dummy
|
||||
|
||||
bool llcan_set_speed(CAN_TypeDef *CANx, uint32_t speed, bool loopback, bool silent);
|
||||
void llcan_irq_disable(const CAN_TypeDef *CANx);
|
||||
void llcan_irq_enable(const CAN_TypeDef *CANx);
|
||||
bool llcan_init(CAN_TypeDef *CANx);
|
||||
void llcan_clear_send(CAN_TypeDef *CANx);
|
|
@ -1,19 +1,8 @@
|
|||
#include "llusb_declarations.h"
|
||||
|
||||
USB_OTG_GlobalTypeDef *USBx = USB_OTG_FS;
|
||||
|
||||
#define USBx_HOST ((USB_OTG_HostTypeDef *)((uint32_t)USBx + USB_OTG_HOST_BASE))
|
||||
#define USBx_DEVICE ((USB_OTG_DeviceTypeDef *)((uint32_t)USBx + USB_OTG_DEVICE_BASE))
|
||||
#define USBx_INEP(i) ((USB_OTG_INEndpointTypeDef *)((uint32_t)USBx + USB_OTG_IN_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE)))
|
||||
#define USBx_OUTEP(i) ((USB_OTG_OUTEndpointTypeDef *)((uint32_t)USBx + USB_OTG_OUT_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE)))
|
||||
#define USBx_DFIFO(i) *(__IO uint32_t *)((uint32_t)USBx + USB_OTG_FIFO_BASE + ((i) * USB_OTG_FIFO_SIZE))
|
||||
#define USBx_PCGCCTL *(__IO uint32_t *)((uint32_t)USBx + USB_OTG_PCGCCTL_BASE)
|
||||
|
||||
#define USBD_FS_TRDT_VALUE 5UL
|
||||
#define USB_OTG_SPEED_FULL 3UL
|
||||
|
||||
|
||||
void usb_irqhandler(void);
|
||||
|
||||
void OTG_FS_IRQ_Handler(void) {
|
||||
static void OTG_FS_IRQ_Handler(void) {
|
||||
NVIC_DisableIRQ(OTG_FS_IRQn);
|
||||
//__disable_irq();
|
||||
usb_irqhandler();
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
extern USB_OTG_GlobalTypeDef *USBx;
|
||||
|
||||
#define USBx_HOST ((USB_OTG_HostTypeDef *)((uint32_t)USBx + USB_OTG_HOST_BASE))
|
||||
#define USBx_DEVICE ((USB_OTG_DeviceTypeDef *)((uint32_t)USBx + USB_OTG_DEVICE_BASE))
|
||||
#define USBx_INEP(i) ((USB_OTG_INEndpointTypeDef *)((uint32_t)USBx + USB_OTG_IN_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE)))
|
||||
#define USBx_OUTEP(i) ((USB_OTG_OUTEndpointTypeDef *)((uint32_t)USBx + USB_OTG_OUT_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE)))
|
||||
#define USBx_DFIFO(i) *(__IO uint32_t *)((uint32_t)USBx + USB_OTG_FIFO_BASE + ((i) * USB_OTG_FIFO_SIZE))
|
||||
#define USBx_PCGCCTL *(__IO uint32_t *)((uint32_t)USBx + USB_OTG_PCGCCTL_BASE)
|
||||
|
||||
#define USBD_FS_TRDT_VALUE 5UL
|
||||
#define USB_OTG_SPEED_FULL 3UL
|
||||
|
||||
|
||||
void usb_irqhandler(void);
|
||||
void usb_init(void);
|
|
@ -1,52 +1,10 @@
|
|||
// SAE J2284-4 document specifies a bus-line network running at 2 Mbit/s
|
||||
// SAE J2284-5 document specifies a point-to-point communication running at 5 Mbit/s
|
||||
|
||||
#define CAN_PCLK 80000U // KHz, sourced from PLL1Q
|
||||
#define BITRATE_PRESCALER 2U // Valid from 250Kbps to 5Mbps with 80Mhz clock
|
||||
#define CAN_SP_NOMINAL 80U // 80% for both SAE J2284-4 and SAE J2284-5
|
||||
#define CAN_SP_DATA_2M 80U // 80% for SAE J2284-4
|
||||
#define CAN_SP_DATA_5M 75U // 75% for SAE J2284-5
|
||||
#define CAN_QUANTA(speed, prescaler) (CAN_PCLK / ((speed) / 10U * (prescaler)))
|
||||
#define CAN_SEG1(tq, sp) (((tq) * (sp) / 100U)- 1U)
|
||||
#define CAN_SEG2(tq, sp) ((tq) * (100U - (sp)) / 100U)
|
||||
|
||||
// FDCAN core settings
|
||||
#define FDCAN_MESSAGE_RAM_SIZE 0x2800UL
|
||||
#define FDCAN_START_ADDRESS 0x4000AC00UL
|
||||
#define FDCAN_OFFSET 3384UL // bytes for each FDCAN module, equally
|
||||
#define FDCAN_OFFSET_W 846UL // words for each FDCAN module, equally
|
||||
#define FDCAN_END_ADDRESS 0x4000D3FCUL // Message RAM has a width of 4 bytes
|
||||
|
||||
// FDCAN_RX_FIFO_0_EL_CNT + FDCAN_TX_FIFO_EL_CNT can't exceed 47 elements (47 * 72 bytes = 3,384 bytes) per FDCAN module
|
||||
|
||||
// RX FIFO 0
|
||||
#define FDCAN_RX_FIFO_0_EL_CNT 46UL
|
||||
#define FDCAN_RX_FIFO_0_HEAD_SIZE 8UL // bytes
|
||||
#define FDCAN_RX_FIFO_0_DATA_SIZE 64UL // bytes
|
||||
#define FDCAN_RX_FIFO_0_EL_SIZE (FDCAN_RX_FIFO_0_HEAD_SIZE + FDCAN_RX_FIFO_0_DATA_SIZE)
|
||||
#define FDCAN_RX_FIFO_0_EL_W_SIZE (FDCAN_RX_FIFO_0_EL_SIZE / 4UL)
|
||||
#define FDCAN_RX_FIFO_0_OFFSET 0UL
|
||||
|
||||
// TX FIFO
|
||||
#define FDCAN_TX_FIFO_EL_CNT 1UL
|
||||
#define FDCAN_TX_FIFO_HEAD_SIZE 8UL // bytes
|
||||
#define FDCAN_TX_FIFO_DATA_SIZE 64UL // bytes
|
||||
#define FDCAN_TX_FIFO_EL_SIZE (FDCAN_TX_FIFO_HEAD_SIZE + FDCAN_TX_FIFO_DATA_SIZE)
|
||||
#define FDCAN_TX_FIFO_EL_W_SIZE (FDCAN_TX_FIFO_EL_SIZE / 4UL)
|
||||
#define FDCAN_TX_FIFO_OFFSET (FDCAN_RX_FIFO_0_OFFSET + (FDCAN_RX_FIFO_0_EL_CNT * FDCAN_RX_FIFO_0_EL_W_SIZE))
|
||||
|
||||
#define CAN_NAME_FROM_CANIF(CAN_DEV) (((CAN_DEV)==FDCAN1) ? "FDCAN1" : (((CAN_DEV) == FDCAN2) ? "FDCAN2" : "FDCAN3"))
|
||||
#define CAN_NUM_FROM_CANIF(CAN_DEV) (((CAN_DEV)==FDCAN1) ? 0UL : (((CAN_DEV) == FDCAN2) ? 1UL : 2UL))
|
||||
|
||||
|
||||
void print(const char *a);
|
||||
#include "llfdcan_declarations.h"
|
||||
|
||||
// kbps multiplied by 10
|
||||
const uint32_t speeds[] = {100U, 200U, 500U, 1000U, 1250U, 2500U, 5000U, 10000U};
|
||||
const uint32_t data_speeds[] = {100U, 200U, 500U, 1000U, 1250U, 2500U, 5000U, 10000U, 20000U, 50000U};
|
||||
const uint32_t speeds[SPEEDS_ARRAY_SIZE] = {100U, 200U, 500U, 1000U, 1250U, 2500U, 5000U, 10000U};
|
||||
const uint32_t data_speeds[DATA_SPEEDS_ARRAY_SIZE] = {100U, 200U, 500U, 1000U, 1250U, 2500U, 5000U, 10000U, 20000U, 50000U};
|
||||
|
||||
|
||||
bool fdcan_request_init(FDCAN_GlobalTypeDef *FDCANx) {
|
||||
static bool fdcan_request_init(FDCAN_GlobalTypeDef *FDCANx) {
|
||||
bool ret = true;
|
||||
// Exit from sleep mode
|
||||
FDCANx->CCCR &= ~(FDCAN_CCCR_CSR);
|
||||
|
@ -68,7 +26,7 @@ bool fdcan_request_init(FDCAN_GlobalTypeDef *FDCANx) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool fdcan_exit_init(FDCAN_GlobalTypeDef *FDCANx) {
|
||||
static bool fdcan_exit_init(FDCAN_GlobalTypeDef *FDCANx) {
|
||||
bool ret = true;
|
||||
|
||||
FDCANx->CCCR &= ~(FDCAN_CCCR_INIT);
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
#pragma once
|
||||
|
||||
// SAE J2284-4 document specifies a bus-line network running at 2 Mbit/s
|
||||
// SAE J2284-5 document specifies a point-to-point communication running at 5 Mbit/s
|
||||
|
||||
#define CAN_PCLK 80000U // KHz, sourced from PLL1Q
|
||||
#define BITRATE_PRESCALER 2U // Valid from 250Kbps to 5Mbps with 80Mhz clock
|
||||
#define CAN_SP_NOMINAL 80U // 80% for both SAE J2284-4 and SAE J2284-5
|
||||
#define CAN_SP_DATA_2M 80U // 80% for SAE J2284-4
|
||||
#define CAN_SP_DATA_5M 75U // 75% for SAE J2284-5
|
||||
#define CAN_QUANTA(speed, prescaler) (CAN_PCLK / ((speed) / 10U * (prescaler)))
|
||||
#define CAN_SEG1(tq, sp) (((tq) * (sp) / 100U)- 1U)
|
||||
#define CAN_SEG2(tq, sp) ((tq) * (100U - (sp)) / 100U)
|
||||
|
||||
// FDCAN core settings
|
||||
#define FDCAN_MESSAGE_RAM_SIZE 0x2800UL
|
||||
#define FDCAN_START_ADDRESS 0x4000AC00UL
|
||||
#define FDCAN_OFFSET 3384UL // bytes for each FDCAN module, equally
|
||||
#define FDCAN_OFFSET_W 846UL // words for each FDCAN module, equally
|
||||
#define FDCAN_END_ADDRESS 0x4000D3FCUL // Message RAM has a width of 4 bytes
|
||||
|
||||
// FDCAN_RX_FIFO_0_EL_CNT + FDCAN_TX_FIFO_EL_CNT can't exceed 47 elements (47 * 72 bytes = 3,384 bytes) per FDCAN module
|
||||
|
||||
// RX FIFO 0
|
||||
#define FDCAN_RX_FIFO_0_EL_CNT 46UL
|
||||
#define FDCAN_RX_FIFO_0_HEAD_SIZE 8UL // bytes
|
||||
#define FDCAN_RX_FIFO_0_DATA_SIZE 64UL // bytes
|
||||
#define FDCAN_RX_FIFO_0_EL_SIZE (FDCAN_RX_FIFO_0_HEAD_SIZE + FDCAN_RX_FIFO_0_DATA_SIZE)
|
||||
#define FDCAN_RX_FIFO_0_EL_W_SIZE (FDCAN_RX_FIFO_0_EL_SIZE / 4UL)
|
||||
#define FDCAN_RX_FIFO_0_OFFSET 0UL
|
||||
|
||||
// TX FIFO
|
||||
#define FDCAN_TX_FIFO_EL_CNT 1UL
|
||||
#define FDCAN_TX_FIFO_HEAD_SIZE 8UL // bytes
|
||||
#define FDCAN_TX_FIFO_DATA_SIZE 64UL // bytes
|
||||
#define FDCAN_TX_FIFO_EL_SIZE (FDCAN_TX_FIFO_HEAD_SIZE + FDCAN_TX_FIFO_DATA_SIZE)
|
||||
#define FDCAN_TX_FIFO_EL_W_SIZE (FDCAN_TX_FIFO_EL_SIZE / 4UL)
|
||||
#define FDCAN_TX_FIFO_OFFSET (FDCAN_RX_FIFO_0_OFFSET + (FDCAN_RX_FIFO_0_EL_CNT * FDCAN_RX_FIFO_0_EL_W_SIZE))
|
||||
|
||||
#define CAN_NAME_FROM_CANIF(CAN_DEV) (((CAN_DEV)==FDCAN1) ? "FDCAN1" : (((CAN_DEV) == FDCAN2) ? "FDCAN2" : "FDCAN3"))
|
||||
#define CAN_NUM_FROM_CANIF(CAN_DEV) (((CAN_DEV)==FDCAN1) ? 0UL : (((CAN_DEV) == FDCAN2) ? 1UL : 2UL))
|
||||
|
||||
|
||||
void print(const char *a);
|
||||
|
||||
// kbps multiplied by 10
|
||||
#define SPEEDS_ARRAY_SIZE 8
|
||||
extern const uint32_t speeds[SPEEDS_ARRAY_SIZE];
|
||||
#define DATA_SPEEDS_ARRAY_SIZE 10
|
||||
extern const uint32_t data_speeds[DATA_SPEEDS_ARRAY_SIZE];
|
||||
|
||||
bool llcan_set_speed(FDCAN_GlobalTypeDef *FDCANx, uint32_t speed, uint32_t data_speed, bool non_iso, bool loopback, bool silent);
|
||||
void llcan_irq_disable(const FDCAN_GlobalTypeDef *FDCANx);
|
||||
void llcan_irq_enable(const FDCAN_GlobalTypeDef *FDCANx);
|
||||
bool llcan_init(FDCAN_GlobalTypeDef *FDCANx);
|
||||
void llcan_clear_send(FDCAN_GlobalTypeDef *FDCANx);
|
|
@ -1,20 +1,8 @@
|
|||
#include "llusb_declarations.h"
|
||||
|
||||
USB_OTG_GlobalTypeDef *USBx = USB_OTG_HS;
|
||||
|
||||
#define USBx_HOST ((USB_OTG_HostTypeDef *)((uint32_t)USBx + USB_OTG_HOST_BASE))
|
||||
#define USBx_DEVICE ((USB_OTG_DeviceTypeDef *)((uint32_t)USBx + USB_OTG_DEVICE_BASE))
|
||||
#define USBx_INEP(i) ((USB_OTG_INEndpointTypeDef *)((uint32_t)USBx + USB_OTG_IN_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE)))
|
||||
#define USBx_OUTEP(i) ((USB_OTG_OUTEndpointTypeDef *)((uint32_t)USBx + USB_OTG_OUT_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE)))
|
||||
#define USBx_DFIFO(i) *(__IO uint32_t *)((uint32_t)USBx + USB_OTG_FIFO_BASE + ((i) * USB_OTG_FIFO_SIZE))
|
||||
#define USBx_PCGCCTL *(__IO uint32_t *)((uint32_t)USBx + USB_OTG_PCGCCTL_BASE)
|
||||
|
||||
#define USBD_FS_TRDT_VALUE 6UL
|
||||
#define USB_OTG_SPEED_FULL 3U
|
||||
#define DCFG_FRAME_INTERVAL_80 0U
|
||||
|
||||
|
||||
void usb_irqhandler(void);
|
||||
|
||||
void OTG_HS_IRQ_Handler(void) {
|
||||
static void OTG_HS_IRQ_Handler(void) {
|
||||
NVIC_DisableIRQ(OTG_HS_IRQn);
|
||||
usb_irqhandler();
|
||||
NVIC_EnableIRQ(OTG_HS_IRQn);
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
extern USB_OTG_GlobalTypeDef *USBx;
|
||||
|
||||
#define USBx_HOST ((USB_OTG_HostTypeDef *)((uint32_t)USBx + USB_OTG_HOST_BASE))
|
||||
#define USBx_DEVICE ((USB_OTG_DeviceTypeDef *)((uint32_t)USBx + USB_OTG_DEVICE_BASE))
|
||||
#define USBx_INEP(i) ((USB_OTG_INEndpointTypeDef *)((uint32_t)USBx + USB_OTG_IN_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE)))
|
||||
#define USBx_OUTEP(i) ((USB_OTG_OUTEndpointTypeDef *)((uint32_t)USBx + USB_OTG_OUT_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE)))
|
||||
#define USBx_DFIFO(i) *(__IO uint32_t *)((uint32_t)USBx + USB_OTG_FIFO_BASE + ((i) * USB_OTG_FIFO_SIZE))
|
||||
#define USBx_PCGCCTL *(__IO uint32_t *)((uint32_t)USBx + USB_OTG_PCGCCTL_BASE)
|
||||
|
||||
#define USBD_FS_TRDT_VALUE 6UL
|
||||
#define USB_OTG_SPEED_FULL 3U
|
||||
#define DCFG_FRAME_INTERVAL_80 0U
|
||||
|
||||
void usb_irqhandler(void);
|
||||
void usb_init(void);
|
Loading…
Reference in New Issue