Bar Logo 3.8/7.6 kw Totem pole Demonstration Application (Part-No. (not specified))
 
Content
     
Loading...
Searching...
No Matches
main.c
1/*
2© [2023] Microchip Technology Inc. and its subsidiaries.
3
4 Subject to your compliance with these terms, you may use Microchip
5 software and any derivatives exclusively with Microchip products.
6 You are responsible for complying with 3rd party license terms
7 applicable to your use of 3rd party software (including open source
8 software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
9 NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
10 SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
11 MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
12 WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
13 INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
14 KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
15 MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
16 FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
17 TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
18 EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
19 THIS SOFTWARE.
20*/
21#include "mcc_generated_files/system/system.h"
22#include "mcc_generated_files/system/pins.h"
24#include "driver/can/drv_can.h"
25
26#include "dma/dma.h"
27#include "driver/dma/drv_dma.h"
28#include "driver/spi/drv_spi.h"
29
30#include "main.h"
31#include "spi_client/spi1.h"
32#include "sources/driver/i2c/i2c2.h"
33
34
35/*
36 Main application
37*/
38
39static __inline__ void SPI1_InitializeCustom(void);
40
41int main(void)
42{
44
45 // using non-melody drivers for I2C, so initialize separately
46 I2C2_Initialize();
47
48 // ensure that DMA is disabled until we have sync'd with SPI bus
49 // not using SPI CS pin, so need to enable SPI and DMA modules when
50 // SPI bus is idle
52
53 // melody based SPI initialization doesn't work, so replace
54 // with custom initialization for now
55// SPI1_Deinitialize();
56// SPI1_InitializeCustom();
57
59
61
62 //<<< initialize secondary core
65
66 //<<< initialize FIFO that is used to send data from secondary core to primary core
67 MSI1FIFOCSbits.RFEN = 1;
68 MSI1FIFOCSbits.WFEN = 0;
69
70
72
73 while(1)
74 {
75 Tasks_Background();
76
77 // simple 100us task driven by timer 1 (setup in MCC to expire after 100us)
78 // this process is polled, not interrupt driven
79 if (IFS0bits.T1IF)
80 {
81 Tasks_100us();
82 IFS0bits.T1IF = 0; // clear timer 1 flag
83 }
84 }
85}
86
87
94static __inline__ void SPI1_InitializeCustom(void)
95{
96 SPI1CON1H = 0x00;
97 // WLENGTH 0;
98 SPI1CON2L = 0x00;
99 // SPIROV disabled; FRMERR disabled;
100 SPI1STATL = 0x00;
101 // SPI1BRGL 0;
102 SPI1BRGL = 0x00;
103 // SPITBFEN disabled; SPITUREN disabled; FRMERREN disabled; SRMTEN disabled; SPIRBEN disabled; BUSYEN disabled; SPITBEN disabled; SPIROVEN disabled; SPIRBFEN enabled;
104 SPI1IMSKL = 0x01;
105 // RXMSK 4; TXWIEN disabled; TXMSK 0; RXWIEN disabled;
106 SPI1IMSKH = 0x400;
107 // SPI1URDTL 0;
108 SPI1URDTL = 0x00;
109 // SPI1URDTH 0;
110 SPI1URDTH = 0x00;
111 // SPIEN disabled; DISSDO disabled; MCLKEN FOSC/2; CKP Idle:High, Active:Low; SSEN disabled; MSTEN Slave; MODE16 enabled; SMP Middle; DISSCK disabled; SPIFE Frame Sync pulse precedes; CKE Idle to Active; MODE32 disabled; SPISIDL disabled; ENHBUF disabled; DISSDI disabled;
112 SPI1CON1L = 0x440;
113}
114
115//------------------------------------------------------------------------------
116// notes: differences between Melody and MCC
117//------------------------------------------------------------------------------
118// SPI
119// differences
120// SPI1IMSKL: MCC = 0x01, MELODY = default.
121// MCC: SPIRBFEN = 1 (enable interrupts events via SPIRBF bit)
122
123// SPI1IMSKH: MCC = 0x400, MELODY = default.
124// MCC: RXMSK = 4. Works with RXWIEN bit (Receive watermark interrupt enable bit). Not sure if this is required
125
126// SPI1CON1L: MCC = 0x440, MELODY = 0x81
127// MCC: MODE16 = 1, CKP = 1
128// MELODY: SSEN = 1, ENHBUF = 1
129
130
131
132
133
This is the generated driver header file for the DMA driver.
This is the generated driver header file for the SEC_CORE1 driver.
This is the generated driver header file for the SPI1 driver.
void CAN_TX_Obj_Init(void)
Definition drv_can.c:111
header of the CAN Driver
void DRV_DMA_init(void)
Definition drv_dma.c:90
This is the driver header file for DMA driver.
void Drv_SPI_Reset_Timeout_Counter(uint16_t count)
Definition drv_spi.c:87
This is the driver source file for spi builds upon mcc.
#define SPI_TIMEOUT_IN_100us_TICKS
Definition drv_spi.h:44
void SYSTEM_Initialize(void)
Initializes the System module.
Definition system.c:51
static void DMA_ChannelDisable(enum DMA_CHANNEL channel)
This inline function disables the DMA channel.
Definition dma.h:175
void SEC_CORE1_Program(void)
This routine programs secondary.
Definition sec_core1.c:227
void SEC_CORE1_Start(void)
This routine enables secondary core.
Definition sec_core1.c:211