uint8_t flags; /* Flags */
} tBuffer;
-/** Buffer used for sending to SCI */
-tBuffer outBuffer;
-/** Buffer used for receiving from SCI */
-tBuffer inBuffer;
-
#endif
void drv_sci_init()
{
- // Initialize buffers
- outBuffer.buf = xQueueCreate(MAX_BUFFER_LEN, sizeof(uint8_t));
- outBuffer.mutex = xSemaphoreCreateMutex();
- outBuffer.flags = 0;
- inBuffer.buf = xQueueCreate(MAX_BUFFER_LEN, sizeof(uint8_t));
- inBuffer.mutex = xSemaphoreCreateMutex();
- outBuffer.flags = 0;
-
- // Initialize hal
- spi_tms570_init();
-
// Low level init
sciInit();
}
-
+/** Declared in ti_drv_sci.c */
+extern tBuffer sciOutBuffer;
+extern tBuffer sciInBuffer;
int8_t drv_sci_send(uint32_t length, uint8_t *data)
{
- if(outBuffer.buf == NULL) {
+ if(sciOutBuffer.buf == NULL) {
return FAILURE;
}
portBASE_TYPE ret = pdPASS;
- xSemaphoreTake(outBuffer.mutex, portMAX_DELAY);
+ xSemaphoreTake(sciOutBuffer.mutex, portMAX_DELAY);
while(length-- > 0) {
- if(!outBuffer.flags & BUF_TRANSFER_IN_PROGRESS) {
+ if(!sciOutBuffer.flags & BUF_TRANSFER_IN_PROGRESS) {
taskENTER_CRITICAL();
- if (!outBuffer.flags & BUF_TRANSFER_IN_PROGRESS) {
- outBuffer.flags |= BUF_TRANSFER_IN_PROGRESS;
+ if (!sciOutBuffer.flags & BUF_TRANSFER_IN_PROGRESS) {
+ sciOutBuffer.flags |= BUF_TRANSFER_IN_PROGRESS;
sciREG->SETINT = SCI_TX_INT; // Start new transfer by sending first byte
sciREG->TD = *data++;
}
continue;
}
- ret = xQueueSend(outBuffer.buf, (void*)data++, portMAX_DELAY);
+ ret = xQueueSend(sciOutBuffer.buf, (void*)data++, portMAX_DELAY);
if(ret != pdPASS) {
return FAILURE;
}
}
- xSemaphoreGive(outBuffer.mutex);
+ xSemaphoreGive(sciOutBuffer.mutex);
return SUCCESS;
}
adcInit();
linInit();
emif_SDRAMInit();
+ spi_tms570_init();
_enable_IRQ();
#endif
} g_sciTransfer[2];
+/** Buffer used for sending to SCI */
+tBuffer sciOutBuffer;
+/** Buffer used for receiving from SCI */
+tBuffer sciInBuffer;
+
+
/** @fn void sciInit(void)
* @brief Initializes the SCI Driver
*
/* USER CODE BEGIN (2) */
/* USER CODE END */
+ /** Initialise buffers */
+ sciOutBuffer.buf = xQueueCreate(MAX_BUFFER_LEN, sizeof(uint8_t));
+ sciOutBuffer.mutex = xSemaphoreCreateMutex();
+ sciOutBuffer.flags = 0;
+ sciOutBuffer.buf = xQueueCreate(MAX_BUFFER_LEN, sizeof(uint8_t));
+ sciOutBuffer.mutex = xSemaphoreCreateMutex();
+ sciOutBuffer.flags = 0;
+
/** @b intalise @b SCI */
/** - bring SCI out of reset */
case 11:
// receive
{ uint8_t byte = sciREG->RD;
- if (xQueueSendFromISR(inBuffer.buf, (void*)&byte, NULL) == errQUEUE_FULL) {
+ if (xQueueSendFromISR(sciOutBuffer.buf, (void*)&byte, NULL) == errQUEUE_FULL) {
receiveError++;
}
sciNotification(sciREG, SCI_RX_INT);
// transmit
{
uint8_t byte = 0;
- if (xQueueReceiveFromISR(outBuffer.buf, (uint8_t *)&byte, NULL) == errQUEUE_EMPTY) {
+ if (xQueueReceiveFromISR(sciOutBuffer.buf, (uint8_t *)&byte, NULL) == errQUEUE_EMPTY) {
sciREG->CLRINT = SCI_TX_INT;
- outBuffer.flags &= ~BUF_TRANSFER_IN_PROGRESS;
+ sciOutBuffer.flags &= ~BUF_TRANSFER_IN_PROGRESS;
}
else {
sciREG->TD = byte;