forked from peng-zhihui/Dummy-Robot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
peng-zhihui
committed
Feb 9, 2022
1 parent
f0e2c8d
commit fe1007c
Showing
21 changed files
with
3,793 additions
and
3,705 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
184 changes: 89 additions & 95 deletions
184
2.Firmware/Core-STM32F4-fw/Bsp/communication/communication.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.