コード例 #1
0
ファイル: blinker.c プロジェクト: EDAyele/wsn430
void vBlinkerRequest(uint8_t cmd)
{
    switch (cmd & CMD_MASK)
    {
        case CMD_LED_ON:
            switch (cmd & LED_MASK)
            {
                case LED_RED:
                    LED_RED_ON();
                    break;
                case LED_GREEN:
                    LED_GREEN_ON();
                    break;
                case LED_BLUE:
                    LED_BLUE_ON();
                    break;
                case LED_ALL:
                    LEDS_ON();
                    break;
            }
            break;

        case CMD_LED_OFF:
            switch (cmd & LED_MASK)
            {
                case LED_RED:
                    LED_RED_OFF();
                    break;
                case LED_GREEN:
                    LED_GREEN_OFF();
                    break;
                case LED_BLUE:
                    LED_BLUE_OFF();
                    break;
                case LED_ALL:
                    LEDS_OFF();
                    break;
            }
            break;
        case CMD_LED_TOGGLE:
            switch (cmd & LED_MASK)
            {
                case LED_RED:
                    LED_RED_TOGGLE();
                    break;
                case LED_GREEN:
                    LED_GREEN_TOGGLE();
                    break;
                case LED_BLUE:
                    LED_BLUE_TOGGLE();
                    break;
                case LED_ALL:
                    LED_RED_TOGGLE();
                    LED_GREEN_TOGGLE();
                    LED_BLUE_TOGGLE();
                    break;
            }
            break;
    }
}
コード例 #2
0
ファイル: mac.c プロジェクト: EDAyele/wsn430
static void vMacTask(void* pvParameters)
{
    uint16_t rx_count;
    uint8_t event;
    vInitMac();

    for (;;)
    {
        vStartRx();

        rx_count = 0;

        while ( xQueueReceive(xEvent, &event, 15000) == pdTRUE)
        {
            if (event == EVENT_FRAME_RECEIVED)
            {
                rx_count ++;
                LED_GREEN_ON();
                vParseFrame();
                LED_GREEN_OFF();
            }

            if (rx_count == 128)
            {
                break;
            }
        }
        LED_RED_TOGGLE();
    }
}
コード例 #3
0
/*------------------------PIT Handler---------------------------*/
void PIT_IRQHandler(void)
{
	if(PIT->CHANNEL[0].TFLG!=0)	            // Check Interrupt Timer0 Flag 
	{	
		LED_GREEN_TOGGLE();   								//Toggle led green after 2s
	}
	
	if(PIT->CHANNEL[1].TFLG!=0)	            // Check Interrupt Timer1 Flag 
	{	
		LED_RED_TOGGLE();   								  //Toggle led red after 4s
	}
	
	PIT->CHANNEL[0].TFLG = 1UL;	          	// Clear Interrupt Timer0 Flag
	PIT->CHANNEL[1].TFLG = 1UL;	          	// Clear Interrupt Timer1 Flag
}
コード例 #4
0
ファイル: main.c プロジェクト: EDAyele/wsn430
uint16_t char_rx(uint8_t c) {
    LED_GREEN_TOGGLE();

    if (c=='t' || c=='l') {
        LED_RED_TOGGLE();
        // copy received character to cmd variable.
        cmd = c;
        // return not zero to wake up the CPU.
        return 1;
    } else {
        LED_BLUE_TOGGLE();
        // if not a valid command don't wake the CPU up.
        return 0;
    }
}
コード例 #5
0
ファイル: main.c プロジェクト: colossus212/RM_Driver
int main(void)
{
	//设置NVIC中断分组2位抢占优先级,2位响应优先级
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2) ;

	Ticker_Configuration();

	LED_Configuration();

	USART2_Configuration();

	delay_init();

	//Do_Loop_LED_Test();
	//Do_Loop_Motor_Test();
	//DISABLE_FOLLOWING_CODE(1);

	//主控通信控制器初始化
	Maincontrol_Configuration();

	Encoder_Configuration();
	Encoder_Start();

	//速度采样控制器初始化
	TIM2_Configuration(5);
	TIM2_Start();

	//电流检测
	ADC_Configuration();

	//电机初始化
	Motor_Init();

	while (1)
	{
		delay_ms(200);

		LED_RED_TOGGLE();
		LED_GREEN_TOGGLE();
	}
}
コード例 #6
0
ファイル: main_node.c プロジェクト: EDAyele/wsn430
int main (void)
{
    WDTCTL = WDTPW+WDTHOLD;                   // Stop watchdog timer

    set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();
    set_aclk_div(1);

    LEDS_INIT();
    LEDS_OFF();

    uart0_init(UART0_CONFIG_1MHZ_115200);
    printf("\n-----------------------------------\n");
    printf("TDMA_NODE test\r\n");
    eint();

    mac_init(0);
    mac_set_access_allowed_cb(mac_ready);

    printf("*** I'm %u ***\n", node_addr);

    uint8_t dodo = 'a';
    while(1) {
        if (mac_is_access_allowed()) {
            mac_payload[0] = dodo;
            mac_send();

            dodo++;
            if (dodo>'z')dodo='a';

            LED_RED_TOGGLE();
        }
        LPM3;
    }

    return 0;
}
コード例 #7
0
ファイル: main_rx.c プロジェクト: EDAyele/wsn430
/**
 * The main function.
 */
int main( void )
{
    uint8_t i;
    uint8_t length;

    /* Stop the watchdog timer. */
    WDTCTL = WDTPW + WDTHOLD;

    /* Setup MCLK 8MHz and SMCLK 1MHz */
    set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();

    /* Enable Interrupts */
    eint();

    LEDS_INIT();
    LEDS_ON();

    uart0_init(UART0_CONFIG_1MHZ_115200);
    printf("CC2420 RX test program with address recognition and acknowledge frames\r\n");

    cc2420_init();
    cc2420_io_sfd_register_cb(sfd_cb);
    cc2420_io_sfd_int_set_falling();
    cc2420_io_sfd_int_clear();
    cc2420_io_sfd_int_enable();

    uint8_t src_pan_id[2] = {0x22,0x00};
    uint8_t src_addr[2] = {0x11,0x11};

    while ( (cc2420_get_status() & 0x40) == 0 ); // waiting for xosc being stable

    cc2420_set_panid(src_pan_id); // save pan id in ram
    cc2420_set_shortadr(src_addr); // save short address in ram

    printf("CC2420 initialized\r\n");

    LEDS_OFF();

    while(1)
    {
        cc2420_cmd_idle();
        cc2420_cmd_flushrx();
        cc2420_cmd_rx();

        while (flag == 0) ;
        micro_delay(0xFFFF);
        flag = 0;
	LED_GREEN_TOGGLE();
        cc2420_fifo_get(&length, 1);
        if ( length < 128 )
        {
            cc2420_fifo_get(rxframe, length);
            // check CRC
            if ( (rxframe[length-1] & 0x80) != 0 )
            {
                printf("Frame received with rssi=%ddBm:\r\n", ((signed int)((signed char)(rxframe[length-2])))-45);
                LED_BLUE_TOGGLE();
		// ignore 11 first bytes (fcf,seq,addr) and the 2 last ones (crc)
                for (i=11; i<length-2; i++)
                {
                    printf("%c",rxframe[i]);
                }
                printf("\r\n\n");
            }
	    else {
		printf("CRC non OK, erreur de transmission?\n");
                printf("\r\n");
                LED_RED_TOGGLE();
	    }
        }
    }

    return 0;
}
コード例 #8
0
ファイル: main.c プロジェクト: EDAyele/wsn430
uint16_t alarm(void) {
    LED_RED_TOGGLE();
    LED_BLUE_TOGGLE();
    LED_GREEN_TOGGLE();
    return 0;
}
コード例 #9
0
ファイル: main_tx.c プロジェクト: EDAyele/wsn430
/**
 * The main function.
 */
int main( void )
{

    /* Stop the watchdog timer. */
    WDTCTL = WDTPW + WDTHOLD;

    /* Setup MCLK 8MHz and SMCLK 1MHz */
    set_mcu_speed_xt2_mclk_8MHz_smclk_1MHz();

    /* Enable Interrupts */
    eint();

    LEDS_INIT();
    LEDS_ON();

    uart0_init(UART0_CONFIG_1MHZ_115200);
    printf("CC2420 TX test program with address recognition and acknowledge frames\r\n");

    cc2420_init();
    cc2420_io_sfd_register_cb(sfd_cb);
    cc2420_io_sfd_int_set_falling();
    cc2420_io_sfd_int_clear();
    cc2420_io_sfd_int_enable();
    cc2420_set_txpower(CC2420_2_45GHz_TX_0dBm);

    uint8_t fcf[2] = {0x21, 0x88};  /* -> 00100001 10001000 -> reverse of bits for each byte -> 10000100 00010001 -> ack bit = 1 (6th bit), Frame type = 001 (don't forget to read from right to left) */
    uint8_t seq_numb = 0x01;
    uint8_t dest_pan_id[2] = {0x22, 0x00};
    uint8_t dest_addr[2] = {0x11, 0x11};

    uint8_t src_pan_id[2] = {0x22, 0x01};
    uint8_t src_addr[2] = {0x11, 0x12};

    while ( (cc2420_get_status() & 0x40) == 0 ); // waiting for xosc being stable

    cc2420_set_panid(src_pan_id); // save pan id in ram
    cc2420_set_shortadr(src_addr); // save short address in ram

    printf("CC2420 initialized\r\n");

    LEDS_OFF();

    while (1)
    {
        cc2420_cmd_idle();
        cc2420_cmd_flushtx();

        txlength = sprintf((char *)txframe, "Hello World #%i", seq_numb);

        printf("Sent : %s of length %d\r\n", txframe,txlength);

        txlength += 13;

        cc2420_fifo_put(&txlength, 1);
        cc2420_fifo_put(fcf, 2);
        cc2420_fifo_put(&seq_numb, 1);
        cc2420_fifo_put(dest_pan_id, 2);
        cc2420_fifo_put(dest_addr, 2);
        cc2420_fifo_put(src_pan_id, 2);
        cc2420_fifo_put(src_addr, 2);
        cc2420_fifo_put(txframe, txlength-13);

	LED_BLUE_TOGGLE();

        cc2420_cmd_tx();

        micro_delay(0xFFFF);
	while (cc2420_io_sfd_read());

	printf("Waiting for acknowledge frame...\n");

	if (rx_ack())
	{
            seq_numb ++;
	}
	else
	{
	    printf("No Acknowledge frame received for frame number #%i - Retrying...\r\n\n", seq_numb);
	    LED_RED_TOGGLE();
	}
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
        micro_delay(0xFFFF);
    }


    return 0;
}