Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of Photon CAN bus Driver #790

Merged
merged 2 commits into from
Jan 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Release/*
*.d
*.o

# Unit test build folder
user/tests/unit/obj/*

# Platform-specific settings
.settings/*
.cproject
Expand Down
1 change: 1 addition & 0 deletions hal-dynalib/src/hal_can.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "hal_dynalib_can.h"
144 changes: 144 additions & 0 deletions hal/inc/can_hal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/**
******************************************************************************
* @file can_hal.h
* @author Brian Spranger, Julien Vanier
* @version V1.0.0
* @date 04-Jan-2016
* @brief
******************************************************************************
Copyright (c) 2013-2015 Particle Industries, Inc. All rights reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see <http://www.gnu.org/licenses/>.
******************************************************************************
*/

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __CAN_HAL_H
#define __CAN_HAL_H

#include <stdbool.h>

/* Includes ------------------------------------------------------------------*/
#include "pinmap_hal.h"

/* Exported defines ----------------------------------------------------------*/
#if PLATFORM_ID == 6 || PLATFORM_ID == 8 // Photon and P1
#define TOTAL_CAN 1
#define HAL_HAS_CAN_D1_D2
#elif PLATFORM_ID == 10 // Electron
#define TOTAL_CAN 2
#define HAL_HAS_CAN_D1_D2
#define HAL_HAS_CAN_C4_C5
#else
// Core
#define TOTAL_CAN 0
#endif

/* Exported constants --------------------------------------------------------*/

typedef enum HAL_CAN_Channel
{
#ifdef HAL_HAS_CAN_D1_D2
CAN_D1_D2,
#endif
#ifdef HAL_HAS_CAN_C4_C5
CAN_C4_C5,
#endif
} HAL_CAN_Channel;

// Flags for HAL_CAN_Begin
typedef enum HAL_CAN_Flags {
CAN_TEST_MODE = 0x0001,
} HAL_CAN_Flags;

typedef enum HAL_CAN_Errors {
CAN_NO_ERROR,
CAN_ERROR_PASSIVE,
CAN_BUS_OFF
} HAL_CAN_Errors;

typedef enum HAL_CAN_Filters {
CAN_FILTER_STANDARD,
CAN_FILTER_EXTENDED
} HAL_CAN_Filters;

/* Exported types ------------------------------------------------------------*/

struct CANMessage
{
uint32_t id;
uint8_t size;
bool extended;
bool rtr;
uint8_t len;
uint8_t data[8];

#ifdef __cplusplus
CANMessage()
: id { 0 },
size { sizeof(CANMessage) },
extended { false },
rtr { false },
len { 0 },
data { 0 }
{
}
#endif
};

/* Exported constants --------------------------------------------------------*/

/* Exported macros -----------------------------------------------------------*/

/* Exported functions --------------------------------------------------------*/

#ifdef __cplusplus
extern "C" {
#endif

void HAL_CAN_Init(HAL_CAN_Channel channel,
uint16_t rxQueueSize,
uint16_t txQueueSize,
void *reserved);
void HAL_CAN_Begin(HAL_CAN_Channel channel,
uint32_t baud,
uint32_t flags,
void *reserved);
void HAL_CAN_End(HAL_CAN_Channel channel,
void *reserved);
bool HAL_CAN_Transmit(HAL_CAN_Channel channel,
const CANMessage *message,
void *reserved);
bool HAL_CAN_Receive(HAL_CAN_Channel channel,
CANMessage *message,
void *reserved);
uint8_t HAL_CAN_Available_Messages(HAL_CAN_Channel channel,
void *reserved);
bool HAL_CAN_Add_Filter(HAL_CAN_Channel channel,
uint32_t id,
uint32_t mask,
HAL_CAN_Filters type,
void *reserved);
void HAL_CAN_Clear_Filters(HAL_CAN_Channel channel,
void *reserved);
bool HAL_CAN_Is_Enabled(HAL_CAN_Channel channel);
HAL_CAN_Errors HAL_CAN_Error_Status(HAL_CAN_Channel channel);


#ifdef __cplusplus
}
#endif

#endif /* __CAN_HAL_H */

49 changes: 49 additions & 0 deletions hal/inc/hal_dynalib_can.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
******************************************************************************
* @file hal_dynalib_can.h
* @authors Brian Spranger
* @date 01 October 2015
******************************************************************************
Copyright (c) 2015 Particle Industries, Inc. All rights reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, either
version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see <http://www.gnu.org/licenses/>.
******************************************************************************
*/

#ifndef HAL_DYNALIB_CAN_H
#define HAL_DYNALIB_CAN_H

#include "dynalib.h"

#ifdef DYNALIB_EXPORT
#include "can_hal.h"
#endif

DYNALIB_BEGIN(hal_can)

DYNALIB_FN(hal_can,HAL_CAN_Init)
DYNALIB_FN(hal_can,HAL_CAN_Begin)
DYNALIB_FN(hal_can,HAL_CAN_End)
DYNALIB_FN(hal_can,HAL_CAN_Transmit)
DYNALIB_FN(hal_can,HAL_CAN_Receive)
DYNALIB_FN(hal_can,HAL_CAN_Available_Messages)
DYNALIB_FN(hal_can,HAL_CAN_Add_Filter)
DYNALIB_FN(hal_can,HAL_CAN_Clear_Filters)
DYNALIB_FN(hal_can,HAL_CAN_Is_Enabled)
DYNALIB_FN(hal_can,HAL_CAN_Error_Status)

DYNALIB_END(hal_can)

#endif /* HAL_DYNALIB_CAN_H */

6 changes: 5 additions & 1 deletion hal/inc/interrupts_irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ typedef enum hal_irq_t {
SysInterrupt_CAN2_RX0_IRQ,
SysInterrupt_CAN2_RX1_IRQ,
SysInterrupt_CAN2_SCE_IRQ,
__Last_irq = 46
SysInterrupt_CAN1_TX_IRQ,
SysInterrupt_CAN1_RX0_IRQ,
SysInterrupt_CAN1_RX1_IRQ,
SysInterrupt_CAN1_SCE_IRQ,
__Last_irq = SysInterrupt_CAN1_SCE_IRQ + 1,
#else
__Last_irq = 0
#endif
Expand Down
20 changes: 12 additions & 8 deletions hal/src/electron/core_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ IDX[x] = added IRQ handler
32 [ ] DMA1_Stream5_IRQHandler // DMA1 Stream 5
33 [ ] DMA1_Stream6_IRQHandler // DMA1 Stream 6
34 [x] ADC_IRQHandler // ADC1, ADC2 and ADC3s
35 [ ] CAN1_TX_IRQHandler // CAN1 TX
36 [ ] CAN1_RX0_IRQHandler // CAN1 RX0
37 [ ] CAN1_RX1_IRQHandler // CAN1 RX1
38 [ ] CAN1_SCE_IRQHandler // CAN1 SCE
35 [x] CAN1_TX_IRQHandler // CAN1 TX
36 [x] CAN1_RX0_IRQHandler // CAN1 RX0
37 [x] CAN1_RX1_IRQHandler // CAN1 RX1
38 [x] CAN1_SCE_IRQHandler // CAN1 SCE
39 [x] EXTI9_5_IRQHandler // External Line[9:5]s
40 [x] TIM1_BRK_TIM9_IRQHandler // TIM1 Break and TIM9
41 [x] TIM1_UP_TIM10_IRQHandler // TIM1 Update and TIM10
Expand Down Expand Up @@ -174,6 +174,10 @@ const unsigned EXTI2_IRQHandler_Idx = 24;
const unsigned EXTI3_IRQHandler_Idx = 25;
const unsigned EXTI4_IRQHandler_Idx = 26;
const unsigned ADC_IRQHandler_Idx = 34;
const unsigned CAN1_TX_IRQHandler_Idx = 35;
const unsigned CAN1_RX0_IRQHandler_Idx = 36;
const unsigned CAN1_RX1_IRQHandler_Idx = 37;
const unsigned CAN1_SCE_IRQHandler_Idx = 38;
const unsigned EXTI9_5_IRQHandler_Idx = 39;
const unsigned TIM1_BRK_TIM9_IRQHandler_Idx = 40;
const unsigned TIM1_UP_TIM10_IRQHandler_Idx = 41;
Expand Down Expand Up @@ -251,6 +255,10 @@ void HAL_Core_Setup_override_interrupts(void)
isrs[EXTI3_IRQHandler_Idx] = (uint32_t)EXTI3_IRQHandler;
isrs[EXTI4_IRQHandler_Idx] = (uint32_t)EXTI4_IRQHandler;
isrs[ADC_IRQHandler_Idx] = (uint32_t)ADC_irq;
isrs[CAN1_TX_IRQHandler_Idx] = (uint32_t)CAN1_TX_irq;
isrs[CAN1_RX0_IRQHandler_Idx] = (uint32_t)CAN1_RX0_irq;
isrs[CAN1_RX1_IRQHandler_Idx] = (uint32_t)CAN1_RX1_irq;
isrs[CAN1_SCE_IRQHandler_Idx] = (uint32_t)CAN1_SCE_irq;
isrs[EXTI9_5_IRQHandler_Idx] = (uint32_t)EXTI9_5_IRQHandler;
isrs[TIM1_BRK_TIM9_IRQHandler_Idx] = (uint32_t)TIM1_BRK_TIM9_irq;
isrs[TIM1_UP_TIM10_IRQHandler_Idx] = (uint32_t)TIM1_UP_TIM10_irq;
Expand Down Expand Up @@ -601,10 +609,6 @@ void DMA1_Stream3_IRQHandler(void) {__ASM("bkpt 0");}
void DMA1_Stream4_IRQHandler(void) {__ASM("bkpt 0");}
void DMA1_Stream5_IRQHandler(void) {__ASM("bkpt 0");}
void DMA1_Stream6_IRQHandler(void) {__ASM("bkpt 0");}
void CAN1_TX_IRQHandler(void) {__ASM("bkpt 0");}
void CAN1_RX0_IRQHandler(void) {__ASM("bkpt 0");}
void CAN1_RX1_IRQHandler(void) {__ASM("bkpt 0");}
void CAN1_SCE_IRQHandler(void) {__ASM("bkpt 0");}
void I2C2_EV_IRQHandler(void) {__ASM("bkpt 0");}
void I2C2_ER_IRQHandler(void) {__ASM("bkpt 0");}
void SPI1_IRQHandler(void) {__ASM("bkpt 0");}
Expand Down
1 change: 1 addition & 0 deletions hal/src/newhal/sources.mk
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ CPPSRC += $(call target_files,$(overridedir)/,*.cpp)
# ASM source files included in this build.
ASRC +=

CPPFLAGS += -std=gnu++11


8 changes: 8 additions & 0 deletions hal/src/photon/core_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ const unsigned USART2Index = 54;
const unsigned ButtonExtiIndex = BUTTON1_EXTI_IRQ_INDEX;
const unsigned TIM7Index = 71;
const unsigned DMA2Stream2Index = 74;
const unsigned CAN2_TX_IRQHandler_Idx = 79;
const unsigned CAN2_RX0_IRQHandler_Idx = 80;
const unsigned CAN2_RX1_IRQHandler_Idx = 81;
const unsigned CAN2_SCE_IRQHandler_Idx = 82;
/**
* Updated by HAL_1Ms_Tick()
*/
Expand All @@ -73,6 +77,10 @@ void HAL_Core_Setup_override_interrupts(void) {
isrs[ButtonExtiIndex] = (uint32_t)Mode_Button_EXTI_irq;
isrs[TIM7Index] = (uint32_t)TIM7_override; // WICED uses this for a JTAG watchdog handler
isrs[DMA2Stream2Index] = (uint32_t)DMA2_Stream2_irq_override;
isrs[CAN2_TX_IRQHandler_Idx] = (uint32_t)CAN2_TX_irq;
isrs[CAN2_RX0_IRQHandler_Idx] = (uint32_t)CAN2_RX0_irq;
isrs[CAN2_RX1_IRQHandler_Idx] = (uint32_t)CAN2_RX1_irq;
isrs[CAN2_SCE_IRQHandler_Idx] = (uint32_t)CAN2_SCE_irq;
SCB->VTOR = (unsigned long)isrs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "stm32f2xx_syscfg.h"
#include "stm32f2xx_tim.h"
#include "stm32f2xx_usart.h"
#include "stm32f2xx_can.h"
#include "wwd_constants.h"
#include "RTOS/wwd_rtos_interface.h"
#include "ring_buffer.h"
Expand Down
Loading