Skip to content

Commit

Permalink
[Fw] Update REF protocols.
Browse files Browse the repository at this point in the history
  • Loading branch information
peng-zhihui committed Feb 9, 2022
1 parent f0e2c8d commit fe1007c
Show file tree
Hide file tree
Showing 21 changed files with 3,793 additions and 3,705 deletions.
2 changes: 1 addition & 1 deletion 2.Firmware/Core-STM32F4-fw/.idea/REF-STM32F4.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions 2.Firmware/Core-STM32F4-fw/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

184 changes: 89 additions & 95 deletions 2.Firmware/Core-STM32F4-fw/Bsp/communication/communication.cpp
Original file line number Diff line number Diff line change
@@ -1,95 +1,89 @@

/* Includes ------------------------------------------------------------------*/

#include "communication.hpp"
#include "common_inc.h"

/* Private defines -----------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
/* Global constant data ------------------------------------------------------*/
/* Global variables ----------------------------------------------------------*/
/* Private constant data -----------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
volatile bool endpointListValid = false;
/* Private function prototypes -----------------------------------------------*/
/* Function implementations --------------------------------------------------*/
// @brief Sends a line on the specified output.

osThreadId_t commTaskHandle;
const osThreadAttr_t commTask_attributes = {
.name = "commTask",
.stack_size = 10000 * 4,
.priority = (osPriority_t) osPriorityNormal,
};

void InitCommunication(void)
{
printf("\r\nHello, REF v%.1f Started!\r\n", CONFIG_FW_VERSION);

// Start command handling thread
commTaskHandle = osThreadNew(CommunicationTask, NULL, &commTask_attributes);

while (!endpointListValid)
osDelay(1);
}

extern PCD_HandleTypeDef hpcd_USB_OTG_FS;
osThreadId_t usbIrqTaskHandle;

void UsbDeferredInterruptTask(void* ctx)
{
(void) ctx; // unused parameter

for (;;)
{
// Wait for signalling from USB interrupt (OTG_FS_IRQHandler)
osStatus semaphore_status = osSemaphoreAcquire(sem_usb_irq, osWaitForever);
if (semaphore_status == osOK)
{
// We have a new incoming USB transmission: handle it
HAL_PCD_IRQHandler(&hpcd_USB_OTG_FS);
// Let the irq (OTG_FS_IRQHandler) fire again.
HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
}
}
}

// Thread to handle deffered processing of USB interrupt, and
// read commands out of the UART DMA circular buffer
void CommunicationTask(void* ctx)
{
(void) ctx; // unused parameter

CommitProtocol();

// Allow main init to continue
endpointListValid = true;

StartUartServer();
StartUsbServer();
StartCanServer(CAN1);
StartCanServer(CAN2);

for (;;)
{
osDelay(1000); // nothing to do
}
}

extern "C" {
int _write(int file, const char* data, int len);
}

// @brief This is what printf calls internally
int _write(int file, const char* data, int len)
{
#ifdef DEBUG_VIA_USB_SERIAL
usbStreamOutputPtr->process_bytes((const uint8_t*) data, len, nullptr);
uart4StreamOutputPtr->process_bytes((const uint8_t*) data, len, nullptr);
#endif

uart5StreamOutputPtr->process_bytes((const uint8_t*) data, len, nullptr);

return len;
}

/* Includes ------------------------------------------------------------------*/

#include "communication.hpp"
#include "common_inc.h"

/* Private defines -----------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/* Private typedef -----------------------------------------------------------*/
/* Global constant data ------------------------------------------------------*/
/* Global variables ----------------------------------------------------------*/
/* Private constant data -----------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
volatile bool endpointListValid = false;
/* Private function prototypes -----------------------------------------------*/
/* Function implementations --------------------------------------------------*/
// @brief Sends a line on the specified output.

osThreadId_t commTaskHandle;
const osThreadAttr_t commTask_attributes = {
.name = "commTask",
.stack_size = 45000,
.priority = (osPriority_t) osPriorityNormal,
};

void InitCommunication(void)
{
// Start command handling thread
commTaskHandle = osThreadNew(CommunicationTask, nullptr, &commTask_attributes);

while (!endpointListValid)
osDelay(1);
}

extern PCD_HandleTypeDef hpcd_USB_OTG_FS;
osThreadId_t usbIrqTaskHandle;

void UsbDeferredInterruptTask(void* ctx)
{
(void) ctx; // unused parameter

for (;;)
{
// Wait for signalling from USB interrupt (OTG_FS_IRQHandler)
osStatus semaphore_status = osSemaphoreAcquire(sem_usb_irq, osWaitForever);
if (semaphore_status == osOK)
{
// We have a new incoming USB transmission: handle it
HAL_PCD_IRQHandler(&hpcd_USB_OTG_FS);
// Let the irq (OTG_FS_IRQHandler) fire again.
HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
}
}
}

// Thread to handle deffered processing of USB interrupt, and
// read commands out of the UART DMA circular buffer
void CommunicationTask(void* ctx)
{
(void) ctx; // unused parameter

CommitProtocol();

// Allow main init to continue
endpointListValid = true;

StartUartServer();
StartUsbServer();
StartCanServer(CAN1);
StartCanServer(CAN2);

for (;;)
{
osDelay(1000); // nothing to do
}
}

extern "C" {
int _write(int file, const char* data, int len);
}

// @brief This is what printf calls internally
int _write(int file, const char* data, int len)
{
usbStreamOutputPtr->process_bytes((const uint8_t*) data, len, nullptr);
uart4StreamOutputPtr->process_bytes((const uint8_t*) data, len, nullptr);

return len;
}
Loading

0 comments on commit fe1007c

Please sign in to comment.