Skip to content

Instantly share code, notes, and snippets.

View scottellis's full-sized avatar

Scott Ellis scottellis

View GitHub Profile
@scottellis
scottellis / gist:715712
Created November 25, 2010 17:52
spike_prepare_spi_message
static void spike_prepare_spi_message(void)
{
spi_message_init(&spike_ctl.msg);
/* put some changing values in tx_buff for testing */
spike_ctl.tx_buff[0] = spike_dev.test_data++;
spike_ctl.tx_buff[1] = spike_dev.test_data++;
spike_ctl.tx_buff[2] = spike_dev.test_data++;
spike_ctl.tx_buff[3] = spike_dev.test_data++;
@scottellis
scottellis / gist:715716
Created November 25, 2010 17:55
spike_do_one_message
static int spike_do_one_message(void)
{
int status;
if (down_interruptible(&spike_dev.spi_sem))
return -ERESTARTSYS;
if (!spike_dev.spi_device) {
up(&spike_dev.spi_sem);
return -ENODEV;
@scottellis
scottellis / gist:716613
Created November 26, 2010 11:54
add_spike_device_to_bus
static int __init add_spike_device_to_bus(void)
{
struct spi_master *spi_master;
struct spi_device *spi_device;
struct device *pdev;
char buff[64];
int status = 0;
spi_master = spi_busnum_to_master(SPI_BUS);
if (!spi_master) {
@scottellis
scottellis / gist:729666
Created December 6, 2010 00:52
spike_completion_handler
static void spike_completion_handler(void *arg)
{
spike_ctl.spi_callbacks++;
spike_ctl.busy = 0;
}
@scottellis
scottellis / gist:729672
Created December 6, 2010 00:58
struct spike_oontrol
struct spike_control {
struct spi_message msg;
struct spi_transfer transfer;
u32 busy;
u32 spi_callbacks;
u32 busy_counter;
u8 *tx_buff;
};
@scottellis
scottellis / gist:729673
Created December 6, 2010 00:58
struct spike_oontrol
struct spike_control {
struct spi_message msg;
struct spi_transfer transfer;
u32 busy;
u32 spi_callbacks;
u32 busy_counter;
u8 *tx_buff;
};
@scottellis
scottellis / gist:729675
Created December 6, 2010 01:00
spike_queue_spi_write
static int spike_queue_spi_write(void)
{
int status;
unsigned long flags;
spi_message_init(&spike_ctl.msg);
/* this gets called when the spi_message completes */
spike_ctl.msg.complete = spike_completion_handler;
spike_ctl.msg.context = NULL;
@scottellis
scottellis / gist:729676
Created December 6, 2010 01:01
struct spike_dev
struct spike_dev {
spinlock_t spi_lock;
struct semaphore fop_sem;
dev_t devt;
struct cdev cdev;
struct class *class;
struct spi_device *spi_device;
struct hrtimer timer;
u32 timer_period_sec;
u32 timer_period_ns;
@scottellis
scottellis / gist:730170
Created December 6, 2010 11:35
spike_timer_callback
static enum hrtimer_restart spike_timer_callback(struct hrtimer *timer)
{
if (!spike_dev.running) {
return HRTIMER_NORESTART;
}
/* busy means the previous message has not completed */
if (spike_ctl.busy) {
spike_ctl.busy_counter++;
}
@scottellis
scottellis / gist:736463
Created December 10, 2010 16:55
struct spi_board_info
struct spi_board_info {
/* the device name and module name are coupled, like platform_bus;
* "modalias" is normally the driver name.
*
* platform_data goes to spi_device.dev.platform_data,
* controller_data goes to spi_device.controller_data,
* irq is copied too
*/
char modalias[SPI_NAME_SIZE];
const void *platform_data;