2018-04-04 18:57:36 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* drivers/1wire/1wire_internal.h
|
|
|
|
*
|
2021-11-15 08:04:55 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2018-04-04 18:57:36 +02:00
|
|
|
*
|
2021-11-15 08:04:55 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-04-04 18:57:36 +02:00
|
|
|
*
|
2021-11-15 08:04:55 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2018-04-04 18:57:36 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __DRIVERS_1WIRE_1WIRE_INTERNAL_H
|
|
|
|
#define __DRIVERS_1WIRE_1WIRE_INTERNAL_H
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
2020-02-01 08:17:32 +01:00
|
|
|
#include <nuttx/semaphore.h>
|
2018-04-24 15:21:02 +02:00
|
|
|
#include <nuttx/power/pm.h>
|
2018-04-04 18:57:36 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct onewire_dev_s;
|
|
|
|
|
|
|
|
struct onewire_sem_s
|
|
|
|
{
|
|
|
|
sem_t sem;
|
|
|
|
pid_t holder; /* The current holder of the semaphore */
|
|
|
|
int16_t count; /* Number of counts held */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct onewire_master_s
|
|
|
|
{
|
|
|
|
FAR struct onewire_dev_s *dev; /* 1-Wire lower half */
|
|
|
|
struct onewire_sem_s devsem; /* Re-entrant semaphore */
|
|
|
|
int nslaves; /* Number of 1-wire slaves */
|
|
|
|
int maxslaves; /* Maximum number of 1-wire slaves */
|
|
|
|
bool insearch; /* If we are in middle of 1-wire search */
|
2018-04-24 15:21:02 +02:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
struct pm_callback_s pm_cb; /* PM callbacks */
|
|
|
|
#endif
|
2018-04-04 18:57:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct onewire_slave_s
|
|
|
|
{
|
|
|
|
FAR struct onewire_master_s *master; /* Slave's bus master */
|
|
|
|
uint64_t romcode; /* Unique ROM id in bus */
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-07-04 17:31:21 +02:00
|
|
|
/* Additional CRC helpers from 1wire_crc.c */
|
2018-04-04 18:57:36 +02:00
|
|
|
|
|
|
|
bool onewire_valid_rom(uint64_t rom);
|
|
|
|
|
|
|
|
/* Rest are from 1wire.c */
|
|
|
|
|
2020-03-31 23:19:07 +02:00
|
|
|
int onewire_sem_wait(FAR struct onewire_master_s *master);
|
2018-04-04 18:57:36 +02:00
|
|
|
void onewire_sem_post(FAR struct onewire_master_s *master);
|
|
|
|
|
|
|
|
int onewire_addslave(FAR struct onewire_master_s *master,
|
|
|
|
FAR struct onewire_slave_s *slave);
|
|
|
|
int onewire_removeslave(FAR struct onewire_master_s *master,
|
|
|
|
FAR struct onewire_slave_s *slave);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: onewire_reset_resume
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int onewire_reset_resume(FAR struct onewire_master_s *master);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: onewire_reset_select
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-04-08 19:12:10 +02:00
|
|
|
int onewire_reset_select(FAR struct onewire_master_s *master,
|
|
|
|
uint64_t romcode);
|
2018-04-04 18:57:36 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: onewire_triplet
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Used by 1-wire search algorithm. Reads two bits and writes
|
|
|
|
* one based on comparison of read bits.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* search_bit - Bit to write if both id_bit and cmp_id_bit match
|
|
|
|
*
|
|
|
|
* Output Parameters:
|
|
|
|
* taken_bit - Bit indicating the direction where the search is
|
|
|
|
* progressing.
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* Number of valid bits or negative on error.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int onewire_triplet(FAR struct onewire_master_s *master,
|
|
|
|
uint8_t search_bit,
|
|
|
|
FAR uint8_t *taken_bit);
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: onewire_search
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Search all devices from a 1-wire network. This is the 1-wire search
|
2021-04-08 18:21:35 +02:00
|
|
|
* algorithm from Maxim Application Note 187. Note! This is an atomic
|
|
|
|
* operation. The callback 'cb_search' can't execute any function that will
|
|
|
|
* lock this bus, because of the locked state as long the search is active.
|
2018-04-04 18:57:36 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* master - Pointer to the allocated 1-wire interface
|
|
|
|
* family - Limit search to devices of matching family
|
|
|
|
* alarmonly - Limit search to devices on alarm state
|
|
|
|
* cb_search - Callback to call on each device found
|
|
|
|
* arg - Argument passed to cb_search
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* Number of slaves present and matching family.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int onewire_search(FAR struct onewire_master_s *master,
|
|
|
|
int family,
|
|
|
|
bool alarmonly,
|
2020-03-31 23:19:07 +02:00
|
|
|
CODE void (*cb_search)(int family,
|
|
|
|
uint64_t romcode,
|
|
|
|
FAR void *arg),
|
2021-04-08 18:21:35 +02:00
|
|
|
FAR void *arg);
|
2018-04-24 15:21:02 +02:00
|
|
|
|
2018-04-04 18:57:36 +02:00
|
|
|
#endif /* __DRIVERS_1WIRE_1WIRE_INTERNAL_H */
|