Commit 1a597863 authored by smartinezs's avatar smartinezs
Browse files

solving bug on tx higher than 8 bits

parent 2535d0ee
......@@ -17,7 +17,7 @@
CAN_HandleTypeDef CANHandle;
CAN_FilterTypeDef CANFilterConfig;
CAN_TxHeaderTypeDef CAN_txHeader;
uint8_t *CAN_txMessage;
uint8_t CAN_txMessage[8];
uint32_t TxMailbox;
CAN_RxHeaderTypeDef CAN_rxHeader;
uint8_t CAN_rxMessage[8];
......@@ -123,6 +123,7 @@ void can_init(TComm *comm_dev,CAN_InitTypeDef *conf,TCAN_IRQ_Priorities *priorit
HAL_CAN_Start(&CANHandle);
//Activate default interrupt when message in FIFO0
HAL_CAN_ActivateNotification(&CANHandle, CAN_IT_RX_FIFO0_MSG_PENDING);
HAL_CAN_ActivateNotification(&CANHandle, CAN_IT_TX_MAILBOX_EMPTY);
}
void can_config(TComm *comm_dev,CAN_InitTypeDef *conf)
......@@ -217,7 +218,6 @@ void can_set_filter(TComm *comm_dev,CAN_FilterTypeDef *filter)
void can_set_can_id(TComm *comm_dev,unsigned int id)
{
CAN_txHeader.StdId = id;
//CANHandle.pTxMsg->StdId = id;
}
/**
......@@ -231,43 +231,6 @@ void HAL_CAN_ErrorCallback(CAN_HandleTypeDef* CANHandle)
//HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4,GPIO_PIN_SET);
}
void HAL_CAN_TxMailbox0CompleteCallback(CAN_HandleTypeDef* CANHandle)
{
if (can_send_lenght != 0)
{
if (can_send_lenght > 8)
{
CAN_txHeader.DLC = 8;
for (uint8_t i=0;i<8;i++)
{
CAN_txMessage[i] = can_send_data[i+(8*can_send_iterations)];
//CANHandle->pTxMsg->Data[i] = can_send_data[i+(8*can_send_iterations)];
}
can_send_lenght = can_send_lenght - 8;
can_send_iterations++;
//HAL_CAN_Transmit_IT(CANHandle);
HAL_CAN_AddTxMessage(CANHandle, &CAN_txHeader, CAN_txMessage, &TxMailbox);
}
else
{
//CANHandle->pTxMsg->DLC = can_send_lenght;
for (uint8_t i=0;i<can_send_lenght;i++)
{
CAN_txMessage[i] = can_send_data[i+(8*can_send_iterations)];
//CANHandle->pTxMsg->Data[i] = can_send_data[i+(8*can_send_iterations)];
}
can_send_lenght = 0;
can_send_iterations = 0;
//HAL_CAN_Transmit_IT(CANHandle);
HAL_CAN_AddTxMessage(CANHandle, &CAN_txHeader, CAN_txMessage, &TxMailbox);
uint8_t byte;
comm_do_dma_send(can_comm_dev);
comm_do_irq_send(can_comm_dev,&byte);
}
}
}
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef* CANHandle)
{
HAL_CAN_GetRxMessage(CANHandle, CAN_RX_FIFO0, &CAN_rxHeader, CAN_rxMessage);
......@@ -300,6 +263,8 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef* CANHandle)
else
{
if(can_missing_bytes_length<=8){
comm_cancel_irq_receive(can_comm_dev);
comm_cancel_dma_receive(can_comm_dev);
for(uint8_t i=0;i<CAN_rxHeader.DLC;i++)
{
can_missing_bytes_write_ptr++;
......@@ -312,14 +277,14 @@ void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef* CANHandle)
comm_do_irq_receive(can_comm_dev,can_missing_bytes_data[i]);
else
{
can_dma_phase_data[can_dma_phase_write_ptr]=can_missing_bytes_data[i];
can_dma_phase_length--;
can_dma_phase_write_ptr++;
if(can_dma_phase_length==0){
comm_do_dma_receive(can_comm_dev);
can_missing_bytes_length = 0;
can_missing_bytes_write_ptr = 0;
}
can_dma_phase_data[can_dma_phase_write_ptr]=can_missing_bytes_data[i];
can_dma_phase_length--;
can_dma_phase_write_ptr++;
if(can_dma_phase_length==0){
comm_do_dma_receive(can_comm_dev);
can_missing_bytes_length = 0;
can_missing_bytes_write_ptr = 0;
}
}
}
}
......@@ -372,8 +337,7 @@ unsigned char can_receive_irq(void)
{
can_dma_phase=0x00;
can_dma_phase_write_ptr=0x00;
//HAL_CAN_Receive_IT(&CANHandle,CAN_FIFO0);
HAL_CAN_GetRxMessage(&CANHandle, CAN_RX_FIFO0, &CAN_rxHeader, CAN_rxMessage);
//HAL_CAN_GetRxMessage(&CANHandle, CAN_RX_FIFO0, &CAN_rxHeader, CAN_rxMessage);
return 0x00;
}
......@@ -395,22 +359,12 @@ unsigned char can_send_dma(unsigned char *data,unsigned short int length)
}
can_send_lenght = length - 8;
can_send_iterations = 1;
// for (uint8_t i=0;i<8;i++)
// {
// CANHandle.pTxMsg->Data[i] = data[i];
// }
//HAL_CAN_Transmit_IT(&CANHandle);
HAL_CAN_AddTxMessage(&CANHandle, &CAN_txHeader, data, &TxMailbox);
}
else{
CAN_txHeader.DLC = length;
// for (uint8_t i=0;i<length;i++)
// {
// CANHandle.pTxMsg->Data[i] = data[i];
// }
can_send_lenght = 0;
can_send_iterations = 0;
//HAL_CAN_Transmit_IT(&CANHandle);
HAL_CAN_AddTxMessage(&CANHandle, &CAN_txHeader, data, &TxMailbox);
uint8_t byte;
comm_do_dma_send(can_comm_dev);
......@@ -419,6 +373,38 @@ unsigned char can_send_dma(unsigned char *data,unsigned short int length)
return 0x00;
}
void HAL_CAN_TxMailbox0CompleteCallback(CAN_HandleTypeDef* CANHandle)
{
if (can_send_lenght != 0)
{
if (can_send_lenght > 8)
{
CAN_txHeader.DLC = 8;
for (uint8_t i=0;i<8;i++)
{
CAN_txMessage[i] = can_send_data[i+(8*can_send_iterations)];
}
can_send_lenght = can_send_lenght - 8;
can_send_iterations++;
HAL_CAN_AddTxMessage(CANHandle, &CAN_txHeader, CAN_txMessage, &TxMailbox);
}
else
{
CAN_txHeader.DLC = can_send_lenght;
for (uint8_t i=0;i<can_send_lenght;i++)
{
CAN_txMessage[i] = can_send_data[i+(8*can_send_iterations)];
}
can_send_lenght = 0;
can_send_iterations = 0;
HAL_CAN_AddTxMessage(CANHandle, &CAN_txHeader, CAN_txMessage, &TxMailbox);
uint8_t byte;
comm_do_dma_send(can_comm_dev);
comm_do_irq_send(can_comm_dev,&byte);
}
}
}
unsigned char can_receive_dma(unsigned char *data,unsigned short int length)
{
can_dma_phase=0x01;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment