GitLab system status is available here and here

Commit c38f0789 authored by Singaravelavan Rajesh's avatar Singaravelavan Rajesh
Browse files

Part 7 Pending Test

parent fb79abca
......@@ -2,13 +2,6 @@
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/C:/Users/sirajesh/Desktop/ECE118/ece118-lab-0/Lab0.X/Lab0EventChecker.c</file>
<file>file:/C:/Users/sirajesh/Desktop/ECE118/ece118-lab-0/Lab0.X/TemplateEventChecker.h</file>
<file>file:/C:/Users/sirajesh/Desktop/ECE118/ece118-lab-0/Lab0.X/TemplateService.c</file>
<file>file:/C:/Users/sirajesh/Desktop/ECE118/ece118-lab-0/Lab0.X/TemplateService.h</file>
<file>file:/C:/Users/sirajesh/Desktop/ECE118/ece118-lab-0/Lab0.X/Lab0ES_Main.c</file>
<file>file:/C:/Users/sirajesh/Desktop/ECE118/ece118-lab-0/Lab0.X/ES_Configure.h</file>
</group>
<group/>
</open-files>
</project-private>
$(MP_EXTRA_CC_PRE) -g -D__DEBUG -fframe-base-loclist -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -fno-common -I"." -I"../Lab0.X/" -I"../ECE118/include" -DXPRJ_default=$(CND_CONF) -legacy-libc $(COMPARISON_BUILD) -mdfp="${DFP_DIR}" C:\Users\sirajesh\Desktop\ECE118\ece118-lab-0\Lab0Part7.X\TemplateService.c
\ No newline at end of file
$(MP_EXTRA_CC_PRE) -g -x c -c -mprocessor=$(MP_PROCESSOR_OPTION) -fno-common -I"." -I"../Lab0.X/" -I"../ECE118/include" -DXPRJ_default=$(CND_CONF) -legacy-libc $(COMPARISON_BUILD) -mdfp="${DFP_DIR}" C:\Users\sirajesh\Desktop\ECE118\ece118-lab-0\Lab0Part7.X\TemplateService.c
\ No newline at end of file
......@@ -46,6 +46,16 @@ typedef enum {
/* User-defined events start here */
BATTERY_CONNECTED,
BATTERY_DISCONNECTED,
LIGHT,
DARK,
FRONT,
BACK,
FR,
FL,
BR,
BL,
NB,
NUMBEROFEVENTS,
} ES_EventTyp_t;
......@@ -62,6 +72,15 @@ static const char *EventNames[] = {
"ES_TIMERSTOPPED",
"BATTERY_CONNECTED",
"BATTERY_DISCONNECTED",
"LIGHT",
"DARK",
"FRONT",
"BACK",
"FR",
"FL",
"BR",
"BL",
"NB",
"NUMBEROFEVENTS",
};
......@@ -74,15 +93,15 @@ static const char *EventNames[] = {
/****************************************************************************/
// This is the list of event checking functions
#define EVENT_CHECK_LIST TemplateCheckBattery
#define EVENT_CHECK_LIST TemplateCheckBattery, CheckLight
/****************************************************************************/
// These are the definitions for the post functions to be executed when the
// corresponding timer expires. All 16 must be defined. If you are not using
// a timers, then you can use TIMER_UNUSED
#define TIMER_UNUSED ((pPostFunc)0)
#define TIMER0_RESP_FUNC TIMER_UNUSED
#define TIMER1_RESP_FUNC TIMER_UNUSED
#define TIMER0_RESP_FUNC PostTemplateService
#define TIMER1_RESP_FUNC PostTemplateFSM
#define TIMER2_RESP_FUNC TIMER_UNUSED
#define TIMER3_RESP_FUNC TIMER_UNUSED
#define TIMER4_RESP_FUNC TIMER_UNUSED
......@@ -105,7 +124,7 @@ static const char *EventNames[] = {
// definitions for the response functions to make it easire to check that
// the timer number matches where the timer event will be routed
#define GENERIC_NAMED_TIMER 0 /*make sure this is enabled above and posting to the correct state machine*/
#define SIMPLE_SERVICE_TIMER 0 /*make sure this is enabled above and posting to the correct state machine*/
/****************************************************************************/
......@@ -117,7 +136,7 @@ static const char *EventNames[] = {
/****************************************************************************/
// This macro determines that nuber of services that are *actually* used in
// a particular application. It will vary in value from 1 to MAX_NUM_SERVICES
#define NUM_SERVICES 2
#define NUM_SERVICES 3
/****************************************************************************/
// These are the definitions for Service 0, the lowest priority service
......@@ -148,14 +167,13 @@ static const char *EventNames[] = {
// These are the definitions for Service 2
#if NUM_SERVICES > 2
// the header file with the public fuction prototypes
#define SERV_2_HEADER "TestService.h"
// the name of the Init function
#define SERV_2_INIT TestServiceInit
// the name of the run function
#define SERV_2_RUN TestServiceRun
// How big should this services Queue be?
#define SERV_2_QUEUE_SIZE 3
#define SERV_2_HEADER "TemplateService.h"
// the name of the Init function
#define SERV_2_INIT InitTemplateService
// the name of the run function
#define SERV_2_RUN RunTemplateService
// How big should this services Queue be?
#define SERV_2_QUEUE_SIZE 3
#endif
......
This diff is collapsed.
......@@ -17,6 +17,7 @@ void main(void)
// Your hardware initialization function calls go here
Roach_Init();
ES_Timer_Init();
// now initialize the Events and Services Framework and start it running
ErrorType = ES_Initialize();
if (ErrorType == Success) {
......
......@@ -60,14 +60,20 @@
typedef enum {
InitPState,
FirstState,
SecondState,
FORWARD,
BACKWARD,
TRBACK,
TRFWD,
TR,
} TemplateFSMState_t;
static const char *StateNames[] = {
"InitPState",
"FirstState",
"SecondState",
"FORWARD",
"BACKWARD",
"TRBACK",
"TRFWD",
"TR",
};
......@@ -126,6 +132,8 @@ uint8_t PostTemplateFSM(ES_Event ThisEvent) {
* @note Remember to rename to something appropriate.
* Returns ES_NO_EVENT if the event have been "consumed."
* @author J. Edward Carryer, 2011.10.23 19:25 */
unsigned int stuck = 0;
ES_Event RunTemplateFSM(ES_Event ThisEvent) {
uint8_t makeTransition = FALSE; // use to flag transition
TemplateFSMState_t nextState; // <- need to change enum type here
......@@ -141,33 +149,69 @@ ES_Event RunTemplateFSM(ES_Event ThisEvent) {
// initial state
// now put the machine into the actual initial state
nextState = FirstState;
nextState = FORWARD;
stuck = 1;
ES_Timer_InitTimer(1, 5000);
makeTransition = TRUE;
ThisEvent.EventType = ES_NO_EVENT;
}
break;
case FirstState: // in the first state, replace this with appropriate state
if (ThisEvent.EventType == BATTERY_DISCONNECTED) {
Roach_LEDSSet(0);
nextState = FirstState;
} else if (ThisEvent.EventType == BATTERY_CONNECTED) {
Roach_LEDSSet(0xFFF);
nextState = SecondState;
case FORWARD: // in the first state, replace this with appropriate state
Roach_RightMtrSpeed(-75);
Roach_LeftMtrSpeed(-75);
Roach_LEDSSet(0);
if (ThisEvent.EventType == ES_TIMEOUT && ThisEvent.EventParam == 1) {
stuck = 0;
}
if (ThisEvent.EventType == FRONT && stuck) {
nextState = BACKWARD;
makeTransition = TRUE;
}
if (ThisEvent.EventType == FRONT && !stuck) {
ES_Timer_InitTimer(1, 500);
nextState = TRBACK;
makeTransition = TRUE;
}
break;
case SecondState:
if (ThisEvent.EventType == BATTERY_CONNECTED) {
Roach_LEDSSet(0xFFF);
nextState = SecondState;
} else if (ThisEvent.EventType == BATTERY_DISCONNECTED) {
Roach_LEDSSet(0);
nextState = FirstState;
case BACKWARD:
Roach_RightMtrSpeed(75);
Roach_LeftMtrSpeed(75);
Roach_LEDSSet(0);
if (ThisEvent.EventType == BACK) {
ES_Timer_InitTimer(1, 500);
nextState = TRFWD;
makeTransition = TRUE;
}
break;
case TRBACK:
Roach_RightMtrSpeed(75);
Roach_LeftMtrSpeed(75);
if (ThisEvent.EventType == ES_TIMEOUT && ThisEvent.EventParam == 1) {
ES_Timer_InitTimer(1, 500);
nextState = TR;
makeTransition = TRUE;
}
break;
case TRFWD:
Roach_RightMtrSpeed(-75);
Roach_LeftMtrSpeed(-75);
if (ThisEvent.EventType == ES_TIMEOUT && ThisEvent.EventParam == 1) {
ES_Timer_InitTimer(1, 500);
nextState = TR;
makeTransition = TRUE;
}
break;
case TR:
Roach_RightMtrSpeed(75);
Roach_LeftMtrSpeed(-75);
if (ThisEvent.EventType == ES_TIMEOUT && ThisEvent.EventParam == 1) {
ES_Timer_InitTimer(1, 500);
nextState = FORWARD;
makeTransition = TRUE;
}
default: // all unhandled states fall into here
break;
} // end switch on Current State
......
/*
* File: TemplateService.h
* Author: J. Edward Carryer
* Modified: Gabriel H Elkaim
*
* Template file to set up a simple service to work with the Events and Services
* Framework (ES_Framework) on the Uno32 for the CMPE-118/L class. Note that this file
* will need to be modified to fit your exact needs, and most of the names will have
* to be changed to match your code.
*
* This is provided as an example and a good place to start.
*
* Created on 23/Oct/2011
* Updated on 13/Nov/2013
*/
/*******************************************************************************
* MODULE #INCLUDE *
******************************************************************************/
#include "BOARD.h"
#include "AD.h"
#include "roach.h"
#include "ES_Configure.h"
#include "ES_Framework.h"
#include "TemplateService.h"
#include <stdio.h>
/*******************************************************************************
* MODULE #DEFINES *
******************************************************************************/
#define BATTERY_DISCONNECT_THRESHOLD 175
#define TIMER_0_TICKS 5
/*******************************************************************************
* PRIVATE FUNCTION PROTOTYPES *
******************************************************************************/
/* Prototypes for private functions for this machine. They should be functions
relevant to the behavior of this state machine */
/*******************************************************************************
* PRIVATE MODULE VARIABLES *
******************************************************************************/
/* You will need MyPriority and maybe a state variable; you may need others
* as well. */
static uint8_t MyPriority;
/*******************************************************************************
* PUBLIC FUNCTIONS *
******************************************************************************/
/**
* @Function InitTemplateService(uint8_t Priority)
* @param Priority - internal variable to track which event queue to use
* @return TRUE or FALSE
* @brief This will get called by the framework at the beginning of the code
* execution. It will post an ES_INIT event to the appropriate event
* queue, which will be handled inside RunTemplateService function. Remember
* to rename this to something appropriate.
* Returns TRUE if successful, FALSE otherwise
* @author J. Edward Carryer, 2011.10.23 19:25 */
uint8_t InitTemplateService(uint8_t Priority) {
ES_Event ThisEvent;
MyPriority = Priority;
// in here you write your initialization code
// this includes all hardware and software initialization
// that needs to occur.
// post the initial transition event
ThisEvent.EventType = ES_INIT;
ES_Timer_InitTimer(SIMPLE_SERVICE_TIMER, TIMER_0_TICKS);
if (ES_PostToService(MyPriority, ThisEvent) == TRUE) {
return TRUE;
} else {
return FALSE;
}
}
/**
* @Function PostTemplateService(ES_Event ThisEvent)
* @param ThisEvent - the event (type and param) to be posted to queue
* @return TRUE or FALSE
* @brief This function is a wrapper to the queue posting function, and its name
* will be used inside ES_Configure to point to which queue events should
* be posted to. Remember to rename to something appropriate.
* Returns TRUE if successful, FALSE otherwise
* @author J. Edward Carryer, 2011.10.23 19:25 */
uint8_t PostTemplateService(ES_Event ThisEvent) {
return ES_PostToService(MyPriority, ThisEvent);
}
/**
* @Function RunTemplateService(ES_Event ThisEvent)
* @param ThisEvent - the event (type and param) to be responded.
* @return Event - return event (type and param), in general should be ES_NO_EVENT
* @brief This function is where you implement the whole of the service,
* as this is called any time a new event is passed to the event queue.
* @note Remember to rename to something appropriate.
* Returns ES_NO_EVENT if the event have been "consumed."
* @author J. Edward Carryer, 2011.10.23 19:25 */
uint16_t BumperArray[25];
unsigned int i = 0;
static ES_EventTyp_t lastEvent = NB;
ES_Event RunTemplateService(ES_Event ThisEvent) {
ES_Event ReturnEvent;
ReturnEvent.EventType = lastEvent; // assume no errors
/********************************************
in here you write your service code
*******************************************/
ES_EventTyp_t curEvent = lastEvent;
ES_Event thisEvent;
uint16_t currentBumper = Roach_ReadBumpers();
switch (ThisEvent.EventType) {
case ES_INIT:
// No hardware initialization or single time setups, those
// go in the init function above.
//
// This section is used to reset service for some reason
break;
case ES_TIMERACTIVE:
case ES_TIMERSTOPPED:
break;
case ES_TIMEOUT:
ES_Timer_InitTimer(SIMPLE_SERVICE_TIMER, TIMER_0_TICKS);
BumperArray[i] = currentBumper;
i++;
if (i == 25) {
i = 0;
unsigned char same = 0;
for (int j = 0; j < 25; j++) {
if (BumperArray[j] != BumperArray[0]) {
same = 0;
break;
} else {
same = 1;
}
}
if (same) {
if (BumperArray[0] == 0b0011)
curEvent = FRONT;
if (BumperArray[0] == 0b1100)
curEvent = BACK;
if (BumperArray[0] == 0b0001)
curEvent = FL;
if (BumperArray[0] == 0b0010)
curEvent = FR;
if (BumperArray[0] == 0b0100)
curEvent = BL;
if (BumperArray[0] == 0b1000)
curEvent = BR;
if (BumperArray[0] == 0b0000)
curEvent = NB;
if (curEvent != lastEvent) { // check for change from last time
thisEvent.EventType = curEvent;
thisEvent.EventParam = BumperArray[0];
lastEvent = curEvent; // update history
ReturnEvent = thisEvent;
PostTemplateFSM(ReturnEvent);
//PostTemplateService(ReturnEvent);
}
}
#ifndef SIMPLESERVICE_TEST // keep this as is for test harness
//PostGenericService(ReturnEvent);
#endif
}
break;
#ifdef SIMPLESERVICE_TEST // keep this as is for test harness
default:
printf("\r\nEvent: %s\tParam: 0x%X",
EventNames[ThisEvent.EventType], ThisEvent.EventParam);
break;
#endif
}
return ReturnEvent;
}
/*******************************************************************************
* PRIVATE FUNCTIONs *
******************************************************************************/
/*
* File: TemplateService.h
* Author: J. Edward Carryer
* Modified: Gabriel H Elkaim
*
* Template file to set up a simple service to work with the Events and Services
* Framework (ES_Framework) on the Uno32 for the CMPE-118/L class. Note that this file
* will need to be modified to fit your exact needs, and most of the names will have
* to be changed to match your code.
*
* This is provided as an example and a good place to start.
*
* Created on 23/Oct/2011
* Updated on 13/Nov/2013
*/
#ifndef TemplateService_H // <- This should be changed to your own guard on both
#define TemplateService_H // of these lines
/*******************************************************************************
* PUBLIC #INCLUDES *
******************************************************************************/
#include "inttypes.h"
#include "ES_Configure.h" // defines ES_Event, INIT_EVENT, ENTRY_EVENT, and EXIT_EVENT
#include "ES_Events.h"
/*******************************************************************************
* PUBLIC #DEFINES *
******************************************************************************/
/*******************************************************************************
* PUBLIC TYPEDEFS *
******************************************************************************/
/*******************************************************************************
* PUBLIC FUNCTION PROTOTYPES *
******************************************************************************/
/**
* @Function InitTemplateService(uint8_t Priority)
* @param Priority - internal variable to track which event queue to use
* @return TRUE or FALSE
* @brief This will get called by the framework at the beginning of the code
* execution. It will post an ES_INIT event to the appropriate event
* queue, which will be handled inside RunTemplateService function. Remember
* to rename this to something appropriate.
* Returns TRUE if successful, FALSE otherwise
* @author J. Edward Carryer, 2011.10.23 19:25 */
uint8_t InitTemplateService(uint8_t Priority);
/**
* @Function PostTemplateService(ES_Event ThisEvent)
* @param ThisEvent - the event (type and param) to be posted to queue
* @return TRUE or FALSE
* @brief This function is a wrapper to the queue posting function, and its name
* will be used inside ES_Configure to point to which queue events should
* be posted to. Remember to rename to something appropriate.
* Returns TRUE if successful, FALSE otherwise
* @author J. Edward Carryer, 2011.10.23 19:25 */
uint8_t PostTemplateService(ES_Event ThisEvent);
/**
* @Function RunTemplateService(ES_Event ThisEvent)
* @param ThisEvent - the event (type and param) to be responded.
* @return Event - return event (type and param), in general should be ES_NO_EVENT
* @brief This function is where you implement the whole of the service,
* as this is called any time a new event is passed to the event queue.
* @note Remember to rename to something appropriate.
* Returns ES_NO_EVENT if the event have been "consumed."
* @author J. Edward Carryer, 2011.10.23 19:25 */
ES_Event RunTemplateService(ES_Event ThisEvent);
#endif /* TemplateService_H */
build/default/production/TemplateService.o: TemplateService.c \
../ECE118/include/BOARD.h ../ECE118/include/AD.h \
../ECE118/include/roach.h ES_Configure.h \
../ECE118/include/ES_Framework.h ../ECE118/include/ES_Events.h \
ES_Configure.h ../ECE118/include/ES_Timers.h \
../ECE118/include/ES_CheckEvents.h ../ECE118/include/ES_General.h \
../ECE118/include/ES_KeyboardInput.h ../ECE118/include/ES_LookupTables.h \
../ECE118/include/ES_Port.h ../ECE118/include/ES_PostList.h \
../ECE118/include/ES_PriorTables.h ../ECE118/include/ES_Queue.h \
../ECE118/include/ES_ServiceHeaders.h TemplateFSM.h ES_Configure.h \
TemplateService.h ../ECE118/include/ES_Events.h \
../ECE118/include/ES_TattleTale.h TemplateService.h
../ECE118/include/BOARD.h:
../ECE118/include/AD.h:
../ECE118/include/roach.h:
ES_Configure.h:
../ECE118/include/ES_Framework.h:
../ECE118/include/ES_Events.h:
ES_Configure.h:
../ECE118/include/ES_Timers.h:
../ECE118/include/ES_CheckEvents.h:
../ECE118/include/ES_General.h:
../ECE118/include/ES_KeyboardInput.h:
../ECE118/include/ES_LookupTables.h:
../ECE118/include/ES_Port.h:
../ECE118/include/ES_PostList.h:
../ECE118/include/ES_PriorTables.h:
../ECE118/include/ES_Queue.h:
../ECE118/include/ES_ServiceHeaders.h:
TemplateFSM.h:
ES_Configure.h:
TemplateService.h:
../ECE118/include/ES_Events.h:
../ECE118/include/ES_TattleTale.h:
TemplateService.h:
......@@ -9,6 +9,7 @@ build/default/production/_ext/256631604/TemplateES_Main.o: \
../ECE118/include/ES_Port.h ../ECE118/include/ES_PostList.h \
../ECE118/include/ES_PriorTables.h ../ECE118/include/ES_Queue.h \
../ECE118/include/ES_ServiceHeaders.h TemplateFSM.h ES_Configure.h \
TemplateService.h ../ECE118/include/ES_Events.h \
../ECE118/include/ES_TattleTale.h
../ECE118/include/BOARD.h:
......@@ -47,4 +48,8 @@ TemplateFSM.h:
ES_Configure.h:
TemplateService.h:
../ECE118/include/ES_Events.h:
../ECE118/include/ES_TattleTale.h:
......@@ -8,6 +8,7 @@ build/default/production/_ext/256631604/TemplateFSM.o: \
../ECE118/include/ES_Port.h ../ECE118/include/ES_PostList.h \
../ECE118/include/ES_PriorTables.h ../ECE118/include/ES_Queue.h \
../ECE118/include/ES_ServiceHeaders.h TemplateFSM.h ES_Configure.h \
TemplateService.h ../ECE118/include/ES_Events.h \
../ECE118/include/ES_TattleTale.h ../ECE118/include/roach.h \
../ECE118/include/BOARD.h \
C:/Users/sirajesh/Desktop/ECE118/ece118-lab-0/Lab0Part7.X/TemplateFSM.h
......@@ -44,6 +45,10 @@ TemplateFSM.h:
ES_Configure.h:
TemplateService.h:
../ECE118/include/ES_Events.h:
../ECE118/include/ES_TattleTale.h:
../ECE118/include/roach.h:
......