Bar Logo 3.8/7.6 kw Totem pole Demonstration Application (Part-No. (not specified))
 
Content
     
Loading...
Searching...
No Matches
drv_i2c.h
Go to the documentation of this file.
1
10/*
11 (c) 2022 Microchip Technology Inc. and its subsidiaries. You may use this
12 software and any derivatives exclusively with Microchip products.
13
14 THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
15 EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
16 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
17 PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
18 WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
19
20 IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
21 INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
22 WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
23 BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
24 FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
25 ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
26 THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
27
28 MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
29 TERMS.
30*/
31
32// This is a guard condition so that contents of this file are not included
33// more than once.
34#ifndef DRV_I2C_H
35#define DRV_I2C_H
36
37#include <xc.h> // include processor files - each processor file is guarded.
38
39#include "i2c2.h"
40
41//------------------------------------------------------------------------------
42// macro definitions
43//------------------------------------------------------------------------------
44// I2C_WRITE_BUFFER_SIZE: buffer to store received data from I2C master
45#define I2C_WRITE_BUFFER_SIZE (9)
46
47// first byte transmitted from PIC16 is a "command" byte
48#define CMD_SEND_COMBINED_STATUS_DATA (0x43)
49
50// expect I2C message every 50ms, if not within this time of last message, set error flag
51#define I2C_TIMEOUT (60.0e-3) // in seconds
52
53// I2C_TIMEOUT in 100us ticks
54#define I2C_TIMEOUT_IN_100us_TICKS ((uint16_t)(I2C_TIMEOUT/100.0e-6))
55
56//------------------------------------------------------------------------------
57// typedefs
58//------------------------------------------------------------------------------
59
61
62 union {
63
64 struct {
65 volatile bool cmd_ok : 1;
66 volatile bool pec_ok : 1;
67 volatile bool done : 1;
68 volatile bool timeout : 1;
69 volatile unsigned : 1;
70 volatile unsigned : 1;
71 volatile unsigned : 1;
72 volatile unsigned : 1;
73 } __attribute__((packed)) bits; // data structure for single bit addressing operations
74
75 volatile uint8_t value; // buffer for 8-bit word read/write operations
76 };
77};
78typedef struct I2C_STATUS_s I2C_STATUS_t;
79
81
82 union {
83
84 struct {
85 volatile uint8_t sic1 : 2;
86 volatile uint8_t sic2 : 2;
87 volatile uint8_t sic3 : 2;
88 volatile uint8_t sic4 : 2;
89 } __attribute__((packed)) bits;
90 volatile uint8_t value;
91 };
92};
93typedef struct SIC_FLAGS_s SIC_FLAGS_t;
94
96
97 union {
98
99 struct {
100 volatile uint8_t _5v : 2;
101 volatile uint8_t _12v : 2;
102 volatile uint8_t _24v : 2;
103 volatile uint8_t : 2;
104 } __attribute__((packed)) bits;
105 volatile uint8_t value;
106 };
107};
109
111
112 union {
113
114 struct {
115 uint8_t command_id; // byte 0
117 uint8_t temp_sic1; // byte 2
118 uint8_t temp_sic2; // byte 3
119 uint8_t temp_sic3; // byte 4
120 uint8_t temp_sic4; // byte 5
122 uint8_t fan_duty;
123 // byte 7
124 uint8_t crc_rx; // byte 8
125 } __attribute__((packed)) bytes;
127 };
128};
130
137
138typedef struct I2C_s I2C_t;
139
140
141//------------------------------------------------------------------------------
142// Public data objects
143//------------------------------------------------------------------------------
144bool I2C2_StatusCallback(I2C2_SLAVE_DRIVER_STATUS status);
145I2C_t Drv_I2C_Get_Write_Data(void); // API function
146void Drv_I2C_Timeout(void);
147
148// Comment a function and leverage automatic documentation with slash star star
170#endif /* DRV_I2C_H */
171
void Drv_I2C_Timeout(void)
Definition drv_i2c.c:235
I2C_t Drv_I2C_Get_Write_Data(void)
Definition drv_i2c.c:68
bool I2C2_StatusCallback(I2C2_SLAVE_DRIVER_STATUS status)
Definition drv_i2c.c:82
#define I2C_WRITE_BUFFER_SIZE
Definition drv_i2c.h:45
size_t status
Definition uart1.c:99
volatile bool done
Bit #2: flag indicating that I2C module is finished processing this message.
Definition drv_i2c.h:67
volatile unsigned
Bit #4: unused
Definition drv_i2c.h:69
volatile bool cmd_ok
Bit #0: flag indicating the validity of the command byte.
Definition drv_i2c.h:65
struct I2C_STATUS_s::@3::@5 bits
volatile uint8_t value
Definition drv_i2c.h:75
volatile bool timeout
Bit #3: flag indicating that I2C message has not been received withing timeout period.
Definition drv_i2c.h:68
volatile bool pec_ok
Bit #1: flag indicating PEC error (CRC error in datastream)
Definition drv_i2c.h:66
volatile uint8_t sic4
Bit 6:7
Definition drv_i2c.h:88
struct SIC_FLAGS_s::@6::@8 bits
volatile uint8_t sic2
Bit 2:3
Definition drv_i2c.h:86
volatile uint8_t sic3
Bit 4:5
Definition drv_i2c.h:87
volatile uint8_t value
Definition drv_i2c.h:90
volatile uint8_t sic1
Bit 0:1
Definition drv_i2c.h:85
volatile uint8_t
Bit 6:7 -> 0 = no fault.
Definition drv_i2c.h:103
volatile uint8_t _24v
Bit 4:5 -> 0 = no fault.
Definition drv_i2c.h:102
struct AUX_FLAGS_s::@9::@11 bits
volatile uint8_t _5v
Bit 0:1 -> 0 = no fault
Definition drv_i2c.h:100
volatile uint8_t value
Definition drv_i2c.h:105
volatile uint8_t _12v
Bit 2:3 -> 0 = no fault.
Definition drv_i2c.h:101
uint8_t array[I2C_WRITE_BUFFER_SIZE]
Definition drv_i2c.h:126
struct SIC_CLIENT_RECEIVE_FRAME_s::@12::@14 bytes
SIC_FLAGS_t sic_status_flags
Definition drv_i2c.h:116
AUX_FLAGS_t aux_fault_flags
Definition drv_i2c.h:121
SIC_CLIENT_RECEIVE_FRAME_t frame
buffer to store I2C data
Definition drv_i2c.h:133
I2C_STATUS_t status
status flags
Definition drv_i2c.h:132
uint8_t crc
running crc
Definition drv_i2c.h:134
uint16_t timeout_counter
Definition drv_i2c.h:135