Exemple #1
0
/**
 ****************************************************************************************
 * @brief Checks if system is in startup phase.

 * @return uint8   1 if system is in startup phase, otherwise 0.
 ****************************************************************************************
 */
uint8_t check_sys_startup_period(void)
{
   uint8_t ret_value = 0;  
    
    if (sys_startup_flag)
    {
        uint32_t current_time;
        
        current_time = lld_evt_time_get();
                
        if (current_time < startup_sleep_delay) // startup_sleep_delay after system startup to allow system to sleep
            ret_value = 1;
        else // After 2 seconds system can sleep
        {
            sys_startup_flag = false;
            if ( (app_get_sleep_mode() == 2) || (app_get_sleep_mode() == 1) )
            {
                SetWord16(SET_FREEZE_REG, FRZ_WDOG);            // Stop WDOG until debugger is removed
                while ((GetWord16(SYS_STAT_REG) & DBG_IS_UP) == DBG_IS_UP) {};
                SetBits16(SYS_CTRL_REG, DEBUGGER_ENABLE, 0);    // close debugger
            }

#if (USE_WDOG)
            SetWord16(RESET_FREEZE_REG, FRZ_WDOG);  // Start WDOG
#endif
         
            ret_value = 0;
        }
    }

    return ret_value;
}
Exemple #2
0
/**
 ****************************************************************************************
 * @brief Read from 3-wire SPI
 * @param[in] registerIndex: Target address (A6..A0)
 *
 * @return  byte read
 ****************************************************************************************
 */
uint8_t read_from_3wire_SPI_register(uint8_t registerIndex, uint8_t is_last_transaction)
{
    static uint8_t i, dataRead;

    GPIO_SetInactive(cs.port, cs.pin);                              // pull CS low

    GPIO_SetPinFunction( sdio.port, sdio.pin, OUTPUT, PID_SPI_DO);  // configure SDIO as output

    SetWord16(SPI_RX_TX_REG0, (uint16_t)(registerIndex) );          // MSB set to HIGH - A6..A0 Address of register to write to
    do {
    } while (GetBits16(SPI_CTRL_REG,SPI_INT_BIT)==0);               // polling to wait for spi transmission

    SetWord16(SPI_CLEAR_INT_REG, 0);                                //Clear SPI_CTRL_REG[SPI_INT_BIT] interrupt

    GPIO_SetPinFunction( sdio.port, sdio.pin, INPUT, PID_SPI_DI);   // configure SDIO as input

    for (i=0; i<TsradCounter; i++);                                 // {DEV.NOTE#: For Mouse sensor Delay > Tsrad = 4us <-- suitable counter is 6}

    SetWord16(SPI_RX_TX_REG0, (uint16_t)0x00 );                     // dummy write data - read data
    do {
    } while (GetBits16(SPI_CTRL_REG,SPI_INT_BIT)==0);               // polling to wait for spi transmission

    SetWord16(SPI_CLEAR_INT_REG, 0);                                //Clear SPI_CTRL_REG[SPI_INT_BIT] interrupt

    dataRead = GetWord16(SPI_RX_TX_REG0);                           // read received byte

    SetWord16(SPI_CLEAR_INT_REG, 0x01);                             // clear pending flag

    if(is_last_transaction)
        GPIO_SetActive(cs.port, cs.pin);                              // set CS high

    return dataRead;
}
/**
****************************************************************************************
* @brief Read a single item from serial flash via SPI
* @param[in] x: buffer to read the data 
****************************************************************************************
*/
inline void getByte_SPI(uint8* x  )
{
    SetWord16(SPI_RX_TX_REG0, (uint16) DUMMY);
    while (GetBits16(SPI_CTRL_REG, SPI_INT_BIT==0));
    SetWord16(SPI_CLEAR_INT_REG, 0x01);
    *(uint8*)x=(uint8)GetWord16(SPI_RX_TX_REG0);   
} 
/**
****************************************************************************************
* @brief Read a block of data from spu flash
* @param[in] destination_buffer: buffer to put the data
* @param[in] source_addr: starting position to read the data from spi
* @param[in] len: size of data to read  
****************************************************************************************
*/
void SpiFlashRead(unsigned long destination_buffer,unsigned long source_addr,unsigned long len)
{
    unsigned long i;

    spi_mem_cs_low();
    putByte_SPI(0x03);
    putByte_SPI((source_addr&0xffffff)>>16);
    putByte_SPI((source_addr&0xffff)>>8);
    putByte_SPI(source_addr&0xff);
    SetWord16(SPI_RX_TX_REG0, (uint16) 0);

    __ASM volatile ("nop");
    __ASM volatile ("nop");
    for (i=0;i<len;i++)
    {
        SetWord16(SPI_RX_TX_REG0, (uint16) 0); 
        __ASM volatile ("nop");
        __ASM volatile ("nop");
        __ASM volatile ("nop");
        __ASM volatile ("nop");
        __ASM volatile ("nop");
        __ASM volatile ("nop");
        *(uint8*)(uint32)(destination_buffer+i)=(uint8)GetWord16(SPI_RX_TX_REG0);
    }
    spi_mem_cs_high();
} 
Exemple #5
0
void adc_init(void){
	SetWord16(GP_ADC_CTRL_REG,  GP_ADC_LDO_EN | GP_ADC_SE);
	SetWord16(GP_ADC_CTRL_REG,  GP_ADC_LDO_EN | GP_ADC_SE | GP_ADC_EN);
	SetWord16(GP_ADC_CTRL2_REG, 0x000E);																	// Enable 3x attenuation
//	SetWord16(GP_ADC_OFFP_REG, 0x297);
	
}
Exemple #6
0
/**
 ****************************************************************************************
 * @brief  Acquires the raw RFADC IQ samples
 ****************************************************************************************
 */
void trng_get_raw_data(uint32 address, uint32 length)
{
    SetWord16(RFPT_ADDR_REG, address);
    SetWord16(RFPT_LEN_REG, length);
    SetWord16(RFPT_CTRL_REG, 0x1);

    while ((GetWord16(RFPT_STAT_REG) & RFPT_ACTIVE)== RFPT_ACTIVE);
}
void quad_decoder_init(QUAD_DEC_INIT_PARAMS_t *quad_dec_init_params)
{
   // Enable the Quadrature clock    
    SetBits16(CLK_PER_REG, QUAD_ENABLE , true);
   // Setup Quadrature Decoder pin assignment    
    SetWord16(QDEC_CTRL2_REG, quad_dec_init_params->chx_port_sel | quad_dec_init_params->chy_port_sel | quad_dec_init_params->chz_port_sel);
    SetWord16(QDEC_CLOCKDIV_REG, quad_dec_init_params->qdec_clockdiv);
           
}
/**
****************************************************************************************
* @brief Write a single item to serial flash via SPI
* @param[in] x: data to send
****************************************************************************************
*/
void putByte_SPI(uint32 x)
{ 
    uint16 tmp; 
    SetWord16(SPI_RX_TX_REG0, (uint16_t)x);    // write (low part of) dataToSend
    do
    {
    } while (GetBits16(SPI_CTRL_REG, SPI_INT_BIT) == 0);  // polling to wait for spi transmission
    SetWord16(SPI_CLEAR_INT_REG, 0x01);            // clear pending flag
    tmp = GetWord16(SPI_RX_TX_REG0);
}
Exemple #9
0
void burst_write_to_3wire_SPI_register(uint8_t registerIndex)
{
    GPIO_SetPinFunction( sdio.port, sdio.pin, OUTPUT, PID_SPI_DO);   // configure SDIO as output
    SetWord16(SPI_RX_TX_REG0, (uint16_t)(registerIndex) );           // MSB set to HIGH - A6..A0 Address of register to write to
    do {
    } while (GetBits16(SPI_CTRL_REG,SPI_INT_BIT)==0);                // polling to wait for spi transmission

    SetWord16(SPI_CLEAR_INT_REG, 0);                                 // Clear SPI_CTRL_REG[SPI_INT_BIT] interrupt
    GPIO_SetPinFunction( sdio.port, sdio.pin, INPUT, PID_SPI_DI);    // configure SDIO as input

}
Exemple #10
0
void uart_initialization(void)
{
	SetBits16(CLK_PER_REG, UART1_ENABLE, 1);  	// enable  clock for UART 1

	SetWord16(UART_LCR_REG, 0x80); // set bit to access DLH and DLL register
	SetWord16(UART_IER_DLH_REG,(UART_BAUDRATE_115K2&0xFF>>8));//set high byte
	SetWord16(UART_RBR_THR_DLL_REG,UART_BAUDRATE_115K2&0xFF);//set low byte
	SetWord16(UART_LCR_REG,UART_DATALENGTH|UART_PARITY|UART_STOPBITS);
	SetBits16(UART_MCR_REG, UART_SIRE, 0);  // mode 0 for normal , 1 for IRDA
	SetWord16(UART_IIR_FCR_REG,1);  // enable fifo  
	SetBits16(UART_IER_DLH_REG,ERBFI_dlh0,0);  // IER access, disable interrupt for available data
}
Exemple #11
0
void set_pxact_gpio(void)
{
#if DEVELOPMENT_DEBUG    
    uint32_t i;

    SetWord16(P13_MODE_REG, PID_GPIO|OUTPUT);
    SetWord16(P1_SET_DATA_REG, 0x8);
    for ( i=0;i<150;i++); //20 is almost 7.6usec of time.
    SetWord16(P1_RESET_DATA_REG, 0x8);
#endif
    return;
}
/**
 ****************************************************************************************
 * @brief Initialize I2C controller as a master for EEPROM handling.
 ****************************************************************************************
 */
void i2c_eeprom_init(uint16_t dev_address, uint8_t speed, uint8_t address_mode, uint8_t address_size)
{
    mem_address_size = address_size;
    SetBits16(CLK_PER_REG, I2C_ENABLE, 1);                                        // enable  clock for I2C 
    SetWord16(I2C_ENABLE_REG, 0x0);                                               // Disable the I2C controller	
    SetWord16(I2C_CON_REG, I2C_MASTER_MODE | I2C_SLAVE_DISABLE | I2C_RESTART_EN); // Slave is disabled
    SetBits16(I2C_CON_REG, I2C_SPEED, speed);                                     // Set speed
    SetBits16(I2C_CON_REG, I2C_10BITADDR_MASTER, address_mode);                   // Set addressing mode
    SetWord16(I2C_TAR_REG, dev_address & 0x3FF);                                  // Set Slave device address
    SetWord16(I2C_ENABLE_REG, 0x1);                                               // Enable the I2C controller
    while( (GetWord16(I2C_STATUS_REG) & 0x20) != 0 );                             // Wait for I2C master FSM to be IDLE
    i2c_dev_address = dev_address;
}
void NMI_HandlerC(unsigned long *hardfault_args)
{
    // Reached this point due to a WDOG timeout
    
    SetBits16(PMU_CTRL_REG, RADIO_SLEEP, 1);        // turn off radio PD
    SetBits16(PMU_CTRL_REG, PERIPH_SLEEP, 1);       // turn off peripheral power domain
    SetBits16(CLK_RADIO_REG, BLE_LP_RESET, 1);      // reset the BLE LP timer
    NVIC_ClearPendingIRQ(BLE_WAKEUP_LP_IRQn);       // clear any pending LP IRQs

#if (DEVELOPMENT_DEBUG)
    SetWord16(SET_FREEZE_REG, FRZ_WDOG);            // Stop WDOG
    SetBits16(SYS_CTRL_REG, DEBUGGER_ENABLE, 1);    // enable debugger to be able to re-attach
    
    *(volatile unsigned long *)(STATUS_BASE       ) = hardfault_args[0];    // R0
    *(volatile unsigned long *)(STATUS_BASE + 0x04) = hardfault_args[1];    // R1
    *(volatile unsigned long *)(STATUS_BASE + 0x08) = hardfault_args[2];    // R2
    *(volatile unsigned long *)(STATUS_BASE + 0x0C) = hardfault_args[3];    // R3
    *(volatile unsigned long *)(STATUS_BASE + 0x10) = hardfault_args[4];    // R12
    *(volatile unsigned long *)(STATUS_BASE + 0x14) = hardfault_args[5];    // LR
    *(volatile unsigned long *)(STATUS_BASE + 0x18) = hardfault_args[6];    // PC
    *(volatile unsigned long *)(STATUS_BASE + 0x1C) = hardfault_args[7];    // PSR

    *(volatile unsigned long *)(STATUS_BASE + 0x20) = (*((volatile unsigned long *)(0xE000ED28)));    // CFSR
    *(volatile unsigned long *)(STATUS_BASE + 0x24) = (*((volatile unsigned long *)(0xE000ED2C)));    // HFSR
    *(volatile unsigned long *)(STATUS_BASE + 0x28) = (*((volatile unsigned long *)(0xE000ED30)));    // DFSR
    *(volatile unsigned long *)(STATUS_BASE + 0x2C) = (*((volatile unsigned long *)(0xE000ED3C)));    // AFSR
    *(volatile unsigned long *)(STATUS_BASE + 0x30) = (*((volatile unsigned long *)(0xE000ED34)));    // MMAR
    *(volatile unsigned long *)(STATUS_BASE + 0x34) = (*((volatile unsigned long *)(0xE000ED38)));    // BFAR
    
    if ((GetWord16(SYS_STAT_REG) & DBG_IS_UP) == DBG_IS_UP)
       // __asm("BKPT #0\n");
	   BKPT();
    else
    {
        while(1);
    }

#else // DEVELOPMENT_DEBUG

# ifdef PRODUCTION_DEBUG_OUTPUT
	// Power up peripherals' power domain
    SetBits16(PMU_CTRL_REG, PERIPH_SLEEP, 0);
    while (!(GetWord16(SYS_STAT_REG) & PER_IS_UP));
    
    dbg_prod_output(0, hardfault_args);
# endif    
    
    // Remap addres 0x00 to ROM and force execution
    SetWord16(SYS_CTRL_REG, (GetWord16(SYS_CTRL_REG) & ~REMAP_ADR0) | SW_RESET );
#endif // DEVELOPMENT_DEBUG
}
Exemple #14
0
void Uart_init(void)
{
	SetBits16(CLK_PER_REG, UART1_ENABLE, 1);  	// enable  clock for UART 1

	SetWord16(UART_LCR_REG, 0x80); // set bit to access DLH and DLL register
	SetWord16(UART_IER_DLH_REG,(UART_BAUDRATE_115K2&0xFF>>8));//set high byte
	SetWord16(UART_RBR_THR_DLL_REG,UART_BAUDRATE_115K2&0xFF);//set low byte
	SetWord16(UART_LCR_REG,UART_DATALENGTH_8|UART_PARITY_NONE|UART_STOPBITS_1);
	SetBits16(UART_MCR_REG, UART_SIRE, 0);  // mode 0 for normal , 1 for IRDA
	SetWord16(UART_IIR_FCR_REG,1);  // enable fifo  
	SetBits16(UART_IER_DLH_REG,ERBFI_dlh0,1);  // IER access, disable interrupt for available data
	NVIC_SetPriority(UART_IRQn,1);
	NVIC_EnableIRQ(UART_IRQn);
}
Exemple #15
0
void spi_439_getblock(int i)
{
    uint16_t firstword = spi_439_bufstart0;
    if (!(i & 0x01)) 
        firstword = spi_439_bufstart1;

    spi_439_block_idx = 20;  // 1 Control + 20*2 samples, 
    SetWord16(SPI_RX_TX_REG1, (uint16_t)firstword);
    SetWord16(SPI_RX_TX_REG0, 40);   /* Tell 439 it needs to send 40 samples */

        #ifdef TESTING_SPI    
    startpkt=1;
        #endif
}
Exemple #16
0
uint8_t burst_read_from_3wire_SPI_register(void)
{
    static uint8_t dataRead;

    SetWord16(SPI_RX_TX_REG0, (uint16_t)0x00 );                      // dummy write data - read data
    do {
    } while (GetBits16(SPI_CTRL_REG,SPI_INT_BIT)==0);                // polling to wait for spi transmission

    SetWord16(SPI_CLEAR_INT_REG, 0);                                 // Clear SPI_CTRL_REG[SPI_INT_BIT] interrupt
    dataRead = GetWord16(SPI_RX_TX_REG0);                            // read received byte
    SetWord16(SPI_CLEAR_INT_REG, 0x01);                              // clear pending flag

    return dataRead;
}
Exemple #17
0
 /**
 ****************************************************************************************
 * @brief Enable pad's and peripheral clocks assuming that peripherals' power domain is down.
 *        The Uart and SPi clocks are set. 
 * 
 ****************************************************************************************
 */
void periph_init(void)  // set i2c, spi, uart, uart2 serial clks
{
    // system init
    SetWord16(CLK_AMBA_REG, 0x00);              // set clocks (hclk and pclk ) 16MHz
    SetWord16(SET_FREEZE_REG,FRZ_WDOG);         // stop watch dog
    SetBits16(SYS_CTRL_REG,PAD_LATCH_EN,1);     // open pads
    SetBits16(SYS_CTRL_REG,DEBUGGER_ENABLE,1);  // open debugger
    SetBits16(PMU_CTRL_REG, PERIPH_SLEEP,0);    // exit peripheral power down
    // Power up peripherals' power domain
    SetBits16(PMU_CTRL_REG, PERIPH_SLEEP, 0);
    while (!(GetWord16(SYS_STAT_REG) & PER_IS_UP));  
    // Initialize UART component
    //Init pads 
}
Exemple #18
0
/**
 ****************************************************************************************
 * @brief The 439 SPI Interrupt handler, to copy the Audio sample to location in memory
 *
 * Note that this function is called twice per sample. Note that the SPI interface
 * needs 3 16-bits transactions to read one register. We are doing 32 bits transactions
 * and therefore need 2 to handle interrupt twice.
 * 
 * @return void
 ****************************************************************************************
 */
void SPI_Handler(void)
{ 
    // Received SPI interrupt..
    SetWord16(SPI_CLEAR_INT_REG, 0x01);  
    if (spi_439_first)
    {
        // Start next SPI transaction
        SetWord16(SPI_RX_TX_REG1, 0);  // write high part of dataToSend
        SetWord16(SPI_RX_TX_REG0, 0);  // write low part of dataToSend - this will trigger next SPI 
        spi_439_first = 0;
    }
    else
        /** We are done */
        *spi_439_buf_ptr = GetWord16(SPI_RX_TX_REG1); // tst2++; // 
}
Exemple #19
0
void SPI_Handler(void)
{ 
    // Received SPI interrupt..
    SetWord16(SPI_CLEAR_INT_REG, 0x01);
    /* Save the words in memory */
    int16_t v1 = (int16_t)GetWord16(SPI_RX_TX_REG1);
    int16_t v2 = (int16_t)GetWord16(SPI_RX_TX_REG0);
        #ifndef TESTING_SPI    
            #ifdef MARK_PACKETS
    if ((spi_439_block_idx<3) || ((spi_439_block_idx>8) && (spi_439_block_idx<12)))
    {
        if ((spi_439_block_idx==0) || (spi_439_block_idx==9))
            packet_marker+=3000;
        
        if (packet_marker>30000)
            packet_marker=0;
        
        v2+=packet_marker;
        v1+=packet_marker;
    }
            #endif
    *spi_439_buf_ptr++ = v1; // (int16_t)GetWord16(SPI_RX_TX_REG1);
    *spi_439_buf_ptr++ = v2; // (int16_t)GetWord16(SPI_RX_TX_REG0);  // spitst++; // 
        #else
    int offs = 0;
    if (startpkt==5)
        offs=100;
    else 
        startpkt++;
    testctn+=testctnincr;
    *spi_439_buf_ptr++ =testctn + offs;
    testctn+=testctnincr;
    *spi_439_buf_ptr++ =testctn;
    if (testctn>16000) 
        testctnincr=-2;
    if (testctn<0)  
        testctnincr=+2;
        #endif
    
    if (spi_439_block_idx > 0)
    {
        // Start next SPI transaction
        SetWord16(SPI_RX_TX_REG1, 0);  // write high part of dataToSend
        SetWord16(SPI_RX_TX_REG0, 0);  // write low part of dataToSend - this will trigger next SPI 
        spi_439_block_idx--;
    }
    /** else ** We are done */
}
Exemple #20
0
/**
 ****************************************************************************************
 * @brief Enable pad's and peripheral clocks assuming that peripherals' power domain is down.
 *
 * The Uart and SPi clocks are set. 
 ****************************************************************************************
 */
void periph_init(void)  // set i2c, spi, uart, uart2 serial clks
{
	// Power up peripherals' power domain
    SetBits16(PMU_CTRL_REG, PERIPH_SLEEP, 0);
    while (!(GetWord16(SYS_STAT_REG) & PER_IS_UP)) ; 
    
	
	// TODO: Application specific - Modify accordingly!
	// Example: Activate UART and SPI.
	
    // Initialize UART component
#ifdef PROGRAM_ENABLE_UART
    SetBits16(CLK_PER_REG, UART1_ENABLE, 1);    // enable clock - always @16MHz
	
    // baudr=9-> 115k2
    // mode=3-> no parity, 1 stop bit 8 data length
#ifdef UART_MEGABIT
    uart_init(UART_BAUDRATE_1M, 3);
#else
    uart_init(UART_BAUDRATE_115K2, 3);
#endif // UART_MEGABIT
    //NVIC_SetPriority(UART_IRQn, 1);
#endif // PROGRAM_ENABLE_UART

#if 0
	//Example: Do something with the timer if need be...
    SetWord16(TIMER0_CTRL_REG, 0); 
    SetWord16(TIMER0_RELOAD_M_REG, 0);
    SetWord16(TIMER0_RELOAD_N_REG, 0);
    SetWord16(TIMER0_ON_REG, 0);
#endif
	
	//rom patch
	patch_func();
	
	//Init pads
	set_pad_functions();

#if (BLE_APP_PRESENT)
#if BLE_BATTERY_SERVER
    app_batt_port_reinit();
#endif //BLE_BATTERY_SERVER
#endif //BLE_APP_PRESENT

    // Enable the pads
	SetBits16(SYS_CTRL_REG, PAD_LATCH_EN, 1);
}
Exemple #21
0
/**
 ****************************************************************************************
 * @brief Starts RCX20 calibration. 
 *
 * @param[in]   cal_time. Calibration time in RCX20 cycles. 
 *
 * @return void 
 ****************************************************************************************
 */
void calibrate_rcx20(uint16_t cal_time)
{
    
    SetWord16(CLK_REF_CNT_REG, cal_time);
    SetBits16(CLK_REF_SEL_REG, REF_CLK_SEL, 0x3); //RCX select 
    SetBits16(CLK_REF_SEL_REG, REF_CAL_START, 0x1); //Start Calibration
    cal_enable = 1;
}
Exemple #22
0
void rfpt_init(void)
{
    volatile uint16  wait;

	SetWord16(CLK_RADIO_REG, 0x0089);                          // En BLE clk, dis BLE timer, En RFCU, RFCU div by 2
	SetWord16(BLE_CNTL2_REG, 0x2000);                          //
	SetBits16 (CLK_AMBA_REG, OTP_ENABLE, 1);
	SetBits16 (CLK_AMBA_REG, HCLK_DIV, 0);
    SetBits16 (TEST_CTRL_REG, ENABLE_RFPT, 1);
     // Recommended settings
    //set_recommended_settings();
    rf_regs();

    IffCalibration();
    DCoffsetCalibration();
    WAIT100();                                  // Wait 100 us to finish all DCF signals
}
/**
 ****************************************************************************************
 * @brief 
 *
 * @param[in]
 *
 * @return 
 ****************************************************************************************
 */
void quad_decoder_release(void)
{
   // Reset Quadrature Decoder pin assignment (PLEASE REVIEW)
    SetWord16(QDEC_CTRL2_REG, QUAD_DEC_CHXA_NONE_AND_CHXB_NONE | QUAD_DEC_CHYA_NONE_AND_CHYB_NONE | QUAD_DEC_CHZA_NONE_AND_CHZB_NONE);
   // Disable the Quadrature clock    
    SetBits16(CLK_PER_REG, QUAD_ENABLE , false);
    
}
Exemple #24
0
/**
****************************************************************************************
* @brief SPI 439  Write
* @param[in] address: 12 bits address on 439
* @param[in] data: 16 bits value for the register
*
* To write one data word to 439 with the SPI, 2 transactions are needed.
* - First transaction: send command&address
* - Second transaction: write data
* This functions uses POLLING to check if SPI transaction has completed.
*
* @return  data read 
****************************************************************************************
*/
void spi_setword(uint32_t address, uint32_t data)  // IZP named changed
{    
    spi_cs_low();
    
    uint32_t dataToSend = ((SC14439_MEM_WR<<13) | (address&0x1FFF ));
    
    SetWord16(SPI_RX_TX_REG0, (uint16_t)dataToSend);    // write address

    while (!GetBits16(SPI_CTRL_REG, SPI_INT_BIT));      // polling to wait for spi transmission
    SetWord16(SPI_CLEAR_INT_REG, 0x01);                 // clear pending flag
        
    SetWord16(SPI_RX_TX_REG0, (uint16_t)data);          // write (low part of) dataToSend

    while (!GetBits16(SPI_CTRL_REG, SPI_INT_BIT));      // polling to wait for spi transmission
    SetWord16(SPI_CLEAR_INT_REG, 0x01);                 // clear pending flag

    spi_cs_high();
}
Exemple #25
0
void uart_send_byte(char ch){
	#ifndef UART_ENABLED
		return ;
#else
	while((GetWord16(UART_LSR_REG)&0x20)==0);	// read status reg to check if THR is empty
	SetWord16(UART_RBR_THR_DLL_REG,(0xFF&ch)); // write to THR register
	return;
	#endif
}
Exemple #26
0
/**
 ****************************************************************************************
 * @brief Gets ADC sample.
 *
 * @return ADC sample
 ****************************************************************************************
 */
int adc_get_sample(void){
	int cnt=100000;
    
	SetBits16(GP_ADC_CTRL_REG, GP_ADC_START, 1);
	while (cnt-- && (GetWord16(GP_ADC_CTRL_REG) & GP_ADC_START) != 0x0000); 
	SetWord16(GP_ADC_CLEAR_INT_REG, 0x0000); // Clear interrupt
	return GetWord16(GP_ADC_RESULT_REG); 

}
Exemple #27
0
/**
 ****************************************************************************************
 * @brief Starts RCX20 calibration. 
 *
 * @param[in]   cal_time. Calibration time in RCX20 cycles. 
 *
 * @return void 
 ****************************************************************************************
 */
void calibrate_rcx20(uint16_t cal_time)
{
    if ((CFG_LP_CLK == LP_CLK_FROM_OTP) || (CFG_LP_CLK == LP_CLK_RCX20))
    {
        SetWord16(CLK_REF_CNT_REG, cal_time);
        SetBits16(CLK_REF_SEL_REG, REF_CLK_SEL, 0x3); //RCX select 
        SetBits16(CLK_REF_SEL_REG, REF_CAL_START, 0x1); //Start Calibration
        cal_enable = 1;
    }
}
Exemple #28
0
void uart_sps_init(uint8_t baudr, uint8_t mode )
{
    //ENABLE FIFO, REGISTER FCR IF UART_LCR_REG.DLAB=0
    SetBits16(UART_LCR_REG, UART_DLAB, 0);
			
    // XMIT FIFO RESET, RCVR FIFO RESET, FIFO ENABLED,
    SetWord16(UART_IIR_FCR_REG,0x87); //rcv int when rx fifo 1/2 full
    //SetWord16(UART_IIR_FCR_REG,0xC7); //rcv int when rx fifo 14/16 full	/* this option will cause the sps application to overflow the Rx FIFO */
	
    //DISABLE INTERRUPTS, REGISTER IER IF UART_LCR_REG.DLAB=0
    SetWord16(UART_IER_DLH_REG, 0);

    // ACCESS DIVISORLATCH REGISTER FOR BAUDRATE, REGISTER UART_DLH/DLL_REG IF UART_LCR_REG.DLAB=1
    SetBits16(UART_LCR_REG, UART_DLAB, 1);
    SetWord16(UART_IER_DLH_REG,0); 

    SetWord16(UART_IER_DLH_REG, (baudr&0xFF>>0x8));
    SetWord16(UART_RBR_THR_DLL_REG,baudr&0xFF); 

    // NO PARITY, 1 STOP BIT, 8 DATA LENGTH
    SetWord16(UART_LCR_REG, mode);

    //ENABLE TX INTERRUPTS, REGISTER IER IF UART_LCR_REG.DLAB=0
    SetBits16(UART_LCR_REG, UART_DLAB, 0);

    NVIC_DisableIRQ(UART_IRQn);
    NVIC_SetPriority(UART_IRQn,1);  
    NVIC_EnableIRQ(UART_IRQn);
    NVIC_ClearPendingIRQ(UART_IRQn);

    // Configure UART environment
    uart_sps_env.errordetect = UART_ERROR_DETECT_DISABLED;
    uart_sps_env.rx.bufptr   = NULL;
    uart_sps_env.rx.state	   = NULL;
    uart_sps_env.rx.size     = 0;
    uart_sps_env.tx.bufptr   = NULL;
	  uart_sps_env.tx.state	   = NULL;
    uart_sps_env.tx.size     = 0;

	  uart_sps_flow_off(); 

}
Exemple #29
0
/**
 ****************************************************************************************
 * @brief Write to 3-wire SPI
 * @param[in] registerIndex: Target address (A6..A0)
 * @param[in] valueToWrite: Value to write
 *
 * @return  Number of read bytes
 ****************************************************************************************
 */
void write_to_3wire_SPI_register(uint8_t registerIndex, uint8_t valueToWrite)
{
    GPIO_SetInactive(cs.port, cs.pin);                              // pull CS low

    GPIO_SetPinFunction( sdio.port, sdio.pin, OUTPUT, PID_SPI_DO);  // configure SDIO as output

    SetWord16(SPI_RX_TX_REG0, (uint16_t)(registerIndex | 0x80) );   // MSB set to HIGH - A6..A0 Address of register to write to
    do {
    } while (GetBits16(SPI_CTRL_REG,SPI_INT_BIT)==0);               // polling to wait for spi transmission

    SetWord16(SPI_CLEAR_INT_REG, 0);                                //Clear SPI_CTRL_REG[SPI_INT_BIT] interrupt

    SetWord16(SPI_RX_TX_REG0, (uint16_t)valueToWrite );             // write data
    do {
    } while (GetBits16(SPI_CTRL_REG,SPI_INT_BIT)==0);               // polling to wait for spi transmission

    SetWord16(SPI_CLEAR_INT_REG, 0);                                // Clear SPI_CTRL_REG[SPI_INT_BIT] interrupt

    GPIO_SetActive(cs.port, cs.pin);                                // set CS high
}
/**
 ********************************************************************m********************
 * @brief Send I2C EEPROM's memory address
 *
 * @param[in] address of the I2C EEPROM memory
 ****************************************************************************************
 */
void i2c_send_address(uint32_t address_to_send)
{
    switch(mem_address_size)
    {
        case I2C_2BYTES_ADDR:
            SetWord16(I2C_ENABLE_REG, 0x0);  
            SetWord16(I2C_TAR_REG, i2c_dev_address | ((address_to_send & 0x10000) >> 16));  // Set Slave device address
            SetWord16(I2C_ENABLE_REG, 0x1);
            while( (GetWord16(I2C_STATUS_REG) & 0x20) != 0 );   // Wait for I2C master FSM to be IDLE
            SEND_I2C_COMMAND( (address_to_send >> 8) & 0xFF );  // Set address MSB, write access        
        break;
        
        case I2C_3BYTES_ADDR:
            SEND_I2C_COMMAND( (address_to_send >> 16) & 0xFF);  // Set address MSB, write access
            SEND_I2C_COMMAND( (address_to_send >> 8) & 0xFF);   // Set address MSB, write access        
        break;
    }

    SEND_I2C_COMMAND(address_to_send & 0xFF);                   // Set address LSB, write access    
}