Skip to content

Commit

Permalink
ctrl-f (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cam0Cow authored Oct 14, 2023
1 parent a0d1c0c commit c7af939
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Apps/Src/CommandLine.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ static bool cmd_CANbus_Read(void){
}

if(CANbus_Read(&msg, blocking, bus) == SUCCESS){
printf("msg recieved on %s (%s)\n\r", busInput, blockInput);
printf("msg received on %s (%s)\n\r", busInput, blockInput);
printf("ID: %d, Data: ", msg.ID);
for(int i = 0; i < 8; i++){
printf("[%d] %x \n\r", i, msg.data[i]);
Expand Down
2 changes: 1 addition & 1 deletion BSP/STM32F413/Src/BSP_UART.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ uint32_t BSP_UART_Read(UART_t usart, char *str) {
bool *line_recvd = lineRecvd[usart];

while(*line_recvd == false){
BSP_UART_Write(usart, "", 0); // needs to be in. Otherwise, usbLineRecieved will not update
BSP_UART_Write(usart, "", 0); // needs to be in. Otherwise, usbLineReceived will not update
}

USART_TypeDef *usart_handle = handles[usart];
Expand Down
2 changes: 1 addition & 1 deletion CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -11939,7 +11939,7 @@ typedef struct
#define ETH_DMASR_RPS_Waiting ((uint32_t)0x00060000) /* Running - waiting for packet */
#define ETH_DMASR_RPS_Suspended ((uint32_t)0x00080000) /* Suspended - Rx Descriptor unavailable */
#define ETH_DMASR_RPS_Closing ((uint32_t)0x000A0000) /* Running - closing descriptor */
#define ETH_DMASR_RPS_Queuing ((uint32_t)0x000E0000) /* Running - queuing the recieve frame into host memory */
#define ETH_DMASR_RPS_Queuing ((uint32_t)0x000E0000) /* Running - queuing the receive frame into host memory */
#define ETH_DMASR_NIS ((uint32_t)0x00010000) /* Normal interrupt summary */
#define ETH_DMASR_AIS ((uint32_t)0x00008000) /* Abnormal interrupt summary */
#define ETH_DMASR_ERS ((uint32_t)0x00004000) /* Early receive status */
Expand Down
4 changes: 2 additions & 2 deletions Docs/source/Drivers/CANBus.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Implementation Details
The microcontroller's CAN hardware block includes three sending and three receiving mailboxes, which act as a small queue of CAN messages.
The driver will write directly to the write mailboxes as long as they aren't full, and will block otherwise.

The receive mailboxes are constantly emptied (by the CAN recieve interrupt)
into a software queue in the BSP layer in order to deepen the queue (we recieve a lot of messages).
The receive mailboxes are constantly emptied (by the CAN receive interrupt)
into a software queue in the BSP layer in order to deepen the queue (we receive a lot of messages).
When reading, the driver will read directly from a software queue in the BSP layer. A non-blocking read will return an error if the queue is empty. A blocking read will block on a driver-layer semaphore, to be woken up when data is avilable.
Everytime the BSP software queue is posted to, a receive interrupt signals to a driver-layer semaphore that a message has been received. This allows any waiting tasks to wake up and read the message.
This is done since tasks that read and write CAN messages don't usually have anything else to do while waiting, which makes blocking fairly efficient.
Expand Down
2 changes: 1 addition & 1 deletion Drivers/Inc/CANbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ ErrorStatus CANbus_Send(CANDATA_t CanData,bool blocking, CAN_t bus);

/**
* @brief Reads a CAN message from the CAN hardware and returns it to the provided pointers.
* @param data pointer to where to store the CAN id of the recieved msg
* @param data pointer to where to store the CAN id of the received msg
* @param blocking Whether or not this read should be a blocking read
* @param bus The bus to use. This should either be CARCAN or MOTORCAN.
* @returns ERROR if read failed, SUCCESS otherwise
Expand Down
12 changes: 6 additions & 6 deletions Drivers/Src/CANbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
#include "CANConfig.h"

static OS_SEM CANMail_Sem4[NUM_CAN]; // sem4 to count how many sending hardware mailboxes we have left (start at 3)
static OS_SEM CANBus_RecieveSem4[NUM_CAN]; // sem4 to count how many msgs in our recieving queue
static OS_SEM CANBus_ReceiveSem4[NUM_CAN]; // sem4 to count how many msgs in our recieving queue
static OS_MUTEX CANbus_TxMutex[NUM_CAN]; // mutex to lock tx line
static OS_MUTEX CANbus_RxMutex[NUM_CAN]; // mutex to lock Rx line



/**
* @brief this function will be passed down to the BSP layer to trigger on RX events. Increments the recieve semaphore to signal message in hardware mailbox. Do not access directly outside this driver.
* @brief this function will be passed down to the BSP layer to trigger on RX events. Increments the receive semaphore to signal message in hardware mailbox. Do not access directly outside this driver.
* @param bus The CAN bus to operate on. Should be CARCAN or MOTORCAN.
*/
void CANbus_RxHandler(CAN_t bus)
{
OS_ERR err;
OSSemPost(&(CANBus_RecieveSem4[bus]), OS_OPT_POST_1, &err); // increment our queue counter
OSSemPost(&(CANBus_ReceiveSem4[bus]), OS_OPT_POST_1, &err); // increment our queue counter
assertOSError(OS_CANDRIVER_LOC,err);
}

Expand Down Expand Up @@ -95,7 +95,7 @@ ErrorStatus CANbus_Init(CAN_t bus, CANId_t* idWhitelist, uint8_t idWhitelistSize
OSSemCreate(&(CANMail_Sem4[bus]), (bus == CAN_1 ? "CAN Mailbox Semaphore 1":"CAN Mailbox Semaphore 3"), 3, &err); // there's 3 hardware mailboxes on the board, so 3 software mailboxes
assertOSError(OS_CANDRIVER_LOC,err);

OSSemCreate(&(CANBus_RecieveSem4[bus]), (bus == CAN_1 ? "CAN Recieved Msg Queue Ctr 1":"CAN Recieved Msg Queue Ctr 3"), 0, &err); // create a mailbox counter to hold the messages in as they come in
OSSemCreate(&(CANBus_ReceiveSem4[bus]), (bus == CAN_1 ? "CAN Received Msg Queue Ctr 1":"CAN Received Msg Queue Ctr 3"), 0, &err); // create a mailbox counter to hold the messages in as they come in
assertOSError(OS_CANDRIVER_LOC,err);

return SUCCESS;
Expand Down Expand Up @@ -188,7 +188,7 @@ ErrorStatus CANbus_Read(CANDATA_t* MsgContainer, bool blocking, CAN_t bus)
if (blocking == CAN_BLOCKING)
{
OSSemPend( // check if the queue actually has anything
&(CANBus_RecieveSem4[bus]),
&(CANBus_ReceiveSem4[bus]),
0,
OS_OPT_PEND_BLOCKING,
&timestamp,
Expand All @@ -197,7 +197,7 @@ ErrorStatus CANbus_Read(CANDATA_t* MsgContainer, bool blocking, CAN_t bus)
else
{
OSSemPend(
&(CANBus_RecieveSem4[bus]),
&(CANBus_ReceiveSem4[bus]),
0,
OS_OPT_PEND_NON_BLOCKING,
&timestamp,
Expand Down

0 comments on commit c7af939

Please sign in to comment.