void init_pwm(void) /***************************************************************************** * Function : See h-file for specification. *****************************************************************************/ { SYSCTL_RCGC0_R |= SYSCTL_RCC_USEPWMDIV; // Enable clock SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOB; INT8U dummy = SYSCTL_RCGC2_R; // Dummy! Yay! GPIO_PORTB_AFSEL_R |= 0x03; // Alt conf. GPIO_PORTB_DEN_R |= 0x03; SYSCTL_RCC_R |= SYSCTL_RCC_USEPWMDIV; // RCC uses PWM divide and divide by two SYSCTL_RCC_R &= ~SYSCTL_RCC_PWMDIV_M; SYSCTL_RCC_R |= SYSCTL_RCC_PWMDIV_2; PWM_1_CTL_R = 0; // PWM countdown PWM_1_GENA_R |= 0x8C; PWM_1_GENB_R |= 0x80C; PWM_1_LOAD_R |= PWM_LOAD; // The period PWM_1_CMPA_R = 0; // Pulse width, PWM2 pin PWM_INVERT_R |= PWM_INVERT_PWM2INV; PWM_1_CTL_R |= 0x1; // Start PWM generator 1 timers PWM_ENABLE_R |= 0xC; // Enable outputs // Start task _start2(PWM_TASK, MILLI_SEC(10)); }
void sec_tick(void) /***************************************************************************** * Function : See module specification (.h-file). *****************************************************************************/ { if(rtc_state == RTC_NORMAL) { if(seconds >= 59) { seconds = 0; if(minutes >= 59) { minutes = 0; if(hours >= 23) { hours = 0; } else { hours++; } } else { minutes++; } } else { seconds++; } } // Wait 1 sec. _wait(MILLI_SEC(1000)); }
void init_pot(void) /***************************************************************************** * Function : See module specification (.h-file). *****************************************************************************/ { // Init ADC SYSCTL_RCGC0_R |= 0x00010000; // ADC clock ADC_ACTSS_R &= ~ADC_ACTSS_ASEN3; // Disable sequenser 3 ADC_SSMUX3_R |=1; ADC_SSCTL3_R |= ADC_SSCTL3_IE0 | ADC_SSCTL3_END0; ADC_ACTSS_R |= ADC_ACTSS_ASEN3; // Enable sequence 3 ADC_PSSI_R |= ADC_PSSI_SS3; // Start conversion INT16U dummy; for(dummy=20000;dummy>1;dummy--); // Dummy, yay! // Start task _start2(POT_TASK, MILLI_SEC(10)); }
void init_alive_task(void) /***************************************************************************** * Function : See h-file for specification. *****************************************************************************/ { // Init status led port. INT8S dummy; // Enable the GPIO port that is used for the on-board LED. SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF; // Do a dummy read to insert a few cycles after enabling the peripheral. dummy = SYSCTL_RCGC2_R; // Set the direction as output (PF0). GPIO_PORTF_DIR_R |= 0x01; //SET_BIT_HIGH(GPIO_PORTF_DIR_R, PF0); // Enable the GPIO pins for digital function (PF0 and PF1). GPIO_PORTF_DEN_R |= 0x01; //SET_BIT_HIGH(GPIO_PORTF_DEN_R, PF0); // Set pin high GPIO_PORTF_DATA_R |= 0x01; //SET_BIT_HIGH(GPIO_PORTF_DATA_R, PF0); // Start task _start2(ALIVE_TASK, MILLI_SEC(1000)); }
void keyboard_task(void *pvParameters) /***************************************************************************** * Function : See module specification (.h-file). *****************************************************************************/ { INT8U x = 1; INT8U y, key; static INT8U key_state = 0; key_init(); while(1) { switch( key_state ) { case 0: xSemaphoreTake(common_pins_mutex, portMAX_DELAY ); select_x( x ); key_state = 1; break; case 1: y = GPIO_PORTD_DATA_R & 0x3C; xSemaphoreGive(common_pins_mutex); if( y ) { // One key pressed y = row( y ); key = key_catch( x, y ); xQueueSend(keyboard_input_queue, &key, 0); key_state = 2; } case 2: xSemaphoreTake(common_pins_mutex, portMAX_DELAY ); select_x( x ); key_state = 3; break; case 3: y = GPIO_PORTD_DATA_R & 0x3C; xSemaphoreGive(common_pins_mutex); if( y ) { key_state = 2; } else { x++; if( x > 3 ) { x = 1; } key_state = 0; } break; } vTaskDelay(MILLI_SEC(10)); } }
void init_sec_tick(void) /***************************************************************************** * Function : See module specification (.h-file). *****************************************************************************/ { // Start task _start2(RTC_SEC_TASK, MILLI_SEC(1000)); }
void init_fan_rpm(void) /***************************************************************************** * Function : See module specification (.h-file). *****************************************************************************/ { fan_port_setup(); fan_int_setup(); disable_fan_rpm_int(); _start(FAN_RPM_TASK, MILLI_SEC(0)); }
void init_clock(void) /***************************************************************************** * Function : See module specification (.h-file). *****************************************************************************/ { // Setup the first line of the LCD for clock use: lcd_add_string_to_buffer(3, 0, "Time 00:00:00"); // Start task _start2(CLOCK_TASK, MILLI_SEC(500)); }
void alive_task(void) /***************************************************************************** * Function : See h-file for specification. *****************************************************************************/ { // Toggles status LED every 1 sec. GPIO_PORTF_DATA_R ^= 0x01; // Wait 1 sec. _wait(MILLI_SEC(1000)); }
void pwm_task(void) /***************************************************************************** * Function : See h-file for specification. *****************************************************************************/ { // Start CPU cpu_busy(); PWM_1_CMPA_R = pwm_duty_cycle; // Exit CPU cpu_idle(); _wait(MILLI_SEC(10)); }
void update_clock(void) /***************************************************************************** * Function : See module specification (.h-file). *****************************************************************************/ { INT8U state_changes = get_button_count(); if(state_changes > 0) { update_normal(); // To get rid of any lingering boxes in the LCD. change_state(state_changes); } INT8S edit_counter = get_digiswitch_counter(); switch ( rtc_state ) { case RTC_NORMAL: update_normal(); break; case RTC_EDIT_HOURS: adjust_hours(edit_counter); update_edit_hours(); break; case RTC_EDIT_MINUTES: adjust_minutes(edit_counter); update_edit_minutes(); break; case RTC_EDIT_SECONDS: adjust_seconds(edit_counter); update_edit_seconds(); break; default: break; } // Wait 1/2 sec. _wait(MILLI_SEC(330)); }
void pot_task(void) /***************************************************************************** * Function : See module specification (.h-file). *****************************************************************************/ { // Start CPU cpu_busy(); if( ADC_RIS_R && ADC_RIS_INR3 ) { pot_value = (0x3FF & ADC_SSFIFO3_R) / 10; // we only want from 0-100 if(pot_value > 100) // 1024 / 10 = 102, truncate. { pot_value = 100; } ADC_PSSI_R |=ADC_PSSI_SS3; } // Exit CPU cpu_idle(); _wait(MILLI_SEC(10)); }
void fan_rpm_task(void) { fan_rpm = get_fan_int_counter() * 10 * 60 / 4; _wait(MILLI_SEC(100)); }