{"id":124,"date":"2014-03-27T00:25:36","date_gmt":"2014-03-27T00:25:36","guid":{"rendered":"http:\/\/int03.co.uk\/blog\/?p=124"},"modified":"2019-02-11T21:47:17","modified_gmt":"2019-02-11T21:47:17","slug":"linux-kernel-module-for-the-tsic-306","status":"publish","type":"post","link":"https:\/\/int03.co.uk\/blog\/2014\/03\/27\/linux-kernel-module-for-the-tsic-306\/","title":{"rendered":"Linux Kernel Module for the TSIC 306"},"content":{"rendered":"<p>I&#8217;ve made my first foray into the kernel, by writing a kernel module for the TSIC 306 temperature sensor. After overcoming the difficulties in setting up the tools, the actual driver development was much easier than expected. The <a title=\"tsic-kernel\" href=\"http:\/\/code.google.com\/p\/tsic-kernel\/\">source code<\/a> is up on Google Code and is basically working, but needs a little more development.<\/p>\n<p>This maps the sensor to the file-system, so you can load the module and read the temperature like this:<\/p>\n<pre>$ sudo insmod tsic.ko\n$ cat \/sys\/kernel\/tsic\/temp\n14680<\/pre>\n<p>In the example above, the temperature is 14.68\u00b0C and all the values are scaled by 1000 to avoid floating point maths in the module, and to match the behaviour of existing sensors such as:<\/p>\n<pre>$ cat \/sys\/class\/thermal\/thermal_zone0\/temp \n40084<\/pre>\n<p>Writing the module turned out to be easier than expected, and there are some great libraries such as gpiolib and kobject which simplify development. Documentation is a bit scarce, but there are some useful resources:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.tldp.org\/LDP\/lkmpg\/2.6\/html\/index.html\" target=\"_blank\">http:\/\/www.tldp.org\/LDP\/lkmpg\/2.6\/html\/index.html<\/a><\/li>\n<li><a href=\"http:\/\/oreilly.com\/openbook\/linuxdrive3\/book\/\" target=\"_blank\">http:\/\/oreilly.com\/openbook\/linuxdrive3\/book\/<\/a><\/li>\n<li><a href=\"https:\/\/www.kernel.org\/doc\/Documentation\/gpio\/\" target=\"_blank\">https:\/\/www.kernel.org\/doc\/Documentation\/gpio\/<\/a><\/li>\n<\/ul>\n<p>Eventually I plan to add support for multiple sensors on configurable GPIO pins,&nbsp; make it more robust and clean up a few issues such as the lack of time-outs in the I\/O.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve made my first foray into the kernel, by writing a kernel module for the TSIC 306 temperature sensor. After overcoming the difficulties in setting up the tools, the actual driver development was much easier than expected. The source code is up on Google Code and is basically working, but needs a little more development. &hellip; <a href=\"https:\/\/int03.co.uk\/blog\/2014\/03\/27\/linux-kernel-module-for-the-tsic-306\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Linux Kernel Module for the TSIC 306<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/posts\/124"}],"collection":[{"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=124"}],"version-history":[{"count":3,"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/posts\/124\/revisions"}],"predecessor-version":[{"id":785,"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/posts\/124\/revisions\/785"}],"wp:attachment":[{"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/int03.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}