Beispiel #1
0
/*******************************************************************************
* Function Name: WaveDAC_0_Low_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 WaveDAC_0_Low_Wave2Setup(const uint8 * wavePtr, uint16 sampleSize)
 
{
	#if (CY_PSOC3)
		uint16 memoryType; /* determining the source memory type */
		memoryType = (WaveDAC_0_Low_HI16FLASHPTR == HI16(wavePtr)) ? HI16(CYDEV_FLS_BASE) : HI16(CYDEV_SRAM_BASE);
			
		WaveDAC_0_Low_Wave2Chan = WaveDAC_0_Low_Wave2_DMA_DmaInitialize(
		WaveDAC_0_Low_Wave2_DMA_BYTES_PER_BURST, WaveDAC_0_Low_Wave2_DMA_REQUEST_PER_BURST,
		memoryType, HI16(CYDEV_PERIPH_BASE));
	#else /* PSoC 5 */
		WaveDAC_0_Low_Wave2Chan = WaveDAC_0_Low_Wave2_DMA_DmaInitialize(
		WaveDAC_0_Low_Wave2_DMA_BYTES_PER_BURST, WaveDAC_0_Low_Wave2_DMA_REQUEST_PER_BURST,
		HI16(wavePtr), HI16(WaveDAC_0_Low_DAC8__D));
	#endif /* CY_PSOC3 */
	
	/*
	* TD is looping on itself. 
	* Increment the source address, but not the destination address. 
	*/
	(void)CyDmaTdSetConfiguration(WaveDAC_0_Low_Wave2TD, sampleSize, WaveDAC_0_Low_Wave2TD, 
                                    (uint8)CY_DMA_TD_INC_SRC_ADR | (uint8)WaveDAC_0_Low_Wave2_DMA__TD_TERMOUT_EN); 
	
	/* Set the TD source and destination address */
	(void)CyDmaTdSetAddress(WaveDAC_0_Low_Wave2TD, LO16((uint32)wavePtr), LO16(WaveDAC_0_Low_DAC8__D));
	
	/* Associate the TD with the channel */
	(void)CyDmaChSetInitialTd(WaveDAC_0_Low_Wave2Chan, WaveDAC_0_Low_Wave2TD);
}
Beispiel #2
0
static void scsiPhyInitDMA()
{
	// One-time init only.
	if (scsiDmaTxChan == CY_DMA_INVALID_CHANNEL)
	{
		scsiDmaRxChan =
			SCSI_RX_DMA_DmaInitialize(
				1, // Bytes per burst
				1, // request per burst
				HI16(CYDEV_PERIPH_BASE),
				HI16(CYDEV_SRAM_BASE)
				);

		scsiDmaTxChan =
			SCSI_TX_DMA_DmaInitialize(
				1, // Bytes per burst
				1, // request per burst
				HI16(CYDEV_SRAM_BASE),
				HI16(CYDEV_PERIPH_BASE)
				);

		CyDmaChDisable(scsiDmaRxChan);
		CyDmaChDisable(scsiDmaTxChan);

		scsiDmaRxTd[0] = CyDmaTdAllocate();
		scsiDmaTxTd[0] = CyDmaTdAllocate();

		SCSI_RX_DMA_COMPLETE_StartEx(scsiRxCompleteISR);
		SCSI_TX_DMA_COMPLETE_StartEx(scsiTxCompleteISR);
	}
}
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]);
}
Beispiel #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
}
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);

}
Beispiel #6
0
/*******************************************************************************
* Function Name: AuxDetection_Initialization
********************************************************************************
* Summary:
*       This routine sets up the DMA path for obtaining the AUX I2S data in
*		SRAM buffer for comparing.
*
* Parameters:
*  void
*
* Return:
*  void
*
*******************************************************************************/
void AuxDetection_Initialization(void)
{
    uint16 index;
    
    I2SRxMDAChan = I2S_Rx_DMA_DmaInitialize(1, 1, HI16(CYDEV_PERIPH_BASE),HI16(CYDEV_SRAM_BASE));
    auxDMA_Td = CyDmaTdAllocate();
    CyDmaTdSetConfiguration(auxDMA_Td, AUX_TD_SIZE, auxDMA_Td, TD_INC_DST_ADR | auxTermOut);
    CyDmaTdSetAddress(auxDMA_Td, (uint16)(I2S_RX_FIFO_0_PTR), (uint16)auxBuffer );
    CyDmaChSetInitialTd(I2SRxMDAChan, auxDMA_Td);  
   
    for(index = 0; index < AUX_TD_SIZE; index++)
    {
        auxBuffer[index] = 0;
    }
}
Beispiel #7
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);
}
Beispiel #8
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);   
}
Beispiel #9
0
/*******************************************************************************
* Function Name: OSC1_ADC_SAR_Init
********************************************************************************
*
* Summary:
*  Inits channels for DMA transfer. Provides loading period to the AMUX address
*  selection counter
*
* Parameters:
*  None.
*
* Return:
*  None.
*
* Reentrant:
*  No.
*
*******************************************************************************/
void OSC1_ADC_SAR_Init(void)
{
    /* Init DMA, 2 bytes bursts, each burst requires a request */
    OSC1_ADC_SAR_tempChan = OSC1_ADC_SAR_TempBuf_DmaInitialize(OSC1_ADC_SAR_TEMP_BYTES_PER_BURST,
        OSC1_ADC_SAR_REQUEST_PER_BURST, (uint16)(HI16(CYDEV_PERIPH_BASE)), (uint16)(HI16(CYDEV_SRAM_BASE)));

    /* Init DMA, (OSC1_ADC_SAR_NUMBER_OF_CHANNELS << 1u) bytes bursts, each burst requires a request */
    OSC1_ADC_SAR_finalChan = OSC1_ADC_SAR_FinalBuf_DmaInitialize((uint8)OSC1_ADC_SAR_FINAL_BYTES_PER_BURST,
        OSC1_ADC_SAR_REQUEST_PER_BURST, (uint16)(HI16(CYDEV_SRAM_BASE)), (uint16)(HI16(CYDEV_SRAM_BASE)));

    #if(OSC1_ADC_SAR_IRQ_REMOVE == 0u)
        /* Set the ISR to point to the OSC1_ADC_SAR_IRQ Interrupt. */
        OSC1_ADC_SAR_IRQ_SetVector(&OSC1_ADC_SAR_ISR);
        /* Set the priority. */
        OSC1_ADC_SAR_IRQ_SetPriority((uint8)OSC1_ADC_SAR_INTC_NUMBER);
    #endif   /* End OSC1_ADC_SAR_IRQ_REMOVE */

}
Beispiel #10
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);
}
Beispiel #11
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]);
}
Beispiel #12
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
}
Beispiel #13
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;
}
Beispiel #14
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);
}
Beispiel #15
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);
}
static  u32 win_proc(MSG *pMsg)
{
    HWND hwnd;
    HDC hdc;
    RECT rc,rc0;
    u32 i;

    hwnd =pMsg->hwnd;

    switch(pMsg->Code)
    {
        case    MSG_CREATE:

        		text_align_idx =0;

                prog1_val=0;
                prog2_val=0;

                prog1_inc=1;
                prog2_inc=1;

            	pb1.Flag    =PBF_SHOWTEXT|PBF_ORG_LEFT;
            	pb1.Range	=100;
            	pb1.Pos		=prog1_val;
            	pb1.FGColor =RGB(0,160,0);
            	pb1.BGColor =RGB(10,10,10);
            	pb1.TextColor =RGB(240,240,240);
            	pb1.DrawTextFlag =DT_VCENTER|DT_CENTER;


            	pb2.Flag    =PBF_SHOWTEXT|PBF_ORG_BOTTOM;
            	pb2.Range	=100;
            	pb2.Pos		=prog1_val;
            	pb2.FGColor =RGB(200,0,0);
            	pb2.BGColor =RGB(10,10,200);
            	pb2.TextColor =RGB(1,1,1);
            	pb2.DrawTextFlag =DT_VCENTER|DT_CENTER;

                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);

                i=RectH(&rc0)-(3*30);
                CreateWindow(CHECKBOX,"显示文字",WS_CHILD|CBS_SELECTED|WS_VISIBLE,4,i+0*32,128,24,hwnd,ID_SHOWTEXT,NULL);
                CreateWindow(CHECKBOX,"增长方向",WS_CHILD|CBS_SELECTED|WS_VISIBLE,4,i+1*32,128,24,hwnd,ID_ORG,NULL);
 //               CreateWindow(CHECKBOX,"改变颜色",WS_CHILD|CBS_SELECTED|WS_VISIBLE,4,i+2*32,128,24,hwnd,ID_COLOR,NULL);

                CreateWindow(PROGRESSBAR,"水平进度条1",WS_CHILD|PBS_HOR|WS_VISIBLE,8,16,128,28,hwnd,ID_PROGBAR1,NULL);
                CreateWindow(PROGRESSBAR,"垂直进度条2",WS_CHILD|PBS_VER|WS_VISIBLE,160,16,28,128,hwnd,ID_PROGBAR2,NULL);

                GDD_CreateTimer(hwnd,1,3000,TMR_START);
                GDD_CreateTimer(hwnd,2,100,TMR_START);

                break;
                ////
        case    MSG_TIMER:
                {
                    switch(pMsg->Param1)
                    {
                        case    1:
                        		{
									HWND wnd;

									text_align_idx++;
									if(text_align_idx>=9)
									{
										text_align_idx=0;
									}
									pb1.DrawTextFlag =text_align[text_align_idx];
									pb2.DrawTextFlag =text_align[text_align_idx];

									wnd =GetDlgItem(hwnd,ID_PROGBAR1);
									SendMessage(wnd,PBM_SETDATA,(u32)&pb1,NULL);

									wnd =GetDlgItem(hwnd,ID_PROGBAR2);
									SendMessage(wnd,PBM_SETDATA,(u32)&pb2,NULL);
                        		}
                                break;
                                /////
                        case    2:
                                {
                                	HWND wnd;

                                	if(prog1_val<=0)
                                	{
                                		prog1_val =0;
                                		prog1_inc =1;
                                	}
                                	if(prog1_val>=100)
                                	{
                                		prog1_val =100;
                                		prog1_inc =-1;
                                	}
                                	wnd =GetDlgItem(hwnd,ID_PROGBAR1);
                                	pb1.Pos =prog1_val;
                                	SendMessage(wnd,PBM_SETDATA,(u32)&pb1,NULL);

                                   	sprintf(text_buf,"进度:%d...",pb1.Pos);
                                   	SetWindowText(wnd,text_buf,1000);
                                	prog1_val += prog1_inc;

                                	if(prog2_val<=0)
                                	{
                                		prog2_val =0;
                                		prog2_inc =1;
                                	}
                                	if(prog2_val>=100)
                                	{
                                		prog2_val =100;
                                		prog2_inc =-1;
                                	}
                                	wnd =GetDlgItem(hwnd,ID_PROGBAR2);
                                	pb2.Pos =prog2_val;
                                	SendMessage(wnd,PBM_SETDATA,(u32)&pb2,NULL);

                                	sprintf(text_buf,"%d%%",pb2.Pos);
                                	SetWindowText(wnd,text_buf,1000);
                                	prog2_val += prog2_inc;


                                    InvalidateWindow(hwnd);
                                }
                                break;
                                /////
                    }
                }
                break;

        case    MSG_NOTIFY:
                {
                    u16 event,id;

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

                    switch(id)
                    {
                        case ID_CLOSE:
                            if(event==BTN_UP)
                            {
                                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;
                        	 ////
                    }

                }
                break;
                ////

        case    MSG_PAINT:
                {
                    hdc =BeginPaint(hwnd);

                    GetClientRect(hwnd,&rc0);
                    SetFillColor(hdc,RGB(200,200,200));
                    FillRect(hdc,&rc0);

                    EndPaint(hwnd,hdc);

                }
                break;
                ////

        default:
                return  DefWindowProc(pMsg);


    }
    return  0;
}
Beispiel #17
0
static  u32 win_proc(MSG *pMsg)
{
    HWND hwnd;
    HDC hdc;
    RECT rc,rc0;
    u32 x,y;

    hwnd =pMsg->hwnd;

    switch(pMsg->Code)
    {
        case    MSG_CREATE:
                timer_500ms_count=0;
                memset(ZigBeeTextBuf,0,sizeof(ZigBeeTextBuf));
                memset(ZigBeeTimeBuf,0,sizeof(ZigBeeTimeBuf));
                zigbee_ShowString("Zigbee Text");
                hwndZigBee =hwnd;
                GetClientRect(hwnd,&rc0);
                SetFocusWindow(hwnd);
                CreateWindow(BUTTON,"关闭",WS_BORDER|WS_DLGFRAME|WS_CHILD|BS_SIMPLE|WS_VISIBLE,RectW(&rc0)-60,RectH(&rc0)-60,56,56,hwnd,ID_CLOSE,NULL);

                SetRect(&rcZigBeeString,4,4,RectW(&rc0)-4*2,60);

                x=4;
                y=RectH(&rc0)-70;
                SetRect(&rcGroupBox_LED,x,y,100,66);
                SetRect(&rcGroupBox_CTR,x+100+4,y,100,66);

                x=rcGroupBox_LED.left+12;
                y=rcGroupBox_LED.top+18;
                CreateWindow(BUTTON,"LED1",WS_BORDER|WS_CHILD|BS_HOLD|WS_VISIBLE,x,y+0*24,72,20,hwnd,ID_LED1,NULL);
                CreateWindow(BUTTON,"LED2",WS_BORDER|WS_CHILD|BS_HOLD|WS_VISIBLE,x,y+1*24,72,20,hwnd,ID_LED2,NULL);

                x=rcGroupBox_CTR.left+12;
                y=rcGroupBox_CTR.top+18;
                CreateWindow(BUTTON,"组网",WS_BORDER|WS_CHILD|WS_VISIBLE,x,y+0*24,72,20,hwnd,ID_NET_ON,NULL);
                CreateWindow(BUTTON,"断开",WS_BORDER|WS_CHILD|WS_VISIBLE,x,y+1*24,72,20,hwnd,ID_NET_OFF,NULL);

                CreateWindow(BUTTON,"发送",WS_BORDER|WS_CHILD|BS_SIMPLE|WS_VISIBLE,RectW(&rc0)-60,rcGroupBox_CTR.top-(24+2),56,24,hwnd,ID_SEND,NULL);

                GDD_CreateTimer(hwnd,0,500,TMR_START);

                break;
                ////
        case MSG_KEY_DOWN:
         		break;
         		//////

        case MSG_KEY_UP:
        {
        		u16 key_val;
                hdc =BeginPaint(hwnd);
        		key_val =LO16(pMsg->Param1);
        		sprintf(ZigBeeTextBuf,"KeyVal:%04XH",key_val);
                DrawText(hdc,ZigBeeTextBuf,-1,&rc,DT_LEFT|DT_VCENTER|DT_BORDER|DT_BKGND);
                EndPaint(hwnd,hdc);
//        		InvalidateWindow(hwnd);
        }
         		break;
         		//////

        case    MSG_TIMER:
                {
                    timer_500ms_count++;

                    sprintf(ZigBeeTimeBuf,"TIME:%06d",timer_500ms_count);

                    /*
                    i=SendMessage(GetDesktopWindow(),MSG_GET_POS,timer_500ms_count,0);
                    printf("i=%08XH.\r\n",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_LED1)
                            {
                                zigbee_LED1_ON();
                            }

                            if(id==ID_LED2)
                            {
                                zigbee_LED2_ON();
                            }

                            if(id==ID_NET_ON)
                            {
                                zigbee_NET_ON();
                            }

                            if(id==ID_NET_OFF)
                            {
                                zigbee_NET_OFF();
                            }

                            if(id==ID_SEND)
                            {
                                zigbee_send_string(ZigBeeTextBuf);
                            }
                            break;
                            ////

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

                            if(id==ID_LED1)
                            {
                                zigbee_LED1_OFF();
                            }

                            if(id==ID_LED2)
                            {
                                zigbee_LED2_OFF();
                            }


                            break;
                            ////



                    }

                }
                break;
                ////

        case    MSG_PAINT:
                {

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

                    SetTextColor(hdc,RGB(0,0,128));
                    SetDrawColor(hdc,RGB(100,100,100));
                    DrawGroupBox(hdc,&rcZigBeeString,"信息接收区");

                    ////
                    SetRect(&rc,
                            rcGroupBox_LED.left,
                            rcGroupBox_LED.top-(24+2),
                            RectW(&rcGroupBox_LED),
                            24);

                    if(zigbee_is_ok())
                    {
                        SetTextColor(hdc,RGB(0,255,0));
                        SetDrawColor(hdc,RGB(0,200,0));
                        SetFillColor(hdc,RGB(0,128,0));
                        DrawText(hdc,"连接成功",-1,&rc,DT_CENTER|DT_VCENTER|DT_BORDER|DT_BKGND);

                    }
                    else
                    {
                        SetTextColor(hdc,RGB(255,0,0));
                        SetDrawColor(hdc,RGB(200,0,0));
                        SetFillColor(hdc,RGB(100,0,0));
                        if(timer_500ms_count&0x01)
                        {
                            DrawText(hdc,"未连接",-1,&rc,DT_CENTER|DT_VCENTER|DT_BORDER|DT_BKGND);

                        }
                        else
                        {
                            DrawText(hdc," ",-1,&rc,DT_CENTER|DT_VCENTER|DT_BORDER|DT_BKGND);
                        }

                    }

                    ////
                    SetRect(&rc,
                            rcGroupBox_CTR.left,
                            rcGroupBox_CTR.top-(24+2),
                            RectW(&rcGroupBox_CTR),
                            24);
                    SetTextColor(hdc,RGB(0,255,255));
                    SetDrawColor(hdc,RGB(0,200,200));
                    SetFillColor(hdc,RGB(0,80,80));
                    DrawText(hdc,ZigBeeTimeBuf,-1,&rc,DT_CENTER|DT_VCENTER|DT_BORDER|DT_BKGND);

                    ////
                    SetTextColor(hdc,RGB(0,255,0));
                    SetDrawColor(hdc,RGB(0,200,0));
                    SetFillColor(hdc,RGB(0,80,0));

                    CopyRect(&rc,&rcZigBeeString);
                    InflateRectEx(&rc,-4,-20,-4,-4);
                    DrawText(hdc,ZigBeeTextBuf,-1,&rc,DT_LEFT|DT_VCENTER|DT_BORDER|DT_BKGND);

                    SetTextColor(hdc,RGB(0,0,128));
                    SetDrawColor(hdc,RGB(80,80,80));
                    DrawGroupBox(hdc,&rcGroupBox_LED,"LED控制");
                    DrawGroupBox(hdc,&rcGroupBox_CTR,"网络控制");

                    EndPaint(hwnd,hdc);

                }
                break;
                ////

        default:
                return  DefWindowProc(pMsg);


    }
    return  0;
}
Beispiel #18
0
static  u32 win_proc(MSG *pMsg)
{
    HWND hwnd;
    HDC hdc;
    RECT rc,rc0;
    u32 i;

    hwnd =pMsg->hwnd;

    switch(pMsg->Code)
    {
        case    MSG_CREATE:


                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);

                SetRect(&rc,4,8,120,100);
                hwndLB1=CreateWindow(LISTBOX,"列表框1",WS_CHILD|WS_BORDER|WS_VISIBLE,rc.left,rc.top,RectW(&rc),RectH(&rc),hwnd,ID_LISTBOX1,NULL);
                OffsetRect(&rc,RectW(&rc)+8,0);
                hwndLB2=CreateWindow(LISTBOX,"列表框2",WS_CHILD|WS_BORDER|WS_VISIBLE,rc.left,rc.top,RectW(&rc),RectH(&rc),hwnd,ID_LISTBOX2,NULL);

                GetWindowRect(hwndLB1,&rc);
                OffsetRect(&rc,0,RectH(&rc)+4);
                ScreenToClient(hwnd,(POINT*)&rc,2);
                CreateWindow(BUTTON,"-->",WS_CHILD|BS_NORMAL|WS_BORDER|WS_VISIBLE,rc.right-50,rc.top,50,20,hwnd,ID_RIGHT,NULL);

                GetWindowRect(hwndLB2,&rc);
                OffsetRect(&rc,0,RectH(&rc)+4);
                ScreenToClient(hwnd,(POINT*)&rc,2);
                CreateWindow(BUTTON,"<--",WS_CHILD|BS_NORMAL|WS_BORDER|WS_VISIBLE,rc.left,rc.top,50,20,hwnd,ID_LEFT,NULL);


                SendMessage(hwndLB1,LBM_ADDSTRING,0,(u32)"ListItem-0");
                SendMessage(hwndLB1,LBM_ADDSTRING,1,(u32)"ListItem-1");
                SendMessage(hwndLB1,LBM_ADDSTRING,2,(u32)"ListItem-2");
                SendMessage(hwndLB1,LBM_ADDSTRING,3,(u32)"ListItem-3");
                SendMessage(hwndLB1,LBM_ADDSTRING,4,(u32)"ListItem-4");
                SendMessage(hwndLB1,LBM_ADDSTRING,5,(u32)"ListItem-5");
                SendMessage(hwndLB1,LBM_ADDSTRING,6,(u32)"ListItem-6");
                SendMessage(hwndLB1,LBM_ADDSTRING,7,(u32)"ListItem-7");
                SendMessage(hwndLB1,LBM_ADDSTRING,8,(u32)"ListItem-8");
                SendMessage(hwndLB1,LBM_ADDSTRING,9,(u32)"ListItem-9");
                SendMessage(hwndLB1,LBM_SETTOPINDEX,0,0);
                SendMessage(hwndLB1,LBM_SETCURSEL,3,0);

                SendMessage(hwndLB2,LBM_ADDSTRING,0,(u32)"ListItem-10");
                SendMessage(hwndLB2,LBM_ADDSTRING,1,(u32)"ListItem-11");
                SendMessage(hwndLB2,LBM_ADDSTRING,2,(u32)"ListItem-12");
                SendMessage(hwndLB2,LBM_ADDSTRING,3,(u32)"ListItem-13");
                SendMessage(hwndLB2,LBM_ADDSTRING,4,(u32)"ListItem-14");
                SendMessage(hwndLB2,LBM_ADDSTRING,5,(u32)"ListItem-15");
                SendMessage(hwndLB2,LBM_ADDSTRING,6,(u32)"ListItem-16");
                SendMessage(hwndLB2,LBM_ADDSTRING,7,(u32)"ListItem-17");
                SendMessage(hwndLB2,LBM_ADDSTRING,8,(u32)"ListItem-18");
                SendMessage(hwndLB2,LBM_ADDSTRING,9,(u32)"ListItem-19");
                SendMessage(hwndLB2,LBM_SETTOPINDEX,0,0);
                SendMessage(hwndLB2,LBM_SETCURSEL,3,0);

                GDD_CreateTimer(hwnd,1,3000,TMR_START);
                GDD_CreateTimer(hwnd,2,100,TMR_START);

                break;
                ////
        case    MSG_TIMER:
                {
                    switch(pMsg->Param1)
                    {
                        case    1:
                        		{

                        		}
                                break;
                                /////
                        case    2:
                                {

                                }
                                break;
                                /////
                    }
                }
                break;

        case    MSG_NOTIFY:
                {
                    u16 event,id;

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

                    if(event==BTN_UP && id==ID_CLOSE)
                    {
                    	PostMessage(hwnd,MSG_CLOSE,0,0);
                    }////


                    if(event==BTN_UP && id==ID_RIGHT)
                    {
                    	char *buf;
                    	int i;
                    	i =SendMessage(hwndLB1,LBM_GETCURSEL,0,0);

                    	if(i>=0)
                    	{
                    	     buf =(char*)malloc(SendMessage(hwndLB1,LBM_GETTEXTLEN,i,0));
                    	     if(buf!=NULL)
                    	     {
                    	         SendMessage(hwndLB1,LBM_GETTEXT,i,(u32)buf);
                    	         SendMessage(hwndLB1,LBM_DELSTRING,i,0);

                    	         SendMessage(hwndLB2,LBM_ADDSTRING,-1,(u32)buf);
                    	         i=SendMessage(hwndLB2,LBM_GETCOUNT,0,0)-1;
                    	         SendMessage(hwndLB2,LBM_SETTOPINDEX,i-3,0);
                    	         SendMessage(hwndLB2,LBM_SETCURSEL,-1,0);

                    	         free(buf);
                    	      }
                    	}
                    }////

                    if(event==BTN_UP && id==ID_LEFT)
                    {
                    	char *buf;
                        int i;
                        i =SendMessage(hwndLB2,LBM_GETCURSEL,0,0);
                        if(i>=0)
                        {
                    		buf =(char*)malloc(SendMessage(hwndLB2,LBM_GETTEXTLEN,i,0));
                    		if(buf!=NULL)
                    		{
                    			SendMessage(hwndLB2,LBM_GETTEXT,i,(u32)buf);
                    			SendMessage(hwndLB2,LBM_DELSTRING,i,0);

                    			SendMessage(hwndLB1,LBM_ADDSTRING,-1,(u32)buf);
                    			i=SendMessage(hwndLB1,LBM_GETCOUNT,0,0)-1;
                    			SendMessage(hwndLB1,LBM_SETTOPINDEX,i-3,0);
                    			SendMessage(hwndLB1,LBM_SETCURSEL,-1,0);

                    			free(buf);
                    		}
                         }
                    }////

                    if(event==LBN_SELCHANGE && id==ID_LISTBOX1)
                    {
                    	printf("listbox1 sel change.\r\n");
                    }////

                    if(event==LBN_SELCHANGE && id==ID_LISTBOX2)
                    {
                    	printf("listbox2 sel change.\r\n");
                    }////
                }
                break;
                ////

        case    MSG_PAINT:
                {
                    hdc =BeginPaint(hwnd);

                    GetClientRect(hwnd,&rc0);
                    SetFillColor(hdc,RGB(200,200,200));
                    FillRect(hdc,&rc0);

                    EndPaint(hwnd,hdc);

                }
                break;
                ////

        default:
                return  DefWindowProc(pMsg);


    }
    return  0;
}
Beispiel #19
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;
}
Beispiel #20
0
/*******************************************************************************
* Function Name: SimulateCyclingSpeed
********************************************************************************
*
* Summary:
*  Simulates Cycling speed data and send them to the Client device.
*
* Parameters:  
*  None.
*
* Return: 
*  None
*
*******************************************************************************/
void SimulateCyclingSpeed(void)
{
    CYBLE_API_RESULT_T apiResult;
    uint8 csValue[CSC_MEASUREMENT_CHAR_SIZE];
    uint8 len = 0u;
    
    /*  Updates CSC Measurement Characteristic data */
    wheelRev += CSC_WHEEL_REV_VAL;
    lastWheelEvTime += CSC_WHEEL_EV_TIME_VAL;
    crankRev += CSC_CRANK_REV_VAL;
    lastCrankEvTime += CSC_CRANK_EV_TIME_VAL;

    if((speedSimulation & CSCS_NOTIFICATION_ENABLE) != 0u)
    {
        /* Pack SCS Measurement Characteristic data */
        csValue[len++] = cscFlags;
        
        if(0u != (cscFlags & CSC_WHEEL_REV_DATA_PRESENT))
        {
            csValue[len++] = LO8(LO16(wheelRev));
            csValue[len++] = HI8(LO16(wheelRev));
            csValue[len++] = LO8(HI16(wheelRev));
            csValue[len++] = HI8(HI16(wheelRev));

            csValue[len++] = LO8(lastWheelEvTime);
            csValue[len++] = HI8(lastWheelEvTime);

            /* Calculate instantaneous speed */
            cscSpeed = ((((((uint32)WHEEEL_CIRCUMFERENCE_CM) * (CSC_WHEEL_REV_VAL))
                        * ((uint32) WHEEL_TIME_EVENT_UNIT)) / ((uint32) CSC_WHEEL_EV_TIME_VAL))
                            * ((uint32) MS_TO_KMH_COEFITIENT)) / ((uint32) INT_DIVIDER);
        }

        if(0u != (cscFlags & CSC_CRANK_REV_DATA_PRESENT))
        {
            csValue[len++] = LO8(crankRev);
            csValue[len++] = HI8(crankRev);

            csValue[len++] = LO8(lastCrankEvTime);
            csValue[len++] = HI8(lastCrankEvTime);

            cscCadenceRpm = (((uint32) CSC_CRANK_REV_VAL) * ((uint32) WHEEL_TIME_EVENT_UNIT) * 60u) /
                               ((uint32) CSC_CRANK_EV_TIME_VAL);
        }
        
        /* Send Characteristic value to peer device */
        apiResult = CyBle_CscssSendNotification(cyBle_connHandle, CYBLE_CSCS_CSC_MEASUREMENT, len, csValue);

        if(CYBLE_ERROR_OK == apiResult)
        {
            DBG_PRINTF("CscssSendNotification, ");
            DBG_PRINTF("Wheel Revolution: %ld, ", wheelRev);
            DBG_PRINTF("Wheel Time: %ld s, ", lastWheelEvTime / CSC_TIME_PER_SEC);
            DBG_PRINTF("Crank Revolution: %ld, ", crankRev);
            DBG_PRINTF("Crank Time: %ld s, ", lastCrankEvTime / CSC_TIME_PER_SEC);
            DBG_PRINTF("Speed: %d.%2.2d km/h, ", cscSpeed/100u, cscSpeed%100u);
            DBG_PRINTF("Cadence: %d rpm\r\n", cscCadenceRpm);
        }
        else
        {
            DBG_PRINTF("Error #%x while sending CSC Measurement Characteristic notification\r\n", apiResult);
        }
    }
    
    if(((speedSimulation & CSCS_INDICATION_ENABLE) != 0u) && (speedCPresponse != 0u))
    {
        apiResult = CyBle_CscssSendIndication(cyBle_connHandle, CYBLE_CSCS_SC_CONTROL_POINT, 
                                                 scCPResponse[CSCS_SC_CP_RESP_LEN_IDX], scCPResponse + 1u);
        DBG_PRINTF("CyBle_CscsSendIndication(CYBLE_CSCS_SC_CONTROL_POINT), API result: %x \r\n", apiResult);
        speedCPresponse = 0u;
    }
}
Beispiel #21
0
/*******************************************************************************
* Function Name: CscServiceAppEventHandler
********************************************************************************
*
* Summary:
*  This is an event callback function to receive events from the BLE Component,
*  which are specific to Cycling Speed and Cadence Service.
*
* Parameters:  
*  event:           CSCS event.
*  *eventParams:    Data structure specific to event received.
*
* Return: 
*  None
*
*******************************************************************************/
void CscsCallback(uint32 event, void *eventParam)
{
    uint8 i;
    uint8 sensorLocSupported = 0u;
    CYBLE_CSCS_CHAR_VALUE_T *wrReqParam;

    switch(event)
    {
    /* CSCS Server - Notifications for Cycling Speed and Cadence Service
        Characteristic was enabled. The parameter of this event is a structure of
        CYBLE_CSCS_CHAR_VALUE_T type.
    */
    case CYBLE_EVT_CSCSS_NOTIFICATION_ENABLED:
        DBG_PRINTF("Notifications for CSC Measurement Characteristic are enabled\r\n");
        speedSimulation |= CSCS_NOTIFICATION_ENABLE;
		break;

    /* CSCS Server - Notifications for Cycling Speed and Cadence Service
        Characteristic was disabled. The parameter of this event is a structure  of
        CYBLE_CSCS_CHAR_VALUE_T type
    */
    case CYBLE_EVT_CSCSS_NOTIFICATION_DISABLED:
        DBG_PRINTF("Notifications for CSC Measurement Characteristic are disabled\r\n");
		speedSimulation &= ~CSCS_NOTIFICATION_ENABLE;
        break;

    /* CSCS Server - Indication for Cycling Speed and Cadence Service Characteristic
        was enabled. The parameter of this event is a structure of
        CYBLE_CSCS_CHAR_VALUE_T type
    */
    case CYBLE_EVT_CSCSS_INDICATION_ENABLED:
        DBG_PRINTF("Indications for SC Control Point Characteristic are enabled\r\n");
        speedSimulation |= CSCS_INDICATION_ENABLE;
		break;

    /* CSCS Server - Indication for Cycling Speed and Cadence Service Characteristic
        was disabled. The parameter of this event is a structure of
        CYBLE_CSCS_CHAR_VALUE_T type
    */
    case CYBLE_EVT_CSCSS_INDICATION_DISABLED:
        DBG_PRINTF("Indications for SC Control Point Characteristic are disabled\r\n");
        speedSimulation &= ~CSCS_INDICATION_ENABLE;
		break;

    /* CSCS Server - Cycling Speed and Cadence Service Characteristic
        Indication was confirmed. The parameter of this event is a structure of 
        CYBLE_CSCS_CHAR_VALUE_T type
    */
    case CYBLE_EVT_CSCSS_INDICATION_CONFIRMATION:
        DBG_PRINTF("Confirmation of SC Control Point Characteristic indication received\r\n");
		break;
    
    /* CSCS Server - Write Request for Cycling Speed and Cadence Service
        Characteristic was received. The parameter of this event is a structure of
        CYBLE_CSCS_CHAR_VALUE_T type.
    */
    case CYBLE_EVT_CSCSS_CHAR_WRITE:

        wrReqParam = (CYBLE_CSCS_CHAR_VALUE_T *) eventParam;
        DBG_PRINTF("Write to SC Control Point Characteristic occurred. ");
        DBG_PRINTF("Data length: %d. ", wrReqParam->value->len);
        DBG_PRINTF("Received data:");
        
        for(i = 0u; i < wrReqParam->value->len; i++)
        {
             DBG_PRINTF(" %x", wrReqParam->value->val[i]);
        }
         DBG_PRINTF("\r\n");

        /* Form the general response packet */
        scCPResponse[CSCS_SC_CP_RESP_LEN_IDX] = SC_CP_CHAR_LENGTH_3BYTES;
        scCPResponse[CSCS_SC_CP_RESP_OP_CODE_IDX] = CYBLE_CSCS_RESPONSE_CODE;
        scCPResponse[CSCS_SC_CP_REQ_OP_CODE_IDX] = wrReqParam->value->val[CSCS_SC_CP_OP_CODE_IDX];
        scCPResponse[CSCS_SC_CP_RESP_VALUE_IDX] = CYBLE_CSCS_ERR_SUCCESS;

        /* Handle the received op code */
        switch(wrReqParam->value->val[CSCS_SC_CP_OP_CODE_IDX])
        {
            case CYBLE_CSCS_SET_CUMMULATIVE_VALUE:
                if(wrReqParam->value->len == CSCS_SET_CUMMULATIVE_VALUE_LEN)
                {
                    wheelRev = (wrReqParam->value->val[CSCS_SC_CUM_VAL_BYTE0_IDX + 3u] << THREE_BYTES_SHIFT) |
                                    (wrReqParam->value->val[CSCS_SC_CUM_VAL_BYTE0_IDX + 2u] << TWO_BYTES_SHIFT) |
                                    (wrReqParam->value->val[CSCS_SC_CUM_VAL_BYTE0_IDX + 1u] << ONE_BYTE_SHIFT) |
                                    wrReqParam->value->val[CSCS_SC_CUM_VAL_BYTE0_IDX];
                    
                    if(0ul == wheelRev)
                    {
                        DBG_PRINTF("Set cumulative value to zero.\r\n");
                    }
                    else
                    {
                        DBG_PRINTF("Set cumulative value to 0x%4.4x%4.4x.\r\n", HI16(wheelRev), LO16(wheelRev));
                    }
                }
                else
                {
                    /* Length is invalid, indicate failure */
                    scCPResponse[CSCS_SC_CP_RESP_VALUE_IDX] = CYBLE_CSCS_ERR_OPERATION_FAILED;
                }
                break;

            case CYBLE_CSCS_START_SENSOR_CALIBRATION:
                DBG_PRINTF("Start Sensor calibration command received. ");
                if(wrReqParam->value->len == CSCS_START_SENSOR_CALIBRATION_LEN)
                {
                    DBG_PRINTF("This command is not supported in this example project.\r\n");
                    /* The Start Sensor Calibration command is not supported in the example */
                    scCPResponse[CSCS_SC_CP_RESP_VALUE_IDX] = CYBLE_CSCS_ERR_OP_CODE_NOT_SUPPORTED;
                }
                else
                {
                    /* Length is invalid, indicate failure */
                    scCPResponse[CSCS_SC_CP_RESP_VALUE_IDX] = CYBLE_CSCS_ERR_OPERATION_FAILED;
                }
                break;

            case CYBLE_CSCS_UPDATE_SENSOR_LOCATION:
                DBG_PRINTF("Update Sensor Location \r\n");

                if(wrReqParam->value->len == CSCS_UPDATE_SENSOR_LOCATION_LEN)
                {
                    /* Update to the location of the Sensor with the value sent as parameter to this op code. 
                    */
                    for(i = 0u; i < NUM_SUPPORTED_SENSORS; i++)
                    {
                        if(sensorLocations[i] == wrReqParam->value->val[CYBLE_CSCS_SENSOR_LOC_IDX])
                        {
                            sensorLocSupported = 1u;
                        }
                    }

                    if(0u != sensorLocSupported)
                    {
                        (void) CyBle_CscssSetCharacteristicValue(CYBLE_CSCS_SENSOR_LOCATION, 
                                                                 sizeof(uint8),
                                                                 &wrReqParam->value->val[CYBLE_CSCS_SENSOR_LOC_IDX]);
                        DBG_PRINTF("Set sensor location operation completed successfully. \r\n");
                    }
                    else
                    {
                        scCPResponse[CSCS_SC_CP_RESP_VALUE_IDX] = CYBLE_CSCS_ERR_INVALID_PARAMETER;
                        DBG_PRINTF("Unsupported sensor location.\r\n");
                    }
                }
                else
                {
                    /* Length is invalid, indicate failure */
                    scCPResponse[CSCS_SC_CP_RESP_VALUE_IDX] = CYBLE_CSCS_ERR_OPERATION_FAILED;
                }
                break;

            case CYBLE_CSCS_REQ_SUPPORTED_SENSOR_LOCATION:
                DBG_PRINTF("Request Supported Sensor Locations \r\n");

                if(wrReqParam->value->len == CSCS_REQ_SUPPORTED_SENSOR_LOCATION_LEN)
                {
                    /* Request a list of supported locations where the Sensor can be attached. */
                    scCPResponse[CSCS_SC_CP_RESP_LEN_IDX] += NUM_SUPPORTED_SENSORS;
                    
                    for(i = 0u; i < NUM_SUPPORTED_SENSORS; i++)
                    {
                        scCPResponse[CSCS_SC_CP_RESP_PARAMETER_IDX + i] = sensorLocations[i];
                    }
                }
                else
                {
                    /* Length is invalid, indicate failure */
                    scCPResponse[CSCS_SC_CP_RESP_VALUE_IDX] = CYBLE_CSCS_ERR_OPERATION_FAILED;
                }
                break;

            default:
                DBG_PRINTF("Unsupported command.\r\n");
                scCPResponse[CSCS_SC_CP_RESP_VALUE_IDX] = CYBLE_CSCS_ERR_OP_CODE_NOT_SUPPORTED;
                break;
        }

		/* Set the flag about active response pending */
        speedCPresponse = 1u;
		break;


    /* CSCS Client - Cycling Speed and Cadence Service Characteristic
        Notification was received. The parameter of this event is a structure of
        CYBLE_CSCS_CHAR_VALUE_T type
    */
    case CYBLE_EVT_CSCSC_NOTIFICATION:
        break;

    /* CSCS Client - Cycling Speed and Cadence Service Characteristic
        Indication was received. The parameter of this event is a structure of 
        CYBLE_CSCS_CHAR_VALUE_T type
    */
    case CYBLE_EVT_CSCSC_INDICATION:
        break;

    /* CSCS Client - Read Response for Read Request of Cycling Speed and Cadence 
        Service Characteristic value. The parameter of this event is a structure of
        CYBLE_CSCS_CHAR_VALUE_T type
    */
    case CYBLE_EVT_CSCSC_READ_CHAR_RESPONSE:
        break;

    /* CSCS Client - Write Response for Write Request of Cycling Speed and Cadence 
        Service Characteristic value. The parameter of this event is a structure of
        CYBLE_CSCS_CHAR_VALUE_T type
    */
    case CYBLE_EVT_CSCSC_WRITE_CHAR_RESPONSE:
        break;

    /* CSCS Client - Read Response for Read Request of Cycling Speed and Cadence
        Service Characteristic Descriptor Read request. The parameter of this event
        is a structure of CYBLE_CSCS_DESCR_VALUE_T type
    */
    case CYBLE_EVT_CSCSC_READ_DESCR_RESPONSE:
        break;

    /* CSCS Client - Write Response for Write Request of Cycling Speed and Cadence
        Service Characteristic Configuration Descriptor value. The parameter of
        this event is a structure of  CYBLE_CSCS_DESCR_VALUE_T type
    */
    case CYBLE_EVT_CSCSC_WRITE_DESCR_RESPONSE:
        break;

	default:
        DBG_PRINTF("Unrecognized CSCS event.\r\n");
	    break;
    }
}
Beispiel #22
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;
}
static  u32 win_proc(MSG *pMsg)
{
    HWND hwnd;
    HDC hdc;
    RECT rc,rc0;
    u32 i;

    hwnd =pMsg->hwnd;

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

                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);

                i=RectH(&rc0)-(3*30);
                CreateWindow(CHECKBOX,"绘制边框",WS_CHILD|CBS_SELECTED|WS_VISIBLE,4,i+0*32,128,24,hwnd,ID_BORDER,NULL);
                CreateWindow(CHECKBOX,"绘制背景",WS_CHILD|CBS_SELECTED|WS_VISIBLE,4,i+1*32,128,24,hwnd,ID_BKGND,NULL);
                CreateWindow(CHECKBOX,"改变颜色",WS_CHILD|CBS_SELECTED|WS_VISIBLE,4,i+2*32,128,24,hwnd,ID_COLOR,NULL);

                GDD_CreateTimer(hwnd,1,3000,TMR_START);
                GDD_CreateTimer(hwnd,2,1000,TMR_START);

                break;
                ////
        case    MSG_TIMER:
                {
                    switch(pMsg->Param1)
                    {
                        case    1:
                                cfg_idx++;
                                if(DrawText_Cfg_Tbl[cfg_idx].text==NULL)
                                {
                                    cfg_idx=0;
                                }
                                InvalidateWindow(hwnd);
                                break;
                                /////
                        case    2:
                                if(bColor!=FALSE)
                                {
                                    color_idx++;
                                    if(color_idx>=8)
                                    {
                                        color_idx=0;
                                    }
                                    InvalidateWindow(hwnd);
                                }
                                break;
                                /////
                    }
                }
                break;

        case    MSG_NOTIFY:
                {
                    u16 event,id;

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

                    if(id==ID_CLOSE)
                    {
                    	if(event==BTN_UP)
                    	{
                    		PostMessage(hwnd,MSG_CLOSE,0,0);
                    	}
                    	InvalidateWindow(hwnd);
                    }

                    if(id==ID_BORDER)
                    {
                    	if(event==CBN_SELECTED)
                    	{
                    		bBorder =TRUE;
                    	}
                    	if(event==CBN_UNSELECTED)
                    	{
                    		bBorder =FALSE;
                    	}
                    	InvalidateWindow(hwnd);
                    }

                    if(id==ID_BKGND)
                    {
                    	if(event==CBN_SELECTED)
                    	{
                    		bBKGND =TRUE;
                    	}
                    	if(event==CBN_UNSELECTED)
                    	{
                    		bBKGND =FALSE;
                    	}
                    	InvalidateWindow(hwnd);
                    }

                    if(id==ID_COLOR)
                    {
                    	if(event==CBN_SELECTED)
                    	{
                    		bColor =TRUE;
                    	}
                    	if(event==CBN_UNSELECTED)
                    	{
                    		bColor =FALSE;
                    	}
                    	InvalidateWindow(hwnd);
                    }

                }
                break;
                ////

        case    MSG_PAINT:
                {

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


                    SetRect(&rc,4,10,RectW(&rc0)-4*2,60);
                    SetTextColor(hdc,DrawText_Color_Tbl[color_idx].text_color);
                    SetDrawColor(hdc,DrawText_Color_Tbl[color_idx].bd_color);
                    SetFillColor(hdc,DrawText_Color_Tbl[color_idx].bk_color);

                    i=DrawText_Cfg_Tbl[cfg_idx].flag;
                    if(bBorder)
                    {
                        i |= DT_BORDER;
                    }
                    if(bBKGND)
                    {
                        i |= DT_BKGND;
                    }

                    DrawText(hdc,DrawText_Cfg_Tbl[cfg_idx].text,-1,&rc,i);
                   // DrawText(hdc,"DrawText\r\n**绘制字符串**",-1,&rc,DT_BORDER|DT_BKGND|DT_VCENTER|DT_CENTER);

                    EndPaint(hwnd,hdc);

                }
                break;
                ////

        default:
                return  DefWindowProc(pMsg);


    }
    return  0;
}
Beispiel #24
0
 /*******************************************************************************
 * Function Name: USBFS_1_InitEP_DMA
 ********************************************************************************
 *
 * Summary:
 *  This function allocates and initializes a DMA channel to be used by the
 *  USBFS_1_LoadInEP() or USBFS_1_ReadOutEP() APIs for data
 *  transfer.
 *
 * Parameters:
 *  epNumber: Contains the data endpoint number.
 *            Valid values are between 1 and 8.
 *  *pData: Pointer to a data array that is related to the EP transfers.
 *
 * Return:
 *  None.
 *
 * Reentrant:
 *  No.
 *
 *******************************************************************************/
 void USBFS_1_InitEP_DMA(uint8 epNumber, const uint8 *pData)
                                                                 
 {
     uint16 src;
     uint16 dst;
     #if (CY_PSOC3)                  /* PSoC 3 */
         src = HI16(CYDEV_SRAM_BASE);
         dst = HI16(CYDEV_PERIPH_BASE);
         pData = pData;
     #else                           /* PSoC 5 */
         if((USBFS_1_EP[epNumber].addr & USBFS_1_DIR_IN) != 0u )
         {   /* for the IN EP source is the SRAM memory buffer */
             src = HI16(pData);
             dst = HI16(CYDEV_PERIPH_BASE);
         }
         else
         {   /* for the OUT EP source is the SIE register */
             src = HI16(CYDEV_PERIPH_BASE);
             dst = HI16(pData);
         }
     #endif  /* End C51 */
     switch(epNumber)
     {
         case USBFS_1_EP1:
             #if(USBFS_1_DMA1_REMOVE == 0u)
                 USBFS_1_DmaChan[epNumber] = USBFS_1_ep1_DmaInitialize(
                     USBFS_1_DMA_BYTES_PER_BURST, USBFS_1_DMA_REQUEST_PER_BURST, src, dst);
             #endif   /* End USBFS_1_DMA1_REMOVE */
             break;
         case USBFS_1_EP2:
             #if(USBFS_1_DMA2_REMOVE == 0u)
                 USBFS_1_DmaChan[epNumber] = USBFS_1_ep2_DmaInitialize(
                     USBFS_1_DMA_BYTES_PER_BURST, USBFS_1_DMA_REQUEST_PER_BURST, src, dst);
             #endif   /* End USBFS_1_DMA2_REMOVE */
             break;
         case USBFS_1_EP3:
             #if(USBFS_1_DMA3_REMOVE == 0u)
                 USBFS_1_DmaChan[epNumber] = USBFS_1_ep3_DmaInitialize(
                     USBFS_1_DMA_BYTES_PER_BURST, USBFS_1_DMA_REQUEST_PER_BURST, src, dst);
             #endif   /* End USBFS_1_DMA3_REMOVE */
             break;
         case USBFS_1_EP4:
             #if(USBFS_1_DMA4_REMOVE == 0u)
                 USBFS_1_DmaChan[epNumber] = USBFS_1_ep4_DmaInitialize(
                     USBFS_1_DMA_BYTES_PER_BURST, USBFS_1_DMA_REQUEST_PER_BURST, src, dst);
             #endif   /* End USBFS_1_DMA4_REMOVE */
             break;
         case USBFS_1_EP5:
             #if(USBFS_1_DMA5_REMOVE == 0u)
                 USBFS_1_DmaChan[epNumber] = USBFS_1_ep5_DmaInitialize(
                     USBFS_1_DMA_BYTES_PER_BURST, USBFS_1_DMA_REQUEST_PER_BURST, src, dst);
             #endif   /* End USBFS_1_DMA5_REMOVE */
             break;
         case USBFS_1_EP6:
             #if(USBFS_1_DMA6_REMOVE == 0u)
                 USBFS_1_DmaChan[epNumber] = USBFS_1_ep6_DmaInitialize(
                     USBFS_1_DMA_BYTES_PER_BURST, USBFS_1_DMA_REQUEST_PER_BURST, src, dst);
             #endif   /* End USBFS_1_DMA6_REMOVE */
             break;
         case USBFS_1_EP7:
             #if(USBFS_1_DMA7_REMOVE == 0u)
                 USBFS_1_DmaChan[epNumber] = USBFS_1_ep7_DmaInitialize(
                     USBFS_1_DMA_BYTES_PER_BURST, USBFS_1_DMA_REQUEST_PER_BURST, src, dst);
             #endif   /* End USBFS_1_DMA7_REMOVE */
             break;
         case USBFS_1_EP8:
             #if(USBFS_1_DMA8_REMOVE == 0u)
                 USBFS_1_DmaChan[epNumber] = USBFS_1_ep8_DmaInitialize(
                     USBFS_1_DMA_BYTES_PER_BURST, USBFS_1_DMA_REQUEST_PER_BURST, src, dst);
             #endif   /* End USBFS_1_DMA8_REMOVE */
             break;
         default:
             /* Do not support EP0 DMA transfers */
             break;
     }
     if((epNumber > USBFS_1_EP0) && (epNumber < USBFS_1_MAX_EP))
     {
         USBFS_1_DmaTd[epNumber] = CyDmaTdAllocate();
     }
 }
Beispiel #25
0
/*******************************************************************************
* Function Name: main
********************************************************************************
* Summary:
*        System entry point. This calls the user SFlash write API when switch SW2
* is pressed during system bootup.
*
* Parameters:
*  void
*
* Return:
*  int
*
*******************************************************************************/
int main()
{
    uint32 data[USER_SFLASH_ROW_SIZE/4];
    uint8 *sflashPtr;
    uint8 rowIndex;
    uint32 dataIndex;
            
    CyGlobalIntEnable; /* Enable system interrupts required for UART operation */
    
    UART_Console_Start(); /* UART is used for UI on the serial port terminal */
    
    if(Write_Switch_Read() == SWITCH_PRESSED) /* If SW2 on BLE pioneer kit baseboard is pressed during startup */
    {
        for(dataIndex = 0; dataIndex < (USER_SFLASH_ROW_SIZE/4); dataIndex++)
        {
            data[dataIndex] = SFLASH_STARTING_VALUE + dataIndex;  /* Fill the user SFlash write buffer with known data */
        }
        
        for(rowIndex = 0; rowIndex < USER_SFLASH_ROWS; rowIndex++) /* Continuously write all the 4 user FLASH rows */
        {
            uint32 status;
            
            UART_Console_UartPutString("\r\nWriting user SFlash row");
            UART_Console_UartPutChar('0' + rowIndex);
            
            /* User SFlash write API will change the IMO frequency to 48MHz internally (which is not desired for any
             * peripherals that are operating on IMO based clock (UART in this example). Wait for UART data transfer
             * to complete before calling the user SFlash write API */
            while((UART_Console_SpiUartGetTxBufferSize() + UART_Console_GET_TX_FIFO_SR_VALID) != 0u);
            
            status  = WriteUserSFlashRow(rowIndex, &data[0]);
            
            if(status == USER_SFLASH_WRITE_SUCCESSFUL)
            {
                UART_Console_UartPutString(" successful");
            }
            else
            {
                UART_Console_UartPutString(" failed - ");
                UART_Console_UartPutChar(HexToAscii(HI8(HI16(status)),1));
                UART_Console_UartPutChar(HexToAscii(HI8(HI16(status)),0));
                UART_Console_UartPutChar(HexToAscii(LO8(HI16(status)),1));
                UART_Console_UartPutChar(HexToAscii(LO8(HI16(status)),0));
            }
        }
        
        UART_Console_UartPutString("\r\nUser SFlash write complete\r\n");
    }
    
    sflashPtr = (uint8 *)USER_SFLASH_BASE_ADDRESS; /* User SFlash read is direct memory read using pointers */

    /* Read all the 512 bytes of user configurable SFlash content and display on UART console */
    for(rowIndex = 0; rowIndex < USER_SFLASH_ROWS; rowIndex++)
    {
        UART_Console_UartPutString("\r\n\nUser SFlash row ");
        UART_Console_UartPutChar('0' + rowIndex);
        UART_Console_UartPutString(" data:\r\n");
        
        for(dataIndex = 0; dataIndex < USER_SFLASH_ROW_SIZE; dataIndex++)
        {
            uint8 readData;
            
            readData = *sflashPtr++;
            
            UART_Console_UartPutChar(HexToAscii(readData,1));
            UART_Console_UartPutChar(HexToAscii(readData,0));
            UART_Console_UartPutChar(' ');
        }
    }

    while(1); /* halt the system */
}
Beispiel #26
0
static  u32 win_proc(MSG *pMsg)
{
    HWND hwnd;
    HDC hdc;
    RECT rc,rc0;
    u32 i;

    hwnd =pMsg->hwnd;

    switch(pMsg->Code)
    {
        case    MSG_CREATE:

                x1_inc =2;
                y1_inc =1;

                x2_inc =2;
                y2_inc =1;

                bMoveMainWin=FALSE;

                GetClientRect(hwnd,&rc0);
                hwnd_BTN1 =CreateWindow(BUTTON,"关闭",WS_CHILD|BS_NORMAL|WS_BORDER|WS_VISIBLE,RectW(&rc0)-64,RectH(&rc0)-28,60,24,hwnd,ID_CLOSE,NULL);
                hwnd_BTN2 =CreateWindow(BUTTON,"关闭",WS_CHILD|BS_NORMAL|WS_BORDER|WS_VISIBLE,4,4,60,24,hwnd,ID_CLOSE,NULL);


                CreateWindow(BUTTON,"移动主窗口",WS_CHILD|BS_HOLD|WS_BORDER|WS_VISIBLE,4,RectH(&rc0)-28,100,24,hwnd,ID_MOVE_1,NULL);


                GDD_CreateTimer(hwnd,0,200,TMR_START);
                GDD_CreateTimer(hwnd,1,150,TMR_START);
                GDD_CreateTimer(hwnd,2,100,TMR_START);

                break;
                ////

        case    MSG_TIMER:
                {

                    switch(pMsg->Param1)
                    {
                    case 0:
                        {
                            static int x_inc=2;
                            static int y_inc=1;

                            if(bMoveMainWin==FALSE)
                            {
                                break;
                            }

                            GetWindowRect(hwnd,&rc);

                            if(rc.left > 320)
                            {
                                x_inc =-3;
                            }

                            if(rc.left <- 200)
                            {
                                x_inc =3;
                            }

                            if(rc.top > 200)
                            {
                                y_inc =-2;
                            }

                            if(rc.top < -100)
                            {
                                y_inc =2;
                            }

                            rc.left+=x_inc;
                            rc.top+=y_inc;

                            ScreenToClient(GetParent(hwnd),(POINT*)&rc,2);
                            MoveWindow(hwnd,rc.left,rc.top);
                        }
                        break;
                        /////

                    case 1:
                    {

                        GetClientRect(hwnd,&rc0);
                        ClientToScreen(hwnd,(POINT*)&rc0,2);

                        GetWindowRect(hwnd_BTN1,&rc);
                        /*
                        GetWindowRect(hwnd_BTN2,&rc0);
                        if(IsIntersectRect(&rc,&rc0))
                        {
                            x1_inc *=-1;
                            y1_inc *=-1;

                            x2_inc *=-1;
                            y2_inc *=-1;
                        }
                         */

                        if((rc.right) >= (rc0.right))
                        {
                            x1_inc =-3;
                        }

                        if(rc.left <= rc0.left)
                        {
                            x1_inc =3;
                        }

                        if((rc.bottom) >= (rc0.bottom))
                        {
                            y1_inc =-2;
                        }

                        if(rc.top <= rc0.top)
                        {
                            y1_inc =2;
                        }

                        rc.left +=x1_inc;
                        rc.top +=y1_inc;

                        ScreenToClient(hwnd,(POINT*)&rc,2);
                        MoveWindow(hwnd_BTN1,rc.left,rc.top);
                    }

                    case 2:
                    {

                        GetClientRect(hwnd,&rc0);
                        ClientToScreen(hwnd,(POINT*)&rc0,2);

                        GetWindowRect(hwnd_BTN2,&rc);
                        /*
                        GetWindowRect(hwnd_BTN1,&rc0);
                        if(IsIntersectRect(&rc,&rc0))
                        {
                            x1_inc *=-1;
                            y1_inc *=-1;

                            x2_inc *=-1;
                            y2_inc *=-1;
                        }
                        */

                        if((rc.right) >= (rc0.right))
                        {
                            x2_inc =-2;
                        }

                        if(rc.left <= rc0.left)
                        {
                            x2_inc =2;
                        }

                        if((rc.bottom) >= (rc0.bottom))
                        {
                            y2_inc =-1;
                        }

                        if(rc.top <= rc0.top)
                        {
                            y2_inc =1;
                        }

                        rc.left +=x2_inc;
                        rc.top +=y2_inc;

                        ScreenToClient(hwnd,(POINT*)&rc,2);
                        MoveWindow(hwnd_BTN2,rc.left,rc.top);
                    }

                    break;
                    ////

                    default:

                        break;

                    }

                    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_MOVE_1)
                            {
                                bMoveMainWin=TRUE;
                            }
                            break;
                            ////

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

                            if(id==ID_MOVE_1)
                            {
                                bMoveMainWin=FALSE;
                            }
                            break;
                            ////

                        default:
                            break;

                    }


                }
                break;
                ////

        case    MSG_PAINT:
                {
                    char wbuf[32];

                    hdc =BeginPaint(hwnd);

                    GetClientRect(hwnd,&rc0);


                    SetTextColor(hdc,RGB(0,240,0));
                    SetFillColor(hdc,RGB(40,40,40));
                    SetDrawColor(hdc,RGB(0,240,0));


                    GetWindowRect(hwnd,&rc);
                    sprintf(wbuf,"当前主窗口位置: %d,%d",rc.left,rc.top);
                    DrawText(hdc,wbuf,-1,&rc0,DT_LEFT|DT_VCENTER|DT_BORDER|DT_BKGND);

                    EndPaint(hwnd,hdc);

                }
                break;
                ////

        default:
                return  DefWindowProc(pMsg);


    }
    return  0;
}
Beispiel #27
0
/*******************************************************************************
* Function Name: DMA_Config
********************************************************************************
*
* Summary:
*  Initializes and sets up DMA for use (generated by DMA Wizard)
*
* Parameters:
*  None.
*
* Return:
*  None.
*
*******************************************************************************/
void DMA_Config(void)
{
    /* Declare variable to hold the handle for DMA channel */
    uint8 channelHandle;

    /* Declare DMA Transaction Descriptor for memory transfer into
     * Filter Channel.
     */
    uint8 tdChanA;

    /* Configure the DMA to Transfer the data in 1 burst with individual trigger
     * for each burst.
     */
    channelHandle = DMA_DmaInitialize(BYTES_PER_BURST, REQUEST_PER_BURST,
                                        HI16(UPPER_SRC_ADDRESS), HI16(UPPER_DEST_ADDRESS));

    /* This function allocates a TD for use with an initialized DMA channel */
    tdChanA = CyDmaTdAllocate();

    /* Configure the tdChanA to transfer 1 byte with no next TD */
    CyDmaTdSetConfiguration(tdChanA, 1u, DMA_INVALID_TD, 0u);

    /* Set the source address as ADC_DelSig and the destination as
     * Filter Channel A.
     */
    CyDmaTdSetAddress(tdChanA, LO16((uint32)ADC_DelSig_DEC_SAMP_PTR), LO16((uint32)Filter_STAGEAH_PTR));

    /* Set tdChanA to be the initial TD associated with channelHandle */
    CyDmaChSetInitialTd(channelHandle, tdChanA);

    /* Enable the DMA channel represented by channelHandle and preserve the TD */
    CyDmaChEnable(channelHandle, 1u);
    
    
    uint8 DMA_1_Chan;
uint8 DMA_1_TD[1];
    
   
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, TD_INC_DST_ADR);
CyDmaTdSetAddress(DMA_1_TD[0], LO16((uint32)Filter_HOLDA_PTR), LO16((uint32)buffer));
CyDmaChSetInitialTd(DMA_1_Chan, DMA_1_TD[0]);
CyDmaChEnable(DMA_1_Chan, 1);






/* 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_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], 1, CY_DMA_DISABLE_TD, 0);
CyDmaTdSetAddress(DMA_2_TD[0], LO16((uint32)Filter_HOLDA_PTR), LO16((uint32)VDAC8_Data_PTR));
CyDmaChSetInitialTd(DMA_2_Chan, DMA_2_TD[0]);
CyDmaChEnable(DMA_2_Chan, 1);


}