int main(void) { cpu_set_clock_source(cpu_32mhz_clock); cpu_configure_interrupt_level(cpu_interrupt_level_medium, true); cpu_configure_interrupt_level(cpu_interrupt_level_low, true); cpu_configure_interrupt_level(cpu_interrupt_level_high, true); uint8_t outbuffer[128]; uint8_t inbuffer[128]; uart_port_t debug_port = uart_init_port(&PORTE, &USARTE0, uart_baud_115200, outbuffer, 128, inbuffer, 128); uart_connect_port(&debug_port, true); printf("Menial PWM test.....\n> "); pwm_output_t pwm_output = pwm_initilize_output(io_init_pin(&PORTC, 4), pwm_div256, 1000); pwm_enable_output(&pwm_output); PORTC.DIRSET = 1<<3; while (1) { PORTC.OUTTGL = 1<<3; pwm_set_output(&pwm_output, 100); _delay_ms(1000); PORTC.OUTTGL = 1<<3; pwm_set_output(&pwm_output, 500); _delay_ms(1000); } while(1); return 1; }
void pwm_exit( void) { if (debug_flags & DEBUG_PWM) { printf( "pwm_exit called, releasing PWM subsystem\n"); } for (int ch = 0 ; ch < num_pwm_channels ; ++ch) { if (pwm_channels[ ch].duty_fd != -1) { struct pwm_channel_record* pd = &pwm_channels[ ch]; pwm_set_output( pd->id, 0); pwm_write_int_to_file( pd->device_path, "run", 0); pwm_write_int_to_file( pd->device_path, "request", 0); close (pd->duty_fd); } } }
int pwm_init( void) { if (debug_flags & DEBUG_PWM) { printf( "pwm_init called'\n"); } if (pwm_config_data) { char s[ 100]; atexit( pwm_exit); for (int ch = 0 ; ch < pwm_config_items ; ++ch) { pwm_config_record* ps = &pwm_config_data[ ch]; struct pwm_channel_record* pd = &pwm_channels[ ch]; pd->id = ps->tag; pd->device_path = ps->device_path; pd->frequency = ps->frequency; pd->duty_fd = -1; ++num_pwm_channels; pwm_write_int_to_file( pd->device_path, "request", 1); pwm_write_int_to_file( pd->device_path, "polarity", 0); pwm_write_int_to_file( pd->device_path, "duty_percent", 0); if (pd->frequency) { pwm_write_int_to_file( pd->device_path, "period_freq", pd->frequency); } snprintf( s, sizeof( s), "%s/duty_percent", pwm_channels[ ch].device_path); pwm_channels[ ch].duty_fd = open( s, O_WRONLY); if (pwm_channels[ ch].duty_fd < 0) { perror( "pwm_init: failed to open 'duty_percent' file"); } pwm_set_output( pd->id, 0); pwm_write_int_to_file( pd->device_path, "run", 1); } return 0; } fprintf( stderr, "pwm_init: no configuration data!\n"); return -1; }
int unicorn_test(void) { int i = 0; int idx = 0; int num_fans = 0; double celsius = 0.0; channel_tag heater, fan, pwm; if (bbp_board_type == BOARD_BBP1S) { num_fans = 6; } else if (bbp_board_type == BOARD_BBP1) { num_fans = 5; } #if 0 start_test_thread(); int count = 10; while (1) { printf("wait evtout count=%d\n", count); prussdrv_pru_wait_event(PRU_EVTOUT_1); prussdrv_pru_clear_event(PRU_EVTOUT_1, PRU1_ARM_INTERRUPT); if(count-- == 0){ return; } } #endif printf("Test 1: Fan testing...\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 1: Fan testing...\n"); printf(" Please watch the led lights and leds on board\n"); printf(" 1.1 close all fans\n"); for (idx = 0; idx < num_fans; idx++) { fan = fan_lookup_by_index(idx); if (fan) { fan_disable(fan); } } printf(" 1.2 open each fan for 1s then close one by one\n"); for (idx = 0; idx < num_fans; idx++) { fan = fan_lookup_by_index(idx); if (fan) { printf(" Open %s\n", tag_name(fan)); fan_enable(fan); fan_set_level(fan, 80); sleep(1); printf(" Close %s\n", tag_name(fan)); fan_set_level(fan, 0); fan_disable(fan); } } printf(" 1.3 turn on all fans for 1s, then turn off, repeat 3 times\n"); for (i = 0; i < 2; i++) { for (idx = 0; idx < num_fans; idx++) { fan = fan_lookup_by_index(idx); if (fan) { fan_enable(fan); fan_set_level(fan, 80); } } sleep(1); for (idx = 0; idx < num_fans; idx++) { fan = fan_lookup_by_index(idx); if (fan) { fan_disable(fan); } } sleep(1); } printf("-------------------------------------------------------------\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 2: LMSW testing...\n"); printf(" 2.1 Please press min x: \n"); wait_lmsw_min_test(X_AXIS); printf(" min_x ok\n"); printf(" 2.2 Please press min y: \n"); wait_lmsw_min_test(Y_AXIS); printf(" min_y ok\n"); printf(" 2.3 Please press min z: \n"); wait_lmsw_min_test(Z_AXIS); printf(" min_z ok\n"); printf(" 2.4 Please press max x: \n"); wait_lmsw_max(X_AXIS); printf(" max_x ok\n"); printf(" 2.5 Please press max y: \n"); wait_lmsw_max(Y_AXIS); printf(" max_y ok\n"); printf(" 2.6 Please press max z: \n"); wait_lmsw_max(Z_AXIS); printf(" max_z ok\n"); printf("-------------------------------------------------------------\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 3: Heater testing...\n"); printf(" open each heater for 1s then close\n"); printf(" Please watch the led beside the heater interface!\n"); if (bbp_board_type == BOARD_BBP1S) { pwm = pwm_lookup_by_name("pwm_ext"); if (pwm) { pwm_set_output(pwm, 80); } sleep(1); pwm_set_output(pwm, 0); sleep(1); pwm = pwm_lookup_by_name("pwm_ext2"); if (pwm) { pwm_set_output(pwm, 80); } sleep(1); pwm_set_output(pwm, 0); sleep(1); pwm = pwm_lookup_by_name("pwm_bed"); if (pwm) { pwm_set_output(pwm, 80); } sleep(1); pwm_set_output(pwm, 0); sleep(1); for (i = 0; i < 2; i++) { pwm = pwm_lookup_by_name("pwm_ext"); if (pwm) { pwm_set_output(pwm, 80); } pwm = pwm_lookup_by_name("pwm_ext2"); if (pwm) { pwm_set_output(pwm, 80); } pwm = pwm_lookup_by_name("pwm_bed"); if (pwm) { pwm_set_output(pwm, 80); } sleep(4); pwm = pwm_lookup_by_name("pwm_ext"); if (pwm) { pwm_set_output(pwm, 0); } pwm = pwm_lookup_by_name("pwm_ext2"); if (pwm) { pwm_set_output(pwm, 0); } pwm = pwm_lookup_by_name("pwm_bed"); if (pwm) { pwm_set_output(pwm, 0); } sleep(2); } } if (bbp_board_type == BOARD_BBP1) { for (idx = 0; idx < NUM_HEATERS; idx++) { heater = heater_lookup_by_index(idx); if (heater) { printf(" Open %s\n", tag_name(heater)); heater_enable(heater); heater_set_raw_pwm(heater, 40); sleep(5); printf(" Close %s\n", tag_name(heater)); heater_set_raw_pwm(heater, 0); heater_disable(heater); } } } printf("done.\n"); printf("-------------------------------------------------------------\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 4: Stepper testing...\n"); printf(" 4.1 Turn on all stepper\n"); stepper_test(); printf(" 4.2 Stop Stepper\n"); printf(" Please press min x to stop stepper\n"); wait_lmsw_min(X_AXIS); printf("-------------------------------------------------------------\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 5: USB Host testing...\n"); printf(" 5.1 please insert U mass storage\n"); if(unicorn_test_usb_storage() == -1){ halt_test("Usb mass storage is BAD!!!!!!!!!!!!!!!\n"); } printf("Usb mass storage is OK\n"); printf("-------------------------------------------------------------\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 6: Internal emmc testing...\n"); if(unicorn_test_emmc() == -1){ halt_test("Internal emmc is BAD!!!!!!!!!!!!!!\n"); } printf("Internal emmc is OK\n"); printf("done.\n"); printf("-------------------------------------------------------------\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 7: eeprom testing...\n"); if(unicorn_test_eeprom() == -1){ halt_test("eeprom is BAD!!!!!!!!!!!!\n"); } printf("eeprom is OK\n"); printf("done.\n"); printf("-------------------------------------------------------------\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 8: rtc testing...\n"); if(unicorn_test_rtc() == -1) { halt_test("rtc is BAD!!!!!!!!!!!!\n"); } printf("rtc is OK\n"); printf("done.\n"); printf("-------------------------------------------------------------\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 9: Network testing...\n"); printf(" Start to ping the router..\n"); if(unicorn_test_network() == -1) { halt_test("network is BAD!!!!!!!!!!!!\n"); } printf("done.\n"); printf("-------------------------------------------------------------\n"); printf("Test 10: USB OTG testing...\n"); printf(" 11.1 Please connect usb otg line to PC\n"); printf(" 11.2 Could you see the boot partion? If yes, Please press min_x..\n"); wait_lmsw_min_test(X_AXIS); printf("done.\n"); printf("-------------------------------------------------------------\n"); if (bbp_board_type == BOARD_BBP1S) { printf("Test 11: Test max6675 temperature...\n"); printf("long press min y key to exit\n"); if(unicorn_test_max6675() == -1) { halt_test("max6675 is BAD!!!!!!!!!!!!\n"); } printf("\n-------------------------------------------------------------\n"); } #if 0 if (bbp_board_type == BOARD_BBP1S) { #ifdef SERVO printf("Test 12: Test servo...\n"); if (unicorn_test_servo()) { halt_test("servo is BAD!!!!!!!!!!!!\n"); } printf("\n-------------------------------------------------------------\n"); #endif } #endif printf("\n-------------------------------------------------------------\n"); printf("Test 12: Temp adc testing...\n"); heater_start(); if (bbp_board_type == BOARD_BBP1S) { char *heater_array_bbp1s[] = {"heater_ext", "heater_ext2", "heater_bed"}; for (idx = 0; idx < sizeof(heater_array_bbp1s)/sizeof(heater_array_bbp1s[0]); idx++) { heater = heater_lookup_by_name(heater_array_bbp1s[idx]); if (heater) { heater_enable(heater); heater_set_setpoint(heater, TARGET_TEMP); } } for (i = 0; i < 80 && stepper_check_lmsw(X_AXIS) == 0; i++) { for (idx = 0; idx < sizeof(heater_array_bbp1s)/sizeof(heater_array_bbp1s[0]); idx++) { heater = heater_lookup_by_name(heater_array_bbp1s[idx]); if (heater) { celsius = 0.0; heater_get_celsius(heater, &celsius); printf("%s -> %f\n", tag_name(heater), celsius); sleep(1); } } } } else if (bbp_board_type == BOARD_BBP1) { for (idx = 0; idx < NUM_HEATERS; idx++) { heater = heater_lookup_by_index(idx); if (heater) { heater_enable(heater); heater_set_setpoint(heater, TARGET_TEMP); } } printf("long press min x key to exit\n"); heater = heater_lookup_by_name("heater_bed"); for (i = 0; i < 80 && stepper_check_lmsw(X_AXIS) == 0; i++) { if (heater_temp_reached(heater)) { printf("ok\n"); break; } else { sleep(1); } for (idx = 0; idx < NUM_HEATERS; idx++) { heater = heater_lookup_by_index(idx); if (heater) { celsius = 0.0; heater_get_celsius(heater, &celsius); printf("%s -> %f\n", tag_name(heater), celsius); } } printf("\n"); } } heater_stop(); printf("done.\n"); printf("-------------------------------------------------------------\n"); halt_test("All is Good!\n"); return 0; }