-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.h
239 lines (164 loc) · 6.48 KB
/
app.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*******************************************************************************
Porting of official MCP251xFDcanfdspiAPIforSAMV71_v1_1 on Raspberry Pico
developped by Pierpaolo Scorrano of SG Electronic Systems srls
www.sg-electronic-systems.com
Porting of official MCP251xFDcanfdspiAPIforSAMV71_v1_1 on Raspberry Pico
https://ww1.microchip.com/downloads/aemDocuments/documents/APID/ProductDocuments/SoftwareLibraries/Firmware/MCP251xFDcanfdspiAPIforSAMV71_v1_1.zip
*******************************************************************************/
/*******************************************************************************
Application: Header File
Company:
Microchip Technology Inc.
File Name:
app.h
Summary:
This header file contains the definitions and declarations for this simple application.
Description:
.
*******************************************************************************/
//DOM-IGNORE-BEGIN
/*******************************************************************************
Copyright (c) 2018 Microchip Technology Inc. and its subsidiaries.
Subject to your compliance with these terms, you may use Microchip software and
any derivatives exclusively with Microchip products. It is your responsibility
to comply with third party license terms applicable to your use of third party
software (including open source software) that may accompany Microchip software.
THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER EXPRESS,
IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES
OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER
RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF
THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT ALLOWED
BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO
THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID
DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
*******************************************************************************/
//DOM-IGNORE-END
#ifndef APP_H_
#define APP_H_
// Include files
#include "common.h"
// *****************************************************************************
// *****************************************************************************
// Section: Type Definitions
// *****************************************************************************
// *****************************************************************************
//#define TEST_SPI
//! Use RX and TX Interrupt pins to check FIFO status
//#define APP_USE_RX_INT
#define MAX_TXQUEUE_ATTEMPTS 50
// Switches
#define APP_DEBOUNCE_TIME 100
#define APP_SWITCH_PRESSED false
#define APP_SWITCH_RELEASED true
//#define APP_S1_READ() (ioport_get_pin_level(GPIO_PUSH_BUTTON_1))
// LEDs
#define APP_N_LED LED_COUNT
// Special LEDs
#define APP_INIT_LED 0
#define APP_LED_D1 1
#define APP_TX_LED 0
#define APP_RX_LED 1
#define APP_LED_TIME 50000
// Interrupts
/*#define INT_IN EXT1_PIN_9
#define INT_TX_IN EXT1_PIN_13
//#define INT_RX_IN EXT1_PIN_14
#define APP_INT() (!ioport_get_pin_level(INT_IN))
#define APP_TX_INT() (!ioport_get_pin_level(INT_TX_IN))
#define APP_RX_INT() (!ioport_get_pin_level(INT_RX_IN))
// Test output
#define TST1_OUT EXT1_PIN_5*/
// Message IDs
#define TX_REQUEST_ID 0x300
#define TX_RESPONSE_ID 0x301
#define BUTTON_STATUS_ID 0x201
#define LED_STATUS_ID 0x200
#define PAYLOAD_ID 0x101
// Transmit Channels
#define APP_TX_FIFO CAN_FIFO_CH2
// Receive Channels
#define APP_RX_FIFO CAN_FIFO_CH1
// Switch states
typedef struct {
bool S1;
} APP_SwitchState;
// Payload
typedef struct {
bool On;
uint8_t Dlc;
bool Mode;
uint8_t Counter;
uint8_t Delay;
bool BRS;
} APP_Payload;
// *****************************************************************************
/* Application states
Summary:
Application states enumeration
Description:
This enumeration defines the valid application states. These states
determine the behavior of the application at various times.
*/
typedef enum {
// Initialization
APP_STATE_INIT = 0,
APP_STATE_INIT_TXOBJ,
// POR signaling
APP_STATE_FLASH_LEDS,
// Transmit and Receive
APP_STATE_TRANSMIT,
APP_STATE_RECEIVE,
//APP_STATE_PAYLOAD,
// Test SPI access
APP_STATE_TEST_RAM_ACCESS,
APP_STATE_TEST_REGISTER_ACCESS,
// Switch monitoring
APP_STATE_SWITCH_CHANGED
} APP_STATES;
// *****************************************************************************
/* Application Data
Summary:
Holds application data
Description:
This structure holds the application's data.
Remarks:
Application strings and buffers are be defined outside this structure.
*/
typedef struct {
/* The application's current state */
APP_STATES state;
/* TODO: Define any additional data used by the application. */
} APP_DATA;
// *****************************************************************************
// *****************************************************************************
// Section: Application Initialization and State Machine Functions
// *****************************************************************************
// *****************************************************************************
//! Application Initialization
void APP_Initialize(void);
//! Application Tasks
// This routine must be called from SYS_Tasks() routine.
void APP_Tasks(void);
//! Write LEDs based on input byte
void APP_LED_Write(uint8_t led);
//! Clear One LED
void APP_LED_Clear(uint8_t led);
//! Set One LED
void APP_LED_Set(uint8_t led);
//! Initialize CANFDSPI
void APP_CANFDSPI_Init(void);
//! Add message to transmit FIFO
void APP_TransmitMessageQueue(void);
//! Decode received messages
APP_STATES APP_ReceiveMessage_Tasks(void);
//! Transmit switch state
//void APP_TransmitSwitchState(void);
//! Periodically send message with requested payload
//void APP_PayLoad_Tasks(void);
//! Test SPI access
uint8_t APP_TestRegisterAccess(void);
//! Test RAM access
uint8_t APP_TestRamAccess(void);
#endif /* APP_H_ */