Commit 7dece4dc authored by Martin Jeřábek's avatar Martin Jeřábek Committed by Martin Jeřábek

driver: add missing linux includes/typedefs, fix some compile errors

parent 35d35708
......@@ -28,16 +28,14 @@
*
*******************************************************************************/
#ifndef __KERNEL__
# include "ctu_can_fd_linux_defs.h"
#endif
#include "ctu_can_fd_frame.h"
#include "ctu_can_fd_regs.h"
//#include "ctu_can_fd_regs.h"
#include "ctu_can_fd_hw.h"
#ifndef __linux__
#include "ctu_can_fd_linux_defs.h"
#endif
inline void ctu_can_fd_write32(void *base, enum ctu_can_fd_regs reg,
u32 val)
......@@ -92,14 +90,14 @@ static inline void ctu_can_fd_id_to_hwid(canid_t id, union ctu_can_fd_identifier
hwid->s.identifier_base = id & CAN_SFF_MASK;
}
static inline void ctu_can_fd_hwid_to_id(union ctu_can_fd_identifier_w hwid,
static inline void ctu_can_fd_hwid_to_id(union ctu_can_fd_identifier_w hwid,
canid_t *id,
enum ctu_can_fd_frame_form_w_id_type type)
{
// Preserve flags which we dont set
*id &= ~(CAN_EFF_FLAG | CAN_EFF_MASK);
if (type == EXTENDED){
if (type == EXTENDED){
*id |= CAN_EFF_FLAG;
*id |= hwid.s.identifier_base << 18;
*id |= hwid.s.identifier_ext;
......@@ -110,7 +108,7 @@ static inline void ctu_can_fd_hwid_to_id(union ctu_can_fd_identifier_w hwid,
static bool ctu_can_fd_len_to_dlc(u8 len, u8 *dlc)
{
if (len =< 8){
if (len <= 8){
*dlc = len;
goto exit_ok;
}
......@@ -133,9 +131,9 @@ static bool ctu_can_fd_len_to_dlc(u8 len, u8 *dlc)
default : *dlc = 0x0;
}
if (!dlc)
if (*dlc == 0)
return false;
exit:
exit_ok:
return true;
}
......@@ -178,7 +176,7 @@ bool ctu_can_fd_set_ret_limit(void *base, bool enable, u8 limit)
reg.u32 = ctu_can_fd_read32(base, CTU_CAN_FD_MODE);
reg.s.rtrle = enable ? RTRLE_ENABLED : RTRLE_DISABLED;
reg.s.rtrth = limit & 0xF;
reg.s.rtr_th = limit & 0xF;
ctu_can_fd_write32(base, CTU_CAN_FD_MODE, reg.u32);
return true;
}
......@@ -189,27 +187,27 @@ void ctu_can_fd_set_mode_reg(void *base, const struct can_ctrlmode *mode)
reg.u32 = ctu_can_fd_read32(base, CTU_CAN_FD_MODE);
if (mode->mask & CAN_CTRLMODE_LOOPBACK)
reg.s.int_loop = mode->flag & CAN_CTRLMODE_LOOPBACK ?
reg.s.int_loop = mode->flags & CAN_CTRLMODE_LOOPBACK ?
INT_LOOP_ENABLED : INT_LOOP_DISABLED;
if (mode->mask & CAN_CTRLMODE_LISTENONLY)
reg.s.lom = mode->flag & CAN_CTRLMODE_LISTENONLY ?
reg.s.lom = mode->flags & CAN_CTRLMODE_LISTENONLY ?
LOM_ENABLED : LOM_DISABLED;
if (mode->mask & CAN_CTRLMODE_3_SAMPLES)
reg.s.tsm = mode->flag & CAN_CTRLMODE_3_SAMPLES ?
reg.s.tsm = mode->flags & CAN_CTRLMODE_3_SAMPLES ?
TSM_ENABLE : TSM_DISABLE;
if (mode->mask & CAN_CTRLMODE_FD)
reg.s.fde = mode->flag & CAN_CTRLMODE_FD ?
reg.s.fde = mode->flags & CAN_CTRLMODE_FD ?
FDE_ENABLE : FDE_DISABLE;
if (mode->mask & CAN_CTRLMODE_PRESUME_ACK)
reg.s.stm = mode->flag & CAN_CTRLMODE_PRESUME_ACK ?
reg.s.stm = mode->flags & CAN_CTRLMODE_PRESUME_ACK ?
STM_ENABLED : STM_DISABLED;
if (mode->mask & CAN_CTRLMODE_FD_NON_ISO)
reg.s.fd_type = mode->flag & CAN_CTRLMODE_FD_NON_ISO ?
reg.s.fd_type = mode->flags & CAN_CTRLMODE_FD_NON_ISO ?
NON_ISO_FD : ISO_FD;
ctu_can_fd_write32(base, CTU_CAN_FD_MODE, reg.u32);
......@@ -737,7 +735,7 @@ bool ctu_can_fd_insert_frame(void *base, const unsigned char *data, u64 ts,
enum ctu_can_fd_regs buf;
union ctu_can_fd_frame_form_w ffw;
union ctu_can_fd_identifier_w idw;
struct canfd_frame *cf = (struct canfd_frame *)data;
struct canfd_frame *cf = (struct canfd_frame *)data; // TODO: may break alignment constraints
u8 dlc;
ffw.u32 = 0;
......
......@@ -31,6 +31,15 @@
#ifndef __CTU_CAN_FD_HW__
#define __CTU_CAN_FD_HW__
#include "ctu_can_fd_regs.h"
/*
MJ TODO:
- move small functions to *.h, make them inline
- either pass union arguments by value or just as u32;
this way they are forced on stack instead of passing in register
+ one level of pointer indirection, which sucks performance-wise
*/
#define CTU_CAN_FD_RETR_MAX 15
......@@ -145,7 +154,7 @@ u32 ctu_can_fd_get_version(const void *base);
* enable Enable/disable the core.
*
*/
void ctu_can_fd_enable(const void *base, bool enable);
void ctu_can_fd_enable(void *base, bool enable);
/*
......@@ -162,7 +171,7 @@ void ctu_can_fd_enable(const void *base, bool enable);
* Returns:
* True if set correctly. False if "limit" is too high.
*/
bool ctu_can_fd_set_ret_limit(void *base, bool enable, u8 limit)
bool ctu_can_fd_set_ret_limit(void *base, bool enable, u8 limit);
/*
......@@ -245,18 +254,6 @@ union ctu_can_fd_mode_command_status_settings ctu_can_get_status(const void *bas
union ctu_can_fd_int_stat ctu_can_fd_int_sts(const void *base);
/*
* Reads the interrupt status vector from CTU CAN FD Core.
*
* Arguments:
* base Pointer to the base address
* Returns:
* Interrupt status vector.
*/
union ctu_can_fd_int_stat ctu_can_fd_int_sts(const void *base);
/*
* Clears the interrupts from CTU CAN FD Core.
*
......@@ -320,7 +317,7 @@ void ctu_can_fd_set_nom_bittiming(void *base, struct can_bittiming *nbt);
* base Pointer to the base address
* nbt Data bit timing settings of CAN Controller.
*/
void ctu_can_fd_set_data_bittiming(void *base, struct can_bittiming *dbt)
void ctu_can_fd_set_data_bittiming(void *base, struct can_bittiming *dbt);
/*
......@@ -409,7 +406,7 @@ void ctu_can_fd_erase_fd_errs(void *base);
* Returns:
* Error state of the CTU CAN FD Core.
*/
enum can_state ctu_can_fd_read_error_state(const void *base)
enum can_state ctu_can_fd_read_error_state(const void *base);
/*
......
......@@ -35,6 +35,62 @@
#ifndef __CTU_CAN_FD_LINUX_DEFS__
#define __CTU_CAN_FD_LINUX_DEFS__
#include <stdint.h>
#include <stddef.h>
//#include <linux/types.h>
#include <linux/socket.h>
typedef uint8_t __u8;
typedef uint16_t __u16;
typedef uint32_t __u32;
typedef uint64_t __u64;
typedef int8_t __s8;
typedef int16_t __s16;
typedef int32_t __s32;
typedef int64_t __s64;
typedef __u8 u8;
typedef __u16 u16;
typedef __u32 u32;
typedef __u64 u64;
typedef __s8 s8;
typedef __s16 s16;
typedef __s32 s32;
typedef __s64 s64;
#ifndef __cplusplus
typedef _Bool bool;
enum {
false = 0,
true = 1
};
#endif
/*
// from include/uapi/linux/types.h
#define __bitwise
typedef __u16 __bitwise __le16;
typedef __u16 __bitwise __be16;
typedef __u32 __bitwise __le32;
typedef __u32 __bitwise __be32;
typedef __u64 __bitwise __le64;
typedef __u64 __bitwise __be64;
typedef __u16 __bitwise __sum16;
typedef __u32 __bitwise __wsum;
*/
static inline void iowrite32(u32 value, void *addr) {*(volatile u32*)addr = value;}
static inline void iowrite16(u16 value, void *addr) {*(volatile u16*)addr = value;}
static inline void iowrite8(u8 value, void *addr) {*(volatile u8*)addr = value;}
static inline u32 ioread32(const void *addr) {return *(const volatile u32*)addr;}
static inline u16 ioread16(const void *addr) {return *(const volatile u16*)addr;}
static inline u8 ioread8(const void *addr) {return *(const volatile u8*)addr;}
/*
* CAN bit-timing parameters
*
......@@ -204,8 +260,6 @@ enum {
#ifndef _UAPI_CAN_H
#define _UAPI_CAN_H
#include <linux/types.h>
#include <linux/socket.h>
......@@ -388,5 +442,7 @@ struct can_filter {
#define CAN_INV_FILTER 0x20000000U /* to be set in can_filter.can_id */
#define CAN_RAW_FILTER_MAX 512 /* maximum number of can_filter set via setsockopt() */
#endif /* _UAPI_CAN_H */
#endif
#endif /* __CTU_CAN_FD_LINUX_DEFS__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment