int main (void) { // Disable the watchdog timer unless it's needed later. This is important because // sometimes the watchdog timer may have been left on...and it tends to stay on MCUSR = 0; wdt_disable (); // Configure a serial port which can be used by a task to print debugging infor- // mation, or to allow user interaction, or for whatever use is appropriate. The // serial port will be used by the user interface task after setup is complete and // the task scheduler has been started by the function vTaskStartScheduler() rs232* p_ser_port = new rs232 (9600, 1); *p_ser_port << clrscr << PMS ("ME405 Lab 1 Program") << endl; // Create the queues and other shared data items here p_print_ser_queue = new TextQueue (32, "Print", p_ser_port, 10); // The user interface is at low priority; it could have been run in the idle task // but it is desired to exercise the RTOS more thoroughly in this test program new task_user ("UserInt", task_priority (1), 260, p_ser_port); // Create a task which reads the A/D and adjusts an LED's brightness accordingly new task_brightness ("Bright", task_priority (2), 280, p_ser_port); // Here's where the RTOS scheduler is started up. It should never exit as long as // power is on and the microcontroller isn't rebooted vTaskStartScheduler (); }
error_t increase_priority (void) { mach_port_t pset = MACH_PORT_NULL, psetcntl = MACH_PORT_NULL; error_t err; err = thread_get_assignment (mach_thread_self (), &pset); if (err) goto out; err = host_processor_set_priv (_hurd_host_priv, pset, &psetcntl); if (err) goto out; err = thread_max_priority (mach_thread_self (), psetcntl, 0); if (err) goto out; err = task_priority (mach_task_self (), 2, 1); out: if (MACH_PORT_VALID (pset)) mach_port_deallocate (mach_task_self (), pset); if (MACH_PORT_VALID (psetcntl)) mach_port_deallocate (mach_task_self (), psetcntl); return err; }
int main (void) { // Disable the watchdog timer unless it's needed later. This is important because // sometimes the watchdog timer may have been left on...and it tends to stay on MCUSR = 0; wdt_disable (); // Configure a serial port which can be used by a task to print debugging infor- // mation, or to allow user interaction, or for whatever use is appropriate. The // serial port will be used by the user interface task after setup is complete and // the task scheduler has been started by the function vTaskStartScheduler() rs232* p_ser_port = new rs232 (9600, 1); // print this identifier line. *p_ser_port << clrscr << PMS ("ME405 Lab 2 Motor Controller Program") << endl; //initialize the A/D converter for potentiometer control adc* p_main_adc = new adc (p_ser_port); // Create the queues and other shared data items here p_print_ser_queue = new TextQueue (32, "Print", p_ser_port, 10); motor_directive = new TaskShare<uint8_t> ("Motor Directive"); motor_power = new TaskShare<int16_t> ("Motor Power"); motor_select = new TaskShare<uint8_t> ("Motor Select"); //initialize to special value so no motor is affected yet motor_select -> put(NULL_MOTER); //initilaize two different motor driver pointers to pass into two tasks motor_driver* p_motor1 = new motor_driver(p_ser_port, &PORTC, &PORTC, &PORTB, &OCR1B, PC0, PC1, PC2, PB6); motor_driver* p_motor2 = new motor_driver(p_ser_port, &PORTD, &PORTD, &PORTB, &OCR1A, PD5, PD6, PD7, PB5); // The user interface is at low priority; it could have been run in the idle task // but it is desired to exercise the RTOS more thoroughly in this test program new task_user ("UserInt", task_priority (1), 260, p_ser_port); // Create tasks to control motors, given individual p_motors new task_motor ("Motor1", task_priority (2), 280, p_ser_port, p_motor1, p_main_adc, 1); new task_motor ("Motor2", task_priority (2), 280, p_ser_port, p_motor2, p_main_adc, 2); // Here's where the RTOS scheduler is started up. It should never exit as long as // power is on and the microcontroller isn't rebooted vTaskStartScheduler (); }
t_status interface_task_priority(o_syscall* message) { t_status error; error = task_priority(message->u.request.u.task_priority.arg1, message->u.request.u.task_priority.arg2); message->u.reply.error = error; return (STATUS_OK); }
int main (int argc, char **argv, char **envp) { mach_port_t boot; error_t err; mach_port_t pset, psetcntl; void *genport; process_t startup_port; struct argp argp = { 0, 0, 0, "Hurd process server" }; argp_parse (&argp, argc, argv, 0, 0, 0); initialize_version_info (); err = task_get_bootstrap_port (mach_task_self (), &boot); assert_perror (err); if (boot == MACH_PORT_NULL) error (2, 0, "proc server can only be run by init during boot"); proc_bucket = ports_create_bucket (); proc_class = ports_create_class (0, 0); generic_port_class = ports_create_class (0, 0); exc_class = ports_create_class (exc_clean, 0); ports_create_port (generic_port_class, proc_bucket, sizeof (struct port_info), &genport); generic_port = ports_get_right (genport); /* Create the initial proc object for init (PID 1). */ startup_proc = create_startup_proc (); /* Create our own proc object (we are PID 0). */ self_proc = allocate_proc (mach_task_self ()); assert (self_proc); complete_proc (self_proc, 0); startup_port = ports_get_send_right (startup_proc); err = startup_procinit (boot, startup_port, &startup_proc->p_task, &authserver, &master_host_port, &master_device_port); assert_perror (err); mach_port_deallocate (mach_task_self (), startup_port); mach_port_mod_refs (mach_task_self (), authserver, MACH_PORT_RIGHT_SEND, 1); _hurd_port_set (&_hurd_ports[INIT_PORT_AUTH], authserver); mach_port_deallocate (mach_task_self (), boot); proc_death_notify (startup_proc); add_proc_to_hash (startup_proc); /* Now that we have the task port. */ /* Set our own argv and envp locations. */ self_proc->p_argv = (vm_address_t) argv; self_proc->p_envp = (vm_address_t) envp; /* Give ourselves good scheduling performance, because we are so important. */ err = thread_get_assignment (mach_thread_self (), &pset); assert_perror (err); err = host_processor_set_priv (master_host_port, pset, &psetcntl); assert_perror (err); thread_max_priority (mach_thread_self (), psetcntl, 0); assert_perror (err); err = task_priority (mach_task_self (), 2, 1); assert_perror (err); mach_port_deallocate (mach_task_self (), pset); mach_port_deallocate (mach_task_self (), psetcntl); { /* Get our stderr set up to print on the console, in case we have to panic or something. */ mach_port_t cons; error_t err; err = device_open (master_device_port, D_READ|D_WRITE, "console", &cons); assert_perror (err); stdin = mach_open_devstream (cons, "r"); stdout = stderr = mach_open_devstream (cons, "w"); mach_port_deallocate (mach_task_self (), cons); } while (1) ports_manage_port_operations_multithread (proc_bucket, message_demuxer, 0, 0, 0); }
int main (void) { // Disable the watchdog timer unless it's needed later. This is important because // sometimes the watchdog timer may have been left on...and it tends to stay on MCUSR = 0; wdt_disable (); // MAKE RESET INTERRUPT // time_stamp the_time_now; // Configure a serial port which can be used by a task to print debugging infor- // mation, or to allow user interaction, or for whatever use is appropriate. The // serial port will be used by the user interface task after setup is complete and // the task scheduler has been started by the function vTaskStartScheduler() rs232* p_ser_port = new rs232 (9600, 1); // print this identifier line. *p_ser_port << clrscr << PMS ("ME405 Lego Car Comms Test") << endl; // set up USART0 on E0 and E1 for external comms // rs232* p_ser_bt = new rs232(0, 0); // UCSR0A |= (1 << U2X0); // set the double-speed bit // UBRR0 = 16; // set baud rate to 115200 //initialize the A/D converter for potentiometer control // adc* p_main_adc = new adc (p_ser_port); // Create the queues and other shared data items here p_print_ser_queue = new TextQueue (32, "Print", p_ser_port, 10); /// Start Shares Motor Variables motor_setpoint = new TaskShare<int16_t> ("Motor SetPoint"); motor_directive = new TaskShare<uint8_t> ("Motor Directive"); motor_power = new TaskShare<int16_t> ("Motor Power"); // Start Shares Encoder Variables encoder_count = new TaskShare<int32_t> ("Encoder Pulse Count"); encoder_ticks_per_task = new TaskShare<int16_t> ("Encoder Pulse Per Time"); // Start Shares IMU variables data_read = new TaskShare<uint32_t> ("imu data"); // Start Shares Steering Variables steering_power = new TaskShare<int16_t> ("Steering Power"); // Start Shares oystick Position Variables x_joystick = new TaskShare<int16_t> ("X Joystick Position"); y_joystick = new TaskShare<int16_t> ("Y Joystick Position"); // Start Shares Gear Variables gear_state = new TaskShare<int16_t> ("Shift State"); // new task_encoder ("EncoderControl", task_priority(5), 280, p_ser_port, p_hctl); new task_receiver ("REC", task_priority(5), 300, p_ser_port); //*p_ser_port << "Waiting.." << endl; //initialize to special value so no motor is affected yet //**DROPPING SUPPORT 2 MOTORS// //motor_select -> put(NULL_MOTER); // //initilaize two different motor driver pointers to pass into two tasks // motor_driver* p_motor1 = new motor_driver(p_ser_port, &PORTC, &PORTC, &PORTB, &OCR1B, PC0, PC1, PC2, PB6); // //USE TIMER AND COUNTER 3 // // this is steering // servo_driver* p_steering_servo = new servo_driver(p_ser_port, &TCCR3A, &TCCR3B, &ICR3, &OCR3A, 8, 20000, PE3); // // this is shifting // //encoder_driver* p_encoder1 = new encoder_driver(p_ser_port, &EICRB, &EIMSK, &DDRE, ISC60, ISC70, INT6, INT7, PE6, PE7); // servo_driver* p_shift_servo = new servo_driver(p_ser_port, &TCCR3A, &TCCR3B, &ICR3, &OCR3B, 8, 20000, PE4); // // make instance of hctl_driver to count external ticks from hctl chip // hctl_driver* p_hctl = new hctl_driver(p_ser_port, &PORTA, &PORTC, 7, &PORTC, 6); // // make instance of imu_driver to be able to link to the BNO055 // imu_driver* p_imu = new imu_driver(p_ser_port, &PORTD, &DDRD, 0, 1); // // temp method to read from IMU // int8_t tempsss = p_imu -> readIMU(0, 1); // shift_driver* p_local_shift = new shift_driver(p_ser_port, &EICRB, &EIMSK, &PORTE, ISC50, INT5, PE5); // // Create tasks to control motors, encoders, and IMUs // new task_user ("UserInt", task_priority (1), 260, p_ser_port); // new task_motor ("MotorControl", task_priority (2), 280, p_ser_port, p_motor1, p_main_adc, 1); // //start encoder and give the highest priority // new task_encoder ("EncoderControl", task_priority(5), 280, p_ser_port, p_hctl); // new task_steering ("SteeringControl", task_priority(3), 280, p_ser_port, p_steering_servo, 1); // new task_shift ("ShiftControl", task_priority(4), 280, p_ser_port,p_shift_servo, 1, p_local_shift); // // create a new PID manager for the motor, with K values of: // // Proportional = 1, Integral = 0, Derivative = 0, Windup = 0 // // And the default saturation limits // new task_pid ("PID", task_priority(4), 280, p_ser_port, motor_setpoint, encoder_ticks_per_task, motor_power, 1024, 0, 0, 0, -1023, 1023); vTaskStartScheduler (); }