aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Embedded_SW/Embedded/Modules/Control
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Embedded_SW/Embedded/Modules/Control')
-rw-r--r--Software/Embedded_SW/Embedded/Modules/Control/DriverWithCallbackExample.c7
-rw-r--r--Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c165
-rw-r--r--Software/Embedded_SW/Embedded/Modules/Control/control.c75
-rw-r--r--Software/Embedded_SW/Embedded/Modules/Control/control.h9
4 files changed, 198 insertions, 58 deletions
diff --git a/Software/Embedded_SW/Embedded/Modules/Control/DriverWithCallbackExample.c b/Software/Embedded_SW/Embedded/Modules/Control/DriverWithCallbackExample.c
new file mode 100644
index 000000000..216779f8b
--- /dev/null
+++ b/Software/Embedded_SW/Embedded/Modules/Control/DriverWithCallbackExample.c
@@ -0,0 +1,7 @@
+/*
+ * DriverWithCallbackExample.c
+ *
+ * Created on: 11 במרץ 2018
+ * Author: shlomo
+ */
+uint32_t
diff --git a/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c
new file mode 100644
index 000000000..6f3a59852
--- /dev/null
+++ b/Software/Embedded_SW/Embedded/Modules/Control/MillisecTask.c
@@ -0,0 +1,165 @@
+/************************************************************************************************************************
+ * Millisec.c
+ * Millisec module
+ *
+ * The millisec task is called once every 1 millisecond to gather data from the FPGA crucial modules,
+ * so it will be ready for the Millisec operations. it is called 300 (TBD, configurable)
+ * microsecond before the Millisec task, so that the data will be ready for the Millisec handling.
+ * the ,millisecond task holds the pointer to a double buffer of results, so that the Millisec will handle the
+ * most updated data, without disturbing data gathering
+ *
+ **************************************************************************************************************************/
+
+////////////////////////////////State machine operation////////////////////////////////////
+//the state machine operation is used to operate in runtime correct profile flow execution
+//by recieved esign flow of the user from the UI
+///////////////////////////////////////////////////////////////////////////////////////////
+#include "include.h"
+#include "Modules/General/GeneralHardware.h"
+
+#include <driverlib/timer.h>
+#include <inc/hw_ints.h>
+
+#include "drivers/adc_sampling/adc.h"
+#include "control.h"
+/******************** Definitions ********************************************/
+#define INVALID_MSG_ID 0xFFFF
+#define MAX_TANGO_CONTROL_DEVICES 200
+/******************** STRUCTURES AND ENUMs ********************************************/
+
+typedef enum
+{
+ OneMillisec,
+}nillisecMessages;
+
+typedef struct MillisecMessage{
+ uint16_t messageId;
+ uint16_t msglen;
+ uint32_t tick;
+ uint8_t messageData[20];
+}MillisecMessageStruc;
+/******************** GLOBAL PARAMETERS ********************************************/
+Mailbox_Handle MillisecMsgQ = NULL;
+bool MillisecRestart;
+static GateMutex_Handle gateMillisecDB;
+
+uint32_t MillisecDatalog[MAX_TANGO_CONTROL_DEVICES];
+uint32_t Millisec_timerBase = TIMER1_BASE; //Timer handle
+/******************** Functions ********************************************/
+
+//**********************************************************************
+/******************** CODE ********************************************/
+//**********************************************************************
+
+void MillisecInit(void)
+{
+ Error_Block eb;
+
+ MillisecMsgQ = Mailbox_create(sizeof(MillisecMessageStruc), 20, NULL,NULL);
+
+ MillisecRestart = false;
+
+ memset(MillisecDatalog,0,sizeof(uint32_t)*MAX_TANGO_CONTROL_DEVICES);
+
+
+ gateMillisecDB = GateMutex_create(NULL, &eb);
+ if (gateMillisecDB == NULL)
+ {
+ System_abort("Could not create USB Wait gate");
+ }
+
+ ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
+ ROM_TimerConfigure(Millisec_timerBase, TIMER_CFG_PERIODIC); // 32 bits Timer
+ //TimerIntRegister(Millisec_timerBase, TIMER_A, Timer0Isr); // Registering isr
+ ROM_TimerEnable(Millisec_timerBase, TIMER_A);
+ ROM_IntEnable(INT_TIMER1A);
+ ROM_TimerIntEnable(Millisec_timerBase, TIMER_TIMA_TIMEOUT);
+
+ ADCAcquireInit();
+
+ return;
+}
+void MillisecStop(void)
+{
+ MillisecRestart = false;
+ ADCAcquireStop();
+}
+
+void MillisecStart(void)
+{
+ MillisecRestart = true;
+ ROM_TimerLoadSet(Millisec_timerBase, TIMER_A,120000/*one millisecond*/);
+ ADCAcquireStart(0,1);
+}
+
+
+void OneMilliSecondMillisecInterrupt(UArg arg0)
+{
+ MillisecMessageStruc Message;
+ bool retcode = false;
+ ROM_IntMasterDisable();
+ if (MillisecRestart == true)
+ {
+ ROM_TimerLoadSet(Millisec_timerBase, TIMER_A,120000/*one millisecond*/);
+ }
+ else
+ ROM_TimerDisable(Millisec_timerBase,TIMER_A);
+
+ //trigger the ADC collection - check and set priorities to make sure handling timing is correct.
+ //we might want to call it from the task, afetr execution of other taks!!!
+ ADC_TriggerCollection();
+ //send message to the Millisec task
+ Message.messageId = OneMillisec;
+ Message.tick = UsersysTickGet();
+ Message.msglen = sizeof(MillisecMessageStruc);
+ if (MillisecMsgQ != NULL)
+ retcode = Mailbox_post(MillisecMsgQ , &Message, BIOS_NO_WAIT);
+
+ ROM_TimerIntClear(Millisec_timerBase, TIMER_TIMA_TIMEOUT); // Clear the timer interrupt
+ //
+ // Enable all interrupts.
+ //
+ ROM_IntMasterEnable();
+ return ;
+}
+
+uint32_t MillisecLoop(uint32_t tick)
+{
+ //call all modules Millisec functions
+ //test dancers and speed encoders
+ //check all callback units (state machine waiting for completion of a change)
+ bool Ten_msTick, Hundred_msTick, Onesecond_Tick;
+ Ten_msTick = (tick%eTenMilliSecond == 0) ?true:false;
+ Hundred_msTick = (tick%eHunderdMillisecond == 0) ?true:false;
+ Onesecond_Tick = (tick%eOneSecond == 0) ?true:false;
+
+ //gather data from FPGA
+ return OK;
+}
+/******************************************************************************
+ * ======== messageTsk ========
+ * Task for this function is created statically. See the project's .cfg file.
+ * this message task is created statically in system initialization,
+ ******************************************************************************/
+void MillisecTask(UArg arg0, UArg arg1)
+{
+ MillisecMessageStruc Message;
+ //char str[60];
+ //uint16_t length;
+ //Clock_setTimeout(HostKAClock, 1000);
+ //Clock_start(HostKAClock);
+ MillisecInit();
+
+ while(1)
+ {
+ Mailbox_pend(MillisecMsgQ , &Message, BIOS_WAIT_FOREVER);
+ switch (Message.messageId)
+ {
+ case OneMillisec:
+ MillisecLoop(Message.tick);
+ break;
+ default:
+ break;
+ }
+ }
+}
diff --git a/Software/Embedded_SW/Embedded/Modules/Control/control.c b/Software/Embedded_SW/Embedded/Modules/Control/control.c
index 8f389855e..abc61972d 100644
--- a/Software/Embedded_SW/Embedded/Modules/Control/control.c
+++ b/Software/Embedded_SW/Embedded/Modules/Control/control.c
@@ -56,13 +56,6 @@
#define INVALID_MSG_ID 0xFFFF
#define MAX_TANGO_CONTROL_DEVICES 200
/******************** STRUCTURES AND ENUMs ********************************************/
-typedef struct
-{
- uint32_t PartId; // the identity of the inspected/controlled part in the Devices enum.
- DeviceDataFunction Callback;
- uint32_t lastStatus;
-}DriverDeviceStruc;
-DriverDeviceStruc DevicesArray[MAX_PORT_ENUM];
typedef struct
@@ -73,6 +66,7 @@ typedef struct
DataReadCBFunction ControlDataReadPtr;
ControlCBFunction ControlCallbackPtr;
CTRL_TIMING_ENUM ControlTiming;
+ uint32_t lastStatus;
}ControlDeviceStruc;
typedef enum
@@ -86,6 +80,9 @@ typedef struct ControlMessage{
uint32_t tick;
uint8_t messageData[20];
}ControlMessageStruc;
+
+int ControlPhaseDelay = 300; //the control task enters only after data gathering in the millisecond task is finished.
+//this parameters defines how many microseconds in the delay. it is used only on starting the control loop on the first time
/******************** GLOBAL PARAMETERS ********************************************/
Mailbox_Handle ControlMsgQ = NULL;
bool ControlRestart;
@@ -100,6 +97,12 @@ void OneMilliSecondFunction(UArg arg0);
//**********************************************************************
/******************** CODE ********************************************/
//**********************************************************************
+uint32_t TemplateDataReadCBFunction (uint32_t deviceID, uint32_t Parameter)
+{
+ return 0;
+}
+
+
void ControlInit(void)
{
@@ -114,12 +117,6 @@ void ControlInit(void)
for (Device_i = 0; Device_i < MAX_TANGO_CONTROL_DEVICES; Device_i++)
{
- DevicesArray[Device_i].Callback = NULL;
- DevicesArray[Device_i].lastStatus = ERROR;
- }
-
- for (Device_i = 0; Device_i < MAX_TANGO_CONTROL_DEVICES; Device_i++)
- {
ControlArray[Device_i].ControlActive = false;
ControlArray[Device_i].ControlCallbackPtr = NULL;
ControlArray[Device_i].ControlDataReadPtr = NULL;
@@ -151,7 +148,7 @@ void ControlStop(void)
void ControlStart(void)
{
ControlRestart = true;
- ROM_TimerLoadSet(Control_timerBase, TIMER_BOTH,120000/*one millisecond*/);
+ ROM_TimerLoadSet(Control_timerBase, TIMER_A,120000+(ControlPhaseDelay*120)/*one millisecond*/);
ADCAcquireStart(0,1);
}
@@ -163,22 +160,20 @@ void ControlStart(void)
* both these callbacks can be removed. if a new call is arriving, it invalidates the previous one (no dual control or data)
*
***************************************************************************************************************************************************/
-int AddControlCallback(uint32_t deviceId, ControlCBFunction Callback, CTRL_TIMING_ENUM CtrlFrequency )
+int AddControlCallback(uint32_t deviceId, ControlCBFunction Callback, CTRL_TIMING_ENUM CtrlFrequency, DataReadCBFunction DriverfPtr, uint32_t Parameter )
{
assert(deviceId < MAX_TANGO_CONTROL_DEVICES);
assert(Callback);
+ assert(DriverfPtr);
unsigned int key;
- if(ControlArray[deviceId].ControlDataReadPtr == NULL)
- {
- LOG_ERROR (deviceId, "No dataread function for device");
- return ERROR;
- }
key = GateMutex_enter(gateControlDB);
ControlArray[deviceId].ControlTiming = CtrlFrequency;
ControlArray[deviceId].ControlCallbackPtr = Callback;
ControlArray[deviceId].ControlActive = true;
+ ControlArray[deviceId].ControlDataReadPtr = DriverfPtr;
+ ControlArray[deviceId].Parameter = Parameter;
GateMutex_leave(gateControlDB, key);
return OK;
@@ -194,6 +189,7 @@ int RemoveControlCallback(uint32_t deviceId , ControlCBFunction Callback)
key = GateMutex_enter(gateControlDB);
ControlArray[deviceId].ControlTiming = eNoControl;
ControlArray[deviceId].ControlCallbackPtr = NULL;
+ ControlArray[deviceId].ControlDataReadPtr = NULL;
ControlArray[deviceId].ControlActive = false;
GateMutex_leave(gateControlDB, key);
return OK;
@@ -203,41 +199,18 @@ int RemoveControlCallback(uint32_t deviceId , ControlCBFunction Callback)
}
-int RegisterDevice(uint32_t deviceId, DataReadCBFunction Callback, uint32_t Parameter)
-{
- assert(deviceId < MAX_TANGO_CONTROL_DEVICES);
- assert(Callback);
- unsigned int key;
- key = GateMutex_enter(gateControlDB);
- ControlArray[deviceId].Parameter = Parameter;
- ControlArray[deviceId].ControlDataReadPtr = Callback;
- GateMutex_leave(gateControlDB, key);
- return OK;
-
-}
-int UnRegisterDevice(uint32_t deviceId, DataReadCBFunction Callback )
-{
- assert(deviceId < MAX_TANGO_CONTROL_DEVICES);
- unsigned int key;
- if (Callback == ControlArray[deviceId].ControlDataReadPtr)
- {
- key = GateMutex_enter(gateControlDB);
- ControlArray[deviceId].Parameter = 0;
- ControlArray[deviceId].ControlDataReadPtr = NULL;
- ControlDatalog[deviceId] = 0;
- GateMutex_leave(gateControlDB, key);
- return OK;
- }
- else
- return ERROR;
-
-}
void OneMilliSecondControlInterrupt(UArg arg0)
{
ControlMessageStruc Message;
bool retcode = false;
ROM_IntMasterDisable();
+ if (ControlRestart == true)
+ {
+ ROM_TimerLoadSet(Control_timerBase, TIMER_A,120000/*one millisecond*/);
+ }
+ else
+ ROM_TimerDisable(Control_timerBase, TIMER_A);
//trigger the ADC collection - check and set priorities to make sure handling timing is correct.
//we might want to call it from the task, afetr execution of other taks!!!
@@ -248,10 +221,6 @@ void OneMilliSecondControlInterrupt(UArg arg0)
Message.msglen = sizeof(ControlMessageStruc);
if (ControlMsgQ != NULL)
retcode = Mailbox_post(ControlMsgQ , &Message, BIOS_NO_WAIT);
- if (ControlRestart == true)
- {
- ROM_TimerLoadSet(Control_timerBase, TIMER_BOTH,120000/*one millisecond*/);
- }
ROM_TimerIntClear(Control_timerBase, TIMER_TIMA_TIMEOUT); // Clear the timer interrupt
//
diff --git a/Software/Embedded_SW/Embedded/Modules/Control/control.h b/Software/Embedded_SW/Embedded/Modules/Control/control.h
index ab259993a..292bbeb82 100644
--- a/Software/Embedded_SW/Embedded/Modules/Control/control.h
+++ b/Software/Embedded_SW/Embedded/Modules/Control/control.h
@@ -8,7 +8,7 @@
///////////////////////////////////////////////////////////////////////////////////////////
#include "include.h"
-typedef uint32_t (* DeviceDataFunction)(uint32_t deviceID, uint32_t *Value);
+//typedef uint32_t (* DeviceDataFunction)(uint32_t deviceID, uint32_t *Value);
typedef uint32_t (* ControlCBFunction)(uint32_t deviceID, uint32_t ReadValue);
typedef uint32_t (* DataReadCBFunction)(uint32_t deviceID, uint32_t Parameter);
typedef enum {
@@ -23,8 +23,7 @@ typedef enum {
void ControlInit(void);
void ControlStop(void);
void ControlStart(void);
-int AddControlCallback(uint32_t deviceID, ControlCBFunction Callback, CTRL_TIMING_ENUM CtrlFrequency );
-int RemoveControlCallback(uint32_t deviceID, ControlCBFunction Callback );
-int RegisterDevice(uint32_t deviceID, DataReadCBFunction Callback, uint32_t Parameter);
-int UnRegisterDevice(uint32_t deviceID, DataReadCBFunction Callback );
+int AddControlCallback(uint32_t deviceId, ControlCBFunction Callback, CTRL_TIMING_ENUM CtrlFrequency, DataReadCBFunction DriverfPtr, uint32_t Parameter );
+int RemoveControlCallback(uint32_t deviceId, ControlCBFunction Callback );
+uint32_t TemplateDataReadCBFunction (uint32_t deviceId, uint32_t Parameter);