aboutsummaryrefslogtreecommitdiff
path: root/AT91SAM7S256/Source/c_lowspeed.c
diff options
context:
space:
mode:
Diffstat (limited to 'AT91SAM7S256/Source/c_lowspeed.c')
-rw-r--r--AT91SAM7S256/Source/c_lowspeed.c228
1 files changed, 114 insertions, 114 deletions
diff --git a/AT91SAM7S256/Source/c_lowspeed.c b/AT91SAM7S256/Source/c_lowspeed.c
index 26851db..de0cf77 100644
--- a/AT91SAM7S256/Source/c_lowspeed.c
+++ b/AT91SAM7S256/Source/c_lowspeed.c
@@ -58,147 +58,147 @@ void cLowSpeedCtrl(void)
for (ChannelNumber = 0; ChannelNumber < NO_OF_LOWSPEED_COM_CHANNEL; ChannelNumber++)
{
//Lowspeed com is activated
- switch (IOMapLowSpeed.ChannelState[ChannelNumber])
- {
- case LOWSPEED_IDLE:
- {
- }
- break;
-
- case LOWSPEED_INIT:
- {
- if ((pMapInput->Inputs[ChannelNumber].SensorType == LOWSPEED) || (pMapInput->Inputs[ChannelNumber].SensorType == LOWSPEED_9V))
+ switch (IOMapLowSpeed.ChannelState[ChannelNumber])
+ {
+ case LOWSPEED_IDLE:
{
- if (VarsLowSpeed.TimerState == TIMER_STOPPED)
- {
- dLowSpeedStartTimer();
- VarsLowSpeed.TimerState = TIMER_RUNNING;
- }
- IOMapLowSpeed.ChannelState[ChannelNumber] = LOWSPEED_LOAD_BUFFER;
- IOMapLowSpeed.ErrorType[ChannelNumber] = LOWSPEED_NO_ERROR;
- VarsLowSpeed.ErrorCount[ChannelNumber] = 0;
- dLowSpeedInitPins(ChannelNumber);
}
- else
+ break;
+
+ case LOWSPEED_INIT:
{
- IOMapLowSpeed.ChannelState[ChannelNumber] = LOWSPEED_ERROR;
- IOMapLowSpeed.ErrorType[ChannelNumber] = LOWSPEED_CH_NOT_READY;
+ if ((pMapInput->Inputs[ChannelNumber].SensorType == LOWSPEED) || (pMapInput->Inputs[ChannelNumber].SensorType == LOWSPEED_9V))
+ {
+ if (VarsLowSpeed.TimerState == TIMER_STOPPED)
+ {
+ dLowSpeedStartTimer();
+ VarsLowSpeed.TimerState = TIMER_RUNNING;
+ }
+ IOMapLowSpeed.ChannelState[ChannelNumber] = LOWSPEED_LOAD_BUFFER;
+ IOMapLowSpeed.ErrorType[ChannelNumber] = LOWSPEED_NO_ERROR;
+ VarsLowSpeed.ErrorCount[ChannelNumber] = 0;
+ dLowSpeedInitPins(ChannelNumber);
+ }
+ else
+ {
+ IOMapLowSpeed.ChannelState[ChannelNumber] = LOWSPEED_ERROR;
+ IOMapLowSpeed.ErrorType[ChannelNumber] = LOWSPEED_CH_NOT_READY;
+ }
}
- }
- break;
+ break;
- case LOWSPEED_LOAD_BUFFER:
- {
- if ((pMapInput->Inputs[ChannelNumber].SensorType == LOWSPEED) || (pMapInput->Inputs[ChannelNumber].SensorType == LOWSPEED_9V))
+ case LOWSPEED_LOAD_BUFFER:
{
- VarsLowSpeed.OutputBuf[ChannelNumber].OutPtr = 0;
- for (VarsLowSpeed.OutputBuf[ChannelNumber].InPtr = 0; VarsLowSpeed.OutputBuf[ChannelNumber].InPtr < IOMapLowSpeed.OutBuf[ChannelNumber].InPtr; VarsLowSpeed.OutputBuf[ChannelNumber].InPtr++)
+ if ((pMapInput->Inputs[ChannelNumber].SensorType == LOWSPEED) || (pMapInput->Inputs[ChannelNumber].SensorType == LOWSPEED_9V))
{
- VarsLowSpeed.OutputBuf[ChannelNumber].Buf[VarsLowSpeed.OutputBuf[ChannelNumber].InPtr] = IOMapLowSpeed.OutBuf[ChannelNumber].Buf[IOMapLowSpeed.OutBuf[ChannelNumber].OutPtr];
- IOMapLowSpeed.OutBuf[ChannelNumber].OutPtr++;
- }
- if (dLowSpeedSendData(ChannelNumber, &VarsLowSpeed.OutputBuf[ChannelNumber].Buf[0], (VarsLowSpeed.OutputBuf[ChannelNumber].InPtr - VarsLowSpeed.OutputBuf[ChannelNumber].OutPtr)))
- {
- if (IOMapLowSpeed.InBuf[ChannelNumber].BytesToRx != 0)
+ VarsLowSpeed.OutputBuf[ChannelNumber].OutPtr = 0;
+ for (VarsLowSpeed.OutputBuf[ChannelNumber].InPtr = 0; VarsLowSpeed.OutputBuf[ChannelNumber].InPtr < IOMapLowSpeed.OutBuf[ChannelNumber].InPtr; VarsLowSpeed.OutputBuf[ChannelNumber].InPtr++)
+ {
+ VarsLowSpeed.OutputBuf[ChannelNumber].Buf[VarsLowSpeed.OutputBuf[ChannelNumber].InPtr] = IOMapLowSpeed.OutBuf[ChannelNumber].Buf[IOMapLowSpeed.OutBuf[ChannelNumber].OutPtr];
+ IOMapLowSpeed.OutBuf[ChannelNumber].OutPtr++;
+ }
+ if (dLowSpeedSendData(ChannelNumber, &VarsLowSpeed.OutputBuf[ChannelNumber].Buf[0], (VarsLowSpeed.OutputBuf[ChannelNumber].InPtr - VarsLowSpeed.OutputBuf[ChannelNumber].OutPtr)))
{
- dLowSpeedReceiveData(ChannelNumber, &VarsLowSpeed.InputBuf[ChannelNumber].Buf[0], IOMapLowSpeed.InBuf[ChannelNumber].BytesToRx);
- VarsLowSpeed.RxTimeCnt[ChannelNumber] = 0;
+ if (IOMapLowSpeed.InBuf[ChannelNumber].BytesToRx != 0)
+ {
+ dLowSpeedReceiveData(ChannelNumber, &VarsLowSpeed.InputBuf[ChannelNumber].Buf[0], IOMapLowSpeed.InBuf[ChannelNumber].BytesToRx, IOMapLowSpeed.NoRestartOnRead);
+ VarsLowSpeed.RxTimeCnt[ChannelNumber] = 0;
+ }
+ IOMapLowSpeed.ChannelState[ChannelNumber] = LOWSPEED_COMMUNICATING;
+ IOMapLowSpeed.Mode[ChannelNumber] = LOWSPEED_TRANSMITTING;
}
- IOMapLowSpeed.ChannelState[ChannelNumber] = LOWSPEED_COMMUNICATING;
- IOMapLowSpeed.Mode[ChannelNumber] = LOWSPEED_TRANSMITTING;
- }
+ else
+ {
+ IOMapLowSpeed.ChannelState[ChannelNumber] = LOWSPEED_ERROR;
+ IOMapLowSpeed.ErrorType[ChannelNumber] = LOWSPEED_CH_NOT_READY;
+ }
+ }
else
{
IOMapLowSpeed.ChannelState[ChannelNumber] = LOWSPEED_ERROR;
IOMapLowSpeed.ErrorType[ChannelNumber] = LOWSPEED_CH_NOT_READY;
}
}
- else
- {
- IOMapLowSpeed.ChannelState[ChannelNumber] = LOWSPEED_ERROR;
- IOMapLowSpeed.ErrorType[ChannelNumber] = LOWSPEED_CH_NOT_READY;
- }
- }
- break;
+ break;
- case LOWSPEED_COMMUNICATING:
- {
- if ((pMapInput->Inputs[ChannelNumber].SensorType == LOWSPEED) || (pMapInput->Inputs[ChannelNumber].SensorType == LOWSPEED_9V))
+ case LOWSPEED_COMMUNICATING:
{
- if (IOMapLowSpeed.Mode[ChannelNumber] == LOWSPEED_TRANSMITTING)
- {
- Temp = dLowSpeedComTxStatus(ChannelNumber); // Returns 0x00 if not done, 0x01 if success, 0xFF if error
-
- if (Temp == LOWSPEED_COMMUNICATION_SUCCESS)
- {
- if (IOMapLowSpeed.InBuf[ChannelNumber].BytesToRx != 0)
+ if ((pMapInput->Inputs[ChannelNumber].SensorType == LOWSPEED) || (pMapInput->Inputs[ChannelNumber].SensorType == LOWSPEED_9V))
+ {
+ if (IOMapLowSpeed.Mode[ChannelNumber] == LOWSPEED_TRANSMITTING)
+ {
+ Temp = dLowSpeedComTxStatus(ChannelNumber); // Returns 0x00 if not done, 0x01 if success, 0xFF if error
+
+ if (Temp == LOWSPEED_COMMUNICATION_SUCCESS)
+ {
+ if (IOMapLowSpeed.InBuf[ChannelNumber].BytesToRx != 0)
+ {
+ IOMapLowSpeed.Mode[ChannelNumber] = LOWSPEED_RECEIVING;
+ }
+ else
+ {
+ IOMapLowSpeed.Mode[ChannelNumber] = LOWSPEED_DATA_RECEIVED;
+ IOMapLowSpeed.ChannelState[ChannelNumber] = LOWSPEED_DONE;
+ }
+ }
+ if (Temp == LOWSPEED_COMMUNICATION_ERROR)
+ {
+ //ERROR in Communication, No ACK received from SLAVE, retry send data 3 times!
+ VarsLowSpeed.ErrorCount[ChannelNumber]++;
+ if (VarsLowSpeed.ErrorCount[ChannelNumber] > MAX_RETRY_TX_COUNT)
+ {
+ IOMapLowSpeed.ChannelState[ChannelNumber] = LOWSPEED_ERROR;
+ IOMapLowSpeed.ErrorType[ChannelNumber] = LOWSPEED_TX_ERROR;
+ }
+ else
+ {
+ IOMapLowSpeed.ChannelState[ChannelNumber] = LOWSPEED_LOAD_BUFFER;
+ }
+ }
+ }
+ if (IOMapLowSpeed.Mode[ChannelNumber] == LOWSPEED_RECEIVING)
+ {
+ VarsLowSpeed.RxTimeCnt[ChannelNumber]++;
+ if (VarsLowSpeed.RxTimeCnt[ChannelNumber] > LOWSPEED_RX_TIMEOUT)
{
- IOMapLowSpeed.Mode[ChannelNumber] = LOWSPEED_RECEIVING;
+ IOMapLowSpeed.ChannelState[ChannelNumber] = LOWSPEED_ERROR;
+ IOMapLowSpeed.ErrorType[ChannelNumber] = LOWSPEED_RX_ERROR;
}
- else
+ Temp = dLowSpeedComRxStatus(ChannelNumber);
+ if (Temp == LOWSPEED_COMMUNICATION_SUCCESS)
{
+ for (VarsLowSpeed.InputBuf[ChannelNumber].OutPtr = 0; VarsLowSpeed.InputBuf[ChannelNumber].OutPtr < IOMapLowSpeed.InBuf[ChannelNumber].BytesToRx; VarsLowSpeed.InputBuf[ChannelNumber].OutPtr++)
+ {
+ IOMapLowSpeed.InBuf[ChannelNumber].Buf[IOMapLowSpeed.InBuf[ChannelNumber].InPtr] = VarsLowSpeed.InputBuf[ChannelNumber].Buf[VarsLowSpeed.InputBuf[ChannelNumber].OutPtr];
+ IOMapLowSpeed.InBuf[ChannelNumber].InPtr++;
+ if (IOMapLowSpeed.InBuf[ChannelNumber].InPtr >= SIZE_OF_LSBUF)
+ {
+ IOMapLowSpeed.InBuf[ChannelNumber].InPtr = 0;
+ }
+ VarsLowSpeed.InputBuf[ChannelNumber].Buf[VarsLowSpeed.InputBuf[ChannelNumber].OutPtr] = 0;
+ }
IOMapLowSpeed.Mode[ChannelNumber] = LOWSPEED_DATA_RECEIVED;
IOMapLowSpeed.ChannelState[ChannelNumber] = LOWSPEED_DONE;
}
- }
- if (Temp == LOWSPEED_COMMUNICATION_ERROR)
- {
- //ERROR in Communication, No ACK received from SLAVE, retry send data 3 times!
- VarsLowSpeed.ErrorCount[ChannelNumber]++;
- if (VarsLowSpeed.ErrorCount[ChannelNumber] > MAX_RETRY_TX_COUNT)
- {
- IOMapLowSpeed.ChannelState[ChannelNumber] = LOWSPEED_ERROR;
- IOMapLowSpeed.ErrorType[ChannelNumber] = LOWSPEED_TX_ERROR;
- }
- else
- {
- IOMapLowSpeed.ChannelState[ChannelNumber] = LOWSPEED_LOAD_BUFFER;
- }
- }
- }
- if (IOMapLowSpeed.Mode[ChannelNumber] == LOWSPEED_RECEIVING)
- {
- VarsLowSpeed.RxTimeCnt[ChannelNumber]++;
- if (VarsLowSpeed.RxTimeCnt[ChannelNumber] > LOWSPEED_RX_TIMEOUT)
- {
- IOMapLowSpeed.ChannelState[ChannelNumber] = LOWSPEED_ERROR;
- IOMapLowSpeed.ErrorType[ChannelNumber] = LOWSPEED_RX_ERROR;
- }
- Temp = dLowSpeedComRxStatus(ChannelNumber);
- if (Temp == LOWSPEED_COMMUNICATION_SUCCESS)
- {
- for (VarsLowSpeed.InputBuf[ChannelNumber].OutPtr = 0; VarsLowSpeed.InputBuf[ChannelNumber].OutPtr < IOMapLowSpeed.InBuf[ChannelNumber].BytesToRx; VarsLowSpeed.InputBuf[ChannelNumber].OutPtr++)
+ if (Temp == LOWSPEED_COMMUNICATION_ERROR)
{
- IOMapLowSpeed.InBuf[ChannelNumber].Buf[IOMapLowSpeed.InBuf[ChannelNumber].InPtr] = VarsLowSpeed.InputBuf[ChannelNumber].Buf[VarsLowSpeed.InputBuf[ChannelNumber].OutPtr];
- IOMapLowSpeed.InBuf[ChannelNumber].InPtr++;
- if (IOMapLowSpeed.InBuf[ChannelNumber].InPtr >= SIZE_OF_LSBUF)
+ //There was and error in receiving data from the device
+ for (VarsLowSpeed.InputBuf[ChannelNumber].OutPtr = 0; VarsLowSpeed.InputBuf[ChannelNumber].OutPtr < IOMapLowSpeed.InBuf[ChannelNumber].BytesToRx; VarsLowSpeed.InputBuf[ChannelNumber].OutPtr++)
{
- IOMapLowSpeed.InBuf[ChannelNumber].InPtr = 0;
+ VarsLowSpeed.InputBuf[ChannelNumber].Buf[VarsLowSpeed.InputBuf[ChannelNumber].OutPtr] = 0;
}
- VarsLowSpeed.InputBuf[ChannelNumber].Buf[VarsLowSpeed.InputBuf[ChannelNumber].OutPtr] = 0;
- }
- IOMapLowSpeed.Mode[ChannelNumber] = LOWSPEED_DATA_RECEIVED;
- IOMapLowSpeed.ChannelState[ChannelNumber] = LOWSPEED_DONE;
+ IOMapLowSpeed.ChannelState[ChannelNumber] = LOWSPEED_ERROR;
+ IOMapLowSpeed.ErrorType[ChannelNumber] = LOWSPEED_RX_ERROR;
+ }
}
- if (Temp == LOWSPEED_COMMUNICATION_ERROR)
- {
- //There was and error in receiving data from the device
- for (VarsLowSpeed.InputBuf[ChannelNumber].OutPtr = 0; VarsLowSpeed.InputBuf[ChannelNumber].OutPtr < IOMapLowSpeed.InBuf[ChannelNumber].BytesToRx; VarsLowSpeed.InputBuf[ChannelNumber].OutPtr++)
- {
- VarsLowSpeed.InputBuf[ChannelNumber].Buf[VarsLowSpeed.InputBuf[ChannelNumber].OutPtr] = 0;
- }
- IOMapLowSpeed.ChannelState[ChannelNumber] = LOWSPEED_ERROR;
- IOMapLowSpeed.ErrorType[ChannelNumber] = LOWSPEED_RX_ERROR;
- }
- }
- }
- else
- {
- IOMapLowSpeed.ChannelState[ChannelNumber] = LOWSPEED_ERROR;
- IOMapLowSpeed.ErrorType[ChannelNumber] = LOWSPEED_CH_NOT_READY;
- }
- }
- break;
+ }
+ else
+ {
+ IOMapLowSpeed.ChannelState[ChannelNumber] = LOWSPEED_ERROR;
+ IOMapLowSpeed.ErrorType[ChannelNumber] = LOWSPEED_CH_NOT_READY;
+ }
+ }
+ break;
case LOWSPEED_ERROR:
{