Fork of Andy Kirkham's MODDMA GPDMA Controller for Mbed OS 6
Read MODDMA for more info.
Diff: MODDMA.cpp
- Revision:
- 18:31f858967e93
- Parent:
- 12:1dfee7208043
--- a/MODDMA.cpp Sat Mar 02 19:27:12 2013 +0000 +++ b/MODDMA.cpp Sat Dec 10 09:59:10 2022 +0000 @@ -1,16 +1,16 @@ /* Copyright (c) 2010 Andy Kirkham - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -37,7 +37,7 @@ bool MODDMA::Enabled(CHANNELS ChannelNumber) { - LPC_GPDMACH_TypeDef *pChannel = (LPC_GPDMACH_TypeDef *)Channel_p( ChannelNumber ); + LPC_GPDMACH_TypeDef *pChannel = (LPC_GPDMACH_TypeDef *)Channel_p( ChannelNumber ); return (bool)(pChannel->DMACCConfig & _E); } @@ -55,14 +55,14 @@ return (bool)( pChannel->DMACCConfig & CxConfig_A() ) ; } -void +void MODDMA::haltChannel(CHANNELS ChannelNumber) { LPC_GPDMACH_TypeDef *pChannel = (LPC_GPDMACH_TypeDef *)Channel_p( ChannelNumber ); pChannel->DMACCConfig |= CxConfig_H(); } -uint32_t +uint32_t MODDMA::getControl(CHANNELS ChannelNumber) { LPC_GPDMACH_TypeDef *pChannel = (LPC_GPDMACH_TypeDef *)Channel_p( ChannelNumber ); @@ -74,7 +74,7 @@ extern "C" void MODDMA_IRQHandler(void) { uint32_t channel_mask; - + if (moddma_p == (class MODDMA *)NULL) { if (oldDMAHandler) { ((MODDMA_FN)oldDMAHandler)(); @@ -84,7 +84,7 @@ error("Interrupt without instance"); } } - + for (int channel_number = 0; channel_number < 8; channel_number++) { channel_mask = (1UL << channel_number); if (LPC_GPDMA->DMACIntStat & channel_mask) { @@ -92,8 +92,10 @@ if (moddma_p->setups[channel_number] != (MODDMA_Config *)NULL) { moddma_p->setIrqProcessingChannel((MODDMA::CHANNELS)channel_number); moddma_p->setIrqType(MODDMA::TcIrq); - moddma_p->setups[channel_number]->isrIntTCStat->call(); - moddma_p->isrIntTCStat.call(); + if (moddma_p->setups[channel_number]->isrIntTCStat != NULL) + moddma_p->setups[channel_number]->isrIntTCStat.call(); + if (moddma_p->isrIntTCStat != NULL) + moddma_p->isrIntTCStat.call(); // The user callback should clear the IRQ. But if they forget // then the Mbed will lockup. So, check to see if the IRQ has // been dismissed, if not, we will dismiss it here. @@ -108,18 +110,20 @@ // is null otherwise we can crap out a series of transfers. if (moddma_p->Enabled( (MODDMA::CHANNELS)channel_number )) { if (moddma_p->lli( (MODDMA::CHANNELS)channel_number ) == 0 ) { - moddma_p->Disable( (MODDMA::CHANNELS)channel_number ); + moddma_p->Disable( (MODDMA::CHANNELS)channel_number ); } } - } + } } - + if (LPC_GPDMA->DMACIntErrStat & channel_mask) { if (moddma_p->setups[channel_number] != (MODDMA_Config *)NULL) { moddma_p->setIrqProcessingChannel((MODDMA::CHANNELS)channel_number); moddma_p->setIrqType(MODDMA::ErrIrq); - moddma_p->setups[channel_number]->isrIntErrStat->call(); - moddma_p->isrIntErrStat.call(); + if (moddma_p->setups[channel_number]->isrIntErrStat != NULL) + moddma_p->setups[channel_number]->isrIntErrStat.call(); + if (moddma_p->isrIntErrStat != NULL) + moddma_p->isrIntErrStat.call(); // The user callback should clear the IRQ. But if they forget // then the Mbed will lockup. So, check to see if the IRQ has // been dismissed, if not, we will dismiss it here. @@ -134,14 +138,14 @@ // is null otherwise we can crap out a series of transfers. if (moddma_p->Enabled( (MODDMA::CHANNELS)channel_number )) { if (moddma_p->lli( (MODDMA::CHANNELS)channel_number ) == 0 ) { - moddma_p->Disable( (MODDMA::CHANNELS)channel_number ); + moddma_p->Disable( (MODDMA::CHANNELS)channel_number ); } } - } + } } } } - + /* IRQ should be handled by now, check to make sure. */ if (LPC_GPDMA->DMACIntStat) { ((MODDMA_FN)oldDMAHandler)(); @@ -153,5 +157,4 @@ } } -}; // namespace AjK ends - +}