33//
44// SPDX-License-Identifier: MPL-1.0
55// Copyright (c) 2016 Tobias Schießl (System Init / partial pinmux / boot order / exceptionhandler)
6-
7- #include <tiam1808/psc.h>
6+ //
7+ /*
8+ * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
9+ *
10+ * Redistribution and use in source and binary forms, with or without
11+ * modification, are permitted provided that the following conditions
12+ * are met:
13+ *
14+ * Redistributions of source code must retain the above copyright
15+ * notice, this list of conditions and the following disclaimer.
16+ *
17+ * Redistributions in binary form must reproduce the above copyright
18+ * notice, this list of conditions and the following disclaimer in the
19+ * documentation and/or other materials provided with the
20+ * distribution.
21+ *
22+ * Neither the name of Texas Instruments Incorporated nor the names of
23+ * its contributors may be used to endorse or promote products derived
24+ * from this software without specific prior written permission.
25+ *
26+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37+ */
38+
39+ #include <tiam1808/armv5/am1808/edma_event.h>
40+ #include <tiam1808/armv5/am1808/evmAM1808.h>
841#include <tiam1808/armv5/am1808/interrupt.h>
9- #include <tiam1808/hw/soc_AM1808 .h>
10- #include <tiam1808/hw/hw_types .h>
42+ #include <tiam1808/edma .h>
43+ #include <tiam1808/hw/hw_edma3cc .h>
1144#include <tiam1808/hw/hw_syscfg0_AM1808.h>
1245#include <tiam1808/hw/hw_syscfg1_AM1808.h>
13- #include <tiam1808/armv5/am1808/evmAM1808.h>
46+ #include <tiam1808/hw/hw_types.h>
47+ #include <tiam1808/hw/soc_AM1808.h>
48+ #include <tiam1808/psc.h>
1449
1550#include <pbdrv/ioport.h>
1651#include <pbio/port_interface.h>
1752
1853#include "../../drv/button/button_gpio.h"
54+ #include "../../drv/display/display_ev3.h"
1955#include "../../drv/gpio/gpio_ev3.h"
2056#include "../../drv/led/led_array_pwm.h"
2157#include "../../drv/led/led_dual.h"
@@ -361,6 +397,127 @@ void copy_vector_table(void) {
361397 }
362398}
363399
400+ unsigned int EDMAVersionGet (void ) {
401+ return 1 ;
402+ }
403+
404+ /**
405+ * Callback for completion of all EDMA3 transfers on this platform.
406+ *
407+ * @param tccNum [in] Transfer completion code number.
408+ * @param status [in] Status of the transfer. Currently only EDMA3_XFER_COMPLETE.
409+ */
410+ static void Edma3CompleteCallback (unsigned int tccNum , unsigned int status ) {
411+ if (tccNum == EDMA3_CHA_SPI1_TX ) {
412+ pbdrv_display_ev3_spi1_tx_complete (status );
413+ }
414+ // Add other callbacks here as needed.
415+ }
416+
417+ /**
418+ * ISR for completion of all EDMA3 transfers on this platform.
419+ *
420+ * This is unchanged from the TI StarterWare example.
421+ */
422+ static void Edma3ComplHandlerIsr (void ) {
423+ volatile unsigned int pendingIrqs ;
424+ volatile unsigned int isIPR = 0 ;
425+
426+ volatile unsigned int indexl ;
427+ volatile unsigned int Cnt = 0 ;
428+ indexl = 1 ;
429+ IntSystemStatusClear (SYS_INT_CCINT0 );
430+ isIPR = EDMA3GetIntrStatus (SOC_EDMA30CC_0_REGS );
431+ if (isIPR ) {
432+ while ((Cnt < EDMA3CC_COMPL_HANDLER_RETRY_COUNT ) && (indexl != 0 )) {
433+ indexl = 0 ;
434+ pendingIrqs = EDMA3GetIntrStatus (SOC_EDMA30CC_0_REGS );
435+ while (pendingIrqs ) {
436+ if ((pendingIrqs & 1 ) == TRUE) {
437+ // Here write to ICR to clear the corresponding IPR bits.
438+ EDMA3ClrIntr (SOC_EDMA30CC_0_REGS , indexl );
439+ Edma3CompleteCallback (indexl , EDMA3_XFER_COMPLETE );
440+ }
441+ ++ indexl ;
442+ pendingIrqs >>= 1 ;
443+ }
444+ Cnt ++ ;
445+ }
446+ }
447+
448+ }
449+
450+ /**
451+ * ISR for error handling of all EDMA3 transfers on this platform.
452+ *
453+ * This is unchanged from the TI StarterWare example.
454+ */
455+ static void Edma3CCErrHandlerIsr (void ) {
456+ volatile unsigned int pendingIrqs = 0 ;
457+ unsigned int Cnt = 0 ;
458+ unsigned int index = 1 ;
459+ unsigned int regionNum = 0 ;
460+ unsigned int evtqueNum = 0 ;
461+
462+ IntSystemStatusClear (SYS_INT_CCERRINT );
463+
464+ if ((HWREG (SOC_EDMA30CC_0_REGS + EDMA3CC_EMR ) != 0 )
465+ || (HWREG (SOC_EDMA30CC_0_REGS + EDMA3CC_QEMR ) != 0 )
466+ || (HWREG (SOC_EDMA30CC_0_REGS + EDMA3CC_CCERR ) != 0 )) {
467+ // Loop for EDMA3CC_ERR_HANDLER_RETRY_COUNT number of time, breaks
468+ // when no pending interrupt is found.
469+ while ((Cnt < EDMA3CC_ERR_HANDLER_RETRY_COUNT ) && (index != 0 )) {
470+ index = 0 ;
471+ pendingIrqs = HWREG (SOC_EDMA30CC_0_REGS + EDMA3CC_EMR );
472+ while (pendingIrqs ) {
473+ // Process all the pending interrupts.
474+ if ((pendingIrqs & 1 ) == TRUE) {
475+ // Write to EMCR to clear the corresponding EMR bits.
476+ HWREG (SOC_EDMA30CC_0_REGS + EDMA3CC_EMCR ) = (1 << index );
477+ // Clear any SER
478+ HWREG (SOC_EDMA30CC_0_REGS + EDMA3CC_S_SECR (regionNum )) = (1 << index );
479+ }
480+ ++ index ;
481+ pendingIrqs >>= 1 ;
482+ }
483+ index = 0 ;
484+ pendingIrqs = HWREG (SOC_EDMA30CC_0_REGS + EDMA3CC_QEMR );
485+ while (pendingIrqs ) {
486+ // Process all the pending interrupts.
487+ if ((pendingIrqs & 1 ) == TRUE) {
488+ // Here write to QEMCR to clear the corresponding QEMR bits.
489+ HWREG (SOC_EDMA30CC_0_REGS + EDMA3CC_QEMCR ) = (1 << index );
490+ // Clear any QSER
491+ HWREG (SOC_EDMA30CC_0_REGS + EDMA3CC_S_QSECR (0 )) = (1 << index );
492+ }
493+ ++ index ;
494+ pendingIrqs >>= 1 ;
495+ }
496+ index = 0 ;
497+ pendingIrqs = HWREG (SOC_EDMA30CC_0_REGS + EDMA3CC_CCERR );
498+ if (pendingIrqs != 0 ) {
499+ // Process all the pending CC error interrupts.
500+ // Queue threshold error for different event queues.
501+ for (evtqueNum = 0 ; evtqueNum < EDMA3_0_NUM_EVTQUE ; evtqueNum ++ )
502+ {
503+ if ((pendingIrqs & (1 << evtqueNum )) != 0 ) {
504+ // Clear the error interrupt.
505+ HWREG (SOC_EDMA30CC_0_REGS + EDMA3CC_CCERRCLR ) = (1 << evtqueNum );
506+ }
507+ }
508+
509+ // Transfer completion code error.
510+ if ((pendingIrqs & (1 << EDMA3CC_CCERR_TCCERR_SHIFT )) != 0 ) {
511+ HWREG (SOC_EDMA30CC_0_REGS + EDMA3CC_CCERRCLR ) = \
512+ (0x01 << EDMA3CC_CCERR_TCCERR_SHIFT );
513+ }
514+ ++ index ;
515+ }
516+ Cnt ++ ;
517+ }
518+ }
519+ }
520+
364521// Called from assembly code in startup.s. After this, the "main" function in
365522// lib/pbio/sys/main.c is called. That contains all calls to the driver
366523// initialization (low level in pbdrv, high level in pbio), and system level
@@ -371,21 +528,26 @@ void SystemInit(void) {
371528
372529 copy_vector_table ();
373530
374- /* Initialize AINTC */
531+ // Initialize advanced interrupt controller (AINTC)
375532 IntAINTCInit ();
376-
377- /* Enable IRQ for ARM (in CPSR)*/
378533 IntMasterIRQEnable ();
379-
380- /* Enable AINTC interrupts in GER */
381534 IntGlobalEnable ();
382-
383- /* Enable IRQ in AINTC */
384535 IntIRQEnable ();
385-
386536 IntMasterFIQEnable ();
387537 IntFIQEnable ();
388538
539+ // Initialization of EDMA3
540+ PSCModuleControl (SOC_PSC_0_REGS , HW_PSC_CC0 , PSC_POWERDOMAIN_ALWAYS_ON , PSC_MDCTL_NEXT_ENABLE );
541+ PSCModuleControl (SOC_PSC_0_REGS , HW_PSC_TC0 , PSC_POWERDOMAIN_ALWAYS_ON , PSC_MDCTL_NEXT_ENABLE );
542+ EDMA3Init (SOC_EDMA30CC_0_REGS , 0 ); // Que num 0
543+ IntRegister (SYS_INT_CCINT0 , Edma3ComplHandlerIsr );
544+ IntChannelSet (SYS_INT_CCINT0 , 2 );
545+ IntSystemEnable (SYS_INT_CCINT0 );
546+ IntRegister (SYS_INT_CCERRINT , Edma3CCErrHandlerIsr );
547+ IntChannelSet (SYS_INT_CCERRINT , 2 );
548+ IntSystemEnable (SYS_INT_CCERRINT );
549+
550+
389551 PSCModuleControl (SOC_PSC_1_REGS , HW_PSC_GPIO , PSC_POWERDOMAIN_ALWAYS_ON , PSC_MDCTL_NEXT_ENABLE );
390552
391553 // Must set the power enable bin before disabling the pull up on the power
0 commit comments