collab/mm20
git clone https://git.julia.blue/collab/mm20
8b79c2e
firmware
1#include "launchpad.h" 2#include "tivaware/gpio.h" 3#include "tivaware/hw_ints.h" 4#include "tivaware/hw_memmap.h" 5#include "tivaware/rom.h" 6#include "tivaware/sysctl.h" 7#include "tivaware/timer.h" 8#include "driverlib/adc.h" 9#include "driverlib/debug.h" 10#include "driverlib/fpu.h" 11#include "driverlib/gpio.h" 12#include "driverlib/pin_map.h" 13#include "driverlib/sysctl.h" 14#include <math.h> 15#include <stdint.h> 16#include <stdio.h> 17/* XDCtools Header files */ 18#include <xdc/std.h> 19#include <xdc/runtime/System.h> 20 21/* BIOS Header files */ 22#include <ti/sysbios/BIOS.h> 23#include <ti/sysbios/knl/Task.h> 24 25/* TI-RTOS Header files */ 26#include <ti/drivers/GPIO.h> 27#include <ti/drivers/PWM.h> 28 29/* Example/Board Header files */ 30#include "Board.h" 31#include "v_tm4c123gh6pm.h" 32 33#define TASKSTACKSIZE 1024 34 35extern void disable_interrupts (void ); 36extern void enable_interrupts (void ); 37 38volatile uint32_t delay_timer ; 39 40void systick_handler (void ) { 41-- delay_timer ; 42} 43 44void wait_ms (uint32_t t ) { 45 46} 47 48void blink_success (void ) { 49led_write (GREEN_LED , true); 50Task_sleep (250 ); 51led_write (GREEN_LED , false); 52} 53 54void timer0_init () { 55ROM_SysCtlPeripheralEnable (SYSCTL_PERIPH_TIMER0 ); 56ROM_TimerConfigure (TIMER0_BASE ,TIMER_CFG_PERIODIC ); 57ROM_TimerLoadSet (TIMER0_BASE ,TIMER_A ,800000 );// 100Hz 58ROM_IntEnable (INT_TIMER0A ); 59ROM_TimerIntEnable (TIMER0_BASE ,TIMER_TIMA_TIMEOUT ); 60ROM_TimerEnable (TIMER0_BASE ,TIMER_BOTH ); 61} 62 63void timer0a_handler (void ) { 64ROM_TimerIntClear (TIMER0_BASE ,TIMER_A ); 65ROM_GPIOPinWrite (GPIO_PORTA_BASE ,GPIO_PIN_7 , 66 ~ROM_GPIOPinRead (GPIO_PORTA_BASE ,GPIO_PIN_7 )); 67} 68 69void LEDtask (UArg arg0 ,UArg arg1 ) 70{ 71while (1 ) { 72blink_success (); 73printf ("left: %d\t\tright:%d\n\r" ,left_switch (),right_switch ()); 74Task_sleep (1000 ); 75 } 76} 77 78void Task_WallDetector (UArg arg0 ,UArg arg1 ) { 79// cycle through all 4 sensors 80 81// init 82SysCtlPeripheralEnable (SYSCTL_PERIPH_ADC0 ); 83 84/* 85* Test circuit Pinout 86* Emitter On/Off Gate: PD0 87* Receiver Voltage Level: PD1 88*/ 89while (1 ) 90 { 91// 1. turn on emitter 92GPIO_PORTD_DATA_R = GPIO_PORTD_DATA_R |0x0001 ; 93// 2. wait for emitter to fully turn on 94Task_sleep (1 ); 95// 3. read receiver voltage using ADC 96 97uint32_t result ; 98ADC0_PSSI_R = 0x0008 ; 99while ((ADC0_RIS_R & 0x08 )== 0 ){}; 100result = ADC0_SSFIFO3_R & 0xFFF ; 101ADC0_ISC_R = 0x0008 ; 102System_printf ("%d\n" ,result ); 103System_flush (); 104 105// 4. turn off emitter 106GPIO_PORTD_DATA_R = GPIO_PORTD_DATA_R & 0xFFFE ; 107 108Task_sleep (1000 ); 109 } 110} 111 112Task_Struct tsk0Struct ; 113Task_Struct tsk1Struct ; 114UInt8 tsk0Stack [TASKSTACKSIZE ]; 115UInt8 tsk1Stack [TASKSTACKSIZE ]; 116 117int main (void ) { 118ROM_SysCtlClockSet (SYSCTL_SYSDIV_2_5 |SYSCTL_USE_PLL |SYSCTL_XTAL_16MHZ | 119SYSCTL_OSC_MAIN ); 120ROM_SysTickEnable (); 121launchpad_init (); 122 123Board_initGeneral (); 124Board_initPWM (); 125Board_initGPIO (); 126 127timer0_init (); 128 129// Task Initialization 130Task_Params tskParams ; 131Task_Params_init (& tskParams ); 132tskParams .stackSize = TASKSTACKSIZE ; 133tskParams .stack = & tsk0Stack ; 134tskParams .arg0 = 0 ; 135 136// Task_construct(&tsk0Struct, (Task_FuncPtr)LEDtask, &tskParams, NULL); 137Task_construct (& tsk1Struct , (Task_FuncPtr )Task_WallDetector ,& tskParams ,NULL ); 138 139BIOS_start ();// This must be the very last line! 140}