提交 a4456b86 编写于 作者: D dzzxzz@gmail.com

re-format the coding style in spi_core.c

1, Tabs to Spaces
2, File Format(CR/LF) using UNIX style
3, maximum line length = 80

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2273 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 c1a64657
/*
* File : spi_core.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
*/
#include <drivers/spi.h>
extern rt_err_t rt_spi_bus_device_init(struct rt_spi_bus* bus, const char* name);
extern rt_err_t rt_spidev_device_init(struct rt_spi_device* dev, const char* name);
extern rt_err_t rt_spi_bus_device_init(struct rt_spi_bus *bus, const char *name);
extern rt_err_t rt_spidev_device_init(struct rt_spi_device *dev, const char *name);
rt_err_t rt_spi_bus_register(struct rt_spi_bus* bus, const char* name, const struct rt_spi_ops* ops)
rt_err_t rt_spi_bus_register(struct rt_spi_bus *bus,
const char *name,
const struct rt_spi_ops *ops)
{
rt_err_t result;
......@@ -21,7 +36,10 @@ rt_err_t rt_spi_bus_register(struct rt_spi_bus* bus, const char* name, const str
return RT_EOK;
}
rt_err_t rt_spi_bus_attach_device(struct rt_spi_device* device, const char* name, const char* bus_name, void* user_data)
rt_err_t rt_spi_bus_attach_device(struct rt_spi_device *device,
const char *name,
const char *bus_name,
void *user_data)
{
rt_err_t result;
rt_device_t bus;
......@@ -30,7 +48,7 @@ rt_err_t rt_spi_bus_attach_device(struct rt_spi_device* device, const char* name
bus = rt_device_find(bus_name);
if (bus != RT_NULL && bus->type == RT_Device_Class_SPIBUS)
{
device->bus = (struct rt_spi_bus*)bus;
device->bus = (struct rt_spi_bus *)bus;
/* initialize spidev device */
result = rt_spidev_device_init(device, name);
......@@ -47,7 +65,8 @@ rt_err_t rt_spi_bus_attach_device(struct rt_spi_device* device, const char* name
return -RT_ERROR;
}
rt_err_t rt_spi_configure(struct rt_spi_device* device, struct rt_spi_configuration* cfg)
rt_err_t rt_spi_configure(struct rt_spi_device *device,
struct rt_spi_configuration *cfg)
{
rt_err_t result;
......@@ -76,8 +95,11 @@ rt_err_t rt_spi_configure(struct rt_spi_device* device, struct rt_spi_configurat
return RT_EOK;
}
rt_err_t rt_spi_send_then_send(struct rt_spi_device* device, const void *send_buf1, rt_size_t send_length1,
const void* send_buf2, rt_size_t send_length2)
rt_err_t rt_spi_send_then_send(struct rt_spi_device *device,
const void *send_buf1,
rt_size_t send_length1,
const void *send_buf2,
rt_size_t send_length2)
{
rt_err_t result;
struct rt_spi_message message;
......@@ -144,11 +166,15 @@ rt_err_t rt_spi_send_then_send(struct rt_spi_device* device, const void *send_bu
__exit:
rt_mutex_release(&(device->bus->lock));
return result;
}
rt_err_t rt_spi_send_then_recv(struct rt_spi_device* device, const void *send_buf, rt_size_t send_length,
void* recv_buf, rt_size_t recv_length)
rt_err_t rt_spi_send_then_recv(struct rt_spi_device *device,
const void *send_buf,
rt_size_t send_length,
void *recv_buf,
rt_size_t recv_length)
{
rt_err_t result;
struct rt_spi_message message;
......@@ -215,11 +241,14 @@ rt_err_t rt_spi_send_then_recv(struct rt_spi_device* device, const void *send_bu
__exit:
rt_mutex_release(&(device->bus->lock));
return result;
}
rt_size_t rt_spi_transfer(struct rt_spi_device* device, const void *send_buf,
void* recv_buf, rt_size_t length)
rt_size_t rt_spi_transfer(struct rt_spi_device *device,
const void *send_buf,
void *recv_buf,
rt_size_t length)
{
rt_err_t result;
struct rt_spi_message message;
......@@ -252,7 +281,8 @@ rt_size_t rt_spi_transfer(struct rt_spi_device* device, const void *send_buf,
message.send_buf = send_buf;
message.recv_buf = recv_buf;
message.length = length;
message.cs_take = message.cs_release = 1;
message.cs_take = 1;
message.cs_release = 1;
message.next = RT_NULL;
/* transfer message */
......@@ -266,30 +296,34 @@ rt_size_t rt_spi_transfer(struct rt_spi_device* device, const void *send_buf,
else
{
rt_set_errno(-RT_EIO);
return 0;
}
__exit:
rt_mutex_release(&(device->bus->lock));
return result;
}
struct rt_spi_message *rt_spi_transfer_message(struct rt_spi_device* device,
struct rt_spi_message *rt_spi_transfer_message(struct rt_spi_device *device,
struct rt_spi_message *message)
{
rt_err_t result;
struct rt_spi_message* index;
struct rt_spi_message *index;
RT_ASSERT(device != RT_NULL);
/* get first message */
index = message;
if (index == RT_NULL) return index;
if (index == RT_NULL)
return index;
result = rt_mutex_take(&(device->bus->lock), RT_WAITING_FOREVER);
if (result != RT_EOK)
{
rt_set_errno(-RT_EBUSY);
return index;
}
......@@ -332,10 +366,11 @@ struct rt_spi_message *rt_spi_transfer_message(struct rt_spi_device* device,
__exit:
/* release bus lock */
rt_mutex_release(&(device->bus->lock));
return index;
}
rt_err_t rt_spi_take_bus(struct rt_spi_device* device)
rt_err_t rt_spi_take_bus(struct rt_spi_device *device)
{
rt_err_t result = RT_EOK;
......@@ -346,6 +381,7 @@ rt_err_t rt_spi_take_bus(struct rt_spi_device* device)
if (result != RT_EOK)
{
rt_set_errno(-RT_EBUSY);
return -RT_EBUSY;
}
......@@ -376,7 +412,7 @@ rt_err_t rt_spi_take_bus(struct rt_spi_device* device)
return result;
}
rt_err_t rt_spi_release_bus(struct rt_spi_device* device)
rt_err_t rt_spi_release_bus(struct rt_spi_device *device)
{
RT_ASSERT(device != RT_NULL);
RT_ASSERT(device->bus != RT_NULL);
......@@ -388,7 +424,7 @@ rt_err_t rt_spi_release_bus(struct rt_spi_device* device)
return RT_EOK;
}
rt_err_t rt_spi_take(struct rt_spi_device* device)
rt_err_t rt_spi_take(struct rt_spi_device *device)
{
rt_err_t result;
struct rt_spi_message message;
......@@ -400,10 +436,11 @@ rt_err_t rt_spi_take(struct rt_spi_device* device)
message.cs_take = 1;
result = device->bus->ops->xfer(device, &message);
return result;
}
rt_err_t rt_spi_release(struct rt_spi_device* device)
rt_err_t rt_spi_release(struct rt_spi_device *device)
{
rt_err_t result;
struct rt_spi_message message;
......@@ -415,5 +452,6 @@ rt_err_t rt_spi_release(struct rt_spi_device* device)
message.cs_release = 1;
result = device->bus->ops->xfer(device, &message);
return result;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册