fix whitespace

The project uses tabs with a length of 4 spaces, and spaces for
continuation, so lets use that for the whole project. There are
many trailing whitespaces and empty lines here and there; get
rid of them as well.
This commit is contained in:
Jeroen Hofstee 2019-09-26 21:12:51 +02:00 committed by fenugrec
parent cd31acce28
commit 7618128cf6
11 changed files with 109 additions and 128 deletions

View File

@ -42,7 +42,7 @@ THE SOFTWARE.
#define GS_CAN_MODE_PAD_PKTS_TO_MAX_PKT_SIZE (1<<7)
#define GS_CAN_FEATURE_LISTEN_ONLY (1<<0)
#define GS_CAN_FEATURE_LISTEN_ONLY (1<<0)
#define GS_CAN_FEATURE_LOOP_BACK (1<<1)
#define GS_CAN_FEATURE_TRIPLE_SAMPLE (1<<2)
#define GS_CAN_FEATURE_ONE_SHOT (1<<3)
@ -73,7 +73,7 @@ THE SOFTWARE.
/* arbitration lost in bit ... / data[0] */
#define CAN_ERR_LOSTARB_UNSPEC 0x00 /* unspecified */
/* else bit number in bitstream */
/* else bit number in bitstream */
/* error status of CAN-controller / data[1] */
#define CAN_ERR_CRTL_UNSPEC 0x00 /* unspecified */
@ -83,8 +83,8 @@ THE SOFTWARE.
#define CAN_ERR_CRTL_TX_WARNING 0x08 /* reached warning level for TX errors */
#define CAN_ERR_CRTL_RX_PASSIVE 0x10 /* reached error passive status RX */
#define CAN_ERR_CRTL_TX_PASSIVE 0x20 /* reached error passive status TX */
/* (at least one error counter exceeds */
/* the protocol-defined level of 127) */
/* (at least one error counter exceeds */
/* the protocol-defined level of 127) */
#define CAN_ERR_CRTL_ACTIVE 0x40 /* recovered to error active state */
/* error in CAN protocol (type) / data[2] */

View File

@ -30,4 +30,3 @@ THE SOFTWARE.
extern USBD_DescriptorsTypeDef FS_Desc;
extern uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ];

View File

@ -30,7 +30,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32F0xx_HAL_CONF_H
@ -45,9 +45,9 @@
/* ########################## Module Selection ############################## */
/**
* @brief This is the list of modules to be used in the HAL driver
* @brief This is the list of modules to be used in the HAL driver
*/
#define HAL_MODULE_ENABLED
#define HAL_MODULE_ENABLED
/*#define HAL_ADC_MODULE_ENABLED */
/*#define HAL_CRYP_MODULE_ENABLED */
#define HAL_CAN_MODULE_ENABLED
@ -84,15 +84,15 @@
/**
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSE is used as system clock source, directly or through the PLL).
* (when HSE is used as system clock source, directly or through the PLL).
*/
#if !defined (HSE_VALUE)
#if !defined (HSE_VALUE)
#define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
/**
* @brief In the following line adjust the External High Speed oscillator (HSE) Startup
* Timeout value
* @brief In the following line adjust the External High Speed oscillator (HSE) Startup
* Timeout value
*/
#if !defined (HSE_STARTUP_TIMEOUT)
#define HSE_STARTUP_TIMEOUT ((uint32_t)100) /*!< Time out for HSE start up, in ms */
@ -101,52 +101,52 @@
/**
* @brief Internal High Speed oscillator (HSI) value.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSI is used as system clock source, directly or through the PLL).
* (when HSI is used as system clock source, directly or through the PLL).
*/
#if !defined (HSI_VALUE)
#define HSI_VALUE ((uint32_t)8000000) /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */
/**
* @brief In the following line adjust the Internal High Speed oscillator (HSI) Startup
* Timeout value
* @brief In the following line adjust the Internal High Speed oscillator (HSI) Startup
* Timeout value
*/
#if !defined (HSI_STARTUP_TIMEOUT)
#if !defined (HSI_STARTUP_TIMEOUT)
#define HSI_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for HSI start up */
#endif /* HSI_STARTUP_TIMEOUT */
#endif /* HSI_STARTUP_TIMEOUT */
/**
* @brief Internal High Speed oscillator for ADC (HSI14) value.
*/
#if !defined (HSI14_VALUE)
#if !defined (HSI14_VALUE)
#define HSI14_VALUE ((uint32_t)14000000) /*!< Value of the Internal High Speed oscillator for ADC in Hz.
The real value may vary depending on the variations
in voltage and temperature. */
The real value may vary depending on the variations
in voltage and temperature. */
#endif /* HSI14_VALUE */
/**
* @brief Internal High Speed oscillator for USB (HSI48) value.
*/
#if !defined (HSI48_VALUE)
#if !defined (HSI48_VALUE)
#define HSI48_VALUE ((uint32_t)48000000) /*!< Value of the Internal High Speed oscillator for USB in Hz.
The real value may vary depending on the variations
in voltage and temperature. */
The real value may vary depending on the variations
in voltage and temperature. */
#endif /* HSI48_VALUE */
/**
* @brief Internal Low Speed oscillator (LSI) value.
*/
#if !defined (LSI_VALUE)
#define LSI_VALUE ((uint32_t)40000)
#if !defined (LSI_VALUE)
#define LSI_VALUE ((uint32_t)40000)
#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
The real value may vary depending on the variations
in voltage and temperature. */
The real value may vary depending on the variations
in voltage and temperature. */
/**
* @brief External Low Speed oscillator (LSI) value.
*/
#if !defined (LSE_VALUE)
#define LSE_VALUE ((uint32_t)32768) /*!< Value of the External Low Speed oscillator in Hz */
#endif /* LSE_VALUE */
#endif /* LSE_VALUE */
#if !defined (LSE_STARTUP_TIMEOUT)
#define LSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for LSE start up, in ms */
@ -158,18 +158,18 @@
/* ########################### System Configuration ######################### */
/**
* @brief This is the HAL system configuration section
*/
#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */
#define TICK_INT_PRIORITY ((uint32_t)0) /*!< tick interrupt priority (lowest by default) */
/* Warning: Must be set to higher priority for HAL_Delay() */
/* and HAL_GetTick() usage under interrupt context */
#define USE_RTOS 0
#define PREFETCH_ENABLE 1
*/
#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */
#define TICK_INT_PRIORITY ((uint32_t)0) /*!< tick interrupt priority (lowest by default) */
/* Warning: Must be set to higher priority for HAL_Delay() */
/* and HAL_GetTick() usage under interrupt context */
#define USE_RTOS 0
#define PREFETCH_ENABLE 1
#define INSTRUCTION_CACHE_ENABLE 0
#define DATA_CACHE_ENABLE 0
/* ########################## Assert Selection ############################## */
/**
* @brief Uncomment the line below to expanse the "assert_param" macro in the
* @brief Uncomment the line below to expanse the "assert_param" macro in the
* HAL drivers code
*/
/* #define USE_FULL_ASSERT 1 */
@ -185,7 +185,7 @@
/* Includes ------------------------------------------------------------------*/
/**
* @brief Include module's header file
* @brief Include module's header file
*/
#ifdef HAL_RCC_MODULE_ENABLED
@ -298,7 +298,7 @@
* @brief The assert_param macro is used for function's parameters check.
* @param expr: If expr is false, it calls assert_failed function
* which reports the name of the source file and the source
* line number of the call that failed.
* line number of the call that failed.
* If expr is true, it returns no value.
* @retval None
*/
@ -307,8 +307,8 @@
void assert_failed(uint8_t* file, uint32_t line);
#else
#define assert_param(expr) ((void)0)
#endif /* USE_FULL_ASSERT */
#endif /* USE_FULL_ASSERT */
#ifdef __cplusplus
}
#endif

View File

@ -68,13 +68,13 @@ void can_enable(can_data_t *hcan, bool loop_back, bool listen_only, bool one_sho
uint32_t mcr = CAN_MCR_INRQ
| CAN_MCR_ABOM
| CAN_MCR_TXFP
| CAN_MCR_TXFP
| (one_shot ? CAN_MCR_NART : 0);
uint32_t btr = ((uint32_t)(hcan->sjw-1)) << 24
| ((uint32_t)(hcan->phase_seg1-1)) << 16
| ((uint32_t)(hcan->phase_seg2-1)) << 20
| (hcan->brp - 1)
| ((uint32_t)(hcan->phase_seg1-1)) << 16
| ((uint32_t)(hcan->phase_seg2-1)) << 20
| (hcan->brp - 1)
| (loop_back ? CAN_MODE_LOOPBACK : 0)
| (listen_only ? CAN_MODE_SILENT : 0);
@ -104,7 +104,6 @@ void can_enable(can_data_t *hcan, bool loop_back, bool listen_only, bool one_sho
can->FFA1R &= ~filter_bit; // assign filter 0 to FIFO 0
can->FA1R |= filter_bit; // enable filter
can->FMR &= ~CAN_FMR_FINIT;
}
void can_disable(can_data_t *hcan)
@ -133,7 +132,7 @@ bool can_receive(can_data_t *hcan, struct gs_host_frame *rx_frame)
CAN_FIFOMailBox_TypeDef *fifo = &can->sFIFOMailBox[0];
if (fifo->RIR & CAN_RI0R_IDE) {
rx_frame->can_id = CAN_EFF_FLAG | ((fifo->RIR >> 3) & 0x1FFFFFFF);
rx_frame->can_id = CAN_EFF_FLAG | ((fifo->RIR >> 3) & 0x1FFFFFFF);
} else {
rx_frame->can_id = (fifo->RIR >> 21) & 0x7FF;
}
@ -155,12 +154,9 @@ bool can_receive(can_data_t *hcan, struct gs_host_frame *rx_frame)
can->RF0R |= CAN_RF0R_RFOM0; // release FIFO
return true;
return true;
} else {
return false;
}
}

View File

@ -47,7 +47,6 @@ void flash_load()
bool flash_set_user_id(uint8_t channel, uint32_t user_id)
{
if (channel<NUM_CHANNEL) {
if (flash_data_ram.user_id[channel] != user_id) {
flash_data_ram.user_id[channel] = user_id;
flash_flush();
@ -70,7 +69,6 @@ uint32_t flash_get_user_id(uint8_t channel)
void flash_flush()
{
FLASH_EraseInitTypeDef erase_pages;
erase_pages.PageAddress = (uint32_t)&flash_data_rom;
erase_pages.NbPages = 1;

View File

@ -65,5 +65,4 @@ void gpio_init()
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LED2_GPIO_Port, &GPIO_InitStruct);
}

View File

@ -98,7 +98,6 @@ static void led_update_normal_mode(led_state_t *led)
static void led_update_sequence(led_data_t *leds)
{
if (leds->sequence == NULL) {
return;
}
@ -125,10 +124,8 @@ static void led_update_sequence(led_data_t *leds)
} else {
leds->sequence = NULL;
}
}
}
}
void led_update(led_data_t *leds)
@ -153,6 +150,4 @@ void led_update(led_data_t *leds)
led_set(&leds->led_state[0], false);
led_set(&leds->led_state[1], true);
}
}

View File

@ -83,7 +83,7 @@ void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
}
void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
{
{
USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, USBD_SPEED_FULL);
USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData);
}
@ -99,7 +99,7 @@ void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
}
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
{
{
/* Init USB_IP */
/* Link The driver to the stack */
hpcd_USB_FS.pData = pdev;

View File

@ -39,7 +39,7 @@ uint8_t *USBD_FS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *lengt
#ifdef USB_SUPPORT_USER_STRING_DESC
uint8_t *USBD_FS_USRStringDesc(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
#endif /* USB_SUPPORT_USER_STRING_DESC */
#endif /* USB_SUPPORT_USER_STRING_DESC */
USBD_DescriptorsTypeDef FS_Desc = {
USBD_FS_DeviceDescriptor,

View File

@ -48,7 +48,7 @@ typedef struct {
queue_t *q_frame_pool;
queue_t *q_from_host;
struct gs_host_frame *from_host_buf;
struct gs_host_frame *from_host_buf;
can_data_t *channels[NUM_CAN_CHANNEL];
@ -62,8 +62,7 @@ typedef struct {
bool timestamps_enabled;
uint32_t sof_timestamp_us;
bool pad_pkts_to_max_pkt_size;
bool pad_pkts_to_max_pkt_size;
} USBD_GS_CAN_HandleTypeDef __attribute__ ((aligned (4)));
static uint8_t USBD_GS_CAN_Start(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
@ -287,7 +286,6 @@ static const struct gs_device_bt_const USBD_GS_CAN_btconst = {
1, // brp increment;
};
uint8_t USBD_GS_CAN_Init(USBD_HandleTypeDef *pdev, queue_t *q_frame_pool, queue_t *q_from_host, led_data_t *leds)
{
uint8_t ret = USBD_FAIL;
@ -308,18 +306,16 @@ uint8_t USBD_GS_CAN_Init(USBD_HandleTypeDef *pdev, queue_t *q_frame_pool, queue_
return ret;
}
static uint8_t USBD_GS_CAN_Start(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
{
UNUSED(cfgidx);
uint8_t ret = USBD_FAIL;
if (pdev->pClassData) {
USBD_GS_CAN_HandleTypeDef *hcan = (USBD_GS_CAN_HandleTypeDef*) pdev->pClassData;
USBD_GS_CAN_HandleTypeDef *hcan = (USBD_GS_CAN_HandleTypeDef*) pdev->pClassData;
USBD_LL_OpenEP(pdev, GSUSB_ENDPOINT_IN, USBD_EP_TYPE_BULK, CAN_DATA_MAX_PACKET_SIZE);
USBD_LL_OpenEP(pdev, GSUSB_ENDPOINT_OUT, USBD_EP_TYPE_BULK, CAN_DATA_MAX_PACKET_SIZE);
hcan->from_host_buf = queue_pop_front(hcan->q_frame_pool);
hcan->from_host_buf = queue_pop_front(hcan->q_frame_pool);
USBD_GS_CAN_PrepareReceive(pdev);
ret = USBD_OK;
} else {
@ -354,9 +350,9 @@ void USBD_GS_CAN_SetChannel(USBD_HandleTypeDef *pdev, uint8_t channel, can_data_
}
static led_seq_step_t led_identify_seq[] = {
{ .state = 0x01, .time_in_10ms = 10 },
{ .state = 0x02, .time_in_10ms = 10 },
{ .state = 0x00, .time_in_10ms = 0 }
{ .state = 0x01, .time_in_10ms = 10 },
{ .state = 0x02, .time_in_10ms = 10 },
{ .state = 0x00, .time_in_10ms = 0 }
};
static uint8_t USBD_GS_CAN_EP0_RxReady(USBD_HandleTypeDef *pdev) {
@ -370,35 +366,35 @@ static uint8_t USBD_GS_CAN_EP0_RxReady(USBD_HandleTypeDef *pdev) {
USBD_SetupReqTypedef *req = &hcan->last_setup_request;
switch (req->bRequest) {
switch (req->bRequest) {
case GS_USB_BREQ_HOST_FORMAT:
// TODO process host data (expect 0x0000beef in byte_order)
memcpy(&hcan->host_config, hcan->ep0_buf, sizeof(hcan->host_config));
break;
case GS_USB_BREQ_HOST_FORMAT:
// TODO process host data (expect 0x0000beef in byte_order)
memcpy(&hcan->host_config, hcan->ep0_buf, sizeof(hcan->host_config));
break;
case GS_USB_BREQ_IDENTIFY:
memcpy(&param_u32, hcan->ep0_buf, sizeof(param_u32));
if (param_u32) {
led_run_sequence(hcan->leds, led_identify_seq, -1);
} else {
ch = hcan->channels[req->wValue]; // TODO verify wValue input data (implement getChannelData() ?)
led_set_mode(hcan->leds, can_is_enabled(ch) ? led_mode_normal : led_mode_off);
}
break;
case GS_USB_BREQ_IDENTIFY:
memcpy(&param_u32, hcan->ep0_buf, sizeof(param_u32));
if (param_u32) {
led_run_sequence(hcan->leds, led_identify_seq, -1);
} else {
ch = hcan->channels[req->wValue]; // TODO verify wValue input data (implement getChannelData() ?)
led_set_mode(hcan->leds, can_is_enabled(ch) ? led_mode_normal : led_mode_off);
}
break;
case GS_USB_BREQ_SET_USER_ID:
memcpy(&param_u32, hcan->ep0_buf, sizeof(param_u32));
if (flash_set_user_id(req->wValue, param_u32)) {
flash_flush();
}
break;
case GS_USB_BREQ_SET_USER_ID:
memcpy(&param_u32, hcan->ep0_buf, sizeof(param_u32));
if (flash_set_user_id(req->wValue, param_u32)) {
flash_flush();
}
break;
case GS_USB_BREQ_MODE:
if (req->wValue < NUM_CAN_CHANNEL) {
case GS_USB_BREQ_MODE:
if (req->wValue < NUM_CAN_CHANNEL) {
mode = (struct gs_device_mode*)hcan->ep0_buf;
ch = hcan->channels[req->wValue];
mode = (struct gs_device_mode*)hcan->ep0_buf;
ch = hcan->channels[req->wValue];
if (mode->mode == GS_CAN_MODE_RESET) {
@ -420,11 +416,11 @@ static uint8_t USBD_GS_CAN_EP0_RxReady(USBD_HandleTypeDef *pdev) {
led_set_mode(hcan->leds, led_mode_normal);
}
}
break;
break;
case GS_USB_BREQ_BITTIMING:
timing = (struct gs_device_bittiming*)hcan->ep0_buf;
if (req->wValue < NUM_CAN_CHANNEL) {
case GS_USB_BREQ_BITTIMING:
timing = (struct gs_device_bittiming*)hcan->ep0_buf;
if (req->wValue < NUM_CAN_CHANNEL) {
can_set_bittiming(
hcan->channels[req->wValue],
timing->brp,
@ -432,12 +428,12 @@ static uint8_t USBD_GS_CAN_EP0_RxReady(USBD_HandleTypeDef *pdev) {
timing->phase_seg2,
timing->sjw
);
}
break;
}
break;
default:
break;
}
}
req->bRequest = 0xFF;
return USBD_OK;
@ -498,7 +494,7 @@ static uint8_t USBD_GS_CAN_Config_Request(USBD_HandleTypeDef *pdev, USBD_SetupRe
case GS_USB_BREQ_TIMESTAMP:
memcpy(hcan->ep0_buf, &hcan->sof_timestamp_us, sizeof(hcan->sof_timestamp_us));
USBD_CtlSendData(pdev, hcan->ep0_buf, sizeof(hcan->sof_timestamp_us));
break;
break;
case GS_USB_BREQ_GET_USER_ID:
if (req->wValue < NUM_CAN_CHANNEL) {
@ -559,7 +555,6 @@ bool USBD_GS_CAN_CustomDeviceRequest(USBD_HandleTypeDef *pdev, USBD_SetupReqType
break;
}
}
return false;
@ -616,20 +611,20 @@ static uint8_t USBD_GS_CAN_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum) {
uint32_t rxlen = USBD_LL_GetRxDataSize(pdev, epnum);
if (rxlen >= (sizeof(struct gs_host_frame)-4)) {
struct gs_host_frame *frame = queue_pop_front_i(hcan->q_frame_pool);
struct gs_host_frame *frame = queue_pop_front_i(hcan->q_frame_pool);
if(frame){
queue_push_back_i(hcan->q_from_host, hcan->from_host_buf);
hcan->from_host_buf = frame;
retval = USBD_OK;
queue_push_back_i(hcan->q_from_host, hcan->from_host_buf);
hcan->from_host_buf = frame;
retval = USBD_OK;
}
else{
// Discard current packet from host if we have no place
// to put the next one
// Discard current packet from host if we have no place
// to put the next one
}
}
USBD_GS_CAN_PrepareReceive(pdev);
return retval;
return retval;
}
static uint8_t *USBD_GS_CAN_GetCfgDesc(uint16_t *len)
@ -680,21 +675,21 @@ uint8_t USBD_GS_CAN_GetPadPacketsToMaxPacketSize(USBD_HandleTypeDef *pdev)
uint8_t USBD_GS_CAN_SendFrame(USBD_HandleTypeDef *pdev, struct gs_host_frame *frame)
{
uint8_t buf[CAN_DATA_MAX_PACKET_SIZE],*send_addr;
uint8_t buf[CAN_DATA_MAX_PACKET_SIZE],*send_addr;
USBD_GS_CAN_HandleTypeDef *hcan = (USBD_GS_CAN_HandleTypeDef*)pdev->pClassData;
size_t len = sizeof(struct gs_host_frame);
if (!hcan->timestamps_enabled)
len -= 4;
len -= 4;
send_addr = (uint8_t *)frame;
if(hcan->pad_pkts_to_max_pkt_size){
// When talking to WinUSB it seems to help a lot if the
// When talking to WinUSB it seems to help a lot if the
// size of packet you send equals the max packet size.
// In this mode, fill packets out to max packet size and
// then send.
// In this mode, fill packets out to max packet size and
// then send.
memcpy(buf, frame, len);
// zero rest of buffer
@ -702,7 +697,7 @@ uint8_t USBD_GS_CAN_SendFrame(USBD_HandleTypeDef *pdev, struct gs_host_frame *fr
send_addr = buf;
len = sizeof(buf);
}
return USBD_GS_CAN_Transmit(pdev, send_addr, len);
}
@ -729,4 +724,3 @@ bool USBD_GS_CAN_DfuDetachRequested(USBD_HandleTypeDef *pdev)
USBD_GS_CAN_HandleTypeDef *hcan = (USBD_GS_CAN_HandleTypeDef*)pdev->pClassData;
return hcan->dfu_detach_requested;
}

View File

@ -27,15 +27,15 @@ THE SOFTWARE.
#include <util.h>
inline int disable_irq(void) {
int primask;
asm volatile("mrs %0, PRIMASK\n"
"cpsid i\n" : "=r"(primask));
return primask & 1;
int primask;
asm volatile("mrs %0, PRIMASK\n"
"cpsid i\n" : "=r"(primask));
return primask & 1;
}
inline void enable_irq(int primask) {
if (!primask)
asm volatile("cpsie i\n");
if (!primask)
asm volatile("cpsie i\n");
}
void hex32(char *out, uint32_t val)