Exemplo n.º 1
0
static void
doTxSingleDMA(const uint8* data, uint32 count)
{
	// Prepare DMA transfer
	dmaInProgress = 1;
	trace(trace_doTxSingleDMA);

	CyDmaTdSetConfiguration(
		scsiDmaTxTd[0],
		count,
		CY_DMA_DISABLE_TD, // Disable the DMA channel when TD completes count bytes
		TD_INC_SRC_ADR |
			SCSI_TX_DMA__TD_TERMOUT_EN // Trigger interrupt when complete
		);
	CyDmaTdSetAddress(
		scsiDmaTxTd[0],
		LO16((uint32)data),
		LO16((uint32)scsiTarget_datapath__F0_REG));
	CyDmaChSetInitialTd(scsiDmaTxChan, scsiDmaTxTd[0]);

	// The DMA controller is a bit trigger-happy. It will retain
	// a drq request that was triggered while the channel was
	// disabled.
	CyDmaClearPendingDrq(scsiDmaTxChan);

	scsiTxDMAComplete = 0;
	scsiRxDMAComplete = 1;

	CyDmaChEnable(scsiDmaTxChan, 1);
}
Exemplo n.º 2
0
void DmaTxConfiguration(void)
{
    uint8 i;
    /* Initialize DMA channel. */
    TxOutDmaCh = TxDma_DmaInitialize(TX_DMA_BYTES_PER_BURST, TX_DMA_REQUEST_PER_BURST,
                                            HI16(TX_DMA_SRC_BASE), HI16(TX_DMA_DST_BASE));

    /* Allocate transfer descriptors for each buffer chunk. */
    for (i = 0u; i < NUM_OF_BUFFERS; ++i)
    {
        TxOutDmaTd[i] = CyDmaTdAllocate();
    }

    /* Configure DMA transfer descriptors. */
    for (i = 0u; i < (NUM_OF_BUFFERS - 1u); ++i)
    {
        /* Chain current and next DMA transfer descriptors to be in row. */
        CyDmaTdSetConfiguration(TxOutDmaTd[i], TRANSFER_SIZE, TxOutDmaTd[i + 1u],
                                TD_INC_SRC_ADR);
    }
    /* Chain last and 1st DMA transfer descriptors to make cyclic buffer. */
    CyDmaTdSetConfiguration(TxOutDmaTd[NUM_OF_BUFFERS - 1u], TRANSFER_SIZE, TxOutDmaTd[0u],
                                TD_INC_SRC_ADR);


    for (i = 0u; i < NUM_OF_BUFFERS; i++)
    {
        /* Set source and destination addresses. */
        CyDmaTdSetAddress(TxOutDmaTd[i], LO16((uint32) &soundBuffer[i * TRANSFER_SIZE]),
                                           LO16((uint32) I2S_1_TX_CH0_F0_PTR));
    }

    /* Set 1st transfer descriptor to execute. */
    CyDmaChSetInitialTd(TxOutDmaCh, TxOutDmaTd[0u]);
}
Exemplo n.º 3
0
/*******************************************************************************
* Function Name: WaveDAC8_1_Wave2Setup
********************************************************************************
*
* Summary:
*  Sets pointer and size for waveform 2.
*
* Parameters:
*  uint8 * WavePtr:     Pointer to the waveform array.
*  uint16  SampleSize:  The amount of samples in the waveform.
*
* Return:
*  None
*
*******************************************************************************/
void WaveDAC8_1_Wave2Setup(const uint8 * wavePtr, uint16 sampleSize)

{
#if (CY_PSOC3)
    uint16 memoryType; /* determining the source memory type */
    memoryType = (WaveDAC8_1_HI16FLASHPTR == HI16(wavePtr)) ? HI16(CYDEV_FLS_BASE) : HI16(CYDEV_SRAM_BASE);

    WaveDAC8_1_Wave2Chan = WaveDAC8_1_Wave2_DMA_DmaInitialize(
                               WaveDAC8_1_Wave2_DMA_BYTES_PER_BURST, WaveDAC8_1_Wave2_DMA_REQUEST_PER_BURST,
                               memoryType, HI16(CYDEV_PERIPH_BASE));
#else /* PSoC 5 */
    WaveDAC8_1_Wave2Chan = WaveDAC8_1_Wave2_DMA_DmaInitialize(
                               WaveDAC8_1_Wave2_DMA_BYTES_PER_BURST, WaveDAC8_1_Wave2_DMA_REQUEST_PER_BURST,
                               HI16(wavePtr), HI16(WaveDAC8_1_DAC8__D));
#endif /* CY_PSOC3 */

    /*
    * TD is looping on itself.
    * Increment the source address, but not the destination address.
    */
    (void)CyDmaTdSetConfiguration(WaveDAC8_1_Wave2TD, sampleSize, WaveDAC8_1_Wave2TD,
                                  (uint8)CY_DMA_TD_INC_SRC_ADR | (uint8)WaveDAC8_1_Wave2_DMA__TD_TERMOUT_EN);

    /* Set the TD source and destination address */
    (void)CyDmaTdSetAddress(WaveDAC8_1_Wave2TD, LO16((uint32)wavePtr), LO16(WaveDAC8_1_DAC8__D));

    /* Associate the TD with the channel */
    (void)CyDmaChSetInitialTd(WaveDAC8_1_Wave2Chan, WaveDAC8_1_Wave2TD);
}
Exemplo n.º 4
0
void dcbInitThunk(DCThunk* p, void (*entry)())
{
#if DC__ABI_PPC64_ELF_V != 2
  /*
    ppc64 thunk code:                (v1)
      oris   r11, r2, HI16(p)
      ori    r11,r11, LO16(p)
      ld     r12,48(r11)
      ld     r2,56(r11)
      mtctr r12
      bctr
  */

  p->thunk_entry  = (void *)&(p->code_load_hi);
  p->toc_thunk    = ((long)(p->thunk_entry) & 0xffffffff00000000UL);

  p->code_load_hi = 0x644bU;     /* oris  r11, r2, HI16(p) */
  p->addr_self_hi = HI16(p);
  p->code_load_lo = 0x616bU; 	 /* ori   r11,r11, LO16(p) */
  p->addr_self_lo = LO16(p);
  p->code_jump[0] = 0xe98b0030U; /* ld    r12,48(r11) */
  p->code_jump[1] = 0xe84b0038U; /* ld    r2,56(r11) */
  p->code_jump[2] = 0x7d8903a6U; /* mtclr r12 */
  p->code_jump[3] = 0x4e800420U; /* bctr */
  p->addr_entry   = (void *)*((long *)entry);
  p->toc_entry    = *((long *)(entry + 8));

#else
  /*
    ppc64 thunk code:                (v2)
      lis    r11, HIST16(p)
      ori    r11,r11, HIER16(p)
      rldicr r11,r11,32,31
      oris   r11,r11, HI16(p)
      ori    r11,r11, LO16(p)
      ld     r12,40(r11)
      mtctr r12
      bctr
  */

  p->code_load_hist = 0x3d60U;     /* lis    r11,HIST16(p) */
  p->addr_self_hist = HIST16(p);
  p->code_load_hier = 0x616bU;     /* ori    r11,r11, HIER16(p) */
  p->addr_self_hier = HIER16(p);
  p->code_rot       = 0x796b07c6U; /* rldicr r11,r11,32,31 */
  p->code_load_hi   = 0x656bU;     /* oris   r11,r11, HI16(p) */
  p->addr_self_hi   = HI16(p);
  p->code_load_lo   = 0x616bU; 	   /* ori    r11,r11, LO16(p) */
  p->addr_self_lo   = LO16(p);
  p->code_jump[0]   = 0xe98b0028U; /* ld     r12,40(r11) */
  p->code_jump[1]   = 0x7d8903a6U; /* mtclr  r12 */
  p->code_jump[2]   = 0x4e800420U; /* bctr */
  p->addr_entry     = (void *)(entry);
#endif
}
 /*******************************************************************************
 * Function Name: comm_RS485_UART_PutWordInTxBuffer
 ********************************************************************************
 *
 * Summary:
 *  Stores byte/word into the TX buffer.
 *  Only available in the Unconfigured operation mode.
 *
 * Parameters:
 *  idx:        index to store data byte/word in the TX buffer.
 *  txDataByte: byte/word to store.
 *
 * Return:
 *  None
 *
 *******************************************************************************/
 void comm_RS485_UART_PutWordInTxBuffer(uint32 idx, uint32 txDataByte)
 {
     /* Put data in buffer */
     if(comm_RS485_UART_ONE_BYTE_WIDTH == comm_RS485_UART_txDataBits)
     {
         comm_RS485_UART_txBuffer[idx] = ((uint8) txDataByte);
     }
     else
     {
         comm_RS485_UART_txBuffer[(uint32)(idx << 1u)]      = LO8(LO16(txDataByte));
         comm_RS485_UART_txBuffer[(uint32)(idx << 1u) + 1u] = HI8(LO16(txDataByte));
     }
 }
Exemplo n.º 6
0
 /*******************************************************************************
 * Function Name: Rx_Right_PutWordInTxBuffer
 ********************************************************************************
 *
 * Summary:
 *  Stores byte/word into the TX buffer.
 *  Only available in the Unconfigured operation mode.
 *
 * Parameters:
 *  idx:        index to store data byte/word in the TX buffer.
 *  txDataByte: byte/word to store.
 *
 * Return:
 *  None
 *
 *******************************************************************************/
 void Rx_Right_PutWordInTxBuffer(uint32 idx, uint32 txDataByte)
 {
     /* Put data in buffer */
     if(Rx_Right_ONE_BYTE_WIDTH == Rx_Right_txDataBits)
     {
         Rx_Right_txBuffer[idx] = ((uint8) txDataByte);
     }
     else
     {
         Rx_Right_txBuffer[(uint32)(idx << 1u)]      = LO8(LO16(txDataByte));
         Rx_Right_txBuffer[(uint32)(idx << 1u) + 1u] = HI8(LO16(txDataByte));
     }
 }
Exemplo n.º 7
0
 /*******************************************************************************
 * Function Name: ESP_UART_PutWordInRxBuffer
 ********************************************************************************
 *
 * Summary:
 *  Stores a byte/word into the RX buffer.
 *  Only available in the Unconfigured operation mode.
 *
 * Parameters:
 *  index:      index to store data byte/word in the RX buffer.
 *  rxDataByte: byte/word to store.
 *
 * Return:
 *  None
 *
 *******************************************************************************/
 void ESP_UART_PutWordInRxBuffer(uint32 idx, uint32 rxDataByte)
 {
     /* Put data in buffer */
     if (ESP_UART_ONE_BYTE_WIDTH == ESP_UART_rxDataBits)
     {
         ESP_UART_rxBuffer[idx] = ((uint8) rxDataByte);
     }
     else
     {
         ESP_UART_rxBuffer[(uint32)(idx << 1u)]      = LO8(LO16(rxDataByte));
         ESP_UART_rxBuffer[(uint32)(idx << 1u) + 1u] = HI8(LO16(rxDataByte));
     }
 }
Exemplo n.º 8
0
 /*******************************************************************************
 * Function Name: UART_DEB_PutWordInRxBuffer
 ****************************************************************************//**
 *
 *  Stores a byte/word into the RX buffer.
 *  Only available in the Unconfigured operation mode.
 *
 *  \param index:      index to store data byte/word in the RX buffer.
 *  \param rxDataByte: byte/word to store.
 *
 *******************************************************************************/
 void UART_DEB_PutWordInRxBuffer(uint32 idx, uint32 rxDataByte)
 {
     /* Put data in buffer */
     if (UART_DEB_ONE_BYTE_WIDTH == UART_DEB_rxDataBits)
     {
         UART_DEB_rxBuffer[idx] = ((uint8) rxDataByte);
     }
     else
     {
         UART_DEB_rxBuffer[(uint32)(idx << 1u)]      = LO8(LO16(rxDataByte));
         UART_DEB_rxBuffer[(uint32)(idx << 1u) + 1u] = HI8(LO16(rxDataByte));
     }
 }
Exemplo n.º 9
0
 /*******************************************************************************
 * Function Name: SPIS_1_PutWordInTxBuffer
 ********************************************************************************
 *
 * Summary:
 *  Stores byte/word into the TX buffer.
 *  Only available in the Unconfigured operation mode.
 *
 * Parameters:
 *  idx:        index to store data byte/word in the TX buffer.
 *  txDataByte: byte/word to store.
 *
 * Return:
 *  None
 *
 *******************************************************************************/
 void SPIS_1_PutWordInTxBuffer(uint32 idx, uint32 txDataByte)
 {
     /* Put data in buffer */
     if(SPIS_1_ONE_BYTE_WIDTH == SPIS_1_txDataBits)
     {
         SPIS_1_txBuffer[idx] = ((uint8) txDataByte);
     }
     else
     {
         SPIS_1_txBuffer[(uint32)(idx << 1u)]      = LO8(LO16(txDataByte));
         SPIS_1_txBuffer[(uint32)(idx << 1u) + 1u] = HI8(LO16(txDataByte));
     }
 }
 /*******************************************************************************
 * Function Name: ModbusUART_PutWordInRxBuffer
 ********************************************************************************
 *
 * Summary:
 *  Stores byte/word into the RX buffer.
 *  Only available in Unconfigured operation mode.
 *
 * Parameters:
 *  index:      index to store data byte/word in the RX buffer.
 *  rxDataByte: byte/word to store.
 *
 * Return:
 *  None
 *
 *******************************************************************************/
 void ModbusUART_PutWordInRxBuffer(uint32 idx, uint32 rxDataByte)
 {
     /* Put data in the buffer */
     if(ModbusUART_ONE_BYTE_WIDTH == ModbusUART_rxDataBits)
     {
         ModbusUART_rxBuffer[idx] = ((uint8) rxDataByte);
     }
     else
     {
         ModbusUART_rxBuffer[(uint32)(idx << 1u)]      = LO8(LO16(rxDataByte));
         ModbusUART_rxBuffer[(uint32)(idx << 1u) + 1u] = HI8(LO16(rxDataByte));
     }
 }
Exemplo n.º 11
0
 /*******************************************************************************
 * Function Name: xbee_PutWordInTxBuffer
 ********************************************************************************
 *
 * Summary:
 *  Stores byte/word into the TX buffer.
 *  Only available in the Unconfigured operation mode.
 *
 * Parameters:
 *  idx:        index to store data byte/word in the TX buffer.
 *  txDataByte: byte/word to store.
 *
 * Return:
 *  None
 *
 *******************************************************************************/
 void xbee_PutWordInTxBuffer(uint32 idx, uint32 txDataByte)
 {
     /* Put data in buffer */
     if (xbee_ONE_BYTE_WIDTH == xbee_txDataBits)
     {
         xbee_txBuffer[idx] = ((uint8) txDataByte);
     }
     else
     {
         xbee_txBuffer[(uint32)(idx << 1u)]      = LO8(LO16(txDataByte));
         xbee_txBuffer[(uint32)(idx << 1u) + 1u] = HI8(LO16(txDataByte));
     }
 }
Exemplo n.º 12
0
 /*******************************************************************************
 * Function Name: UART_PutWordInTxBuffer
 ********************************************************************************
 *
 * Summary:
 *  Stores byte/word into the TX buffer.
 * Only available in Unconfigured operation mode.
 *
 * Parameters:
 *  idx:        index to store data byte/word in the TX buffer.
 *  txDataByte: byte/word to store.
 *
 * Return:
 *  None
 *
 *******************************************************************************/
 void UART_PutWordInTxBuffer(uint32 idx, uint32 txDataByte)
 {
     /* Put data in the buffer */
     if(UART_ONE_BYTE_WIDTH == UART_txDataBits)
     {
         UART_txBuffer[idx] = ((uint8) txDataByte);
     }
     else
     {
         UART_txBuffer[(uint32)(idx << 1u)]      = LO8(LO16(txDataByte));
         UART_txBuffer[(uint32)(idx << 1u) + 1u] = HI8(LO16(txDataByte));
     }
 }
 /*******************************************************************************
 * Function Name: ModbusComms_PutWordInTxBuffer
 ********************************************************************************
 *
 * Summary:
 *  Stores byte/word into the TX buffer.
 * Only available in Unconfigured operation mode.
 *
 * Parameters:
 *  idx:        index to store data byte/word in the TX buffer.
 *  txDataByte: byte/word to store.
 *
 * Return:
 *  None
 *
 *******************************************************************************/
 void ModbusComms_PutWordInTxBuffer(uint32 idx, uint32 txDataByte)
 {
     /* Put data in the buffer */
     if(ModbusComms_ONE_BYTE_WIDTH == ModbusComms_txDataBits)
     {
         ModbusComms_txBuffer[idx] = ((uint8) txDataByte);
     }
     else
     {
         ModbusComms_txBuffer[(uint32)(idx << 1u)]      = LO8(LO16(txDataByte));
         ModbusComms_txBuffer[(uint32)(idx << 1u) + 1u] = HI8(LO16(txDataByte));
     }
 }
 /*******************************************************************************
 * Function Name: SPI_PutWordInRxBuffer
 ********************************************************************************
 *
 * Summary:
 *  Stores byte/word into the RX buffer.
 *  Only available in Unconfigured operation mode.
 *
 * Parameters:
 *  index:      index to store data byte/word in the RX buffer.
 *  rxDataByte: byte/word to store.
 *
 * Return:
 *  None
 *
 *******************************************************************************/
 void SPI_PutWordInRxBuffer(uint32 idx, uint32 rxDataByte)
 {
     /* Put data in the buffer */
     if(SPI_ONE_BYTE_WIDTH == SPI_rxDataBits)
     {
         SPI_rxBuffer[idx] = ((uint8) rxDataByte);
     }
     else
     {
         SPI_rxBuffer[(uint32)(idx << 1u)]      = LO8(LO16(rxDataByte));
         SPI_rxBuffer[(uint32)(idx << 1u) + 1u] = HI8(LO16(rxDataByte));
     }
 }
Exemplo n.º 15
0
 /*******************************************************************************
 * Function Name: DEBUG_PutWordInRxBuffer
 ********************************************************************************
 *
 * Summary:
 *  Stores a byte/word into the RX buffer.
 *  Only available in the Unconfigured operation mode.
 *
 * Parameters:
 *  index:      index to store data byte/word in the RX buffer.
 *  rxDataByte: byte/word to store.
 *
 * Return:
 *  None
 *
 *******************************************************************************/
 void DEBUG_PutWordInRxBuffer(uint32 idx, uint32 rxDataByte)
 {
     /* Put data in buffer */
     if (DEBUG_ONE_BYTE_WIDTH == DEBUG_rxDataBits)
     {
         DEBUG_rxBuffer[idx] = ((uint8) rxDataByte);
     }
     else
     {
         DEBUG_rxBuffer[(uint32)(idx << 1u)]      = LO8(LO16(rxDataByte));
         DEBUG_rxBuffer[(uint32)(idx << 1u) + 1u] = HI8(LO16(rxDataByte));
     }
 }
Exemplo n.º 16
0
void setupType0Adv()
{
    advPacket0 *ap;
    
    ap = (advPacket0 *)&cyBle_discoveryModeInfo.advData->advData[ADVINDEX];
    
    // packet type + LSM9Setting
  
    
    ap->setup = ADVPACKET0 | (LSM9DS0GetSetting()<<2);
    
    // fix this
    ap->tb0 =LO8(systime);
    ap->tb1 =HI8(LO16(systime));
    ap->tb2 =LO8(HI16(systime));
    
    
    // position // if it is a uint16 it causes some unhandled exception
    uint16 val= QD_ReadCounter();
     
    
    ap->position = val;
       
    
    // acceleration x,y,z
    memcpy(&ap->accel , LSM9DS0GetAccel(), 6); // sizeof(LSM9DS0DATA));
    
    // gyro x,y,z
    memcpy(&ap->gyro , LSM9DS0GetGyro(),6 ); // sizeof(LSM9DS0DATA));
    
    // mag x,y,z
    memcpy(&ap->mag , LSM9DS0GetMag(),6); //sizeof(LSM9DS0DATA));
             
    CyBle_GapUpdateAdvData(cyBle_discoveryModeInfo.advData, cyBle_discoveryModeInfo.scanRspData);
}
Exemplo n.º 17
0
    /*******************************************************************************
    * Function Name: SCB_1_UartInit
    ****************************************************************************//**
    *
    *  Configures the SCB for the UART operation.
    *
    *******************************************************************************/
    void SCB_1_UartInit(void)
    {
        /* Configure UART interface */
        SCB_1_CTRL_REG = SCB_1_UART_DEFAULT_CTRL;

        /* Configure sub-mode: UART, SmartCard or IrDA */
        SCB_1_UART_CTRL_REG = SCB_1_UART_DEFAULT_UART_CTRL;

        /* Configure RX direction */
        SCB_1_UART_RX_CTRL_REG = SCB_1_UART_DEFAULT_UART_RX_CTRL;
        SCB_1_RX_CTRL_REG      = SCB_1_UART_DEFAULT_RX_CTRL;
        SCB_1_RX_FIFO_CTRL_REG = SCB_1_UART_DEFAULT_RX_FIFO_CTRL;
        SCB_1_RX_MATCH_REG     = SCB_1_UART_DEFAULT_RX_MATCH_REG;

        /* Configure TX direction */
        SCB_1_UART_TX_CTRL_REG = SCB_1_UART_DEFAULT_UART_TX_CTRL;
        SCB_1_TX_CTRL_REG      = SCB_1_UART_DEFAULT_TX_CTRL;
        SCB_1_TX_FIFO_CTRL_REG = SCB_1_UART_DEFAULT_TX_FIFO_CTRL;

    #if !(SCB_1_CY_SCBIP_V0 || SCB_1_CY_SCBIP_V1)
        SCB_1_UART_FLOW_CTRL_REG = SCB_1_UART_DEFAULT_FLOW_CTRL;
    #endif /* !(SCB_1_CY_SCBIP_V0 || SCB_1_CY_SCBIP_V1) */

        /* Configure interrupt with UART handler but do not enable it */
    #if(SCB_1_SCB_IRQ_INTERNAL)
        CyIntDisable    (SCB_1_ISR_NUMBER);
        CyIntSetPriority(SCB_1_ISR_NUMBER, SCB_1_ISR_PRIORITY);
        (void) CyIntSetVector(SCB_1_ISR_NUMBER, &SCB_1_SPI_UART_ISR);
    #endif /* (SCB_1_SCB_IRQ_INTERNAL) */

        /* Configure WAKE interrupt */
    #if(SCB_1_UART_RX_WAKEUP_IRQ)
        CyIntDisable    (SCB_1_RX_WAKE_ISR_NUMBER);
        CyIntSetPriority(SCB_1_RX_WAKE_ISR_NUMBER, SCB_1_RX_WAKE_ISR_PRIORITY);
        (void) CyIntSetVector(SCB_1_RX_WAKE_ISR_NUMBER, &SCB_1_UART_WAKEUP_ISR);
    #endif /* (SCB_1_UART_RX_WAKEUP_IRQ) */

        /* Configure interrupt sources */
        SCB_1_INTR_I2C_EC_MASK_REG = SCB_1_UART_DEFAULT_INTR_I2C_EC_MASK;
        SCB_1_INTR_SPI_EC_MASK_REG = SCB_1_UART_DEFAULT_INTR_SPI_EC_MASK;
        SCB_1_INTR_SLAVE_MASK_REG  = SCB_1_UART_DEFAULT_INTR_SLAVE_MASK;
        SCB_1_INTR_MASTER_MASK_REG = SCB_1_UART_DEFAULT_INTR_MASTER_MASK;
        SCB_1_INTR_RX_MASK_REG     = SCB_1_UART_DEFAULT_INTR_RX_MASK;
        SCB_1_INTR_TX_MASK_REG     = SCB_1_UART_DEFAULT_INTR_TX_MASK;
    
        /* Configure TX interrupt sources to restore. */
        SCB_1_IntrTxMask = LO16(SCB_1_INTR_TX_MASK_REG);

    #if(SCB_1_INTERNAL_RX_SW_BUFFER_CONST)
        SCB_1_rxBufferHead     = 0u;
        SCB_1_rxBufferTail     = 0u;
        SCB_1_rxBufferOverflow = 0u;
    #endif /* (SCB_1_INTERNAL_RX_SW_BUFFER_CONST) */

    #if(SCB_1_INTERNAL_TX_SW_BUFFER_CONST)
        SCB_1_txBufferHead = 0u;
        SCB_1_txBufferTail = 0u;
    #endif /* (SCB_1_INTERNAL_TX_SW_BUFFER_CONST) */
    }
Exemplo n.º 18
0
void DMA_2_Config()
{
	// Variable declarations for DMA_2
	// Move these variable declarations to the top of the function
	uint8 DMA_2_Chan;
	uint8 DMA_2_TD[1];

	// DMA Configuration for DMA_2
	#define DMA_2_BYTES_PER_BURST 2
	#define DMA_2_REQUEST_PER_BURST 1
	#define DMA_2_SRC_BASE (CYDEV_PERIPH_BASE)
	#define DMA_2_DST_BASE (CYDEV_SRAM_BASE)
	DMA_2_Chan = DMA_2_DmaInitialize(DMA_2_BYTES_PER_BURST, DMA_2_REQUEST_PER_BURST, HI16(DMA_2_SRC_BASE), HI16(DMA_2_DST_BASE));
	DMA_2_TD[0] = CyDmaTdAllocate();
	CyDmaTdSetConfiguration(DMA_2_TD[0], n*2, DMA_INVALID_TD, TD_SWAP_EN | DMA_2__TD_TERMOUT_EN | TD_INC_SRC_ADR | TD_INC_DST_ADR);
	CyDmaTdSetAddress(DMA_2_TD[0], LO16((uint32)Filter_1_HOLDAM_PTR), LO16((uint32)V_Sample));
	CyDmaChSetInitialTd(DMA_2_Chan, DMA_2_TD[0]);
	CyDmaChEnable(DMA_2_Chan, 1);
}
Exemplo n.º 19
0
/*******************************************************************************
* Function Name: DmaRxConfiguration
********************************************************************************
* Summary:
*  Configures the DMA transfer for RX direction
*   
* Parameters:
*  None.
*
* Return:
*  None.
*
*******************************************************************************/
void DmaRxConfiguration()
{ 
    /* Init DMA, 1 byte bursts, each burst requires a request */ 
    rxChannel = DMA_RX_DmaInitialize(DMA_RX_BYTES_PER_BURST, DMA_RX_REQUEST_PER_BURST,
                                     HI16(DMA_RX_SRC_BASE), HI16(DMA_RX_DST_BASE));

    rxTD = CyDmaTdAllocate();
    
    /* Configure this Td as follows:
    *  - Increment the destination address, but not the source address
    */
    CyDmaTdSetConfiguration(rxTD, BUFFER_SIZE, CY_DMA_DISABLE_TD, TD_INC_DST_ADR);

    /* From the SPIM to the memory */
    CyDmaTdSetAddress(rxTD, LO16((uint32)SPIM_RXDATA_PTR), LO16((uint32)rxBuffer));

    /* Associate the TD with the channel */
    CyDmaChSetInitialTd(rxChannel, rxTD);
}
Exemplo n.º 20
0
void DMA_1_Config()
{
	// Variable declarations for DMA_1 
	// Move these variable declarations to the top of the function 
	uint8 DMA_1_Chan;
	uint8 DMA_1_TD[1];

	// DMA Configuration for DMA_1
	#define DMA_1_BYTES_PER_BURST 2
	#define DMA_1_REQUEST_PER_BURST 1
	#define DMA_1_SRC_BASE (CYDEV_PERIPH_BASE)
	#define DMA_1_DST_BASE (CYDEV_PERIPH_BASE)
	DMA_1_Chan = DMA_1_DmaInitialize(DMA_1_BYTES_PER_BURST, DMA_1_REQUEST_PER_BURST, HI16(DMA_1_SRC_BASE), HI16(DMA_1_DST_BASE));
	DMA_1_TD[0] = CyDmaTdAllocate();
	CyDmaTdSetConfiguration(DMA_1_TD[0], 2, DMA_INVALID_TD, TD_INC_DST_ADR);
	CyDmaTdSetAddress(DMA_1_TD[0], LO16((uint32)ADC_DelSig_1_DEC_SAMP_PTR), LO16((uint32)Filter_1_STAGEAM_PTR));
	CyDmaChSetInitialTd(DMA_1_Chan, DMA_1_TD[0]);
	CyDmaChEnable(DMA_1_Chan, 1);
}
Exemplo n.º 21
0
/*******************************************************************************
* Function Name: SCB_1_UartStop
****************************************************************************//**
*
*  Changes the HSIOM settings for the UART output pins (TX and/or RTS) to keep
*  them inactive after the block is disabled. The output pins are controlled by
*  the GPIO data register. Also, the function disables the skip start feature
*  to not cause it to trigger after the component is enabled.
*
*******************************************************************************/
void SCB_1_UartStop(void)
{
#if(SCB_1_SCB_MODE_UNCONFIG_CONST_CFG)
    #if (SCB_1_TX_SCL_MISO_PIN)
        if (SCB_1_CHECK_TX_SCL_MISO_PIN_USED)
        {
            /* Set GPIO to drive output pin */
            SCB_1_SET_HSIOM_SEL(SCB_1_TX_SCL_MISO_HSIOM_REG, SCB_1_TX_SCL_MISO_HSIOM_MASK,
                                           SCB_1_TX_SCL_MISO_HSIOM_POS, SCB_1_TX_SCL_MISO_HSIOM_SEL_GPIO);
        }
    #endif /* (SCB_1_TX_SCL_MISO_PIN_PIN) */

    #if !(SCB_1_CY_SCBIP_V0 || SCB_1_CY_SCBIP_V1)
        #if (SCB_1_RTS_SS0_PIN)
            if (SCB_1_CHECK_RTS_SS0_PIN_USED)
            {
                /* Set output pin state after block is disabled */
                SCB_1_uart_rts_spi_ss0_Write(SCB_1_GET_UART_RTS_INACTIVE);

                /* Set GPIO to drive output pin */
                SCB_1_SET_HSIOM_SEL(SCB_1_RTS_SS0_HSIOM_REG, SCB_1_RTS_SS0_HSIOM_MASK,
                                               SCB_1_RTS_SS0_HSIOM_POS, SCB_1_RTS_SS0_HSIOM_SEL_GPIO);
            }
        #endif /* (SCB_1_RTS_SS0_PIN) */
    #endif /* !(SCB_1_CY_SCBIP_V0 || SCB_1_CY_SCBIP_V1) */

#else
    #if (SCB_1_UART_TX_PIN)
        /* Set GPIO to drive output pin */
        SCB_1_SET_HSIOM_SEL(SCB_1_TX_HSIOM_REG, SCB_1_TX_HSIOM_MASK,
                                       SCB_1_TX_HSIOM_POS, SCB_1_TX_HSIOM_SEL_GPIO);
    #endif /* (SCB_1_UART_TX_PIN) */

    #if (SCB_1_UART_RTS_PIN)
        /* Set output pin state after block is disabled */
        SCB_1_rts_Write(SCB_1_GET_UART_RTS_INACTIVE);

        /* Set GPIO to drive output pin */
        SCB_1_SET_HSIOM_SEL(SCB_1_RTS_HSIOM_REG, SCB_1_RTS_HSIOM_MASK,
                                       SCB_1_RTS_HSIOM_POS, SCB_1_RTS_HSIOM_SEL_GPIO);
    #endif /* (SCB_1_UART_RTS_PIN) */

#endif /* (SCB_1_SCB_MODE_UNCONFIG_CONST_CFG) */

#if (SCB_1_UART_WAKE_ENABLE_CONST)
    /* Disable skip start feature used for wakeup */
    SCB_1_UART_RX_CTRL_REG &= (uint32) ~SCB_1_UART_RX_CTRL_SKIP_START;
#endif /* (SCB_1_UART_WAKE_ENABLE_CONST) */

    /* Store TX interrupt sources (exclude level triggered). */
    SCB_1_IntrTxMask = LO16(SCB_1_GetTxInterruptMode() & SCB_1_INTR_UART_TX_RESTORE);
}
Exemplo n.º 22
0
void Camera_Start()
{
	Camera_SIOD_SetDriveMode(Camera_SIOD_DM_RES_UP); //turn on pull-up resistors on I2C pins
	Camera_SIOC_SetDriveMode(Camera_SIOC_DM_RES_UP);
	Camera_I2C_Start();
	
	Camera_WriteReg(0x12,0x80); //reset
	CyDelay(1);
	uint16 i;
	for(i=0;Camera_settings[i][0]!=0xff;i++) Camera_WriteReg(Camera_settings[i][0],Camera_settings[i][1]); //camera settings
	for(i=0;Camera_format[i]!=0xff;i++) Camera_WriteReg(Camera_format[i],Camera_qcif[i]); //qcif format (176x144)
	
	uint8 (*buffer)[BUFFER_SIZE]=(uint8(*)[BUFFER_SIZE])Camera_framebuffer; //recast buffer for easier arithmetic
	DMA_channel=Camera_DMA_DmaInitialize(1,1,HI16(CYDEV_PERIPH_BASE),HI16(CYDEV_SRAM_BASE)); //peripheral -> SRAM
	for(i=0;i<sizeof DMA_TD;i++) //set up TDs
	{
		DMA_TD[i]=CyDmaTdAllocate();
		CyDmaTdSetAddress(DMA_TD[i],LO16(Camera_FIFO_dp__F0_REG),LO16((uint32)buffer[i]));
		if(i) CyDmaTdSetConfiguration(DMA_TD[i-1],BUFFER_SIZE,DMA_TD[i],TD_INC_DST_ADR);
	}
	CyDmaChPriority(DMA_channel,0); //ensure highest priority for DMA channel
}
Exemplo n.º 23
0
/*******************************************************************************
* Function Name: Dma_M_Rx_Configuration
********************************************************************************
* Summary:
*  Configures the DMA transfer for RX direction
*   
* Parameters:
*  None.
*
* Return:
*  None.
*
*******************************************************************************/
void Dma_M_Rx_Configuration()
{ 
    /* Init DMA, 1 byte bursts, each burst requires a request */ 
    M_RxChannel = DMA_RX_M_DmaInitialize(DMA_RX_M_BYTES_PER_BURST, DMA_RX_M_REQUEST_PER_BURST,
                                     HI16(DMA_RX_M_SRC_BASE), HI16(DMA_RX_M_DST_BASE));

    M_RxTD[0u] = CyDmaTdAllocate();
    M_RxTD[1u] = CyDmaTdAllocate();
    /* Configure this Td as follows:
    *  - The TD is looping on itself
    *  - Increment the destination address, but not the source address
    */
    CyDmaTdSetConfiguration(M_RxTD[0u], 8u, M_RxTD[1u], TD_INC_DST_ADR);
    CyDmaTdSetConfiguration(M_RxTD[1u], 1u, M_RxTD[0u], 0u);

    /* From the SPIM to the memory */
    CyDmaTdSetAddress(M_RxTD[0u], LO16((uint32)SPIM_BSPIM_sR8_Dp_u0__F1_REG), LO16((uint32)m_rxBuffer));
    CyDmaTdSetAddress(M_RxTD[1u], LO16((uint32)m_rxBuffer), LO16((uint32)m_rxBuffer));

    /* Associate the TD with the channel */
    CyDmaChSetInitialTd(M_RxChannel, M_RxTD[0u]);
}
Exemplo n.º 24
0
//子控件发送消息处理函数
static ptu32_t HmiNotify(struct WindowMsg *pMsg)
{
    HWND hwnd;
    u16 event,id;

    hwnd =pMsg->hwnd;
    event =HI16(pMsg->Param1);
    id =LO16(pMsg->Param1);
	switch(id)
	{
		case ID_CLOSE:
			if(event==MSG_BTN_DOWN)
			{
				PostMessage(hwnd,MSG_CLOSE,0,0);
			}
			break;
			////

		case ID_SHOWTEXT:
			if(event==CBN_SELECTED)//复选框选中
			{
				pb1.Flag |= PBF_SHOWTEXT;
				pb2.Flag |= PBF_SHOWTEXT;
			}

			if(event==CBN_UNSELECTED)//复选框未选中
			{
				pb1.Flag &= ~PBF_SHOWTEXT;
				pb2.Flag &= ~PBF_SHOWTEXT;
			}
			break;
			////
		case    ID_ORG:
			 if(event==CBN_SELECTED)
			 {
				pb1.Flag &= ~PBF_ORG_RIGHT;
				pb2.Flag &= ~PBF_ORG_BOTTOM;
			 }

			 if(event==CBN_UNSELECTED)
			 {
				 pb1.Flag |= PBF_ORG_RIGHT;
				 pb2.Flag |= PBF_ORG_BOTTOM;
			 }
			 break;
	}
    return true;
}
Exemplo n.º 25
0
void `$INSTANCE_NAME`_Start() {
    uint8* DMA_TD = (uint8*)`$INSTANCE_NAME`_DMA_TD;
    uint8 numTD = `$INSTANCE_NAME`_numTD;
    uint8* pwm_data_ptr = ((uint8*)&`$INSTANCE_NAME`_PWM_data) + 0x40;
    uint8* dc_data_ptr = (uint8*)&`$INSTANCE_NAME`_PWM_data;
    uint8 i,j,k;
    
    for (i=0; i<4; i++)
        for (j=0; j<8; j++)
            `$INSTANCE_NAME`_PWM_data.dc[i][j] = 0;
    for (i=0; i<4; i++)
        for (j=0; j<16; j++)
            `$INSTANCE_NAME`_PWM_data.pwm[i][j] = 0;
    
    uint8 interruptState;
    interruptState = CyEnterCriticalSection();
    *(reg8*)`$INSTANCE_NAME`_C_TLC5940_WordCounter__CONTROL_AUX_CTL_REG |= 0x20u;
    *(reg8*)`$INSTANCE_NAME`_C_TLC5940_BitCounter__CONTROL_AUX_CTL_REG |= 0x20u;
    *(reg8*)`$INSTANCE_NAME`_C_TLC5940_WordCounter__PERIOD_REG = 0x08;
    *(reg8*)`$INSTANCE_NAME`_C_TLC5940_gsclk_counter_GSCLKCounter_u0__D1_REG = 0x04;
    `$INSTANCE_NAME`_DP_AUX_0 |= 5;
    `$INSTANCE_NAME`_DP_AUX_1 |= 5;
    `$INSTANCE_NAME`_DP_AUX_0 &= ~0x01;
    `$INSTANCE_NAME`_DP_AUX_1 &= ~0x01;
    CyExitCriticalSection(interruptState);
    
    `$INSTANCE_NAME`_DMA_Chan = `$INSTANCE_NAME`_DMA_DmaInitialize(`$INSTANCE_NAME`_DMA_BYTES_PER_BURST, `$INSTANCE_NAME`_DMA_REQUEST_PER_BURST, 
        HI16(`$INSTANCE_NAME`_DMA_SRC_BASE), HI16(`$INSTANCE_NAME`_DMA_DST_BASE));
    
    for (i = 0; i < numTD; i++)
        DMA_TD[i] = CyDmaTdAllocate();
        
    for (i = 0; i < numTD; i++) {
        CyDmaTdSetConfiguration(DMA_TD[i], 16, DMA_TD[(i+1)%numTD], TD_TERMIN_EN | `$INSTANCE_NAME`_DMA__TD_TERMOUT_EN | TD_INC_SRC_ADR);
    }
    
    for (i = 0; i < 4; i++) {
        CyDmaTdSetAddress(DMA_TD[i*3], LO16((uint32)dc_data_ptr + i*16 ), LO16((uint32)`$INSTANCE_NAME`_SHIFT_REG_FIFO));
        CyDmaTdSetAddress(DMA_TD[i*3+1], LO16((uint32)pwm_data_ptr + i*32 ), LO16((uint32)`$INSTANCE_NAME`_SHIFT_REG_FIFO));
        CyDmaTdSetAddress(DMA_TD[i*3+2], LO16((uint32)pwm_data_ptr + i*32 + 16 ), LO16((uint32)`$INSTANCE_NAME`_SHIFT_REG_FIFO));
    }
    
    CyDmaChSetInitialTd(`$INSTANCE_NAME`_DMA_Chan, DMA_TD[0]);
    CyDmaChEnable(`$INSTANCE_NAME`_DMA_Chan, 1);   
}
Exemplo n.º 26
0
void Configure_DMA(){

ADC2Filter_DMA_Chan = ADC2Filter_DMA_DmaInitialize(ADC2Filter_DMA_BYTES_PER_BURST, ADC2Filter_DMA_REQUEST_PER_BURST, 
    HI16(ADC2Filter_DMA_SRC_BASE), HI16(ADC2Filter_DMA_DST_BASE));
ADC2Filter_DMA_TD[0] = CyDmaTdAllocate();
ADC2Filter_DMA_TD[1] = CyDmaTdAllocate();
CyDmaTdSetConfiguration(ADC2Filter_DMA_TD[0], 2, ADC2Filter_DMA_TD[1], TD_AUTO_EXEC_NEXT);
CyDmaTdSetConfiguration(ADC2Filter_DMA_TD[1], 2, ADC2Filter_DMA_TD[0], ADC2Filter_DMA__TD_TERMOUT_EN);
CyDmaTdSetAddress(ADC2Filter_DMA_TD[0], LO16((uint32)ADC_DelSig_1_DEC_SAMP_PTR), LO16((uint32)Filter_STAGEA_PTR));
CyDmaTdSetAddress(ADC2Filter_DMA_TD[1], LO16((uint32)ADC_DelSig_1_DEC_SAMP_PTR), LO16((uint32)Filter_STAGEB_PTR));
CyDmaChSetInitialTd(ADC2Filter_DMA_Chan, ADC2Filter_DMA_TD[0]);
CyDmaChEnable(ADC2Filter_DMA_Chan, 1);


/*Second buffer*/
DMA_2_Chan = DMA_2_DmaInitialize(DMA_2_BYTES_PER_BURST, DMA_2_REQUEST_PER_BURST, 
    HI16(DMA_2_SRC_BASE), HI16(DMA_2_DST_BASE));
DMA_2_TD[0] = CyDmaTdAllocate();
CyDmaTdSetConfiguration(DMA_2_TD[0], buffersize, CY_DMA_DISABLE_TD /* DMA_2_TD[0]*/, DMA_2__TD_TERMOUT_EN | TD_INC_SRC_ADR | TD_INC_DST_ADR);
CyDmaTdSetAddress(DMA_2_TD[0], LO16((uint32)ADC_samples), LO16((uint32)Buffer_samples));
CyDmaChSetInitialTd(DMA_2_Chan, DMA_2_TD[0]);
CyDmaChEnable(DMA_2_Chan, 1);

/*First buffer*/
DMA_1_Chan = DMA_1_DmaInitialize(DMA_1_BYTES_PER_BURST, DMA_1_REQUEST_PER_BURST, 
    HI16(DMA_1_SRC_BASE), HI16(DMA_1_DST_BASE));
DMA_1_TD[0] = CyDmaTdAllocate();
CyDmaTdSetConfiguration(DMA_1_TD[0], buffersize,/* CY_DMA_DISABLE_TD*/ DMA_1_TD[0], DMA_1__TD_TERMOUT_EN | TD_INC_DST_ADR);
CyDmaTdSetAddress(DMA_1_TD[0], LO16((uint32)Filter_HOLDA_PTR), LO16((uint32)ADC_samples));
CyDmaChSetInitialTd(DMA_1_Chan, DMA_1_TD[0]);
CyDmaChEnable(DMA_1_Chan, 1);

DMA_3_Chan = DMA_3_DmaInitialize(DMA_3_BYTES_PER_BURST, DMA_3_REQUEST_PER_BURST, 
    HI16(DMA_3_SRC_BASE), HI16(DMA_3_DST_BASE));
DMA_3_TD[0] = CyDmaTdAllocate();
CyDmaTdSetConfiguration(DMA_3_TD[0], buffersize, DMA_3_TD[0], DMA_3__TD_TERMOUT_EN | TD_INC_DST_ADR);
CyDmaTdSetAddress(DMA_3_TD[0], LO16((uint32)Filter_HOLDB_PTR), LO16((uint32)LPF_samples));
CyDmaChSetInitialTd(DMA_3_Chan, DMA_3_TD[0]);
CyDmaChEnable(DMA_3_Chan, 1);

DMA_4_Chan = DMA_4_DmaInitialize(DMA_4_BYTES_PER_BURST, DMA_4_REQUEST_PER_BURST, 
    HI16(DMA_4_SRC_BASE), HI16(DMA_4_DST_BASE));
DMA_4_TD[0] = CyDmaTdAllocate();
CyDmaTdSetConfiguration(DMA_4_TD[0], buffersize, CY_DMA_DISABLE_TD /*DMA_4_TD[0]*/, DMA_4__TD_TERMOUT_EN | TD_INC_SRC_ADR | TD_INC_DST_ADR);
CyDmaTdSetAddress(DMA_4_TD[0], LO16((uint32)LPF_samples), LO16((uint32)LPF_buffer));
CyDmaChSetInitialTd(DMA_4_Chan, DMA_4_TD[0]);
CyDmaChEnable(DMA_4_Chan, 1);

}
Exemplo n.º 27
0
cystatus CyDmaTdSetAddress(uint8 tdHandle, uint16 source, uint16 destination) {
	if (source == LO16(UART_Asser_RXDATA_PTR)) td[0] = tdHandle;
	else td[1] = tdHandle;
	return 0;
}
Exemplo n.º 28
0
    },

    {   ASSIGN,	FOREFF|INBREG,
        SBREG,		TLONGLONG|TULONGLONG,
        SSCON,		TANY,
        0,	RDEST,
        "	li AL,AR\n"
        "	li UL,UR\n",
    },

    {   ASSIGN,	FOREFF|INAREG,
        SAREG,		TWORD|TPOINT|TSHORT|TUSHORT|TCHAR|TUCHAR,
        SCON,		TANY,
        0,	RDEST,
        "	lis AL," HA16(AR) "\n"
        "	addi AL,AL," LO16(AR) "\n",
    },

    {   ASSIGN,	FOREFF|INBREG,
        SBREG,		TLONGLONG|TULONGLONG,
        SCON,		TANY,
        0,	RDEST,
        "	lis AL," HA16(AR) "\n"
        "	addi AL,AL," LO16(AR) "\n"
        "	lis UL," HA16(UR) "\n"
        "	addi UL,UL," LO16(UR) "\n",
    },

    {   ASSIGN,	FOREFF|INAREG,
        SAREG,		TWORD|TPOINT,
        SOREG,		TWORD|TPOINT,
Exemplo n.º 29
0
static  u32 win_proc(MSG *pMsg)
{
    HWND hwnd;
    HDC hdc;
    RECT rc,rc0;
    u32 i,x,y;

    hwnd =pMsg->hwnd;

    switch(pMsg->Code)
    {
        case    MSG_CREATE:
                cfg_idx =0;
                bBorder=TRUE;
                bBKGND=TRUE;
                bColor=TRUE;

                for(i=0;i<8;i++)
                {
                    timer_count[i] =0;
                    timer_run[i]    =FALSE;
                }
                GetClientRect(hwnd,&rc0);
                CreateWindow(BUTTON,"关闭",WS_CHILD|BS_NORMAL|WS_BORDER|WS_VISIBLE,RectW(&rc0)-64,RectH(&rc0)-28,60,24,hwnd,ID_CLOSE,NULL);

                y=20;
                x=128+8;
                CreateWindow(BUTTON,"运行",WS_CHILD|BS_HOLD|WS_VISIBLE,x,y+0*28,60,24,hwnd,ID_START_1,NULL);
                CreateWindow(BUTTON,"运行",WS_CHILD|BS_HOLD|WS_VISIBLE,x,y+1*28,60,24,hwnd,ID_START_2,NULL);
                CreateWindow(BUTTON,"运行",WS_CHILD|BS_HOLD|WS_VISIBLE,x,y+2*28,60,24,hwnd,ID_START_3,NULL);
                CreateWindow(BUTTON,"运行",WS_CHILD|BS_HOLD|WS_VISIBLE,x,y+3*28,60,24,hwnd,ID_START_4,NULL);

                y=20;
                x=128+8+64;
                CreateWindow(BUTTON,"清零",WS_CHILD|WS_VISIBLE,x,y+0*28,60,24,hwnd,ID_CLR_1,NULL);
                CreateWindow(BUTTON,"清零",WS_CHILD|WS_VISIBLE,x,y+1*28,60,24,hwnd,ID_CLR_2,NULL);
                CreateWindow(BUTTON,"清零",WS_CHILD|WS_VISIBLE,x,y+2*28,60,24,hwnd,ID_CLR_3,NULL);
                CreateWindow(BUTTON,"清零",WS_CHILD|WS_VISIBLE,x,y+3*28,60,24,hwnd,ID_CLR_4,NULL);

                GDD_CreateTimer(hwnd,0,timer_interval[0],0);
                GDD_CreateTimer(hwnd,1,timer_interval[1],0);
                GDD_CreateTimer(hwnd,2,timer_interval[2],0);
                GDD_CreateTimer(hwnd,3,timer_interval[3],0);
                GDD_CreateTimer(hwnd,7,500,TMR_START);

                break;
                ////
        case    MSG_TIMER:
                {
                    i =pMsg->Param1&0xFF;
                    timer_count[i]++;
                    InvalidateWindow(hwnd);
                }
                break;

        case    MSG_NOTIFY:
                {
                    u16 event,id;

                    event =HI16(pMsg->Param1);
                    id =LO16(pMsg->Param1);

                    switch(event)
                    {
                        case BTN_DOWN:  //按钮按下
                            if(id>=ID_START_1 && id<=ID_START_4)
                            {
                                i =id&0xF;
                                timer_run[i] =TRUE;
                                GDD_ResetTimer(GDD_FindTimer(hwnd,i),timer_interval[i],TMR_START);
                            }

                            if(id>=ID_CLR_1 && id<=ID_CLR_4)
                            {
                                i =id&0xF;
                                timer_count[i] =0;
                                InvalidateWindow(hwnd);
                            }
                            break;
                            ////

                        case BTN_UP:    //按钮弹起
                            if(id==ID_CLOSE)
                            {
                                PostMessage(hwnd,MSG_CLOSE,0,0);
                            }

                            if(id>=ID_START_1 && id<=ID_START_4)
                            {
                                i =id&0xF;
                                timer_run[i] =FALSE;
                                GDD_ResetTimer(GDD_FindTimer(hwnd,i),timer_interval[i],0);
                            }
                            break;
                            ////



                    }

                }
                break;
                ////

        case    MSG_PAINT:
                {
                    char wbuf[32];

                    hdc =BeginPaint(hwnd);
                    GetClientRect(hwnd,&rc0);
                    SetFillColor(hdc,RGB(100,100,100));
                    FillRect(hdc,&rc0);

                    SetRect(&rc,4,20,128,24);
                    for(i=0;i<4;i++)
                    {
                        SetTextColor(hdc,DrawText_Color_Tbl[i].text_color);
                        SetDrawColor(hdc,DrawText_Color_Tbl[i].bd_color);
                        SetFillColor(hdc,DrawText_Color_Tbl[i].bk_color);
                        sprintf(wbuf," 定时器%d: %d",i+1,timer_count[i]);

                        if(timer_run[i]!=FALSE)
                        {
                            DrawText(hdc,wbuf,-1,&rc,DT_LEFT|DT_VCENTER|DT_BORDER|DT_BKGND);
                        }
                        else
                        {
                            if(timer_count[7]&0x01)
                            {
                                DrawText(hdc,wbuf,-1,&rc,DT_LEFT|DT_VCENTER|DT_BORDER|DT_BKGND);

                            }
                            else
                            {
                                DrawText(hdc,wbuf,-1,&rc,DT_LEFT|DT_VCENTER|DT_BKGND);
                            }
                        }

                        OffsetRect(&rc,0,28);

                    }

                    EndPaint(hwnd,hdc);

                }
                break;
                ////

        default:
                return  DefWindowProc(pMsg);


    }
    return  0;
}
Exemplo n.º 30
0
int sbv_patch_enable_lmb()
{
	u8 buf[256];
	slib_exp_lib_t *modload_lib = (slib_exp_lib_t *)buf;
	smod_mod_info_t *loadfile_info = (smod_mod_info_t *)buf;
	void *pStartModule, *pLoadModuleBuffer, *lf_text_start, *patch_addr;
	u32 lf_rpc_dispatch, lf_jump_table, result;
	int nexps, id, i;

	memset(&_slib_cur_exp_lib_list, 0, sizeof(slib_exp_lib_list_t));

	/* Locate the modload export library - it must have at least 16 exports.  */
	if ((nexps = slib_get_exp_lib("modload", modload_lib)) < 16)
		return -1;

	pStartModule = modload_lib->exports[8];
	pLoadModuleBuffer = modload_lib->exports[10];

	/* Now we need to find the loadfile module.  */
	memset(buf, 0, sizeof(smod_mod_info_t));
	if (!(id = smod_get_mod_by_name("LoadModuleByEE", loadfile_info)))
		return -1;

	/* Locate the loadfile RPC dispatch code, where the first 4 instructions look like:
	
	   27bdffe8	addiu	$sp, -24
	   2c820006	sltiu	$v0, $a0, 6
	   14400003	bnez	$v0, +12
	   afbf0010	sw	$ra, 0x10($sp)
	*/
	lf_text_start = (void *)(loadfile_info->text_start + 0x400);
	smem_read(lf_text_start, buf, sizeof buf);

	for (i = 0; i < sizeof buf; i += 4) {
		if ((*(u32 *)(buf + i) == 0x27bdffe8) &&
				(*(u32 *)(buf + i + 4) == 0x2c820006) &&
				(*(u32 *)(buf + i + 8) == 0x14400003) &&
				(*(u32 *)(buf + i + 12) == 0xafbf0010))
			break;
	}
	/* This is a special case: if the IOP was reset with an image that contains a
	   LOADFILE that supports LMB, we won't detect the dispatch routine.  If we
	   even got this far in the code then we can return success.  */
	if (i >= sizeof buf)
		return 0;

	/* We need to extract the address of the jump table, it's only 40 bytes in. */
	lf_rpc_dispatch = (u32)lf_text_start + i;
	smem_read((void *)lf_rpc_dispatch, buf, 40);

	lf_jump_table = (*(u16 *)(buf + 0x1c) << 16) + *(s16 *)(buf + 0x24);

	/* Now we can patch our subversive LoadModuleBuffer RPC call.  */
	SifInitIopHeap();
	if (!(patch_addr = SifAllocIopHeap(sizeof lmb_patch)))
		return -1;

	/* result is where the RPC return structure is stored.  */
	result = (u32)patch_addr + 96;
	lmb_patch[5] = JAL((u32)pLoadModuleBuffer);
	lmb_patch[7] = HI16(result);
	lmb_patch[9] = LO16(result);
	lmb_patch[15] = JAL((u32)pStartModule);

	SyncDCache(lmb_patch, (void *)(lmb_patch + 24));
	smem_write(patch_addr, lmb_patch, sizeof lmb_patch);

	/* Finally.  The last thing to do is to patch the loadfile RPC dispatch routine
	   so that it will jump to entry #6 in it's jump table, and to patch the jump
	   table itself.  */
	ee_kmode_enter();
	*(u32 *)(SUB_VIRT_MEM + lf_rpc_dispatch + 4) = 0x2c820007;
	*(u32 *)(SUB_VIRT_MEM + lf_jump_table + 0x18) = (u32)patch_addr;
	ee_kmode_exit();

	return 0;
}