Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions embedded/common/app/algorithm_t.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
/*--------------------------------------------------------------------*\
| E X T E R N A L V A R I A B L E S & F U N C T I O N S
\*--------------------------------------------------------------------*/
osMutexDef(mutexCritSection);
osMutexId mutex_id;

/*--------------------------------------------------------------------*\
| P U B L I C V A R I A B L E S D E F I N I T I O N S
Expand Down Expand Up @@ -247,8 +249,6 @@ static const OSP_Library_Version_t* version;
static ResultHandle_t _outSensorHandles[NUM_ANDROID_SENSOR_TYPE]; // Android Sensors
static ResultHandle_t _outPSensorHandles[NUM_PRIVATE_SENSOR_TYPE]; // Private Sensors

static OS_MUT mutexCritSection;

/*--------------------------------------------------------------------*\
| F O R W A R D F U N C T I O N D E C L A R A T I O N S
\*--------------------------------------------------------------------*/
Expand Down Expand Up @@ -277,12 +277,12 @@ SystemDescriptor_t gSystemDesc =
**********************************************************************/
__inline void EnterCriticalSection(void)
{
os_mut_wait( mutexCritSection, OS_WAIT_FOREVER );
osMutexWait(mutex_id,osWaitForever);
}

__inline void ExitCriticalSection(void)
{
os_mut_release( mutexCritSection );
osMutexRelease(mutex_id);
}


Expand Down Expand Up @@ -825,6 +825,9 @@ ASF_TASK void AlgorithmTask (ASF_TASK_ARG)
OSP_GetLibraryVersion(&version);
D1_printf("OSP Version: %s\r\n", version->VersionString);

/* Initialize the mutex */
mutex_id = osMutexCreate(osMutex(mutexCritSection));

OSP_Status = OSP_Initialize(&gSystemDesc);
ASF_assert_msg(OSP_STATUS_OK == OSP_Status, "OSP_Initialize Failed");
OSP_SetCalibrationConfig( 0x1); // disable rotational cal.
Expand Down Expand Up @@ -909,6 +912,7 @@ ASF_TASK void AlgorithmTask (ASF_TASK_ARG)
D1_printf("Alg-FG:!!!UNHANDLED MESSAGE:%d!!!\r\n", rcvMsg->msgId);
break;
}
ASFDeleteMessage( ALGORITHM_TASK_ID, &rcvMsg );
#ifdef DEBUG_TEST_SENSOR_SUBSCRIPTION
// Testing subscribe and unsubscribe sensors
DebugTestSensorSubscription();
Expand Down Expand Up @@ -952,6 +956,7 @@ ASF_TASK void AlgBackGndTask (ASF_TASK_ARG)
D1_printf("Alg-BG:!!!UNHANDLED MESSAGE:%d!!!\r\n", rcvMsg->msgId);
break;
}
ASFDeleteMessage( ALG_BG_TASK_ID, &rcvMsg );
}
}

Expand Down
19 changes: 15 additions & 4 deletions embedded/common/app/cmdhandler_t.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ static uint8_t SerialRead( PortInfo *pPort, int8_t *pBuff, uint16_t length, uint
uint32_t readIdx;
uint16_t bytesRead = 0;
uint8_t retVal = APP_OK;
uint16_t evtFlags = 0;
osEvent evtFlags;
evtFlags.value.v=0;

if ((pBuff == NULL) || (length == 0) || (length > RX_BUFFER_SIZE))
{
Expand All @@ -91,8 +92,18 @@ static uint8_t SerialRead( PortInfo *pPort, int8_t *pBuff, uint16_t length, uint
((pPort->rxReadIdx + 1) % RX_BUFFER_SIZE))
{
/* Wait here for ISR event */
os_evt_wait_or( UART_CMD_RECEIVE | UART_CRLF_RECEIVE, EVT_WAIT_FOREVER );
evtFlags = os_evt_get();
osThreadId myId = osThreadGetId();
while(1){
evtFlags = osSignalWait(UART_CMD_RECEIVE,200);
if (evtFlags.status == osEventTimeout){
evtFlags = osSignalWait(UART_CRLF_RECEIVE,200);
}
if (evtFlags.status == osEventSignal){
break;
}
}
osSignalClear(myId,UART_CMD_RECEIVE);
osSignalClear(myId,UART_CRLF_RECEIVE);
}
else
{
Expand All @@ -105,7 +116,7 @@ static uint8_t SerialRead( PortInfo *pPort, int8_t *pBuff, uint16_t length, uint
}
pBuff[bytesRead++] = pPort->rxBuffer[readIdx];
pPort->rxReadIdx = readIdx;
if ( evtFlags & UART_CRLF_RECEIVE )
if ( evtFlags.value.signals & UART_CRLF_RECEIVE )
{
break;
}
Expand Down
9 changes: 4 additions & 5 deletions embedded/common/app/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
/*-------------------------------------------------------------------------------------------------*\
| C O N S T A N T S & M A C R O S
\*-------------------------------------------------------------------------------------------------*/
#define OS_WAIT_NEVER 0x00 ///< Zero wait as defined by RTX
#define OS_WAIT_FOREVER 0xFFFF ///< Wait forever as defined by RTX
#define TIMER_SYS_ID 0xC0DEFEEDUL

/* Critical Section Locks */
Expand Down Expand Up @@ -130,7 +128,7 @@ typedef enum AppResultCodesTag

typedef struct AsfTimerTag
{
TimerId timerId; /**< Id of the timer - internal use */
osTimerId timerId; /**< Id of the timer - internal use */
TaskId owner; /**< Owner task that created the timer */
uint16_t ticks; /**< Timeout value in system ticks */
uint16_t userValue; /**< User defined value */
Expand All @@ -146,7 +144,7 @@ typedef osp_bool_t (*fpInputValidate_t)(uint8_t);
/* UART driver data structure */
typedef struct PortInfoTag
{
uint32_t *pBuffPool;
osPoolId pBuffPool;
#ifdef UART_DMA_ENABLE
void *pHead;
void *pTail;
Expand Down Expand Up @@ -228,7 +226,8 @@ void put_u32(const uint32_t);
void _ASFTimerStart( TaskId owner, uint16_t ref, uint16_t tick, AsfTimer *pTimer, char *_file, int _line );
osp_bool_t ASFTimerStarted ( AsfTimer *pTimer );
void _ASFKillTimer( AsfTimer *pTimer, char *_file, int _line );
void _ASFTimerExpiry ( uint16_t info, char *_file, int _line );
void _ASFTimerExpiry ( uint32_t info, char *_file, int _line );
void ASFTimerCallback(void const *argument);
void AsfInitialiseTasks ( void );

/* User instrumentation hooks */
Expand Down
20 changes: 13 additions & 7 deletions embedded/common/app/debugprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ PortInfo gDbgUartPort; //Debug information port
*/
#ifdef UART_DMA_ENABLE
# define DPRINTF_MPOOL_SIZE (DPRINTF_BUFF_SIZE + 8)
_declare_box( gMemPoolDprintf, DPRINTF_MPOOL_SIZE, MAX_DPRINTF_MESSAGES);
typedef struct TempStructForPoolDefTag
{
unsigned char uc_temp_for_pool_def[DPRINTF_MPOOL_SIZE]; //This variable is unused struct
} TempStructForPoolDef;
/* Define memory pool */
osPoolDef(gMemPoolDprintf, MAX_DPRINTF_MESSAGES, TempStructForPoolDef );
osPoolId gMemPoolDprintf;
#endif


Expand Down Expand Up @@ -143,7 +149,7 @@ void *RemoveFromList( PortInfo *pPort )
void DebugPortInit( void )
{
#if 0
_init_box( gMemPoolDprintf, sizeof(gMemPoolDprintf), DPRINTF_MPOOL_SIZE );
gMemPoolDprintf = osPoolCreate(osPool(gMemPoolDprintf));
gDbgUartPort.pBuffPool = gMemPoolDprintf;
gDbgUartPort.rxWriteIdx = 1;
gDbgUartPort.rxReadIdx = 0;
Expand Down Expand Up @@ -200,12 +206,12 @@ void RxBytesToBuff( PortInfo *pPort, uint8_t byte )
{
if (byte == '\r' || byte == '\n')
{
isr_evt_set( UART_CRLF_RECEIVE, asfTaskHandleTable[pPort->rcvTask].handle );
osSignalSet(asfTaskHandleTable[pPort->rcvTask].posThreadId,UART_CRLF_RECEIVE);
}
else
{
/* Wake up the task. */
isr_evt_set( UART_CMD_RECEIVE, asfTaskHandleTable[pPort->rcvTask].handle );
osSignalSet(asfTaskHandleTable[pPort->rcvTask].posThreadId,UART_CMD_RECEIVE);
}
}

Expand Down Expand Up @@ -233,7 +239,7 @@ void RxBytesToBuff( PortInfo *pPort, uint8_t byte )
void *GetNextBuffer( PortInfo *pPort )
{
void *pFreeBuff = RemoveFromList( pPort );
ASF_assert(_free_box( pPort->pBuffPool, pFreeBuff ) == 0); //Free the current consumed buffer
ASF_assert(osPoolFree( pPort->pBuffPool, pFreeBuff ) == 0); //Free the current consumed buffer
return pPort->pHead; //Return the current head of the list
}
#endif
Expand Down Expand Up @@ -266,7 +272,7 @@ int Print_LIPS( const char *fmt, ... )

#if defined UART_DMA_ENABLE
/* Note: Output will be truncated to allowed max size */
pNewBuff = _alloc_box(pPort->pBuffPool);
pNewBuff = osPoolAlloc(pPort->pBuffPool);
ASF_assert( pNewBuff != NULL );
pPrintBuff = M_GetBuffStart(pNewBuff);
if (pPrintBuff != NULL)
Expand Down Expand Up @@ -334,7 +340,7 @@ int _dprintf( uint8_t dbgLvl, const char *fmt, ... )

#ifdef UART_DMA_ENABLE
/* Note: Output will be truncated to allowed max size */
pNewBuff = _alloc_box(pPort->pBuffPool);
pNewBuff = osPoolAlloc(pPort->pBuffPool);
ASF_assert( pNewBuff != NULL );
if (pNewBuff != NULL)
{
Expand Down
3 changes: 1 addition & 2 deletions embedded/common/app/instrmgr_t.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ extern uint32_t gStackSize;

extern const AsfTaskInitDef C_gAsfTaskInitTable[NUMBER_OF_TASKS];
extern uint32_t gSystemRTCRefTime;
extern struct OS_TCB os_idle_TCB; //RTX internal
extern void *os_active_TCB[]; //RTX internal

extern void InitializeTasks( void );
extern uint8_t GetTaskList( uint8_t **pTaskList );
Expand Down Expand Up @@ -111,6 +109,7 @@ ASF_TASK void InstrManagerTask( ASF_TASK_ARG )

}
}
ASFDeleteMessage( INSTR_MANAGER_TASK_ID, &rcvMsg );
}
}

Expand Down
6 changes: 3 additions & 3 deletions embedded/common/app/instrmgr_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ RtcClock_t gRtcClockData;
/*-------------------------------------------------------------------------------------------------*\
| P R I V A T E C O N S T A N T S & M A C R O S
\*-------------------------------------------------------------------------------------------------*/

#define INSTR_MGR_SAMPLE_PERIOD (1000) //This is currently unused
/*-------------------------------------------------------------------------------------------------*\
| P R I V A T E T Y P E D E F I N I T I O N S
\*-------------------------------------------------------------------------------------------------*/
Expand Down Expand Up @@ -110,7 +110,7 @@ void InstrManagerUserInit( void )
{
sInitialTime = os_time;

// ASFTimerStart( INSTR_MANAGER_TASK_ID, TIMER_REF_RTC_UPDATE, TICS_PER_SEC, &sRtcUpdateTimer );
// ASFTimerStart( INSTR_MANAGER_TASK_ID, TIMER_REF_RTC_UPDATE, INSTR_MGR_SAMPLE_PERIOD, &sRtcUpdateTimer );
}


Expand All @@ -137,7 +137,7 @@ osp_bool_t InstrManagerUserHandler( MessageBuffer *pMsg )
UpdateRTC();

/* Restart timer for periodic output */
// ASFTimerStart( INSTR_MANAGER_TASK_ID, TIMER_REF_RTC_UPDATE, TICS_PER_SEC, &sRtcUpdateTimer );
// ASFTimerStart( INSTR_MANAGER_TASK_ID, TIMER_REF_RTC_UPDATE, INSTR_MGR_SAMPLE_PERIOD, &sRtcUpdateTimer );
break;

default:
Expand Down
38 changes: 27 additions & 11 deletions embedded/common/app/sensoracq_t.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ void WaitForHostSync(void);
static AsfTimer sSensorTimer = NULL_TIMER;
#endif
static AsfTimer sPressureTimer = NULL_TIMER;

/* This flag prevents data-ready messeges to be sent until
* Sensor Acquisition task is ready
*/
static uint8_t sTskRdyFlag = 0;

/*-------------------------------------------------------------------*\
| F O R W A R D F U N C T I O N D E C L A R A T I O N S
\*-------------------------------------------------------------------*/
Expand Down Expand Up @@ -333,18 +339,25 @@ void SensorControlCmdHandler(MsgSensorControlData *pData)
void SendDataReadyIndication(uint8_t sensorId, uint32_t timeStamp)
{
MessageBuffer *pSendMsg = NULLP;
if (ASFCreateMessage(MSG_SENSOR_DATA_RDY,
sizeof(MsgSensorDataRdy), &pSendMsg) == ASF_OK) {
pSendMsg->msg.msgSensorDataRdy.sensorId = sensorId;
pSendMsg->msg.msgSensorDataRdy.timeStamp = timeStamp;

if ( ASFSendMessage(SENSOR_ACQ_TASK_ID, pSendMsg) != ASF_OK ) {
D0_printf("Error sending sensoracq message for senosr id %d\r\n", sensorId);
/* Do not send a message until sensor acquisition task is ready */
if (0 != sTskRdyFlag){
if (ASFCreateMessage(MSG_SENSOR_DATA_RDY,
sizeof(MsgSensorDataRdy), &pSendMsg) == ASF_OK) {
pSendMsg->msg.msgSensorDataRdy.sensorId = sensorId;
pSendMsg->msg.msgSensorDataRdy.timeStamp = timeStamp;

if ( ASFSendMessage(SENSOR_ACQ_TASK_ID, pSendMsg) != ASF_OK ) {
D0_printf("Error sending sensoracq message for senosr id %d\r\n", sensorId);
}
} else {
D0_printf("Error creating sensoracq message for sensor id %d\r\n", sensorId);
}
} else {
D0_printf("Error creating sensoracq message for sensor id %d\r\n", sensorId);
}

/* Mag interrupt needs to be explicitly cleaned after the interrupt is read/ignored */
else if(sensorId == MAG_INPUT_SENSOR)
{
Mag_ClearDataInt();
}
}

/*******************************************************************
Expand All @@ -370,7 +383,7 @@ ASF_TASK void SensorAcqTask(ASF_TASK_ARG)
volatile uint8_t i;

#ifndef WAIT_FOR_HOST_SYNC
os_dly_wait(MSEC_TO_TICS(50)); /* Allow startup time for sensors */
osDelay(50);
#else
WaitForHostSync(); //This also allows for startup time for sensors
#endif
Expand Down Expand Up @@ -417,6 +430,8 @@ ASF_TASK void SensorAcqTask(ASF_TASK_ARG)

/* Magnetometer sensor does not re-generate interrupt if its outputs are not read. */
Mag_ClearDataInt();
/* Indicate sensor init done */
sTskRdyFlag = 1;

while (1) {
ASFReceiveMessage(SENSOR_ACQ_TASK_ID, &rcvMsg);
Expand Down Expand Up @@ -450,6 +465,7 @@ ASF_TASK void SensorAcqTask(ASF_TASK_ARG)
D2_printf("SensorAcqTask:!!!UNHANDLED MESSAGE:%d!!!\r\n", rcvMsg->msgId);
break;
}
ASFDeleteMessage( SENSOR_ACQ_TASK_ID, &rcvMsg );
}
}

Expand Down
Loading