-/* Copyright (C) 2013 Czech Technical University in Prague
+/* Copyright (C) 2013, 2015, 2016 Czech Technical University in Prague
*
* Authors:
* - Michal Horn
// PWM is available for HBR control.
#include "drv/drv.h"
#include <os/semphr.h>
+#include "drv/spi_tms570.h"
+#include "drv/gio_tab.h"
//Flag variable if pwm was initialized and is ready to start.
static boolean_t pwm_initialized = FALSE;
// Prepared command to be send on SPI.
// Default value is watchdog reset command.
-uint16_t hbr_spi_wdg_tx = 0x03DB;
-
-// Shadow variable of hbr_spi_wdg_tx
-uint16_t hbr_spi_wdg_tx_shd = 0x03DB;
+static const uint8_t hbr_spi_wdg_tx[2] = { 0x03, 0xDB };
// Response from SPI.
-uint16_t hbr_spi_wdg_rx = 0;
+static uint8_t hbr_spi_wdg_rx[2] = {0};
// Shadow variable of hbr_spi_wdg_shd
-uint16_t hbr_spi_wdg_rx_shd = 0;
+static uint8_t hbr_spi_wdg_rx_shd[2] = {0};
// SPI communication result code (one of SPI_MSG_*)
int hbr_spi_code = 0;
* @return always zero
*/
int drv_hbr_spi_wdg_callback(struct spi_drv *ifc, int code,
- struct spi_msg_head *msg)
+ struct spi_msg *msg)
{
hbr_spi_code = code;
if (code == SPI_MSG_FINISHED) {
- hbr_spi_wdg_rx = hbr_spi_wdg_rx_shd;
- hbr_spi_wdg_tx_shd = hbr_spi_wdg_tx;
+ memcpy(hbr_spi_wdg_rx, hbr_spi_wdg_rx_shd, sizeof(hbr_spi_wdg_rx));
}
return 0;
}
// SPI message format definition for watchdog reset command
-spi_msg_head_t hbr_spi_wdg = {
+spi_msg_t hbr_spi_wdg = {
.flags = 0,
- .addr = 0,
- .rq_len = 2,
- .tx_buf = (uint8_t *)&hbr_spi_wdg_tx_shd,
- .rx_buf = (uint8_t *)&hbr_spi_wdg_rx_shd,
+ .dev = SPIDEV_L99H01,
+ .rq_len = sizeof(hbr_spi_wdg_tx),
+ .tx_buf = hbr_spi_wdg_tx,
+ .rx_buf = hbr_spi_wdg_rx_shd,
.callback = drv_hbr_spi_wdg_callback,
.private = 1
};
*/
void drv_hbr_wdg_task(void *p)
{
- spi_drv_t *ifc;
-
- ifc = spi_find_drv(NULL, 4);
-
- if (ifc == NULL) {
- wdg_start = FALSE;
- vTaskDelete(NULL);
- }
-
portTickType xLastWakeTime;
xLastWakeTime = xTaskGetTickCount();
wdg_start = FALSE;
}
else
- spi_msg_rq_ins(ifc, &hbr_spi_wdg);
+ spi_msg_rq_ins(&hbr_spi_wdg);
xSemaphoreGive(wdg_sync);
}
}
if (wdg_sync == NULL )
return -RPP_ENOMEM;
if (xTaskCreate(drv_hbr_wdg_task,
- (const signed char *)"hbr_wdg_task",
+ "hbr_wdg_task",
1024, NULL, 1, &wdg_handle) != pdPASS) {
wdg_start = FALSE;
return -RPP_ENOMEM;
*/
void drv_hbr_set_dir(int direction)
{
- hal_gpio_pin_set_value(PIN_DSC_HBRDIR, direction);
+ gio_tab_set(PIN_HBRDIR, !!direction);
}
/**
*/
int drv_hbr_get_dir()
{
- return hal_gpio_pin_get_value(PIN_DSC_HBRDIR);
+ return gio_tab_get(PIN_HBRDIR) ? 1 : 0;
}
/**
*/
void drv_hbr_set_en(int value)
{
- hal_gpio_pin_set_value(PIN_DSC_HBREN, value);
+ gio_tab_set(PIN_HBREN, !!value);
}
/**
*/
int drv_hbr_get_en()
{
- return hal_gpio_pin_get_value(PIN_DSC_HBREN);
+ return gio_tab_get(PIN_HBREN) ? 1 : 0;
}