MODSERIAL with support for more devices
Fork of MODSERIAL by
Diff: MODSERIAL.h
- Revision:
- 30:b04ce87dc424
- Parent:
- 28:76793a84f9e5
- Child:
- 31:b90b20f78f04
--- a/MODSERIAL.h Fri Jul 12 15:56:20 2013 +0000 +++ b/MODSERIAL.h Sun Sep 01 12:24:12 2013 +0000 @@ -937,127 +937,7 @@ */ int upSizeBuffer(int size, IrqType type, bool memory_check); - /* - * If MODDMA is available the compile in code to handle sending - * an arbitary char buffer. Note, the parts before teh #ifdef - * are declared so that MODSERIAL can access then even if MODDMA - * isn't avaiable. Since MODDMA.h is only available at this point - * all DMA functionality must be declared inline in the class - * definition. - */ -public: - - int dmaSendChannel; - void *moddma_p; -#ifdef MODDMA_H - - MODDMA_Config *config; - - /** - * Set the "void pointer" moddma_p to be a pointer to a - * MODDMA controller class instance. Used to manage the - * data transfer of DMA configurations. - * - * @ingroup API - * @param p A pointer to "the" instance of MODDMA. - */ - void MODDMA(MODDMA *p) { moddma_p = p; } - - /** - * Send a char buffer to the Uarts TX system - * using DMA. This blocks regular library - * sending. - * - * @param buffer A char buffer of bytes to send. - * @param len The length of the buffer to send. - * @param dmaChannel The DMA channel to use, defaults to 7 - * @return MODDMA::Status MODDMA::ok if all went ok - */ - int dmaSend(char *buffer, int len, int dmaChannel = 7) - { - if (moddma_p == (void *)NULL) return -2; - class MODDMA *dma = (class MODDMA *)moddma_p; - - dmaSendChannel = dmaChannel & 0x7; - - uint32_t conn = MODDMA::UART0_Tx; - switch(_serial.index) { - case 0: conn = MODDMA::UART0_Tx; break; - case 1: conn = MODDMA::UART1_Tx; break; - case 2: conn = MODDMA::UART2_Tx; break; - case 3: conn = MODDMA::UART3_Tx; break; - } - - config = new MODDMA_Config; - config - ->channelNum ( (MODDMA::CHANNELS)(dmaSendChannel & 0x7) ) - ->srcMemAddr ( (uint32_t) buffer ) - ->transferSize ( len ) - ->transferType ( MODDMA::m2p ) - ->dstConn ( conn ) - ->attach_tc ( this, &MODSERIAL::dmaSendCallback ) - ->attach_err ( this, &MODSERIAL::dmaSendCallback ) - ; // config end - - // Setup the configuration. - if (dma->Setup(config) == 0) { - return -1; - } - - //dma.Enable( MODDMA::Channel_0 ); - dma->Enable( config->channelNum() ); - return MODDMA::Ok; - } - - /** - * Attach a callback to the DMA completion. - * - * @ingroup API - * @param fptr A function pointer to call - * @return this - */ - void attach_dmaSendComplete(void (*fptr)(MODSERIAL_IRQ_INFO *)) { - _isrDmaSendComplete.attach(fptr); - } - - /** - * Attach a callback to the DMA completion. - * - * @ingroup API - * @param tptr A template pointer to the calling object - * @param mptr A method pointer within the object to call. - * @return this - */ - template<typename T> - void attach_dmaSendComplete(T* tptr, void (T::*mptr)(MODSERIAL_IRQ_INFO *)) { - if((mptr != NULL) && (tptr != NULL)) { - _isrDmaSendComplete.attach(tptr, mptr); - } - } - - MODSERIAL_callback _isrDmaSendComplete; - -protected: - /** - * Callback for dmaSend(). - */ - void dmaSendCallback(void) - { - if (moddma_p == (void *)NULL) return; - class MODDMA *dma = (class MODDMA *)moddma_p; - - MODDMA_Config *config = dma->getConfig(); - dma->haltAndWaitChannelComplete( (MODDMA::CHANNELS)config->channelNum()); - dma->Disable( (MODDMA::CHANNELS)config->channelNum() ); - if (dma->irqType() == MODDMA::TcIrq) dma->clearTcIrq(); - if (dma->irqType() == MODDMA::ErrIrq) dma->clearErrIrq(); - dmaSendChannel = -1; - _isrDmaSendComplete.call(&this->callbackInfo); - delete(config); - } - -#endif // MODDMA_H //DEVICE SPECIFIC FUNCTIONS: