示例#1
0
void buzzer_callback()
{
	/* Start by incrementing the counter; we are playing the next note
	 * This is here because the index must atually point to the note
	 * currently playing, so main knows if we can go to LPM3 */
	buzzer_counter++;

	/* Here the -1 is needed for the offset of buzzer_counter due to the
	 * increment above. */
	note n = *(buzzer_buffer + buzzer_counter - 1);
	/* 0x000F is the "stop bit" */
	if(PITCH(n) == 0) {
		/* Stop buzzer */
		buzzer_stop();
		return;
	}
	if (PITCH(n) == 0x000F) {
		/* Stop the timer! We are playing a rest */
		TA1CTL &= ~MC_3;
	} else {
		/* Set PWM frequency */
		TA1CCR0 = base_notes[PITCH(n)] >> OCTAVE(n);

		/* Start the timer */
		TA1CTL |= MC__UP;
	}

	/* Delay for DURATION(*n) milliseconds, */
	timer0_delay_callback(DURATION(n), &buzzer_callback);
}
示例#2
0
static ssize_t zili_demo_char_buzzer_write(struct file *fp, const char *buf, size_t count, loff_t *position){

	unsigned long buzzer_status;

	int  ret;

	ret = copy_from_user(&buzzer_status, buf, sizeof(buzzer_status) );

	if(ret){

		printk("Fail to copy data from the user space to the kernel space!\n");

	}

	if( buzzer_status > 0 ){

		printk("Write Buzzuer Status: %lu\n",buzzer_status);

		set_freq(buzzer_status);

		

	}

	else{

		buzzer_stop();

	}

	return sizeof(buzzer_status);

}
示例#3
0
void buzzer_play(note *notes)
{

	/* Allow buzzer PWM output on P2.7 */
	P2SEL |= BIT7;

	/* 0x000F is the "stop bit" */
	while (PITCH(*notes) != 0x000F) {
		if (PITCH(*notes) == 0) {
			/* Stop the timer! We are playing a rest */
			TA1CTL &= ~MC_3;
		} else {
			/* Set PWM frequency */
			TA1CCR0 = base_notes[PITCH(*notes)] >> OCTAVE(*notes);

			/* Start the timer */
			TA1CTL |= MC__UP;
		}

		/* Delay for DURATION(*notes) milliseconds,
		   use LPM1 because we need SMCLK for tone generation */
		timer0_delay(DURATION(*notes), LPM1_bits);

		/* Advance to the next note */
		notes++;
	}

	/* Stop buzzer */
	buzzer_stop();
}
示例#4
0
static int zili_demo_char_buzzer_close(struct inode *inode, struct file *file) {

	buzzer_stop();

	return 0;

}
示例#5
0
static int zili_demo_char_buzzer_open(struct inode *inode, struct file *file) {

	//map the IO physical memory address to virtual address

	ZL_GPD0_CON_ADDR = ioremap(GPD0_CON_ADDR, 0x00000004);

	ZL_GPD0_CON_DATA = ioremap(GPD0_CON_DATA, 0x00000004);
	/*IO remap*/

	ZL_TCFG0 = ioremap(TCFG0, 0x00000004);

	ZL_TCFG1 = ioremap(TCFG1, 0x00000004);

	ZL_TCNTB0 = ioremap(TCNTB0, 0x00000004);

	ZL_TCMPB0 = ioremap(TCMPB0, 0x00000004);

	ZL_TCON = ioremap(TCON, 0x00000004);
	 	
	buzzer_stop();

	printk("Device " DEVICE_NAME " open.\n");

	return 0;

}
示例#6
0
void stop_sound()
{
    if (buzzer_init)
    {
        buzzer_stop();
        printf("********CLOSED AUDIO BUFFER***********\n");
        buzzer_init = 0;
    }
}
示例#7
0
static void __exit zili_demo_char_buzzer_dev_exit(void) {

	buzzer_stop();

	cdev_del(&dev_buzzer);

	unregister_chrdev_region(devno, N_D);

	printk("Device " DEVICE_NAME " unloaded.\n");

}
/*---------------------------------------------------------------------------*/
static void
shutdown_handler(uint8_t mode)
{
  if(mode == LPM_MODE_SHUTDOWN) {
    buzzer_stop();
    SENSORS_DEACTIVATE(bmp_280_sensor);
    SENSORS_DEACTIVATE(opt_3001_sensor);
    SENSORS_DEACTIVATE(tmp_007_sensor);
    SENSORS_DEACTIVATE(sht_21_sensor);
    mpu_9250_sensor.configure(MPU_9250_SENSOR_SHUTDOWN, 0);
  }
}
示例#9
0
/*---------------------------------------------------------------------------*/
static void
pub_handler(const char *topic, uint16_t topic_len, const uint8_t *chunk,
            uint16_t chunk_len)
{
    DBG("Pub Handler: topic='%s' (len=%u), chunk_len=%u\n", topic, topic_len,
        chunk_len);

    /* If we don't like the length, ignore */

    if(/*topic_len != 23 ||*/ chunk_len != 1) {
        printf("Incorrect topic or chunk len. Ignored\n");
        return;
    }

    /* If the format != json, ignore
    if(strncmp(&topic[topic_len - 4], "json", 4) != 0) {
      printf("Incorrect format\n");
    }*/

    if(strstr(topic, "/cmd/leds") != NULL) {
        if(chunk[0] == '1') {
            leds_on(LEDS_RED);
        } else if(chunk[0] == '0') {
            leds_off(LEDS_RED);
        }
        return;
    }

#if BOARD_SENSORTAG
    if(strstr(topic, "/cmd/buzz") != NULL) {
        if(chunk[0] == '1') {
            buzzer_start(1000);
        } else if(chunk[0] == '0') {
            buzzer_stop();
        }
        return;
    }
#endif
}
示例#10
0
void buzzer_play(note *notes)
{
	/* TODO: Define correct behaviour here. Should we error out or just
	 * return? Should we return an error code? or just crash, to identify
	 * and eliminate any race condition? Or just replace the buffer? */
	if(buzzer_buffer != NULL)
		buzzer_stop();

	uint8_t len = 0;
	while (notes[len] != 0) len++;

	len++; /* We count the end note to get actual length */
	buzzer_buffer = malloc(len * sizeof(notes));
	memcpy(buzzer_buffer, notes, len * sizeof(notes));
	buzzer_counter = 0;

	/* Allow buzzer PWM output on P2.7 */
	P2SEL |= BIT7;

	/* Play first note */
	buzzer_callback();
}
示例#11
0
文件: main.c 项目: hexianren/Mini6410
int main()
{
	char c;
	{
		putchar('1');
		putchar('\n');
		putchar('1');
		putchar('\n');
		putchar('1');
		putchar('\r');
	}
	unsigned long delay = 0;
	while(1)
	{
	buzzer_stop();
	for(delay = 0; delay < 0xfffff * 2; delay++);
	buzzer_ring();
	for(delay = 0; delay < 0xfffff * 2; delay++);
	}
	while(1);	
	return 0;
}
示例#12
0
文件: debug.c 项目: narumiya/stm32
void debug(void)
{
	robot_information_t robot;
	target_cam_t target_cam;

	unsigned char str[10] = "\0";

	unsigned short 	old_sw = 0,
								start_sw =0,
								old_limit_sw = 0;

	float target_degree = 0.00;

	transmit_usb("[ r : reset] \n\r");
	transmit_usb("[ 1 : encoder]\n\r");
	transmit_usb("[ 2 : AD]\n\r");
	transmit_usb("[ 3 : coordinate]\n\r");
	transmit_usb("[ 4 : sonic_waves]\n\r");
	transmit_usb("[ 5 : encoder reset]\n\r");
	transmit_usb("[ 6 : cam_inf]\n\r");
	transmit_usb("[ 7 : target_cam]\n\r");
	transmit_usb("[ 8 : inf&target]\n\r");
	transmit_usb("[ 9 : start_switch]\n\r");
	transmit_usb("[10 : limit_switch]\n\r");
	transmit_usb("[11 : motor]\n\r");
	transmit_usb("[12 : reverse motor]\n\r");
	transmit_usb("[13 : stop motor]\n\r");
	transmit_usb("[14 : arm motor]\n\r");
	transmit_usb("[15 : reverse arm motor]\n\r");
	//transmit_usb("[p : p gain adjustment]\n\r");
	//transmit_usb("[d : d gain adjustment]\n\r");
	GPIO_ResetBits(ENC_RESET);

	while(strcmp(str, "r") != 0){
		if(usb_available() != 0){
			usb_get_string(str);
		}
		buzzer_stop();
		//sonic_waves(&robot);

		if(count_time(3) >= INTERRUPT_TIME){
			reset_count_time(3);
			get_robot_inf( &robot );
			cam_data(&target_cam, &robot);
			start_sw =positive_chattering(START_SW,1);
			robot.sw.limit_sw = negative_chattering(LIMIT_SW,2);
			robot.ad = get_ADC1_value(0);
		}

		if(strcmp(str, "1") == 0){
			f_print(PC,"ENCL",robot.enc_cnt.l);
			f_print(PC,"ENCR",robot.enc_cnt.r);
			f_print(PC,"ENCF",robot.enc_cnt.f);
			put_enter(PC);

		}else if(strcmp(str, "2") == 0){
			f_print(PC,"AD",robot.ad);
			put_enter(PC);

		}else if(strcmp(str, "3") == 0){
			f2_print(PC,"now_coord",robot.coord.c_x, robot.coord.c_y);
			f_print(PC,"deg",robot.angle.degree);
			put_enter(PC);

		}else if(strcmp(str, "4") == 0){
			f_print(PC,"time",count_time(2));
			f_print(PC,"dis",robot.waves);
			put_enter(PC);

		}else if(strcmp(str, "5") == 0){
			GPIO_SetBits(ENC_RESET);
			//str[0] = 'r';

		}else if(strcmp(str, "6") == 0){
			f2_print(PC, "under", target_cam.under_x, target_cam.under_y );
			f2_print(PC, "over", target_cam.over_x, target_cam.over_y );
			put_enter(PC);

		}else if(strcmp(str, "7") == 0){
			f2_print(PC, "target_cam", (target_cam.x) * cos(D_TO_R(robot.angle.degree))+robot.coord.c_x, (target_cam.y)*sin(D_TO_R(robot.angle.degree))+robot.coord.c_y);
			put_enter(PC);

		}else if(strcmp(str, "8") == 0){
			f2_print(PC, "under", target_cam.under_x, target_cam.under_y);
			f2_print(PC, "over", target_cam.over_x, target_cam.over_y );
			target_degree = get_target_degree(ROBO_TO_CENTER - robot.coord.c_x, robot.coord.c_y);
			f2_print(PC, "target_cam", (target_cam.x) * cos(D_TO_R(target_degree)) + robot.coord.c_x, (target_cam.y) * sin(D_TO_R(target_degree)) + robot.coord.c_y);
			put_enter(PC);

		}else if(strcmp(str, "9") == 0){
			if(robot.sw.start_sw != old_sw ){
				f_print(PC,"sw",start_sw);
				put_enter(PC);
			}

		}else if(strcmp(str, "10") == 0){
			if(robot.sw.limit_sw != old_limit_sw ){
				f_print(PC,"limit_sw",robot.sw.limit_sw);
				put_enter(PC);
			}

		}else if(strcmp(str, "11") == 0){
			move(50, 50, 50);

		}else if(strcmp(str, "12") == 0){
			move(-50, -50, -50);

		}else if(strcmp(str, "13") == 0){
			move(0, 0, 0);
			move_arm(0);

		}else if(strcmp(str, "14") == 0){
			move_arm(100);

		}else if(strcmp(str, "15") == 0){
			move_arm(-100);
		}

		old_limit_sw = robot.sw.start_sw;
		old_sw = start_sw;
	}
}
示例#13
0
void _beep(uint16_t freq, uint16_t time) {
   buzzer_start(freq);
   sleep(time);
   buzzer_stop();
}