void main (void) { BSP_Init( ); SET_MAIN_CLOCK_SOURCE(CRYSTAL); initUART(); printf( "Start iwsn system...\n" ); InitRFIO(); /* set io as normal io, not uart */ //P0DIR &= ~0x03; /* Set button as input */ EnableRecv(); SMPL_Init( NULL ); /* turn on the radio so we are always able to receive data asynchronously */ SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RXON, NULL ); /* turn on LED. */ BSP_TURN_ON_LED1( ); BSP_TURN_ON_LED2( ); /* never coming back... */ framework_entry(); /* but in case we do... */ while (1) ; }
void USART_Init(char uart, char USART_InitStruct) { IO_PER_LOC_USART0_AT_PORT0_PIN2345(); SET_MAIN_CLOCK_SOURCE(CRYSTAL); UART_SETUP(0, 57600, HIGH_STOP); UTX0IF = 1; }
/****************************************************************************** * @fn initDma * * @brief * Initializes components for the DMA transfer application example. * * Parameters: * * @param void * * @return void * ******************************************************************************/ void initDma(void) { initLcd(); SET_MAIN_CLOCK_SOURCE(CRYSTAL); INIT_BUTTON(); INIT_GLED(); INIT_YLED(); }
/****************************************************************************** * @fn initUART * * @brief * Initializes components for the UART application example. * * Parameters: * * @param void * * @return void * ******************************************************************************/ void initUART(void) { // Setup for UART0 IO_PER_LOC_UART0_AT_PORT0_PIN2345(); SET_MAIN_CLOCK_SOURCE(CRYSTAL); UART_SETUP(0, 57600, HIGH_STOP); UTX0IF = 1; }
/****************************************************************************** * @fn initAdc * * @brief * Initializes components for use with the ADC application example (e.g. * LEDs, PotMeter, Joystick). * * Parameters: * * @param void * * @return void * ******************************************************************************/ void initAdc(void) { initLcd(); SET_MAIN_CLOCK_SOURCE(CRYSTAL); //init LEDs INIT_GLED(); INIT_YLED(); INIT_POT(); INIT_JOYSTICK(); }
/****************************************************************************** * @TODO 20061013 * if the uart adapter is driven by interrupt, then you should enable the interrupt * in configure function. however, whether the ISR really works or not still depends * on the global interrupt flag. * * @assume: the global interrupt should be disabled before calling this function. * @todo stop bits input is actually no use now. *****************************************************************************/ TiUartAdapter * uart_open( TiUartAdapter * uart, uint8 id, uint16 baudrate, uint8 databits, uint8 stopbits, uint8 option ) { //USART_InitTypeDef USART_InitStructure; /* assume: * - the global interrupt is disabled when calling this function * - you have already call HAL_SET_PIN_DIRECTIONS. the pin should initialized correctly. or else it doesn't work. */ uart->id = id; uart->baudrate = baudrate; uart->databits = databits; uart->stopbits = stopbits; uart->option = option; #ifdef CONFIG_UART_INTERRUPT_DRIVEN uart->txlen = 0; uart->txidx = 0; uart->rxlen = 0; uart->listener = NULL; uart->lisowner = NULL; #endif switch (id) { case 0: IO_PER_LOC_USART0_AT_PORT0_PIN2345(); SET_MAIN_CLOCK_SOURCE(CRYSTAL); UART_SETUP(0, 38400, HIGH_STOP); //UART_SETUP(0, 57600, HIGH_STOP); UTX0IF = 1; break; case 1: break; case 2: break; default: // not support now. hal_assert(false); uart = NULL; break; } return uart; }
/****************************************************************************** * @fn initStopWatch * * @brief * Initializes components for the stopwatch application example. * * Parameters: * * @param void * * @return void * ******************************************************************************/ void initStopWatch(void) { //interrupts[INUM_T3] = stop_watch_T3_IRQ; INIT_GLED(); SET_MAIN_CLOCK_SOURCE(CRYSTAL); CLKCON &= ~0x38; // Enabling overflow interrupt from timer 3 TIMER34_INIT(3); halSetTimer34Period(3, 1000); INT_ENABLE(INUM_T3, INT_ON); TIMER34_ENABLE_OVERFLOW_INT(3,INT_ON); INT_GLOBAL_ENABLE(INT_ON); }
void main() { BSP_Init( ); SET_MAIN_CLOCK_SOURCE(CRYSTAL); initUART(); initOuterRF(); enableOuterRF(); enableOuterRFData(); /* turn on LED. */ BSP_TURN_ON_LED1( ); BSP_TURN_ON_LED2( ); running(); return; }
//////////////////////////////////////////////////////////////////////////////// /// @brief Application main function. //////////////////////////////////////////////////////////////////////////////// void main(void) { // Initializations SET_MAIN_CLOCK_SOURCE(CRYSTAL); SET_MAIN_CLOCK_SPEED(MHZ_26); CLKCON = (CLKCON & 0xC7); init_peripherals(); P0 &= ~0x40; // Pulse the Codec Reset line (high to low, low to high) P0 |= 0x40; init_codec(); // Initilize the Codec INT_SETFLAG(INUM_DMA, INT_CLR); // clear the DMA interrupt flag I2SCFG0 |= 0x01; // Enable the I2S interface DMA_SET_ADDR_DESC0(&DmaDesc0); // Set up DMA configuration table for channel 0 DMA_SET_ADDR_DESC1234(&DmaDesc1_4[0]); // Set up DMA configuration table for channels 1 - 4 dmaMemtoMem(AF_BUF_SIZE); // Set up DMA Channel 0 for memmory to memory data transfers initRf(); // Set radio base frequency and reserve DMA channels 1 and 2 for RX/TX buffers dmaAudio(); // Set up DMA channels 3 and 4 for the Audio In/Out buffers DMAIRQ = 0; DMA_ARM_CHANNEL(4); // Arm DMA channel 4 macTimer3Init(); INT_ENABLE(INUM_T1, INT_ON); // Enable Timer 1 interrupts INT_ENABLE(INUM_DMA, INT_ON); // Enable DMA interrupts INT_GLOBAL_ENABLE(INT_ON); // Enable Global interrupts MAStxData.macPayloadLen = TX_PAYLOAD_LEN; MAStxData.macField = MAC_ADDR; while (1) { // main program loop setChannel(channel[band][ActiveChIdx]); // SetChannel will set the MARCSTATE to IDLE ActiveChIdx = (ActiveChIdx + 1) & 0x03; SCAL(); // Start PLL calibration at new channel if ((P1 & 0x08) != aux_option_status) { // if the 'SEL AUX IN' option bit has changed state if ((P1 & 0x08) == 0) { // SEL AUX IN has changed state to true I2Cwrite(MIC1LP_LEFTADC, 0xFC); // Disconnect MIC1LP/M from the Left ADC, Leave Left DAC enabled I2Cwrite(MIC2L_MIC2R_LEFTADC, 0x2F); // Connect AUX In (MIC2L) to Left ADC I2Cwrite(LEFT_ADC_PGA_GAIN, 0x00); // Set PGA gain to 0 dB aux_option_status &= ~0x08; } else { // SEL AUX IN has changed state to false I2Cwrite(MIC2L_MIC2R_LEFTADC, 0xFF); // Disconnect AUX In (MIC2L) from Left ADC I2Cwrite(MIC1LP_LEFTADC, 0x84); // Connect the internal microphone to the Left ADC using differential inputs (gain = 0 dB); Power Up the Left ADC I2Cwrite(LEFT_ADC_PGA_GAIN, 0x3C); // Enable PGA and set gain to 30 dB aux_option_status |= 0x08; } } if ((P1 & 0x04) != agc_option_status) { // if the 'ENA AGC' option bit has changed state if ((P1 & 0x04) == 0) { // ENA AGC has changed state to true I2Cwrite(LEFT_AGC_CNTRL_A, 0x90); // Left AGC Control Register A - Enable, set target level to -8 dB I2Cwrite(LEFT_AGC_CNTRL_B, 0xC8); // Left AGC Control Register B - Set maximum gain to to 50 dB I2Cwrite(LEFT_AGC_CNTRL_C, 0x00); // Left AGC Control Register C - Disable Silence Detection agc_option_status &= ~0x04; } else { // SEL AUX IN has changed state to false I2Cwrite(LEFT_AGC_CNTRL_A, 0x10); // Left AGC Control Register A - Disable agc_option_status |= 0x04; } } // Check the band selection bits band = 2; // if the switch is not in position 1 or 2, in must be in position 3 if ((P1 & 0x10) == 0) // check if switch is in position 1 band = 0; else if ((P0 & 0x04) == 0) // check if switch is in position 2 band = 1; // Now wait for the "audio frame ready" signal while (audioFrameReady == FALSE); // Wait until an audioframe is ready to be transmitted audioFrameReady = FALSE; // Reset the flag // Move data from the CODEC (audioOut) buffer to the TX buffer using DMA Channel 0 SET_WORD(DmaDesc0.SRCADDRH, DmaDesc0.SRCADDRL, audioOut[activeOut]); SET_WORD(DmaDesc0.DESTADDRH, DmaDesc0.DESTADDRL, MAStxData.payload); DmaDesc0.SRCINC = SRCINC_1; // Increment Source address DMAARM |= DMA_CHANNEL_0; DMAREQ |= DMA_CHANNEL_0; // Enable memory-to-memory transfer using DMA channel 0 while ((DMAARM & DMA_CHANNEL_0) > 0); // Wait for transfer to complete while (MARCSTATE != 0x01); // Wait for calibration to complete P2 |= 0x08; // Debug - Set P2_3 (TP2) rfSendPacket(MASTER_TX_TIMEOUT_WO_CALIB); P2 &= ~0x08; // Debug - Reset P2_3 (TP2) } // end of 'while (1)' loop }
void InitTempSensor(void){ DISABLE_ALL_INTERRUPTS(); SET_MAIN_CLOCK_SOURCE(0); *((BYTE __xdata*) 0xDF26) = 0x80; }