int main() { int i; /* The clock frequency of systick may be changed by user's application. Please change the value of SYSTICK_CLOCK according to real situration */ #define TT_SYSTICK_CLOCK 22118400 /* Initialize TinyThread */ tt_init(TT_SYSTICK_CLOCK); /* Open LED GPIO for testing */ DrvGPIO_Open(LED_GPIO_GREEN_GRP, LED_GPIO_GREEN_BIT, E_IO_OUTPUT); DrvGPIO_Open(LED_GPIO_RED_GRP, LED_GPIO_RED_BIT, E_IO_OUTPUT); DrvGPIO_Open(LED_GPIO_ISP_GRP, LED_GPIO_ISP_BIT, E_IO_OUTPUT); DrvGPIO_Open(LED_GPIO_ICE_GRP, LED_GPIO_ICE_BIT, E_IO_OUTPUT); /* Create and run thread */ arg[0].gpio_group = LED_GPIO_RED_GRP; arg[1].gpio_group = LED_GPIO_ISP_GRP; arg[2].gpio_group = LED_GPIO_ICE_GRP; arg[0].gpio_bit = LED_GPIO_RED_BIT; arg[1].gpio_bit = LED_GPIO_ISP_BIT; arg[2].gpio_bit = LED_GPIO_ICE_BIT; for (i = 0; i < THREAD_NUM; ++i) { tt_sem_init (&join_sem[i], 0); arg[i].join_sem = &join_sem[i]; thread[i] = tt_thread_create("thread", /* thread Name */ 0, /* thread priority */ stack[i], /* stack pointer */ sizeof(stack[i]), /* stack size */ thread_entry, /* thread entry function */ (void *)&arg[i] /* argument for thread entry function */ ); } /* Join threads. * TinyThread does not support build-in tt_thread_join() * since it is easy to emulate by a semaphore. */ for (i = 0; i < THREAD_NUM; ++i) tt_sem_down (&join_sem[i]); /* Set LED to indicate that run to here */ DrvGPIO_SetBit(LED_GPIO_RED_GRP, LED_GPIO_RED_BIT); /* OFF */ DrvGPIO_SetBit(LED_GPIO_ISP_GRP, LED_GPIO_ISP_BIT); /* OFF */ DrvGPIO_SetBit(LED_GPIO_ISP_GRP, LED_GPIO_ISP_BIT); /* OFF */ DrvGPIO_ClrBit(LED_GPIO_GREEN_GRP, LED_GPIO_GREEN_BIT); /* ON */ while(1); }
uchar Drv_Uart_init(uchar i) { if(i==0) DrvGPIO_InitFunction(E_FUNC_UART0); else DrvGPIO_InitFunction(E_FUNC_UART0); DrvGPIO_Open(E_GPC,2,E_IO_OUTPUT); DrvGPIO_Open(E_GPC,3,E_IO_OUTPUT); DrvGPIO_Open(E_GPC,1,E_IO_OUTPUT); }
void Bargraph_Init() { uint32_t i; for(i=0;i<8;i++) { DrvGPIO_Open(0,i,E_IO_OUTPUT); DrvGPIO_Open(2,i,E_IO_OUTPUT); DrvGPIO_Open(3,i,E_IO_OUTPUT); } DrvGPIO_SetPortBits(0,0); DrvGPIO_SetPortBits(2,0); DrvGPIO_SetPortBits(3,0); bg_l = 0; bg_r = 0; bg_disp_pos = 0; }
int main() { int i; THREAD_ARG_T arg[THREAD_NUM]; MY_SEM_T sem; /* The clock frequency of systick may be changed by user's application. Please change the value of SYSTICK_CLOCK according to real situration */ #define TT_SYSTICK_CLOCK 22118400 /* Initialize TinyThread */ tt_init(TT_SYSTICK_CLOCK); /* Open LED GPIO for testing */ DrvGPIO_Open(LED_GPIO_GREEN_GRP, LED_GPIO_GREEN_BIT, E_IO_OUTPUT); DrvGPIO_Open(LED_GPIO_RED_GRP, LED_GPIO_RED_BIT, E_IO_OUTPUT); DrvGPIO_Open(LED_GPIO_ISP_GRP, LED_GPIO_ISP_BIT, E_IO_OUTPUT); DrvGPIO_Open(LED_GPIO_ICE_GRP, LED_GPIO_ICE_BIT, E_IO_OUTPUT); /* Set semaphore value to 3, so that always 3 threads' LED is blinking */ my_sem_init (&sem, 3); /* Create and run thread */ arg[0].gpio_group = LED_GPIO_RED_GRP; arg[1].gpio_group = LED_GPIO_ISP_GRP; arg[2].gpio_group = LED_GPIO_ICE_GRP; arg[3].gpio_group = LED_GPIO_GREEN_GRP; arg[0].gpio_bit = LED_GPIO_RED_BIT; arg[1].gpio_bit = LED_GPIO_ISP_BIT; arg[2].gpio_bit = LED_GPIO_ICE_BIT; arg[3].gpio_bit = LED_GPIO_GREEN_BIT; for (i = 0; i < THREAD_NUM; ++i) { arg[i].sem = &sem; thread[i] = tt_thread_create("thread", /* thread Name */ 0, /* thread priority */ stack[i], /* stack pointer */ sizeof(stack[i]), /* stack size */ thread_entry, /* thread entry function */ (void *)&arg[i] /* argument for thread entry function */ ); } tt_thread_exit (); return 0; }
int main() { int i; /* The clock frequency of systick may be changed by user's application. Please change the value of SYSTICK_CLOCK according to real situration */ #define TT_SYSTICK_CLOCK 22118400 /* Initialize TinyThread */ tt_init(TT_SYSTICK_CLOCK); /* Open LED GPIO for testing */ DrvGPIO_Open(LED_GPIO_GREEN_GRP, LED_GPIO_GREEN_BIT, E_IO_OUTPUT); DrvGPIO_Open(LED_GPIO_RED_GRP, LED_GPIO_RED_BIT, E_IO_OUTPUT); DrvGPIO_Open(LED_GPIO_ISP_GRP, LED_GPIO_ISP_BIT, E_IO_OUTPUT); DrvGPIO_Open(LED_GPIO_ICE_GRP, LED_GPIO_ICE_BIT, E_IO_OUTPUT); /* Test threads lock by value[] the element in value should be the same, if not, there must be an error */ tt_rmutex_init(&mutex); for(i = 0; i < THREAD_NUM; ++i) value[i] = 0; arg[0].gpio_group = LED_GPIO_RED_GRP; arg[1].gpio_group = LED_GPIO_ISP_GRP; arg[2].gpio_group = LED_GPIO_ICE_GRP; arg[0].gpio_bit = LED_GPIO_RED_BIT; arg[1].gpio_bit = LED_GPIO_ISP_BIT; arg[2].gpio_bit = LED_GPIO_ICE_BIT; for(i = THREAD_NUM; i-- != 0; ) { arg[i].value = value; arg[i].mutex = &mutex; thread[i] = tt_thread_create("th", 0, stack[i], sizeof(stack[i]), thread_entry, (void *)&arg[i]); } tt_sleep(1024); while(1); return 0; }
void init_SPI3(void) { DrvGPIO_Open(E_GPB, 9, E_IO_OUTPUT); DrvGPIO_Open(E_GPB, 7, E_IO_OUTPUT); DrvGPIO_Open(E_GPB, 10, E_IO_OUTPUT); DrvGPIO_Open(E_GPD, 14, E_IO_OUTPUT); DrvGPIO_ClrBit(E_GPD, 14); DrvGPIO_InitFunction(E_FUNC_SPI3); /* Configure SPI3 as a master, Type1 waveform, 8-bit transaction */ DrvSPI_Open(eDRVSPI_PORT3, eDRVSPI_MASTER, eDRVSPI_TYPE1, 8); /* MSB first */ DrvSPI_SetEndian(eDRVSPI_PORT3, eDRVSPI_MSB_FIRST); /* Disable the automatic slave select function of SS0. */ DrvSPI_DisableAutoSS(eDRVSPI_PORT3); /* Set the active level of slave select. */ DrvSPI_SetSlaveSelectActiveLevel(eDRVSPI_PORT3, eDRVSPI_ACTIVE_LOW_FALLING); /* SPI clock rate 20MHz */ DrvSPI_SetClockFreq(eDRVSPI_PORT3, 25000000, 0); SPI_CS_SET; }
/*************************************************************************//** * @brief Delay 1 second exactly with timer. * @param None * @return None *****************************************************************************/ void Delay1Sec(void) { UNLOCKREG(); SYSCLK->PWRCON.XTL12M_EN = 1; /* Waiting for 12M Xtal stable */ while (DrvSYS_GetChipClockSourceStatus(E_SYS_XTL12M) != 1); /*Configure gpio p3.6 as OUTPUT for led*/ DrvGPIO_Open(E_PORT3, E_PIN6, E_IO_OUTPUT); /* Example code */ DrvTIMER_Init(); DrvTIMER_Open(E_TMR0, 1000, E_PERIODIC_MODE); DrvTIMER_EnableInt(E_TMR0); DrvTIMER_Start(E_TMR0); /* Start counting */ while (1) { DrvGPIO_SetBit(E_PORT3, E_PIN6); DrvTIMER_Delay(E_TMR0, 1000); /*Delay 1000/1000 Sec*/ DrvGPIO_ClrBit(E_PORT3, E_PIN6); DrvTIMER_Delay(E_TMR0, 1000); } }
void RC_PWM_Init(void) { SYS->GPB_MFPL &= ~(SYS_GPB_MFPL_PB4MFP_Msk | SYS_GPB_MFPL_PB5MFP_Msk | SYS_GPB_MFPL_PB6MFP_Msk | SYS_GPB_MFPL_PB7MFP_Msk); SYS->GPB_MFPL |= (SYS_GPB_MFPL_PB7MFP_GPIO | SYS_GPB_MFPL_PB6MFP_GPIO | SYS_GPB_MFPL_PB4MFP_GPIO | SYS_GPB_MFPL_PB5MFP_GPIO); SYS->GPD_MFPL &= ~SYS_GPD_MFPL_PD3MFP_Msk; SYS->GPD_MFPL |= SYS_GPD_MFPL_PD3MFP_GPIO; #ifdef M451 GPIO_SetMode(IO_RC_D2, GPIO_MODE_QUASI); GPIO_SetMode(IO_RC_D4, GPIO_MODE_QUASI); GPIO_SetMode(IO_RC_D5, GPIO_MODE_QUASI); GPIO_SetMode(IO_RC_D6, GPIO_MODE_QUASI); GPIO_SetMode(IO_RC_D7, GPIO_MODE_QUASI); GPIO_SetMode(IO_RC_D8, GPIO_MODE_QUASI); #else DrvGPIO_Open(IO_RC_D2, E_IO_QUASI); DrvGPIO_Open(IO_RC_D4, E_IO_QUASI); DrvGPIO_Open(IO_RC_D5, E_IO_QUASI); DrvGPIO_Open(IO_RC_D6, E_IO_QUASI); DrvGPIO_Open(IO_RC_D7, E_IO_QUASI); DrvGPIO_Open(IO_RC_D8, E_IO_QUASI); DrvGPIO_SetIntCallback(GPABCallback, GPCDCallback); #endif rcValuePwm = getValue(); }
void Disable_Buzzer(void) { DrvGPIO_Open(E_GPB,11, E_IO_OUTPUT); DrvGPIO_SetBit(E_GPB,11); }
int main(void) { uint8_t buffer[32] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; /* Unlock the protected registers */ UNLOCKREG(); /* Enable the 12MHz oscillator oscillation */ DrvSYS_SetOscCtrl(E_SYS_XTL12M, 1); /* Waiting for 12MHz Xtal stable */ DrvSYS_Delay(5000); /* HCLK clock source. 0: external 12MHz. */ DrvSYS_SelectHCLKSource(0); LOCKREG(); DrvSYS_SetClockDivider(E_SYS_HCLK_DIV, 0); /* HCLK clock frequency = HCLK clock source / (HCLK_N + 1) */ nrf_init(); nrf_detect(); //nrf_rx_mode_no_aa(addr,5,16,40); //nrf_rx_mode(addr,5,16,40); nrf_rx_mode_dual(addr,5,40); nrf_test_reg(); DrvGPIO_Open(E_GPA, 2, E_IO_OUTPUT); DrvGPIO_Open(E_GPA, 3, E_IO_OUTPUT); DrvGPIO_Open(E_GPA, 4, E_IO_OUTPUT); DrvGPIO_Open(E_GPA, 5, E_IO_OUTPUT); { uint8_t status = nrf_read_reg(NRF_STATUS); nrf_write_reg(NRF_WRITE_REG|NRF_STATUS,status); // clear IRQ flags nrf_write_reg(NRF_FLUSH_RX, 0xff); nrf_write_reg(NRF_FLUSH_TX, 0xff); } while(1) { uint8_t buffer[32]; if(tx_done) { static uint8_t yy = 0; yy++; if(yy&1) { DrvGPIO_SetBit(E_GPA,2); } else { DrvGPIO_ClrBit(E_GPA,2); } if(tx_done == 1) { } else { } buffer[0] = tx_done; tx_done = 0; } if(rx_done) { static uint8_t xx = 0; rx_done = 0; xx++; if(xx & 1) DrvGPIO_SetBit(E_GPA,5); else DrvGPIO_ClrBit(E_GPA,5); //nrf_ack_packet(0,buffer, (xx&15) + 1); nrf_ack_packet(0,rx_buffer, rx_len); } } while(1) { static uint8_t cnt = 0; if(cnt&1) { DrvGPIO_SetBit(E_GPA,2); } else { DrvGPIO_ClrBit(E_GPA,2); } DrvSYS_Delay(50000*2); cnt++; //nrf_tx_packet(buffer, 16); //buffer[0]++; if(nrf_rx_packet(buffer,16) == NRF_RX_OK) { static uint8_t xx = 0; xx++; if(xx & 1) DrvGPIO_SetBit(E_GPA,5); else DrvGPIO_ClrBit(E_GPA,5); } } return 0; }
//***************************************************************************** // //! \brief GPIO test. //! //! \param None //! //! \return None // //***************************************************************************** void GpioTest(void) { int32_t i32Err; UNLOCKREG(); // // Enable high external clock and use it as system clock (HCLK) // DrvSYS_Open(XTL_CLK); // // Waiting for 12M Xtal stable // while (DrvSYS_GetChipClockSourceStatus(XTL_CLK) != 1); // // Configure Bit0 in Port1 to Output pin and Bit4 in Port3 to Input // pin then close it // DrvGPIO_Open(E_PORT1, E_PIN0, E_IO_OUTPUT); DrvGPIO_Open(E_PORT3, E_PIN4, E_IO_INPUT); i32Err = 0; DrvGPIO_ClrBit(E_PORT1, E_PIN0); if (DrvGPIO_GetBit(E_PORT3, E_PIN4) != 0) { i32Err = 1; } DrvGPIO_SetBit(E_PORT1, E_PIN0); if (DrvGPIO_GetBit(E_PORT3, E_PIN4) != 1) { i32Err = 1; } DrvGPIO_Close(E_PORT1, E_PIN0); DrvGPIO_Close(E_PORT3, E_PIN4); // // GPIO Interrupt Test:P15, P22, P32(INT0) and P52(INT1) are used to test // interrupt and control LEDs(P30) // // //Configure P30 for LED control // DrvGPIO_Open(E_PORT3, E_PIN0, E_IO_OUTPUT); // //Configure P15 as general GPIO interrupt // DrvGPIO_Open(E_PORT1, E_PIN5, E_IO_INPUT); // //The Quasi-bidirection mode could be used as input with pull up enable // DrvGPIO_Open(E_PORT2, E_PIN2, E_IO_QUASI); // // Configure general interrupt callback function for P0/P1 and P2/P3/P4 // DrvGPIO_SetIntCallback(P0P1Callback, P2P3P4Callback, P5Callback); DrvGPIO_EnableInt(E_PORT1, E_PIN5, E_IO_RISING, E_MODE_EDGE); // // IO_FALLING means low level trigger if it is in level trigger mode. // DrvGPIO_EnableInt(E_PORT2, E_PIN2, E_IO_FALLING, E_MODE_LEVEL); DrvGPIO_SetDebounceTime(0, E_DBCLKSRC_HCLK); DrvGPIO_EnableDebounce(E_PORT1, E_PIN5); DrvGPIO_EnableDebounce(E_PORT2, E_PIN2); DrvGPIO_EnableDebounce(E_PORT3, E_PIN2); DrvGPIO_EnableDebounce(E_PORT5, E_PIN2); // // Configure external interrupt. // DrvGPIO_InitFunction(FUNC_EXTINT0); DrvGPIO_InitFunction(FUNC_EXTINT1); DrvGPIO_EnableEINT(E_EINT0_PIN, E_IO_FALLING, E_MODE_EDGE, EINT0Callback); DrvGPIO_EnableEINT(E_EINT1_PIN, E_IO_BOTH_EDGE, E_MODE_EDGE, EINT1Callback); }